/** * stop execution - returning the given assignment, will cause a TERMINATION message to be sent to * all other agents, if ans is null there is no solution * * @param ans */ protected void finish(Assignment ans) { if (ans == null) { controller.reportNoSolution(); } else { controller.assignAll(ans); } terminate(); }
/** * if this method return null the message is rejected and should be dumped. * * @param currentMessage * @return */ public final Message setCurrentMessage(Message currentMessage) { this.currentMessage = currentMessage; if (!controller.isControlling(currentMessage.getSender()) && !SYS_TERMINATION_MESSAGE.equals(currentMessage.getName())) { messageCount[controller.pid()]++; } return beforeMessageProcessing(currentMessage); }
public final ContinuationMediator exec(Agent agent, String contextId) { try { return controller.nest(agent, contextId); } catch (ClassNotFoundException ex) { throw new RuntimeException(ex); } }
/** * @return the last submitted assignment will throw InvalideValueException if no assignment was * submitted */ protected Integer getAssignment() { Integer assignment = controller.getAssignment(id); if (assignment != null) { return assignment; } throw new InvalidValueException( "Agent called 'getSubmitedCurrentAssignment' before he ever called 'submitCurrentAssignment'"); }
/** * Note: the concept 'system time' only exists in synchronized execution * * @return the number of ticks passed since the algorithm start (first tick is 0), you can read * about the definition of tick in agent zero manual */ public long getSystemTimeInTicks() { return controller.getTickNumber(); }
/** remove the submitted current assignment */ protected void unassign() { controller.unassign(id); }
/** * the agent can submit its assignment so that when the algorithm is finish running (happened when * all agents call finish) this will be the assignment to be accumulated - if you want to * re-assign a new value you don't have to call unSubmitCurrentAssignment, you can just call this * function again with the new value * * @param currentAssignment the assignment to submit */ protected void assign(int currentAssignment) { controller.assign(getId(), currentAssignment); }
/** * log something inside this agent log * * @param what */ protected void log(String what) { controller.log(id, what); }