math - 这可以用整数规划或约束规划来表达吗?

标签 math constraint-programming integer-programming

考虑一个固定的 m × n 矩阵 M,其所有条目均为 0 或 1。问题是是否存在一个非零向量 v,其所有条目均为 -1、0 或 1,且 Mv = 0。例如,

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

在这个例子中,不存在这样的向量v。

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

在此示例中,向量 (0,0,0,1) 给出 M_2v = 0。

我目前正在通过尝试所有不同的向量 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.

最佳答案

如果您还提供一个正面的例子,而不仅仅是负面的例子,将会有所帮助。

我可能遗漏了需求/定义中的某些内容,但这里有一种在约束编程 (CP) 系统 MiniZinc ( http://minizinc.org/ ) 中执行此操作的方法。它不使用 CP 系统特有的任何特定约束 - 也许除了函数语法之外,因此应该可以将其转换为其他 CP 或 IP 系统。

% 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
   ];

通过更改“M”的定义以使用域为 0..1 的决策变量而不是常量:

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

然后这个模型产生 18066 个不同的解决方案,例如这两个:

  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

注意:生成所有解决方案在 CP 系统中可能比在传统 MIP 系统中更常见(这是我非常欣赏的功能)。

关于math - 这可以用整数规划或约束规划来表达吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31318717/

相关文章:

python - 在 python-constraint 中添加约束时出现 KeyError

knapsack-problem - 用于求解 knapsack-prblm(整数规划)的库

algorithm - 直线多边形相交

java - 为什么这个数学函数在 Java 和 JavaScript 中返回不同的值?

c - Project Euler Number 160 - C 语言尝试

genetic-algorithm - 遗传算法和约束规划的区别?

c# - 重叠的矩形

algorithm - 在解决约束问题时需要帮助(第 2 次)

javascript - 以最低成本为一组给定功能选择产品的算法?

math - 从昂贵的搜索到整数规划或约束规划?