使用Netlogo的复杂网络上的本地路由 [英] Local Routing on Complex Network using Netlogo

查看:166
本文介绍了使用Netlogo的复杂网络上的本地路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个小型无向网络,其中一些节点作为源,而有些则是目标.然后我创建了放置在源节点上的walker. 现在,我想使用此网络实现非常简单的本地路由算法. 在这里,我的算法步骤;

I created a small undirected network, where some nodes are as sources and some are targets. then I created walkers placed on source nodes. Now, I want to implement a very simple local routing algorithm using this network. Here, my algo steps;

1 go
2 get-list-of-neighbors
3 select one-of from list of neighbors
    check is-visited:
    if yes: [remove from the list 
           check is-loop
           if yes: Die
           else go to setp 3]

  4 else Move-to selected node
  5 check is-target?
    if yes: die 
    else add to list-of-visited and Go

问题: 我是Netlog的新手,并且不知道如何实现此算法. 这是我的代码.

Question: I'm new to Netlog, and don't know how to implement this algorithm. Here is my code.

to go
ask walkers[
set list-of-neighbors (list [link-neighbors] of location)
let selected-node one-of list-of-neighbors
if (visited?=true)[ set list-of-neighbors remove-duplicate list-of-neighbors
chek if loop? exist
     if yes:
     if no:
if(visited?=false)[ move-to selected-node]
set location selected-node
ask location[ ifelse target=true[die][set list-of-visited lput location 
go ]
end

推荐答案

我的回答是对

My answer here is a slight modification to my answer to your other question. I'm not sure exactly what you mean by check is-loop, so in my solution I just have the walkers die if they have no neighboring nodes to which they can move (as they have already visited that node). Additionally, I'm suggesting a slightly different approach to accomplish the same idea as the algorithm you outline. The steps here are more like:

  • 行者选择一个尚未移动到的邻居
  • 如果不存在这样的邻居(因为它已经拜访了其当前位置的所有邻居),那么行者就会死亡.
  • 如果存在尚未访问过的邻居,步行者将移动到该邻居,并将其新位置添加到其变量locations-list
  • 如果新位置是目标:
  • Walker selects one of the neighbors to which it has not already moved
  • If no such neighbor exists (as it has already visited all neighbors of its current location) the walker dies.
  • If a neighbor that has not been visited does exist, the walker will move to that neighbor, and add its new location to its variable locations-list
  • If the new location is a target:
  1. 目标节点被标记为已访问
  2. 目标节点更改其颜色
  3. 行者死亡

  • 如果在go过程的末尾没有剩余的行者,则会在源节点上产生一个新的行者.
  • 如果所有目标均已访问,则模型会停止
  • If no walkers remain at the end of the go procedure, a new walker is spawned on the source node.
  • If all targets are visited, the model stops
  • 很明显,如果有一条带有多个目标节点的线性路径,则步行者每次到达第一个目标时都会死亡,因此永远不会访问那些距离较远的节点-但这只是一个例子.删除die块或修改其他内容以进行玩耍.

    Obviously if there is a linear path with multiple target nodes on it, the walkers will die each time they come to the first target and so will never visit those nodes that are farther along- but this is just an example. Remove the die chunk or modify other things to play around.

    就像我说的那样,这只是对上面链接的答案的很小的修改,但是我在下面复制了整个代码,以便于访问.

    Like I said, this is only a very small modification to the answer linked above, but I copy the whole code below for easy access.

    breed [nodes node]
    breed [walkers walker]
    
    walkers-own [location locations-list]  
    nodes-own [ source? target? visited? ] 
    
    to setup
      clear-all
      set-default-shape nodes "circle"
      create-nodes 30 [ 
        set color blue 
        set target? false
        set source? false
        set visited? false
      ]
      ask nodes [ create-link-with one-of other nodes ]
      repeat 500 [ layout ]
      ask nodes [ 
        setxy 0.95 * xcor 0.95 * ycor 
      ]
      ask n-of 3 nodes [
        set target? true
        set color white
      ]
    
      ask n-of 1 nodes with [ target? = false ] [
        set source? true
        set color green
      ]
    
      spawn-walkers
    
      reset-ticks
    end
    
    to layout
      layout-spring nodes links 0.5 2 1
    end
    
    to spawn-walkers
    
        create-walkers 1 [
        set color red
        set location one-of nodes with [ source? ]
        move-to location
        set locations-list ( list location)
      ]
    
    end
    
    to go
      ask links [ set thickness 0 ]
      ask walkers [
        let new-location one-of ( [link-neighbors] of location ) with [ not member? self [locations-list] of myself ]
        ifelse new-location = nobody [
          print "I'm stuck!"
          die
        ]
        [
          move-to new-location
          set location new-location
          set locations-list lput location locations-list 
          ask location [ 
            set visited? true
            if target? = true [
              set color color + 1
              ask myself [
                die
              ]
            ]
          ]
        ]
      ]
    
      if not any? nodes with [ target? = true and visited? = false ] [
        print ("All target nodes have been visited.")
        stop
      ]
    
      if count walkers < 1 [
        spawn-walkers
      ]  
    
      tick
    end
    

    这篇关于使用Netlogo的复杂网络上的本地路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆