예제 #1
0
 protected boolean beginExecution(final IScope scope) throws GamaRuntimeException {
   final IAgent agent = scope.getAgentScope();
   if (scope.interrupted()) {
     return false;
   }
   final Boolean enter = (Boolean) agent.getAttribute(ENTER);
   Map<String, Object> memory = (Map) agent.getAttribute(STATE_MEMORY);
   if (enter || memory == null) {
     memory = new THashMap();
     agent.setAttribute(STATE_MEMORY, memory);
   } else {
     for (final Map.Entry<String, Object> entry : memory.entrySet()) {
       scope.addVarWithValue(entry.getKey(), entry.getValue());
     }
   }
   if (enter) {
     if (enterActions != null) {
       enterActions.executeOn(scope);
     }
     if (agent.dead()) {
       return false;
     }
     agent.setAttribute(ENTER, false);
   }
   return true;
 }
예제 #2
0
 @Override
 public IList<ISpecies> getMicroSpecies() {
   final IList<ISpecies> retVal = GamaListFactory.create(Types.SPECIES);
   retVal.addAll(microSpecies.values());
   final ISpecies parentSpecies = this.getParentSpecies();
   if (parentSpecies != null) {
     retVal.addAll(parentSpecies.getMicroSpecies());
   }
   return retVal;
 }
예제 #3
0
 /**
  * Returns a micro-species with the specified name or null otherwise.
  *
  * @param microSpeciesName
  * @return a species or null
  */
 @Override
 public ISpecies getMicroSpecies(final String microSpeciesName) {
   final ISpecies retVal = microSpecies.get(microSpeciesName);
   if (retVal != null) {
     return retVal;
   }
   final ISpecies parentSpecies = this.getParentSpecies();
   if (parentSpecies != null) {
     return parentSpecies.getMicroSpecies(microSpeciesName);
   }
   return null;
 }
예제 #4
0
 @Override
 public void setChildren(final List<? extends ISymbol> children) {
   // First we verify the control architecture
   final IArchitecture control = getArchitecture();
   if (control == null) {
     throw GamaRuntimeException.error(
         "The control of species " + description.getName() + " cannot be computed");
   }
   // Then we classify the children in their categories
   for (final ISymbol s : children) {
     if (s instanceof ISpecies) {
       final ISpecies oneMicroSpecies = (ISpecies) s;
       oneMicroSpecies.setMacroSpecies(this);
       microSpecies.put(oneMicroSpecies.getName(), oneMicroSpecies);
     } else if (s instanceof IVariable) {
       variables.put(s.getName(), (IVariable) s);
     } else if (s instanceof AspectStatement) {
       aspects.put(s.getName(), (AspectStatement) s);
     } else if (s instanceof ActionStatement) {
       if (!s.getDescription().isBuiltIn()) {
         String name = s.getName();
         if (name.equals(initActionName)) {
           isInitOverriden = true;
         } else if (name.equals(stepActionName)) {
           isStepOverriden = true;
         }
       }
       actions.put(s.getName(), (ActionStatement) s);
     } else if (s instanceof UserCommandStatement) {
       userCommands.put(s.getName(), (UserCommandStatement) s);
     } else if (s instanceof IStatement) {
       behaviors.add((IStatement) s); // reflexes, states or tasks
     }
   }
   control.setChildren(behaviors);
   control.verifyBehaviors(this);
 }
예제 #5
0
 @Override
 public void dispose() {
   super.dispose();
   for (final IVariable v : variables.values()) {
     v.dispose();
   }
   variables.clear();
   for (final AspectStatement ac : aspects.values()) {
     ac.dispose();
   }
   aspects.clear();
   for (final ActionStatement ac : actions.values()) {
     ac.dispose();
   }
   actions.clear();
   for (final IStatement c : behaviors) {
     c.dispose();
   }
   behaviors.clear();
   macroSpecies = null;
   parentSpecies = null;
   // TODO dispose micro_species first???
   microSpecies.clear();
 }
예제 #6
0
 @Override
 public Collection<String> getMicroSpeciesNames() {
   return microSpecies.keySet();
 }
예제 #7
0
 @Override
 public Collection<UserCommandStatement> getUserCommands() {
   return userCommands.values();
 }
예제 #8
0
 @Override
 public Collection<? extends IExecutable> getAspects() {
   return aspects.values();
 }
예제 #9
0
 @Override
 public List<String> getAspectNames() {
   return new ArrayList<String>(aspects.keySet());
 }
예제 #10
0
 @Override
 public boolean hasAspect(final String n) {
   return aspects.containsKey(n);
 }
예제 #11
0
 @Override
 public IExecutable getAspect(final String n) {
   return aspects.get(n);
 }
예제 #12
0
 @Override
 public WithArgs getAction(final String name) {
   return actions.get(name);
 }
예제 #13
0
 @Override
 public Collection<ActionStatement> getActions() {
   return actions.values();
 }
예제 #14
0
 @Override
 public boolean containMicroSpecies(final ISpecies species) {
   final ISpecies parentSpecies = this.getParentSpecies();
   return microSpecies.values().contains(species)
       || (parentSpecies != null ? parentSpecies.containMicroSpecies(species) : false);
 }
예제 #15
0
 @Override
 public Collection<IVariable> getVars() {
   return variables.values();
 }
예제 #16
0
 @Override
 public boolean hasVar(final String name) {
   return variables.containsKey(name);
 }
예제 #17
0
 @Override
 public IVariable getVar(final String n) {
   return variables.get(n);
 }
예제 #18
0
 @Override
 public boolean hasMicroSpecies() {
   final ISpecies parentSpecies = this.getParentSpecies();
   return !microSpecies.isEmpty()
       || (parentSpecies != null ? parentSpecies.hasMicroSpecies() : false);
 }