I am creating a taxi-like simulation in which vehicles search for customers. When a vehicle is within 1 unit distance of the customer, it picks up the customer and takes it to its destination (and begins searching for customers again, etc.).
My issue: if 2 vehicles come within 1 unit distance of the same customer within the same time-step, I need the vehicle with the highest [rating] (vehicles-own variable) to always get the customer. This is my code (updated from a previous post):
to find-customers
if (distance closest-customer <= 1)
[ask closest-customer [check-for-vehicles]]
end
to check-for-vehicles
set competitors vehicles in-radius 1
determine-highest-rated
end
to determine-highest-rated
set highest-rated max-one-of competitors [rating]
ask highest-rated [set color red]
end
[competitors] and [highest-rated] are waiting-customer-own variables. closest-customer is min-one of waiting-customers (distance myself). Normally [set color red] would run the procedure in which the vehicle gets the customer transport information. When forcing two vehicles on the same customer, the correct vehicle always sets its color red. Sometimes the incorrect vehicle also sets its color red. When I check the variable values for the waiting-customer, the correct vehicle is identified as highest-rated, yet sometimes the other vehicle still turns red. There is obviously a mistake with how I've set up the procedures. If anyone has suggestions on how to fix this (or how to approach this task differently) it would be appreciated.
I think the reason why your
ifelse
always return false is because theifelse
is placed at the same time step as the initialization ofidentification
for each taxi.The way netlogo works when running some function to an agenset is, each agent, one by one will individually run the function in random order, not in the same time.
So, if the
ifelse
is placed just right after theidentification
is set and in the same function, it will always return false since the other vehicles haven't got their identification set yet. Then it will directly runmake-deal
before even compare it to other-vehicles.for example:
is different with
The first one will make each agent set their identification and do the ifelse statement before make other agent do. The second one will make every agent set their identification first then make every agent do the ifelse statement.
The conclusion is, I suggest you to separate the find-costumer function and the make-deal function.
I hope this helps