本文整理汇总了Java中jason.asSemantics.ActionExec类的典型用法代码示例。如果您正苦于以下问题:Java ActionExec类的具体用法?Java ActionExec怎么用?Java ActionExec使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ActionExec类属于jason.asSemantics包,在下文中一共展示了ActionExec类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: act
import jason.asSemantics.ActionExec; //导入依赖的package包/类
@Override
public void act(ActionExec action) { //, List<ActionExec> feedback) {
if (!isRunning()) return;
if (getEnvironmentAg() == null) return;
try {
Term acTerm = action.getActionTerm();
logger.fine("doing: " + acTerm);
String rw = "id"+jadeAg.incReplyWithId();
ACLMessage m = new ACLMessage(ACLMessage.REQUEST);
m.addReceiver(environmentAID);
m.setOntology(JadeEnvironment.actionOntology);
m.setContent(acTerm.toString());
m.setReplyWith(rw);
myPA.put(rw, action);
jadeAg.send(m);
} catch (Exception e) {
logger.log(Level.SEVERE, "Error sending action " + action, e);
}
}
示例2: isActionFeedback
import jason.asSemantics.ActionExec; //导入依赖的package包/类
boolean isActionFeedback(ACLMessage m) {
// check if there are feedbacks on requested action executions
if (m.getOntology() != null && m.getOntology().equals(JadeEnvironment.actionOntology)) {
String irt = m.getInReplyTo();
if (irt != null) {
ActionExec a = myPA.remove(irt);
// was it a pending action?
if (a != null) {
if (m.getContent().equals("ok")) {
a.setResult(true);
} else {
a.setResult(false);
}
actionExecuted(a);
} else {
logger.log(Level.SEVERE, "Error: received feedback for an Action that is not pending. The message is "+m);
}
}
return true;
}
return false;
}
示例3: execute
import jason.asSemantics.ActionExec; //导入依赖的package包/类
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
checkArguments(args);
Circumstance C = ts.getC();
Trigger teGoal = new Trigger(TEOperator.add, TEType.achieve, (Literal)args[0]);
// search in PA
for (ActionExec a: C.getPendingActions().values())
if (a.getIntention().hasTrigger(teGoal, un))
return un.unifies(args[1], aAct);
// search in PI
Map<String, Intention> pi = C.getPendingIntentions();
for (String reason: pi.keySet())
if (pi.get(reason).hasTrigger(teGoal, un))
return un.unifies(args[1], new StringTermImpl(reason));
return false;
}
示例4: addActionInSchedule
import jason.asSemantics.ActionExec; //导入依赖的package包/类
/** this method is called by the agents to request some action performance */
public void addActionInSchedule(final LocalMinerArch ag, final ActionExec act) {
synchronized (finished) {
if (finished[getAgNbFromName(ag.getAgName())] != null) { // the agent already did an action in this cycle
logger.warning("** Agent "+ag.getAgName()+" is trying two action is the same cycle! This action was ignored.");
} else {
executor.execute(new Runnable() {
public void run() {
Structure acTerm = act.getActionTerm();
if (executeAction(ag.getAgName(), acTerm)) {
act.setResult(true);
} else {
act.setResult(false);
}
addExecutedAction(new ActRequest(ag,act));
};
});
}
}
}
示例5: notifyActionSuccess
import jason.asSemantics.ActionExec; //导入依赖的package包/类
protected void notifyActionSuccess(Op op, Structure action, ActionExec actionExec) {
Object[] values = op.getParamValues();
for (int i = 0; i < action.getArity(); i++) {
if (action.getTerm(i).isVar()) { // isVar means is a variable AND is not bound (see Jason impl)
try {
boolean bound = bind(values[i], action.getTerm(i), actionExec);
if (!bound) {
// env.logger.severe("INTERNAL ERROR: binding failed "+values[i]+" "+action.getTerm(i));
actionExec.setResult(false);
Literal reason = ASSyntax.createLiteral("bind_param_error", action.getTerm(i), ASSyntax.createString(values[i]));
actionExec.setFailureReason(reason, "Error binding parameters: " + action.getTerm(i) + " with " + values[i]);
super.actionExecuted(actionExec);
return;
}
} catch (Exception ex) {
ex.printStackTrace();
return;
}
}
}
actionExec.setResult(true);
super.actionExecuted(actionExec);
}
示例6: act
import jason.asSemantics.ActionExec; //导入依赖的package包/类
@Override
public void act(ActionExec action) {
if (!isRunning()) return;
if (getEnvironmentAg() == null) return;
try {
Term acTerm = action.getActionTerm();
logger.fine("doing: " + acTerm);
String rw = "id"+jadeAg.incReplyWithId();
ACLMessage m = new ACLMessage(ACLMessage.REQUEST);
m.addReceiver(environmentAID);
m.setOntology(JadeEnvironment.actionOntology);
m.setContent(acTerm.toString());
m.setReplyWith(rw);
myPA.put(rw, action);
jadeAg.send(m);
} catch (Exception e) {
logger.log(Level.SEVERE, "Error sending action " + action, e);
}
}
示例7: isActionFeedback
import jason.asSemantics.ActionExec; //导入依赖的package包/类
boolean isActionFeedback(ACLMessage m) {
// check if there are feedbacks on requested action executions
if (m.getOntology() != null && m.getOntology().equals(JadeEnvironment.actionOntology)) {
String irt = m.getInReplyTo();
if (irt != null) {
ActionExec a = myPA.remove(irt);
// was it a pending action?
if (a != null) {
a.setResult(m.getContent().equals("ok"));
actionExecuted(a);
} else {
logger.log(Level.SEVERE, "Error: received feedback for an Action that is not pending. The message is "+m);
}
}
return true;
}
return false;
}
示例8: act
import jason.asSemantics.ActionExec; //导入依赖的package包/类
@Override
public void act(ActionExec action, List<ActionExec> feedback) {
final Structure term = action.getActionTerm();
switch (term.getFunctor()) {
case "printList":
final String nodeName = System.getProperty("jboss.node.name");
logger.info(getAgent().getAid().getName() + " hosted by " + nodeName + " says: " + term.getTerm(0));
try {
Thread.sleep((int) (Math.random() * 1000) + 500);
} catch (InterruptedException ex) {
}
action.setResult(true);
break;
default:
action.setResult(false);
action.setFailureReason(Literal.parseLiteral("unknownAction"), "Unknown action.");
break;
}
feedback.add(action);
}
示例9: actionExecuted
import jason.asSemantics.ActionExec; //导入依赖的package包/类
public void actionExecuted(String agName, Structure actTerm, boolean success, Object infraData) {
ActionExec action = (ActionExec)infraData;
action.setResult(success);
CentralisedAgArch ag = masRunner.getAg(agName);
if (ag != null) // the agent may was killed
ag.actionExecuted(action);
}
示例10: act
import jason.asSemantics.ActionExec; //导入依赖的package包/类
/** called by the TS to ask the execution of an action in the environment */
@Override
public void act(ActionExec action) {
//if (logger.isLoggable(Level.FINE)) logger.fine("doing: " + action.getActionTerm());
super.act(action);
if (isRunning() && infraEnv != null)
infraEnv.act(getAgName(), action);
}
示例11: startNextStep
import jason.asSemantics.ActionExec; //导入依赖的package包/类
public void startNextStep(int step, List<Literal> p) {
perceptions = p;
List<ActionExec> feedback = getTS().getC().getFeedbackActions();
while (!toExecute.isEmpty()) {
ActionExec action = toExecute.poll();
action.setResult(true);
feedback.add(action);
}
getTS().newMessageHasArrived();
setCycle(step);
}
示例12: act
import jason.asSemantics.ActionExec; //导入依赖的package包/类
synchronized public void act(ActionExec action, List<ActionExec> feedback) {
if (isRunning()) {
if (waitingExecution) {
toExecute.add(action);
} else {
waitingExecution = true;
//getTS().getAg().getLogger().info("doing: " + action.getActionTerm());
CentralisedEnvironment jEnv = RunCentralisedMAS.getRunner().getEnvironmentInfraTier();
if (jEnv != null) {
MiningEnvironment env = (MiningEnvironment)jEnv.getUserEnvironment();
env.addActionInSchedule(this, action);
}
}
}
}
示例13: actFinished
import jason.asSemantics.ActionExec; //导入依赖的package包/类
synchronized public void actFinished(ActionExec action) {
List<ActionExec> feedback = getTS().getC().getFeedbackActions();
feedback.add(action);
waitingExecution = false;
// if there is an action waiting for execution
if (!toExecute.isEmpty()) {
action = toExecute.poll();
// if the action is for an intention already dropped (it is not in PA anymore), ignore it
if (getTS().getC().getPendingActions().containsKey(action.getIntention().getId())) {
act(action, feedback);
}
}
getTS().newMessageHasArrived(); // in case the agent is sleeping...
}
示例14: addAction
import jason.asSemantics.ActionExec; //导入依赖的package包/类
void addAction(ActionExec action) {
if (action == null) return;
logger.info("adding action "+action.getActionTerm()+" to be executed.");
lock.lock();
try {
if (lastAction != null)
toExecute.offer(lastAction);
lastAction = action;
} finally {
lock.unlock();
}
}
示例15: addAction
import jason.asSemantics.ActionExec; //导入依赖的package包/类
void addAction(ActionExec action) {
if (action == null) return;
logger.info("adding action "+action.getActionTerm()+" to be executed.");
lock.lock();
try {
if (lastAction != null)
toExecute.offer(lastAction);
lastAction = action;
} finally {
lock.unlock();
}
}