>xabsl | The Extensible Agent Behavior Specification Language |
start | team | language reference | tools | xabsl engine | download | licence | |
XabslEngine Class Library Reference | |
  | |
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members
XabslCoopState.hGo to the documentation of this file.00001 /** 00002 * @file XabslCoopState.h 00003 * 00004 * Definition of class CoopState and Helper classes 00005 * 00006 * @author <a href="http://www.sim.informatik.tu-darmstadt.de/pers/card/risler.html">Max Risler</a> 00007 */ 00008 00009 #ifndef __XabslCoopState_h_ 00010 #define __XabslCoopState_h_ 00011 00012 #include "XabslState.h" 00013 00014 namespace xabsl 00015 { 00016 00017 /** 00018 * @class CoopState 00019 * 00020 * Represents a state which has features to connect to other cooperating agents 00021 * 00022 * @author <a href="http://www.sim.informatik.tu-darmstadt.de/pers/card/risler.html">Max Risler</a> 00023 */ 00024 class CoopState : public State 00025 { 00026 public: 00027 /** 00028 * Constructor. Does not create the state. 00029 * @param name The name of the state. For debugging purposes. 00030 * @param errorHandler A reference to a ErrorHandler instance 00031 * @param time The system time in ms. 00032 * @param optionIndex Index of the corresponding option this state belongs to 00033 * @param index Index of the state in array states in corresponding option 00034 * @param agentPriority Priority value of the agent, used for solving conflicts in cooperative state assignment 00035 * @param synchronizationTicks Number of execution cycles that is required for synchonization with other agents, i.e time from sending a message until answer is received 00036 */ 00037 CoopState(const char* name, 00038 ErrorHandler& errorHandler, 00039 const unsigned& time, 00040 int optionIndex, 00041 int index, 00042 const int& agentPriority, 00043 const int& synchronizationTicks) : 00044 State(name, errorHandler, time, optionIndex, index), 00045 numberOfAgentsExecuting(0), 00046 numberOfAgentsEntering(0), 00047 numberOfAgentsInOption(0), 00048 highestPriorityOfAgentsEntering(0), 00049 entering(false), 00050 enterCount(0), 00051 agentPriority(agentPriority), 00052 synchronizationTicks(synchronizationTicks) 00053 {}; 00054 00055 /** Number of other agents currently executing this state, not including myself */ 00056 int numberOfAgentsExecuting; 00057 00058 /** Number of other agents currently trying to execute this state, but are blocked due to cooperating agents, not including myself */ 00059 int numberOfAgentsEntering; 00060 00061 /** Number of other agents currently executing the option corresponding to this state, not including myself */ 00062 int numberOfAgentsInOption; 00063 00064 /** Highest priority values of agents currently entering this state, not including myself */ 00065 int highestPriorityOfAgentsEntering; 00066 00067 /** Flag whether the agent is currently trying to execute this state, but is blocked due to cooperating agents */ 00068 bool entering; 00069 00070 /** Counter for number of cycles that the enter flag of this state is set */ 00071 int enterCount; 00072 00073 /** Priority value of the agent, used for solving conflicts in cooperative state assignment */ 00074 const int &agentPriority; 00075 00076 /** Number of execution cycles that is required for synchonization with other agents, i.e time from sending a message until answer is received */ 00077 const int &synchronizationTicks; 00078 00079 /** Prepare for processing incoming team messages. This resets previously processed messages. */ 00080 void prepareIncomingMessages() 00081 { 00082 numberOfAgentsExecuting = numberOfAgentsEntering = numberOfAgentsInOption = 0; 00083 if (entering) 00084 enterCount++; 00085 else 00086 enterCount = 0; 00087 entering = false; 00088 } 00089 00090 }; 00091 00092 /** 00093 * @class SynchronizedState 00094 * 00095 * Represents a state which can only be entered by all agents simultaneously 00096 * 00097 * @author <a href="http://www.sim.informatik.tu-darmstadt.de/pers/card/risler.html">Max Risler</a> 00098 */ 00099 class SynchronizedState : public CoopState 00100 { 00101 public: 00102 /** 00103 * Constructor. Does not create the state. 00104 * @param name The name of the state. For debugging purposes. 00105 * @param errorHandler A reference to a ErrorHandler instance 00106 * @param time The system time in ms. 00107 * @param optionIndex Index of the corresponding option this state belongs to 00108 * @param index Index of the state in array states in corresponding option 00109 * @param agentPriority Priority value of the agent, used for solving conflicts in cooperative state assignment 00110 * @param synchronizationTicks Number of execution cycles that is required for synchonization with other agents, i.e time from sending a message until answer is received 00111 */ 00112 SynchronizedState(const char* name, 00113 ErrorHandler& errorHandler, 00114 const unsigned& time, 00115 int optionIndex, 00116 int index, 00117 const int& agentPriority, 00118 const int& synchronizationTicks, 00119 int minAgents) : 00120 CoopState(name, errorHandler, time, optionIndex, index, agentPriority, synchronizationTicks), minAgents(minAgents) 00121 {}; 00122 00123 /** Minimum number of agents that have to enter the state at once */ 00124 int minAgents; 00125 00126 /** Check whether this state can be entered, or whether entering is blocked due to cooperating agents */ 00127 virtual bool coopCheck() 00128 { 00129 entering = true; 00130 return (numberOfAgentsInOption >= minAgents && 00131 numberOfAgentsExecuting + numberOfAgentsEntering == numberOfAgentsInOption && 00132 enterCount > synchronizationTicks / 2); 00133 } 00134 }; 00135 00136 /** 00137 * @class CapacityState 00138 * 00139 * Represents a state which can only be entered by at most the given number of agents simultaneously 00140 * 00141 * @author <a href="http://www.sim.informatik.tu-darmstadt.de/pers/card/risler.html">Max Risler</a> 00142 */ 00143 class CapacityState : public CoopState 00144 { 00145 public: 00146 /** 00147 * Constructor. Does not create the state. 00148 * @param name The name of the state. For debugging purposes. 00149 * @param errorHandler A reference to a ErrorHandler instance 00150 * @param time The system time in ms. 00151 * @param optionIndex Index of the corresponding option this state belongs to 00152 * @param index Index of the state in array states in corresponding option 00153 * @param agentPriority Priority value of the agent, used for solving conflicts in cooperative state assignment 00154 * @param synchronizationTicks Number of execution cycles that is required for synchonization with other agents, i.e time from sending a message until answer is received 00155 * @param capacity Number of agents that can enter the state simultaneously 00156 */ 00157 CapacityState(const char* name, 00158 ErrorHandler& errorHandler, 00159 const unsigned& time, 00160 int optionIndex, 00161 int index, 00162 const int& agentPriority, 00163 const int& synchronizationTicks, 00164 int capacity) : 00165 CoopState(name, errorHandler, time, optionIndex, index, agentPriority, synchronizationTicks), capacity(capacity), conflict(false) 00166 {}; 00167 00168 /** Number of agents that can enter the state simultaneously */ 00169 int capacity; 00170 00171 /** Whether this state is currently conflicted, i.e. there are more robots executing than the given capacity.*/ 00172 bool conflict; 00173 00174 /** Whether this state is currently conflicted, i.e. there are more robots executing than the given capacity.*/ 00175 virtual bool getConflict() 00176 { 00177 return conflict; 00178 } 00179 00180 /** 00181 * Executes the decision tree and determines the next active state (can be the same). 00182 */ 00183 virtual State* getNextState() 00184 { 00185 conflict = numberOfAgentsExecuting >= capacity; 00186 //if (conflict) 00187 //{ 00188 // errorHandler.message("xabsl::CapacityState::getNextState(): Conflict detected in capacity state \"%s\". Number of agents executing is %d while the capacity is %d. Number of synchronization ticks might need to be increased; current value is %d.",n,numberOfAgentsExecuting,capacity,synchronizationTicks); 00189 //} 00190 return CoopState::getNextState(); 00191 } 00192 00193 /** Check whether this state can be entered, or whether entering is blocked due to cooperating agents */ 00194 virtual bool coopCheck() 00195 { 00196 //if (numberOfAgentsInOption < capacity) 00197 //{ 00198 // // no potential conflict for state capacity => enter state 00199 // return true; 00200 //} 00201 //else 00202 if (numberOfAgentsExecuting >= capacity) 00203 { 00204 // state is currently busy 00205 entering = true; 00206 return false; 00207 } 00208 else if (numberOfAgentsExecuting + numberOfAgentsEntering >= capacity && highestPriorityOfAgentsEntering > agentPriority) 00209 { 00210 // state seems to have available capacity but other agents with higher priority want to enter it 00211 entering = true; 00212 return false; 00213 } 00214 else if (numberOfAgentsExecuting + numberOfAgentsEntering >= capacity && highestPriorityOfAgentsEntering == agentPriority) 00215 { 00216 // another agent wants to enter the state that has the same priority 00217 errorHandler.message("xabsl::CapacityState::coopCheck(): Conflict detected in capacity state \"%s\". Multiple agents with the same priority value %d are trying to execute the state.",n,agentPriority); 00218 // in order to resolve the conflict we do not set enter flag 00219 // if both agents remove their flag at the same time this situation might repeat indefinitely 00220 return false; 00221 } 00222 else if (enterCount < synchronizationTicks) 00223 { 00224 // state seems to have available capacity => set enter flag and wait specified tick count 00225 entering = true; 00226 return false; 00227 } 00228 else 00229 { 00230 // enter state only after enter count has reached specified count 00231 return true; 00232 } 00233 } 00234 }; 00235 00236 } // namespace 00237 00238 #endif //__XabslCoopState_h_ Up | Main Page | Generated at Wed Aug 19 17:32:28 2009.
|
|
Copyright 2002 - 2009 by the XABSL developer team. See the licence for details. | |