Search code examples
mathconstraint-programminginteger-programming

Can this be expressed using Integer Programming or Constraint Programming?


Consider a fixed m by n matrix M, all of whose entries are 0 or 1. The question is whether there exists a non zero vector v, all of whose entries are -1, 0 or 1 for which Mv = 0. For example,

      [0 1 1 1]
M_1 = [1 0 1 1]
      [1 1 0 1]

In this example, there is no such vector v.

      [1 0 0 0]
M_2 = [0 1 0 0]
      [0 0 1 0]

In this example, the vector (0,0,0,1) gives M_2v = 0.

I am currently solving this problem by trying all different vectors v.

However, is it possible to express the problem as an integer programming problem or constraint programming problem so I can use an existing software package, such as SCIP instead which might be more efficient.


Solution

  • It would help a little if you also give a positive example, not just a negative.

    I might have missed something in the requirement/definitions, but here is a way of doing it in the Constraint Programming (CP) system MiniZinc (http://minizinc.org/). It don't use any specific constraints unique to CP systems - except perhaps for the function syntax, so it should be possible to translate it to other CP or IP systems.

    % dimensions
    int: rows = 3;
    int: cols = 4;
    % the matrix
    array[1..rows, 1..cols] of int: M = array2d(1..rows,1..cols, 
        [0, 1, 1, 1,
         1, 0, 1, 1,
         1, 1, 0, 1,
         ] );
    
     % function for matrix multiplication: res = matrix x vec 
     function array[int] of var int: matrix_mult(array[int,int] of var int: m, 
                                                 array[int] of var int: v) =
        let {
           array[index_set_2of2(m)] of var int: res; % result
           constraint
           forall(i in index_set_1of2(m)) (
               res[i] = sum(j in index_set_2of2(m)) (
                   m[i,j]*v[j]
               )
           )
         ;
        } in res; % return value
    
       solve satisfy;
       constraint
           % M x v = 0
           matrix_mult(M, v) = [0 | j in 1..cols] /\
           sum(i in 1..cols) (abs(v[i])) != 0 % non-zero vector
       ;
       output 
       [
           "v: ", show(v), "\n",
           "M: ", 
       ]
       ++
       [
         if j = 1 then "\n" else " " endif ++
           show(M[i,j])
         | i in 1..rows, j in 1..cols
       ];
    

    By changing the definition of "M" to use decision variables with the domain 0..1 instead of constants:

      array[1..rows, 1..cols] of var 0..1: M;
    

    then this model yield 18066 different solutions, for example these two:

      v: [-1, 1, 1, 1]
      M: 
       1 0 0 1
       1 1 0 0
       1 0 0 1
      ----------
      v: [-1, 1, 1, 1]
      M: 
      0 0 0 0
      1 0 1 0
      1 0 0 1
    

    Note: Generating all solutions is probably more common in CP systems than in traditional MIP systems (this is a feature that I really appreciate).