Skip to content

Commit

Permalink
Merge pull request #265 from Jkings300/develop
Browse files Browse the repository at this point in the history
Fix for #264 and documentation. Easy fix, thank you!
  • Loading branch information
4flixt committed May 18, 2022
2 parents f755494 + ffd475b commit bbb858e
Showing 1 changed file with 32 additions and 28 deletions.
60 changes: 32 additions & 28 deletions do_mpc/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def x0(self):
mpc.x0['temperature'] # all elements of variable
mpc.x0['temperature', 0:2] # 0th and 1st element
Usefull CasADi symbolic structure methods:
Useful CasADi symbolic structure methods:
* ``.shape``
Expand Down Expand Up @@ -138,7 +138,7 @@ def u0(self):
mpc.u0['heating'] # all elements of variable
mpc.u0['heating', 0:2] # 0th and 1st element
Usefull CasADi symbolic structure methods:
Useful CasADi symbolic structure methods:
* ``.shape``
Expand Down Expand Up @@ -176,7 +176,7 @@ def z0(self):
mpc.z0['temperature'] # all elements of variable
mpc.z0['temperature', 0:2] # 0th and 1st element
Usefull CasADi symbolic structure methods:
Useful CasADi symbolic structure methods:
* ``.shape``
Expand Down Expand Up @@ -371,6 +371,10 @@ def _getvar(self, var_name):
else:
# Before calling setup the attributes _x,_u,_z etc. are dicts with the keys: name and var.
sym_dict = getattr(self, var_name)
if var_name == '_aux_expression': # or possibly '_aux, depending on what is called in the getter
# create the required dict from what is currently a
sym_dict = {'name':[entry.name for entry in sym_dict],
'var': [entry.expr for entry in sym_dict]}
# We use the same method as in setup to create symbolic structures from these dicts
sym_struct = self._convert2struct(sym_dict)
# We then create a mutable structure of the same structure
Expand Down Expand Up @@ -403,7 +407,7 @@ def x(self):
model.x['temperature'] # all elements of variable
model.x['temperature', 0:2] # 0th and 1st element
Usefull CasADi symbolic structure methods:
Useful CasADi symbolic structure methods:
* ``.shape``
Expand All @@ -412,13 +416,13 @@ def x(self):
* ``.labels()``
:raises assertion: Cannot set model variables direcly. Use set_variable instead.
:raises assertion: Cannot set model variables directly Use set_variable instead.
"""
return self._getvar('_x')

@x.setter
def x(self, val):
raise Exception('Cannot set model variables direcly. Use set_variable instead.')
raise Exception('Cannot set model variables directly Use set_variable instead.')

@property
def u(self):
Expand All @@ -441,21 +445,21 @@ def u(self):
model.u['heating'] # all elements of variable
model.u['heating', 0:2] # 0th and 1st element
Usefull CasADi symbolic structure methods:
Useful CasADi symbolic structure methods:
* ``.shape``
* ``.keys()``
* ``.labels()``
:raises assertion: Cannot set model variables direcly. Use set_variable instead.
:raises assertion: Cannot set model variables directly Use set_variable instead.
"""
return self._getvar('_u')

@u.setter
def u(self, val):
raise Exception('Cannot set model variables direcly. Use set_variable instead.')
raise Exception('Cannot set model variables directly Use set_variable instead.')

@property
def z(self):
Expand All @@ -478,7 +482,7 @@ def z(self):
model.z['temperature'] # all elements of variable
model.z['temperature', 0:2] # 0th and 1st element
Usefull CasADi symbolic structure methods:
Useful CasADi symbolic structure methods:
* ``.shape``
Expand All @@ -487,13 +491,13 @@ def z(self):
* ``.labels()``
:raises assertion: Cannot set model variables direcly. Use set_variable instead.
:raises assertion: Cannot set model variables directly Use set_variable instead.
"""
return self._getvar('_z')

@z.setter
def z(self, val):
raise Exception('Cannot set model variables direcly. Use set_variable instead.')
raise Exception('Cannot set model variables directly Use set_variable instead.')

@property
def p(self):
Expand All @@ -516,7 +520,7 @@ def p(self):
model.p['temperature'] # all elements of variable
model.p['temperature', 0:2] # 0th and 1st element
Usefull CasADi symbolic structure methods:
Useful CasADi symbolic structure methods:
* ``.shape``
Expand All @@ -525,13 +529,13 @@ def p(self):
* ``.labels()``
:raises assertion: Cannot set model variables direcly. Use set_variable instead.
:raises assertion: Cannot set model variables directly Use set_variable instead.
"""
return self._getvar('_p')

@p.setter
def p(self, val):
raise Exception('Cannot set model variables direcly. Use set_variable instead.')
raise Exception('Cannot set model variables directly Use set_variable instead.')

@property
def tvp(self):
Expand All @@ -554,21 +558,21 @@ def tvp(self):
model.tvp['temperature'] # all elements of variable
model.tvp['temperature', 0:2] # 0th and 1st element
Usefull CasADi symbolic structure methods:
Useful CasADi symbolic structure methods:
* ``.shape``
* ``.keys()``
* ``.labels()``
:raises assertion: Cannot set model variables direcly. Use set_variable instead.
:raises assertion: Cannot set model variables directly Use set_variable instead.
"""
return self._getvar('_tvp')

@tvp.setter
def tvp(self, val):
raise Exception('Cannot set model variables direcly. Use set_variable instead.')
raise Exception('Cannot set model variables directly Use set_variable instead.')

@property
def y(self):
Expand All @@ -591,21 +595,21 @@ def y(self):
model.y['temperature', 0] # 0th element of variable
model.y['temperature'] # all elements of variable
Usefull CasADi symbolic structure methods:
Useful CasADi symbolic structure methods:
* ``.shape``
* ``.keys()``
* ``.labels()``
:raises assertion: Cannot set model variables direcly. Use set_meas instead.
:raises assertion: Cannot set model variables directly Use set_meas instead.
"""
return self._getvar('_y')

@y.setter
def y(self, val):
raise Exception('Cannot set model variables direcly. Use set_variable instead.')
raise Exception('Cannot set model variables directly Use set_variable instead.')

@property
def aux(self):
Expand All @@ -629,21 +633,21 @@ def aux(self):
model.aux['dtemp', 0] # 0th element of variable
model.aux['dtemp'] # all elements of variable
Usefull CasADi symbolic structure methods:
Useful CasADi symbolic structure methods:
* ``.shape``
* ``.keys()``
* ``.labels()``
:raises assertion: Cannot set aux direcly. Use set_expression instead.
:raises assertion: Cannot set aux directly Use set_expression instead.
"""
return self._getvar('_aux_expression')

@aux.setter
def aux(self, val):
raise Exception('Cannot set model variables direcly. Use set_variable instead.')
raise Exception('Cannot set model variables directly Use set_variable instead.')

@property
def w(self):
Expand All @@ -658,15 +662,15 @@ def w(self):
The process noise is used for the :py:class:`do_mpc.estimator.MHE` and
can be used to simulate a disturbed system in the :py:class:`do_mpc.simulator.Simulator`.
Usefull CasADi symbolic structure methods:
Useful CasADi symbolic structure methods:
* ``.shape``
* ``.keys()``
* ``.labels()``
:raises assertion: Cannot set w direcly.
:raises assertion: Cannot set w directly
"""
return self._getvar('_w')

Expand All @@ -688,15 +692,15 @@ def v(self):
The measurement noise is used for the :py:class:`do_mpc.estimator.MHE` and
can be used to simulate a disturbed system in the :py:class:`do_mpc.simulator.Simulator`.
Usefull CasADi symbolic structure methods:
Useful CasADi symbolic structure methods:
* ``.shape``
* ``.keys()``
* ``.labels()``
:raises assertion: Cannot set v direcly.
:raises assertion: Cannot set v directly
"""
return self._getvar('_v')

Expand Down

0 comments on commit bbb858e

Please sign in to comment.