I have an optimization (maximization) problem in which I need to optimize a variable (2-D matrix) under some constraints. Let say I have following entries in a $5$x$4$ matrix.

\begin{array}{|c|c|c|c|} \hline 0.42& 0.42 & 0.42 & 0 \\ \hline 0.38 & 0 & 0 & 0\\ \hline 0 & 0 & 0.69 & 0.69\\ \hline 0.78 & 0.78 & 0 & 0\\ \hline 0 & 0 & 0 & 0.41\\ \hline \end{array}

I want to optimize entries under the following $3$ conditions:

1) Sum of each column in updated matrix is $\leq$ $1$, preferably $1$

2) Sum of each row is less than or equal to a specific number. For example, $\sum1^{st}$ row $\leq$1.2, $\sum2^{nd}$ row $\leq$0.3, $\sum3^{rd}$ row $\leq$1.3, $\sum4^{th}$ row $\leq$1.2, $\sum5^{th}$ row (say)$\leq$0.3

3) All non-zero elements in a row must be same. For example, in the above case if $1^{st}$ element in $1^{st}$ row in the updated matrix is $0.35$ then $2^{nd}, and \ 3^{rd}$ elements must also be $0.35$.

how can I program that.



1 Answer 1


Let $x_{ij}$ be the $(i,j)$ entries in the updated table.

we want the sum of each column in the updated matrix to be less than or equal to $1$.

$$\sum_{i=1}^{5} x_{ij} \leq 1, j=1,\ldots 4$$

We want the sum of each row to be less than equal to certain number, say the number is $b_i$, then we have

$$\sum_{j=1}^4x_{ij}\leq b_i, i=1,\ldots 5$$

All non-zero elements along a row has to be the same.

$$x_{11}=x_{12}=x_{13}$$ $$x_{33}=x_{34}$$ $$x_{41}=x_{42}$$

If the objective function is linear, then this is a linear programming problem.

  • $\begingroup$ Dear Goh,Thanks for your reply. However, it is easy for me to write $$x_{33}=x_{34}$$ as $$x_{33}-x_{34}=0$$ But, I am surprised how to write $$x_{11}=x_{12}=x_{13}$$ in an equation form with variables on left hand side and 0 on right side. $\endgroup$ Dec 20, 2016 at 3:22
  • $\begingroup$ Write them as $x_{11}-x_{12}=0$ and $x_{11}-x_{13}=0$. $\endgroup$ Dec 20, 2016 at 4:13
  • $\begingroup$ IC! but unfortunately my matrix could be very large. A pairwise comparison may result in a large number of equations, leading to a high computational cost. Anyway thanks for your time and support. $\endgroup$ Dec 20, 2016 at 4:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .