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


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

  @Override
  public void perform(final Context context) throws LogoException {
    AgentSet agentset = argEvalAgentSet(context, 0);
    if (agentset.type() != Turtle.class) {
      throw new ArgumentTypeException(
        context, this, 0, Syntax.TurtlesetType(), agentset);
    }
    AgentSet breed = breedName == null ? world.links() : world.getLinkBreed(breedName);
    mustNotBeDirected(breed, context);
    checkForBreedCompatibility(breed, context);
    if (breed == world.links()) {
      breed.setDirected(false);
    }
    AgentSet edgeset = new org.nlogo.agent.ArrayAgentSet(Link.class, agentset.count(),
        false, world);
    Turtle src = (Turtle) context.agent;
    // We have to shuffle here in order for who number assignment
    // to be random! - ST 3/15/06
    for (AgentSet.Iterator iter = agentset.shufflerator(context.job.random); iter.hasNext();) {
      Turtle dest = (Turtle) iter.next();
      if (world.linkManager.findLinkEitherWay(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;
          if (src.id > dest.id) {
            link = world.linkManager.createLink(dest, src, breed);
          } else {
            link = world.linkManager.createLink(src, dest, breed);
          }
          edgeset.add(link);
          workspace.joinForeverButtons(link);
        }
      }
    }
    if (offset - context.ip > 2 && edgeset.count() > 0) {
      context.runExclusiveJob(edgeset, next);
    }
    context.ip = offset;
  }
View Full Code Here

  @Override
  public void perform(final Context context)
      throws LogoException {
    int numberOfTurtles = argEvalIntValue(context, 0);
    if (numberOfTurtles > 0) {
      AgentSet breed =
          breedName == _createturtles.NO_BREED
              ? world.turtles()
              : world.getBreed(breedName);
      org.nlogo.util.MersenneTwisterFast random = context.job.random;
      for (int i = 0; i < numberOfTurtles; i++) {
View Full Code Here

  @Override
  public void perform(final Context context) throws LogoException {
    Turtle dest = argEvalTurtle(context, 0);
    Turtle src = (Turtle) context.agent;
    AgentSet breed = breedName == null ? world.links() : world.getLinkBreed(breedName);
    mustNotBeDirected(breed, context);
    checkForBreedCompatibility(breed, context);
    if (breed == world.links()) {
      breed.setDirected(false);
    }
    if (world.linkManager.findLinkEitherWay(src, dest, breed, false) == null) {
      if (src == dest) {
        throw new EngineException
            (context, this,
                I18N.errorsJ().get("org.nlogo.prim.$common.turtleCantLinkToSelf"));
      }
      if (src.id > dest.id) {
        Turtle tmp = src;
        src = dest;
        dest = tmp;
      }
      if (src.id != -1 && dest.id != -1) {
        Link link = world.linkManager.createLink(src, dest, breed);
        workspace.joinForeverButtons(link);

        if (offset - context.ip > 2) {
          // Needed to run the commands with runExclusive(). I was not
          // clear how to run those commands otherwise.  -CLB 03/16/06
          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

    this.breedName = breedName;
  }

  @Override
  public Object report(final Context context) throws LogoException {
    AgentSet breed = world.getLinkBreed(breedName);
    Link link = world.getLink(argEvalDouble(context, 0),
        argEvalDouble(context, 1), breed);
    if (link == null) {
      return Nobody$.MODULE$;
    }
View Full Code Here

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

      if (breedName == _hatch.NO_BREED) {
        for (int i = 0; i < numberOfTurtles; i++) {
          workspace.joinForeverButtons(parent.hatch());
        }
      } else {
        AgentSet breed = world.getBreed(breedName);
        for (int i = 0; i < numberOfTurtles; i++) {
          Turtle child = parent.hatch();
          child.setBreed(breed);
          workspace.joinForeverButtons(child);
        }
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.findLinksTo
        ((Turtle) context.agent, breed);
  }
View Full Code Here

  public void perform(final Context context) {
    perform_1(context);
  }

  public void perform_1(final Context context) {
    AgentSet agentset =
        new org.nlogo.agent.ArrayAgentSet
            (context.agent.getAgentClass(), 1, false, world);
    agentset.add(context.agent);
    try {
      // start new job that skips over the _goto command
      context.runExclusiveJob(agentset, next + 1);
      // move on to the _goto command, which will skip to the end.
      context.ip = next;
View Full Code Here

  @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++) {
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.