Typical problem and execution method
$ n $ jobs $ J = \ {1,2, \ dots, n \} $ and $ m $ agents $ I = \ {1,2, \ dots, m \} $ On the other hand, the cost of allocating work $ j \ in J $ to agent $ i \ in I $ $ c_ {ij} $, resource requirement $ a_ {ij} (\ ge 0) $, and each agent The available resource amount $ b_i (\ ge 0) $ of $ i \ in I $ is given. Each job must be assigned to one of the agents, and the total resource requirements for the jobs assigned to each agent must not exceed the available resources of that agent. At this time, find the allocation that minimizes the total cost.
usage
Signature: gap(cst, req, cap)
Docstring:
Generalization allocation problem
Solve the minimum cost allocation
input
cst:Table of costs by agent and job
req:Request amount table for each agent and job
cap:List of agent capacities
output
Agent number list for each job
python
from ortoolpy import gap
gap([[2, 2, 2], [1, 1, 1]], [[1, 1, 1], [1, 1, 1]], [2, 1])
result
[0, 0, 1]
python
# pandas.DataFrame
from ortoolpy.optimization import Gap
Gap('data/gap.csv', [2,1])
agent | job | cost | req | |
---|---|---|---|---|
0 | 0 | 0 | 2 | 1 |
1 | 0 | 1 | 2 | 1 |
5 | 1 | 2 | 1 | 1 |
Recommended Posts