4
$\begingroup$

I recently started with Pyomo and I have the following Problem:

I want to construct a ConstraintList with an if statement. I already learned, that it's not possible. But the problem still exists... My first code (with the if statement) was the following one:

m.Constraint10=pyo.ConstraintList()
for i in m.Stunde:
  for j in m.Kraftwerk:
     if pyo.value(m.Kraftwerkseinsatz[i,j]) != 0:
        m.Constraint10.add(m.Kraftwerkseinsatz[i,j]>=m.MinOutput[j])

m.Stunde and m. Kraftwerk are indices.

m.Kraftwerkseinsatz is a variable!

m.MinOutput is a parameter.

In other words, my variable must be greater than the MinOutput parameter or zero (for every hour and every power plant).

I already thought of reframing the constraint like this: m.Kraftwerkseinsatz[i,j] must not be between 0.1 and m.MinOutput.

But I don't know how to code this either. Can anyone help me?

$\endgroup$
6
$\begingroup$

A variable that can assume values of zero or between some lower and upper bound is called a semi-continuous variable. Most high-end solvers have direct support for this type of variable. If not supported, you can model this with an additional binary variable: $$\begin{align} & \color{darkblue}L\cdot \color{darkred}\delta \le \color{darkred}x \le \color{darkblue}U \cdot \color{darkred}\delta \\ & \color{darkred}\delta \in \{0,1\} \\ &\color{darkred}x\in [0,\color{darkblue}U]\end{align}$$

AFAIK, Pyomo has no direct support for semi-continuous variables. So the obvious approach is to use binary variables. An alternative would be to use Pyomo's Disjunctive Programming tools (GDP).

Note: in the bounds for $\color{darkred}x$, I assumed $\color{darkblue}L\gt 0$. We can make this more general by stating $\color{darkred}x \in [\min(0,\color{darkblue}L),\max(0,\color{darkblue}U)]. $

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.