I'm very new to MILP, and I'm testing python-mip. I'm trying to model a simple power distribution system with some constraints, but I'm stuck....
I want to find a valid power balance between a device, a power loss and a power input, that maximisizes, if possible, power_provided_to_device, like:
max(power_provided_to_device)
power_available = power_provided_to_device + unused_power
with: 0. 0 < lb <= power_provided_to_device <= ub
- if power_available < lb: power_provided_to_device = 0, unused_power = power_available
- if lb <= power_available <= ub: power_provided_to_device = power_available, unused_power = 0
- if ub < power_available: power_provided_to_device = ub, unused_power = power_available - ub
I made it work for power_available >= lb. However, I just can't figure out how to fulfill the condition 1. . I tried some exemples with the bigM and binary variables, piecewise functions, but with no success...
Sorry for my poor formating and problem description. Thanks a lot for your kind help! Max.
The objective and linear constraints naturally satisfy conditions 2 and 3. For condition 1, you want to enforce $$\text{power_available} < \text{lb} \implies \text{power_provided_to_device} = 0$$ Introduce a binary variable $x$ and big-M constraints \begin{align} \text{lb} - \text{power_available} &\le M_1 x \tag1\\ \text{power_provided_to_device} &\le M_2 (1-x) \tag2\\ \end{align} Constraint $(1)$ enforces $$\text{power_available} < \text{lb} \implies x=1$$ Constraint $(2)$ enforces $$x=1 \implies \text{power_provided_to_device} = 0$$ You can take $M_1=\text{lb}$ and $M_2=\text{ub}$.