1414
1515def parse_problem_data (data ):
1616 data_splitted = data .split ('\n ' )
17- number_machines = int (data_splitted [0 ].strip ())
18- number_jobs = int (data_splitted [1 ].strip ())
1917 processing_t__ = []
20- for line in data_splitted [ 2 ::] :
18+ for line in data_splitted :
2119 temp = list (map (int , line .strip ('\n ' ).split (' ' )))
2220 processing_t__ .append (temp )
23- print (processing_t__ )
24- return number_machines , number_jobs , processing_t__
21+ return processing_t__
2522
2623
2724def ganttfig_to_json (fig ):
@@ -69,11 +66,11 @@ def jobs_to_gantt_fig(scheduled_jobs, nb_machines, nb_jobs):
6966def random_johnson (nb_machines , nb_jobs ):
7067 random_problem = RandomFlowshop (nb_machines , nb_jobs )
7168 rand_prob_inst = random_problem .get_problem_instance ()
72- _ , jobs = rand_prob_inst .solve_johnson ()
69+ seq , jobs , opt_makespan = rand_prob_inst .solve_johnson ()
7370 fig = jobs_to_gantt_fig (jobs , random_problem .get_number_machines (
7471 ), random_problem .get_number_jobs ())
7572 gantt_json = ganttfig_to_json (fig )
76- return gantt_json
73+ return gantt_json , seq , opt_makespan
7774
7875
7976@app .route ('/solve' , methods = ["POST" , "GET" ])
@@ -82,26 +79,31 @@ def solve():
8279 prob = request .get_json ()
8380 pfsp_algorithm = prob ["algorithm" ]
8481 data = prob ["data" ]
85- num_machines , num_jobs , procesing_times = parse_problem_data (data )
82+ num_machines = int (prob ["nb_machines" ])
83+ num_jobs = int (prob ["nb_jobs" ])
84+ procesing_times = parse_problem_data (data )
8685 problem_inst = Flowshop (procesing_times , num_machines , num_jobs )
8786 if pfsp_algorithm == "johnson" :
88- _ , jobs = problem_inst .solve_johnson ()
87+ seq , jobs , optim_makespan = problem_inst .solve_johnson ()
8988 fig = jobs_to_gantt_fig (jobs , num_machines , num_jobs )
9089 graph_json = ganttfig_to_json (fig )
90+ resp = json .dumps (
91+ {"graph" : graph_json , "optim_makespan" : optim_makespan , "opt_seq" : seq })
92+ 9193 response = app .response_class (
92- response = graph_json ,
94+ response = resp ,
9395 status = 200 ,
9496 mimetype = 'application/json' ,
9597 )
9698 return response
9799
98- return render_template ("index.html" , plot = random_johnson (2 , 6 ))
100+ return render_template ("index.html" , plot = random_johnson (2 , 6 ), seq = seq , opt_makespan = optim_makespan )
99101
100102
101103@app .route ('/' )
102104def index ():
103- graph_json = random_johnson (2 , 6 )
104- return render_template ('index.html' , plot = graph_json )
105+ graph_json , seq , opt_makespan = random_johnson (2 , 6 )
106+ return render_template ('index.html' , plot = graph_json , seq = seq , opt_makespan = opt_makespan )
105107
106108
107109if __name__ == "__main__" :
0 commit comments