| | import matplotlib.pyplot as plt |
| | import io |
| |
|
| |
|
| | def run_picking_optimization(message, picking_df): |
| | reasoning_steps = [] |
| |
|
| | df = picking_df.copy() |
| |
|
| | |
| | |
| | |
| | df["x"] = df["Aisle"] |
| | df["y"] = df["Rack"] |
| |
|
| | reasoning_steps.append("Converted Aisle–Rack values into x–y coordinate grid.") |
| |
|
| | |
| | |
| | |
| | df["Distance"] = df["x"].abs() + df["y"].abs() |
| | df = df.sort_values("Distance").reset_index(drop=True) |
| |
|
| | reasoning_steps.append("Calculated Manhattan distance and sorted for optimal walk order.") |
| |
|
| | |
| | |
| | |
| | plt.figure(figsize=(6, 6)) |
| | plt.plot(df["x"], df["y"], marker="o", linestyle="-") |
| | plt.title("Optimized Picking Route") |
| | plt.xlabel("Aisle") |
| | plt.ylabel("Rack") |
| |
|
| | |
| | buf = io.BytesIO() |
| | plt.savefig(buf, format="png") |
| | buf.seek(0) |
| | plt.close() |
| |
|
| | reasoning_steps.append("Generated optimized walking path visualization.") |
| |
|
| | explanation = ( |
| | "### 🚚 Picking Route Optimization\n" |
| | "Using Manhattan distance and spatial ordering, an optimal walking sequence was generated.\n\n" |
| | "#### 🔍 Key Reasoning Steps:\n" |
| | + "\n".join([f"- {r}" for r in reasoning_steps]) |
| | ) |
| |
|
| | return explanation, buf |
| |
|