Cannot find feasible solution

30 views
Skip to first unread message

Bogosel Beniamin

unread,
Mar 30, 2014, 5:59:29 PM3/30/14
to yal...@googlegroups.com
I liked the Sudoku example you have on the wiki page as a SDP program application, so I tried to do the same for other type of problems and play a bit.

I found the following problem: https://www.brainbashers.com/show3inarow.asp

The 6x6 table must be filled with two colors such that on every line and on every column exactly three instances of the same color are used.

I modelled the problem like this: the first color is 0 and the second is 1. Therefore we have a binary matrix of colors. 

The constraints are just A*(vector of ones) = (vector of threes) and A' *(vector of ones) = (vector of threes) + the initial constraints.

This seems way simpler than the sudoku example, yet the solver doesn't find a feasible matrix. What am I doing wrong? (I attach the matlab file)
three_in_a_row.m

Bogosel Beniamin

unread,
Mar 30, 2014, 6:11:12 PM3/30/14
to yal...@googlegroups.com
Found the error: I needed to define A=binvar(n,n,'full');

Johan Löfberg

unread,
Mar 31, 2014, 2:17:11 AM3/31/14
to yal...@googlegroups.com
The Sudoku example has nothing to do with SDP. It is a linear program with integrality constraints

Johan Löfberg

unread,
Mar 31, 2014, 2:20:44 AM3/31/14
to yal...@googlegroups.com
BTW, no logic in running checkset before any solution has been computed. If you simply want to display the constraints, just write F and it is displayed

You loop can be written conveniently and efficiently as

F = [F, A(find(S))==S(find(S))-1];


Johan Löfberg

unread,
Mar 31, 2014, 2:22:55 AM3/31/14
to yal...@googlegroups.com
and you can use sums instead of doing things the explicit linear algebra way

F = [sum(A,1) == 3, sum(A,2) == 3];


Johan Löfberg

unread,
Mar 31, 2014, 2:25:56 AM3/31/14
to yal...@googlegroups.com
however, I don't see how you ensure that you don't have 3-in-a-row with your code. Sure, for the particular instance, it follows, but in the general case I don't think so

Bogosel Beniamin

unread,
Mar 31, 2014, 4:39:51 AM3/31/14
to yal...@googlegroups.com
I added the three in a row constraint by using vectors of the type v=(1 1 1 0 0 0)' (with other circular permutations) and writing A*v <=2 and A' *v<=2

Johan Löfberg

unread,
Mar 31, 2014, 4:55:10 AM3/31/14
to yal...@googlegroups.com
OK.

And as I said above, this is not an SDP but a MILP.
Reply all
Reply to author
Forward
0 new messages