当前位置: 首页>>代码示例>>Java>>正文


Java InternalActionLiteral类代码示例

本文整理汇总了Java中jason.asSyntax.InternalActionLiteral的典型用法代码示例。如果您正苦于以下问题:Java InternalActionLiteral类的具体用法?Java InternalActionLiteral怎么用?Java InternalActionLiteral使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


InternalActionLiteral类属于jason.asSyntax包,在下文中一共展示了InternalActionLiteral类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fixAgInIAandFunctions

import jason.asSyntax.InternalActionLiteral; //导入依赖的package包/类
private void fixAgInIAandFunctions(Agent a, Literal l) throws Exception {
    // if l is internal action/function
    if (l instanceof InternalActionLiteral) {
        ((InternalActionLiteral)l).setIA(null); // reset the IA in the literal, the IA there will be updated next getIA call
    }
    if (l instanceof ArithFunctionTerm) {
        ((ArithFunctionTerm)l).setAgent(a);
    }
    if (l instanceof Rule) {
        LogicalFormula f = ((Rule)l).getBody();
        if (f instanceof Literal) {
            fixAgInIAandFunctions(a, (Literal)f);
        }
    }
    for (int i=0; i<l.getArity(); i++) {
        if (l.getTerm(i) instanceof Literal)
            fixAgInIAandFunctions(a, (Literal)l.getTerm(i));            
    }
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:20,代码来源:Agent.java

示例2: fixAgInIAandFunctions

import jason.asSyntax.InternalActionLiteral; //导入依赖的package包/类
private void fixAgInIAandFunctions(Agent a, Literal l) throws Exception {
    // if l is internal action/function
    if (l instanceof InternalActionLiteral) {
        ((InternalActionLiteral)l).setIA(null); // reset the IA in the literal, the IA there will be updated next getIA call
    }
    if (l instanceof ArithFunctionTerm) {
        ((ArithFunctionTerm)l).setAgent(a);
    }
    if (l instanceof Rule) {
        LogicalFormula f = ((Rule)l).getBody();
        if (f instanceof Literal) {
            fixAgInIAandFunctions(a, (Literal)f);
        }
    }
    for (int i=0; i<l.getArity(); i++) {
        if (l.getTerm(i) instanceof Literal)
            fixAgInIAandFunctions(a, (Literal)l.getTerm(i));
    }
}
 
开发者ID:jason-lang,项目名称:jason,代码行数:20,代码来源:Agent.java

示例3: execute

import jason.asSyntax.InternalActionLiteral; //导入依赖的package包/类
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
    checkArguments(args);
    
    ForkData fd = new ForkData( ((Atom)args[0]).equals(aAnd)) ;
    
    Intention currentInt = ts.getC().getSelectedIntention();
    for (int iPlans = 1; iPlans < args.length; iPlans++) {
        Intention i = new ForkIntention(currentInt, fd);
        fd.addIntention(i);
        i.pop(); // remove the top IM, it will be introduced back later (modified)
        IntendedMeans im = (IntendedMeans)currentInt.peek().clone();
        
        // adds the .join in the plan
        InternalActionLiteral joinL = new InternalActionLiteral(joinS, ts.getAg());
        joinL.addTerm(new ObjectTermImpl(fd));
        PlanBody joinPB = new PlanBodyImpl(BodyType.internalAction, joinL);
        joinPB.setBodyNext(im.getCurrentStep().getBodyNext());
        
        // adds the argument in the plan (before join)
        PlanBody whattoadd = (PlanBody)args[iPlans].clone();
        whattoadd.add(joinPB);
        whattoadd.setAsBodyTerm(false);
        im.insertAsNextStep(whattoadd);
        im.removeCurrentStep(); // remove the .fork
        i.push(im);
        ts.getC().addIntention(i);
    }


    return true;
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:33,代码来源:fork.java

示例4: resume

import jason.asSyntax.InternalActionLiteral; //导入依赖的package包/类
void resume(final boolean stopByTimeout) {
    // unregister (to not receive intentionAdded again)
    c.removeEventListener(this);

    // invoke changes in C latter, so to avoid concurrent changes in C
    ts.runAtBeginOfNextCycle(new Runnable() {
        public void run() {
            try {
                // add SI again in C.I if (1) it was not removed (2) is is not running (by some other reason) -- but this test does not apply to atomic intentions --, and (3) this wait was not dropped
                if (c.removePendingIntention(sEvt) == si && (si.isAtomic() || !c.hasIntention(si)) && !dropped) {
                    if (stopByTimeout && te != null && elapsedTimeTerm == null) {
                        // fail the .wait by timeout
                        if (si.isSuspended()) { // if the intention was suspended by .suspend
                            PlanBody body = si.peek().getPlan().getBody();
                            body.add(1, new PlanBodyImpl(BodyType.internalAction, new InternalActionLiteral(".fail")));
                            c.addPendingIntention(suspend.SUSPENDED_INT+si.getId(), si);
                        } else {
                            ts.generateGoalDeletion(si, JasonException.createBasicErrorAnnots("wait_timeout", "timeout in .wait"));
                        }
                    } else if (! si.isFinished()) {
                        si.peek().removeCurrentStep();
                        
                        if (elapsedTimeTerm != null) {
                            long elapsedTime = System.currentTimeMillis() - startTime;
                            un.unifies(elapsedTimeTerm, new NumberTermImpl(elapsedTime));
                        }
                        if (si.isSuspended()) { // if the intention was suspended by .suspend
                            c.addPendingIntention(suspend.SUSPENDED_INT+si.getId(), si);
                        } else {
                            c.resumeIntention(si);
                        }
                    }
                }    
            } catch (Exception e) {
                ts.getLogger().log(Level.SEVERE, "Error at .wait thread", e);
            }
        }
    });
    ts.getUserAgArch().wakeUpDeliberate();
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:41,代码来源:wait.java

示例5: testAgentClone

import jason.asSyntax.InternalActionLiteral; //导入依赖的package包/类
public void testAgentClone() throws Exception {
    Agent a = new Agent();

    a.initAg("examples/auction/ag3.asl");
    String p1 = a.getPL().toString();
    String b1 = a.getBB().toString();
    InternalAction ia1 = ((InternalActionLiteral)a.getPL().get("prop_alliance").getBody().getBodyTerm()).getIA(a);
    assertTrue(ia1 != null);
    // get the arith expr (B+C) from the plan
    Structure send1 = (Structure)a.getPL().get("palliance").getBody().getBodyNext().getBodyNext().getBodyTerm();
    ArithFunctionTerm add1  = (ArithFunctionTerm)((Structure)send1.getTerm(2)).getTerm(1);
    assertEquals("(B+C)", add1.toString());

    // the agent is null here because it is an arith expr
    //assertEquals(null, add1.getAgent());
    
    a = a.clone(new AgArch());
    assertEquals(p1, a.getPL().toString());
    assertEquals(b1.length(), a.getBB().toString().length());

    InternalAction ia2 = ((InternalActionLiteral)a.getPL().get("prop_alliance").getBody().getBodyTerm()).getIA(null);
    assertEquals(null, ia2); // the clone have to set null for the IA so they do not share the same implementation

    Structure send2 = (Structure)a.getPL().get("palliance").getBody().getBodyNext().getBodyNext().getBodyTerm();
    ArithFunctionTerm add2  = (ArithFunctionTerm)((Structure)send2.getTerm(2)).getTerm(1);
    assertEquals("(B+C)", add2.toString());

    // after clone, the agent in (B+C) must be the cloned agent
    assertTrue(a == add2.getAgent());
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:31,代码来源:TSTest.java

示例6: execute

import jason.asSyntax.InternalActionLiteral; //导入依赖的package包/类
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
    checkArguments(args);

    ForkData fd = new ForkData( ((Atom)args[0]).equals(aAnd)) ;

    Intention currentInt = ts.getC().getSelectedIntention();
    for (int iPlans = 1; iPlans < args.length; iPlans++) {
        Intention i = new ForkIntention(currentInt, fd);
        fd.addIntention(i);
        i.pop(); // remove the top IM, it will be introduced back later (modified)
        IntendedMeans im = (IntendedMeans)currentInt.peek().clone();

        // adds the .join in the plan
        InternalActionLiteral joinL = new InternalActionLiteral(joinS, ts.getAg());
        joinL.addTerm(new ObjectTermImpl(fd));
        PlanBody joinPB = new PlanBodyImpl(BodyType.internalAction, joinL);
        joinPB.setBodyNext(im.getCurrentStep().getBodyNext());

        // adds the argument in the plan (before join)
        PlanBody whattoadd = (PlanBody)args[iPlans].clone();
        whattoadd.add(joinPB);
        whattoadd.setAsBodyTerm(false);
        im.insertAsNextStep(whattoadd);
        im.removeCurrentStep(); // remove the .fork
        i.push(im);
        ts.getC().addIntention(i);
    }


    return true;
}
 
开发者ID:jason-lang,项目名称:jason,代码行数:33,代码来源:fork.java

示例7: resume

import jason.asSyntax.InternalActionLiteral; //导入依赖的package包/类
void resume(final boolean stopByTimeout) {
    // unregister (to not receive intentionAdded again)
    c.removeEventListener(this);

    // invoke changes in C latter, so to avoid concurrent changes in C
    ts.runAtBeginOfNextCycle(new Runnable() {
        public void run() {
            try {
                // add SI again in C.I if (1) it was not removed (2) is is not running (by some other reason) -- but this test does not apply to atomic intentions --, and (3) this wait was not dropped
                if (c.removePendingIntention(sEvt) == si && (si.isAtomic() || !c.hasIntention(si)) && !dropped) {
                    if (stopByTimeout && te != null && elapsedTimeTerm == null) {
                        // fail the .wait by timeout
                        if (si.isSuspended()) { // if the intention was suspended by .suspend
                            PlanBody body = si.peek().getPlan().getBody();
                            body.add(1, new PlanBodyImpl(BodyType.internalAction, new InternalActionLiteral(".fail")));
                            c.addPendingIntention(suspend.SUSPENDED_INT+si.getId(), si);
                        } else {
                            ts.generateGoalDeletion(si, JasonException.createBasicErrorAnnots("wait_timeout", "timeout in .wait"));
                        }
                    } else if (! si.isFinished()) {
                        si.peek().removeCurrentStep();

                        if (elapsedTimeTerm != null) {
                            long elapsedTime = System.currentTimeMillis() - startTime;
                            un.unifies(elapsedTimeTerm, new NumberTermImpl(elapsedTime));
                        }
                        if (si.isSuspended()) { // if the intention was suspended by .suspend
                            c.addPendingIntention(suspend.SUSPENDED_INT+si.getId(), si);
                        } else {
                            c.resumeIntention(si);
                        }
                    }
                }
            } catch (Exception e) {
                ts.getLogger().log(Level.SEVERE, "Error at .wait thread", e);
            }
        }
    });
    ts.getUserAgArch().wakeUpDeliberate();
}
 
开发者ID:jason-lang,项目名称:jason,代码行数:41,代码来源:wait.java

示例8: testAgentClone

import jason.asSyntax.InternalActionLiteral; //导入依赖的package包/类
public void testAgentClone() throws Exception {
    Agent a = new Agent();

    a.initAg("examples/auction/ag3.asl");
    String p1 = a.getPL().toString();
    String b1 = a.getBB().toString();
    InternalAction ia1 = ((InternalActionLiteral)a.getPL().get("prop_alliance").getBody().getBodyTerm()).getIA(a);
    assertTrue(ia1 != null);
    // get the arith expr (B+C) from the plan
    Structure send1 = (Structure)a.getPL().get("palliance").getBody().getBodyNext().getBodyNext().getBodyTerm();
    ArithFunctionTerm add1  = (ArithFunctionTerm)((Structure)send1.getTerm(2)).getTerm(1);
    assertEquals("(B+C)", add1.toString());

    // the agent is null here because it is an arith expr
    //assertEquals(null, add1.getAgent());

    a = a.clone(new AgArch());
    assertEquals(p1, a.getPL().toString());
    assertEquals(b1.length(), a.getBB().toString().length());

    InternalAction ia2 = ((InternalActionLiteral)a.getPL().get("prop_alliance").getBody().getBodyTerm()).getIA(null);
    assertEquals(null, ia2); // the clone have to set null for the IA so they do not share the same implementation

    Structure send2 = (Structure)a.getPL().get("palliance").getBody().getBodyNext().getBodyNext().getBodyTerm();
    ArithFunctionTerm add2  = (ArithFunctionTerm)((Structure)send2.getTerm(2)).getTerm(1);
    assertEquals("(B+C)", add2.toString());

    // after clone, the agent in (B+C) must be the cloned agent
    assertTrue(a == add2.getAgent());
}
 
开发者ID:jason-lang,项目名称:jason,代码行数:31,代码来源:TSTest.java


注:本文中的jason.asSyntax.InternalActionLiteral类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。