• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Apr 18th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. # !/usr/bin/env python3
2. import sys
3. import gurobipy as gb
4. # pilots
5. n = 12;
6. # dates
7. m = 4;
8. # commissioners
9. k = 5;
10.
11. cij = [[1, 0, 0, 1],
12.     [1, 0, 1, 1],
13.      [0, 0, 0, 1],
14.      [0, 0, 1, 1],
15.      [1, 1, 1, 1],
16.      [0, 0, 0, 1],
17.      [1, 0, 1, 1],
18.      [0, 0, 0, 0],
19.      [0, 1, 0, 1],
20.      [1, 0, 0, 1],
21.      [1, 1, 0, 1],
22.      [0, 0, 1, 1]]
23.
24. dlj = [[1, 1, 0, 1],
25.     [1, 0, 0, 1],
26.      [1, 1, 0, 1],
27.      [0, 0, 0, 1],
28.      [1, 1, 1, 1],
29.     ]
30.
31. model = gb.Model()
32.
33. # pilot i attends date j
34. aij = [];
35. for i in range(0, n):
36.     aij.append([model.addVar(lb=0, ub=1, vtype=gb.GRB.INTEGER, name="a_" + str(i)+"_" + str(j)) for j in range(0, m)])
37.
38. # commissioner l attends date j
39. blj = [];
40. for l in range(0, k):
41.     blj.append([model.addVar(lb=0, ub=1, vtype=gb.GRB.INTEGER, name="b_" + str(l)+"_" + str(j)) for j in range(0, m)])
42.
43. # each pilot attends a date exactly once
44. sum = 0;
45. for i in range(0, n):
46.     for j in range(0, m):
47.         sum += aij[i][j]
49.
50. # number of pilots must equal to the number of commissioners
51. for j in range(0, m):
52.     model.addConstr(gb.quicksum([aij[i][j] for i in range(0, n)]) == gb.quicksum([blj[l][j] for l in range(0, k)]))
53.
54.
55.
56. # each pilot will come to a date he can
57. sum =0;
58. for i in range(0, n):
59.     for j in range(0, m):
60.         sum += aij[i][j]*cij[i][j]
62.
63.
64. # commissioner can come to a date he will come
65. for l in range(0, k):
66.     for j in range(0, m):