Exemplo n.º 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;
 }
Exemplo n.º 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;
 }
Exemplo n.º 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;
 }
Exemplo n.º 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);
 }
Exemplo n.º 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();
 }
Exemplo n.º 6
0
 @Override
 public Collection<String> getMicroSpeciesNames() {
   return microSpecies.keySet();
 }
Exemplo n.º 7
0
 @Override
 public Collection<UserCommandStatement> getUserCommands() {
   return userCommands.values();
 }
Exemplo n.º 8
0
 @Override
 public Collection<? extends IExecutable> getAspects() {
   return aspects.values();
 }
Exemplo n.º 9
0
 @Override
 public List<String> getAspectNames() {
   return new ArrayList<String>(aspects.keySet());
 }
Exemplo n.º 10
0
 @Override
 public boolean hasAspect(final String n) {
   return aspects.containsKey(n);
 }
Exemplo n.º 11
0
 @Override
 public IExecutable getAspect(final String n) {
   return aspects.get(n);
 }
Exemplo n.º 12
0
 @Override
 public WithArgs getAction(final String name) {
   return actions.get(name);
 }
Exemplo n.º 13
0
 @Override
 public Collection<ActionStatement> getActions() {
   return actions.values();
 }
Exemplo n.º 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);
 }
Exemplo n.º 15
0
 @Override
 public Collection<IVariable> getVars() {
   return variables.values();
 }
Exemplo n.º 16
0
 @Override
 public boolean hasVar(final String name) {
   return variables.containsKey(name);
 }
Exemplo n.º 17
0
 @Override
 public IVariable getVar(final String n) {
   return variables.get(n);
 }
Exemplo n.º 18
0
 @Override
 public boolean hasMicroSpecies() {
   final ISpecies parentSpecies = this.getParentSpecies();
   return !microSpecies.isEmpty()
       || (parentSpecies != null ? parentSpecies.hasMicroSpecies() : false);
 }