Team Ai
Apppublic

faizan-ai-ops/Multiagent-cab-operations-optimization-system

sourceHugging Faceupdated 8mo agoView on Hugging Face
0likes
driver_allocation_agent.py46 linesDownload Raw Back to root
1# agents/driver_allocation_agent.py
2
3class DriverAllocationAgent:
4
5    def __init__(self, demand_results):
6        self.data = demand_results
7
8    def allocate_drivers(self):
9
10        shortage_zones = []
11        surplus_zones = []
12
13        for z in self.data:
14            if z["status"] == "SHORTAGE":
15                shortage_zones.append(z)
16            elif z["status"] == "SURPLUS":
17                surplus_zones.append(z)
18
19        allocations = []
20
21        for shortage in shortage_zones:
22            needed = shortage["shortage"]
23
24            for surplus in surplus_zones:
25                available = abs(surplus["shortage"])
26
27                if available <= 0:
28                    continue
29
30                move = min(needed, available)
31
32                if move > 0:
33                    allocations.append({
34                        "from": surplus["zone"],
35                        "to": shortage["zone"],
36                        "drivers": move
37                    })
38
39                    needed -= move
40                    surplus["shortage"] += move
41
42                if needed <= 0:
43                    break
44
45        return allocations
46