Есть ли способ добавить галочки в foreach l oop в NetLogo? - PullRequest
0 голосов
/ 31 января 2020

Как добавить метки в foreach l oop в NetLo go (для навигации по транспортному средству)?

Я пытаюсь создать навигацию для транспортных средств в этой виртуальной среде. Я использовал чей-то алгоритм *, чтобы найти кратчайший путь. У кодов, похоже, нет проблем, но я хочу сделать два sh совершенными: 1.Как добавить тики, когда транспортное средство движется к новому узлу? и 2 , Как заставить машины двигаться одновременно?

Кто-нибудь может мне помочь решить эту проблему?

Вот код:

extensions [nw]

; In this case, we will work with turtles, not patches.
; Specifically with two types of turtles
breed[nodes node]         ; to represent the nodes of the network
breed[searchers searcher] ; to represent the agents that will make the search
breed[cars car]
links-own [ weight ]


; Searchers will have som additional properties for their functioning.
searchers-own [
  memory               ; Stores the path from the start node to here
  cost                 ; Stores the real cost from the start
  total-expected-cost  ; Stores the total exepcted cost from Start to the Goal that is being computed
  localization         ; The node where the searcher is
  active?              ; is the seacrher active? That is, we have reached the node, but
                       ; we must consider it because its neighbors have not been explored
]

cars-own [
 origin
 destination
 myFN

]

; Setup procedure: simply create the geometric network based on the number of random located nodes
; and the maximum radius to connect two any nodes of the network
to setup
  ca
  create-nodes Num-nodes [
    setxy random-xcor random-ycor
    set shape "circle"
    set size .5
    set color blue]
  ask nodes [
    create-links-with other nodes in-radius radius]

  create-cars 2 [
    set shape "car"
    set color one-of base-colors
    set size 2
    set myFN 0
  ]

  ask nodes [set color blue set size .5]
  ask links with [color = yellow][set color grey set thickness 0]


  ask cars [
    set origin one-of nodes
    move-to origin
    let start [origin] of cars
    let goal max-one-of other nodes [distance myself]
    set destination goal
    ask goal [set color [color] of myself set size 1]
    set myFN distance goal

  ]

  reset-ticks

end

to move1
  tick
  ask cars [
    ; Randomly choose a target node to walk to
    let target max-one-of other nodes [distance myself]
    if target != nobody [
      ; Remember the starting node
      let current one-of nodes-here
      ; Define a path variable from the current node- take all but
      ; the first item (as first item is current node)
      let path nobody
      ask links [ set weight link-length ]
      ask current [
        set path but-first nw:turtles-on-weighted-path-to target weight
        print path
      ]
      ; Indicate the end node
      ask last path [
        set color red
        set size 2.5
      ]
      ; Move along the path node-to-node
      foreach path [
        next-target ->
        face next-target
        move-to next-target
        wait .1
        ask next-target [
        set color yellow
        ]
      ]
    ]
    ;wait .1
    ; Reset
    ask nodes [ set color blue ]
    ask one-of nodes-here [ set color green ]
  ]
end



...