Changeset 950
- Timestamp:
- 02/12/2011 05:24:08 PM (10 years ago)
- Location:
- AgentMind/branches/FAtiMA-Modular
- Files:
-
- 26 edited
Legend:
- Unmodified
- Added
- Removed
-
AgentMind/branches/FAtiMA-Modular/FAtiMA.AdvancedMemory/src/main/java/FAtiMA/advancedMemoryComponent/ActionsLoaderHandler.java
r889 r950 59 59 { 60 60 _sac = SACondition.ParseSA(attributes); 61 operator = _am.getDeliberativeLayer().getEmotionalPlanner().GetStep(_operatorKey); 61 operator = 62 63 _am.getActionLibrary().getAction(_operatorKey); 62 64 63 65 _sac.MakeGround(_self); -
AgentMind/branches/FAtiMA-Modular/FAtiMA.AdvancedMemory/src/main/java/FAtiMA/advancedMemoryComponent/AdvancedMemoryComponent.java
r929 r950 45 45 import FAtiMA.Core.componentTypes.IAppraisalDerivationComponent; 46 46 import FAtiMA.Core.componentTypes.IProcessExternalRequestComponent; 47 import FAtiMA.Core.componentTypes.IAppraisalDerivationComponent; 48 import FAtiMA.Core.componentTypes.IProcessExternalRequestComponent; 47 49 import FAtiMA.Core.emotionalState.AppraisalFrame; 48 50 import FAtiMA.Core.memory.Memory; -
AgentMind/branches/FAtiMA-Modular/FAtiMA.EmotionalIntelligence/src/FAtiMA/emotionalIntelligence/EmotionalConditionsLoaderHandler.java
r805 r950 35 35 ee = EmotionalEpisodeCondition.ParseEmotionalEpisodeCondition(attributes); 36 36 ee.MakeGround(_self); 37 g = _aM.get DeliberativeLayer().getGoalLibrary().GetGoal(Name.ParseName(_currentGoalKey));37 g = _aM.getGoalLibrary().GetGoal(Name.ParseName(_currentGoalKey)); 38 38 g.AddCondition(_conditionType, ee); 39 39 } -
AgentMind/branches/FAtiMA-Modular/FAtiMA.EmotionalIntelligence/src/FAtiMA/emotionalIntelligence/EmotionalIntelligence.java
r929 r950 10 10 import FAtiMA.Core.Display.AgentDisplayPanel; 11 11 import FAtiMA.Core.componentTypes.IComponent; 12 import FAtiMA.Core.deliberativeLayer.EmotionalPlanner;13 12 import FAtiMA.Core.deliberativeLayer.plan.Step; 14 13 import FAtiMA.Core.reactiveLayer.Action; … … 35 34 @Override 36 35 public void initialize(AgentModel am) { 37 38 EmotionalPlanner planner = am.getDeliberativeLayer().getEmotionalPlanner(); 39 36 40 37 ArrayList<Step> occRules = OCCAppraisalRules.GenerateOCCAppraisalRules(am); 41 38 for(Step s : occRules) 42 39 { 43 planner.AddOperator(s);40 am.getActionLibrary().addAction(s); 44 41 } 45 42 46 43 for(Action at: am.getReactiveLayer().getActionTendencies().getActions()) 47 44 { 48 planner.AddOperator(ActionTendencyOperatorFactory.CreateATOperator(am, at));45 am.getActionLibrary().addAction(ActionTendencyOperatorFactory.CreateATOperator(am, at)); 49 46 } 50 47 -
AgentMind/branches/FAtiMA-Modular/FAtiMA.MotivationalSystem/src/FAtiMA/motivationalSystem/ActionEffectsOnDrives.java
r772 r950 8 8 9 9 public class ActionEffectsOnDrives implements Serializable{ 10 11 /** 12 * 13 */ 14 private static final long serialVersionUID = 1L; 15 10 16 11 17 private Name _actionName; -
AgentMind/branches/FAtiMA-Modular/FAtiMA.MotivationalSystem/src/FAtiMA/motivationalSystem/MotivationalComponent.java
r929 r950 21 21 import FAtiMA.Core.componentTypes.IComponent; 22 22 import FAtiMA.Core.componentTypes.IModelOfOtherComponent; 23 import FAtiMA.Core.deliberativeLayer.DeliberativeProcess; 23 24 import FAtiMA.Core.deliberativeLayer.IActionFailureStrategy; 24 25 import FAtiMA.Core.deliberativeLayer.IExpectedUtilityStrategy; … … 271 272 272 273 public float getExpectedUtility(AgentModel am, ActivePursuitGoal g) 273 { 274 float utility = am.getDeliberativeLayer().getUtilityStrategy().getUtility(am, g); 275 float probability = am.getDeliberativeLayer().getProbabilityStrategy().getProbability(am, g); 274 { 275 DeliberativeProcess dp = (DeliberativeProcess) am.getComponent(DeliberativeProcess.NAME); 276 float utility = dp.getUtilityStrategy().getUtility(am, g); 277 float probability = dp.getProbabilityStrategy().getProbability(am, g); 276 278 277 279 float EU = utility * probability * (1 + g.GetGoalUrgency()); … … 284 286 public float getExpectedUtility(AgentModel am, Intention i) 285 287 { 286 float utility = am.getDeliberativeLayer().getUtilityStrategy().getUtility(am, i.getGoal()); 287 float probability = am.getDeliberativeLayer().getProbabilityStrategy().getProbability(am, i); 288 DeliberativeProcess dp = (DeliberativeProcess) am.getComponent(DeliberativeProcess.NAME); 289 290 float utility = dp.getUtilityStrategy().getUtility(am, i.getGoal()); 291 float probability = dp.getProbabilityStrategy().getProbability(am, i); 288 292 289 293 float EU = utility * probability * (1 + i.getGoal().GetGoalUrgency()); … … 460 464 @Override 461 465 public void initialize(AgentModel am) { 462 am.getDeliberativeLayer().setExpectedUtilityStrategy(this); 463 am.getDeliberativeLayer().setProbabilityStrategy(this); 464 am.getDeliberativeLayer().setUtilityStrategy(this); 465 am.getDeliberativeLayer().addActionFailureStrategy(this); 466 am.getDeliberativeLayer().addGoalFailureStrategy(this); 467 am.getDeliberativeLayer().addGoalSuccessStrategy(this); 466 DeliberativeProcess dp = (DeliberativeProcess) am.getComponent(DeliberativeProcess.NAME); 467 468 dp.setExpectedUtilityStrategy(this); 469 dp.setProbabilityStrategy(this); 470 dp.setUtilityStrategy(this); 471 dp.addActionFailureStrategy(this); 472 dp.addGoalFailureStrategy(this); 473 dp.addGoalSuccessStrategy(this); 468 474 LoadNeeds(am); 469 475 } -
AgentMind/branches/FAtiMA-Modular/FAtiMA.SocialRelations/src/FAtiMA/socialRelations/RelationsLoaderHandler.java
r801 r950 62 62 lc = LikeCondition.ParseSocialCondition(attributes); 63 63 lc.MakeGround(_self); 64 g = _aM.get DeliberativeLayer().getGoalLibrary().GetGoal(Name.ParseName(_currentGoalKey));64 g = _aM.getGoalLibrary().GetGoal(Name.ParseName(_currentGoalKey)); 65 65 g.AddCondition(_conditionType, lc); 66 66 } … … 78 78 l.MakeGround(_self); 79 79 80 Step action = _aM.get DeliberativeLayer().getEmotionalPlanner().GetStep(_currentActionKey);80 Step action = _aM.getActionLibrary().getAction(_currentActionKey); 81 81 if(_precondition) 82 82 action.AddPrecondition(l); -
AgentMind/branches/FAtiMA-Modular/FAtiMA.ToM/src/FAtiMA/ToM/ModelOfOther.java
r929 r950 6 6 import java.util.HashMap; 7 7 8 import FAtiMA.Core.ActionLibrary; 8 9 import FAtiMA.Core.AgentCore; 9 10 import FAtiMA.Core.AgentModel; … … 14 15 import FAtiMA.Core.componentTypes.IProcessEmotionComponent; 15 16 import FAtiMA.Core.deliberativeLayer.DeliberativeProcess; 17 import FAtiMA.Core.deliberativeLayer.goals.GoalLibrary; 16 18 import FAtiMA.Core.emotionalState.ActiveEmotion; 17 19 import FAtiMA.Core.emotionalState.AppraisalFrame; … … 190 192 return _components.values(); 191 193 } 192 193 @Override 194 public DeliberativeProcess getDeliberativeLayer() { 195 return _deliberativeProcess; 194 195 public GoalLibrary getGoalLibrary() 196 { 197 return null; 198 } 199 200 public ActionLibrary getActionLibrary() 201 { 202 return null; 196 203 } 197 204 -
AgentMind/branches/FAtiMA-Modular/FAtiMA.ToM/src/FAtiMA/ToM/ToMComponent.java
r929 r950 14 14 import FAtiMA.Core.componentTypes.IComponent; 15 15 import FAtiMA.Core.componentTypes.IModelOfOtherComponent; 16 import FAtiMA.Core.deliberativeLayer.DeliberativeProcess; 16 17 import FAtiMA.Core.deliberativeLayer.IGetUtilityForOthers; 17 18 import FAtiMA.Core.deliberativeLayer.goals.ActivePursuitGoal; … … 70 71 @Override 71 72 public void initialize(AgentModel am) { 73 DeliberativeProcess dp = (DeliberativeProcess) am.getComponent(DeliberativeProcess.NAME); 72 74 am.setModelStrategy(this); 73 am.getDeliberativeLayer().setDetectThreatStrategy(new DetectThreatStrategy());74 am.getDeliberativeLayer().setUtilityForOthersStrategy(this);75 dp.setDetectThreatStrategy(new DetectThreatStrategy()); 76 dp.setUtilityForOthersStrategy(this); 75 77 } 76 78 … … 242 244 @Override 243 245 public float getUtilityForOthers(AgentModel am, ActivePursuitGoal g) { 246 DeliberativeProcess dp = (DeliberativeProcess) am.getComponent(DeliberativeProcess.NAME); 244 247 245 248 float utility = 0; … … 247 250 for(ModelOfOther m : _ToM.values()) 248 251 { 249 utility+= m.getDeliberativeLayer().getUtilityStrategy().getUtility(m, g);252 utility+= dp.getUtilityStrategy().getUtility(m, g); 250 253 } 251 254 -
AgentMind/branches/FAtiMA-Modular/FAtiMA.culture/src/FAtiMA/culture/CulturalDimensionsComponent.java
r937 r950 15 15 import FAtiMA.Core.componentTypes.IAppraisalDerivationComponent; 16 16 import FAtiMA.Core.conditions.Condition; 17 import FAtiMA.Core.deliberativeLayer.DeliberativeProcess; 17 18 import FAtiMA.Core.deliberativeLayer.IExpectedUtilityStrategy; 18 19 import FAtiMA.Core.deliberativeLayer.IGetUtilityForOthers; … … 57 58 @Override 58 59 public void initialize(AgentModel aM){ 60 DeliberativeProcess dp = (DeliberativeProcess) aM.getComponent(DeliberativeProcess.NAME); 59 61 this.loadCulture(aM); 60 aM.getDeliberativeLayer().AddOptionsStrategy(this);61 aM.getDeliberativeLayer().setExpectedUtilityStrategy(this);62 dp.addOptionsStrategy(this); 63 dp.setExpectedUtilityStrategy(this); 62 64 aM.getRemoteAgent().setProcessActionStrategy(new CultureProcessActionStrategy()); 63 65 } … … 111 113 Ritual r2, r3; 112 114 String ritualName; 115 DeliberativeProcess dp = (DeliberativeProcess) am.getComponent(DeliberativeProcess.NAME); 113 116 114 117 //this section detects if a ritual has started with another agent's action … … 138 141 ritualName = r3.getNameWithCharactersOrdered(); 139 142 r3.setUrgency(2); 140 if(!_ritualOptions.containsKey(ritualName) && ! am.getDeliberativeLayer().ContainsIntention(r3))143 if(!_ritualOptions.containsKey(ritualName) && !dp.containsIntention(r3)) 141 144 { 142 145 AgentLogger.GetInstance().logAndPrint("Reactive Activation of a Ritual:" + r3.getName()); … … 159 162 160 163 private void loadCulture(AgentModel aM){ 164 165 DeliberativeProcess dp = (DeliberativeProcess) aM.getComponent(DeliberativeProcess.NAME); 161 166 162 167 AgentLogger.GetInstance().log("LOADING Culture: " + this.cultureFile); … … 171 176 for(Ritual r : cultureLoader.GetRituals(aM)){ 172 177 this._rituals.add(r); 173 aM.getDeliberativeLayer().AddGoal(r);178 dp.addGoal(r); 174 179 } 175 180 … … 276 281 public Collection<? extends ActivePursuitGoal> options(AgentModel am) { 277 282 283 DeliberativeProcess dp = (DeliberativeProcess) am.getComponent(DeliberativeProcess.NAME); 284 278 285 Iterator<Ritual> it = _ritualOptions.values().iterator(); 279 286 Ritual r; … … 282 289 { 283 290 r = it.next(); 284 if( am.getDeliberativeLayer().ContainsIntention(r))291 if(dp.containsIntention(r)) 285 292 { 286 293 it.remove(); … … 294 301 private float culturalEU(AgentModel am, ActivePursuitGoal g, float probability) 295 302 { 296 IUtilityStrategy str = am.getDeliberativeLayer().getUtilityStrategy(); 303 DeliberativeProcess dp = (DeliberativeProcess) am.getComponent(DeliberativeProcess.NAME); 304 305 IUtilityStrategy str = dp.getUtilityStrategy(); 297 306 298 307 float contributionToSelf = str.getUtility(am, g); 299 308 300 IGetUtilityForOthers ostrat = am.getDeliberativeLayer().getUtilityForOthersStrategy();309 IGetUtilityForOthers ostrat = dp.getUtilityForOthersStrategy(); 301 310 302 311 float contributionOthers = ostrat.getUtilityForOthers(am, g); … … 314 323 @Override 315 324 public float getExpectedUtility(AgentModel am, ActivePursuitGoal g) { 316 317 float probability = am.getDeliberativeLayer().getProbabilityStrategy().getProbability(am, g); 325 DeliberativeProcess dp = (DeliberativeProcess) am.getComponent(DeliberativeProcess.NAME); 326 327 float probability = dp.getProbabilityStrategy().getProbability(am, g); 318 328 return culturalEU(am,g,probability); 319 329 } … … 322 332 public float getExpectedUtility(AgentModel am, Intention i) { 323 333 324 float probability = am.getDeliberativeLayer().getProbabilityStrategy().getProbability(am, i); 334 DeliberativeProcess dp = (DeliberativeProcess) am.getComponent(DeliberativeProcess.NAME); 335 336 float probability = dp.getProbabilityStrategy().getProbability(am, i); 325 337 326 338 return culturalEU(am,i.getGoal(),probability); -
AgentMind/branches/FAtiMA-Modular/FAtiMA.culture/src/FAtiMA/culture/CultureLoaderHandler.java
r878 r950 79 79 _rituals = new ArrayList<Ritual>(); 80 80 _self = new Substitution(new Symbol("[SELF]"), new Symbol(FAtiMA.Core.util.Constants.SELF)); 81 _reactiveLayer = aM.getReactiveLayer();82 _deliberativeLayer = aM.getDeliberativeLayer();81 _reactiveLayer = (ReactiveProcess) aM.getComponent(ReactiveProcess.NAME); 82 _deliberativeLayer = (DeliberativeProcess) aM.getComponent(DeliberativeProcess.NAME); 83 83 _am = aM; 84 84 _culturalComponent = cDM; … … 172 172 if(_beforeRituals){ 173 173 String goalName = attributes.getValue("name"); 174 _deliberativeLayer.AddGoal(_am, goalName);174 _deliberativeLayer.addGoal(_am, goalName); 175 175 } 176 176 } … … 216 216 stepName = Name.ParseName(attributes.getValue("name")); 217 217 role = new Symbol(attributes.getValue("role")); 218 _ritual.AddStep( stepName, role);218 _ritual.AddStep(_am, stepName, role); 219 219 } 220 220 … … 266 266 _ritual.AddCondition(_conditionType, cond); 267 267 }else if (_currentGoalKey != null){ 268 Goal g = _ deliberativeLayer.getGoalLibrary().GetGoal(Name.ParseName(_currentGoalKey));268 Goal g = _am.getGoalLibrary().GetGoal(Name.ParseName(_currentGoalKey)); 269 269 g.AddCondition(_conditionType, cond); 270 270 } -
AgentMind/branches/FAtiMA-Modular/FAtiMA.culture/src/FAtiMA/culture/Ritual.java
r733 r950 36 36 import java.util.ListIterator; 37 37 38 import FAtiMA.Core.ActionLibrary;39 38 import FAtiMA.Core.AgentModel; 40 39 import FAtiMA.Core.conditions.Condition; 40 import FAtiMA.Core.deliberativeLayer.DeliberativeProcess; 41 41 import FAtiMA.Core.deliberativeLayer.goals.ActivePursuitGoal; 42 42 import FAtiMA.Core.deliberativeLayer.plan.CausalLink; … … 84 84 } 85 85 86 public void AddStep( Name actionName, Name role)86 public void AddStep(AgentModel am, Name actionName, Name role) 87 87 { 88 88 ArrayList<Substitution> subst; 89 Step action = ActionLibrary.GetInstance().GetAction(_steps.size(), actionName);89 Step action = am.getActionLibrary().getAction(_steps.size(), actionName); 90 90 if(action != null) 91 91 { … … 164 164 public void BuildPlan(AgentModel am) 165 165 { 166 DeliberativeProcess dp = (DeliberativeProcess) am.getComponent(DeliberativeProcess.NAME); 167 166 168 Step s; 167 169 OrderingConstraint o; 168 _plan = new Plan(new ArrayList<ProtectedCondition>(), am.getDeliberativeLayer().getDetectThreatStrategy(),_successConditions);170 _plan = new Plan(new ArrayList<ProtectedCondition>(),dp.getDetectThreatStrategy(),_successConditions); 169 171 170 172 for(int i=0; i < _steps.size(); i++) -
AgentMind/branches/FAtiMA-Modular/FAtiMA/src/FAtiMA/Core/ActionLibrary.java
r667 r950 31 31 32 32 import java.io.File; 33 import java.io.FileInputStream;34 import java.io.FileOutputStream;35 import java.io.ObjectInputStream;36 import java.io.ObjectOutputStream;37 33 import java.io.Serializable; 38 34 import java.util.ArrayList; … … 44 40 import FAtiMA.Core.deliberativeLayer.plan.Step; 45 41 import FAtiMA.Core.exceptions.ActionsParsingException; 42 import FAtiMA.Core.exceptions.UnknownSpeechActException; 43 import FAtiMA.Core.exceptions.UnspecifiedVariableException; 46 44 import FAtiMA.Core.util.AgentLogger; 47 45 import FAtiMA.Core.util.parsers.ActionsLoaderHandler; … … 53 51 * @author João Dias 54 52 * Class that stores the STRIPS definition of the domain actions 55 * You cannot create an ActionLibrary since there is one and only instance56 * for the agent. If you want to access it use AgentLibrary.GetInstance() method.57 53 */ 58 54 public class ActionLibrary implements Serializable { 59 55 60 private static final long serialVersionUID = 1L; 56 private static final long serialVersionUID = 1L; 61 57 62 /** 63 * Singleton pattern 64 */ 65 private static ActionLibrary _actionLibraryInstance = null; 58 private ArrayList<Step> _actions; 66 59 67 /** 68 * Gets a the library with all actions specified in a STRIPS-like fashion 69 * 70 * @return an ActionLibrary 71 */ 72 public static ActionLibrary GetInstance() 60 61 public ActionLibrary() 73 62 { 74 if(_actionLibraryInstance == null) 75 { 76 _actionLibraryInstance = new ActionLibrary(); 77 } 78 return _actionLibraryInstance; 63 _actions = new ArrayList<Step>(); 64 } 65 66 public void addAction(Step action) 67 { 68 _actions.add(action); 79 69 } 80 70 81 71 /** 82 * Saves the state of the current ActionLibrary to a file, 83 * so that it can be later restored from file 84 * @param fileName - the name of the file where we must write 85 * the state of the timer 72 * Checks the integrity of the Planner operators/Steps/actions. 73 * For instance it checks if a operator references a SpeechAct not 74 * defined, or if it uses a unbound variable (in effects or preconditions) 75 * not used in the operator's name 76 * @param val - the IntegrityValidator used to detect problems 77 * @throws UnspecifiedVariableException - thrown when the operator uses a unbound 78 * variable in the effects or preconditions 79 * without using the same variable in the 80 * step's name 81 * @throws UnknownSpeechActException - thrown when the operator references a 82 * SpeechAct not defined 86 83 */ 87 public static void SaveState(String fileName) 84 public void checkIntegrity(IntegrityValidator val) throws UnspecifiedVariableException, UnknownSpeechActException { 85 ListIterator<Step> li = _actions.listIterator(); 86 87 while(li.hasNext()) { 88 li.next().CheckIntegrity(val); 89 } 90 } 91 92 public Step getAction(int id, Name actionName) 88 93 { 89 try 94 Step s; 95 ArrayList<Substitution> subst; 96 97 for(ListIterator<Step> li = _actions.listIterator(); li.hasNext();) 90 98 { 91 FileOutputStream out = new FileOutputStream(fileName); 92 ObjectOutputStream s = new ObjectOutputStream(out); 93 94 s.writeObject(_actionLibraryInstance); 95 s.flush(); 96 s.close(); 97 out.close(); 99 s = (Step) li.next(); 100 s = (Step)s.clone(); 101 s.ReplaceUnboundVariables(id); 102 103 subst = Unifier.Unify(s.getName(), actionName); 104 if(subst != null) 105 { 106 s = (Step) s.clone(); 107 s.MakeGround(subst); 108 return s; 109 } 98 110 } 99 catch(Exception e) 100 { 101 AgentLogger.GetInstance().logAndPrint("Exception: " + e); 102 e.printStackTrace(); 103 } 111 112 return null; 104 113 } 105 114 106 115 /** 107 * Loads a specific state of the ActionLibrary from a previously 108 * saved file 109 * @param fileName - the name of the file that contains the stored 110 * timer 116 * Gets the operator that corresponds to the given name 117 * @param name - the name of the step to get 118 * @return the searched step if it is found, null otherwise 111 119 */ 112 public static void LoadState(String fileName) 120 public Step getAction(String name) { 121 122 for(Step s : _actions) 123 { 124 if(s.getName().toString().equals(name)) 125 { 126 return s; 127 } 128 } 129 130 return null; 131 } 132 133 public ArrayList<Step> getActions() 113 134 { 114 try 115 { 116 FileInputStream in = new FileInputStream(fileName); 117 ObjectInputStream s = new ObjectInputStream(in); 118 _actionLibraryInstance = (ActionLibrary) s.readObject(); 119 120 s.close(); 121 in.close(); 122 } 123 catch (Exception e) 124 { 125 e.printStackTrace(); 126 } 127 } 128 129 private ArrayList<Step> _actions; 130 131 /** 132 * Creates a new timer for the Agent's simulation 133 * 134 */ 135 private ActionLibrary() 136 { 137 _actions = new ArrayList<Step>(); 135 return _actions; 138 136 } 139 137 … … 159 157 } 160 158 } 161 162 public ArrayList<Step> GetActions()163 {164 return _actions;165 }166 167 public Step GetAction(int id, Name actionName)168 {169 Step s;170 ArrayList<Substitution> subst;171 172 for(ListIterator<Step> li = _actions.listIterator(); li.hasNext();)173 {174 s = (Step) li.next();175 s = (Step)s.clone();176 s.ReplaceUnboundVariables(id);177 178 subst = Unifier.Unify(s.getName(), actionName);179 if(subst != null)180 {181 s = (Step) s.clone();182 s.MakeGround(subst);183 return s;184 }185 }186 187 return null;188 }189 159 } -
AgentMind/branches/FAtiMA-Modular/FAtiMA/src/FAtiMA/Core/AgentCore.java
r928 r950 36 36 import FAtiMA.Core.deliberativeLayer.DeliberativeProcess; 37 37 import FAtiMA.Core.deliberativeLayer.EmotionalPlanner; 38 import FAtiMA.Core.deliberativeLayer.goals.Goal; 38 39 import FAtiMA.Core.deliberativeLayer.goals.GoalLibrary; 39 40 import FAtiMA.Core.emotionalState.ActiveEmotion; … … 75 76 public static final Name ACTION_CONTEXT = Name.ParseName("ActionContext()"); 76 77 78 //components 77 79 protected HashMap<String, IComponent> _generalComponents; 78 80 protected ArrayList<IProcessEmotionComponent> _processEmotionComponents; … … 84 86 protected ArrayList<IAppraisalDerivationComponent> _appraisalComponents; 85 87 88 //Data structures 86 89 protected EmotionalState _emotionalState; 87 90 protected Memory _memory; 91 protected GoalLibrary _goalLibrary; 92 protected ActionLibrary _actionLibrary; 93 88 94 protected boolean _shutdown; 89 95 protected DeliberativeProcess _deliberativeLayer; … … 122 128 _perceivedEvents = new ArrayList<Event>(); 123 129 _saveDirectory = ""; 130 124 131 _emotionalState = new EmotionalState(); 125 132 _memory = new Memory(); … … 128 135 _memoryWriter = new MemoryWriter(_memory); 129 136 _strat = this; 137 _actionLibrary = new ActionLibrary(); 130 138 131 139 _generalComponents = new HashMap<String,IComponent>(); … … 184 192 185 193 // Load Plan Operators 186 ActionLibrary.GetInstance().LoadActionsFile(ConfigurationManager.getActionsFile(), this);187 EmotionalPlanner planner = new EmotionalPlanner( ActionLibrary.GetInstance().GetActions());194 _actionLibrary.LoadActionsFile(ConfigurationManager.getActionsFile(), this); 195 EmotionalPlanner planner = new EmotionalPlanner(); 188 196 189 197 // Load GoalLibrary 190 GoalLibrarygoalLibrary = new GoalLibrary(ConfigurationManager.getGoalsFile());198 _goalLibrary = new GoalLibrary(ConfigurationManager.getGoalsFile()); 191 199 192 200 //For efficiency reasons these two are not real processes … … 194 202 addComponent(_reactiveLayer); 195 203 196 _deliberativeLayer = new DeliberativeProcess( goalLibrary,planner);204 _deliberativeLayer = new DeliberativeProcess(planner); 197 205 addComponent(_deliberativeLayer); 198 206 … … 357 365 return this._processExternalRequestComponents; 358 366 } 367 368 public ActionLibrary getActionLibrary() 369 { 370 return _actionLibrary; 371 } 359 372 360 373 /*public void RemoveComponent(IComponent c) … … 366 379 public void AppraiseSelfActionFailed(Event e) 367 380 { 368 _deliberativeLayer. AppraiseSelfActionFailed(e);381 _deliberativeLayer.appraiseSelfActionFailed(e); 369 382 } 370 383 … … 405 418 } 406 419 420 public GoalLibrary getGoalLibrary() 421 { 422 return _goalLibrary; 423 } 424 407 425 /** 408 426 * Gets the name of the agent … … 430 448 _strat = strat; 431 449 } 450 451 public void EnforceCopingStrategy(AgentModel am, String coping) 452 { 453 Goal g; 454 coping = coping.toLowerCase(); 455 for(ListIterator<Goal> li = _goalLibrary.GetGoals();li.hasNext();) 456 { 457 g = (Goal) li.next(); 458 if(g.getName().toString().toLowerCase().startsWith(coping) 459 || (coping.equals("standup") && g.getName().toString().startsWith("ReplyNegatively"))) 460 { 461 AgentLogger.GetInstance().logAndPrint(""); 462 AgentLogger.GetInstance().logAndPrint("Enforcing coping strategy: " + g.getName()); 463 AgentLogger.GetInstance().logAndPrint(""); 464 g.IncreaseImportanceOfFailure(am, 2); 465 g.IncreaseImportanceOfSuccess(am, 2); 466 } 467 } 468 } 432 469 433 470 … … 444 481 this._emotionalState = (EmotionalState) s.readObject(); 445 482 this._memory = (Memory) s.readObject(); 483 this._goalLibrary = (GoalLibrary) s.readObject(); 484 this._actionLibrary = (ActionLibrary) s.readObject(); 446 485 //this._dialogManager = (DialogManager) s.readObject(); 447 486 this._role = (String) s.readObject(); … … 483 522 484 523 AgentSimulationTime.LoadState(fileName+"-Timer.dat"); 485 ActionLibrary.LoadState(fileName+"-ActionLibrary.dat");486 524 487 525 //_remoteAgent.LoadState(fileName+"-RemoteAgent.dat"); … … 507 545 if(agentPlatform == AgentPlatform.WORLDSIM){ 508 546 ListIterator<String> lt = goalList.listIterator(); 509 String goal ;547 String goalDescription; 510 548 String goalName; 511 549 StringTokenizer st; … … 513 551 float impOfFailure; 514 552 while(lt.hasNext()) { 515 goal = (String) lt.next();516 st = new StringTokenizer(goal , "|");553 goalDescription = (String) lt.next(); 554 st = new StringTokenizer(goalDescription, "|"); 517 555 goalName = st.nextToken(); 518 556 impOfSuccess = Float.parseFloat(st.nextToken()); 519 557 impOfFailure = Float.parseFloat(st.nextToken()); 520 558 521 _deliberativeLayer. AddGoal(this, goalName, impOfSuccess, impOfFailure);559 _deliberativeLayer.addGoal(this, goalName, impOfSuccess, impOfFailure); 522 560 } 523 561 } … … 870 908 871 909 AgentSimulationTime.SaveState(fileName+"-Timer.dat"); 872 ActionLibrary.SaveState(fileName+"-ActionLibrary.dat");873 910 _remoteAgent.SaveState(fileName+"-RemoteAgent.dat"); 874 911 … … 882 919 s.writeObject(_emotionalState); 883 920 s.writeObject(_memory); 921 s.writeObject(_goalLibrary); 922 s.writeObject(_actionLibrary); 884 923 //s.writeObject(_dialogManager); 885 924 s.writeObject(_role); … … 970 1009 s.writeObject(_emotionalState); 971 1010 s.writeObject(_memory); 1011 s.writeObject(_goalLibrary); 1012 s.writeObject(_actionLibrary); 972 1013 //s.writeObject(_motivationalState); 973 1014 //s.writeObject(_dialogManager); … … 1031 1072 this._emotionalState = (EmotionalState) s.readObject(); 1032 1073 this._memory = (Memory) s.readObject(); 1074 this._goalLibrary = (GoalLibrary) s.readObject(); 1075 this._actionLibrary = (ActionLibrary) s.readObject(); 1033 1076 //this._dialogManager = (DialogManager) s.readObject(); 1034 1077 //this._role = (String) s.readObject(); -
AgentMind/branches/FAtiMA-Modular/FAtiMA/src/FAtiMA/Core/AgentModel.java
r926 r950 2 2 3 3 import FAtiMA.Core.componentTypes.IComponent; 4 import FAtiMA.Core.deliberativeLayer. DeliberativeProcess;4 import FAtiMA.Core.deliberativeLayer.goals.GoalLibrary; 5 5 import FAtiMA.Core.emotionalState.AppraisalFrame; 6 6 import FAtiMA.Core.emotionalState.EmotionalState; … … 12 12 public interface AgentModel { 13 13 14 public ActionLibrary getActionLibrary(); 15 16 public IComponent getComponent(String name); 17 18 public EmotionalState getEmotionalState(); 19 20 public GoalLibrary getGoalLibrary(); 21 22 public Memory getMemory(); 23 24 //public DeliberativeProcess getDeliberativeLayer(); 25 26 public AgentModel getModelToTest(Symbol ToM); 27 14 28 public String getName(); 15 16 public EmotionalState getEmotionalState();17 18 public Memory getMemory();19 20 public DeliberativeProcess getDeliberativeLayer();21 29 22 30 public ReactiveProcess getReactiveLayer(); 23 31 24 public AgentModel getModelToTest(Symbol ToM); 32 public RemoteAgent getRemoteAgent(); 33 34 public boolean isSelf(); 25 35 26 36 public void setModelStrategy(IGetModelStrategy strat); 27 28 public RemoteAgent getRemoteAgent();29 30 public IComponent getComponent(String name);31 32 public boolean isSelf();33 37 34 38 public void updateEmotions(AppraisalFrame af); -
AgentMind/branches/FAtiMA-Modular/FAtiMA/src/FAtiMA/Core/AgentSimulationTime.java
r667 r950 209 209 public void Tick() 210 210 { 211 long elapsedSimulationTime; 211 212 long currentTime = System.currentTimeMillis(); 212 213 long elapsedRealTime = currentTime - this._lastUpdateTime; … … 215 216 if(this._running) 216 217 { 217 this._simulationTime += elapsedRealTime * this._timeMultiplier; 218 } 219 } 220 221 /** 222 * Advances the agent's simulation time. Very usefull if you 218 elapsedSimulationTime = (long) (elapsedRealTime * this._timeMultiplier); 219 this._simulationTime += elapsedSimulationTime; 220 } 221 } 222 223 /** 224 * Advances the agent's simulation time. Very useful if you 223 225 * want to skip time. 224 226 * @param seconds - the number of seconds you want to advance -
AgentMind/branches/FAtiMA-Modular/FAtiMA/src/FAtiMA/Core/Display/GoalsPanel.java
r667 r950 100 100 DeliberativeProcess deliberative = ag.getDeliberativeLayer(); 101 101 102 if(_goalDisplays.size() != deliberative. GetGoals().size()) {102 if(_goalDisplays.size() != deliberative.getGoals().size()) { 103 103 update = true; 104 104 _goals.removeAll(); 105 105 _goalDisplays.clear(); 106 106 107 Iterator<Goal> it = deliberative. GetGoals().iterator();107 Iterator<Goal> it = deliberative.getGoals().iterator(); 108 108 GoalDisplay gDisplay; 109 109 Goal g; … … 117 117 } 118 118 119 if(_intentionDisplays.keySet().equals(deliberative. GetIntentionKeysSet())) {119 if(_intentionDisplays.keySet().equals(deliberative.getIntentionKeysSet())) { 120 120 //in this case, we just have to update the values for the intensity of emotions 121 121 //since the emotions displayed in the previous update are the same emotions 122 122 //in the current update 123 Iterator<Intention> it = deliberative. GetIntentionsIterator();123 Iterator<Intention> it = deliberative.getIntentionsIterator(); 124 124 IntentionDisplay iDisplay; 125 125 Intention i; … … 136 136 _intentionDisplays.clear(); 137 137 138 Iterator<Intention> it = deliberative. GetIntentionsIterator();138 Iterator<Intention> it = deliberative.getIntentionsIterator(); 139 139 IntentionDisplay iDisplay; 140 140 Intention i; -
AgentMind/branches/FAtiMA-Modular/FAtiMA/src/FAtiMA/Core/deliberativeLayer/DeliberativeProcess.java
r926 r950 135 135 import FAtiMA.Core.deliberativeLayer.goals.ActivePursuitGoal; 136 136 import FAtiMA.Core.deliberativeLayer.goals.Goal; 137 import FAtiMA.Core.deliberativeLayer.goals.GoalLibrary;138 137 import FAtiMA.Core.deliberativeLayer.goals.InterestGoal; 139 138 import FAtiMA.Core.deliberativeLayer.plan.Effect; … … 174 173 private ArrayList<Goal> _goals; 175 174 176 private GoalLibrary _goalLibrary;177 175 private EmotionalPlanner _planner; 178 176 private ActionMonitor _actionMonitor; … … 202 200 * @param planner - the EmotionalPlanner that will be used by the deliberative layer 203 201 */ 204 public DeliberativeProcess( GoalLibrary goalLibrary,EmotionalPlanner planner) {202 public DeliberativeProcess(EmotionalPlanner planner) { 205 203 _goals = new ArrayList<Goal>(); 206 204 207 _goalLibrary = goalLibrary;208 205 _planner = planner; 209 206 _actionMonitor = null; … … 229 226 } 230 227 231 public void addGoalSuccessStrategy(IGoalSuccessStrategy strat) 232 { 233 _goalSuccessStrategies.add(strat); 234 } 235 236 public void addGoalFailureStrategy(IGoalFailureStrategy strat) 237 { 238 _goalFailureStrategies.add(strat); 239 } 240 241 public void addActionSuccessStrategy(IActionSuccessStrategy strat) 242 { 243 _actionSuccessStrategies.add(strat); 244 } 245 246 public void addActionFailureStrategy(IActionFailureStrategy strat) 247 { 248 _actionFailureStrategies.add(strat); 249 } 250 251 public void setUtilityForOthersStrategy(IGetUtilityForOthers strat) 252 { 253 _UOthersStrategy = strat; 254 } 255 256 public void setDetectThreatStrategy(IDetectThreatStrategy strat) 257 { 258 _isThreatStrat = strat; 259 } 260 261 public void setExpectedUtilityStrategy(IExpectedUtilityStrategy strategy) 262 { 263 _EUStrategy = strategy; 264 } 265 266 public void setProbabilityStrategy(IProbabilityStrategy strategy) 267 { 268 _PStrategy = strategy; 269 } 270 271 public void setUtilityStrategy(IUtilityStrategy strategy) 272 { 273 _UStrategy = strategy; 274 } 275 276 public IExpectedUtilityStrategy getExpectedUtilityStrategy() 277 { 278 return _EUStrategy; 279 } 280 281 public IGetUtilityForOthers getUtilityForOthersStrategy() 282 { 283 return _UOthersStrategy; 284 } 285 286 public IProbabilityStrategy getProbabilityStrategy() 287 { 288 return _PStrategy; 289 } 290 291 public IUtilityStrategy getUtilityStrategy() 292 { 293 return _UStrategy; 294 } 295 296 public IDetectThreatStrategy getDetectThreatStrategy() 297 { 298 return _isThreatStrat; 299 } 300 301 /** 302 * Adds a goal to the agent's Goal List 303 * @param goal - the goal to add 304 */ 305 public void AddGoal(Goal goal) { 306 InterestGoal iGoal; 307 ArrayList<Condition> protectionConstraints; 308 ListIterator<Condition> li; 309 310 synchronized (this) { 311 if(!_goals.contains(goal)) { 312 _goals.add(goal); 313 if (goal instanceof InterestGoal) { 314 iGoal = (InterestGoal) goal; 315 protectionConstraints = iGoal.getProtectionConstraints(); 316 if(protectionConstraints != null) 317 { 318 li = protectionConstraints.listIterator(); 319 while(li.hasNext()) 320 { 321 AddProtectionConstraint(new ProtectedCondition(iGoal, (Condition) li.next())); 322 } 323 } 324 } 325 } 326 } 327 } 328 329 /** 330 * Adds a ProtectionConstraint to the DeliberativeLayer. The planner will detect 331 * when there are threats to these ProtectionConstraints and deal with them 332 * with emotion-focused coping strategies. 333 * 334 * @param cond - the ProtectedCondition to add 335 * @see ProtectedCondition 336 */ 337 public void AddProtectionConstraint(ProtectedCondition cond) { 338 _protectionConstraints.add(cond); 339 } 340 341 342 /** 343 * Updates all the plans that the deliberative layer is currently working with, i.e., 344 * it updates all plans of all current active intentions 345 */ 346 public void CheckLinks(AgentModel am) { 347 Iterator<Intention> it; 348 349 synchronized(this) 350 { 351 it = _intentions.values().iterator(); 352 while (it.hasNext()) { 353 ((Intention) it.next()).CheckLinks(am); 354 } 355 } 356 } 357 358 public boolean ContainsIntention(ActivePursuitGoal goal) 359 { 360 String goalName = goal.getNameWithCharactersOrdered(); 361 362 return _intentions.containsKey(goalName); 363 364 365 /* 366 while(it.hasNext()) 367 { 368 i = (Intention) it.next(); 369 if (i.containsIntention(goalName)) return true; 370 } 371 372 return false;*/ 373 } 374 375 /** 376 * Changes a Goal's Importance 377 * @param goalName - the name of the goal to change 378 * @param importance - the new value for the importance 379 * @param importanceType - the type of importance: 380 * the String "CIS" changes the importance of success 381 * the String "CIF" changes the importance of failure 382 */ 383 public void ChangeGoalImportance(AgentModel am, String goalName, float importance, String importanceType) { 384 ListIterator<Goal> li; 385 386 synchronized (this) { 387 li = _goals.listIterator(); 388 Goal g; 389 390 while(li.hasNext()) { 391 g = (Goal) li.next(); 392 if(goalName.equals(g.getName().toString())) { 393 if(importanceType.equals("CIS")) { 394 g.SetImportanceOfSuccess(am, importance); 395 } 396 else { 397 g.SetImportanceOfFailure(am, importance); 398 } 399 break; 400 } 401 } 402 } 403 } 404 405 /** 406 * Removes a given goal from the agent's goal list 407 * @param goalName - the name of the goal to remove 408 */ 409 public void RemoveGoal(String goalName) { 410 Goal g; 411 412 synchronized (this) 413 { 414 for(int i=0; i < _goals.size(); i++) { 415 g = (Goal) _goals.get(i); 416 if(goalName.equals(g.getName().toString())) { 417 _goals.remove(i); 418 break; 419 } 420 } 421 } 422 } 423 424 /** 425 * Removes all the agent's goals 426 * 427 */ 428 public void RemoveAllGoals() { 429 430 synchronized (this) 431 { 432 _goals.clear(); 433 _options.clear(); 434 _intentions.clear(); 435 } 436 } 437 438 /** 439 * Adds a goal to the agent's Goal List 440 * @param goalName - the name of the Goal 441 * @param importanceOfSuccess - the goal's importance of success 442 * @param importanceOfFailure - the goal's importance of failure 443 * @throws UnknownGoalException - thrown if the goal is not specified 444 * in the GoalLibrary file. You can only add 445 * goals defined in the GoalLibrary. 446 */ 447 public void AddGoal(AgentModel am, String goalName, float importanceOfSuccess, float importanceOfFailure) throws UnknownGoalException { 448 Goal g = _goalLibrary.GetGoal(Name.ParseName(goalName)); 449 if (g != null) { 450 g.SetImportanceOfSuccess(am, importanceOfSuccess); 451 g.SetImportanceOfFailure(am, importanceOfFailure); 452 AddGoal(g); 228 public void actionSelectedForExecution(ValuedAction selectedAction) 229 { 230 String action; 231 String target=null; 232 Event e; 233 234 if(_selectedAction == null) 235 { 236 return; 237 } 238 239 ListIterator<Symbol> li = _selectedAction.getName().GetLiteralList().listIterator(); 240 241 action = li.next().toString(); 242 243 if(li.hasNext()) { 244 target = li.next().toString(); 453 245 } 454 else 455 { 456 throw new UnknownGoalException(goalName); 246 247 e = new Event(Constants.SELF,action,target); 248 _actionMonitor = new ActionMonitor(_selectedAction,e); 249 250 while(li.hasNext()) { 251 e.AddParameter(new Parameter("parameter",li.next().toString())); 457 252 } 458 } 459 460 /** 461 * Adds a goal to the agent's Goal List 462 * @param goalName - the name of the Goal 463 * @param importanceOfSuccess - the goal's importance of success 464 * @param importanceOfFailure - the goal's importance of failure 465 * @throws UnknownGoalException - thrown if the goal is not specified 466 * in the GoalLibrary file. You can only add 467 * goals defined in the GoalLibrary. 468 */ 469 public void AddGoal(AgentModel am, String goalName) throws UnknownGoalException { 470 Goal g = _goalLibrary.GetGoal(Name.ParseName(goalName)); 471 if (g != null) { 472 g.SetImportanceOfSuccess(am, 1); 473 g.SetImportanceOfFailure(am, 1); 474 AddGoal(g); 475 } 476 else 477 { 478 throw new UnknownGoalException(goalName); 479 } 480 } 481 482 483 /** 484 * Creates and Adds an intention to the set of intentions that the 485 * planner is currently trying to achieve (however the planner only 486 * picks one of them at each reasoning cycle) 487 * 488 * @param goal - the goal that we want to add 489 */ 490 public void AddIntention(AgentModel am, ActivePursuitGoal goal) { 491 ArrayList<Plan> plans; 492 Plan newPlan; 493 Intention intention; 494 String goalName = goal.getNameWithCharactersOrdered(); 495 496 synchronized(this) 497 { 498 AgentLogger.GetInstance().logAndPrint("Adding 1st level intention: " + goal.getName()); 499 intention = new Intention(am,goal); 500 501 plans = goal.getPlans(am); 502 if(plans == null) 503 { 504 newPlan = new Plan(_protectionConstraints, _isThreatStrat, goal.GetSuccessConditions()); 505 intention.AddPlan(newPlan); 506 } 507 else 508 { 509 intention.AddPlans(plans); 510 } 511 512 _intentions.put(goalName,intention); 513 intention.ProcessIntentionActivation(am); 514 } 515 } 516 517 public void AddSubIntention(AgentModel am, Intention mainIntention, ActivePursuitGoal goal) 518 { 519 ArrayList<Plan> plans; 520 Plan newPlan; 521 Intention subIntention; 522 523 524 subIntention = new Intention(am,goal); 525 plans = goal.getPlans(am); 526 if(plans == null) 527 { 528 newPlan = new Plan(_protectionConstraints, _isThreatStrat, goal.GetSuccessConditions()); 529 subIntention.AddPlan(newPlan); 530 } 531 else 532 { 533 subIntention.AddPlans(plans); 534 } 535 536 mainIntention.AddSubIntention(subIntention); 537 } 538 539 public void AddOptionsStrategy(IOptionsStrategy strategy) 540 { 541 _optionStrategies.add(strategy); 542 } 543 544 /** 545 * Gets the agent's goals 546 * @return a list with the agent's goals 547 */ 548 public ArrayList<Goal> GetGoals() { 549 return _goals; 550 } 551 552 /** 553 * Gets the library of goals (all goals specified for the domain) 554 * @return the GoalLibrary with all goals specified for the domain 555 */ 556 public GoalLibrary getGoalLibrary() { 557 return _goalLibrary; 558 } 559 560 /** 561 * Gets the agent's emotional planner used in the deliberative reasoning process 562 * @return the agent's EmotionalPlanner 563 */ 564 public EmotionalPlanner getEmotionalPlanner() { 565 return _planner; 566 } 567 568 /** 569 * Gets a set of IntentionKeys 570 * @return a set with the keys used to store all intentions 571 */ 572 public Set<String> GetIntentionKeysSet() { 573 synchronized(this) 574 { 575 return _intentions.keySet(); 576 } 577 } 578 579 /** 580 * Gets a iterator that allows you to iterate over the set of active 581 * Intentions 582 * @return 583 */ 584 public Iterator<Intention> GetIntentionsIterator() { 585 return _intentions.values().iterator(); 586 } 587 588 public void EnforceCopingStrategy(AgentModel am, String coping) 589 { 590 Goal g; 591 coping = coping.toLowerCase(); 592 for(ListIterator<Goal> li = _goalLibrary.GetGoals();li.hasNext();) 593 { 594 g = (Goal) li.next(); 595 if(g.getName().toString().toLowerCase().startsWith(coping) 596 || (coping.equals("standup") && g.getName().toString().startsWith("ReplyNegatively"))) 597 { 598 AgentLogger.GetInstance().logAndPrint(""); 599 AgentLogger.GetInstance().logAndPrint("Enforcing coping strategy: " + g.getName()); 600 AgentLogger.GetInstance().logAndPrint(""); 601 g.IncreaseImportanceOfFailure(am, 2); 602 g.IncreaseImportanceOfSuccess(am, 2); 603 } 604 } 605 } 606 607 /** 608 * Determines an answer to a SpeechAct according to the agent's goals and plans 609 * @return the best answer to give according to its influence on the agent's 610 * goals and plans 611 */ 612 /* 613 public ValuedAction AnswerToSpeechAct(SpeechAct speechAct) { 614 Step positiveAnswer; 615 Step negativeAnswer; 616 Name positiveSpeech; 617 Name negativeSpeech; 618 float positiveAnswerIntensity; 619 float negativeAnswerIntensity; 620 ArrayList bindings; 621 Name action; 622 Name goalFailure; 623 float actionValue; 624 Goal g; 625 626 positiveSpeech = Name.ParseName("Reply(" + speechAct.getSender() + "," + speechAct.getMeaning() + ",positiveanswer)"); 627 negativeSpeech = Name.ParseName("Reply(" + speechAct.getSender() + "," + speechAct.getMeaning() + ",negativeanswer)"); 628 629 //check if the speech act refers to any goal 630 synchronized (this) 631 { 632 ListIterator li = _goals.listIterator(); 633 while(li.hasNext()) { 634 g = (Goal) li.next(); 635 if(g.GetName().GetFirstLiteral().toString().equals(speechAct.getMeaning())) { 636 //in this case, the user is suggesting that the agent should try to achieve this goal 637 //if the agent tried previously to achieve it and the goal failed, it will reply no way 638 goalFailure = Name.ParseName(g.GenerateGoalStatus(Goal.GOALFAILURE)); 639 bindings = KnowledgeBase.GetInstance().GetPossibleBindings(goalFailure); 640 if (bindings != null) { 641 return new ValuedAction(negativeSpeech,10); 642 } 643 else { 644 //if the goal didn't failed before, the agent will accept the user sugestion by increasing 645 //the goal's importance 646 g.IncreaseImportanceOfFailure(4); 647 g.IncreaseImportanceOfSuccess(4); 648 return new ValuedAction(positiveSpeech,10); 649 } 650 } 651 } 652 } 653 654 655 positiveAnswer = _planner.GetStep(positiveSpeech); 656 if(positiveAnswer != null) { 657 positiveAnswerIntensity = _planner.AppraiseAnswer(positiveAnswer); 658 } 659 else positiveAnswerIntensity = 0; 660 negativeAnswer = _planner.GetStep(negativeSpeech); 661 if(negativeAnswer != null) { 662 negativeAnswerIntensity = _planner.AppraiseAnswer(negativeAnswer); 663 } 664 else negativeAnswerIntensity = 0; 665 666 if(positiveAnswerIntensity >= negativeAnswerIntensity) { 667 if(positiveAnswer != null) 668 { 669 action = positiveAnswer.getName(); 670 actionValue = positiveAnswerIntensity - negativeAnswerIntensity; 671 } 672 else return null; 673 } 674 else { 675 if(negativeAnswer != null) 676 { 677 action = negativeAnswer.getName(); 678 actionValue = negativeAnswerIntensity - positiveAnswerIntensity; 679 } 680 else return null; 681 } 682 683 return new ValuedAction(action,actionValue); 684 } 685 */ 686 687 @Override 688 public void update(AgentModel am, Event event) { 689 690 CheckLinks(am); 691 692 693 if(_actionMonitor != null && _actionMonitor.matchEvent(event)) { 694 if(_actionMonitor.getStep().getAgent().isGrounded() && 695 !_actionMonitor.getStep().getAgent().toString().equals(Constants.SELF)) 696 { 697 //the agent was waiting for an action of other agent to be complete 698 //since the step of another agent may contain unbound variables, 699 //we cannot just compare the names, we need to try to unify them 700 if(Unifier.Unify(event.toStepName(), 701 _actionMonitor.getStep().getName()) != null) 702 { 703 _actionMonitor.getStep().IncreaseProbability(am); 704 //System.out.println("Calling updateEffectsProbability (other's action: step completed)"); 705 _actionMonitor.getStep().updateEffectsProbability(am); 706 } 707 else 708 { 709 for(IActionFailureStrategy s : _actionFailureStrategies) 710 { 711 s.perceiveActionFailure(am, _actionMonitor.getStep()); 712 } 713 714 _actionMonitor.getStep().DecreaseProbability(am); 715 } 716 } 717 else 718 { 719 for(IActionSuccessStrategy s : _actionSuccessStrategies) 720 { 721 s.perceiveActionSuccess(am, _actionMonitor.getStep()); 722 } 723 //System.out.println("Calling updateEffectsProbability (self: step completed)"); 724 _actionMonitor.getStep().updateEffectsProbability(am); 725 } 726 727 UpdateProbabilities(); 728 _actionMonitor = null; 729 } 730 } 731 732 public ArrayList<ActivePursuitGoal> options(AgentModel am) 733 { 734 Goal g; 735 ActivePursuitGoal aGoal; 736 ListIterator<Goal> li; 737 ListIterator<SubstitutionSet> li2; 738 ActivePursuitGoal desire; 739 SubstitutionSet subSet; 740 ArrayList<SubstitutionSet> substitutionSets; 741 ArrayList<ActivePursuitGoal> options; 742 743 options = new ArrayList<ActivePursuitGoal>(); 744 745 746 //TODO optimize the goal activation verification 747 synchronized (this) 748 { 749 li = _goals.listIterator(); 750 while (li.hasNext()) { 751 g = (Goal) li.next(); 752 if (g instanceof ActivePursuitGoal) { 753 aGoal = (ActivePursuitGoal) g; 754 755 756 substitutionSets = Condition.CheckActivation(am, aGoal.GetPreconditions()); 757 if(substitutionSets != null) { 758 li2 = substitutionSets.listIterator(); 759 while(li2.hasNext()) { 760 761 subSet = (SubstitutionSet) li2.next(); 762 763 desire = (ActivePursuitGoal) aGoal.clone(); 764 desire.MakeGround(subSet.GetSubstitutions()); 765 766 //In addition to testing the preconditions, we only add a goal 767 // as a desire if it's success and failure conditions are not satisfied 768 769 if(!desire.CheckSuccess(am) && !desire.CheckFailure(am)) 770 { 771 772 options.add(desire); 773 } 774 } 775 } 776 } 777 } 778 } 779 780 return options; 781 } 782 783 public ActivePursuitGoal Filter(AgentModel am, ArrayList<ActivePursuitGoal> options) { 784 ActivePursuitGoal g; 785 ActivePursuitGoal maxGoal = null; 786 float maxUtility; 787 // expected utility of achieving a goal 788 float EU; 789 790 maxUtility = -200; 791 792 ListIterator<ActivePursuitGoal> li = options.listIterator(); 793 while(li.hasNext()) 794 { 795 g = li.next(); 796 if(!ContainsIntention(g)) 797 { 798 EU = _EUStrategy.getExpectedUtility(am, g); 799 800 if(EU > maxUtility) 801 { 802 maxUtility = EU; 803 maxGoal = g; 804 } 805 } 806 } 807 808 if(maxGoal != null) 809 { 810 if(maxUtility >= MINIMUMUTILITY) 811 { 812 if(_currentIntention == null || 813 maxUtility > _EUStrategy.getExpectedUtility(am,_currentIntention)*SELECTIONTHRESHOLD) 814 { 815 return maxGoal; 816 } 817 } 818 } 819 820 821 return null; 822 } 823 824 /** 825 * Filters the most relevant intention from the set of possible intentions/goals. 826 * Corresponds to Focusing on a given goal 827 * @return - the most relevant intention (the one with highest expected utility) 828 */ 829 public Intention Filter2ndLevel(AgentModel am) { 830 Iterator<Intention> it; 831 Intention intention; 832 float highestUtility; 833 Intention maxIntention = null; 834 float EU; 835 836 if(_currentIntention != null) 837 { 838 highestUtility = _EUStrategy.getExpectedUtility(am, _currentIntention); 839 840 maxIntention = _currentIntention; 841 //TODO selection threshold here! 842 } 843 else 844 { 845 maxIntention = null; 846 highestUtility = -200; 847 } 848 849 synchronized(this) 850 { 851 it = _intentions.values().iterator(); 852 853 854 while (it.hasNext()) { 855 856 intention = (Intention) it.next(); 857 858 if(intention != _currentIntention) 859 { 860 EU = _EUStrategy.getExpectedUtility(am, intention); 861 862 if(EU > highestUtility && EU > MINIMUMUTILITY) 863 { 864 highestUtility = EU; 865 maxIntention = intention; 866 } 867 } 868 } 869 } 870 871 if(this._currentIntention != maxIntention) 872 { 873 AgentLogger.GetInstance().logAndPrint("Switching 2nd level intention from " + this._currentIntention + " to " + maxIntention); 874 } 875 876 this._currentIntention = maxIntention; 877 878 return maxIntention; 253 254 _selectedActionEmotion = null; 255 _selectedAction = null; 879 256 } 880 257 … … 904 281 905 282 //deliberation; 906 ActivePursuitGoal g = Filter(am, this._options);283 ActivePursuitGoal g = filter(am, this._options); 907 284 908 285 if(g != null) 909 286 { 910 AddIntention(am, g);287 addIntention(am, g); 911 288 } 912 289 913 290 //means-end reasoning 914 _currentIntention = Filter2ndLevel(am);291 _currentIntention = filter2ndLevel(am); 915 292 if(_currentIntention != null) { 916 293 i = _currentIntention.GetSubIntention(); … … 928 305 if(i.getGoal().CheckSuccess(am)) 929 306 { 930 RemoveIntention(i);307 removeIntention(i); 931 308 for(IGoalSuccessStrategy s: _goalSuccessStrategies) 932 309 { … … 934 311 } 935 312 i.ProcessIntentionSuccess(am); 936 cancelAction(am);937 313 } 938 314 else if(i.getGoal().CheckFailure(am)) 939 315 { 940 RemoveIntention(i);316 removeIntention(i); 941 317 for(IGoalFailureStrategy s: _goalFailureStrategies) 942 318 { … … 958 334 if(i.IsStrongCommitment()) 959 335 { 960 RemoveIntention(i);336 removeIntention(i); 961 337 } 962 338 cancelAction(am); 963 339 } 964 else if(!i. getGoal().checkPreconditions(am))340 else if(!i.IsStrongCommitment() && !i.getGoal().checkPreconditions(am)) 965 341 { 966 342 //this is done only if the agent hasn't tried to do anything yet, he cancels the goal out 967 343 //if the preconditions are not yet established 968 if(!i.IsStrongCommitment()) 969 { 970 RemoveIntention(i); 971 } 344 removeIntention(i); 972 345 } 973 346 else 974 347 { 975 _selectedPlan = _planner.ThinkAbout(am, i); 348 _selectedPlan = _planner.ThinkAbout(am,this, i); 349 } 350 351 if(_selectedPlan == null && i.IsStrongCommitment() && !i.getGoal().checkPreconditions(am)) 352 { 353 i.ProcessIntentionCancel(am); 354 removeIntention(i); 976 355 } 977 356 … … 990 369 if(copingAction instanceof ActivePursuitGoal) 991 370 { 992 AddSubIntention(am, _currentIntention, (ActivePursuitGoal) copingAction);371 addSubIntention(am, _currentIntention, (ActivePursuitGoal) copingAction); 993 372 } 994 373 else if(!actionName.startsWith("Inference") && !actionName.endsWith("Appraisal") && !actionName.startsWith("SA")) … … 1033 412 am.getMemory().getSemanticMemory().Tell(eff.GetEffect().getName(), eff.GetEffect().GetValue().toString()); 1034 413 } 1035 this. CheckLinks(am);414 this.checkLinks(am); 1036 415 } 1037 416 else … … 1052 431 } 1053 432 1054 return GetSelectedAction(); 433 return getSelectedAction(); 434 } 435 436 public void addActionFailureStrategy(IActionFailureStrategy strat) 437 { 438 _actionFailureStrategies.add(strat); 439 } 440 441 public void addActionSuccessStrategy(IActionSuccessStrategy strat) 442 { 443 _actionSuccessStrategies.add(strat); 444 } 445 446 /** 447 * Adds a goal to the agent's Goal List 448 * @param goalName - the name of the Goal 449 * @param importanceOfSuccess - the goal's importance of success 450 * @param importanceOfFailure - the goal's importance of failure 451 * @throws UnknownGoalException - thrown if the goal is not specified 452 * in the GoalLibrary file. You can only add 453 * goals defined in the GoalLibrary. 454 */ 455 public void addGoal(AgentModel am, String goalName) throws UnknownGoalException { 456 Goal g = am.getGoalLibrary().GetGoal(Name.ParseName(goalName)); 457 if (g != null) { 458 g.SetImportanceOfSuccess(am, 1); 459 g.SetImportanceOfFailure(am, 1); 460 addGoal(g); 461 } 462 else 463 { 464 throw new UnknownGoalException(goalName); 465 } 466 } 467 468 /** 469 * Adds a goal to the agent's Goal List 470 * @param goalName - the name of the Goal 471 * @param importanceOfSuccess - the goal's importance of success 472 * @param importanceOfFailure - the goal's importance of failure 473 * @throws UnknownGoalException - thrown if the goal is not specified 474 * in the GoalLibrary file. You can only add 475 * goals defined in the GoalLibrary. 476 */ 477 public void addGoal(AgentModel am, String goalName, float importanceOfSuccess, float importanceOfFailure) throws UnknownGoalException { 478 479 Goal g = am.getGoalLibrary().GetGoal(Name.ParseName(goalName)); 480 if (g != null) { 481 g.SetImportanceOfSuccess(am, importanceOfSuccess); 482 g.SetImportanceOfFailure(am, importanceOfFailure); 483 addGoal(g); 484 } 485 else 486 { 487 throw new UnknownGoalException(goalName); 488 } 489 } 490 491 /** 492 * Adds a goal to the agent's Goal List 493 * @param goal - the goal to add 494 */ 495 public void addGoal(Goal goal) { 496 InterestGoal iGoal; 497 ArrayList<Condition> protectionConstraints; 498 ListIterator<Condition> li; 499 500 synchronized (this) { 501 if(!_goals.contains(goal)) { 502 _goals.add(goal); 503 if (goal instanceof InterestGoal) { 504 iGoal = (InterestGoal) goal; 505 protectionConstraints = iGoal.getProtectionConstraints(); 506 if(protectionConstraints != null) 507 { 508 li = protectionConstraints.listIterator(); 509 while(li.hasNext()) 510 { 511 addProtectionConstraint(new ProtectedCondition(iGoal, (Condition) li.next())); 512 } 513 } 514 } 515 } 516 } 517 } 518 519 public void addGoalFailureStrategy(IGoalFailureStrategy strat) 520 { 521 _goalFailureStrategies.add(strat); 522 } 523 524 public void addGoalSuccessStrategy(IGoalSuccessStrategy strat) 525 { 526 _goalSuccessStrategies.add(strat); 527 } 528 529 /** 530 * Creates and Adds an intention to the set of intentions that the 531 * planner is currently trying to achieve (however the planner only 532 * picks one of them at each reasoning cycle) 533 * 534 * @param goal - the goal that we want to add 535 */ 536 public void addIntention(AgentModel am, ActivePursuitGoal goal) { 537 ArrayList<Plan> plans; 538 Plan newPlan; 539 Intention intention; 540 String goalName = goal.getNameWithCharactersOrdered(); 541 542 synchronized(this) 543 { 544 AgentLogger.GetInstance().logAndPrint("Adding 1st level intention: " + goal.getName()); 545 intention = new Intention(am,goal); 546 547 plans = goal.getPlans(am); 548 if(plans == null) 549 { 550 newPlan = new Plan(_protectionConstraints, _isThreatStrat, goal.GetSuccessConditions()); 551 intention.AddPlan(newPlan); 552 } 553 else 554 { 555 intention.AddPlans(plans); 556 } 557 558 _intentions.put(goalName,intention); 559 intention.ProcessIntentionActivation(am); 560 } 561 } 562 563 public void addOptionsStrategy(IOptionsStrategy strategy) 564 { 565 _optionStrategies.add(strategy); 566 } 567 568 /** 569 * Adds a ProtectionConstraint to the DeliberativeLayer. The planner will detect 570 * when there are threats to these ProtectionConstraints and deal with them 571 * with emotion-focused coping strategies. 572 * 573 * @param cond - the ProtectedCondition to add 574 * @see ProtectedCondition 575 */ 576 public void addProtectionConstraint(ProtectedCondition cond) { 577 _protectionConstraints.add(cond); 578 } 579 580 public void addSubIntention(AgentModel am, Intention mainIntention, ActivePursuitGoal goal) 581 { 582 ArrayList<Plan> plans; 583 Plan newPlan; 584 Intention subIntention; 585 586 587 subIntention = new Intention(am,goal); 588 plans = goal.getPlans(am); 589 if(plans == null) 590 { 591 newPlan = new Plan(_protectionConstraints, _isThreatStrat, goal.GetSuccessConditions()); 592 subIntention.AddPlan(newPlan); 593 } 594 else 595 { 596 subIntention.AddPlans(plans); 597 } 598 599 mainIntention.AddSubIntention(subIntention); 600 } 601 602 @Override 603 public void appraisal(AgentModel am, Event e, AppraisalFrame as) { 604 } 605 606 public void appraiseSelfActionFailed(Event e) 607 { 608 if(_actionMonitor != null) 609 { 610 if(_actionMonitor.matchEvent(e)) 611 { 612 _actionMonitor = null; 613 } 614 } 1055 615 } 1056 616 … … 1069 629 } 1070 630 1071 public void AppraiseSelfActionFailed(Event e) 1072 { 1073 if(_actionMonitor != null) 1074 { 1075 if(_actionMonitor.matchEvent(e)) 1076 { 1077 _actionMonitor = null; 1078 } 1079 } 631 632 /** 633 * Changes a Goal's Importance 634 * @param goalName - the name of the goal to change 635 * @param importance - the new value for the importance 636 * @param importanceType - the type of importance: 637 * the String "CIS" changes the importance of success 638 * the String "CIF" changes the importance of failure 639 */ 640 public void changeGoalImportance(AgentModel am, String goalName, float importance, String importanceType) { 641 ListIterator<Goal> li; 642 643 synchronized (this) { 644 li = _goals.listIterator(); 645 Goal g; 646 647 while(li.hasNext()) { 648 g = (Goal) li.next(); 649 if(goalName.equals(g.getName().toString())) { 650 if(importanceType.equals("CIS")) { 651 g.SetImportanceOfSuccess(am, importance); 652 } 653 else { 654 g.SetImportanceOfFailure(am, importance); 655 } 656 break; 657 } 658 } 659 } 660 } 661 662 /** 663 * Updates all the plans that the deliberative layer is currently working with, i.e., 664 * it updates all plans of all current active intentions 665 */ 666 public void checkLinks(AgentModel am) { 667 Iterator<Intention> it; 668 669 synchronized(this) 670 { 671 it = _intentions.values().iterator(); 672 while (it.hasNext()) { 673 ((Intention) it.next()).CheckLinks(am); 674 } 675 } 676 } 677 678 public boolean containsIntention(ActivePursuitGoal goal) 679 { 680 String goalName = goal.getNameWithCharactersOrdered(); 681 682 return _intentions.containsKey(goalName); 683 684 685 /* 686 while(it.hasNext()) 687 { 688 i = (Intention) it.next(); 689 if (i.containsIntention(goalName)) return true; 690 } 691 692 return false;*/ 693 } 694 695 @Override 696 public AgentDisplayPanel createDisplayPanel(AgentModel am) { 697 return null; 698 } 699 700 @Override 701 public IComponent createModelOfOther() { 702 return new DeliberativeProcess(_planner); 703 } 704 705 public ActivePursuitGoal filter(AgentModel am, ArrayList<ActivePursuitGoal> options) { 706 ActivePursuitGoal g; 707 ActivePursuitGoal maxGoal = null; 708 float maxUtility; 709 // expected utility of achieving a goal 710 float EU; 711 712 maxUtility = -200; 713 714 ListIterator<ActivePursuitGoal> li = options.listIterator(); 715 while(li.hasNext()) 716 { 717 g = li.next(); 718 if(!containsIntention(g)) 719 { 720 EU = _EUStrategy.getExpectedUtility(am, g); 721 722 if(EU > maxUtility) 723 { 724 maxUtility = EU; 725 maxGoal = g; 726 } 727 } 728 } 729 730 if(maxGoal != null) 731 { 732 if(maxUtility >= MINIMUMUTILITY) 733 { 734 if(_currentIntention == null || 735 maxUtility > _EUStrategy.getExpectedUtility(am,_currentIntention)*SELECTIONTHRESHOLD) 736 { 737 return maxGoal; 738 } 739 } 740 } 741 742 743 return null; 744 } 745 746 /** 747 * Filters the most relevant intention from the set of possible intentions/goals. 748 * Corresponds to Focusing on a given goal 749 * @return - the most relevant intention (the one with highest expected utility) 750 */ 751 public Intention filter2ndLevel(AgentModel am) { 752 Iterator<Intention> it; 753 Intention intention; 754 float highestUtility; 755 Intention maxIntention = null; 756 float EU; 757 758 if(_currentIntention != null) 759 { 760 highestUtility = _EUStrategy.getExpectedUtility(am, _currentIntention); 761 762 maxIntention = _currentIntention; 763 //TODO selection threshold here! 764 } 765 else 766 { 767 maxIntention = null; 768 highestUtility = -200; 769 } 770 771 synchronized(this) 772 { 773 it = _intentions.values().iterator(); 774 775 776 while (it.hasNext()) { 777 778 intention = (Intention) it.next(); 779 780 if(intention != _currentIntention) 781 { 782 EU = _EUStrategy.getExpectedUtility(am, intention); 783 784 if(EU > highestUtility && EU > MINIMUMUTILITY) 785 { 786 highestUtility = EU; 787 maxIntention = intention; 788 } 789 } 790 } 791 } 792 793 if(this._currentIntention != maxIntention) 794 { 795 AgentLogger.GetInstance().logAndPrint("Switching 2nd level intention from " + this._currentIntention + " to " + maxIntention); 796 } 797 798 this._currentIntention = maxIntention; 799 800 return maxIntention; 801 } 802 803 804 public IDetectThreatStrategy getDetectThreatStrategy() 805 { 806 return _isThreatStrat; 807 } 808 809 /** 810 * Gets the agent's emotional planner used in the deliberative reasoning process 811 * @return the agent's EmotionalPlanner 812 */ 813 public EmotionalPlanner getEmotionalPlanner() { 814 return _planner; 815 } 816 817 public float getExpectedUtility(AgentModel am, ActivePursuitGoal g) { 818 return _UStrategy.getUtility(am, g) * _PStrategy.getProbability(am, g); 819 } 820 821 public float getExpectedUtility(AgentModel am, Intention i) { 822 return _UStrategy.getUtility(am, i.getGoal()) * _PStrategy.getProbability(am, i); 823 } 824 825 public IExpectedUtilityStrategy getExpectedUtilityStrategy() 826 { 827 return _EUStrategy; 828 } 829 830 /** 831 * Gets the agent's goals 832 * @return a list with the agent's goals 833 */ 834 public ArrayList<Goal> getGoals() { 835 return _goals; 836 } 837 838 /** 839 * Gets a set of IntentionKeys 840 * @return a set with the keys used to store all intentions 841 */ 842 public Set<String> getIntentionKeysSet() { 843 synchronized(this) 844 { 845 return _intentions.keySet(); 846 } 847 } 848 849 850 851 /** 852 * Gets a iterator that allows you to iterate over the set of active 853 * Intentions 854 * @return 855 */ 856 public Iterator<Intention> getIntentionsIterator() { 857 return _intentions.values().iterator(); 858 } 859 860 public IProbabilityStrategy getProbabilityStrategy() 861 { 862 return _PStrategy; 1080 863 } 1081 864 … … 1085 868 * if no such action exists 1086 869 */ 1087 private ValuedAction GetSelectedAction() {870 private ValuedAction getSelectedAction() { 1088 871 1089 872 Event e; … … 1149 932 } 1150 933 1151 public void actionSelectedForExecution(ValuedAction selectedAction) 1152 { 1153 String action; 1154 String target=null; 1155 Event e; 1156 1157 if(_selectedAction == null) 1158 { 1159 return; 1160 } 1161 1162 ListIterator<Symbol> li = _selectedAction.getName().GetLiteralList().listIterator(); 1163 1164 action = li.next().toString(); 1165 1166 if(li.hasNext()) { 1167 target = li.next().toString(); 1168 } 1169 1170 e = new Event(Constants.SELF,action,target); 1171 _actionMonitor = new ActionMonitor(_selectedAction,e); 1172 1173 while(li.hasNext()) { 1174 e.AddParameter(new Parameter("parameter",li.next().toString())); 1175 } 1176 1177 _selectedActionEmotion = null; 1178 _selectedAction = null; 934 public IGetUtilityForOthers getUtilityForOthersStrategy() 935 { 936 return _UOthersStrategy; 937 } 938 939 public IUtilityStrategy getUtilityStrategy() 940 { 941 return _UStrategy; 942 } 943 944 @Override 945 public void initialize(AgentModel ag) { 946 } 947 948 @Override 949 public void inverseAppraisal(AgentModel am, AppraisalFrame af) { 950 } 951 952 @Override 953 public String name() { 954 return DeliberativeProcess.NAME; 955 } 956 957 public ArrayList<ActivePursuitGoal> options(AgentModel am) 958 { 959 Goal g; 960 ActivePursuitGoal aGoal; 961 ListIterator<Goal> li; 962 ListIterator<SubstitutionSet> li2; 963 ActivePursuitGoal desire; 964 SubstitutionSet subSet; 965 ArrayList<SubstitutionSet> substitutionSets; 966 ArrayList<ActivePursuitGoal> options; 967 968 options = new ArrayList<ActivePursuitGoal>(); 969 970 971 //TODO optimize the goal activation verification 972 synchronized (this) 973 { 974 li = _goals.listIterator(); 975 while (li.hasNext()) { 976 g = (Goal) li.next(); 977 if (g instanceof ActivePursuitGoal) { 978 aGoal = (ActivePursuitGoal) g; 979 980 981 substitutionSets = Condition.CheckActivation(am, aGoal.GetPreconditions()); 982 if(substitutionSets != null) { 983 li2 = substitutionSets.listIterator(); 984 while(li2.hasNext()) { 985 986 subSet = (SubstitutionSet) li2.next(); 987 988 desire = (ActivePursuitGoal) aGoal.clone(); 989 desire.MakeGround(subSet.GetSubstitutions()); 990 991 //In addition to testing the preconditions, we only add a goal 992 // as a desire if it's success and failure conditions are not satisfied 993 994 if(!desire.CheckSuccess(am) && !desire.CheckFailure(am)) 995 { 996 997 options.add(desire); 998 } 999 } 1000 } 1001 } 1002 } 1003 } 1004 1005 return options; 1006 } 1007 1008 @Override 1009 public AppraisalFrame reappraisal(AgentModel am) { 1010 return null; 1011 } 1012 1013 /** 1014 * Removes all the agent's goals 1015 * 1016 */ 1017 public void removeAllGoals() { 1018 1019 synchronized (this) 1020 { 1021 _goals.clear(); 1022 _options.clear(); 1023 _intentions.clear(); 1024 } 1025 } 1026 1027 /** 1028 * Removes a given goal from the agent's goal list 1029 * @param goalName - the name of the goal to remove 1030 */ 1031 public void removeGoal(String goalName) { 1032 Goal g; 1033 1034 synchronized (this) 1035 { 1036 for(int i=0; i < _goals.size(); i++) { 1037 g = (Goal) _goals.get(i); 1038 if(goalName.equals(g.getName().toString())) { 1039 _goals.remove(i); 1040 break; 1041 } 1042 } 1043 } 1044 } 1045 1046 1047 public void removeIntention(Intention i) 1048 { 1049 if(i.isRootIntention()) 1050 { 1051 synchronized(this) 1052 { 1053 _intentions.remove(i.getGoal().getNameWithCharactersOrdered().toString()); 1054 } 1055 _currentIntention = null; 1056 } 1057 else 1058 { 1059 //TODO remove or change this 1060 this.removeIntention(i.getParentIntention()); 1061 //i.getParentIntention().RemoveSubIntention(); 1062 } 1179 1063 } 1180 1064 … … 1192 1076 _selectedActionEmotion = null; 1193 1077 } 1194 1195 public void RemoveIntention(Intention i) 1196 { 1197 if(i.isRootIntention()) 1198 { 1199 synchronized(this) 1200 { 1201 _intentions.remove(i.getGoal().getNameWithCharactersOrdered().toString()); 1202 } 1203 _currentIntention = null; 1204 } 1205 else 1206 { 1207 //TODO remove or change this 1208 this.RemoveIntention(i.getParentIntention()); 1209 //i.getParentIntention().RemoveSubIntention(); 1210 } 1211 } 1212 1213 /** 1214 * Forces the recalculation of all plan's probability 1215 */ 1216 public void UpdateProbabilities() { 1217 1218 Iterator<Intention> it; 1219 1220 it = _intentions.values().iterator(); 1221 while (it.hasNext()) { 1222 ((Intention) it.next()).UpdateProbabilities(); 1223 } 1224 } 1225 1226 1227 public float getExpectedUtility(AgentModel am, ActivePursuitGoal g) { 1228 return _UStrategy.getUtility(am, g) * _PStrategy.getProbability(am, g); 1229 } 1230 1231 public float getExpectedUtility(AgentModel am, Intention i) { 1232 return _UStrategy.getUtility(am, i.getGoal()) * _PStrategy.getProbability(am, i); 1233 } 1234 1078 1079 public void setDetectThreatStrategy(IDetectThreatStrategy strat) 1080 { 1081 _isThreatStrat = strat; 1082 } 1083 1084 public void setExpectedUtilityStrategy(IExpectedUtilityStrategy strategy) 1085 { 1086 _EUStrategy = strategy; 1087 } 1088 1089 public void setProbabilityStrategy(IProbabilityStrategy strategy) 1090 { 1091 _PStrategy = strategy; 1092 } 1093 1094 1095 public void setUtilityForOthersStrategy(IGetUtilityForOthers strat) 1096 { 1097 _UOthersStrategy = strat; 1098 } 1099 1100 1101 public void setUtilityStrategy(IUtilityStrategy strategy) 1102 { 1103 _UStrategy = strategy; 1104 } 1105 1106 /** 1107 * Determines an answer to a SpeechAct according to the agent's goals and plans 1108 * @return the best answer to give according to its influence on the agent's 1109 * goals and plans 1110 */ 1111 /* 1112 public ValuedAction AnswerToSpeechAct(SpeechAct speechAct) { 1113 Step positiveAnswer; 1114 Step negativeAnswer; 1115 Name positiveSpeech; 1116 Name negativeSpeech; 1117 float positiveAnswerIntensity; 1118 float negativeAnswerIntensity; 1119 ArrayList bindings; 1120 Name action; 1121 Name goalFailure; 1122 float actionValue; 1123 Goal g; 1124 1125 positiveSpeech = Name.ParseName("Reply(" + speechAct.getSender() + "," + speechAct.getMeaning() + ",positiveanswer)"); 1126 negativeSpeech = Name.ParseName("Reply(" + speechAct.getSender() + "," + speechAct.getMeaning() + ",negativeanswer)"); 1127 1128 //check if the speech act refers to any goal 1129 synchronized (this) 1130 { 1131 ListIterator li = _goals.listIterator(); 1132 while(li.hasNext()) { 1133 g = (Goal) li.next(); 1134 if(g.GetName().GetFirstLiteral().toString().equals(speechAct.getMeaning())) { 1135 //in this case, the user is suggesting that the agent should try to achieve this goal 1136 //if the agent tried previously to achieve it and the goal failed, it will reply no way 1137 goalFailure = Name.ParseName(g.GenerateGoalStatus(Goal.GOALFAILURE)); 1138 bindings = KnowledgeBase.GetInstance().GetPossibleBindings(goalFailure); 1139 if (bindings != null) { 1140 return new ValuedAction(negativeSpeech,10); 1141 } 1142 else { 1143 //if the goal didn't failed before, the agent will accept the user sugestion by increasing 1144 //the goal's importance 1145 g.IncreaseImportanceOfFailure(4); 1146 g.IncreaseImportanceOfSuccess(4); 1147 return new ValuedAction(positiveSpeech,10); 1148 } 1149 } 1150 } 1151 } 1152 1153 1154 positiveAnswer = _planner.GetStep(positiveSpeech); 1155 if(positiveAnswer != null) { 1156 positiveAnswerIntensity = _planner.AppraiseAnswer(positiveAnswer); 1157 } 1158 else positiveAnswerIntensity = 0; 1159 negativeAnswer = _planner.GetStep(negativeSpeech); 1160 if(negativeAnswer != null) { 1161 negativeAnswerIntensity = _planner.AppraiseAnswer(negativeAnswer); 1162 } 1163 else negativeAnswerIntensity = 0; 1164 1165 if(positiveAnswerIntensity >= negativeAnswerIntensity) { 1166 if(positiveAnswer != null) 1167 { 1168 action = positiveAnswer.getName(); 1169 actionValue = positiveAnswerIntensity - negativeAnswerIntensity; 1170 } 1171 else return null; 1172 } 1173 else { 1174 if(negativeAnswer != null) 1175 { 1176 action = negativeAnswer.getName(); 1177 actionValue = negativeAnswerIntensity - positiveAnswerIntensity; 1178 } 1179 else return null; 1180 } 1181 1182 return new ValuedAction(action,actionValue); 1183 } 1184 */ 1185 1235 1186 @Override 1236 public String name() { 1237 return DeliberativeProcess.NAME; 1238 } 1239 1240 @Override 1241 public void initialize(AgentModel ag) { 1242 } 1243 1187 public void update(AgentModel am, Event event) { 1188 ArrayList<IPlanningOperator> canceledActions; 1189 1190 if(_selectedPlan != null) 1191 { 1192 canceledActions = _selectedPlan.UpdatePlan(am); 1193 1194 if(_actionMonitor != null) 1195 { 1196 for(IPlanningOperator op : canceledActions) 1197 { 1198 if(_actionMonitor.getStep().getName().equals(op.getName())) 1199 { 1200 cancelAction(am); 1201 checkLinks(am); 1202 return; 1203 } 1204 } 1205 1206 } 1207 } 1208 1209 checkLinks(am); 1210 1211 if(_actionMonitor != null && _actionMonitor.matchEvent(event)) { 1212 if(_actionMonitor.getStep().getAgent().isGrounded() && 1213 !_actionMonitor.getStep().getAgent().toString().equals(Constants.SELF)) 1214 { 1215 //the agent was waiting for an action of other agent to be complete 1216 //since the step of another agent may contain unbound variables, 1217 //we cannot just compare the names, we need to try to unify them 1218 if(Unifier.Unify(event.toStepName(), 1219 _actionMonitor.getStep().getName()) != null) 1220 { 1221 _actionMonitor.getStep().IncreaseProbability(am); 1222 //System.out.println("Calling updateEffectsProbability (other's action: step completed)"); 1223 _actionMonitor.getStep().updateEffectsProbability(am); 1224 } 1225 else 1226 { 1227 for(IActionFailureStrategy s : _actionFailureStrategies) 1228 { 1229 s.perceiveActionFailure(am, _actionMonitor.getStep()); 1230 } 1231 1232 _actionMonitor.getStep().DecreaseProbability(am); 1233 } 1234 } 1235 else 1236 { 1237 for(IActionSuccessStrategy s : _actionSuccessStrategies) 1238 { 1239 s.perceiveActionSuccess(am, _actionMonitor.getStep()); 1240 } 1241 //System.out.println("Calling updateEffectsProbability (self: step completed)"); 1242 _actionMonitor.getStep().updateEffectsProbability(am); 1243 } 1244 1245 updateProbabilities(); 1246 _actionMonitor = null; 1247 } 1248 } 1249 1244 1250 @Override 1245 1251 public void update(AgentModel am, long time) … … 1247 1253 if(_actionMonitor != null) 1248 1254 { 1249 if(_actionMonitor.expired() || !_actionMonitor.checkPreconditions(am))1250 { 1251 AgentLogger.GetInstance().logAndPrint("Action monitor failed orexpired: " + _actionMonitor.toString());1252 //If the action expired or failedwe must check the plan links (continuous planning)1255 if(_actionMonitor.expired()) 1256 { 1257 AgentLogger.GetInstance().logAndPrint("Action monitor expired: " + _actionMonitor.toString()); 1258 //If the action expired we must check the plan links (continuous planning) 1253 1259 //just to make sure 1254 CheckLinks(am);1260 checkLinks(am); 1255 1261 1256 1262 for(IActionFailureStrategy s : _actionFailureStrategies) … … 1260 1266 _actionMonitor.getStep().DecreaseProbability(am); 1261 1267 1262 UpdateProbabilities();1268 updateProbabilities(); 1263 1269 1264 cancelAction(am);1265 1270 _actionMonitor = null; 1266 1271 } … … 1268 1273 } 1269 1274 1270 1271 @Override 1272 public IComponent createModelOfOther() { 1273 return new DeliberativeProcess(_goalLibrary, _planner); 1274 } 1275 1276 1277 @Override 1278 public AgentDisplayPanel createDisplayPanel(AgentModel am) { 1279 return null; 1280 } 1281 1282 @Override 1283 public void appraisal(AgentModel am, Event e, AppraisalFrame as) { 1284 } 1285 1286 @Override 1287 public AppraisalFrame reappraisal(AgentModel am) { 1288 return null; 1289 } 1290 1291 @Override 1292 public void inverseAppraisal(AgentModel am, AppraisalFrame af) { 1275 /** 1276 * Forces the recalculation of all plan's probability 1277 */ 1278 public void updateProbabilities() { 1279 1280 Iterator<Intention> it; 1281 1282 it = _intentions.values().iterator(); 1283 while (it.hasNext()) { 1284 ((Intention) it.next()).UpdateProbabilities(); 1285 } 1293 1286 } 1294 1287 } -
AgentMind/branches/FAtiMA-Modular/FAtiMA/src/FAtiMA/Core/deliberativeLayer/EmotionalPlanner.java
r922 r950 114 114 115 115 import FAtiMA.Core.AgentModel; 116 import FAtiMA.Core.IntegrityValidator;117 116 import FAtiMA.Core.OCCAffectDerivation.OCCAppraisalVariables; 118 117 import FAtiMA.Core.OCCAffectDerivation.OCCBaseEmotion; … … 131 130 import FAtiMA.Core.deliberativeLayer.plan.Plan; 132 131 import FAtiMA.Core.deliberativeLayer.plan.ProtectedCondition; 133 import FAtiMA.Core.deliberativeLayer.plan.Step;134 132 import FAtiMA.Core.emotionalState.ActiveEmotion; 135 133 import FAtiMA.Core.emotionalState.AppraisalFrame; 136 import FAtiMA.Core.exceptions.UnknownSpeechActException;137 import FAtiMA.Core.exceptions.UnspecifiedVariableException;138 134 import FAtiMA.Core.util.AgentLogger; 139 135 import FAtiMA.Core.util.Constants; … … 152 148 private static final long serialVersionUID = 1L; 153 149 154 private ArrayList<Step> _actions;150 155 151 private int _variableIdentifier; 156 152 … … 162 158 * @param es - the character's emotional state 163 159 */ 164 public EmotionalPlanner( ArrayList<Step> operators)160 public EmotionalPlanner() 165 161 { 166 162 this._variableIdentifier = 1; 167 //this._closedGoals = new HashMap();168 this._actions = operators;169 163 } 170 164 … … 211 205 return answerUtility; 212 206 }*/ 213 214 /**215 * Checks the integrity of the Planner operators/Steps/actions.216 * For instance it checks if a operator references a SpeechAct not217 * defined, or if it uses a unbound variable (in effects or preconditions)218 * not used in the operator's name219 * @param val - the IntegrityValidator used to detect problems220 * @throws UnspecifiedVariableException - thrown when the operator uses a unbound221 * variable in the effects or preconditions222 * without using the same variable in the223 * step's name224 * @throws UnknownSpeechActException - thrown when the operator references a225 * SpeechAct not defined226 */227 public void CheckIntegrity(IntegrityValidator val) throws UnspecifiedVariableException, UnknownSpeechActException {228 ListIterator<Step> li = _actions.listIterator();229 230 while(li.hasNext()) {231 li.next().CheckIntegrity(val);232 }233 }234 207 235 208 … … 246 219 * Step, false - uses the steps that the received plan contains 247 220 */ 248 public void FindStepFor( Intention intention, Plan p, OpenPrecondition openPrecond, boolean newStep) {221 public void FindStepFor(AgentModel am, Intention intention, Plan p, OpenPrecondition openPrecond, boolean newStep) { 249 222 ListIterator<? extends IPlanningOperator> li; 250 223 Condition cond; … … 267 240 268 241 if (newStep) 269 li = _actions.listIterator();242 li = am.getActionLibrary().getActions().listIterator(); 270 243 else 271 244 li = p.getSteps().listIterator(); … … 356 329 357 330 358 /** 359 * Gets the planner's operators/steps/actions 360 * @return a list with Steps 361 */ 362 public ArrayList<Step> GetOperators() { 363 return _actions; 364 } 365 366 public void AddOperator(Step op) 367 { 368 _actions.add(op); 369 } 370 371 /** 372 * Gets the operator that corresponds to the given name 373 * @param name - the name of the step to get 374 * @return the searched step if it is found, null otherwise 375 */ 376 public Step GetStep(String name) { 377 378 for(Step s : _actions) 379 { 380 if(s.getName().toString().equals(name)) 381 { 382 return s; 383 } 384 } 385 386 return null; 387 } 331 388 332 389 333 /** … … 400 344 * returns null 401 345 */ 402 public Plan ThinkAbout(AgentModel am, Intention intention) {346 public Plan ThinkAbout(AgentModel am, DeliberativeProcess dp, Intention intention) { 403 347 Plan p; 404 348 Plan newPlan; … … 441 385 442 386 prob = p.getProbability(am); 443 goalProb = am.getDeliberativeLayer().getProbabilityStrategy().getProbability(am, intention.getGoal());387 goalProb = dp.getProbabilityStrategy().getProbability(am, intention.getGoal()); 444 388 if(p.getOpenPreconditions().size() == 0) 445 389 { … … 682 626 //TODO talvez possa fazer isto de uma maneira mais eficiente 683 627 //Tries to find a step in the plan that achieves the precondition 684 FindStepFor( intention, p, openPrecond, false);628 FindStepFor(am,intention, p, openPrecond, false); 685 629 //tries to find a new step from the available actions that achieves the precondition 686 FindStepFor( intention, p, openPrecond, true);630 FindStepFor(am,intention, p, openPrecond, true); 687 631 688 632 } … … 693 637 return null; 694 638 } 639 695 640 //the plan is complete, no flaw was removed 696 641 else return p; … … 706 651 public Plan DevelopPlan(AgentModel am, ActivePursuitGoal goal) 707 652 { 708 Plan p = new Plan(new ArrayList<ProtectedCondition>(),am.getDeliberativeLayer().getDetectThreatStrategy(),goal.GetSuccessConditions()); 653 DeliberativeProcess dp = (DeliberativeProcess) am.getComponent(DeliberativeProcess.NAME); 654 655 Plan p = new Plan(new ArrayList<ProtectedCondition>(),dp.getDetectThreatStrategy(),goal.GetSuccessConditions()); 709 656 Intention i = new Intention(am, goal); 710 657 i.AddPlan(p); … … 713 660 while (i.NumberOfAlternativePlans() > 0) 714 661 { 715 completePlan = ThinkAbout(am, i);662 completePlan = ThinkAbout(am,dp, i); 716 663 if(completePlan != null) 717 664 { -
AgentMind/branches/FAtiMA-Modular/FAtiMA/src/FAtiMA/Core/deliberativeLayer/Intention.java
r922 r950 37 37 import java.io.Serializable; 38 38 import java.util.ArrayList; 39 import java.util.LinkedList;40 39 import java.util.ListIterator; 41 import java.util.SortedSet;42 40 43 41 import FAtiMA.Core.AgentModel; … … 242 240 public float GetProbability(AgentModel am) { 243 241 242 DeliberativeProcess dp = (DeliberativeProcess) am.getComponent(DeliberativeProcess.NAME); 243 244 244 float p; 245 245 float p2; 246 246 float bestProb = 0; 247 float goalProb = am.getDeliberativeLayer().getProbabilityStrategy().getProbability(am, _goal);247 float goalProb = dp.getProbabilityStrategy().getProbability(am, _goal); 248 248 249 249 for(Plan plan : _planConstruction) … … 372 372 public void ProcessIntentionActivation(AgentModel am) 373 373 { 374 DeliberativeProcess dp = (DeliberativeProcess) am.getComponent(DeliberativeProcess.NAME); 374 375 Event e = _goal.GetActivationEvent(); 375 float goalConduciveness = am.getDeliberativeLayer().getUtilityStrategy().getUtility(am, _goal); 376 float probability = am.getDeliberativeLayer().getProbabilityStrategy().getProbability(am, _goal); 376 377 float goalConduciveness = dp.getUtilityStrategy().getUtility(am, _goal); 378 float probability = dp.getProbabilityStrategy().getProbability(am, _goal); 377 379 378 380 AgentLogger.GetInstance().logAndPrint("Adding a new Intention: " + _goal.getName().toString()); … … 396 398 public void ProcessIntentionFailure(AgentModel am) 397 399 { 400 DeliberativeProcess dp = (DeliberativeProcess) am.getComponent(DeliberativeProcess.NAME); 398 401 //mental disengagement consists in lowering the goal's importance 399 402 _goal.DecreaseImportanceOfFailure(am, 0.5f); … … 405 408 AppraisalFrame af = new AppraisalFrame(e); 406 409 af.SetAppraisalVariable(DeliberativeProcess.NAME,(short)8,OCCAppraisalVariables.GOALSTATUS.name(), OCCComponent.GOALDISCONFIRMED); 407 af.SetAppraisalVariable(DeliberativeProcess.NAME, (short)8,OCCAppraisalVariables.GOALCONDUCIVENESS.name(), am.getDeliberativeLayer().getUtilityStrategy().getUtility(am, _goal));410 af.SetAppraisalVariable(DeliberativeProcess.NAME, (short)8,OCCAppraisalVariables.GOALCONDUCIVENESS.name(), dp.getUtilityStrategy().getUtility(am, _goal)); 408 411 am.updateEmotions(af); 409 412 … … 433 436 public void ProcessIntentionSuccess(AgentModel am) 434 437 { 438 DeliberativeProcess dp = (DeliberativeProcess) am.getComponent(DeliberativeProcess.NAME); 435 439 if(!isRootIntention()) 436 440 { … … 442 446 AppraisalFrame af = new AppraisalFrame(e); 443 447 af.SetAppraisalVariable(DeliberativeProcess.NAME,(short)8,OCCAppraisalVariables.GOALSTATUS.name(), OCCComponent.GOALCONFIRMED); 444 af.SetAppraisalVariable(DeliberativeProcess.NAME, (short)8,OCCAppraisalVariables.GOALCONDUCIVENESS.name(), am.getDeliberativeLayer().getUtilityStrategy().getUtility(am, _goal));448 af.SetAppraisalVariable(DeliberativeProcess.NAME, (short)8,OCCAppraisalVariables.GOALCONDUCIVENESS.name(), dp.getUtilityStrategy().getUtility(am, _goal)); 445 449 am.updateEmotions(af); 446 450 -
AgentMind/branches/FAtiMA-Modular/FAtiMA/src/FAtiMA/Core/deliberativeLayer/plan/Plan.java
r801 r950 112 112 import FAtiMA.Core.AgentModel; 113 113 import FAtiMA.Core.conditions.Condition; 114 import FAtiMA.Core.deliberativeLayer.ActionMonitor; 114 115 import FAtiMA.Core.deliberativeLayer.IDetectThreatStrategy; 115 116 import FAtiMA.Core.util.AgentLogger; … … 620 621 * such continuous planning flaws. This method should be called whenever the world changes. 621 622 */ 622 public voidUpdatePlan(AgentModel am)623 public ArrayList<IPlanningOperator> UpdatePlan(AgentModel am) 623 624 { 624 625 CausalLink link; … … 628 629 Condition cond; 629 630 IPlanningOperator op; 631 632 ArrayList<IPlanningOperator> canceledActions = new ArrayList<IPlanningOperator>(); 630 633 631 634 … … 651 654 652 655 //TODO Extending a causal link to start might be causing problems with 653 // the planning algorithm 656 // the planning algorithm (for instance, you may not want to extend a causal link to start 657 // because doing so will lead to a dead end, and instead you want to use another action 654 658 op = getOperator(link.getDestination()); 655 659 cond = op.getPrecondition(link.getCondition()); … … 764 768 .getDestination(), link.getCondition())); 765 769 linksToRemove.add(link); 770 771 canceledActions.add(op); 772 773 766 774 } 767 775 } … … 770 778 //finally at the end of the second stage we must still remove 771 779 //all the unsupported links that were found 780 //in this case we don't need to remove redundant steps, because 781 //the Start Step is never redundant, and furthermore we cannot remove it 772 782 for(ListIterator<CausalLink> li = linksToRemove.listIterator(); li.hasNext();) 773 783 { 774 784 link = (CausalLink) li.next(); 775 785 RemoveCausalLink(link); 776 //in this case we don't need to remove redundant steps, because777 //the Start Step is never redundant, and furthermore we cannot remove it778 }786 } 787 788 return canceledActions; 779 789 } 780 790 -
AgentMind/branches/FAtiMA-Modular/FAtiMA/src/FAtiMA/Core/emotionalState/EmotionalState.java
r922 r950 240 240 Iterator<ActiveEmotion> it; 241 241 242 long currentTime = AgentSimulationTime.GetInstance().Time();; 243 if (currentTime >= _lastTime + 1000) { 242 long currentTime = AgentSimulationTime.GetInstance().Time(); 243 long deltaTime = currentTime - _lastTime; 244 if (deltaTime >= 1000L) { 244 245 _lastTime = currentTime; 245 246 -
AgentMind/branches/FAtiMA-Modular/FAtiMA/src/FAtiMA/Core/sensorEffector/RemoteAgent.java
r926 r950 707 707 String goalName = st.nextToken(); 708 708 float importance = new Float(st.nextToken()).floatValue(); 709 _agent.getDeliberativeLayer(). ChangeGoalImportance(_agent, goalName,importance,type);709 _agent.getDeliberativeLayer().changeGoalImportance(_agent, goalName,importance,type); 710 710 } 711 711 … … 801 801 importance2 = new Float(st2.nextToken()).floatValue(); 802 802 try { 803 _agent.getDeliberativeLayer(). AddGoal(_agent, goalName,importance,importance2);803 _agent.getDeliberativeLayer().addGoal(_agent, goalName,importance,importance2); 804 804 } 805 805 catch(Exception e) { … … 811 811 protected void RemoveGoalPerception(String perc) 812 812 { 813 _agent.getDeliberativeLayer(). RemoveGoal(perc);813 _agent.getDeliberativeLayer().removeGoal(perc); 814 814 } 815 815 816 816 protected void RemoveAllGoalsPerception(String perc) 817 817 { 818 _agent.getDeliberativeLayer(). RemoveAllGoals();818 _agent.getDeliberativeLayer().removeAllGoals(); 819 819 } 820 820 -
AgentMind/branches/FAtiMA-Modular/FAtiMA/src/FAtiMA/Core/util/parsers/AgentLoaderHandler.java
r896 r950 201 201 } 202 202 203 _deliberativeLayer. AddGoal(_am, _goalName,impOfSucess,impOfFailure);203 _deliberativeLayer.addGoal(_am, _goalName,impOfSucess,impOfFailure); 204 204 } 205 205 -
AgentMind/branches/FAtiMA-Modular/WorldTest/src/RemoteAgent.java
r718 r950 31 31 public class RemoteAgent extends SocketListener { 32 32 33 final static int MIN_ACTION_DELAY_MS = 500;34 final static int MAX_ACTION_DELAY_MS = 500;33 final static int MIN_ACTION_DELAY_MS = 10000; 34 final static int MAX_ACTION_DELAY_MS = 10000; 35 35 protected Random _generator; 36 36 private ArrayList<Property> _properties; … … 343 343 aux2= aux2 + " " + x; 344 344 } 345 346 345 347 346 348 synchronized(_ra){ … … 350 352 String perception = "ACTION-FINISHED " + aux; 351 353 synchronized(_world){ 352 _world.GetUserInterface().WriteLine(aux);353 354 _world.SendPerceptionToAll(perception); 355 _world.GetUserInterface().WriteLine(aux); 354 356 } 357 355 358 } 356 359 } -
AgentMind/branches/FAtiMA-Modular/WorldTest/src/UserInterface.java
r868 r950 363 363 364 364 public void actionPerformed(ActionEvent evt) { 365 String perception = "ACTION-FINISHED " + inputList.getSelectedItem().toString(); 366 this.WriteLine(inputList.getSelectedItem().toString()); 367 _world.SendPerceptionToAll(perception); 368 StringTokenizer st = new StringTokenizer(inputList.getSelectedItem().toString(), " "); 365 StringTokenizer st = new StringTokenizer(inputList.getSelectedItem().toString(), " "); 369 366 if(st.countTokens() > 1) 370 367 { … … 375 372 this.UpdateActionEffects(subject, ConvertToActionName(action)); 376 373 } 374 375 String perception = "ACTION-FINISHED " + inputList.getSelectedItem().toString(); 376 this.WriteLine(inputList.getSelectedItem().toString()); 377 _world.SendPerceptionToAll(perception); 377 378 } 378 379
Note: See TracChangeset
for help on using the changeset viewer.