3

I am studying a mixed integer program in the form $$ \textrm{min}: \sum A x$$ constrained by $\sum x_i = N$

where $x$ is a vector containing only 1's and 0's, N is an integer, and $A$ is a square matrix of real numbers.

What may be the best way/algorithm/solver to solve this class of problem?

Another question I have is how to best convert this into the form required for the MATLAB MILP solver $ \textrm{min}: f^T x$, where $f$ is a vector,as I instead have a sum over a square matrix $A$.

Many thanks for anybody's help!

RobPratt
  • 52,643
  • 1
    What have you tried so far? Have you considered letting $f^{T}$ be the sum of the rows of $A$? – Brian Borchers Aug 26 '22 at 23:11
  • @BrianBorchers I haven't considered this but as far as I can figure out summing the rows of $A$ doesn't give me the same problem (e.g consider a 3x3 matrix $A$ and $x=(1,0,1)$). – testman7 Aug 26 '22 at 23:19
  • How is the sum calculated in objective function? –  Aug 26 '22 at 23:26
  • @Bey The objective function first evaluates $Ax$ which returns a vector and then each element of the vector is added together to give a value to minimise. Since $x$ is either 1 or 0, effectively the objective function is the sum of all of the $i$th columns in $A$ for which $x_i=1$ – testman7 Aug 26 '22 at 23:29
  • That is just a compact way to write a linear combination of the values of X — its already linear —not sure what the issue is — are you looking for something else? –  Aug 26 '22 at 23:31
  • @Bey Thank you for your response. Is there a class of algorithms that this problem lends itself to best for fast solutions? Especially for very large $x$ and where $0<<N<<size(x)$ – testman7 Aug 26 '22 at 23:33
  • See my answer below –  Aug 26 '22 at 23:55

1 Answers1

4

This is similar to a knapsack problem — but made simpler by the fact that each item has the same weight.

You can actually use a greedy algorithm here:

  1. Expand $\sum Ax$ onto a linear objective $\sum_{i=1}^{|x|} a_ix_i$ where $a_i=\sum_{j=1}^{|x|} A_{ji}$

  2. Sort $a_i$ in increasing order

  3. Starting from the smallest $a_i$ set the associated $x_i$ to $1$ until you have set $N$ variables to $1$ (rest are 0).

This will be the optimal solution.

  • Actually, not a knapsack problem if there are possibly negative coefficients. – Brian Borchers Aug 27 '22 at 00:01
  • Thank you for your answer. Indeed, I have negative coefficients in $A$. The coefficients are positive along the diagonal and negative or zero everywhere else. – testman7 Aug 27 '22 at 00:06
  • @testman7 true — but above will still give optimal result — negative value items in knapsack can just be ignored b/c you’ll never select them –  Aug 27 '22 at 01:44
  • The signs don’t matter here, and you are right that greedy is optimal. But you want increasing order because the objective is minimization. – RobPratt Aug 27 '22 at 03:42
  • @RobPratt correct I was thinking max — should have checked again!! –  Aug 27 '22 at 04:08
  • min max doesn't matter, just negate A – DanielV Aug 27 '22 at 04:14
  • @DanielV correct but my answer previously assumed we were maximizing –  Aug 27 '22 at 04:54
  • FWIW, you probably want a "selection algorithm" like quickselect, rather than sorting. – DanielV Aug 27 '22 at 05:44
  • @DanielV that works make it quicker :-) –  Aug 27 '22 at 07:21