How to solve simultaneous linear equations with constraints?

272 Views Asked by At

Given:

$$Ax=b$$

$$A = \begin{pmatrix} 1&1&1&1&1&1&1&1&1&1&1&1\\ 1&1&0&1&1&1&0&0&0&0&0&0\\ 0&0&1&1&0&1&1&1&0&0&0&0\\ 0&0&0&0&1&1&0&1&1&1&0&0\\ 0&0&0&0&0&0&1&1&0&1&1&1\\ 1&1&0&0&0&0&0&0&1&1&0&1\\ 0&1&1&1&0&0&0&0&0&0&1&1 \end{pmatrix}$$ $$ b = \begin{pmatrix} 78\\ 33\\ 33\\ 33\\ 33\\ 33\\ 33 \end{pmatrix} $$

$$ \{x_0, x_2, x_4, x_6, x_8, x_{10}\} ∩ \{6, 12\} = ∅, \\ ∀_i\ x_i ∈ ℕ \\ ∀_i\ x_i ∈ [1, 12] \\ ∀_{i ≠ j}\ x_i ≠ x_j $$

How can $x$ be solved for? For now, I've set up a matrix equation and am brute forcing permutations of:

$$ x_0 ∈ [1, 5]∪[7, 11] \\ x_2 ∈ [1, 5]∪[7, 11] \\ x_4 ∈ [1, 5]∪[7, 11] \\ 6 ∈ [x_1, x_3, x_5, x_7, x_9, x_{11}] \\ 12 ∈ [x_1, x_3, x_5, x_7, x_9, x_{11}] $$

Is there a "more mathematical" way to find a solution?

1

There are 1 best solutions below

0
On

Here's how you can solve it with the constraint programming solver in SAS:

proc optmodel;
   num n = 12, m = 7;
   num a {0..m-1, 0..n-1} = [
      1 1 1 1 1 1 1 1 1 1 1 1
      1 1 0 1 1 1 0 0 0 0 0 0
      0 0 1 1 0 1 1 1 0 0 0 0
      0 0 0 0 1 1 0 1 1 1 0 0
      0 0 0 0 0 0 1 1 0 1 1 1
      1 1 0 0 0 0 0 0 1 1 0 1
      0 1 1 1 0 0 0 0 0 0 1 1
   ];
   num b {0..m-1} = [78 33 33 33 33 33 33];

   var X {0..n-1} >= 1 <= 12 integer;

   con Linear {i in 0..m-1}:
      sum {j in 0..n-1} a[i,j] * X[j] = b[i];

   con NotEqual {j in 0..10 by 2, k in {6,12}}:
      X[j] ne k;

   con Alldiff:
      alldiff(X);

   solve with clp / findallsolns;
   print {s in 1.._NSOL_, j in 0..n-1} X[j].sol[s];
quit;

There are exactly 12 feasible solutions, one of which is: $$(x_0, x_1, x_2, x_3, x_4, x_5, x_6, x_7, x_8, x_9, x_{10}, x_{11}) = (1, 9, 2, 12, 8, 3, 11, 5, 10, 7, 4, 6)$$