Write back solve results to model for outer loop

hi all,

i have a simple oemof model and i want to use it in an outer loop.
since v3.0 there is a native way to solve a single time step, but how can i feedback the solve results to my model and start the next time step?
i found this file git hub and line 84 should
# write back results from optimization object to energysystem optimization_model.results()
but this only returns a dict or did i misunderstood something?

thx, niels…

Do you want to access parameters on the optimization model and change them?

1 Like

yes - after the model is solved in the first time step, i want to use the new SOC (found by the solver) of the storage for the next time step. furthermore, i have to change the demand of some sinks. these values are given by an outer loop.
the next time step is to be optimized with these new parameters.

You then need to set the parameters and upper bounds directly on the optimization model (which is a pyomo model).

An example can be found here: https://github.com/oemof/oemof-examples/blob/master/oemof_examples/oemof.solph/v0.3.x/flexible_modelling/add_constraints.py

Unfortunately, the access differs depending on the actual object you are changing. But generally it should work like this whereas om is your optimization model:

# Flow: Set upper bound
om.flow[(source, target), timestep].setub(my_value)

# Flow: Set value
om.flow[(source, target), timestep].value = my_value

# GenericStorage: Set upper bound (capacity)
om.GenericStorageBlock[(my_storage,), timestep].setub(my_value)

# GenericStorage: Set initial/end state of charge
om.GenericStorageBlock[(my_storage,),om.TIMESTEPS[-1]] = my_value * 0.5

# Other components: Set upper bound
om.MyComponent[my_component_instance, timestep].setub = my_value
# Other components: Set value
om.MyComponent[my_component_instance, timestep].value = my_value

Depending on the component you want to change, you might also have a look into the modules here which hold the different model blocks (blocks, components, custom): https://github.com/oemof/oemof/tree/dev/oemof/solph

General information on how to work with pyomo models can be found here: https://pyomo.readthedocs.io/en/latest/working_models.html

Good luck!


1 Like

unfortunately this is not the 1-line-solution i expected, but it leads me in the right direction!

Text and images licensed under CC BY 4.0Data licensed under CC0 1.0Code licensed under MITSite terms of serviceOpenmod mailing list.