本文整理汇总了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));
}
}
示例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));
}
}
示例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;
}
示例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();
}
示例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());
}
示例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;
}
示例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();
}
示例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());
}