How to determine if a constraint is actually applied to the model?

I have yet an another question. I have a working costraint:

            @variable(prmx, PRODAMOUNT[op_k in keys(_ORDER_PRODUCTs_ALL), u_k in keys(UNITS), t in TIME], Int, lower_bound = 0)

            for f_f_k in _FORB
                for (op_k1, op1) in _ORDER_PRODUCTs_ALL
                    if _PRODUCTs_ALL[op1["product"]]["familly"] == split(f_f_k,"-")[1] 
                        @constraint(
                            prmx, 
                            [u_k in keys(UNITS), t in TIME[1:end - 3]],
                            PRODAMOUNT[op_k1, u_k, t]
                            => {
                                sum(PRODAMOUNT[op_k, u_k, t + a]
                                for (op_k, op) in _ORDER_PRODUCTs_ALL, a in [1,2]
                                    if _PRODUCTs_ALL[op["product"]]["familly"] == split(f_f_k,"-")[2]
                                ) == 0
                            }
                        )                 
                    end
                end
            end   

This constraint will prohibit moving from forbidden product families. Now my question is how to denote that this actually happens? I mean if this constraint actually is used in the model.

All constraints are added to the model by definition.

If you find a case where the solution violates a constraint, that is a bug, and you should provide a reproducible example.

1 Like

The customer wants us to make a constraint so between 2 forbidden families of products we have 2 time units of different conditions. Something like this:

If A and B families are forbidden to use one after another then:

t1 -> use family A
t2 -> sum(family B) == 0, but anything else can apply
t3 -> sum(family B) == 0, but anything else can apply
t…-> can be anything

Placing constraint as above worked (as I did in the model too), but when I want to print the constraint in the output I don’t know how.

Here is the extract of the solution printout:

1,V500,500,o12,45,p34,216,G7,216,1
1,CINTAS,1000,o8,63,p8,760,G5,760,3
1,V150,160,o5,49,p6,112,G13,112,1
2,BUHLER1,1500,o11,38,p27,1380,G2,1380,3
2,V150,160,o14,25,p10,150,G2,150,1
3,CINTAS,1000,o6,50,p31,880,G3,880,3
3,BUHLER2,2000,o18,60,p25,3000,G13,1980,3
4,V150,160,o4,36,p44,100,G2,100,1
4,BUHLER2,2000,o17,36,p42,3300,G4,1980,3
5,V500,500,o15,29,p1,480,G13,80,1
5,V500,500,o1,50,p1,480,G13,400,1
5,V150,160,o14,25,p12,60,G2,60,1
5,BUHLER2,2000,o3,63,p26,3000,G2,1980,3
6,CINTAS,1000,o11,38,p45,540,G5,60,3
6,CINTAS,1000,o7,55,p45,540,G5,100,3

How can I know if that constraint applied to, for example, G3 family (3,CINTAS) and G5 family (6,CINTAS)?

So I want to know where the model actually applied the constraint?

Look if you are about to come to my house, when you arrive I would ask you how did you manage to find out where I am and you would say that my neighbor told you where I live :smile: Now the same thing is here, I want to ask the model why 3,CINTAS and 6,CINTAS are 2 time units apart? Is this because of the above constraint?

Re-solve the problem without the constraint, and see if the objective value changes?

3 Likes

As re-solving the model might take too much time (if not, I totally agree with @Per that would probably solve your problem) you might look into removing the constraint and then solve (See Sensitivity analysis solutions e.g. https://math.stackexchange.com/a/3629888)

3 Likes

I will then just iterate through the results and based on them try to figure out if the situation is the same as the constraint applied to it.