I am trying to calculate an optimal answer to a set of binary variables with lots of constraints. I would like to set priorities for the constraints. ex) constraint 1, 2, 3 has priority 100 (highest) and constraint 4, 5, 6 has priority 1 (lowest)
I am currently using pulp linear programming and cbc solver to solve a production scheduling problem.
A small part of my data would look like this.
t0 t1 t2 t3 t4 t5 t6 t7 t8 t9
a v1 v2 v3 v4 v5 v6 v7 v8 v9 v10
b v11 v12 v13 v14 v15 v16 v17 v18 v19 v20
c v21 v22 v23 v24 v25 v26 v27 v28 v29 v30
v_list =
[[v1, v2, v3, v4, v5, v6, v7, v8, v9, v10],
[v11, v12, v13, v14, v15, v16, v17, v18, v19, v20],
[v21, v22, v23, v24, v25, v26, v27, v28, v29, v30]]
n_rows = v_list.shape[0]
n_columns = v_list.shape[1]
Each variable may be -1, 0, 1
The constraints I set will be something like below.
m = LpProblem()
# constraint 1, 2 = find absolute value of each variables
m += vxx <= t
m += -vxx <= t
# constraint 3 = sum of each row must be equal to or below 2
for r_index in range(n_rows):
m += lpSum(v_list[r_index, :]) <= 2
# constraint 4 = sum of rows a and b must be equal to or below 2
m += lpSum(v_list[[0, 1], :]) <= 2
# constraint 5 = sum of all rows must be equal to or below 2
for c_index in n_columns:
m += lpSum(v_list[:, c_index]) <= 2
# constraint 6 = sum of each consecutive value must be equal to or below 1
m += lpSum(v(t) + v(t+1)) <= 1
The objective is to minimize 2 * row(a) + 2 * row(b) + 4 * row(c)
m += lpSum(v_list)
When solving the model with a short time limit and LpStatus is 0 (Unsolved), the constraints with the highest priority are fully met, but others are only partially met.
ex) constraint 1 2 3 4 are met but 5 6 are partial.