MBG0903 commited on
Commit
61854d8
·
verified ·
1 Parent(s): 3bf4c1f

Update agents/reasoner.py

Browse files
Files changed (1) hide show
  1. agents/reasoner.py +55 -2
agents/reasoner.py CHANGED
@@ -1,6 +1,11 @@
1
  import pandas as pd
2
  import numpy as np
 
 
3
 
 
 
 
4
 
5
  def run_slotting_analysis(message, slotting_df):
6
  reasoning_steps = []
@@ -30,7 +35,6 @@ def run_slotting_analysis(message, slotting_df):
30
  # ---------------------------------------------------------
31
  # 3️⃣ Compute Slotting Score
32
  # ---------------------------------------------------------
33
- # Weighted: 60% velocity + 40% frequency
34
  df["Score"] = (0.6 * df["VelocityNorm"]) + (0.4 * df["FreqNorm"])
35
  reasoning_steps.append("Computed weighted slotting score (60% velocity, 40% frequency).")
36
 
@@ -39,7 +43,6 @@ def run_slotting_analysis(message, slotting_df):
39
  # ---------------------------------------------------------
40
  df = df.sort_values("Score", ascending=False).reset_index(drop=True)
41
 
42
- # Prime aisles 1–5 → best locations
43
  aisles = np.arange(1, len(df) + 1)
44
  racks = np.linspace(1, 20, len(df)).astype(int)
45
 
@@ -56,3 +59,53 @@ def run_slotting_analysis(message, slotting_df):
56
  )
57
 
58
  return explanation, df
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import pandas as pd
2
  import numpy as np
3
+ import matplotlib.pyplot as plt
4
+ import io
5
 
6
+ # ============================================================
7
+ # SLOTING OPTIMIZATION — PHASE 1
8
+ # ============================================================
9
 
10
  def run_slotting_analysis(message, slotting_df):
11
  reasoning_steps = []
 
35
  # ---------------------------------------------------------
36
  # 3️⃣ Compute Slotting Score
37
  # ---------------------------------------------------------
 
38
  df["Score"] = (0.6 * df["VelocityNorm"]) + (0.4 * df["FreqNorm"])
39
  reasoning_steps.append("Computed weighted slotting score (60% velocity, 40% frequency).")
40
 
 
43
  # ---------------------------------------------------------
44
  df = df.sort_values("Score", ascending=False).reset_index(drop=True)
45
 
 
46
  aisles = np.arange(1, len(df) + 1)
47
  racks = np.linspace(1, 20, len(df)).astype(int)
48
 
 
59
  )
60
 
61
  return explanation, df
62
+
63
+
64
+ # ============================================================
65
+ # PICKING ROUTE OPTIMIZATION — PHASE 1
66
+ # ============================================================
67
+
68
+ def run_picking_optimization(message, picking_df):
69
+ reasoning_steps = []
70
+
71
+ df = picking_df.copy()
72
+
73
+ # ---------------------------------------------------------
74
+ # 1️⃣ Convert Aisle–Rack to coordinates
75
+ # ---------------------------------------------------------
76
+ df["x"] = df["Aisle"]
77
+ df["y"] = df["Rack"]
78
+ reasoning_steps.append("Converted Aisle–Rack values into x–y coordinate grid.")
79
+
80
+ # ---------------------------------------------------------
81
+ # 2️⃣ Compute Manhattan distance
82
+ # ---------------------------------------------------------
83
+ df["Distance"] = df["x"].abs() + df["y"].abs()
84
+ df = df.sort_values("Distance").reset_index(drop=True)
85
+ reasoning_steps.append("Calculated Manhattan distance and sorted for optimal walk order.")
86
+
87
+ # ---------------------------------------------------------
88
+ # 3️⃣ Plot the route
89
+ # ---------------------------------------------------------
90
+ plt.figure(figsize=(6, 6))
91
+ plt.plot(df["x"], df["y"], marker="o", linestyle="-")
92
+ plt.title("Optimized Picking Route")
93
+ plt.xlabel("Aisle")
94
+ plt.ylabel("Rack")
95
+
96
+ # Save image to BytesIO buffer
97
+ buffer = io.BytesIO()
98
+ plt.savefig(buffer, format="png")
99
+ buffer.seek(0)
100
+ plt.close()
101
+
102
+ reasoning_steps.append("Generated optimized walking path visualization.")
103
+
104
+ explanation = (
105
+ "### 🚚 Picking Route Optimization\n"
106
+ "Using Manhattan distance and spatial ordering, an optimal walking sequence was generated.\n\n"
107
+ "#### 🔍 Key Reasoning Steps:\n"
108
+ + "\n".join([f"- {r}" for r in reasoning_steps])
109
+ )
110
+
111
+ return explanation, buffer