Ullsokk
Ullsokk

Reputation: 717

turtles overshooting their target and getting stuck in infinite movement loop

I am modeling tax evasion. My model has stationary traders (one breed of turtles) and customers (another breed).

The traders go towards the cheapest trader in their vicinity.

As long as my model has less than 10 traders, I have not experienced this problem. But as I ramp it up to over 20, one of the traders seem to, by chance, be at a set of coordinates that make every customer get stuck in an infinite movement loop where they move forward by 1, but overshoot the target, turn around, and overshoot again etc.

I can get less problems by decreasing forward movement to say 0.001 instead of 1, but the problem will still occur eventually.

Is there a quick fix to this problem? I can imagine a solution where an ifelse makes them jump directly into the traders coordinates when within range 1 or something, but is there an easier way?

I have tried implementing moving towards nearest trader given distance - as I suggested above, but now the customers get stuck in conga lines in groups in random locations without a trader

Here is the code regarding movement:

to find_food
ifelse ( num-traders-close < 2 ) 
[nearest_food] 
[choose-cheapest]
end


to nearest_food
let nearest-food min-one-of (traders )[distance myself]
let cf-dist distance min-one-of traders [distance myself]
 ifelse closest-trader > 1
 [face nearest-food
 fd 1]
 [face nearest-food
   fd cf-dist]
 end

to choose-cheapest
let cheapest-food min-one-of traders [price]
let cf-dist distance min-one-of traders [distance myself]
 ifelse closest-trader > 1
 [face cheapest-food
 fd 1]
 [face cheapest-food
   fd cf-dist ]
  end

Upvotes: 2

Views: 264

Answers (1)

Marzy
Marzy

Reputation: 1894

In the code in your other question , I have tried to follow your own code, but you can do this as well :

instead of finding one traders , you always check one-of close traders to that customer, and cheapest food and nearest food are customer property.

Breed [Customers Customer]
Breed [Traders trader]
Customers-own 
[cheapest-food   nearest-food  traders-close]
  traders-own [price]

to setup 
  random-seed 234523432
  clear-all
  Create-traders 10 [move-to one-of patches set price random 100 set shape "house" set color white ]
  create-Customers 50 [move-to one-of patches set shape "person"   ]


  reset-ticks
end


to go
  ask customers
  [
    set-customers
    find_food
    ]
  tick
end
to set-customers
  rt random 100
  fd 1
set  traders-close  traders with [distance myself < 5]  

set nearest-food min-one-of (traders-close  )[distance myself]
set cheapest-food min-one-of traders-close  [price]
 end
to find_food
      ifelse ( count  traders-close < 2 ) 

  [ifelse nearest-food != nobody 
    [Move-to nearest-food ]
    [Move-to min-one-of Traders  [Distance myself]]
  ]
  [ ifelse cheapest-food != nobody 
  [Move-to cheapest-food]
  [Move-to min-one-of Traders with [Distance myself < 5][price]]
  ]
end

Upvotes: 0

Related Questions