I am trying to get coordination for turtle in netlogo using Java API. I have loaded the workspace and I am using the following code:
public static intex (headless works space workspace, string player name, int agent no.) {Double double x = null; Int xVal = 0; Try {XVal = doubleX.valueOf ((workspace.portport ("[xcor]" + player name + + "+ agent name") .string ()). Trim ()). IntValue (); } Hold (Exception pre) {ex.printStackTrace (); } Return xVal; } However, there is a small problem. It is very slow when there are more than 5 turtles. When I run the code coming up with 200 turtles without getting the coordinates, then I get around 300 ticks in 10 seconds, when I run the code with coordinates, each tick takes about 3 seconds to get it Is there a more efficient way of?
Thank you,
Nadim
I came to know What should be the proper way. According to Seth Tissue, this code is in the MailLogo mailing list.
import org.nlogo.headless. *; Import org.nlogo.api. *; Square Jammu {public static zero main (string [] args) {try {headless workspace ws = headless workspace.new instence (); Ws.openString (org.nlogo.util.Utils.url2String ("/ system / empty.nlogo")); Ws.command ("Crow 8 [FD5]"); Org.nlogo.api.Turtle Turtle = (org.nlogo.api.Turtle) ws.world (). Tortoise (). Agent (3); System.out.println ("[xcor] turtle 3 =" + turtle .xcor ()); Ws.dispose (); } Hold (Exception pre) {ex.printStackTrace (); }}} I have reproduced the code here, so its benefit may be for others to see a list of what information you can get from turtle, See Netlogo API documentation.
Nadim
Comments
Post a Comment