model for solving the k-median problem. More...
Go to the source code of this file.
Functions | |
| def | kmedian (I, J, c, k) |
| def | distance (x1, y1, x2, y2) |
| def | make_data (n, m, same=True) |
Variables | |
| int | n = 200 |
| m = n | |
| I | |
| J | |
| c | |
| x_pos | |
| y_pos | |
| same | |
| int | k = 20 |
| model = kmedian(I,J,c,k) | |
| int | EPS = 1 |
| x | |
| y | |
| list | edges = [(i,j) for (i,j) in x if model.getVal(x[i,j]) > EPS] |
| list | facilities = [j for j in y if model.getVal(y[j]) > EPS] |
| G = NX.Graph() | |
| other = set(j for j in J if j not in facilities) | |
| client = set(i for i in I if i not in facilities and i not in other) | |
| dictionary | position = {} |
| with_labels | |
| False | |
| node_color | |
| nodelist | |
| node_size | |
model for solving the k-median problem.
Definition in file kmedian.py.
| def kmedian.distance | ( | x1, | |
| y1, | |||
| x2, | |||
| y2 | |||
| ) |
return distance of two points
Definition at line 43 of file kmedian.py.
| def kmedian.kmedian | ( | I, | |
| J, | |||
| c, | |||
| k | |||
| ) |
kmedian -- minimize total cost of servicing customers from k facilities
Parameters:
- I: set of customers
- J: set of potential facilities
- c[i,j]: cost of servicing customer i from facility j
- k: number of facilities to be used
Returns a model, ready to be solved.
Definition at line 13 of file kmedian.py.
| def kmedian.make_data | ( | n, | |
| m, | |||
same = True |
|||
| ) |
creates example data set
Definition at line 48 of file kmedian.py.