File size: 1,911 Bytes
85768b6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from env import WarehouseEnv
import numpy as np

def grade_agent(task_id, actions):
    """
    Grades an agent's sequence of actions against a specific warehouse task.
    """
    from tasks import get_task
    task_config = get_task(task_id)
    
    env = WarehouseEnv()
    obs, info = env.reset(options={
        "level": task_config["level"],
        "targets": task_config["targets"]
    })
    
    total_reward = 0
    steps = 0
    done = False
    
    for action in actions:
        if done:
            break
        obs, reward, terminated, truncated, info = env.step(action)
        total_reward += reward
        steps += 1
        done = terminated or truncated

    # Evaluation Criteria
    is_success = info.get("is_success", False)
    
    # Grading Algorithm
    score = 0
    if is_success:
        # Base completion score: 50
        # Efficiency bonus: up to 50
        efficiency = max(0, (task_config["max_steps"] - steps) / task_config["max_steps"])
        score = 50 + (50 * efficiency)
    else:
        # Partial credit: 10 points per item collected
        score = info.get("items_collected", 0) * 10

    # Ensure no unfair score
    score = max(0, min(100, score))

    return {
        "is_success": is_success,
        "final_score": round(score, 2),
        "total_reward": total_reward,
        "steps_taken": steps,
        "items_collected": info.get("items_collected", 0),
        "target_count": len(task_config["targets"]),
        "status": "Completed" if is_success else ("Failed (Timeout)" if steps >= task_config["max_steps"] else "Failed (Collision/Error)")
    }

if __name__ == "__main__":
    # Test Level 1: Navigate [0,0] -> [5,5] -> [0,0]
    # Simple manual path for testing the grader
    test_actions = ([3]*5 + [0]*5 + [4] + [2]*5 + [1]*5 + [5])
    result = grade_agent(1, test_actions)
    print(f"--- Grading Test (Level 1) ---")
    print(result)