Ejemplo n.º 1
0
 /**
  * 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();
 }
Ejemplo n.º 2
0
 /**
  * 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);
 }
Ejemplo n.º 3
0
 public final ContinuationMediator exec(Agent agent, String contextId) {
   try {
     return controller.nest(agent, contextId);
   } catch (ClassNotFoundException ex) {
     throw new RuntimeException(ex);
   }
 }
Ejemplo n.º 4
0
  /**
   * @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'");
  }
Ejemplo n.º 5
0
 /**
  * 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();
 }
Ejemplo n.º 6
0
 /** remove the submitted current assignment */
 protected void unassign() {
   controller.unassign(id);
 }
Ejemplo n.º 7
0
 /**
  * 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);
 }
Ejemplo n.º 8
0
 /**
  * log something inside this agent log
  *
  * @param what
  */
 protected void log(String what) {
   controller.log(id, what);
 }