11#!/usr/bin/env python
22# -*- coding: utf-8 -*-
33
4+ import sys
45import datetime
56import json
6-
7+ import time
78import numpy as np
89import plotly
910import plotly .figure_factory as ff
@@ -71,11 +72,11 @@ def r(): return np.random.randint(0, 256, dtype=int)
7172def random_johnson (nb_machines , nb_jobs ):
7273 random_problem = RandomFlowshop (nb_machines , nb_jobs )
7374 rand_prob_inst = random_problem .get_problem_instance ()
74- seq , jobs , opt_makespan = rand_prob_inst .solve_johnson ()
75+ seq , jobs , opt_makespan , t_t = rand_prob_inst .solve_johnson ()
7576 fig = jobs_to_gantt_fig (jobs , random_problem .get_number_machines (
7677 ), random_problem .get_number_jobs ())
7778 gantt_json = ganttfig_to_json (fig )
78- return gantt_json , seq , opt_makespan
79+ return gantt_json , seq , opt_makespan , t_t
7980
8081
8182@app .route ('/solve' , methods = ["POST" ])
@@ -89,11 +90,18 @@ def solve():
8990 procesing_times = parse_problem_data (data )
9091 problem_inst = Flowshop (procesing_times , num_machines , num_jobs )
9192 if pfsp_algorithm == "johnson" :
92- seq , jobs , optim_makespan = problem_inst .solve_johnson ()
93+ seq , jobs , optim_makespan , t_t = problem_inst .solve_johnson ()
94+
9395 fig = jobs_to_gantt_fig (jobs , num_machines , num_jobs )
9496 graph_json = ganttfig_to_json (fig )
97+ if float (t_t ) * 1000 > 1000.0 :
98+ time_ts = t_t
99+ time_typ = "seconds"
100+ else :
101+ time_ts = float (t_t * 1000 )
102+ time_typ = "msecs"
95103 resp = json .dumps (
96- {"graph" : graph_json , "optim_makespan" : optim_makespan , "opt_seq" : seq })
104+ {"graph" : graph_json , "optim_makespan" : optim_makespan , "opt_seq" : seq , "t_time" : time_ts , "tt" : time_typ })
97105
98106 response = app .response_class (
99107 response = resp ,
@@ -102,35 +110,54 @@ def solve():
102110 )
103111 return response
104112 elif pfsp_algorithm == "palmer" :
105- seq , jobs , opt_makespan = problem_inst .palmer_heuristic ()
113+ seq , jobs , opt_makespan , t_t = problem_inst .palmer_heuristic ()
106114 fig = jobs_to_gantt_fig (jobs , num_machines , num_jobs )
107115 graph_json = ganttfig_to_json (fig )
116+
117+ if float (t_t ) * 1000 > 1000.0 :
118+ time_ts = t_t
119+ time_typ = "seconds"
120+ else :
121+ time_ts = float (t_t * 1000 )
122+ time_typ = "msecs"
108123 resp = json .dumps (
109- {"graph" : graph_json , "optim_makespan" : opt_makespan , "opt_seq" : seq })
124+ {"graph" : graph_json , "optim_makespan" : opt_makespan , "opt_seq" : seq , "t_time" : time_ts , "tt" : time_typ })
110125 response = app .response_class (
111126 response = resp ,
112127 status = 200 ,
113128 mimetype = "application/json" ,
114129 )
115130 return response
116131 elif pfsp_algorithm == "neh" :
117- seq , jobs , opt_makespan = problem_inst .neh_heuristic ()
132+ seq , jobs , opt_makespan , t_t = problem_inst .neh_heuristic ()
118133 fig = jobs_to_gantt_fig (jobs , num_machines , num_jobs )
119134 graph_json = ganttfig_to_json (fig )
135+ if float (t_t ) * 1000 > 1000.0 :
136+ time_ts = t_t
137+ time_typ = "seconds"
138+ else :
139+ time_ts = float (t_t * 1000 )
140+ time_typ = "msecs"
120141 resp = json .dumps (
121- {"graph" : graph_json , "optim_makespan" : opt_makespan , "opt_seq" : seq })
142+ {"graph" : graph_json , "optim_makespan" : opt_makespan , "opt_seq" : seq , "t_time" : time_ts , "tt" : time_typ })
122143 response = app .response_class (
123144 response = resp ,
124145 status = 200 ,
125146 mimetype = "application/json" ,
126147 )
127148 return response
128149 elif pfsp_algorithm == "bruteforce" :
129- seq , jobs , opt_makespan = problem_inst .brute_force_exact ()
150+ seq , jobs , opt_makespan , t_t = problem_inst .brute_force_exact ()
130151 fig = jobs_to_gantt_fig (jobs , num_machines , num_jobs )
131152 graph_json = ganttfig_to_json (fig )
153+ if float (t_t ) * 1000 > 1000.0 :
154+ time_ts = t_t
155+ time_typ = "seconds"
156+ else :
157+ time_ts = float (t_t * 1000 )
158+ time_typ = "msecs"
132159 resp = json .dumps (
133- {"graph" : graph_json , "optim_makespan" : opt_makespan , "opt_seq" : seq })
160+ {"graph" : graph_json , "optim_makespan" : opt_makespan , "opt_seq" : seq , "t_time" : time_ts , "tt" : time_typ })
134161 response = app .response_class (
135162 response = resp ,
136163 status = 200 ,
@@ -139,14 +166,17 @@ def solve():
139166 return response
140167
141168 elif pfsp_algorithm == "genetic-algorithm" :
142- seq , jobs , opt_makespan = problem_inst .genetic_algorithm ()
143- print (type (seq ))
144- print (type (seq [0 ]))
145- # exit(0)
169+ seq , jobs , opt_makespan , t_t = problem_inst .genetic_algorithm ()
146170 fig = jobs_to_gantt_fig (jobs , num_machines , num_jobs )
147171 graph_json = ganttfig_to_json (fig )
172+ if float (t_t ) * 1000 > 1000.0 :
173+ time_ts = t_t
174+ time_typ = "seconds"
175+ else :
176+ time_ts = float (t_t * 1000 )
177+ time_typ = "msecs"
148178 resp = json .dumps (
149- {"graph" : graph_json , "optim_makespan" : opt_makespan , "opt_seq" : seq })
179+ {"graph" : graph_json , "optim_makespan" : opt_makespan , "opt_seq" : seq , "t_time" : time_ts , "tt" : time_typ })
150180 response = app .response_class (
151181 response = resp ,
152182 status = 200 ,
@@ -155,11 +185,17 @@ def solve():
155185 return response
156186
157187 elif pfsp_algorithm == "cds" :
158- seq , jobs , opt_makespan = problem_inst .cds ()
188+ seq , jobs , opt_makespan , t_t = problem_inst .cds ()
159189 fig = jobs_to_gantt_fig (jobs , num_machines , num_jobs )
160190 graph_json = ganttfig_to_json (fig )
191+ if float (t_t ) * 1000 > 1000.0 :
192+ time_ts = t_t
193+ time_typ = "seconds"
194+ else :
195+ time_ts = float (t_t * 1000 )
196+ time_typ = "msecs"
161197 resp = json .dumps (
162- {"graph" : graph_json , "optim_makespan" : opt_makespan , "opt_seq" : seq })
198+ {"graph" : graph_json , "optim_makespan" : opt_makespan , "opt_seq" : seq , "t_time" : time_ts , "tt" : time_typ })
163199 response = app .response_class (
164200 response = resp ,
165201 status = 200 ,
@@ -187,9 +223,9 @@ def random():
187223
188224@app .route ('/' )
189225def index ():
190- graph_json , seq , opt_makespan = random_johnson (2 , 6 )
191- return render_template ('index.html' , plot = graph_json , seq = seq , opt_makespan = opt_makespan )
226+ graph_json , seq , opt_makespan , t_t = random_johnson (2 , 6 )
227+ return render_template ('index.html' , plot = graph_json , seq = seq , opt_makespan = opt_makespan , time = t_t )
192228
193229
194230if __name__ == "__main__" :
195- app .run (debug = True , port = 1337 )
231+ app .run (debug = False , port = 1337 )
0 commit comments