Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files- Dockerfile +8 -0
- README.md +26 -10
- inference.py +55 -0
- openenv.yaml +7 -0
Dockerfile
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.10
|
| 2 |
+
|
| 3 |
+
WORKDIR /app
|
| 4 |
+
COPY . .
|
| 5 |
+
|
| 6 |
+
RUN pip install openai
|
| 7 |
+
|
| 8 |
+
CMD ["python", "inference.py"]
|
README.md
CHANGED
|
@@ -1,10 +1,26 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Food Delivery Dispatch Environment (OpenEnv)
|
| 2 |
+
|
| 3 |
+
## Description
|
| 4 |
+
This project simulates a food delivery system where an AI agent assigns orders to riders to maximize on-time deliveries.
|
| 5 |
+
|
| 6 |
+
## State Space
|
| 7 |
+
- Orders: location, prep_time, deadline
|
| 8 |
+
- Riders: location
|
| 9 |
+
|
| 10 |
+
## Action Space
|
| 11 |
+
- assign_<order_id>_to_<rider_id>
|
| 12 |
+
|
| 13 |
+
## Reward Function
|
| 14 |
+
- On-time delivery: +1
|
| 15 |
+
- Slight delay: +0.3
|
| 16 |
+
- Late: -0.5
|
| 17 |
+
- Invalid: -1
|
| 18 |
+
|
| 19 |
+
## Tasks
|
| 20 |
+
- Easy: 2 orders, 1 rider
|
| 21 |
+
- Medium: 4 orders, 2 riders
|
| 22 |
+
- Hard: 6 orders, random setup
|
| 23 |
+
|
| 24 |
+
## Run
|
| 25 |
+
```bash
|
| 26 |
+
python inference.py
|
inference.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from env.delivery_env import DeliveryEnv
|
| 3 |
+
from graders.grader import compute_score
|
| 4 |
+
|
| 5 |
+
TASK = os.getenv("TASK", "easy")
|
| 6 |
+
|
| 7 |
+
env = DeliveryEnv()
|
| 8 |
+
state = env.reset(TASK)
|
| 9 |
+
|
| 10 |
+
print(f"[START] task={TASK} env=food_delivery model=smart-urgency-agent")
|
| 11 |
+
|
| 12 |
+
rewards = []
|
| 13 |
+
step_count = 0
|
| 14 |
+
|
| 15 |
+
while True:
|
| 16 |
+
orders = [o for o in state["orders"] if not o["assigned"]]
|
| 17 |
+
riders = state["riders"]
|
| 18 |
+
|
| 19 |
+
if not orders:
|
| 20 |
+
break
|
| 21 |
+
|
| 22 |
+
best_score = float("inf")
|
| 23 |
+
best_action = None
|
| 24 |
+
|
| 25 |
+
# 🔥 Evaluate all (order, rider) pairs
|
| 26 |
+
for order in orders:
|
| 27 |
+
for rider in riders:
|
| 28 |
+
distance = abs(rider["location"] - order["location"])
|
| 29 |
+
urgency = order["deadline"] - state["time"]
|
| 30 |
+
|
| 31 |
+
score = distance + urgency # lower is better
|
| 32 |
+
|
| 33 |
+
if score < best_score:
|
| 34 |
+
best_score = score
|
| 35 |
+
best_action = (order, rider)
|
| 36 |
+
|
| 37 |
+
order, rider = best_action
|
| 38 |
+
action = f"assign_{order['id']}_to_{rider['id']}"
|
| 39 |
+
|
| 40 |
+
state, reward, done, info = env.step(action)
|
| 41 |
+
|
| 42 |
+
rewards.append(reward)
|
| 43 |
+
step_count += 1
|
| 44 |
+
|
| 45 |
+
error = info["error"] if info["error"] else "null"
|
| 46 |
+
|
| 47 |
+
print(f"[STEP] step={step_count} action={action} reward={reward:.2f} done={str(done).lower()} error={error}")
|
| 48 |
+
|
| 49 |
+
if done:
|
| 50 |
+
break
|
| 51 |
+
|
| 52 |
+
max_possible = len(rewards) * 1.5 # adjusted for bonus rewards
|
| 53 |
+
score = compute_score(sum(rewards), max_possible)
|
| 54 |
+
|
| 55 |
+
print(f"[END] success=true steps={step_count} score={score:.2f} rewards={','.join(f'{r:.2f}' for r in rewards)}")
|
openenv.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: food_delivery_env
|
| 2 |
+
entry_point: env.delivery_env:DeliveryEnv
|
| 3 |
+
|
| 4 |
+
tasks:
|
| 5 |
+
- easy
|
| 6 |
+
- medium
|
| 7 |
+
- hard
|