Reputation: 67
I need some help here on a crucial topic in my master's thesis.
Imagine 2 types of turtles, turtle cars and houses turtles. So the turtle cars are placed in a specific region of the world and the turtle houses are placed at random.
The main objective is for turtle cars to visit all the houses and return to the starting position.
Example of a case study: 2 cars and 5 houses
So imagine that I define the following route vector: route: [0 2 3 1 4, 5 5 6 5 6]
in the first part are placed randomly the houses to visit, then the respective car that will make the visit, ie the car 5 visits the homes 0 2 and 1 and the car 6 visits the house 3 and 4.
I use the IDs of each turtles, depending on the total number of turtles used. That is, using a given route vector, my cars could automatically be viewed to visit all their respective houses (in the order they are inserted into the vector, as explained above).
My question is, knowing the vector route, how do I make the car choose where to go and return to the starting point.
If someone can help me, I really appreciate it.
Upvotes: 0
Views: 456
Reputation: 17678
Here is some code to take an input route-vector and create a route for each car. The pairing of the car and house is taken from NetLogo: How to filter a list using a criterion which refers on a corresponding list?. This is the form with the clearest interpretation, if you can construct the filter
version from that answer, it would be more elegant.
globals [ route-vector ]
breed [cars car]
cars-own [ route ]
to setup
clear-all
set route-vector [ 5 10 15 20 25 0 1 2 0 1 ]
create-turtles 3 [ setxy random-xcor random-ycor ]
make-routes
reset-ticks
end
to make-routes
let houses sublist route-vector 0 (length route-vector / 2 )
let carlist sublist route-vector (length route-vector / 2 ) (length route-vector)
ask cars [ set route [] ]
(foreach carlist houses
[ [the-car the-house] ->
ask cars with [who = the-car] [ set route lput the-house route ]
]
)
end
Please ask a separate question about using the route variable to actually move along the path. But make an attempt to do it yourself so you can show your code and describe what needs to be fixed.
Upvotes: 2