Package org.nlogo.agent

Examples of org.nlogo.agent.AgentSet


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


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

  }

  @Override
  public Object report(final org.nlogo.nvm.Context context) throws LogoException {
    org.nlogo.agent.LinkManager linkManager = world.linkManager;
    AgentSet breed = breedName == null ? world.links() : world.getLinkBreed(breedName);
    mustNotBeUndirected(breed, context);
    Turtle parent = (Turtle) context.agent;
    Turtle target = argEvalTurtle(context, 0);
    Link link = linkManager.findLinkFrom(parent, target, breed, true);
    if (link == null) {
View Full Code Here

  @Override
  public Object report(final Context context)
      throws LogoException {
    org.nlogo.agent.LinkManager linkManager = world.linkManager;
    AgentSet breed = breedName == null ? world.links() : world.getLinkBreed(breedName);
    mustNotBeUndirected(breed, context);
    Turtle target = argEvalTurtle(context, 0);
    Link link = linkManager.findLinkFrom(target, (Turtle) context.agent, breed, true);
    if (link == null) {
      return org.nlogo.api.Nobody$.MODULE$;
View Full Code Here

  @Override
  public Object report(final org.nlogo.nvm.Context context) throws LogoException {
    org.nlogo.agent.LinkManager linkManager = world.linkManager;
    Turtle parent = (Turtle) context.agent;
    Turtle target = argEvalTurtle(context, 0);
    AgentSet breed = breedName == null ? world.links() : world.getLinkBreed(breedName);
    mustNotBeUndirected(breed, context);
    return linkManager.findLinkFrom(parent, target, breed, true) == null
        ? Boolean.FALSE
        : Boolean.TRUE;
  }
View Full Code Here

    }
  }

  public void handle(org.nlogo.window.Events.AddJobEvent e) {
    org.nlogo.api.JobOwner owner = e.owner;
    AgentSet agents = e.agents;
    if (owner instanceof JobWidget &&
        agents == null) {
      JobWidget widget = (JobWidget) owner;
      if (widget.useAgentClass()) {
        agents = world.agentClassToAgentSet(widget.agentClass());
View Full Code Here

  @Override
  public void perform(final Context context) throws LogoException {
    Turtle src = argEvalTurtle(context, 0);
    Turtle dest = (Turtle) context.agent;
    AgentSet breed = breedName == null ? world.links() : world.getLinkBreed(breedName);
    mustNotBeUndirected(breed, context);
    checkForBreedCompatibility(breed, context);
    if (breed == world.links()) {
      breed.setDirected(true);
    }
    if (world.linkManager.findLinkFrom(src, dest, breed, false) == null) {
      if (src == dest) {
        throw new EngineException
            (context, this,
                I18N.errorsJ().get("org.nlogo.prim.$common.turtleCantLinkToSelf"));
      }
      if (src.id != -1 && dest.id != -1) {
        Link link = world.linkManager.createLink(src, dest, breed);
        workspace.joinForeverButtons(link);
        if (offset - context.ip > 2) {
          AgentSet edgeset = new org.nlogo.agent.ArrayAgentSet(Link.class, 1,
              false, world);
          edgeset.add(link);
          context.runExclusiveJob(edgeset, next);
        }
      }
    }
    context.ip = offset;
View Full Code Here

  @Override
  public void perform(final org.nlogo.nvm.Context context) throws LogoException {
    int numberOfTurtles = argEvalIntValue(context, 0);
    if (numberOfTurtles > 0) {
      Turtle parent = (Turtle) context.agent;
      AgentSet agentset =
          new org.nlogo.agent.ArrayAgentSet(Turtle.class, numberOfTurtles, false, world);
      if (breedName == NO_BREED) {
        for (int i = 0; i < numberOfTurtles; i++) {
          Turtle child = parent.hatch();
          agentset.add(child);
          workspace.joinForeverButtons(child);
        }
      } else {
        AgentSet breed = world.getBreed(breedName);
        for (int i = 0; i < numberOfTurtles; i++) {
          Turtle child = parent.hatch();
          child.setBreed(breed);
          agentset.add(child);
          workspace.joinForeverButtons(child);
View Full Code Here

    perform_1(context, args[0].report(context));
  }

  public void perform_1(Context context, Object target)
      throws LogoException {
    AgentSet agentset;
    if (target instanceof AgentSet) {
      agentset = (AgentSet) target;
      if (!(context.agent instanceof Observer)) {
        if (agentset == world.turtles()) {
          throw new EngineException
              (context, this, I18N.errorsJ().get("org.nlogo.prim.$common.onlyObserverCanAskAllTurtles"));
        }
        if (agentset == world.patches()) {
          throw new EngineException
              (context, this, I18N.errorsJ().get("org.nlogo.prim.$common.onlyObserverCanAskAllPatches"));
        }
      }
    } else if (target instanceof Agent) {
      Agent agent = (Agent) target;
      if (agent.id == -1) {
        throw new EngineException(context, this,
          I18N.errorsJ().getN("org.nlogo.$common.thatAgentIsDead", agent.classDisplayName()));
      }
      agentset = new ArrayAgentSet(agent.getAgentClass(), 1, false, world);
      agentset.add(agent);
    } else {
      throw new ArgumentTypeException(context, this, 0, Syntax.AgentsetType() | Syntax.AgentType(), target);
    }
    context.runExclusiveJob(agentset, next);
    context.ip = offset;
View Full Code Here

      throws LogoException {
    if (agent.id == -1) {
      throw new EngineException(context, this,
        I18N.errorsJ().getN("org.nlogo.$common.thatAgentIsDead", agent.classDisplayName()));
    }
    AgentSet agentset = new ArrayAgentSet(agent.getAgentClass(), 1, false, world);
    agentset.add(agent);
    context.runExclusiveJob(agentset, next);
    context.ip = offset;
  }
View Full Code Here

TOP

Related Classes of org.nlogo.agent.AgentSet

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.