コード例 #1
0
ファイル: _minoneof.java プロジェクト: firatsoylu/NetLogo
 @Override
 public Object report(final Context context) throws LogoException {
   AgentSet sourceSet = argEvalAgentSet(context, 0);
   args[1].checkAgentSetClass(sourceSet, context);
   double winningValue = Double.MAX_VALUE;
   List<Agent> winners = new ArrayList<Agent>();
   org.nlogo.nvm.Context freshContext = new org.nlogo.nvm.Context(context, sourceSet);
   for (AgentSet.Iterator iter = sourceSet.iterator(); iter.hasNext(); ) {
     org.nlogo.agent.Agent tester = iter.next();
     Object result = freshContext.evaluateReporter(tester, args[1]);
     if (!(result instanceof Double)) {
       continue;
     }
     double dvalue = ((Double) result).doubleValue();
     // need to be careful here to handle properly the case where
     // dvalue equals Double.MAX_VALUE - ST 10/11/04
     if (dvalue <= winningValue) {
       if (dvalue < winningValue) {
         winningValue = dvalue;
         winners.clear();
       }
       winners.add(tester);
     }
   }
   if (winners.isEmpty()) {
     return org.nlogo.api.Nobody$.MODULE$;
   } else {
     return winners.get(context.job.random.nextInt(winners.size()));
   }
 }
コード例 #2
0
ファイル: _member.java プロジェクト: stepheneb/NetLogo
 @Override
 public Object report(final org.nlogo.nvm.Context context) throws LogoException {
   Object obj = args[1].report(context);
   if (obj instanceof LogoList) {
     Object value = args[0].report(context);
     LogoList list = (LogoList) obj;
     for (Iterator<Object> it = list.iterator(); it.hasNext(); ) {
       if (Equality.equals(value, it.next())) {
         return Boolean.TRUE;
       }
     }
     return Boolean.FALSE;
   } else if (obj instanceof String) {
     return ((String) obj).indexOf(argEvalString(context, 0)) != -1 ? Boolean.TRUE : Boolean.FALSE;
   } else if (obj instanceof AgentSet) {
     Agent agent = argEvalAgent(context, 0);
     AgentSet agentset = (AgentSet) obj;
     if (agent instanceof Turtle) {
       if (agent.id == -1) {
         return Boolean.FALSE;
       }
       if (agentset.type() != Turtle.class) {
         return Boolean.FALSE;
       }
       if (agentset == world.turtles()) {
         return Boolean.TRUE;
       }
       if (world.isBreed(agentset)) {
         return agentset == ((Turtle) agent).getBreed() ? Boolean.TRUE : Boolean.FALSE;
       }
     }
     if (agent instanceof Link) {
       if (agent.id == -1) {
         return Boolean.FALSE;
       }
       if (agentset.type() != Link.class) {
         return Boolean.FALSE;
       }
       if (agentset == world.links()) {
         return Boolean.TRUE;
       }
       if (world.isBreed(agentset)) {
         return agentset == ((Link) agent).getBreed() ? Boolean.TRUE : Boolean.FALSE;
       }
     } else if (agent instanceof Patch) {
       if (agentset.type() != Patch.class) {
         return Boolean.FALSE;
       }
       if (agentset == world.patches()) {
         return Boolean.TRUE;
       }
     }
     return agentset.contains(agent) ? Boolean.TRUE : Boolean.FALSE;
   } else {
     throw new ArgumentTypeException(
         context, this, 1, Syntax.ListType() | Syntax.StringType() | Syntax.AgentsetType(), obj);
   }
 }
コード例 #3
0
ファイル: Context.java プロジェクト: aditiwagh/NetLogo
 // ...while these constructors are used when one Context spawns
 // another Context directly without an intervening Job, such as
 // with _with. - ST 6/12/06
 public Context(Context context, AgentSet agents) {
   job = context.job;
   activation = context.activation;
   letBindings = context.letBindings;
   myself = context.agent;
   agentBit = agents.agentBit();
 }
コード例 #4
0
 @Override
 public void perform(final org.nlogo.nvm.Context context) throws LogoException {
   int numberOfTurtles = argEvalIntValue(context, 0);
   if (numberOfTurtles > 0) {
     AgentSet agentset =
         new org.nlogo.agent.ArrayAgentSet(Turtle.class, numberOfTurtles, false, world);
     AgentSet breed = breedName == NO_BREED ? world.turtles() : world.getBreed(breedName);
     org.nlogo.util.MersenneTwisterFast random = context.job.random;
     for (int i = 0; i < numberOfTurtles; i++) {
       Turtle turtle = world.createTurtle(breed, random.nextInt(14), random.nextInt(360));
       agentset.add(turtle);
       workspace.joinForeverButtons(turtle);
     }
     context.runExclusiveJob(agentset, next);
   }
   context.ip = offset;
 }
コード例 #5
0
 @Override
 public void perform(final Context context) throws LogoException {
   int numberOfTurtles = argEvalIntValue(context, 0);
   if (numberOfTurtles > 0) {
     AgentSet agentset = new ArrayAgentSet(Turtle.class, numberOfTurtles, false, world);
     AgentSet breed = breedName == NO_BREED ? world.turtles() : world.getBreed(breedName);
     for (int i = 0; i < numberOfTurtles; i++) {
       Turtle turtle = world.createTurtle(breed);
       turtle.colorDouble(Double.valueOf(10.0 * i + 5.0));
       turtle.heading((360.0 * i) / numberOfTurtles);
       agentset.add(turtle);
       workspace.joinForeverButtons(turtle);
     }
     context.runExclusiveJob(agentset, next);
   }
   context.ip = offset;
 }
コード例 #6
0
ファイル: _countwith.java プロジェクト: stepheneb/NetLogo
 public double report_1(Context context, AgentSet sourceSet, Reporter block) throws LogoException {
   block.checkAgentSetClass(sourceSet, context);
   Context freshContext = new Context(context, sourceSet);
   int result = 0;
   for (AgentSet.Iterator iter = sourceSet.iterator(); iter.hasNext(); ) {
     Agent tester = iter.next();
     Object value = freshContext.evaluateReporter(tester, block);
     if (!(value instanceof Boolean)) {
       throw new EngineException(
           context,
           this,
           I18N.errorsJ()
               .getN(
                   "org.nlogo.prim.$common.expectedBooleanValue",
                   displayName(),
                   Dump.logoObject(tester),
                   Dump.logoObject(value)));
     }
     if (((Boolean) value).booleanValue()) {
       result++;
     }
   }
   return result;
 }