-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
45 lines (38 loc) · 1.61 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from time import sleep
from UPISAS.exemplars.Dingnet import Dingnet_Exemplar
from UPISAS.strategies.dingnet_strategy import DingNetStrategy
import signal
import sys
import argparse
def init_argparse():
parser = argparse.ArgumentParser(
usage="%(prog)s [OPTION] [arg...]",
description="Run the DingNet exemplar in a docker container and control it with a self-adaptive strategy",
)
parser.add_argument("--debug", help="Run in debug mode", default=False)
parser.add_argument("--config", help="Configuration file name", default="world_1_6g1m.xml")
parser.add_argument("--speed", help="Simulation speed", default=5)
parser.add_argument("--algorithm", help="Algorithm to use, select from [DQN_discrete, Signal_based]", default="DQN_discrete")
parser.add_argument("--mode", help="Mode to use, select from [learning, normal]", default="learning")
return parser
def signal_handler(sig, frame):
print('You pressed Ctrl+C!')
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
if __name__ == '__main__':
parser = init_argparse()
args = parser.parse_args()
print(args)
exemplar = Dingnet_Exemplar(auto_start=True, debug=args.debug)
exemplar.start_run([])
exemplar.init_world(config_name=args.config, speed=args.speed)
exemplar.start_simulation()
try:
strategy = DingNetStrategy(exemplar, mode=args.mode, algorithm=args.algorithm)
while True:
strategy.monitor()
if strategy.analyze():
if strategy.plan():
strategy.execute(strategy.knowledge.plan_data)
except:
sys.exit(0)