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


Java Plan类代码示例

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


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

示例1: importComponents

import jason.asSyntax.Plan; //导入依赖的package包/类
/** Imports beliefs, plans and initial goals from another agent. Initial beliefs and goals 
 *  are stored in "initialBels" and "initialGoals" lists but not included in the BB / TS.
 *  The methods addInitialBelsInBB and addInitialGoalsInTS should be called in the sequel to
 *  add those beliefs and goals into the agent. */
public void importComponents(Agent a) throws JasonException {
    if (a != null) {
        for (Literal b: a.initialBels) {
            this.addInitialBel(b);
            try {
                fixAgInIAandFunctions(this,b);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        
        for (Literal g: a.initialGoals) 
            this.addInitialGoal(g);
                    
        for (Plan p: a.getPL()) 
            this.getPL().add(p, false);

        if (getPL().hasMetaEventPlans())
            getTS().addGoalListener(new GoalListenerForMetaEvents(getTS()));
    }
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:26,代码来源:Agent.java

示例2: testRelevant

import jason.asSyntax.Plan; //导入依赖的package包/类
public void testRelevant() throws JasonException, ParseException {
    PlanLibrary pl = new PlanLibrary();
    pl.add(Plan.parse("+p(0) <- .print(a)."));
    pl.add(Plan.parse("+p(X) : X > 0 <- .print(a)."));
    
    pl.add(Plan.parse("+!p(0) <- .print(a)."));
    pl.add(Plan.parse("+!p(X) : X > 0 <- .print(a)."));

    pl.add(Plan.parse("+!X <- .print(a)."));
    
    List<Plan> pls = pl.getCandidatePlans(ASSyntax.parseTrigger("+p(3)"));
    assertEquals(2, pls.size());

    pls = pl.getCandidatePlans(ASSyntax.parseTrigger("+!p(3)"));
    assertEquals(3, pls.size());    

    pls = pl.getCandidatePlans(ASSyntax.parseTrigger("+!bla"));
    assertEquals(1, pls.size());    

    pls = pl.getCandidatePlans(ASSyntax.parseTrigger("+bla"));
    assertNull(pls);    
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:23,代码来源:PlanTest.java

示例3: testPlanTermWithVarBody

import jason.asSyntax.Plan; //导入依赖的package包/类
public void testPlanTermWithVarBody() throws ParseException {
    Term pt = ASSyntax.parseTerm("{ +!g : c <- B }");
    assertEquals("{ +!g : c <- B }", pt.toString());
    assertTrue(pt instanceof Plan);
    
    Unifier u = new Unifier();
    u.unifies(new VarTerm("B"), ASSyntax.parseTerm("{ .print(a); .print(b); .print(c) }"));
    pt = pt.capply(u);
    assertEquals("{ +!g : c <- .print(a); .print(b); .print(c) }", pt.toString());
    pt = ASSyntax.parseTerm("{ +!g : c <- B; a1; B }");
    pt = pt.capply(u);
    assertEquals("{ +!g : c <- .print(a); .print(b); .print(c); a1; .print(a); .print(b); .print(c) }", pt.toString());
    
    pt = ASSyntax.parseTerm("{ +!g : c <- .print(0); B; B; .print(d); C }");
    u.unifies(new VarTerm("C"), ASSyntax.parseTerm("{ a1 }"));
    pt = pt.capply(u);
    assertEquals(9, ((Plan)pt).getBody().getPlanSize());
    assertEquals("{ +!g : c <- .print(0); .print(a); .print(b); .print(c); .print(a); .print(b); .print(c); .print(d); a1 }", pt.toString());
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:20,代码来源:PlanTest.java

示例4: setUp

import jason.asSyntax.Plan; //导入依赖的package包/类
protected void setUp() throws Exception {
    super.setUp();
    
    intention1 = new Intention();
    Plan p = Plan.parse("+!g0 : true <- !g1; !g4.");
    intention1.push(new IntendedMeans(new Option(p,new Unifier()), null));
    
    p = Plan.parse("+!g1 : true <- !g2.");
    intention1.push(new IntendedMeans(new Option(p,new Unifier()), null));

    p = Plan.parse("+!g2 : true <- !g4; f;g.");
    intention1.push(new IntendedMeans(new Option(p,new Unifier()), null));
    
    p4 = Plan.parse("+!g4 : true <- h.");
    intention1.push(new IntendedMeans(new Option(p4,new Unifier()), null));

    p5 = Plan.parse("+!g5 : true <- i.");
    
    ag = new Agent();
    ag.initAg();
    ag.getPL().add(Plan.parse("-!g1 : true <- j."));
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:23,代码来源:StdLibTest.java

示例5: process

import jason.asSyntax.Plan; //导入依赖的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;
}
 
开发者ID:jason-lang,项目名称:jason,代码行数:23,代码来源:LoggerDirective.java

示例6: testRelevant

import jason.asSyntax.Plan; //导入依赖的package包/类
public void testRelevant() throws JasonException, ParseException {
    PlanLibrary pl = new PlanLibrary();
    pl.add(Plan.parse("+p(0) <- .print(a)."));
    pl.add(Plan.parse("+p(X) : X > 0 <- .print(a)."));

    pl.add(Plan.parse("+!p(0) <- .print(a)."));
    pl.add(Plan.parse("+!p(X) : X > 0 <- .print(a)."));

    pl.add(Plan.parse("+!X <- .print(a)."));

    List<Plan> pls = pl.getCandidatePlans(ASSyntax.parseTrigger("+p(3)"));
    assertEquals(2, pls.size());

    pls = pl.getCandidatePlans(ASSyntax.parseTrigger("+!p(3)"));
    assertEquals(3, pls.size());

    pls = pl.getCandidatePlans(ASSyntax.parseTrigger("+!bla"));
    assertEquals(1, pls.size());

    pls = pl.getCandidatePlans(ASSyntax.parseTrigger("+bla"));
    assertNull(pls);
}
 
开发者ID:jason-lang,项目名称:jason,代码行数:23,代码来源:PlanTest.java

示例7: testPlanTermWithVarBody

import jason.asSyntax.Plan; //导入依赖的package包/类
public void testPlanTermWithVarBody() throws ParseException {
    Term pt = ASSyntax.parseTerm("{ +!g : c <- B }");
    assertEquals("{ +!g : c <- B }", pt.toString());
    assertTrue(pt instanceof Plan);

    Unifier u = new Unifier();
    u.unifies(new VarTerm("B"), ASSyntax.parseTerm("{ .print(a); .print(b); .print(c) }"));
    pt = pt.capply(u);
    assertEquals("{ +!g : c <- .print(a); .print(b); .print(c) }", pt.toString());
    pt = ASSyntax.parseTerm("{ +!g : c <- B; a1; B }");
    pt = pt.capply(u);
    assertEquals("{ +!g : c <- .print(a); .print(b); .print(c); a1; .print(a); .print(b); .print(c) }", pt.toString());

    pt = ASSyntax.parseTerm("{ +!g : c <- .print(0); B; B; .print(d); C }");
    u.unifies(new VarTerm("C"), ASSyntax.parseTerm("{ a1 }"));
    pt = pt.capply(u);
    assertEquals(9, ((Plan)pt).getBody().getPlanSize());
    assertEquals("{ +!g : c <- .print(0); .print(a); .print(b); .print(c); .print(a); .print(b); .print(c); .print(d); a1 }", pt.toString());
}
 
开发者ID:jason-lang,项目名称:jason,代码行数:20,代码来源:PlanTest.java

示例8: setUp

import jason.asSyntax.Plan; //导入依赖的package包/类
protected void setUp() throws Exception {
    super.setUp();

    intention1 = new Intention();
    Plan p = Plan.parse("+!g0 : true <- !g1; !g4.");
    intention1.push(new IntendedMeans(new Option(p,new Unifier()), null));

    p = Plan.parse("+!g1 : true <- !g2.");
    intention1.push(new IntendedMeans(new Option(p,new Unifier()), null));

    p = Plan.parse("+!g2 : true <- !g4; f;g.");
    intention1.push(new IntendedMeans(new Option(p,new Unifier()), null));

    p4 = Plan.parse("+!g4 : true <- h.");
    intention1.push(new IntendedMeans(new Option(p4,new Unifier()), null));

    p5 = Plan.parse("+!g5 : true <- i.");

    ag = new Agent();
    ag.initAg();
    ag.getPL().add(Plan.parse("-!g1 : true <- j."));
}
 
开发者ID:jason-lang,项目名称:jason,代码行数:23,代码来源:StdLibTest.java

示例9: process

import jason.asSyntax.Plan; //导入依赖的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;
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:34,代码来源:DG.java

示例10: process

import jason.asSyntax.Plan; //导入依赖的package包/类
@Override
public Agent process(Pred directive, Agent outerContent, Agent innerContent) {
    try {
        Term goal = directive.getTerm(0);
        Term fail = directive.getTerm(1);
        Term motivation = directive.getTerm(2);
        Pred subDir = Pred.parsePred("bc("+goal+")");
        Directive sd = DirectiveProcessor.getDirective(subDir.getFunctor());

        // apply sub directive
        Agent newAg = sd.process(subDir, outerContent, innerContent); 
        if (newAg != null) {
            // add +f : true <- .fail_goal(g).
            Plan pf = ASSyntax.parsePlan("+"+fail+" <- .fail_goal("+goal+").");
            pf.setSrcInfo(new SourceInfo(outerContent+"/"+directive, 0));
            newAg.getPL().add(pf);

            // add -m : true <- .succeed_goal(g).
            Plan pm = ASSyntax.parsePlan("-"+motivation+" <- .succeed_goal("+goal+").");
            pm.setSrcInfo(new SourceInfo(outerContent+"/"+directive, 0));
            newAg.getPL().add(pm);
            
            return newAg;
        }
    } catch (Exception e) {
        logger.log(Level.SEVERE,"Directive error.", e);
    }
    return null;
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:30,代码来源:OMC.java

示例11: execCmd

import jason.asSyntax.Plan; //导入依赖的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);
    }        
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:34,代码来源:ReplAg.java

示例12: parse

import jason.asSyntax.Plan; //导入依赖的package包/类
public SideKickParsedData parse(Buffer buf, DefaultErrorSource errorSource) {
    String text;
    try {
        buf.readLock();
        text = buf.getText(0,buf.getLength());
    } finally {
        buf.readUnlock();
    }

    try {
        jason.asSyntax.parser.as2j parser = new jason.asSyntax.parser.as2j(new StringReader(text));
        
        Agent ag = new Agent();
        ag.initAg();
        parser.agent(ag);
        
        // create nodes 
        pd = new SideKickParsedData(buf.getName());
        for (Plan p: ag.getPL()) {
            DefaultMutableTreeNode node = new PlanAsset(p, buf).createTreeNode();
            pd.root.add(node);
        }          
            
    } catch (jason.asSyntax.parser.ParseException ex) {
        addError(ex, errorSource, buf.getPath());
    } catch (Exception e) {
        System.out.println("Error in AS SideKick:"+e);
        e.printStackTrace();
    }
    return pd;
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:32,代码来源:AgentSpeakSideKickParser.java

示例13: PlanAsset

import jason.asSyntax.Plan; //导入依赖的package包/类
public PlanAsset(Plan p, Buffer buf) {
    //super(((p.getLabel() == null) ? "" : "@" + p.getLabel() + " ")    + p.getTriggerEvent());
    super(p.getTrigger().toString());
    this.plan  = p;
    this.start = toPos(buf, p.getSrcInfo().getBeginSrcLine());
    this.end   = toPos(buf, p.getSrcInfo().getEndSrcLine());
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:8,代码来源:AgentSpeakSideKickParser.java

示例14: execute

import jason.asSyntax.Plan; //导入依赖的package包/类
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
       checkArguments(args);
       
	Trigger te = null;
	try {
	    te = Trigger.tryToGetTrigger(args[0]);
       } catch (ParseException e) {}
       if (te == null)
           throw JasonException.createWrongArgument(this,"first argument '"+args[0]+"' must follow the syntax of a trigger.");
       
	ListTerm labels = new ListTermImpl();
	ListTerm lt = new ListTermImpl();
	ListTerm last = lt;
       List<Option> rp = ts.relevantPlans(te);
       if (rp != null) {
           for (Option opt: rp) {
               // remove sources (this IA is used for communication)
               Plan np = (Plan)opt.getPlan().clone();
               if (np.getLabel() != null) 
                   np.getLabel().delSources();
               np.setAsPlanTerm(true);
               np.makeVarsAnnon();
               last = last.append(np);
               if (args.length == 3) 
                   labels.add(np.getLabel());
           }
	}

       boolean ok = un.unifies(lt, args[1]); // args[1] is a var;
       if (ok && args.length == 3)
           ok = un.unifies(labels, args[2]);
       
       return ok;
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:36,代码来源:relevant_plans.java

示例15: execute

import jason.asSyntax.Plan; //导入依赖的package包/类
@Override public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
    Trigger te = null;
    if (args.length == 1 && args[0] instanceof Trigger)
        te = Trigger.tryToGetTrigger(args[0]);
    
    for (Plan p: ts.getAg().getPL()) {
        if (!p.getLabel().toString().startsWith("kqml")) { // do not list kqml plans
            if (te == null || new Unifier().unifies(p.getTrigger(), te)) {
                ts.getLogger().info(p.toString());
            }
        }
    }
    return true;
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:15,代码来源:list_plans.java


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