I am working on electricity generation. I have $n$ motors and must produce a given amount of power:
Let the rotational speed of the $i$-th motor be denoted by $\omega_i$. For each motor, there is a lower bound and an upper bound on its rotational speed, i.e., $$\omega_i^\min \leq \omega_i \leq \omega_i^\max$$
Each motor is either active or not. If a motor is active, the given lower and upper bounds must be satisfied. If it is not active, the lower and upper bounds are $0$.
If the $i$-th motor is active, the cost of operating it is $f_i (\omega_i)$, where $\omega_i^\min \leq \omega_i \leq \omega_i^\max$. The function $f_i$ is either linear or quadratic. Let the binary variable $x_i \in \{ 0, 1 \}$ denote whether the $i$-th motor is active ($x_i = 1$) or not. Thus, the total cost to be minimized is
$$ \sum_{i=1}^n x_i f_i (\omega_i)$$
subject to the constraint that enough power be generated
$$ \sum_{i=1} x_i \omega_i \geq \text{required power target} $$
I hope this is understandable. So I need a way/algorithm/paper to solve this and implement this into my code. What constraint should I make?
Assuming $f(0)=0$, you can reformulate as MILP or MIQP, depending on whether $f_i$ is linear or quadratic, respectively. Let nonnegative decision variable $y_i$ represent the product $x_i \omega_i$. The problem is to minimize $\sum_i f_i(y_i)$ subject to linear constraints \begin{align} \sum_i y_i &\ge \text{target} \\ \omega_i^\min x_i \leq y_i &\leq \omega_i^\max x_i &&\text{for all $i$} \end{align}
If $f(0)\not=0$, you can reformulate as MILP or MIQCQP, depending on whether $f_i$ is linear or quadratic, respectively. Let nonnegative decision variable $y_i$ represent the product $x_i \omega_i$, and let nonnegative decision variable $z_i$ represent the product $x_i f_i(\omega_i)$. The problem is to minimize $\sum_i z_i$ subject to linear constraints \begin{align} \sum_i y_i &\ge \text{target} \tag1\label1\\ \omega_i^\min \leq \omega_i &\leq \omega_i^\max &&\text{for all $i$} \tag2\label2\\ \omega_i^\min x_i \leq y_i &\leq \omega_i^\max x_i &&\text{for all $i$} \tag3\label3\\ \omega_i^\min (1-x_i) \leq \omega_i - y_i &\leq \omega_i^\max (1-x_i) &&\text{for all $i$} \tag4\label4\\ f_i(\omega_i) - z_i &\leq M_i(1 - x_i) &&\text{for all $i$} \tag5\label5 \end{align} Constraint \eqref{3} enforces $x_i = 0 \implies y_i = 0$. Constraint \eqref{4} enforces $x_i = 1 \implies y_i = \omega_i$. Constraint \eqref{5} enforces $x_i = 1 \implies z_i \ge f_i(\omega_i)$.