-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.py
230 lines (188 loc) · 9.79 KB
/
main.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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
import sys
from PyQt5.QtWidgets import *
from PyQt5 import uic
from PyQt5.QtGui import *
import urllib.request
import json
import psutil
form_class = uic.loadUiType("./main_window.ui")[0]
from PyQt5.QtCore import Qt
from Map import *
from SimSet import *
from Simulator import *
import os
#멀티프로세스를 위한 패키지
from multiprocessing import Process, Manager
from sub_proc_simulator import *
from fast_simulation import *
from Dynamic.dynamic_sim_gui import Dynamic_Sim
class WindowClass(QMainWindow, form_class):
def __init__(self):
super(WindowClass,self).__init__()
self.setupUi(self)
self.setWindowTitle("TSP 시뮬레이터")
self.move(500, 300)
self.setFixedWidth(263)
self.setFixedHeight(476)
self.mapMaker = Widget_Warehouse() # warehouse make tool Widget
self.mapMaker.hide()
self.ui_info = [self.mapMaker.init_map_x, self.mapMaker.init_map_y] # init parameter
self.simulation_maker = Widget_SimSet() # simulation setting tool widget
self.simulation_maker.hide()
self.simulator = Widget_Simulator_no_gui()
self.simulator.hide()
self.map_data = None
self.run_count = 0 #시물레이션을 돌린횟수입니다.
#시그널링 설정
self.button_openmapmaker.clicked.connect(self.openMap)
self.button_loadMap.clicked.connect(self.loadMap)
self.button_paramset.clicked.connect(self.setSim)
self.button_simStart.clicked.connect(self.openSimulator) # start static simulator(static order picking)
self.button_simStart_dynamic.clicked.connect(self.openDynamicSimulator) # start dynamic simulator(dynamic order picking , order is arrived)
#---21-11-17 : 다이나믹 시물레이션 추가
self.dynamic_simulation = None
def openDynamicSimulator(self):
'''
동적 시물레이션을 엽니다.
'''
if self.dynamic_simulation :
del self.dynamic_simulation#시물레이터를 삭제합니다.
self.dynamic_simulation = Dynamic_Sim()#다시만듭니다.
self.dynamic_simulation.start(self.map_data, self.simulation_maker.sim_data, self.ui_info)
def getProcess(self, order_maker,warehouse_fast_solver,warehouse_tsp_solver):
self.order_maker = order_maker
self.warehouse_tsp_solver = warehouse_tsp_solver
self.warehouse_fast_solver = warehouse_fast_solver
def set_data(self, order_data,sim_data):
self.order_data = order_data
self.sim_data = sim_data
def closeEvent(self, QCloseEvent):
self.sim_data['is_kill_robot_move'] = True
time.sleep(1)
self.order_maker.kill()
self.warehouse_tsp_solver.kill()
self.warehouse_fast_solver.kill()
self.simulator=None
def openSimulator(self):
if self.simulator :
del self.simulator #시물레이터를 삭제합니다.
self.simulator = Widget_Simulator_no_gui() # 시물레이터를 시작합니다.
if not self.map_data: # 세팅된 맵이 있는지 확인합니다.
msgBox = QMessageBox()
msgBox.setWindowTitle("경고")
msgBox.setText("맵의 정보가 없습니다.")
msgBox.exec_()
return False
# self.simulator.setMapInfo(self.map_data, self.ui_info)
if not self.simulation_maker.sim_data: #시물레이션 정보를 얻어옵니다.
msgBox = QMessageBox()
msgBox.setWindowTitle("경고")
msgBox.setText("시물레이션의 정보가 없습니다.")
msgBox.exec_()
return False
self.simulator.set_data(self.order_data, self.sim_data,self.map_data, self.ui_info)
#시물레이션간에 필요한 사전정보를 넣어줍니다.
self.order_data['sim_data'] = self.simulation_maker.sim_data
self.sim_data['ui_info'] = self.ui_info
self.sim_data['map_data'] = self.map_data
self.simulator.start_setting() # 그냥 시작합니다.
self.simulator.timer.start(500)
self.simulator.show()
# self.simulator.show()#실제 시물레이션을 킵니다.
self.run_count +=1#몇번돌렸는지를 확인합니다.
def openMap(self):
if self.mapMaker :
del self.mapMaker
self.mapMaker = Widget_Warehouse()
self.mapMaker.show()
def loadMap(self):
FileSave = QFileDialog.getOpenFileName(self, '맵 불러오기', './Map/', "Map File (*.json)")[0]
if FileSave == "":
pass
else:
with open(FileSave, 'r') as fp:
data = json.load(fp)
self.map_data = data
def setSim(self):
if self.simulation_maker.is_safe_close:
self.simulation_maker.show()
self.simulation_maker.is_safe_close= False
self.last_is_randomorder = self.simulation_maker.is_randomOrder
self.last_init_order = int(self.simulation_maker.lineEdit_initorder.text())
self.last_order_rate = int(self.simulation_maker.lineEdit_orderrate.text())
self.last_robot_cap = int(self.simulation_maker.lineEdit_robotcap.text())
self.last_robot_number = int(self.simulation_maker.lineEdit_robotnumber.text())
else :
if self.last_is_randomorder:
self.simulation_maker.radioButton_orderrandom.setChecked(True) # 랜덤으로 아이템을 배치하는 의미로 라디오버튼을 킵니다.
self.simulation_maker.lineEdit_initorder.setDisabled(True)
self.simulation_maker.lineEdit_orderrate.setDisabled(True)
else:
self.simulation_maker.radioButton_orderdirect.setChecked(True) # 랜덤으로 아이템을 배치하는 의미로 라디오버튼을 킵니다.
self.simulation_maker.lineEdit_initorder.setEnabled(True)
self.simulation_maker.lineEdit_orderrate.setEnabled(True)
self.simulation_maker.lineEdit_initorder.setText(str(self.last_init_order))
self.simulation_maker.lineEdit_orderrate.setText(str(self.last_order_rate))
self.simulation_maker.lineEdit_robotcap.setText(str(self.last_robot_cap))
self.simulation_maker.lineEdit_robotnumber.setText(str(self.last_robot_number))
self.simulation_maker.show()
if __name__ == "__main__":
try:
os.environ["QT_AUTO_SCREEN_SCALE_FACTOR"] ='1'
app = QApplication(sys.argv)
app.setAttribute(Qt.AA_EnableHighDpiScaling)
#시물레이션을 본격적으로 돌리는 프로세스 입니다.
sim_data = Manager().dict() # shared simulation parameter
order_data = Manager().dict() # shared order parameter
sim_data["tsp_solver"] = 'NO_TSP' # FCFS way
order_data["is_start"] = False # Purpose : order generator start check
sim_data["is_start"] = False # Purpose : main simulator start check
sim_data["fast_start"] = False # Purpose : fast simulator start check
sim_data["robot_cordinates"] =[] # Purpose : current robot pose(dynamic)
sim_data["goal_cordinates"] = [] # Purpose : current robot goal pose(dynamic)
sim_data["shelf_node"] = [] # Purpose : shelf node coordinates (static after simulation start)
sim_data["robot_routes"] = []
sim_data["packing_ind"] = []
sim_data["packing_color"] = []
sim_data["packing_point"] = []
sim_data["robot_full_routes"] = []
sim_data["number_order"] =0
sim_data['compare_robot_ind'] =0
sim_data['compare_route'] = []
sim_data["compare_tsp_solver"] = "NO_TSP"
sim_data["tsp_length"] = [1000,1000,1000,1000,1000,1000]
sim_data['compare_time'] = [0,0,0,0,0,0]
order_data["is_set_order"] = False # 선반의 개수가 다 정해졋는지 확인할 때, 사용하는변수
order_data["is_set_initOrder"] = False # 초기 주문들이 다 정해졋을때, 사용하는 변수
order_data["len_order"] =0
order_data["end_flag"] = False
#연속적인 시물레이션 사용간에 사용되는 변수들
sim_data['solver_set'] = ['NO_TSP',"DC","GREEDY","PSO","GA","ACO"]
sim_data['solver_ind'] = 0
sim_data['order_do'] = 0
sim_data['algorithm_time'] = [[], [], [], [], [], []]
sim_data['algorithm_step'] = [[], [], [], [], [], []]
sim_data['algorithm_full_time'] = [0. for _ in range(len(sim_data['solver_set']))]
sim_data['simulation_end'] = False
sim_data['Total_elapsed_time'] = [0. for _ in range(len(sim_data['solver_set']))]
sim_data['Average_travel_time'] = [0. for _ in range(len(sim_data['solver_set']))]
sim_data['Average_travel_distance'] = [0. for _ in range(len(sim_data['solver_set']))]
sim_data['Computation_time'] = [0. for _ in range(len(sim_data['solver_set']))]
sim_data["force_die"] = False
sim_data["doing_order"] =0
order_maker_process = Process(target=warehouse_order_maker, args=(order_data, 1)) # main simulator
warehouse_main_solver_process = Process(target=warehouse_tsp_solver, args=(sim_data,order_data)) # main simulator
warehouse_fast_solver_process = Process(target=process_Fast_sim, args=(sim_data, order_data)) # fast simulator
order_maker_process.start() # main simulator start
warehouse_main_solver_process.start() # main simulator start
warehouse_fast_solver_process.start()
#GUI를 담당하는 프로세스 입니다.
myWindow = WindowClass()
myWindow.getProcess(order_maker_process, warehouse_fast_solver_process, warehouse_main_solver_process)
myWindow.set_data(order_data, sim_data)
myWindow.show()
sys.exit(app.exec_())
except:
# order_maker.join()
# warehouse_fast_solver.join()
print(" ")