當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。