Modeling of a constraint with binary variables

The original problem I have is

for i=1:L
    for j=1:L
        for n=1:N
            if  W(i,j)>0 and i<j
                z(i,j)>=X(i,n)+X(j,n)-1;
            end
        end
    end
end

where W (L,L) is a known matrix and is symmetric. X(L,N) is optimization variable.

So, I tried to reduce the size of the problem by extracting all the pairs (i,j) for which W(i,j)>0. So, I removed the if condition.

Now, let’s says there are M such pairs.

veca contains the i’s

vecb contains the j’s

Now, the constraint becomes

for m=1:M
    for n=1:N
        z(m)>=X(veca(m),n)+ X(vecb(m),n)-1;
    end
end

Am I not doing i right?

If it is correct, I don’t know why it is taking so long for the CVX/solver to solve this? It is taking forever!

There’s CVX “modeling” time, for which vectorization can help.

As for solver solution time, Why is my MILP not finishing - YALMIP

I think in How to model this constraint in a better way? we already reached the conclusion that it is not CVX taking forever, but the solver, and we will debug it from there.

No need to open three threads on the same topic.

On the other hand it is good to provide as much information as possible and not code snippets removed from context. It is much easier for the readers who are trying to help you to ignore the extra information they don’t need, than for them to try to guess or dig themselves to the information they do need.

1 Like