NetLogo Turtles陷入困境

时间:2013-12-17 13:37:43

标签: netlogo

我正在研究逃税模式。我有许多被称为贸易商的固定龟,以及被称为顾客的移动乌龟。每个客户都朝着最近的交易者的方向移动,但如果附近有超过1个交易者,则客户将以最低价格移至交易者。

随机运行但并非总是如此,客户排队并因某些原因而陷入困境。似乎他们更多地陷入我为模型添加的更复杂的情况,即使这些添加与移动无关。

这是移动代码

  ask customers[
set num-traders-close count traders with [distance myself < 10]  
set closest-trader distance min-one-of traders [distance myself]

to find_food
      ifelse ( num-traders-close < 2 ) ;;If only 0 or 1 traders within 10 spaces, move towards it. If number is 2 or larger, go towards cheaper resturant
  [nearest_food] 
  [choose-cheapest]
end


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

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

1 个答案:

答案 0 :(得分:1)

我已经通过添加自己的设置和转到功能测试了您的代码, 但无论如何,如果你在每个蜱中设置交易者和最近交易者的数量,你将只在一两个交易者中排队。如下图所示:

enter image description here

但是如果你在设置功能上设置它,它们将始终转到他们首先检查的那个,就像下面的图像一样

enter image description here

但这种方式可能不合理,您可能需要让客户随机移动,以便他们可以在go函数中稍后更改这些值。

在下面的代码中,他们四处移动,他们更新了他们的num-near-traders和closet trader。没有排队,我也让他们四处走动,所以这更合理,但我不确定你的要求。

Breed [Customers Customer]
Breed [Traders trader]
Customers-own 
[num-traders-close closest-trader]
  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 0.5
set num-traders-close count traders with [distance myself < 5]  
set closest-trader distance min-one-of traders [distance myself]
 end
to find_food
      ifelse ( num-traders-close < 2 ) ;;If only 0 or 1 traders within 10 spaces, move towards it. If number is 2 or larger, go towards cheaper restaurant
  [nearest_food] 
  [choose-cheapest]
end