Commit 3241fa11 authored by Jesse VanderWees's avatar Jesse VanderWees 🐘

incorporate new StateGoal helper class in goal programming example

parent 29fb5481
......@@ -92,7 +92,7 @@ Declaring Goals
Goals are defined as classes that inherit the ``Goal`` parent class. The
components of goals can be found in :doc:`../optimization/multi_objective`. In
this example, we show three ways to define a goal in RTC-Tools.
this example, we demonstrate three ways to define a goal in RTC-Tools.
First, we have a high priority goal to keep the water level within a minimum and
maximum. Since we are applying this goal to a specific state (model variable) in
......@@ -104,10 +104,10 @@ goal, called a ``StateGoal``:
:pyobject: WaterLevelRangeGoal
:lineno-match:
We also want to save energy, so we define a goal to minimize the integral
of ``Q_pump``. This goal has a lower priority than the water level range goal.
With non-path goals, the function range must be large enough to enclose the
integral of the variable over all the timesteps.
We also want to save energy, so we define a goal to minimize the integral of
``Q_pump``. This goal has a lower priority than the water level range goal. With
non-path goals, the function range must be large enough to enclose the integral
of the variable over all the timesteps. This goal does not use a helper class:
.. literalinclude:: ../../examples/goal_programming/src/example.py
:language: python
......@@ -119,7 +119,8 @@ least priority. This goal smoothes out the operation of the pump so that it
changes state as few times as possible. To get an idea of what the pump would
have done without this goal, see Mixed Integer: :ref:`mixed-integer-results`.
The order of this goal must be 2, so that it penalizes both positive and
negative derivatives.
negative derivatives. Order of 2 is the default, but we include it here
explicity for the sake of clarity.
.. literalinclude:: ../../examples/goal_programming/src/example.py
:language: python
......@@ -165,9 +166,10 @@ optimizer.
:pyobject: Example.goals
:lineno-match:
For the goals that 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 path
goals we defined above.
For the goals that 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 path goals
we defined above. Goals that inherit ``StateGoal`` are always path goals and
must also always be initialized with the parameter ``self``.
.. literalinclude:: ../../examples/goal_programming/src/example.py
:language: python
......
......@@ -40,7 +40,7 @@ class MinimizeQpumpGoal(Goal):
# function defined above. The nominal is used to scale the value returned by
# the function method so that the value is on the order of 1.
function_range = (0, 540000.0)
function_nominal = 1.0
function_nominal = 100.0
# The lower the number returned by this function, the higher the priority.
priority = 2
# The penalty variable is taken to the order'th power.
......@@ -57,6 +57,7 @@ class MinimizeChangeInQpumpGoal(Goal):
function_range = (-10.0, 10.0)
function_nominal = 5.0
priority = 3
# Default order is 2, but we want to be explicit
order = 2
......@@ -108,6 +109,13 @@ class Example(GoalProgrammingMixin, CSVMixin, ModelicaMixin,
# do not have to worry about order here.
return [WaterLevelRangeGoal(self), MinimizeChangeInQpumpGoal()]
def pre(self):
# Call super() class to not overwrite default behaviour
super(Example, self).pre()
# We keep track of our intermediate results, so that we can print some
# information about the progress of goals at the end of our run.
self.intermediate_results = []
def priority_completed(self, priority):
# We want to show that the results of our highest priority goal (water
# level) are remembered. The other information we want to see is how our
......@@ -126,13 +134,6 @@ class Example(GoalProgrammingMixin, CSVMixin, ModelicaMixin,
self.intermediate_results.append(
(priority, n_level_satisfied, q_pump_integral))
def pre(self):
# Call super() class to not overwrite default behaviour
super(Example, self).pre()
# We keep track of our intermediate results, so that we can print some
# information about the progress of goals at the end of our run.
self.intermediate_results = []
def post(self):
# Call super() class to not overwrite default behaviour
super(Example, self).post()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment