Isha184 commited on
Commit
a5325eb
Β·
verified Β·
1 Parent(s): a8c0179

Update solver.py

Browse files
Files changed (1) hide show
  1. solver.py +22 -7
solver.py CHANGED
@@ -9,6 +9,17 @@ from PIL import Image
9
  import io
10
 
11
 
 
 
 
 
 
 
 
 
 
 
 
12
  # ---------------------------
13
  # Data utils
14
  # ---------------------------
@@ -378,14 +389,18 @@ def solve_vrp_tw(df, depot=(0.0, 0.0), n_vehicles=4,
378
  }
379
 
380
  metrics = {
381
- "vehicles_used": int(sum(1 for r in routes if r)),
382
- "total_distance": round(total_dist, 2),
383
- "per_route_distance": [round(d, 2) for d in per_route_dist],
384
- "per_route_load": [round(l, 2) for l in per_route_loads],
385
- "capacity": capacity,
386
- "time_window_report": time_window_report,
387
- "note": "Enhanced heuristic (TW-aware clustering β†’ insertion β†’ 2-opt β†’ Or-opt). Auto lateness scaling."
388
  }
 
 
 
 
389
 
390
  return {
391
  "routes": routes,
 
9
  import io
10
 
11
 
12
+ def convert_numpy(obj):
13
+ if isinstance(obj, dict):
14
+ return {k: convert_numpy(v) for k, v in obj.items()}
15
+ elif isinstance(obj, list):
16
+ return [convert_numpy(v) for v in obj]
17
+ elif isinstance(obj, (np.integer, np.floating)):
18
+ return obj.item()
19
+ else:
20
+ return obj
21
+
22
+
23
  # ---------------------------
24
  # Data utils
25
  # ---------------------------
 
389
  }
390
 
391
  metrics = {
392
+ "vehicles_used": int(sum(1 for r in routes if r)),
393
+ "total_distance": round(total_dist, 2),
394
+ "per_route_distance": [round(d, 2) for d in per_route_dist],
395
+ "per_route_load": [round(l, 2) for l in per_route_loads],
396
+ "capacity": capacity,
397
+ "time_window_report": time_window_report,
398
+ "note": "Enhanced heuristic (TW-aware clustering β†’ insertion β†’ 2-opt β†’ Or-opt). Auto lateness scaling."
399
  }
400
+
401
+ # βœ… Convert NumPy values to native types
402
+ metrics = convert_numpy(metrics)
403
+
404
 
405
  return {
406
  "routes": routes,