Package org.nlogo.agent

Examples of org.nlogo.agent.AgentSet$Iterator


    LinkedHashSet<Patch> resultSet =
        new LinkedHashSet<Patch>();
    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.Patch.class) {
          throw new ArgumentTypeException
              (context, this, i, Syntax.PatchType() | Syntax.PatchsetType(), elt);
        }
        for (AgentSet.Iterator iter = tempSet.iterator(); iter.hasNext();) {
          resultSet.add((Patch) iter.next());
        }
      } else if (elt instanceof LogoList) {
        descendList(context, (LogoList) elt, resultSet);
      } else if (elt instanceof Patch) {
View Full Code Here


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

      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,
View Full Code Here

        );
  }

  @Override
  public Object report(final Context context) throws LogoException {
    AgentSet sourceSet = argEvalAgentSet(context, 0);
    double winningValue = -Double.MAX_VALUE;
    Context freshContext = new Context(context, sourceSet);
    List<Agent> result = new ArrayList<Agent>();
    args[1].checkAgentSetClass(sourceSet, context);
    for (AgentSet.Iterator iter = sourceSet.iterator(); iter.hasNext();) {
      Agent tester = iter.next();
      Object value = freshContext.evaluateReporter(tester, args[1]);
      if (!(value instanceof Double)) {
        continue;
      }
      double dvalue = ((Double) value).doubleValue();
      if (dvalue >= winningValue) {
        if (dvalue > winningValue) {
          winningValue = dvalue;
          result.clear();
        }
        result.add(tester);
      }
    }
    return new org.nlogo.agent.ArrayAgentSet
        (sourceSet.type(),
            result.toArray(new Agent[result.size()]),
            world);
  }
View Full Code Here

        return agent.getLinkVariable(vn);
      } 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().getLinkVariable(vn));
        }
      } catch (org.nlogo.api.AgentException ex) {
        throw new EngineException(context, this, ex.getMessage());
View Full Code Here

        return agent.getLinkVariable(vn);
      } 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().getLinkVariable(vn));
        }
      } catch (org.nlogo.api.AgentException ex) {
        throw new EngineException(context, this, ex.getMessage());
View Full Code Here

        throw new EngineException(context, this,
            I18N.errorsJ().getN("org.nlogo.prim.etc.$common.emptyListInput", displayName()));
      }
      return list.get(context.job.random.nextInt(size));
    } else if (obj instanceof AgentSet) {
      AgentSet agents = (AgentSet) obj;
      int count = agents.count();
      if (count == 0) {
        return org.nlogo.api.Nobody$.MODULE$;
      } else {
        return agents.randomOne(count, context.job.random.nextInt(count));
      }
    } else {
      throw new ArgumentTypeException
          (context, this, 0, Syntax.ListType() | Syntax.AgentsetType(), obj);
    }
View Full Code Here

        throw new EngineException(context, this,
            I18N.errorsJ().getN("org.nlogo.prim.etc.$common.emptyListInput", displayName()));
      }
      return list.get(context.job.random.nextInt(size));
    } else if (obj instanceof AgentSet) {
      AgentSet agents = (AgentSet) obj;
      int count = agents.count();
      if (count == 0) {
        return org.nlogo.api.Nobody$.MODULE$;
      } else {
        return agents.randomOne(count, context.job.random.nextInt(count));
      }
    } else {
      throw new ArgumentTypeException(context, this, 0,
          Syntax.ListType() | Syntax.AgentsetType(), obj);
    }
View Full Code Here

  }

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

    if (context.agent instanceof Turtle) {
      patch = ((Turtle) context.agent).getPatchHere();
    } else {
      patch = (Patch) context.agent;
    }
    AgentSet agentset =
        new ArrayAgentSet(Turtle.class, patch.turtleCount(),
            false, world);
    AgentSet breed = world.getBreed(breedName);
    for (Turtle turtle : patch.turtlesHere()) {
      if (turtle.getBreed() == breed) {
        agentset.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.