Я пытаюсь написать программу, которая имитирует дроны, собирающие пакеты и доставляющие их на определенные платформы.Как только пакеты доставлены, они умирают.Прямо сейчас, если выполняется «один шаг», дроны немедленно перемещаются из местоположения пакета на платформу и снова в местоположение пакета.Тем не менее, я бы хотел, чтобы дроны двигались реальными шагами, чтобы я мог включить правильное время ожидания пакетов и получить лучшее представление о том, сколько времени потребуется для доставки одного пакета.
Я пытался реализовать «fd 1» в нескольких местах (например, сразу в функции «идти», но также отдельно в «летать» или оба в «летать-пусто» и «летать»).-loaded ". Если я реализую" fd 1 "в любом из этих мест, дроны все еще прыгают (для меня это кажется) случайных размеров прыжков, и система перестает функционировать, поскольку она фактически не собирает никаких пакетов.было бы здорово, если бы кто-то мог помочь мне с этим !! Заранее спасибо.
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