4

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.

Kevin Lee
  • 83
  • 6
  • 1
    One way set priorities on constraints is to allow them to be violated, and then penalize the extent of constraint violation in the objective function. For example in constraint 1 you might have `m += vxx <= t + slack_1`. Where `slack_1` is a linear variable which is then multiplied by an appropriate weight in the objective function. By setting the weights of each of the constraints you can define how important they are - however, this doesn't guarantee the order in which the constraints will be satisfied during solver running. – kabdulla Jan 21 '19 at 19:34
  • @kabdulla I think you comment should be an answer not a comment – Stuart Mitchell Jan 23 '19 at 01:40

1 Answers1

2

One way set priorities on constraints is to allow them to be violated by some amount, and then penalize the extent of constraint violation in the objective function.

For example in constraint 1 you might have m += vxx <= t + slack_1. Where slack_1 is a linear variable which is then multiplied by an appropriate weight in the objective function. By setting the weights of each of the constraint violations you can define how important those constraints are - however, this doesn't guarantee the order in which the constraints will be satisfied during solver running.

kabdulla
  • 5,199
  • 3
  • 17
  • 30