Netlogo 如何让一只乌龟一步一步地走向另一只乌龟?
我正在尝试编写一个程序,模拟无人机拾取数据包并将其传送到特定平台。一旦包裹被送到,它们就会死亡。现在,如果执行“单一步骤”,无人机将立即从数据包位置移动到平台,然后再次移动到数据包位置。不过,我希望无人机能够按实际步骤移动,这样我就可以包括正确的数据包等待时间,更好地了解交付一个数据包需要多长时间 我曾尝试在多个位置执行“fd 1”(例如,立即在“to go”功能中执行,但也分别在“to fly”或“to fly empty”和“fly loaded”中执行。如果我在这些位置中的任何位置执行“fd 1”,无人机仍会跳入(对我来说,似乎是)随机跳转大小和系统停止运行,因为它实际上没有拾取任何包。如果有人能帮助我,这将是伟大的!!提前感谢Netlogo 如何让一只乌龟一步一步地走向另一只乌龟?,netlogo,Netlogo,我正在尝试编写一个程序,模拟无人机拾取数据包并将其传送到特定平台。一旦包裹被送到,它们就会死亡。现在,如果执行“单一步骤”,无人机将立即从数据包位置移动到平台,然后再次移动到数据包位置。不过,我希望无人机能够按实际步骤移动,这样我就可以包括正确的数据包等待时间,更好地了解交付一个数据包需要多长时间 我曾尝试在多个位置执行“fd 1”(例如,立即在“to go”功能中执行,但也分别在“to fly”或“to fly empty”和“fly loaded”中执行。如果我在这些位置中的任何位置执行“f
enter code here
breed [platforms platform]
breed [packets packet ]
breed [drones drone ]
drones-own [charge
mypacket
status
consumption
target
dropoff
capacity
transportedpackets
]
packets-own [destination
waitingtime
pickups
mydrone
lastdrone
]
globals [delivered
faults
nrdrones
deliverydrones
colorize
pickedup
destinationlist
dronewithpackets]
to setup
ca
clear-all-plots
setup-globals
setup-platforms
setup-drones
setup-packets
reset-ticks
end
to setup-globals
set delivered 0
set faults 0
set deliverydrones (list)
set destinationlist(list)
set colorize color?
end
to setup-platforms
create-platforms 1 [setxy -15 6 set color green set shape "circle" set label "Platform 0"]
create-platforms 1 [setxy -2 10 set color green set shape "circle" set label "Platform 1"]
create-platforms 1 [setxy 18 -7 set color green set shape "circle" set label "Platform 2"]
create-platforms 1 [setxy 9 -2 set color green set shape "circle" set label "Platform 3"]
end
to setup-drones
create-drones 3 [
setxy 0 0
set color red
set mypacket nobody
set status "ready"
set charge MaxCharge
set label who
set transportedpackets (list)
]
end
to setup-packets
create-packets 10 [
setxy 10 10
set color yellow
set shape "circle"
set size .5
set destination platform 1
set waitingtime 0
set pickups 0
set mydrone nobody
]
create-packets 4 [
setxy -10 -10
set color yellow
set shape "circle"
set size .5
set destination platform 3
set waitingtime 0
set pickups 0
set mydrone nobody
]
create-packets 10 [
setxy 9 -2
set color yellow
set shape "circle"
set size .5
set destination platform 1
set waitingtime 0
set pickups 0
set mydrone nobody
]
create-packets 10 [
setxy -2 -10
set color yellow
set shape "circle"
set size .5
set destination platform 0
set waitingtime 0
set pickups 0
set mydrone nobody
]
end
to go
ask drones with [status = "flying" ] [fly ]
ask drones with [status = "charging" ] [recharge ]
ask drones with [status = "ready" ] [pickup ]
ask packets with [mydrone = nobody ] [countwaitingtime ]
ask drones with [status = "waiting for new packets"] [packetstopickup ]
end
to fly
set charge charge - consumption
;print (word "Drone " who "has this much charge left: " charge)
if charge < 0 [if capacity != 0 [ask packets with [mydrone = dronewithpackets] [die] die]]
ifelse mypacket = nobody [fly-empty] [fly-loaded]
end
to fly-loaded
ask packets with [mydrone = dronewithpackets]
[print (word "Thanks drone" dronewithpackets " for dropping me, packet number " who " of at platform " position max destinationlist destinationlist) die]
move-to dropoff
if distance dropoff = 0
[land]
end
to fly-empty
ifelse any? packets with [mydrone = nobody]
[set target one-of packets with [mydrone = nobody]
move-to target
if distance target = 0
[pickup]]
[set status "waiting for new packets"
print "No more packets to transport at the moment"]
end
to land
set delivered delivered + capacity
set status "charging"
end
to pickup
ifelse any? packets-here with [mydrone = nobody]
[ set destinationlist (list)
set destinationlist lput (count packets-here with [destination = platform 0 and mydrone = nobody]) destinationlist
set destinationlist lput (count packets-here with [destination = platform 1 and mydrone = nobody]) destinationlist
set destinationlist lput (count packets-here with [destination = platform 2 and mydrone = nobody]) destinationlist
set destinationlist lput (count packets-here with [destination = platform 3 and mydrone = nobody]) destinationlist
;print destinationlist
;print (word "Platform " position max destinationlist destinationlist "is my next destination")
ifelse max destinationlist >= 5 [set capacity 4][set capacity max destinationlist]
set dronewithpackets who
ask n-of capacity packets-here with [destination = platform (position max destinationlist destinationlist) and mydrone = nobody] [
set mydrone dronewithpackets
print (word "I am packet " who "and I am transported by drone " mydrone "to platform " position max destinationlist destinationlist)
;print (word "I have been waiting to be pickedup for " waitingtime )
]
set dropoff platform (position max destinationlist destinationlist)
set mypacket capacity
set consumption capacity
set pickedup pickedup + capacity
;print (word "I picked up " capacity " packet(s)")
set transportedpackets lput capacity transportedpackets
;print (word "I am drone " who " and I have transported " sum transportedpackets " packets today" )
set status "flying"
]
[set mypacket nobody set consumption 1]
set status "flying"
end
to recharge
set charge charge + RechargePower
if charge > MaxCharge [set status "ready" ]
end
to countwaitingtime
set waitingtime waitingtime + 1
end
to packetstopickup
ifelse any? packets with [mydrone = nobody]
[pickup] [fly-empty]
end
在此处输入代码
繁殖[平台]
繁殖[包]
繁殖[无人机,无人机]
无人驾驶飞机拥有[冲锋]
我的包
地位
消费
目标
下降
容量
传输数据包
]
数据包拥有[目的地]
等待时间
拾音器
我的雄蜂
最后的雄蜂
]
全球[已交付]
缺点
无人机
投递无人机
着色
皮克多普
宿命论者
无人机(带数据包)
设置
ca
清除所有情节
设置全局
设置平台
安装无人机
设置数据包
重置滴答声
结束
设置全局
设置为0
设置错误0
设置交付无人驾驶飞机(列表)
设置目标列表(列表)
设置颜色?
结束
设置平台
创建平台1[setxy-15 6设置颜色绿色设置形状“圆形”设置标签“平台0”]
创建平台1[setxy-2 10组颜色绿色设置形状“圆形”设置标签“平台1”]
创建平台1[setxy 18-7设置颜色绿色设置形状“圆形”设置标签“平台2”]
创建平台1[设置XY 9-2设置颜色绿色设置形状“圆形”设置标签“平台3”]
结束
设置无人机
创建无人机3[
setxy 0 0
设置颜色为红色
把我的包给谁
将状态设置为“就绪”
设置电荷最大电荷
给谁贴标签
设置transportedpackets(列表)
]
结束
设置数据包
创建数据包10[
setxy 10 10
设置颜色为黄色
设置形状“圆”
设置大小
设置目的地站台1
将waitingtime设置为0
设置皮卡0
让我的无人驾驶飞机无人驾驶
]
创建数据包4[
setxy-10-10
设置颜色为黄色
设置形状“圆”
设置大小
设置目的地站台3
将waitingtime设置为0
设置皮卡0
让我的无人驾驶飞机无人驾驶
]
创建数据包10[
setxy 9-2
设置颜色为黄色
设置形状“圆”
设置大小
设置目的地站台1
将waitingtime设置为0
设置皮卡0
让我的无人驾驶飞机无人驾驶
]
创建数据包10[
setxy-2-10
设置颜色为黄色
设置形状“圆”
设置大小
将目标平台设置为0
将waitingtime设置为0
设置皮卡0
让我的无人驾驶飞机无人驾驶
]
结束
外带
用[status=“flying”][fly]询问无人机
向无人机询问[status=“charging”][充电]
向无人机询问[status=“ready”][拾取]
使用[mydrone=nobody][countwaitingtime]询问数据包
用[status=“waiting for new packets”][packetstopickup]询问无人机
结束
飞
设置费用-消耗
;打印(单词“无人机”谁“还有这么多的电荷:”电荷)
如果费用<0[如果容量!=0[询问带有[mydrone=dronewithpackets][die]die]的数据包]
ifelse mypacket=nobody[飞空][飞装]
结束
满载
使用[mydrone=Drone WithPackets]询问数据包
[打印(字“感谢无人机”无人机“带包无人机”丢弃我,包号“谁”在平台“位置最大目标列表目标列表)死亡]
迁离
如果距离衰减=0
[土地]
结束
空空飞行
如果还有?包含[mydrone=nobody]的数据包
[使用[mydrone=nobody]设置目标数据包之一]
向目标移动
如果距离目标=0
[拾取]]
[设置状态“等待新数据包”
打印“目前没有更多要传输的数据包”]
结束
降落
设置交付+容量
设置状态“充电”
结束
拾起
如果还有其他信息?这里有[mydrone=nobody]的数据包
[设置目标列表(列表)
设置destinationlist lput(此处使用[destination=platform 0和mydrone=nobody]统计数据包数)destinationlist
设置destinationlist lput(此处使用[destination=platform 1和mydrone=nobody]统计数据包数)destinationlist
设置destinationlist lput(此处使用[destination=platform 2和mydrone=nobody]统计数据包数)destinationlist
设置destinationlist lput(此处使用[destination=platform 3和mydrone=nobody]统计数据包数)destinationlist
;打印目标列表
;打印(文字“平台”位置最大目的地列表目的地列表“是我的下一个目的地”)
ifelse最大目的列表>=5[设置容量4][设置容量最大目的列表]
设置谁的数据包
在此询问n个容量数据包,其中[destination=平台(position max destinationlist destinationlist)和mydrone=无人][
用数据包设置mydrone无人机
打印(单词“我是谁”和我被无人机“我的无人机”传送到平台“位置最大目标列表目标列表”)
;打印(字“我一直在等待”等待时间)
]
设置升降平台(位置最大目标列表目标
face dropoff
forward 1
breed [targets target]
breed [drones drons]
to setup
ca
create-targets 5 [
set shape "circle"
set color white
setxy random-xcor random-ycor
]
create-drones 1 [
set color red
]
end
to go
ask one-of drones [
;; assuming you have multiple targets to choose from
;; if there is just one target, remove the line below
let temp-target one-of targets
face temp-target
while [distance temp-target != 0] [
ifelse distance temp-target < 1
[ move-to temp-target ]
[ wait 0.1 fd 1 ]
]
show "target reached"
]
end