@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())); } }
public void perform_1(Context context) throws LogoException { if (context.atTopActivation()) { context.ip = offset; } else { // if we're inside an ask inside the current procedure, then we have // to do normal recursion, not "fast" tail recursion - ST 11/17/04 original.perform(context); } }
public void perform_1(Context context) { try { ((Turtle) context.agent).jump(1); } catch (org.nlogo.api.AgentException e) { } // NOPMD context.ip = next; }
@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; }
@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; }
// identical to perform_1() above... BUT with a profiling hook added public void profiling_perform_1(final org.nlogo.nvm.Context context) { if (!context.atTopActivation()) { context.finished = true; } else { if (context.activation.procedure().isReporter() || context.activation.procedure().isTask() && context.activation.procedure().parent().isReporter()) { throw new EngineException( context, this, I18N.errorsJ() .getN("org.nlogo.prim.etc._stop.notAllowedInsideToReport", displayName())); } workspace.profilingTracer().closeCallRecord(context, context.activation); context.stop(); } }
@Override public void perform(final org.nlogo.nvm.Context context) { Turtle turtle = argEvalTurtle(context, 0); if (turtle.id() == -1) { throw new EngineException( context, this, I18N.errorsJ().getN("org.nlogo.$common.thatAgentIsDead", turtle.classDisplayName())); } world.observer().setPerspective(PerspectiveJ.RIDE(), turtle); context.ip = next; }
public void perform_1(final org.nlogo.nvm.Context context) { // check: are we in an ask? if (!context.atTopActivation()) { // if so, then "stop" means that this agent prematurely // finishes its participation in the ask. context.finished = true; } else { // if we're not in an ask, then "stop" means to exit this procedure // immediately. first we must check that it's a command procedure // and not a reporter procedure. if (context.activation.procedure().isReporter() || context.activation.procedure().isTask() && context.activation.procedure().parent().isReporter()) { throw new EngineException( context, this, I18N.errorsJ() .getN("org.nlogo.prim.etc._stop.notAllowedInsideToReport", displayName())); } context.stop(); } }
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; }
@Override public void perform(final Context context) { AgentSet nodeset = argEvalAgentSet(context, 0, AgentKindJ.Turtle()); AgentSet linkset = argEvalAgentSet(context, 1, AgentKindJ.Link()); double springConstant = argEvalDoubleValue(context, 2); double springLength = argEvalDoubleValue(context, 3); double repulsionConstant = argEvalDoubleValue(context, 4); org.nlogo.agent.Layouts.spring( world, nodeset, linkset, springConstant, springLength, repulsionConstant, context.job.random); context.ip = next; }
public void perform_1(final Context context) { Turtle turtle = (Turtle) context.agent; turtle.moveToPatchCenter(); Patch patch = turtle.getPatchHere(); double winningValue = Double.MAX_VALUE; List<Patch> winners = new ArrayList<Patch>(); for (AgentSet.Iterator it = patch.getNeighbors4().iterator(); it.hasNext(); ) { Patch tester = (Patch) it.next(); Object value = tester.getPatchVariable(reference.vn()); if (!(value instanceof Double)) { continue; } double dvalue = ((Double) value).doubleValue(); // need to be careful here to handle properly the case where // dvalue equals Double.MAX_VALUE - ST 10/11/04, 1/6/07 if (dvalue <= winningValue) { if (dvalue < winningValue) { winningValue = dvalue; winners.clear(); } winners.add(tester); } } if (!winners.isEmpty() && (!(patch.getPatchVariable(reference.vn()) instanceof Double) || winningValue < ((Double) patch.getPatchVariable(reference.vn())).doubleValue())) { Patch winner = winners.get(context.job.random.nextInt(winners.size())); turtle.face(winner, true); try { turtle.moveTo(winner); } catch (AgentException ex) { // should be impossible throw new IllegalStateException(ex); } } context.ip = next; }
public void finish() { state = DONE; if (parentContext != null) { parentContext.waiting = false; } }