Commit 3b410044 authored by Jorn Baayen's avatar Jorn Baayen

Added examples.

parent d405bc6b
build
\ No newline at end of file
......@@ -364,8 +364,8 @@ texinfo_documents = [
# -- Hack to strip annotations from Modelica files ------------------------
MODELICA_EXAMPLE_BASE_FOLDER = '../../case-studies'
MODELICA_EXAMPLES = ['example_basic', 'example_ensemble', 'example_goal', 'example_lookuptable_storage', 'example_mixed_integer']
MODELICA_EXAMPLE_BASE_FOLDER = '../examples'
MODELICA_EXAMPLES = ['basic', 'ensembles', 'goal_programming', 'mixed_integer', 'lookup_tables']
MODELICA_STRIPPED_EXAMPLE_FOLDER = '_build/mo'
......
......@@ -17,7 +17,7 @@ does not want to end up with too much water at the end of the six days. They
have chosen to use RTC-Tools to calculate how much water to release and when
to release it.
The folder ``<installation directory>\RTCTools2\examples\example_basic``
The folder ``<installation directory>\RTCTools2\examples\basic``
contains a complete RTC-Tools optimization problem. An RTC-Tools
directory has the following structure:
......@@ -46,7 +46,7 @@ program. Make sure to load the Deltares libray before loading the example:
* Using the menu bar: *File -> Open Model/Library File(s)*
* Select ``<installation
directory>\RTCTools2\examples\example_basic\model\Example.mo``
directory>\RTCTools2\examples\basic\model\Example.mo``
Once loaded, we have an OpenModelica Connection Editor window that looks like
this:
......@@ -74,7 +74,7 @@ and drag between the ports on the elements.
In text mode, the Modelica model looks as follows (with
annotation statements removed):
.. literalinclude:: _build/mo/example_basic.mo
.. literalinclude:: _build/mo/basic.mo
:language: modelica
:lineno-match:
......@@ -125,7 +125,7 @@ package ``run_optimization_problem`` form the ``rtctools.util`` package, and
any extra packages we want to use. For this example, the import block looks
like:
.. literalinclude:: ../../case-studies/example_basic/src/example.py
.. literalinclude:: ../examples/basic/src/example.py
:language: python
:lines: 1-5
:lineno-match:
......@@ -139,7 +139,7 @@ parent classes each perform different tasks realted to importing and exporting
data and solving the optimization problem. Each imported class makes a set of
methods available to the our optimization class.
.. literalinclude:: ../../case-studies/example_basic/src/example.py
.. literalinclude:: ../examples/basic/src/example.py
:language: python
:pyobject: Example
:lineno-match:
......@@ -148,7 +148,7 @@ methods available to the our optimization class.
The next, we define an objective function. This is a class method that returns
the value that needs to be minimized.
.. literalinclude:: ../../case-studies/example_basic/src/example.py
.. literalinclude:: ../examples/basic/src/example.py
:language: python
:pyobject: Example.objective
:lineno-match:
......@@ -160,7 +160,7 @@ at an individual timestep, we could define it inside the ``constraints`` method.
Other parent classes also declare this method, so we call the ``super()`` method
so that we don't overwrite their behaviour.
.. literalinclude:: ../../case-studies/example_basic/src/example.py
.. literalinclude:: ../examples/basic/src/example.py
:language: python
:pyobject: Example.path_constraints
:lineno-match:
......@@ -172,7 +172,7 @@ To make our script run, at the bottom of our file we just have to call
the ``run_optimization_problem()`` method we imported on the optimization
problem class we just created.
.. literalinclude:: ../../case-studies/example_basic/src/example.py
.. literalinclude:: ../examples/basic/src/example.py
:language: python
:lineno-match:
:start-after: # Run
......@@ -182,7 +182,7 @@ The Whole Script
All together, the whole example script is as follows:
.. literalinclude:: ../../case-studies/example_basic/src/example.py
.. literalinclude:: ../examples/basic/src/example.py
:language: python
:lineno-match:
......
......@@ -9,7 +9,7 @@ Using Forecast Ensembles
:doc:`example_basic`.
Then biggest change to RTC-Tools when using ensembles is the structure of the
directory. The folder ``<installation directory>\RTCTools2\examples\example_ensemble``
directory. The folder ``<installation directory>\RTCTools2\examples\ensembles``
contains a complete RTC-Tools ensemble optimization problem. An RTC-Tools
ensemble directory has the following structure:
......@@ -63,7 +63,7 @@ In OpenModelica Connection Editor, the model looks like this:
In text mode, the Modelica model is as follows (with annotation statements
removed):
.. literalinclude:: _build/mo/example_ensemble.mo
.. literalinclude:: _build/mo/ensembles.mo
:language: modelica
:lineno-match:
......@@ -92,7 +92,7 @@ Declaring Goals
First, we have a high priority goal to keep the water volume within a minimum
and maximum.
.. literalinclude:: ../../case-studies/example_ensemble/src/example.py
.. literalinclude:: ../examples/ensembles/src/example.py
:language: python
:pyobject: WaterVolumeRangeGoal
:lineno-match:
......@@ -100,7 +100,7 @@ and maximum.
We also want to save energy, so we define a goal to minimize ``Q_release``. This
goal has a lower priority.
.. literalinclude:: ../../case-studies/example_ensemble/src/example.py
.. literalinclude:: ../examples/ensembles/src/example.py
:language: python
:pyobject: MinimizeQreleaseGoal
:lineno-match:
......@@ -110,7 +110,7 @@ Importing Packages
For this example, the import block is as follows:
.. literalinclude:: ../../case-studies/example_ensemble/src/example.py
.. literalinclude:: ../examples/ensembles/src/example.py
:language: python
:lines: 1-11
:lineno-match:
......@@ -121,7 +121,7 @@ Optimization Problem
Next, we construct the class by declaring it and inheriting the desired parent
classes.
.. literalinclude:: ../../case-studies/example_ensemble/src/example.py
.. literalinclude:: ../examples/ensembles/src/example.py
:language: python
:pyobject: Example
:lineno-match:
......@@ -129,7 +129,7 @@ classes.
We turn on ensemble mode by setting ``csv_ensemble_mode = True``:
.. literalinclude:: ../../case-studies/example_ensemble/src/example.py
.. literalinclude:: ../examples/ensembles/src/example.py
:language: python
:lines: 50-51
:lineno-match:
......@@ -145,14 +145,14 @@ Because the timeseries we set will be the same for both ensemble members, we
also make sure that the timeseries we set are set for both ensemble members
using for loops.
.. literalinclude:: ../../case-studies/example_ensemble/src/example.py
.. literalinclude:: ../examples/ensembles/src/example.py
:language: python
:pyobject: Example.pre
:lineno-match:
Now we pass in the goals:
.. literalinclude:: ../../case-studies/example_ensemble/src/example.py
.. literalinclude:: ../examples/ensembles/src/example.py
:language: python
:pyobject: Example.path_goals
:lineno-match:
......@@ -160,14 +160,14 @@ Now we pass in the goals:
We define the ``priority_completed()`` method. We ensure that it stores the
results from both ensemble members.
.. literalinclude:: ../../case-studies/example_ensemble/src/example.py
.. literalinclude:: ../examples/ensembles/src/example.py
:language: python
:pyobject: Example.priority_completed
:lineno-match:
We output our intermediate results using the ``post()`` method:
.. literalinclude:: ../../case-studies/example_ensemble/src/example.py
.. literalinclude:: ../examples/ensembles/src/example.py
:language: python
:pyobject: Example.post
:lineno-match:
......@@ -175,7 +175,7 @@ We output our intermediate results using the ``post()`` method:
Finally, we want to apply some additional configuration, reducing the amount of
information the solver outputs:
.. literalinclude:: ../../case-studies/example_ensemble/src/example.py
.. literalinclude:: ../examples/ensembles/src/example.py
:language: python
:pyobject: Example.solver_options
:lineno-match:
......@@ -187,7 +187,7 @@ To make our script run, at the bottom of our file we just have to call
the ``run_optimization_problem()`` method we imported on the optimization
problem class we just created.
.. literalinclude:: ../../case-studies/example_ensemble/src/example.py
.. literalinclude:: ../examples/ensembles/src/example.py
:language: python
:lineno-match:
:start-after: # Run
......@@ -197,7 +197,7 @@ The Whole Script
All together, the whole example script is as follows:
.. literalinclude:: ../../case-studies/example_ensemble/src/example.py
.. literalinclude:: ../examples/ensembles/src/example.py
:language: python
:lineno-match:
......
......@@ -52,7 +52,7 @@ In OpenModelica Connection Editor, the model looks like this:
In text mode, the Modelica model looks as follows (with annotation statements
removed):
.. literalinclude:: _build/mo/example_goal.mo
.. literalinclude:: _build/mo/goal_programming.mo
:language: modelica
:lineno-match:
......@@ -80,7 +80,7 @@ Importing Packages
For this example, the import block is as follows:
.. literalinclude:: ../../case-studies/example_goal/src/example.py
.. literalinclude:: ../examples/goal_programming/src/example.py
:language: python
:lines: 1-8
:lineno-match:
......@@ -94,7 +94,7 @@ components of goals can be found in :doc:`multi_objective`.
First, we have a high priority goal to keep the water level within a minimum and
maximum:
.. literalinclude:: ../../case-studies/example_goal/src/example.py
.. literalinclude:: ../examples/goal_programming/src/example.py
:language: python
:pyobject: WaterLevelRangeGoal
:lineno-match:
......@@ -102,7 +102,7 @@ maximum:
We also want to save energy, so we define a goal to minimize ``Q_pump``. This
goal has a lower priority.
.. literalinclude:: ../../case-studies/example_goal/src/example.py
.. literalinclude:: ../examples/goal_programming/src/example.py
:language: python
:pyobject: MinimizeQpumpGoal
:lineno-match:
......@@ -113,7 +113,7 @@ Optimization Problem
Next, we construct the class by declaring it and inheriting the desired parent
classes.
.. literalinclude:: ../../case-studies/example_goal/src/example.py
.. literalinclude:: ../examples/goal_programming/src/example.py
:language: python
:pyobject: Example
:lineno-match:
......@@ -126,7 +126,7 @@ at an individual timestep, define it inside the ``constraints()`` method.
Other parent classes also declare this method, so we call the ``super()`` method
so that we don't overwrite their behaviour.
.. literalinclude:: ../../case-studies/example_goal/src/example.py
.. literalinclude:: ../examples/goal_programming/src/example.py
:language: python
:pyobject: Example.path_constraints
:lineno-match:
......@@ -135,7 +135,7 @@ Now we pass in the goals. We want to apply our goals to every timestep, so we
use the ``path_goals()`` method. This is a method that returns a list of the goals
we defined above.
.. literalinclude:: ../../case-studies/example_goal/src/example.py
.. literalinclude:: ../examples/goal_programming/src/example.py
:language: python
:pyobject: Example.path_goals
:lineno-match:
......@@ -151,7 +151,7 @@ we declare a new ``pre()`` method, call ``super(Example, self).pre()`` to ensure
that the original method runs unmodified, and add in a variable declaration to
store our list of intermediate results:
.. literalinclude:: ../../case-studies/example_goal/src/example.py
.. literalinclude:: ../examples/goal_programming/src/example.py
:language: python
:pyobject: Example.pre
:lineno-match:
......@@ -160,7 +160,7 @@ Next, we define the ``priority_completed()`` method to inspect and summerize the
results. These are appended to our intermediate results variable after each
priority is completed.
.. literalinclude:: ../../case-studies/example_goal/src/example.py
.. literalinclude:: ../examples/goal_programming/src/example.py
:language: python
:pyobject: Example.priority_completed
:lineno-match:
......@@ -169,7 +169,7 @@ We want some way to output our intermediate results. This is accomplished using
the ``post()`` method. Again, we nedd to call the ``super()`` method to avoid
overwiting the internal method.
.. literalinclude:: ../../case-studies/example_goal/src/example.py
.. literalinclude:: ../examples/goal_programming/src/example.py
:language: python
:pyobject: Example.post
:lineno-match:
......@@ -177,7 +177,7 @@ overwiting the internal method.
Finally, we want to apply some additional configuration, reducing the amount of
information the solver outputs:
.. literalinclude:: ../../case-studies/example_goal/src/example.py
.. literalinclude:: ../examples/goal_programming/src/example.py
:language: python
:pyobject: Example.solver_options
:lineno-match:
......@@ -189,7 +189,7 @@ To make our script run, at the bottom of our file we just have to call
the ``run_optimization_problem()`` method we imported on the optimization
problem class we just created.
.. literalinclude:: ../../case-studies/example_goal/src/example.py
.. literalinclude:: ../examples/goal_programming/src/example.py
:language: python
:lineno-match:
:start-after: # Run
......@@ -199,7 +199,7 @@ The Whole Script
All together, the whole example script is as follows:
.. literalinclude:: ../../case-studies/example_goal/src/example.py
.. literalinclude:: ../examples/goal_programming/src/example.py
:language: python
:lineno-match:
......
......@@ -29,7 +29,7 @@ In OpenModelica Connection Editor, the model looks like this:
In text mode, the Modelica model is as follows (with annotation statements
removed):
.. literalinclude:: _build/mo/example_lookuptable_storage.mo
.. literalinclude:: _build/mo/lookup_tables.mo
:language: modelica
:lineno-match:
......@@ -67,7 +67,7 @@ convert the water level goals into volume goals within the optimization problem
class, so we define the ``__init__()`` method so we can pass the values of the
goals in later.
.. literalinclude:: ../../case-studies/example_lookuptable_storage/src/example.py
.. literalinclude:: ../../case-studies/lookup_tables/src/example.py
:language: python
:pyobject: WaterVolumeRangeGoal
:lineno-match:
......@@ -75,7 +75,7 @@ goals in later.
We also want to save energy, so we define a goal to minimize ``Q_release``. This
goal has a lower priority.
.. literalinclude:: ../../case-studies/example_lookuptable_storage/src/example.py
.. literalinclude:: ../../case-studies/lookup_tables/src/example.py
:language: python
:pyobject: MinimizeQreleaseGoal
:lineno-match:
......@@ -85,7 +85,7 @@ Importing Packages
For this example, the import block is as follows:
.. literalinclude:: ../../case-studies/example_lookuptable_storage/src/example.py
.. literalinclude:: ../../case-studies/lookup_tables/src/example.py
:language: python
:lines: 1-10
:lineno-match:
......@@ -96,7 +96,7 @@ Optimization Problem
Next, we construct the class by declaring it and inheriting the desired parent
classes.
.. literalinclude:: ../../case-studies/example_lookuptable_storage/src/example.py
.. literalinclude:: ../../case-studies/lookup_tables/src/example.py
:language: python
:pyobject: Example
:lineno-match:
......@@ -115,7 +115,7 @@ relation using the ``lookup_tables()`` method. We cache the functions for
convenience. The ``lookup_storage_V()`` method can convert timeseries objects,
and we save the water volume goal bounds as timeseries.
.. literalinclude:: ../../case-studies/example_lookuptable_storage/src/example.py
.. literalinclude:: ../../case-studies/lookup_tables/src/example.py
:language: python
:pyobject: Example.pre
:lineno-match:
......@@ -131,7 +131,7 @@ use the ``path_goals()`` method. This is a method that returns a list of the
goals we defined above. The ``WaterVolumeRangeGoal`` needs to be instantiated
with the new water volume timeseries we just defined.
.. literalinclude:: ../../case-studies/example_lookuptable_storage/src/example.py
.. literalinclude:: ../../case-studies/lookup_tables/src/example.py
:language: python
:pyobject: Example.path_goals
:lineno-match:
......@@ -145,7 +145,7 @@ We define the ``priority_completed()`` method to inspect and summerize the
results. These are appended to our intermediate results variable after each
priority is completed.
.. literalinclude:: ../../case-studies/example_lookuptable_storage/src/example.py
.. literalinclude:: ../../case-studies/lookup_tables/src/example.py
:language: python
:pyobject: Example.priority_completed
:lineno-match:
......@@ -155,7 +155,7 @@ to call the ``super()`` method to avoid overwiting the internal method. We can
convert volmes back into water levels using an inverted version of the lookup
table.
.. literalinclude:: ../../case-studies/example_lookuptable_storage/src/example.py
.. literalinclude:: ../../case-studies/lookup_tables/src/example.py
:language: python
:pyobject: Example.post
:lineno-match:
......@@ -163,7 +163,7 @@ table.
Finally, we want to apply some additional configuration, reducing the amount of
information the solver outputs:
.. literalinclude:: ../../case-studies/example_lookuptable_storage/src/example.py
.. literalinclude:: ../../case-studies/lookup_tables/src/example.py
:language: python
:pyobject: Example.solver_options
:lineno-match:
......@@ -175,7 +175,7 @@ To make our script run, at the bottom of our file we just have to call
the ``run_optimization_problem()`` method we imported on the optimization
problem class we just created.
.. literalinclude:: ../../case-studies/example_lookuptable_storage/src/example.py
.. literalinclude:: ../../case-studies/lookup_tables/src/example.py
:language: python
:lineno-match:
:start-after: # Run
......@@ -185,7 +185,7 @@ The Whole Script
All together, the whole example script is as follows:
.. literalinclude:: ../../case-studies/example_lookuptable_storage/src/example.py
.. literalinclude:: ../../case-studies/lookup_tables/src/example.py
:language: python
:lineno-match:
......
......@@ -29,7 +29,7 @@ only when necessary.
The model can be viewed and editied using the OpenModelica Connection Editor
program. First load the Deltares library into OpenModelica Connection Editor,
and then load the example model, located at ``<installation
directory>\RTCTools2\examples\example_mixed_integer\model\Example.mo``. The
directory>\RTCTools2\examples\mixed_integer\model\Example.mo``. The
model ``Example.mo`` represents a simple water system with the following
elements:
......@@ -50,7 +50,7 @@ elements:
In text mode, the Modelica model looks as follows (with annotation statements
removed):
.. literalinclude:: _build/mo/example_mixed_integer.mo
.. literalinclude:: _build/mo/mixed_integer.mo
:language: modelica
:lineno-match:
......@@ -95,7 +95,7 @@ Importing Packages
For this example, the import block is as follows:
.. literalinclude:: ../../case-studies/example_mixed_integer/src/example.py
.. literalinclude:: ../examples/mixed_integer/src/example.py
:language: python
:lines: 1-6
:lineno-match:
......@@ -109,7 +109,7 @@ Optimization Problem
Next, we construct the class by declaring it and inheriting the desired parent
classes.
.. literalinclude:: ../../case-studies/example_mixed_integer/src/example.py
.. literalinclude:: ../examples/mixed_integer/src/example.py
:language: python
:pyobject: Example
:lineno-match:
......@@ -119,7 +119,7 @@ Now we define an objective function. This is a class method that returns the
value that needs to be minimized. Here we specify that we want to minimize the
volume pumped:
.. literalinclude:: ../../case-studies/example_mixed_integer/src/example.py
.. literalinclude:: ../examples/mixed_integer/src/example.py
:language: python
:pyobject: Example.objective
:lineno-match:
......@@ -131,7 +131,7 @@ at an individual timestep, define it inside the ``constraints`` method.
Other parent classes also declare this method, so we call the ``super()`` method
so that we don't overwrite their behaviour.
.. literalinclude:: ../../case-studies/example_mixed_integer/src/example.py
.. literalinclude:: ../examples/mixed_integer/src/example.py
:language: python
:pyobject: Example.path_constraints
:lineno-match:
......@@ -139,7 +139,7 @@ so that we don't overwrite their behaviour.
Finally, we want to apply some additional configuration, reducing the amount of
information the solver outputs:
.. literalinclude:: ../../case-studies/example_mixed_integer/src/example.py
.. literalinclude:: ../examples/mixed_integer/src/example.py
:language: python
:pyobject: Example.solver_options
:lineno-match:
......@@ -151,7 +151,7 @@ To make our script run, at the bottom of our file we just have to call
the ``run_optimization_problem()`` method we imported on the optimization
problem class we just created.
.. literalinclude:: ../../case-studies/example_mixed_integer/src/example.py
.. literalinclude:: ../examples/mixed_integer/src/example.py
:language: python
:lineno-match:
:start-after: # Run
......@@ -161,7 +161,7 @@ The Whole Script
All together, the whole example script is as follows:
.. literalinclude:: ../../case-studies/example_mixed_integer/src/example.py
.. literalinclude:: ../examples/mixed_integer/src/example.py
:language: python
:lineno-match:
......
from subprocess import call
import getpass
import sys
import os
user = getpass.getuser()
srcdir = os.path.normpath(os.path.join(os.getcwd(), '..', '..'))
arguments = \
['docker', 'run', \
# Environment
'-e', 'USER="{}"'.format(user), \
# Mount local filesysteem
'-v', '{}:/usr/src'.format(srcdir.replace('\\', '/').replace('C:', '/c')), \
# Working directory
'-w', '/usr/src/src',
# Run interactively
'-i', \
# Select image
'-t', 'rtctools-modelling-hsl',
# Run nose with JModelica.org Python
'/opt/JModelica/bin/jm_python.sh', \
'setup.py', \
'build_ext', '--inplace']
call(arguments)
run_apidoc = False
if run_apidoc:
arguments = \
['docker', 'run', \
# Environment
'-e', 'USER="{}"'.format(user), \
# Mount local filesysteem
'-v', '{}:/usr/src'.format(srcdir.replace('\\', '/').replace('C:', '/c')), \
# Working directory
'-w', '/usr/src/src',
# Run interactively
'-i', \
# Select image
'-t', 'rtctools-modelling-hsl',
# Run nose with JModelica.org Python
'/opt/JModelica/bin/jm_python.sh', \
'-m', 'sphinx.apidoc', \
'-f', \
'-o', '/usr/src/documentation/api', \
'/usr/src/src/rtctools']
call(arguments)
for backend in ['html']:
arguments = \
['docker', 'run', \
# Environment
'-e', 'USER="{}"'.format(user), \
# Mount local filesysteem
'-v', '{}:/usr/src'.format(srcdir.replace('\\', '/').replace('C:', '/c')), \
# Working directory
'-w', '/usr/src/src', \
# Run interactively
'-i', \
# Select image
'-t', 'rtctools-modelling-hsl',
# Run nose with JModelica.org Python
'/opt/JModelica/bin/jm_python.sh', \
'-m', 'sphinx', \
'-b', backend, \
'/usr/src/documentation/api', '/usr/src/documentation/api/_build/' + backend]
arguments.extend(sys.argv[1:])
call(arguments)
UTC,Q_in
2013-01-01 00:00:00,1.50
2013-01-01 12:00:00,1.95
2013-01-02 00:00:00,2.55
2013-01-02 12:00:00,3.30
2013-01-03 00:00:00,4.35
2013-01-03 12:00:00,5.55
2013-01-04 00:00:00,7.20
2013-01-04 12:00:00,5.55
2013-01-05 00:00:00,4.35
2013-01-05 12:00:00,3.30
2013-01-06 00:00:00,2.55
2013-01-06 12:00:00,1.95
model Example
Deltares.ChannelFlow.SimpleRouting.BoundaryConditions.Inflow inflow annotation(Placement(visible = true, transformation(origin = {-55, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Deltares.ChannelFlow.SimpleRouting.Storage.Storage storage annotation(Placement(visible = true, transformation(origin = {0, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Deltares.ChannelFlow.SimpleRouting.BoundaryConditions.Terminal outfall annotation(Placement(visible = true, transformation(origin = {55, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
input Modelica.SIunits.VolumeFlowRate Q_in(fixed = true);
input Modelica.SIunits.VolumeFlowRate Q_release(fixed = false, min = 0.0, max = 6.5);
output Modelica.SIunits.Volume V_storage;
equation
connect(inflow.QOut, storage.QIn) annotation(Line(points = {{-47, 0}, {-10, 0}}));
connect(storage.QOut, outfall.QIn) annotation(Line(points = {{8, 0}, {47, 0}}));
storage.Q_release = Q_release;
inflow.Q = Q_in;
V_storage = storage.V;
annotation(Diagram(coordinateSystem(extent = {{-148.5, -105}, {148.5, 105}}, initialScale = 0.1, grid = {5, 5})));
end Example;
from rtctools.optimization.collocated_integrated_optimization_problem \
import CollocatedIntegratedOptimizationProblem
from rtctools.optimization.modelica_mixin import ModelicaMixin
from rtctools.optimization.csv_mixin import CSVMixin
from rtctools.util import run_optimization_problem
class Example(CSVMixin, ModelicaMixin, CollocatedIntegratedOptimizationProblem):
"""
A basic example for introducing users to RTC-Tools 2
"""
def objective(self, ensemble_member):
# Minimize water pumped. The total water pumped is the integral of the
# water pumped from the starting time until the stoping time. In
# practice, self.integral() is a summation of all the discrete states.
return self.integral('Q_release', ensemble_member)
def path_constraints(self, ensemble_member):
# Call super() class to not overwrite default behaviour
constraints = super(Example, self).path_constraints(ensemble_member)
# Constrain the volume of storage between 380000 and 420000 m^3
constraints.append((self.state('storage.V'), 380000, 420000))
return constraints
# Run
run_optimization_problem(Example, base_folder='..')
name,probability
forecast1,0.50
forecast2,0.50
UTC,Q_in
2013-01-01 01:00:00,1.50
2013-01-02 01:00:00,1.95
2013-01-03 01:00:00,2.55
2013-01-04 01:00:00,3.30
2013-01-05 01:00:00,4.35
2013-01-06 01:00:00,5.55
2013-01-07 01:00:00,7.20
2013-01-08 01:00:00,5.55
2013-01-09 01:00:00,4.35
2013-01-10 01:00:00,3.30
2013-01-11 01:00:00,2.55
2013-01-12 01:00:00,1.95
UTC,Q_in
2013-01-01 01:00:00,1.5
2013-01-02 01:00:00,1.5
2013-01-03 01:00:00,1.5
2013-01-04 01:00:00,1.5
2013-01-05 01:00:00,1.5
2013-01-06 01:00:00,1.5
2013-01-07 01:00:00,1.5
2013-01-08 01:00:00,1.5
2013-01-09 01:00:00,1.5
2013-01-10 01:00:00,1.5
2013-01-11 01:00:00,1.5
2013-01-12 01:00:00,1.5
[storage_V]
monotonicity = 1
[storage_H]
monotonicity = 1
storage_H,storage_V
-0.75,0
-0.5,0
-0.25,0
0,0
0.25,100000
0.5,500000
0.75,1000000
storage_V,storage_H
0,-0.75
0,-0.5
0,-0.25
0,0
100000,0.25
500000,0.5
1000000,0.75
model Example
Deltares.ChannelFlow.SimpleRouting.BoundaryConditions.Inflow inflow annotation(Placement(visible = true, transformation(origin = {-55, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Deltares.ChannelFlow.SimpleRouting.Storage.Storage storage annotation(Placement(visible = true, transformation(origin = {0, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Deltares.ChannelFlow.SimpleRouting.BoundaryConditions.Terminal outfall annotation(Placement(visible = true, transformation(origin = {55, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
input Modelica.SIunits.VolumeFlowRate Q_in(fixed = true);
input Modelica.SIunits.VolumeFlowRate Q_release(fixed = false, min = 0.0, max = 6.0);
equation
connect(inflow.QOut, storage.QIn) annotation(Line(points = {{-47, 0}, {-10, 0}}));
connect(storage.QOut, outfall.QIn) annotation(Line(points = {{8, 0}, {47, 0}}));
storage.Q_release = Q_release;
inflow.Q = Q_in;
annotation(Diagram(coordinateSystem(extent = {{-148.5, -105}, {148.5, 105}}, initialScale = 0.1, grid = {5, 5})));
end Example;
<
from rtctools.optimization.collocated_integrated_optimization_problem \
import CollocatedIntegratedOptimizationProblem
from rtctools.optimization.goal_programming_mixin \
import GoalProgrammingMixin, Goal