本文整理汇总了Java中jason.asSyntax.PlanBody类的典型用法代码示例。如果您正苦于以下问题:Java PlanBody类的具体用法?Java PlanBody怎么用?Java PlanBody使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PlanBody类属于jason.asSyntax包,在下文中一共展示了PlanBody类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import jason.asSyntax.PlanBody; //导入依赖的package包/类
public Agent process(Pred directive, Agent outerContent, Agent innerContent) {
try {
Agent newAg = new Agent();
newAg.initAg();
// add .print(te) in the begin and end of the plan
for (Plan p: innerContent.getPL()) {
Literal print1 = Literal.parseLiteral(".print(\"Entering \","+p.getTrigger().getLiteral()+")");
PlanBody b1 = new PlanBodyImpl(BodyType.internalAction, print1);
p.getBody().add(0,b1);
Literal print2 = Literal.parseLiteral(".print(\"Leaving \","+p.getTrigger().getLiteral()+")");
PlanBody b2 = new PlanBodyImpl(BodyType.internalAction, print2);
p.getBody().add(b2);
newAg.getPL().add(p);
}
return newAg;
} catch (Exception e) {
logger.log(Level.SEVERE,"Directive error.", e);
}
return null;
}
示例2: process
import jason.asSyntax.PlanBody; //导入依赖的package包/类
@Override
public Agent process(Pred directive, Agent outerContent, Agent innerContent) {
try {
Agent newAg = new Agent();
newAg.initAg();
Literal goal = Literal.parseLiteral(directive.getTerm(0).toString());
// add +!g : g <- true.
newAg.getPL().add(ASSyntax.parsePlan("+!"+goal+" : " +goal+"."));
// add ?g in the end of all inner plans
for (Plan p: innerContent.getPL()) {
// only for +!g plans
if (p.getTrigger().isAchvGoal()) {
Literal planGoal = p.getTrigger().getLiteral();
if (new Unifier().unifies(planGoal, goal)) { // if the plan goal unifier the pattern goal
PlanBody b = new PlanBodyImpl(BodyType.test, planGoal.copy()); //goal.copy());
p.getBody().add(b);
}
}
newAg.getPL().add(p);
}
// add +g : true <- .succeed_goal(g).
newAg.getPL().add(ASSyntax.parsePlan("+"+goal+" <- .succeed_goal("+goal+")."));
return newAg;
} catch (Exception e) {
logger.log(Level.SEVERE,"Directive error.", e);
}
return null;
}
示例3: execCmd
import jason.asSyntax.PlanBody; //导入依赖的package包/类
void execCmd(String sCmd) {
try {
if (sCmd.endsWith("."))
sCmd = sCmd.substring(0,sCmd.length()-1);
for (String c: replCmds) {
if (c.endsWith(sCmd) && sCmd.startsWith(".")) {
sCmd = c;
break;
}
}
if (sCmd.startsWith(".verbose")) {
sCmd = verbose.class.getPackage().getName() + sCmd;
}
sCmd += ";"+print_unifier.class.getName();
PlanBody lCmd = ASSyntax.parsePlanBody(sCmd);
Trigger te = ASSyntax.parseTrigger("+!run_repl_expr");
Intention i = new Intention();
i.push(new IntendedMeans(
new Option(
new Plan(null,te,null,lCmd),
new Unifier()),
te));
//Literal g = ASSyntax.createLiteral("run_repl_expr", lCmd);
//getTS().getLogger().info("running "+i);
//getTS().getC().addAchvGoal(g, null);
getTS().getC().addIntention(i);
cmdCounter++;
clear();
getTS().getUserAgArch().wake();
} catch (Exception e) {
print("Error parsing "+sCmd+"\n"+e);
}
}
示例4: execute
import jason.asSyntax.PlanBody; //导入依赖的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;
}
示例5: resume
import jason.asSyntax.PlanBody; //导入依赖的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();
}
示例6: transform
import jason.asSyntax.PlanBody; //导入依赖的package包/类
public String transform(Agent ag) throws Exception {
StringBuilder so = new StringBuilder();
so.append("// dot file used to generate goals graph\n");
so.append("// run: dot -Tpdf <theoutput> -o goals.pdf\n");
so.append("digraph goals {\n");
so.append(" rankdir=BT;\n\n");
Set<String> done = new HashSet<String>();
for (Plan p: ag.getPL()) {
if (p.getTrigger().getType() == TEType.achieve) {
String ps = p.getTrigger().getLiteral().getFunctor();
if (!done.contains(ps)) {
done.add(ps);
so.append(" "+ps+";\n");
}
PlanBody b = p.getBody();
while (b != null) {
if (b.getBodyType() == BodyType.achieve || b.getBodyType() == BodyType.achieveNF) {
String bs = ((Literal)b.getBodyTerm()).getFunctor();
String e = bs+ps;
if (!done.contains(e)) {
done.add(e);
so.append(" "+bs+" -> "+ps+";\n");
}
}
b = b.getBodyNext();
}
}
}
so.append("}\n");
return so.toString();
}
示例7: testDelete
import jason.asSyntax.PlanBody; //导入依赖的package包/类
public void testDelete() {
Plan p = Plan.parse("+te : a & b <- !a1; ?a2; .print(a); !g1.");
assertEquals(4, p.getBody().getPlanSize());
p.getBody().removeBody(0);
assertEquals(3, p.getBody().getPlanSize());
assertEquals(PlanBody.BodyType.test, p.getBody().getBodyType());
p.getBody().removeBody(0); // 2
p.getBody().removeBody(0); // 1
assertEquals(1, p.getBody().getPlanSize());
p.getBody().removeBody(0); // 1
assertTrue(p.getBody().isEmptyBody());
}
示例8: testEqualsBodyLiteral
import jason.asSyntax.PlanBody; //导入依赖的package包/类
public void testEqualsBodyLiteral() {
PlanBody bl = new PlanBodyImpl(BodyType.achieve, new LiteralImpl("g1"));
VarTerm v = new VarTerm("X");
Unifier u = new Unifier();
// X = !g1
assertTrue(u.unifies(v, bl));
PlanBody vb = (PlanBody)v.capply(u);
assertEquals(BodyType.achieve, vb.getBodyType());
assertEquals(bl.getBodyTerm(),vb.getBodyTerm());
Plan p = Plan.parse("+te : a & b <- !g1.");
assertEquals(p.getBody(),vb);
}
示例9: testUnifyBody
import jason.asSyntax.PlanBody; //导入依赖的package包/类
public void testUnifyBody() {
Plan p1 = Plan.parse("+te : a & b <- !a1; ?a2; .print(a); !g1.");
PlanBody bl = new PlanBodyImpl(BodyType.action, new VarTerm("A1"));
bl.add(new PlanBodyImpl(BodyType.action, new VarTerm("A2")));
bl.add(new PlanBodyImpl(BodyType.action, new VarTerm("A3")));
//assertEquals(p1.getBody().getArity(), bl.getArity());
Unifier u = new Unifier();
assertTrue(u.unifies(p1.getBody(), bl));
assertEquals("a1", u.get("A1").toString());
assertEquals("a2", u.get("A2").toString());
assertEquals(".print(a); !g1", u.get("A3").toString());
}
示例10: testKQML
import jason.asSyntax.PlanBody; //导入依赖的package包/类
public void testKQML() {
Agent ag = new Agent();
ag.initAg();
assertTrue(ag.parseAS(new File("src/asl/kqmlPlans.asl")));
assertTrue(ag.parseAS(new File("examples/auction/ag1.asl")));
Plan p = ag.getPL().get("l__1");
assertNotNull(p);
assertEquals(p.getBody().getPlanSize(), 1);
assertEquals(((PlanBody)p.getBody()).getBodyType(), PlanBody.BodyType.internalAction);
assertTrue(ag.parseAS(new File("examples/auction/ag2.asl")));
assertTrue(ag.parseAS(new File("examples/auction/ag3.asl")));
}
示例11: process
import jason.asSyntax.PlanBody; //导入依赖的package包/类
@Override
public Agent process(Pred directive, Agent outerContent, Agent innerContent) {
try {
Agent newAg = new Agent();
newAg.initAg();
Literal goal = Literal.parseLiteral(directive.getTerm(0).toString());
// add +!g : g <- true.
newAg.getPL().add(ASSyntax.parsePlan("+!"+goal+" : " +goal+"."));
// add ?g in the end of all inner plans
for (Plan p: innerContent.getPL()) {
// only for +!g plans
if (p.getTrigger().isAchvGoal()) {
Literal planGoal = p.getTrigger().getLiteral();
if (new Unifier().unifies(planGoal, goal)) { // if the plan goal unifier the pattern goal
PlanBody b = new PlanBodyImpl(BodyType.test, planGoal.copy()); //goal.copy());
p.getBody().add(b);
}
}
newAg.getPL().add(p);
}
// add +g : true <- .succeed_goal(g).
newAg.getPL().add(ASSyntax.parsePlan("+"+goal+" <- .succeed_goal("+goal+")."));
return newAg;
} catch (Exception e) {
logger.log(Level.SEVERE,"Directive error.", e);
}
return null;
}
示例12: execCmd
import jason.asSyntax.PlanBody; //导入依赖的package包/类
void execCmd(String sCmd) {
try {
if (sCmd.endsWith("."))
sCmd = sCmd.substring(0,sCmd.length()-1);
for (String c: replCmds) {
if (c.endsWith(sCmd) && sCmd.startsWith(".")) {
sCmd = c;
break;
}
}
if (sCmd.startsWith(".verbose")) {
sCmd = verbose.class.getPackage().getName() + sCmd;
}
sCmd += ";"+print_unifier.class.getName();
PlanBody lCmd = ASSyntax.parsePlanBody(sCmd);
Trigger te = ASSyntax.parseTrigger("+!run_repl_expr");
Intention i = new Intention();
i.push(new IntendedMeans(
new Option(
new Plan(null,te,null,lCmd),
new Unifier()),
te));
//Literal g = ASSyntax.createLiteral("run_repl_expr", lCmd);
//getTS().getLogger().info("running "+i);
//getTS().getC().addAchvGoal(g, null);
getTS().getC().addIntention(i);
cmdCounter++;
clear();
getTS().getUserAgArch().wake();
} catch (Exception e) {
print("Error parsing "+sCmd+"\n"+e);
}
}
示例13: execute
import jason.asSyntax.PlanBody; //导入依赖的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;
}
示例14: resume
import jason.asSyntax.PlanBody; //导入依赖的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();
}
示例15: transform
import jason.asSyntax.PlanBody; //导入依赖的package包/类
public String transform(Agent ag) throws Exception {
StringBuilder so = new StringBuilder();
so.append("// dot file used to generate goals graph\n");
so.append("// run: dot -Tpdf <theoutput> -o goals.pdf\n");
so.append("digraph goals {\n");
so.append(" rankdir=BT;\n\n");
Set<String> done = new HashSet<String>();
for (Plan p: ag.getPL()) {
if (p.getTrigger().getType() == TEType.achieve) {
String ps = p.getTrigger().getLiteral().getFunctor();
if (!done.contains(ps)) {
done.add(ps);
so.append(" "+ps+";\n");
}
PlanBody b = p.getBody();
while (b != null) {
if (b.getBodyType() == BodyType.achieve || b.getBodyType() == BodyType.achieveNF) {
String bs = ((Literal)b.getBodyTerm()).getFunctor();
String e = bs+ps;
if (!done.contains(e)) {
done.add(e);
so.append(" "+bs+" -> "+ps+";\n");
}
}
b = b.getBodyNext();
}
}
}
so.append("}\n");
return so.toString();
}