config.py 3.16 KB
Newer Older
1
2
import configparser
from datetime import datetime
Karol Actun's avatar
Karol Actun committed
3
4
from lib.visualization.grid_models import *
from ast import literal_eval as make_tuple
5
6
7
8
9
10
11
12

class ConfigData:

    def __init__(self):
        config = configparser.ConfigParser(allow_no_value=True)
        config.read("config.ini")
        self.seed_value = config.getint("Simulator", "seedvalue")
        self.max_round = config.getint("Simulator", "max_round")
Ahmad Reza's avatar
Ahmad Reza committed
13
        self.particle_random_order = config.getboolean("Simulator", "particle_random_order")
14
15
16
        self.window_size_x = config.getint("Simulator", "window_size_x")
        self.window_size_y = config.getint("Simulator", "window_size_y")

Karol Actun's avatar
Karol Actun committed
17
18
19
20
        self.visualization = config.getint("Visualization", "visualization")
        try:
            self.gui = config.get("Visualization", "gui")
        except configparser.NoOptionError as noe:
Karol Actun's avatar
Karol Actun committed
21
            print("no gui option given. setting to default \"gui.py\"")
Karol Actun's avatar
Karol Actun committed
22
23
            self.gui = "gui.py"

Karol Actun's avatar
Karol Actun committed
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
        try:
            self.grid_class = config.get("World", "grid_class")
        except configparser.NoOptionError as noe:
            raise RuntimeError("Fatal Error: no grid class defined in config.ini!")

        try:
            self.grid_size = config.getint("World", "grid_size")
        except configparser.NoOptionError as noe:
            raise RuntimeError("Fatal Error: no grid size defined in config.ini!")

        if self.grid_class == "cubic":
            self.grid = CubicGrid(self.grid_size)
        elif self.grid_class == "hexagonal":
            self.grid = HexagonalGrid(self.grid_size)
        else:
            raise RuntimeError("Fatal Error: unknown grid type \""+self.grid_class+"\"!")

        self.particle_model_file = config.get("Visualization", "particle_model_file")
        self.tile_model_file = config.get("Visualization", "tile_model_file")
        self.marker_model_file = config.get("Visualization", "marker_model_file")

        self.particle_color = make_tuple(config.get("Visualization", "particle_color"))
        self.tile_color = make_tuple(config.get("Visualization", "tile_color"))
        self.marker_color = make_tuple(config.get("Visualization", "marker_color"))
        self.grid_color = make_tuple(config.get("Visualization", "grid_color"))
Karol Actun's avatar
Karol Actun committed
49

50
51
52
53
54
55
56
57
58
59
        self.size_x = config.getfloat("World", "size_x")
        self.size_y = config.getfloat("World", "size_y")
        self.border = config.getboolean("World", "border")
        self.max_particles = config.getint("World", "max_particles")

        self.memory_limitation = config.getboolean("Matter", "memory_limitation")
        self.particle_mm_size = config.getint("Matter", "particle_mm_size")
        self.tile_mm_size = config.getint("Matter", "tile_mm_size")
        self.marker_mm_size = config.getint("Matter", "marker_mm_size")

60
61
62
63
64
65
66
67
68
        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"
69

Karol Actun's avatar
Karol Actun committed
70

71
72
        self.local_time = datetime.now().strftime('%Y-%m-%d_%H-%M-%S')[:-1]
        self.multiple_sim = 0