Typical problem and execution method
There is a set of customers (demand points) $ D $ and a set of facility placement points $ F $, each of which is given capacity. Each customer $ i \ in D $ always moves to one of the facilities $ i \ in F $. Find the destination of the customer so as to fill the capacity of each facility and minimize the sum of the customer's capacity and travel distance. However, the facility can only be used up to $ p $.
usage
Signature: facility_location(p, point, cand, func=None)
Docstring:
Facility placement problem
P-Median problem: Minimizing the sum of total distance x quantity
input
p:Maximum number of facilities
point:List of customer locations and quantities
cand:List of facility candidate locations and capacities
func:Customer position index,Weight function with facility candidate index as an argument
output
Facility number list for each customer
python
from ortoolpy import facility_location
facility_location(2, [(1, 0, 1), (0, 1, 1), (2, 2, 1)],
[(1, 0, 1), (0, 1, 1), (2, 2, 2)])
result
[0, 2, 2]
python
# pandas.DataFrame
from ortoolpy.optimization import FacilityLocation
FacilityLocation('data/facility.csv',2)
x | y | demand | capacity | id | |
---|---|---|---|---|---|
0 | 1 | 0 | 1.0 | 1.0 | 0.0 |
1 | 0 | 1 | NaN | 1.0 | NaN |
2 | 0 | 1 | 1.0 | NaN | 3.0 |
3 | 2 | 2 | 1.0 | 2.0 | 3.0 |
Recommended Posts