public IFuture<Void> execute(IInternalAccess ia) { IBeliefbase bb = ia.getComponentFeature(IBDIXAgentFeature.class).getBeliefbase(); for (Iterator it = beliefs.entrySet().iterator(); it.hasNext(); ) { Map.Entry entry = (Map.Entry) it.next(); bb.getBelief((String) entry.getKey()).setFact(entry.getValue()); } return IFuture.DONE; } }
/** * Called when something went wrong (e.g. timeout). */ public void failed() { // Remove dealer fact. getBeliefbase().getBelief("dealer").setFact(null); } }
/** * When the plan has failed, assume that environment is down. * Remove fact to enable new search for environment. */ public void failed() { // Received a timeout. Probably the environment agent has died. getBeliefbase().getBelief("environmentagent").setFact(null); }
/** * When the plan has failed, assume that environment is down. * Remove fact to enable new search for environment. */ public void failed() { // Received a timeout. Probably the environment agent has died. getBeliefbase().getBelief("environmentagent").setFact(null); }
/** * Called when something went wrong (e.g. timeout). */ public void failed() { // Remove dealer fact. getBeliefbase().getBelief("dealer").setFact(null); } }
/** * The body method is called on the * instatiated plan instance from the scheduler. */ public void body() { getLogger().info("Plan invoked."); getBeliefbase().getBelief("invoked").setFact(Boolean.TRUE); } }
/** * Check that plans have been executed as stated. * Resets the plan_executed counters for next check. * @return The plans_executed array contains the observed values after the method returns (for debugging). */ protected boolean checkPlans(int plan_a, int plan_b, int plan_c, int[] plans_executed) { plans_executed[0] = ((Integer)getBeliefbase().getBelief("plan_a_executed").getFact()).intValue(); plans_executed[1] = ((Integer)getBeliefbase().getBelief("plan_b_executed").getFact()).intValue(); plans_executed[2] = ((Integer)getBeliefbase().getBelief("plan_c_executed").getFact()).intValue(); boolean ret = plan_a==plans_executed[0] && plan_b==plans_executed[1] && plan_c==plans_executed[2]; getBeliefbase().getBelief("plan_a_executed").setFact(Integer.valueOf(0)); getBeliefbase().getBelief("plan_b_executed").setFact(Integer.valueOf(0)); getBeliefbase().getBelief("plan_c_executed").setFact(Integer.valueOf(0)); return ret; } }
/** * The plan body. */ public void body() { while(true) { int num = ((Integer)getBeliefbase().getBelief("num").getFact()).intValue(); getLogger().info(""+num); getBeliefbase().getBelief("num").setFact(Integer.valueOf(num-1)); waitFor(10); } } }
/** * The plan body. */ public void body() { Double cfp = (Double)getParameter("cfp").getValue(); Integer inv = (Integer)getBeliefbase().getBelief("acceptplan_invoked").getFact(); getBeliefbase().getBelief("acceptplan_invoked").setFact(Integer.valueOf(inv.intValue()+1)); getParameter("accept").setValue(Boolean.valueOf(cfp.doubleValue()>100)); } }
/** * The body method is called on the * instatiated plan instance from the scheduler. */ public void body() { this.belname = (String)getParameter("beliefname").getValue(); if(belname==null) throw new RuntimeException("Beliefname must not null."); this.value = getParameter("value").getValue(); System.out.println("Setting belief: "+belname+" to :"+value); // getLogger().info("Setting belief: "+belname+" to :"+value); getBeliefbase().getBelief(belname).setFact(value); } }
/** * The plan aborted code. */ public void aborted() { if(getBeliefbase().containsBelief("endmem")) { Long endmem = (Long) getBeliefbase().getBelief("endmem").getFact(); if(endmem==null) { endmem = Long.valueOf(Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory()); getBeliefbase().getBelief("endmem").setFact(endmem); } } // waitFor(300000); print("Aborted "+move, depth); // print("Aborted "+(isAbortedOnSuccess()? // "on success: ": "on failure: ")+move, depth); }
/** * Plan body. */ public void body() { // Set belief to true to trigger creation of goal. // Will be checked in worker plan. getBeliefbase().getBelief("trigger").setFact(Boolean.TRUE); waitFor(300); // Kill agent to start end state. killAgent(); } }
public void resultAvailable(Void result) { if(getone.isSucceeded()) { int money = ((Integer)getBeliefbase().getBelief("money").getFact()).intValue(); getBeliefbase().getBelief("money").setFact(Integer.valueOf(money+1)); System.out.println("Has money: "+getBeliefbase().getBelief("money").getFact()); } else { System.out.println("Get money goal failed: "+getone); // createOneEuroSubgoal(); } } });
/** * Called when something went wrong (e.g. timeout). */ public void failed() { getException().printStackTrace(); // Remove dealer fact. getBeliefbase().getBelief("dealer").setFact(null); // Reset state. Player me = (Player)getBeliefbase().getBelief("myself").getFact(); me.setState(Player.STATE_IDLE); } }
/** * The plan body. */ public void body() { waitFor(3000); getBeliefbase().getBelief("mycontext").setFact(Boolean.FALSE); if(getPlanbase().getPlans().length==1) { getLogger().info("Success. Plan has been removed."); } else { getLogger().info("Failure! Plan with invalid context still alive."); } killAgent(); } }
/** * The plan code. */ public void body() { String arg = (String)getBeliefbase().getBelief("arg").getFact(); getBeliefbase().getBelief("arg").setFact(arg+"--written"); killAgent(); } }
/** * The fail method is called on plan failure/abort. */ public void failed() { // getLogger().info("Plan failed: "+getName()+" reason: "+getException()); getLogger().info("Plan failed: "+this+" reason: "+getException()); int num = ((Integer)getBeliefbase().getBelief("cnt").getFact()).intValue(); getBeliefbase().getBelief("cnt").setFact(Integer.valueOf(num+1)); if(num!=3) { tr.setSucceeded(true); } else { tr.setReason("Plan should not call failed."); } getBeliefbase().getBeliefSet("testcap.reports").addFact(tr); }
/** * The body method. */ public void body() { TestReport tr = new TestReport("#1", "Testing waitForResult()."); Future<Object> listener = new Future<Object>(); getBeliefbase().getBelief("listener").setFact(listener); Object result = listener.get(); if("success".equals(result)) tr.setSucceeded(true); else tr.setFailed("Wrong result received: "+result); getBeliefbase().getBeliefSet("testcap.reports").addFact(tr); } }
@Classname("destroy") public IFuture<Void> execute(IInternalAccess ia) { IBDIXAgentFeature bia = ia.getComponentFeature(IBDIXAgentFeature.class); IComponentIdentifier dealer = (IComponentIdentifier)bia.getBeliefbase().getBelief("localDealerAID").getFact(); if(dealer!=null) { IComponentManagementService cms = ia.getComponentFeature(IRequiredServicesFeature.class) .searchService(IComponentManagementService.class, RequiredServiceInfo.SCOPE_PLATFORM).get(); cms.destroyComponent(dealer); bia.getBeliefbase().getBelief("localDealerAID").setFact(null); } return IFuture.DONE; } });