Minimize quadratic function subject to linear equality constraint

335 Views Asked by At

I am trying to minimize an equation which looks something like

$$X_{1}*D_{1} + X_{1}^2 * R_{1} + \dots + X_{n}*D_{n} + X_{n}^2 * R_{n} $$

constraints

$$X_{1} + X_{2}+ \dots + X_{n} = M $$

$$\forall i \in n \space R_{i} > 0, D_{i}>0$$

R and D is constant.

so when I solved this I get a formula for $X_{i}$ but the problem is when I solved it I get the values of $x_{1}, x_{2} \dots , x_{n}$ in decimal form.

For example for n = 3 and M = 10, I get values in form of $X_{1} = 6.8, X_{2} = 2.8, x_{3} = 0.4$ so I round them up and get final solution in the form $X_{1} = 7, X_{2} = 3, x_{3} = 0$ but is this an acceptable solution. (means is it right thing to do), because there can a solution possible where n = 3 and M = 10 and I get values of $X_{1} = 6.5, X_{2} = 3.5, x_{3} = 0$ when I round it i will get answer $X_{1} = 7, X_{2} = 4, x_{3} = 0$ now $X_{1}+X_{2}+X_{3} = 11$ which contradicts the constraint(M=10).

How to handle this problem? (or this it is not possible to solve it by treating it as a minimization problem to get integer solution).

I want $X_{1}, X_{2}, \dots , X_{n}$ to be integer.

Idea 1:

I have noticed that the problem in my solution arrises only when there are mulitiple values of X with decimal value of .5 (ex 3.5, 7.5 etc) so I am thinking to iterate over all values of X and use ceil and floor function alternately when they have decimal value equal to .5 . I think this will solve the problem. (wrong)

2

There are 2 best solutions below

12
On BEST ANSWER

Let $f(x)=\sum_{i=1}^n (x_id_i+{x_i}^2 r_i)$. $f$ is strictly convex and the constraint is linear. If there are no conditions about the $(x_i)$, then there is a sole critical point where $\min(f)$ is reached. If you assume that the $(x_i)$ are $\geq 0$, then the calculation is more complicated ( $\min(f)$ may be reached on the edge).

Step 1. It's easy to calculate $X=(X_i)=argmin(f)$ (if you are lazy, then you can use the Maple software "QPSolve" because $f$ is quadratic).

Step 2. Choose $s>0$ and consider the box (centered in $X$) $U_s=\Pi_i [X_i-s,X_i+s]$ and you calculate $\min(f)$ over the finite set $\{x\in U_s|x_i\in\mathbb{Z}\}$; let the previous minimum be $f(\tilde{x})$ and let $f(\tilde{x})-f(X)=h_s>0$.

Step 3. Notice that, if $x\notin U_s$, then $f(x)-f(X)=\sum_i r_i(x_i-X_i)^2\geq \rho s^2$ where $\rho=\inf_i r_i$. Finally, if $\rho s^2>h_s$, then $\tilde{x}$ is the required solution.

If your first choice $s$ is not convenient, then choose a larger $s$; then $h_s$ decreases...

EDIT. A numerical example; implicitly, when I write $f(x)$, I assume that $\sum_i x_i=M$.

$f(x)=5.4x_1+0.4{x_1}^2+27.2x_2+0.3{x_2}^2+3.4x_3+0.2{x_3}^2$,

$M=102$. Thus $\rho=0.2$.

Then $X\approx(30.76923,4.6923077,66.53846),f(X)\approx 1790.792$

With $s=2$, $\tilde{x}=(31,5,66),f(\tilde{x})=1790.9,h_s\approx 0.1077$.

Finally $\rho s^2-h_s\approx 0.69>0$ and we are done.

1
On

Try Lagrange multipliers.

You will get $$D_i+2R_i\cdot X_i=\lambda \, \forall 1\le i\le n$$

Now you have $n+1$ equations with $n+1$ variables, so you can solve them to get the $X_i$s.