Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -137,44 +137,48 @@ def get_llm_prompt(echelon_state_decision_point: dict, week: int, llm_personalit
|
|
| 137 |
task_word = "order quantity"
|
| 138 |
base_info += f"- Shipments In Transit To You (arriving next week onwards): {list(e_state['incoming_shipments'])}"
|
| 139 |
|
| 140 |
-
# --- PERFECT RATIONAL (NORMATIVE) PROMPTS ---
|
| 141 |
|
| 142 |
if llm_personality == 'perfect_rational' and info_sharing == 'full':
|
| 143 |
stable_demand = current_stable_demand
|
| 144 |
|
| 145 |
-
#
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
|
|
|
|
|
|
|
|
|
| 152 |
|
| 153 |
-
# 2. OSCILLATION FIX: Calculate CORRECT
|
| 154 |
order_in_transit_to_supplier = st.session_state.game_state['last_week_orders'].get(e_state['name'], 0) # Order Delay (1 week)
|
| 155 |
|
| 156 |
if e_state['name'] == 'Factory':
|
| 157 |
# Factory pipeline: In Production (1 week)
|
| 158 |
supply_line = sum(st.session_state.game_state['factory_production_pipeline'])
|
| 159 |
-
|
|
|
|
| 160 |
|
| 161 |
elif e_state['name'] == 'Distributor':
|
| 162 |
# Distributor pipeline: In Shipping (1 week) + In Production (1 week) + Order Delay (1 week)
|
| 163 |
in_shipping = sum(e_state['incoming_shipments'])
|
| 164 |
in_production = sum(st.session_state.game_state['factory_production_pipeline'])
|
| 165 |
supply_line = in_shipping + in_production + order_in_transit_to_supplier
|
| 166 |
-
|
|
|
|
| 167 |
|
| 168 |
else: # Retailer and Wholesaler
|
| 169 |
# R/W pipeline: In Shipping (2 weeks) + Order Delay (1 week)
|
| 170 |
in_shipping = sum(e_state['incoming_shipments'])
|
| 171 |
supply_line = in_shipping + order_in_transit_to_supplier
|
| 172 |
-
|
|
|
|
| 173 |
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
return f"**You are a perfectly rational supply chain AI with full system visibility.**\nYour only goal is to maintain stability and minimize costs based on mathematical optimization.\n**System Analysis (Anchor & Adjust):**\n* **Known Stable End-Customer Demand:** {stable_demand} units/week.\n* **Your Target Net Inventory:** {safety_stock} units.\n* **Your Full Supply Line:** {supply_line} units {inv_pos_components}.\n* **Mathematically Optimal {task_word.title()}:**\n Order = (Stable Demand) + (Target Inventory - Current Inventory) - (Full Supply Line)\n Order = {stable_demand} + ({inventory_correction}) - {supply_line} = **{optimal_order} units**.\n**Your Task:** Confirm this optimal {task_word}. Respond with a single integer."
|
| 178 |
|
| 179 |
elif llm_personality == 'perfect_rational' and info_sharing == 'local':
|
| 180 |
safety_stock = 4
|
|
|
|
| 137 |
task_word = "order quantity"
|
| 138 |
base_info += f"- Shipments In Transit To You (arriving next week onwards): {list(e_state['incoming_shipments'])}"
|
| 139 |
|
| 140 |
+
# --- PERFECT RATIONAL (NORMATIVE) PROMPTS ---
|
| 141 |
|
| 142 |
if llm_personality == 'perfect_rational' and info_sharing == 'full':
|
| 143 |
stable_demand = current_stable_demand
|
| 144 |
|
| 145 |
+
# 1. CALCULATE CORRECT LEAD TIME (UNCHANGED)
|
| 146 |
+
if e_state['name'] == 'Factory':
|
| 147 |
+
total_lead_time = FACTORY_LEAD_TIME # 1
|
| 148 |
+
elif e_state['name'] == 'Distributor':
|
| 149 |
+
total_lead_time = ORDER_PASSING_DELAY + FACTORY_LEAD_TIME + FACTORY_SHIPPING_DELAY # 1+1+1 = 3
|
| 150 |
+
else:
|
| 151 |
+
total_lead_time = ORDER_PASSING_DELAY + SHIPPING_DELAY # 1+2 = 3
|
| 152 |
+
|
| 153 |
+
safety_stock = 4
|
| 154 |
+
target_inventory_level = (stable_demand * total_lead_time) + safety_stock
|
| 155 |
|
| 156 |
+
# 2. OSCILLATION FIX: Calculate CORRECT Inventory Position
|
| 157 |
order_in_transit_to_supplier = st.session_state.game_state['last_week_orders'].get(e_state['name'], 0) # Order Delay (1 week)
|
| 158 |
|
| 159 |
if e_state['name'] == 'Factory':
|
| 160 |
# Factory pipeline: In Production (1 week)
|
| 161 |
supply_line = sum(st.session_state.game_state['factory_production_pipeline'])
|
| 162 |
+
inventory_position = (e_state['inventory'] - e_state['backlog'] + supply_line)
|
| 163 |
+
inv_pos_components = f"(Inv={e_state['inventory']} - Backlog={e_state['backlog']} + InProd={supply_line})"
|
| 164 |
|
| 165 |
elif e_state['name'] == 'Distributor':
|
| 166 |
# Distributor pipeline: In Shipping (1 week) + In Production (1 week) + Order Delay (1 week)
|
| 167 |
in_shipping = sum(e_state['incoming_shipments'])
|
| 168 |
in_production = sum(st.session_state.game_state['factory_production_pipeline'])
|
| 169 |
supply_line = in_shipping + in_production + order_in_transit_to_supplier
|
| 170 |
+
inventory_position = (e_state['inventory'] - e_state['backlog'] + supply_line)
|
| 171 |
+
inv_pos_components = f"(Inv={e_state['inventory']} - Backlog={e_state['backlog']} + InTransitShip={in_shipping} + InProd={in_production} + OrderToSupplier={order_in_transit_to_supplier})"
|
| 172 |
|
| 173 |
else: # Retailer and Wholesaler
|
| 174 |
# R/W pipeline: In Shipping (2 weeks) + Order Delay (1 week)
|
| 175 |
in_shipping = sum(e_state['incoming_shipments'])
|
| 176 |
supply_line = in_shipping + order_in_transit_to_supplier
|
| 177 |
+
inventory_position = (e_state['inventory'] - e_state['backlog'] + supply_line)
|
| 178 |
+
inv_pos_components = f"(Inv={e_state['inventory']} - Backlog={e_state['backlog']} + InTransitShip={in_shipping} + OrderToSupplier={order_in_transit_to_supplier})"
|
| 179 |
|
| 180 |
+
optimal_order = max(0, int(target_inventory_level - inventory_position))
|
| 181 |
+
return f"**You are a perfectly rational supply chain AI with full system visibility.**\nYour only goal is to maintain stability and minimize costs based on mathematical optimization.\n**System Analysis:**\n* **Known Stable End-Customer Demand:** {stable_demand} units/week.\n* **Your Current Total Inventory Position:** {inventory_position} units. {inv_pos_components}\n* **Optimal Target Inventory Level:** {target_inventory_level} units (Target for {total_lead_time} weeks lead time).\n* **Mathematically Optimal {task_word.title()}:** The optimal decision is **{optimal_order} units**.\n**Your Task:** Confirm this optimal {task_word}. Respond with a single integer."
|
|
|
|
|
|
|
| 182 |
|
| 183 |
elif llm_personality == 'perfect_rational' and info_sharing == 'local':
|
| 184 |
safety_stock = 4
|