Spaces:
Runtime error
Runtime error
θζ³ζΊ
commited on
Commit
β’
c8cf824
1
Parent(s):
8ad6835
update
Browse files
app.py
CHANGED
@@ -27,6 +27,7 @@ def solver_plot(data_npy, boost=False):
|
|
27 |
return actual_fig, solution_fig, actual_ac, solution_ac
|
28 |
|
29 |
def demo_plot(city, facility):
|
|
|
30 |
all_facility = ["π« School", "π₯ Hospital", "π³ Park"]
|
31 |
for i in range(len(all_facility)):
|
32 |
if all_facility[i] in facility:
|
@@ -55,7 +56,7 @@ def demo_plot(city, facility):
|
|
55 |
size=10,
|
56 |
color=px.colors.qualitative.Plotly[i]
|
57 |
),
|
58 |
-
name=
|
59 |
))
|
60 |
solution_fig.add_trace(go.Scattermapbox(
|
61 |
lat=positions[solution_facility[:, i] == 1][:, 0],
|
@@ -65,7 +66,7 @@ def demo_plot(city, facility):
|
|
65 |
size=10,
|
66 |
color=px.colors.qualitative.Plotly[i]
|
67 |
),
|
68 |
-
name=
|
69 |
))
|
70 |
|
71 |
actual_fig.update_layout(
|
@@ -125,7 +126,7 @@ def solver_plot(data_npy, boost=False):
|
|
125 |
|
126 |
actual_facility = []
|
127 |
for i in range(2+p, 2+2*p):
|
128 |
-
actual_facility.append(bool(int(row[i])))
|
129 |
actual_facilities.append(actual_facility)
|
130 |
positions = np.array(positions)
|
131 |
demands = np.array(demands)
|
@@ -190,24 +191,17 @@ def solver_plot(data_npy, boost=False):
|
|
190 |
return actual_fig, solution_fig, actual_ac, solution_ac
|
191 |
|
192 |
|
193 |
-
|
194 |
-
|
195 |
def get_example():
|
196 |
return [
|
197 |
-
(
|
198 |
-
|
199 |
-
40.65 -73.88 365 1\n\
|
200 |
-
40.57 -73.96 629 0\n\
|
201 |
-
40.70 -73.97 106 0\n\
|
202 |
-
40.61 -73.95 189 1"),
|
203 |
-
("40.71 -73.93 213 124 0 1\n\
|
204 |
-
40.72 -73.99 15 43 1 0\n\
|
205 |
-
40.65 -73.88 365 214 1 0\n\
|
206 |
-
40.57 -73.96 629 431 0 1\n\
|
207 |
-
40.70 -73.97 106 241 0 1\n\
|
208 |
-
40.61 -73.95 189 264 1 0")
|
209 |
]
|
210 |
-
|
|
|
|
|
|
|
|
|
|
|
211 |
|
212 |
|
213 |
with gr.Blocks() as demo:
|
@@ -218,39 +212,39 @@ with gr.Blocks() as demo:
|
|
218 |
btn = gr.Button(value="π Generate")
|
219 |
with gr.Row():
|
220 |
actual_map = gr.Plot(label='Actual Facility Distribution')
|
221 |
-
solution_map = gr.Plot(label='
|
222 |
with gr.Row():
|
223 |
actual_ac = gr.Textbox(label='Real-world Access Cost')
|
224 |
-
solution_ac = gr.Textbox(label='
|
225 |
demo.load(fn=demo_plot, inputs=[city, facility], outputs=[actual_map, solution_map, actual_ac, solution_ac])
|
226 |
btn.click(fn=demo_plot, inputs=[city, facility], outputs=[actual_map, solution_map, actual_ac, solution_ac])
|
227 |
|
228 |
-
gr.Markdown("## FLP&IUMFLP Solver")
|
229 |
with gr.Column():
|
230 |
with gr.Row():
|
231 |
data_npy = gr.Textbox(label="Input")
|
232 |
data_file = gr.UploadButton(
|
233 |
label="π Upload a npy file",
|
234 |
-
file_count="
|
235 |
file_types=[".npy"])
|
236 |
with gr.Row():
|
237 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
238 |
btn2 = gr.Button(value="π Generate")
|
239 |
with gr.Row():
|
240 |
-
actual_map = gr.Plot(label='
|
241 |
-
solution_map = gr.Plot(label='
|
242 |
with gr.Row():
|
243 |
-
actual_ac = gr.Textbox(label='
|
244 |
-
solution_ac = gr.Textbox(label='
|
245 |
-
data_file.upload(fn=
|
246 |
btn2.click(fn=solver_plot, inputs=[data_npy, boost], outputs=[actual_map, solution_map, actual_ac, solution_ac])
|
247 |
|
248 |
-
gr.Examples(
|
249 |
-
examples=get_example(),
|
250 |
-
inputs=[data_npy],
|
251 |
-
fn=plot_from_npy,
|
252 |
-
outputs=[actual_map, solution_map],
|
253 |
-
)
|
254 |
-
|
255 |
if __name__ == "__main__":
|
256 |
-
demo.launch()
|
|
|
27 |
return actual_fig, solution_fig, actual_ac, solution_ac
|
28 |
|
29 |
def demo_plot(city, facility):
|
30 |
+
facility_name = ["π« School", "π₯ Hospital", "π³ Park"]
|
31 |
all_facility = ["π« School", "π₯ Hospital", "π³ Park"]
|
32 |
for i in range(len(all_facility)):
|
33 |
if all_facility[i] in facility:
|
|
|
56 |
size=10,
|
57 |
color=px.colors.qualitative.Plotly[i]
|
58 |
),
|
59 |
+
name=facility_name[i],
|
60 |
))
|
61 |
solution_fig.add_trace(go.Scattermapbox(
|
62 |
lat=positions[solution_facility[:, i] == 1][:, 0],
|
|
|
66 |
size=10,
|
67 |
color=px.colors.qualitative.Plotly[i]
|
68 |
),
|
69 |
+
name=facility_name[i],
|
70 |
))
|
71 |
|
72 |
actual_fig.update_layout(
|
|
|
126 |
|
127 |
actual_facility = []
|
128 |
for i in range(2+p, 2+2*p):
|
129 |
+
actual_facility.append(bool(int(float(row[i]))))
|
130 |
actual_facilities.append(actual_facility)
|
131 |
positions = np.array(positions)
|
132 |
demands = np.array(demands)
|
|
|
191 |
return actual_fig, solution_fig, actual_ac, solution_ac
|
192 |
|
193 |
|
|
|
|
|
194 |
def get_example():
|
195 |
return [
|
196 |
+
('40.71 -73.93 213 0\n40.72 -73.99 15 1\n40.65 -73.88 365 1\n40.57 -73.96 629 0\n40.70 -73.97 106 0\n40.61 -73.95 189 1'),
|
197 |
+
("40.71 -73.93 213 124 0 1\n40.72 -73.99 15 43 1 0\n40.65 -73.88 365 214 1 0\n40.57 -73.96 629 431 0 1\n40.70 -73.97 106 241 0 1\n40.61 -73.95 189 264 1 0")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
198 |
]
|
199 |
+
|
200 |
+
|
201 |
+
def load_npy_file(file_obj):
|
202 |
+
data = np.load(file_obj.name)
|
203 |
+
string_array = '\n'.join([' '.join(map(str, row)) for row in data])
|
204 |
+
return string_array
|
205 |
|
206 |
|
207 |
with gr.Blocks() as demo:
|
|
|
212 |
btn = gr.Button(value="π Generate")
|
213 |
with gr.Row():
|
214 |
actual_map = gr.Plot(label='Actual Facility Distribution')
|
215 |
+
solution_map = gr.Plot(label='Relocated Facility Distribution')
|
216 |
with gr.Row():
|
217 |
actual_ac = gr.Textbox(label='Real-world Access Cost')
|
218 |
+
solution_ac = gr.Textbox(label='Relocated Access Cost')
|
219 |
demo.load(fn=demo_plot, inputs=[city, facility], outputs=[actual_map, solution_map, actual_ac, solution_ac])
|
220 |
btn.click(fn=demo_plot, inputs=[city, facility], outputs=[actual_map, solution_map, actual_ac, solution_ac])
|
221 |
|
222 |
+
gr.Markdown("## FLP & IUMFLP Solver")
|
223 |
with gr.Column():
|
224 |
with gr.Row():
|
225 |
data_npy = gr.Textbox(label="Input")
|
226 |
data_file = gr.UploadButton(
|
227 |
label="π Upload a npy file",
|
228 |
+
file_count="single",
|
229 |
file_types=[".npy"])
|
230 |
with gr.Row():
|
231 |
+
gr.Examples(
|
232 |
+
examples=get_example(),
|
233 |
+
inputs=[data_npy],
|
234 |
+
fn=plot_from_npy,
|
235 |
+
outputs=[actual_map, solution_map],
|
236 |
+
)
|
237 |
+
with gr.Row():
|
238 |
+
boost = gr.Checkbox(label="Turbo Boost (accelerate solution generation with fewer SWAP steps)", value=False)
|
239 |
btn2 = gr.Button(value="π Generate")
|
240 |
with gr.Row():
|
241 |
+
actual_map = gr.Plot(label='Initial Solution')
|
242 |
+
solution_map = gr.Plot(label='Final Solution')
|
243 |
with gr.Row():
|
244 |
+
actual_ac = gr.Textbox(label='Initial Access Cost')
|
245 |
+
solution_ac = gr.Textbox(label='Final Access Cost')
|
246 |
+
data_file.upload(fn=load_npy_file, inputs=[data_file], outputs=[data_npy])
|
247 |
btn2.click(fn=solver_plot, inputs=[data_npy, boost], outputs=[actual_map, solution_map, actual_ac, solution_ac])
|
248 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
249 |
if __name__ == "__main__":
|
250 |
+
demo.launch()
|