Package org.nlogo.agent

Examples of org.nlogo.agent.AgentSet$Iterator


  @Override
  public void perform(final Context context)
      throws LogoException {
    int numberOfTurtles = argEvalIntValue(context, 0);
    if (numberOfTurtles > 0) {
      AgentSet breed =
          breedName == _createorderedturtles.NO_BREED
              ? world.turtles()
              : world.getBreed(breedName);
      for (int i = 0; i < numberOfTurtles; i++) {
        Turtle turtle = world.createTurtle(breed);
View Full Code Here


public final strictfp class _patchrow
    extends Reporter {
  @Override
  public Object report(Context context) throws LogoException {
    AgentSet result =
        new ArrayAgentSet(Patch.class, world.worldWidth(),
            false, world);
    double yDouble = argEvalDoubleValue(context, 0);
    int y = (int) yDouble;
    if (y == yDouble && y >= world.minPycor() && y <= world.maxPycor()) {
      int xMax = world.maxPxcor();
      for (int x = world.minPxcor(); x <= xMax; x++) {
        result.add(world.fastGetPatchAt(x, y));
      }
    }
    return result;
  }
View Full Code Here

        return agent.getBreedVariable(name);
      } catch (org.nlogo.api.AgentException ex) {
        throw new EngineException(context, this, ex.getMessage());
      }
    } else if (agentOrSet instanceof AgentSet) {
      AgentSet sourceSet = (AgentSet) agentOrSet;
      LogoListBuilder result = new LogoListBuilder();
      try {
        for (AgentSet.Iterator iter = sourceSet.shufflerator(context.job.random);
             iter.hasNext();) {
          result.add(iter.next().getBreedVariable(name));
        }
      } catch (org.nlogo.api.AgentException ex) {
        throw new EngineException(context, this, ex.getMessage());
View Full Code Here

    return Syntax.reporterSyntax(right, ret, "OTPL", "?");
  }

  @Override
  public Object report(final org.nlogo.nvm.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;
      }
View Full Code Here

      throws LogoException {
    LinkedHashSet<Link> resultSet = new LinkedHashSet<Link>();
    for (int i = 0; i < args.length; i++) {
      Object elt = args[i].report(context);
      if (elt instanceof AgentSet) {
        AgentSet tempSet = (AgentSet) elt;
        if (tempSet.type() != org.nlogo.agent.Link.class) {
          throw new ArgumentTypeException
              (context, this, i, Syntax.LinkType() | Syntax.LinksetType(), elt);
        }
        for (AgentSet.Iterator iter = tempSet.iterator(); iter.hasNext();) {
          resultSet.add((Link) iter.next());
        }
      } else if (elt instanceof LogoList) {
        descendList(context, (LogoList) elt, resultSet);
      } else if (elt instanceof Link) {
View Full Code Here

      throws LogoException {
    for (Object obj : tempList) {
      if (obj instanceof Link) {
        result.add((Link) obj);
      } else if (obj instanceof AgentSet) {
        AgentSet tempSet = (AgentSet) obj;
        if (tempSet.type() != org.nlogo.agent.Link.class) {
          throw new EngineException(context, this,
              I18N.errorsJ().getN("org.nlogo.prim.etc._linkset.invalidLAgentsetTypeInputToList",
                  this.displayName(), Dump.logoObject(tempList, true, false), Dump.logoObject(obj, true, false)));
        }
        for (AgentSet.Iterator iter2 = tempSet.iterator();
             iter2.hasNext();) {
          result.add((Link) iter2.next());
        }
      } else if (obj instanceof LogoList) {
        descendList(context, (LogoList) obj, result);
View Full Code Here

      }
      addAll(resultList, turtle.getPatchHere().turtlesHere());
    } else if (agentOrSet instanceof Patch) {
      addAll(resultList, ((Patch) agentOrSet).turtlesHere());
    } else if (agentOrSet instanceof AgentSet) {
      AgentSet sourceSet = (AgentSet) agentOrSet;
      if (sourceSet.type() == Turtle.class) {
        for (AgentSet.Iterator iter = sourceSet.iterator(); iter.hasNext();) {
          addAll(resultList, ((Turtle) iter.next()).getPatchHere().turtlesHere());
        }
      } else {
        for (AgentSet.Iterator iter = sourceSet.iterator(); iter.hasNext();) {
          addAll(resultList, ((Patch) iter.next()).turtlesHere());
        }
      }
    } else {
      throw new ArgumentTypeException
View Full Code Here

    return super.toString() + ":" + breedName;
  }

  @Override
  public Object report(final Context context) throws LogoException {
    AgentSet breed = breedName == null ? world.links() : world.getLinkBreed(breedName);
    mustNotBeUndirected(breed, context);
    return world.linkManager.findLinkedFrom
        ((Turtle) context.agent, breed);
  }
View Full Code Here

  }

  public AgentSet report_1(Context context, Object agentOrSet)
      throws LogoException {
    List<Turtle> resultList = new ArrayList<Turtle>();
    AgentSet breed = world.getBreed(breedName);
    if (agentOrSet instanceof Turtle) {
      Turtle turtle = (Turtle) agentOrSet;
      if (turtle.id == -1) {
        throw new EngineException(context, this,
          I18N.errorsJ().getN("org.nlogo.$common.thatAgentIsDead", turtle.classDisplayName()));
      }
      for (Turtle t : turtle.getPatchHere().turtlesHere()) {
        if (t.getBreed() == breed) {
          resultList.add(t);
        }
      }
    } else if (agentOrSet instanceof Patch) {
      for (Turtle turtle : ((Patch) agentOrSet).turtlesHere()) {
        if (turtle.getBreed() == breed) {
          resultList.add(turtle);
        }
      }
    } else if (agentOrSet instanceof AgentSet) {
      AgentSet sourceSet = (AgentSet) agentOrSet;
      if (sourceSet.type() == Turtle.class) {
        for (AgentSet.Iterator iter = sourceSet.iterator(); iter.hasNext();) {
          for (Turtle turtle : ((Turtle) iter.next()).getPatchHere().turtlesHere()) {
            if (turtle.getBreed() == breed) {
              resultList.add(turtle);
            }
          }
        }
      } else if (sourceSet.type() == Patch.class) {
        for (AgentSet.Iterator iter = sourceSet.iterator(); iter.hasNext();) {
          for (Turtle turtle : ((Patch) iter.next()).turtlesHere()) {
            if (turtle.getBreed() == breed) {
              resultList.add(turtle);
            }
          }
View Full Code Here

  }

  public AgentSet report_2(Context context, AgentSet sourceSet)
      throws LogoException {
    List<Turtle> resultList = new ArrayList<Turtle>();
    AgentSet breed = world.getBreed(breedName);
    if (sourceSet.type() == Turtle.class) {
      for (AgentSet.Iterator iter = sourceSet.iterator(); iter.hasNext();) {
        for (Turtle turtle : ((Turtle) iter.next()).getPatchHere().turtlesHere()) {
          if (turtle.getBreed() == breed) {
            resultList.add(turtle);
View Full Code Here

TOP

Related Classes of org.nlogo.agent.AgentSet$Iterator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.