Commit 52137267 authored by Ahmad Reza's avatar Ahmad Reza
Browse files

added scenario name to the directory name

parent ebad3ba3
......@@ -10,45 +10,40 @@ from datetime import datetime
from lib import sim
class ConfigData():
def __init__(self, config):
self.seedvalue = config.getint("Simulator", "seedvalue")
self.max_round = config.getint("Simulator", "max_round")
self.random_order = config.getboolean("Simulator", "random_order")
self.visualization = config.getint("Simulator", "visualization")
try:
self.scenario = config.get("File", "scenario")
except (configparser.NoOptionError) as noe:
self.scenario = "init_scenario.py"
try:
self.solution = config.get("File", "solution")
except (configparser.NoOptionError) as noe:
self.solution = "solution.py"
self.size_x = config.getint("Simulator", "size_x")
self.size_y = config.getint("Simulator", "size_y")
self.window_size_x = config.getint("Simulator", "window_size_x")
self.window_size_y = config.getint("Simulator", "window_size_y")
self.border = config.getint("Simulator", "border")
self.max_particles = config.getint("Simulator", "max_particles")
self.mm_limitation = config.getboolean("Matter", "mm_limitation")
self.particle_mm_size = config.getint("Matter", "particle_mm_size")
self.tile_mm_size = config.getint("Matter", "tile_mm_size")
self.location_mm_size = config.getint("Matter", "location_mm_size")
self.dir_name = None
def swarm_sim( argv ):
def swarm_sim(argv):
"""In the main function first the config is getting parsed and than
the simulator and the sim object is created. Afterwards the run method of the simulator
is called in which the simlator is going to start to run"""
config = configparser.ConfigParser(allow_no_value=True)
config.read("config.ini")
config_data=ConfigData(config)
seedvalue = config.getint("Simulator", "seedvalue")
max_round = config.getint("Simulator", "max_round")
random_order = config.getboolean("Simulator", "random_order")
visualization = config.getint("Simulator", "visualization")
try:
scenario_file = config.get ("File", "scenario")
except (configparser.NoOptionError) as noe:
scenario_file = "init_scenario.py"
try:
solution_file = config.get("File", "solution")
except (configparser.NoOptionError) as noe:
solution_file = "solution.py"
size_x = config.getint("Simulator", "size_x")
size_y = config.getint("Simulator", "size_y")
window_size_x = config.getint("Simulator", "window_size_x")
window_size_y = config.getint("Simulator", "window_size_y")
border = config.getint("Simulator", "border")
max_particles = config.getint("Simulator", "max_particles")
mm_limitation = config.getboolean("Matter", "mm_limitation")
mm_particle = config.getint("Matter", "particle_mm_size")
mm_tile= config.getint("Matter", "tile_mm_size")
mm_location=config.getint("Matter", "location_mm_size")
# tile_color_map = config.getboolean("Matter", "tile_color_map")
multiple_sim=0
local_time = datetime.now().strftime('%Y-%m-%d_%H:%M:%S')[:-1]
try:
opts, args = getopt.getopt(argv, "hs:w:r:n:m:d:v:", ["solution=", "scenario="])
except getopt.GetoptError:
......@@ -59,42 +54,49 @@ def swarm_sim( argv ):
print('run.py -r <randomeSeed> -w <scenario> -s <solution> -n <maxRounds>')
sys.exit()
elif opt in ("-s", "--solution"):
config_data.solution = arg
solution_file = arg
elif opt in ("-w", "--scenario"):
config_data.scenario = arg
scenario_file = arg
elif opt in ("-r", "--seed"):
config_data.seedvalue = int(arg)
seedvalue = int(arg)
elif opt in ("-n", "--maxrounds"):
config_data.max_round = int(arg)
max_round = int(arg)
elif opt in ("-m"):
multiple_sim = int(arg)
elif opt in ("-v"):
config_data.visualization = int(arg)
visualization = int(arg)
elif opt in ("-d"):
local_time = str(arg)
act_date = arg
#logging.basicConfig(filename='myapp.log', filemode='w', level=logging.INFO, format='%(asctime)s %(message)s')
logging.basicConfig(filename='system.log', filemode='w', level=logging.INFO, format='%(message)s')
nTime = datetime.now().strftime('%Y-%m-%d_%H-%M-%S-%f')[:-1]
dir_name = nTime + "_" + solution_file.rsplit('.',1)[0] + "_" + scenario_file.rsplit('.',1)[0] + "_" + \
str(seedvalue)
if multiple_sim == 1:
config_data.dir_name= local_time + "_" + config_data.scenario.rsplit('.', 1)[0] + \
"_" + config_data.solution.rsplit('.', 1)[0] + "/" + \
str(config_data.seedvalue)
directory = "./outputs/mulitple/"+ act_date + "_" + scenario_file.rsplit('.',1)[0] + \
"_"+solution_file.rsplit('.',1)[0] + "/" + str(seedvalue)
else:
directory = "./outputs/" + dir_name
if not os.path.exists(directory):
os.makedirs(directory)
config_data.dir_name = "./outputs/mulitple/"+ config_data.dir_name
else:
config_data.dir_name= local_time + "_" + config_data.scenario.rsplit('.', 1)[0] + \
"_" + config_data.solution.rsplit('.', 1)[0] + "_" + \
str(config_data.seedvalue)
config_data.dir_name = "./outputs/" + config_data.dir_name
if not os.path.exists(config_data.dir_name):
os.makedirs(config_data.dir_name)
logging.info('Started')
simulator = sim.Sim( config_data )
simulator=sim.Sim(seed=seedvalue, max_round=max_round, solution=solution_file.rsplit('.',1)[0],
size_x=size_x, size_y=size_y, scenario_name=scenario_file,
max_particles=max_particles, mm_limitation=mm_limitation,
particle_mm_size=mm_particle, tile_mm_size=mm_tile, location_mm_size=mm_location,
dir=directory, random_order=random_order,
visualization=visualization, border=border, window_size_x=window_size_x, window_size_y=window_size_y,)
simulator.run()
logging.info('Finished')
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment