Netlogo:找到折扣之前目标的下一个目标

时间:2017-10-29 19:38:16

标签: netlogo

我试图让我的代理人在达到第一个目标后计算下一个补丁目标。目标定义为(最高补丁影响值/距离代理的距离)。下一个目标需要使用相同的程序计算,但也可以从等式中扣除任何先前的目标。

我试图创建一个包含所有目标的补丁集,虽然我不确定它是否有效。

我的问题是如何创建一个计算下一个影响最大值的报告功能。我完全陷入了程序的最后一部分。

我最初的记者功能是:

to-report highest-influence
  let available-target patches with [influence > 0] ;and not any? patches with [pcolor = green]
  report max-one-of available-target [influence / distance myself]
end

但是我不确定如何让下一个记者功能使用相同的参数,同时还要折扣以前的任何目标

to-report next-highest-influence
  ; patches with [influence > 0] and not part of patch set
end  

非常感谢任何帮助。我已经提供了完整的代码。

breed [walkers walker]

walkers-own [traveled?  ;; parameter to keep track of if a walker has traveled to a target yet or not 
             target ]

patches-own [influence influence-set] ;highest-influence

to setup
  clear-all
  reset-ticks
  define-patches
  create-walkers num-walkers
  ask walkers [
    setxy 0 0
    set heading 90
    let streets neighbors with [pcolor = black]
    ifelse any? streets in-cone 1 25
        [fd 1]
        [move-to one-of streets in-radius 1]
    set traveled? false    ;; so that walkers know they have not yet moved to a target
    ]
  ask walkers [
    define-target ]
end

to define-patches
  ask n-of 100 patches [
    set pcolor white
    ]
  ask n-of 40 patches with [pcolor = white] [set influence random 5 set pcolor blue set plabel influence]
  ask patches [set influence-set patches with [pcolor = green] ]
end

to define-target        ;; this defines the initial destination of walkers 
  if traveled? = false [
  set target highest-influence
  ask target [set pcolor green]
    face target ]
end

to new-target            ;; this defines subsequent desinations after walkers have reached inital target 
  if traveled? = true [
    set target next-highest-influence
    ask target [set pcolor green + 2]
       face target ]
end

;;;;;;;;;;;;run-time procedure;;;;;;;;;;

to go
   ask walkers [
    if distance target > 1
      [ travel-walkers
        leave-a-trail 
        set traveled? true ]
    if distance target = 1
      [ stop
        new-target
        travel-walkers
        leave-a-trail
       ]
    ]
  tick
end

to travel-walkers  
    ask walkers [
       move-towards-target 
   ]  
end

to move-towards-target
 ask walkers [ 
  ifelse [pcolor] of patch-ahead 1 != white or any? other turtles-here
    [ Move-Function ]
    [ Avoid-Function ]
  ]  
end

to Move-Function
  let t target
  face min-one-of all-possible-moves [distance t]
  fd 1
end

to Avoid-Function
  let t target
  face min-one-of all-possible-moves [distance t]
end

to leave-a-trail
  ask patch-here [set pcolor grey]
end

;;;;;; reporter calculations ;;;;;;
to-report highest-influence
  let available-target patches with [influence > 0] ;and not any? patches with [pcolor = green]
  report max-one-of available-target [influence / distance myself]
end

to-report next-highest-influence
  ; patches with [influence > 0] and not part of patch set
end

to-report all-possible-moves
  report patches in-radius 1 with [pcolor != white and distance myself  <= 1 and distance myself  > 0 and plabel = "" ]
end

1 个答案:

答案 0 :(得分:1)

您可以使用member?原语来执行此操作。看看下面的简化玩具模型(我没有使用你的代码,因为我不确定你想要如何实现,并且我需要设置一些界面部件来运行它。查看{{3 }})。

turtles-own [ visited-list ]
patches-own [ influence ]

to setup-member?
  ca
  crt 1 [ set visited-list [] ]
  ask patches [ set influence 0 ]
  ask n-of 5 patches [ set influence 5 + random 50 ]
  reset-ticks
end

to go-member?
  ask turtles [
    let target highest-influence
    ifelse target != nobody [
      face target
      ifelse distance target > 1 [
        fd 1
      ] [
        move-to target
        ask target [ set pcolor red]
        set visited-list lput target visited-list
      ]
    ] [ print "No targets remaining." ]
  ]
  tick
end

to-report highest-influence
  let to-visit patches with [ 
    influence > 0 and 
    not member? self [visited-list] of myself ]
  report max-one-of to-visit [ influence / ( distance myself )]
end

报告返回具有最高影响力/距离值的补丁,是乌龟visited-list的成员。最初,没有补丁是列表的成员,但是当乌龟访问每个目标时,它会将目标添加到visited-list,以便不再考虑补丁。