Isha184 commited on
Commit
129a2d7
·
verified ·
1 Parent(s): dc251bd

Update solver.py

Browse files
Files changed (1) hide show
  1. solver.py +18 -2
solver.py CHANGED
@@ -286,6 +286,13 @@ def solve_vrp(
286
  # Visualization
287
  # ---------------------------
288
 
 
 
 
 
 
 
 
289
  def plot_solution(
290
  df: pd.DataFrame,
291
  sol: Dict,
@@ -297,7 +304,9 @@ def plot_solution(
297
  ax.scatter([depot[0]], [depot[1]], s=120, marker="s", label="Depot", zorder=5)
298
 
299
  # color cycle
300
- colors = plt.rcParams["axes.prop_cycle"].by_key().get("color", ["C0","C1","C2","C3","C4","C5"])
 
 
301
 
302
  for v, route in enumerate(routes):
303
  if not route:
@@ -327,4 +336,11 @@ def plot_solution(
327
  ax.grid(True, alpha=0.25)
328
  ax.legend(loc="best", fontsize=8, framealpha=0.9)
329
  ax.set_aspect("equal", adjustable="box")
330
- return fig
 
 
 
 
 
 
 
 
286
  # Visualization
287
  # ---------------------------
288
 
289
+ # ---------------------------
290
+ # Visualization
291
+ # ---------------------------
292
+
293
+ from PIL import Image
294
+ import io
295
+
296
  def plot_solution(
297
  df: pd.DataFrame,
298
  sol: Dict,
 
304
  ax.scatter([depot[0]], [depot[1]], s=120, marker="s", label="Depot", zorder=5)
305
 
306
  # color cycle
307
+ colors = plt.rcParams["axes.prop_cycle"].by_key().get(
308
+ "color", ["C0","C1","C2","C3","C4","C5"]
309
+ )
310
 
311
  for v, route in enumerate(routes):
312
  if not route:
 
336
  ax.grid(True, alpha=0.25)
337
  ax.legend(loc="best", fontsize=8, framealpha=0.9)
338
  ax.set_aspect("equal", adjustable="box")
339
+
340
+ # ✅ Convert Matplotlib figure → PIL.Image for Gradio
341
+ buf = io.BytesIO()
342
+ fig.savefig(buf, format="png", bbox_inches="tight")
343
+ plt.close(fig)
344
+ buf.seek(0)
345
+ return Image.open(buf)
346
+