2022-11-30 14:28:27 +00:00
|
|
|
#! /bin/python3
|
|
|
|
|
2023-01-25 20:51:59 +00:00
|
|
|
import time, sys, random, copy
|
2023-02-24 18:08:41 +00:00
|
|
|
import importlib
|
2022-11-30 14:28:27 +00:00
|
|
|
from DAS import *
|
|
|
|
|
|
|
|
|
|
|
|
def study():
|
2023-01-23 17:04:54 +00:00
|
|
|
if len(sys.argv) < 2:
|
|
|
|
print("You need to pass a configuration file in parameter")
|
|
|
|
exit(1)
|
|
|
|
|
2023-03-02 00:01:52 +00:00
|
|
|
try:
|
|
|
|
config = importlib.import_module(sys.argv[1])
|
|
|
|
except ModuleNotFoundError as e:
|
|
|
|
try:
|
|
|
|
config = importlib.import_module(str(sys.argv[1]).replace(".py", ""))
|
|
|
|
except ModuleNotFoundError as e:
|
|
|
|
print(e)
|
|
|
|
print("You need to pass a configuration file in parameter")
|
|
|
|
exit(1)
|
|
|
|
|
2023-01-25 20:51:59 +00:00
|
|
|
shape = Shape(0, 0, 0, 0, 0, 0)
|
2023-02-23 11:16:43 +00:00
|
|
|
sim = Simulator(shape, config)
|
2022-11-30 14:28:27 +00:00
|
|
|
sim.initLogger()
|
2023-01-16 21:43:52 +00:00
|
|
|
results = []
|
2022-11-30 14:28:27 +00:00
|
|
|
simCnt = 0
|
2023-01-23 17:04:54 +00:00
|
|
|
|
2023-01-25 20:51:59 +00:00
|
|
|
now = datetime.now()
|
2023-03-14 10:25:17 +00:00
|
|
|
if config.deterministic:
|
|
|
|
random.seed("DASsimulator")
|
|
|
|
else:
|
|
|
|
random.seed(str(now).split(".")[1])
|
2023-01-25 20:51:59 +00:00
|
|
|
execID = now.strftime("%Y-%m-%d_%H-%M-%S_")+str(random.randint(100,999))
|
|
|
|
|
2022-11-30 14:28:27 +00:00
|
|
|
sim.logger.info("Starting simulations:", extra=sim.format)
|
|
|
|
start = time.time()
|
2023-01-23 17:04:54 +00:00
|
|
|
|
2023-02-24 18:08:41 +00:00
|
|
|
for shape in config.nextShape():
|
|
|
|
|
|
|
|
sim.resetShape(shape)
|
|
|
|
sim.initValidators()
|
|
|
|
sim.initNetwork()
|
|
|
|
result = sim.run()
|
|
|
|
sim.logger.info("Shape: %s ... Block Available: %d in %d steps" % (str(sim.shape.__dict__), result.blockAvailable, len(result.missingVector)), extra=sim.format)
|
|
|
|
results.append(copy.deepcopy(result))
|
|
|
|
simCnt += 1
|
2023-01-23 17:04:54 +00:00
|
|
|
|
2022-11-30 14:28:27 +00:00
|
|
|
end = time.time()
|
|
|
|
sim.logger.info("A total of %d simulations ran in %d seconds" % (simCnt, end-start), extra=sim.format)
|
2023-01-23 17:04:54 +00:00
|
|
|
|
2023-01-25 20:51:59 +00:00
|
|
|
if config.dumpXML:
|
|
|
|
for res in results:
|
|
|
|
res.dump(execID)
|
|
|
|
sim.logger.info("Results dumped into results/%s/" % (execID), extra=sim.format)
|
|
|
|
|
2023-02-22 15:45:39 +00:00
|
|
|
visualization = 1
|
|
|
|
if visualization:
|
|
|
|
vis = Visualizer(execID)
|
|
|
|
vis.plotHeatmaps()
|
2022-11-30 14:28:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
study()
|
|
|
|
|