我在这里看过了:示例代码 描述
我使用的是矢量地图,那里是道路。然后我画出道路所在的链接。从图像上看,起点是拉脱维亚的首都(里加)。左边是文斯皮尔斯市,离里加约200公里。第一是拉脱维亚/爱沙尼亚边界,也是大约200公里。底部大约有100公里。
我想要的是计算我需要在哪里放置汽车充电站。平均绿色汽车可以驾驶50公里的全电池。所以。我知道到文斯皮尔斯大约有200公里。我们需要那条路上的4个充电站。
想法1号是刚刚后每50公里从起点的地方充电站的各个方向。(图片上的树符号)。此时此刻,我正在随机放置充电站(树木):
to setup-stacijas
set-default-shape boats "tree"
create-boats num-boats [
set speed 0 ; min-speed + random-float (max-speed - min-speed)
let l one-of links
set size 18
set-next-stacija-link l [end1] of l
]
end
to set-next-stacija-link [l n] ;; boat proc
set cur-link l
move-to n
ifelse n = [end1] of l [set to-node [end2] of l] [set to-node [end1] of l]
face to-node
end问题:
我怎么能计算出到四面八方的距离?

发布于 2013-02-04 21:26:31
代理(补丁或海龟)可以使用距离原语与MOD操作符一起,找到50“英里”以外的其他代理。
我假设在我们的模拟中,1补丁=1英里。
我假设“链接”是连接到海龟的品种“节点”。
我假设START是一个包含“节点”的变量。
;; get all nodes that are multiples of 50 miles from start
let stations no-turtles
ask start [ set stations nodes with [ (floor distance myself) MOD 50 = 0 ]这并不完美,原因很多。
其他一些迭代方法也表明了自己:
- At intersections, traveler splits into new travelers to travel each branch
- when traveler meets a traveler, if the total distance from each traveler to its last "station" is more than 50 miles, a station is created. In any case, both travelers die.
- when a traveler finds an existing station, it dies.这样,在所有的道路上都会放置车站。
- Make the stations not on roads move toward the nearest road.
- One all stations have found a road, make stations move away from stations < 50 miles away, moving along roads (break tie by moving away from center of map).
- stations that hit the edge will "fall off" (die)
- so, stations will space themselves out, and extra staions will fall off the edges of map.这可能真的能行。
- Create a station on every mile of road.
- pick one station
- ## ask all other stations in 49 mile radius to die - mark it
- pick one of the stations 50 miles away.
- repeat from ## unil all stations are marked.这个可能不是最理想的。
- Put cars randomly on your roads (starting from cities). Cars can travel about 50 miles before needing recharge (dying)
- there are no stations
- simulate cars driving randomly on the roads.
- when a car hits a station it recharges fully
- if a car runs out of charge, it dies, and the counter for that patch/node/location is increased
- repeat
- when the counter in a patch exceeds some value, put a station there.
- when a station is created, the counters for all patches in a 50 mile radius are reduced--to 0 nearest the station, and by 0 furthest, in a gradular fashion.最终,电台会在需要的地方突然出现。看这个会很有趣的。
~~詹姆斯
https://stackoverflow.com/questions/13518899
复制相似问题