-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
120 lines (105 loc) · 5.05 KB
/
main.py
File metadata and controls
120 lines (105 loc) · 5.05 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#================================================================
# Enter of the project main file
# Last modify date: 2024 04/30
# Author: WU BIN
#================================================================
import configparser
import subprocess
import os
# read configuration file
def read_configuration(config_file):
config = configparser.ConfigParser()
config.read(config_file)
settings = {
'path': config.get('Settings', 'Path').strip('"'),
'mode': config.get('Settings', 'Mode'),
'seed': config.get('Settings', 'RandomSeed'),
'gra_location': config.getboolean('Settings', 'Gra_Location'),
'eng2_location': config.getboolean('Settings', 'Eng2_Location'),
'output_file': config.get('Settings', 'output_file').strip('"')
}
settings['mode'] = int(settings['mode'])
settings['seed'] = int(settings['seed'])
return settings
def main():
config_file = r'model/etc/configuration.conf'
settings = read_configuration(config_file)
# Choose the programm mode:
# If the mode=1 will not use active AP algorithm
if(settings['mode']==0):
print("==============================")
print("The system mode(0) is not using active AP choose algorithm")
# Construct the full path to the Walls.csv file
walls_csv_path = os.path.join(settings['path'], 'Walls.csv')
print("==============================")
# Check if the Walls.csv file exists at the specified path
if not os.path.exists(walls_csv_path):
print(f"Error: 'Walls.csv' not found at path: {walls_csv_path}")
return # Exit the program or raise an exception
# If the file exists, continue with the rest of the program
print("Walls.csv exists, proceeding with the rest of the program.")
print("==============================")
# Check if both locations are set to 1, which is not allowed
if settings['gra_location'] and settings['eng2_location']:
print("Error: Both Gra_Location and Eng#2_Location cannot be set to 1 simultaneously.")
print("==============================")
return
# Set the CSV file path based on configuration
if settings['gra_location']:
csv_file = settings['path'] + 'Gra_Location.csv'
print("You are using the map of Graduated Building !")
print("==============================")
elif settings['eng2_location']:
csv_file = settings['path'] + 'Eng_Location.csv'
print("You are using the map of Engneering Building#2 !")
print("==============================")
else:
print("No valid location configuration found.")
print("==============================")
return
# Prepare the arguments for Calc_Plan.py
csv_path = f"{csv_file}"
output_file = f"{settings['output_file']}"
# Call Calc_Plan.py with the necessary arguments
subprocess.run(['python', 'model/src/Calc_Plan.py', csv_path, output_file, walls_csv_path], check=True)
# If the mode=1 will use active AP algorithm
elif(settings['mode']==1):
print("==============================")
print("The system mode(1) is using active AP algorithm")
walls_csv_path = os.path.join(settings['path'], 'Walls.csv')
# csv path read
# Check if both locations are set to 1, which is not allowed
if settings['gra_location'] and settings['eng2_location']:
print("Error: Both Gra_Location and Eng#2_Location cannot be set to 1 simultaneously.")
print("==============================")
return
# Set the CSV file path based on configuration
if settings['gra_location']:
csv_file = settings['path'] + 'Gra_Location.csv'
print("You are using the map of Graduated Building !")
print("==============================")
elif settings['eng2_location']:
csv_file = settings['path'] + 'Eng_Location.csv'
print("You are using the map of Engneering Building#2 !")
print("==============================")
else:
print("No valid location configuration found.")
print("==============================")
return
csv_path = f"{csv_file}"
# Random seed read
# check input random seed:
if settings['seed'] > 100 or settings['seed'] < 0:
print("Error! Please check the seed range value!")
elif settings['seed'] is None:
print("Error! Please input and save your random seed!")
else:
print("The random seed is:",settings['seed'])
RandomSeed = settings['seed']
output_file = f"{settings['output_file']}"
subprocess.run(['python', 'model/src/ActiveAP.py', csv_path, walls_csv_path, RandomSeed, output_file], check=True)
else:
print("Error! The mode is:", settings['mode'],". Please check the mode setting in configuration.conf")
return
if __name__ == '__main__':
main()