Special Ordered Sets of type 2 (SOS2) for piecewise linearisation #525
brynpickering
started this conversation in
Ideas
Replies: 2 comments 5 replies
-
Beta Was this translation helpful? Give feedback.
1 reply
-
Piecewise constraints would be great addition to Calliope! I have been trying to simulate the tutorial: https://calliope.readthedocs.io/en/latest/examples/piecewise_constraints/ However, I haven't managed to get it work I have tried it two ways: 1. directy via jupyter
It gives error:
2. Additional math through override and yaml file
Now all new math are succesfully added to the model.math, but new error appears during model.build():
Should this tutorial work as it is, or do I maybe have some misconfiguration? |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
With the new math formulation, it is possible to define simple piecewise linear constraints (e.g. for investment costs), possibly solving #107.
In these, a convex hull is created that approximates the non-linear curve and the structure of the model ensures that the variable will sit somewhere along the upper bound of that hull and therefore take on a value very similar to the nonlinear curve's values (see image, Fig 4.2 from my phd).
For example, efficiency might change with technology output. As the output increases on the Y axis, the curve lead to increasingly more input requirements, therefore simulating a reduced efficiency with greater input. This works because the model wants to maximise output for each unit input (otherwise it has to "spend" more on the input carrier, increasing the objective function value) and so will have to sit on the upper bounding curve.
The advantage of this approach is that the model can avoid lots of integer/binary variables. The disadvantage is that it can only be used to describe problems where things get worse with increased output/capacity of a technology. In reality, economies of scale lead to lower investment costs for increased capacity, and part-load efficiencies are often lower than full load efficiency.
To describe these problems, I believe we need to use Special Ordered Sets. in SOS of type 2 - SOS2 - each "joint" on the piecewise curve is described by a binary variable and only two adjacent variables may be non-zero at any time. This means only one section of a piecewise curve is "active" at a given moment and so input and output must be related according to the slope of the line between those two points. SOS2 come with the advantage of being able to describe most non-linear curve shapes in the form of a discrete set of straight lines. But they need many more binary variables so might make most problems intractable. Nevertheless, this should be an option for Calliope modellers.
Solvers have python APIs to define an SOS that we could tap into (Pyomo, Gurobi). They also have more generalised (and easier to use) piecewise linear constraint interfaces (Pyomo, Gurobi) but we still need to provide a way for users to construct them.
If we use the generalised piecewise linear constraint constructor, I would force it to use SOS2 with the "==" operator between x and y. This is partly because it is all that Gurobi can handle (Pyomo has many more options), but also because it is the most likely formulation of a piecewise constraint that someone will think of.
We can't use the standard math syntax we have. Instead we need something that allows reference to the x and y variables being compared and the values of x and y at each "breakpoint". Some ideas:
1
2
3
4
5
Option 1 and 2 are probably better as breakpoints will likely be defined per technology / node and that could be defined by an input parameter in those options. E.g.,:
1:
and...
However, there would need to be an additional model dimension for breakpoints that this parameter is indexed over. All the options would work if you have to define one piecewise constraint for each index item in foreach. Maybe that's OK because it's unlikely that lots of different piecewise constraints are going to be needed (one per tech for 5-15 techs?) but it is a break from the current math format.
Or, there could be one parameter per breakpoint, so the options would become, e.g.:
1:
4:
Beta Was this translation helpful? Give feedback.
All reactions