Q: penalizing variables deviating from a given ratio I want my optimization variables   $\phi_1, \cdots , \phi _n >0$ (positive real) to remain around a known ratio, say $\alpha_1 :\alpha_2 :\cdots :\alpha_n$, where $\alpha_i\in (0, 1)$. To be clear, I want
$\phi _1:\phi _2:\cdots :\phi _n \approx \alpha_1 :\alpha_2 :\cdots :\alpha_n$,
where $\phi_i$ are linear in other optimization (binary) variable $x_k\in\{0,1\} $,  expressed as $\phi_i =\sum_k c_{ik}x_k, (c_{ik}>0) $
Plus, I want to penalize from both ways (no overshoot and no undershoot).
Do you have any suggestions for cost function that would penalize variables deviating from that ratio? If you can write in linear form, that would be great!!
 A: Basically you want to minimize the $\vert \phi_i -\alpha_i\vert $.
Introduce variables $z_i$ defined by
$\phi_i -\alpha_i \le z_i$
$\alpha_i -\phi_i \le z_i$
where $z\in R_+^i$
Min $\sum_i z_i $
Or
Min $\sum_i \log z_i $ if you consider minimizing $\prod_i z_i$
A: You want to minimize $$\sum_i \left|\frac{\phi_i}{\sum_j \phi_j} - \frac{\alpha_i}{\sum_j \alpha_j}\right|.$$
Introduce decision variable $z_i$ to represent the summand, together with constraints
\begin{align}
\frac{\phi_i}{\sum_j \phi_j} - \frac{\alpha_i}{\sum_j \alpha_j} &\le z_i \tag1\label1\\
-\frac{\phi_i}{\sum_j \phi_j} + \frac{\alpha_i}{\sum_j \alpha_j} &\le z_i \tag2\label2\\
\end{align}
Now \eqref{1} and \eqref{2} are still nonlinear, but multiply both sides by the denominator $\sum_j \phi_j$ to obtain
\begin{align}
\phi_i - \frac{\alpha_i \sum_j \phi_j}{\sum_j \alpha_j} &\le z_i \sum_j \phi_j \tag3\label3\\
-\phi_i + \frac{\alpha_i \sum_j \phi_j}{\sum_j \alpha_j} &\le z_i \sum_j \phi_j \tag4\label4\\
\end{align}
Now substitute $\phi_i = \sum_k c_{ik} x_k$, yielding
\begin{align}
\sum_k c_{ik} x_k - \frac{\alpha_i \sum_j \sum_k c_{jk} x_k}{\sum_j \alpha_j} &\le \sum_j \sum_k c_{jk} z_i x_k \tag5\label5\\
-\sum_k c_{ik} x_k + \frac{\alpha_i \sum_j \sum_k c_{jk} x_k}{\sum_j \alpha_j} &\le \sum_j \sum_k c_{jk} z_i x_k \tag6\label6\\
\end{align}
Now introduce decision variable $y_{ik}$ to represent $z_i x_k$, together with big-M constraints
\begin{align}
0 \le y_{ik} &\le M_{ik} x_k \tag7\label7\\
0 \le y_{ik} - z_i &\le M_{ik} (1 - x_k) \tag8\label8\\
\end{align}
Constraint \eqref{7} enforces $x_k = 0 \implies y_{ik} = 0$, and constraint \eqref{8} enforces $x_k = 1 \implies y_{ik} = z_i$.
