1

I am working on a NetLogo model where I have a list of customers and a set of restaurants. The goal is to make the customers go to the nearest restaurant at certain intervals. However, I'm encountering an error message that says ASK expected input to be an agent or agentset and it points to the line where I ask the customers to perform an action.

This is the whole I error I got :

ASK expected input to be an agent or agentset but got the list
[(turtle 4) (turtle 3) (turtle 6) (turtle 0) (turtle 3) (turtle 1) (turtle 6) (turtle 10) (turtle 2) (turtle 7) (turtle 14) (turtle 13) (turtle 1) (turtle 5) (turtle 10) (turtle 9) (turtle 18) (turtle 17) (turtle 10) (turtle 13) (turtle 17) (turtle 17) (turtle 9) (turtle 6) (turtle 15) (turtle 5) (turtle 20) (turtle 31) (turtle 22) (turtle 18) (turtle 14) (turtle 31) (turtle 16) (turtle 7) (turtle 35) (turtle 39) (turtle 2) (turtle 25) (turtle 24) (turtle 17)] instead.
error while observer running ASK
called by procedure CUSTOMERS-GO-TO-RESTAURANTS
called by procedure GO
called by Button 'go'

Here is the code :

globals [restaurants customers]

to setup
   clear-all
   set-default-shape turtles "default"
   create-turtle "house"
   create-customers 40
   reset-ticks
end

to create-turtle [ shapess ]
   let new-restaurants []
   repeat 4 [
          create-turtles 1 [
                 setxy random-xcor random-ycor
                 set size 3
                 set shape shapess
          ]
          set new-restaurants lput one-of turtles new-restaurants
   ]
   set restaurants new-restaurants
   user-message (word "new-restaurants: " new-restaurants)
end


to create-customers [number]             ; Create new customer agents
   let new-customers []
   repeat number [
          create-turtles 1 [
                 setxy random-xcor random-ycor
                 set heading random 360
               ; ...                     ; Additional turtle setup code
          ]
          set new-customers lput one-of turtles new-customers
   ]
   set customers new-customers
   user-message (word "Customers: " new-customers)
end


to go-to-restaurant [customer restaurant]
  ask customer [
      face restaurant
      fd 1
      set label [label] of restaurant
  ]
end


to customers-go-to-restaurants
   if ticks mod 12 = 0 [
      ask customers [
          let customer self
          let closest-restaurant min-one-of restaurants [distance customer]
          go-to-restaurant customer closest-restaurant
      ]
   ]
end


to go
   customers-go-to-restaurants
   tick
end

I would greatly appreciate any insights or suggestions on how to resolve this issue.

"I tried running the 'go' command in my NetLogo model to simulate the movement of customers to restaurants. I expected the customers to move towards the nearest restaurant and update their labels accordingly. However, instead of the expected behavior, I encountered an error message stating ASK expected input to be an agent or agentset but got the list [(turtle 4) (turtle 3) (turtle 6) ...]. As a result, the simulation did not run successfully."

Feel free to modify this example based on your specific scenario and the error message you encountered.

user3666197
  • 1
  • 6
  • 50
  • 92

1 Answers1

3

The error says it all really. The turtles in customers are stored as a list instead of as an turtle-set. having them stored as a list can be useful when you want to use functions like sort and foreach to let the turtles perform something in a specific order, but in general you want them to be a turtle-set instead.

The quickest fix that I can make with your code is turning the list into an agentset: set customers (turtle-set new-customers)

to create-customers [number]
  ; Create new customer agents
  let new-customers []
  repeat number [
    create-turtles 1 [
      setxy random-xcor random-ycor
      set heading random 360
      ; Additional turtle setup code
    ]
    set new-customers lput one-of turtles new-customers
  ]
  set customers (turtle-set new-customers)
  user-message (word "Customers: " new-customers)


end

However, that doesn't actually fix all the problems you have with the way you do your setup. A better way to go about it in general would be using breeds. You can see breeds as separate agent-sets that are mutually exclusive and in general easier to work with. One of the benefits is that you can use the create-<breed> primitive in order to quickly create the right type of turtles. In your case that would be create-customers and create-restaurant. Another benefit is that you can set-default-shape for the separate breeds. For a full explanation of how breeds work, I'm going to refer you to the manual.

Another issue I see in your turtle creation process is that you use set new-customers lput one-of turtles new-customers. This adds a random turtle to your list of customers. This turtle that you add could be a restaurant, an unassigned turtle, or even a turtle that is already a part of the list. It becomes completely redundant when working with breed so I won't bother fixing it, but I wanted to point out the issue in case you try to use something similar again in the future.

On a last note, set heading random 360 is completely redundant since turtles already get created with a random heading.

With all that in mind, your entire setup procedure becomes as follows. Your create-turtle and create-customers procedures become completely redundant and should be removed, especially since create-customers now interferes with the inbuilt procedure that is tied to the breed.

breed [restaurants restaurant]
breed [customers customer]

to setup
   clear-all
   set-default-shape customers "default"
   set-default-shape restaurants "house"
   create-customers 40 [ setxy random-xcor random-ycor]
   create-restaurants 4 [ setxy random-xcor random-ycor]
   reset-ticks    
end

I don't expect your code to fully work once you have this implemented, but it will fix give you a solid setup from which you can continue on.

LeirsW
  • 2,070
  • 4
  • 18