MPC and time-dependent terms in cost function

6 posts / 0 new
Last post
borlum
Offline
Joined: 2016-09-22
MPC and time-dependent terms in cost function

Hello!

I am currently employing the MPC-class by Axelsson in a project revolving optimal control of both district heating and power production. Generally, it works great with very nice solution times. However, I am banging my head against a problem -- and have been for quite some time now...

I would like to investigate scenarios with changes to power prices, which alters my general cost function of maximizing profit while maintaining a certain QoS of for the consumers.

In a very crude example, I would simply like to change the price at a certain time, t. This should have the effect, that e.g. load is switched from one production unit to another. The price change is simply modeled by a Step (Modelica.Blocks.Sources), and the output of the step is then simply a factor in my cost function.

This works just fine for 'open loop' optimal control; solving the problem once and just obtaining the control input trajectories.

But when I use the MPC-class and the same optimization problem, it is as if the price change never happens... No response/reaction at all.

I stumbled upon a paragraph in Axelssons thesis about the MPC-class, which states that it can't handle time-dependent models (e.g. equations including 'time' explicitly).
Perhaps this is this case?

If this is simply not possible using the MPC-class; are there other options? Should it be possible if one instead uses the cstr_mpc.py example as reference?

 

Best regards!

Joakim

 

UPDATE:

So, I fooled around with the external_data after reading http://www.jmodelica.org/4436 -- which is basically what I want. Now, I understand from Axelssons thesis, that external_data is not supported. But after the implementation of https://trac.jmodelica.org/ticket/4258 (mutable_external_data), it theoretically should be, right?

But, with a naive attempt, I run into the following problems:

Traceback (most recent call last):
File "MPC.py", line 131, in
MPC_object = MPC(op['model'], opts, sample_period, horizon, initial_guess='prev')
File "/opt/jmodelica/Python/pyjmi/optimization/mpc.py", line 180, in __init__
self._create_nlp_object()
File "/opt/jmodelica/Python/pyjmi/optimization/mpc.py", line 384, in _create_nlp_object
self.alg = LocalDAECollocationAlg(self.op, self.options)
File "/opt/jmodelica/Python/pyjmi/jmi_algorithm_drivers.py", line 1300, in __init__
self.nlp = LocalDAECollocator(self.op, self.options)
File "/opt/jmodelica/Python/pyjmi/optimization/casadi_collocation.py", line 981, in __init__
self._create_nlp()
File "/opt/jmodelica/Python/pyjmi/optimization/casadi_collocation.py", line 1034, in _create_nlp
self._create_nlp_variables()
File "/opt/jmodelica/Python/pyjmi/optimization/casadi_collocation.py", line 1542, in _create_nlp_variables
global_split=casadi.vertsplit(xx,global_split_indices)
File "/opt/jmodelica/Python/casadi/casadi_core.py", line 18979, in vertsplit
return _casadi_core.vertsplit(*args)
RuntimeError: The assertion "isMonotone(offset)" on line 198 of file "/home/borlum/JModelica.org/ThirdParty/CasADi/CasADi/casadi/core/mx/mx_tools.cpp" failed.
Please notify the CasADi developers.

I would be happy to help in getting it to work, but my understanding of the underlying functionality is very limited. It would however be a great feature(!).

fredrik
Offline
Joined: 2011-08-26
I will take a look at this

I will take a look at this some time next week (hopefully). It would be very helpful if you can send some code (Python + Modelica) to reproduce the above error.

borlum
Offline
Joined: 2016-09-22
Will package it

Hi Fredrik,

Thank you - greatly appreciated. I will just attempt to package it easily for you, as the project is quite large.

From my own investigation, I am pretty certain, that the problem lies in the 'shifting' method of the MPC-class. It has to be expanded, to also be able to shift variables eliminated by external data, now that external data is mutable.

Regards,

Joakim

borlum
Offline
Joined: 2016-09-22
Code

Hi Fredrik,

 

Code found here: https://dl.dropboxusercontent.com/u/9884796/problem.zip (Zipped to preserve directory structure)

 

So, I have attempted to cut down on as much as possible, in order for you to run it :-)

In the control/ folder, I have the MPC example and an open loop optimal control example.

If you enter the mpc/ folder and run "MPC.py", you should be able to reproduce the error.

 

I am attempting to supply an elimination trajectory for the top-level input I call "price".

 

Please do reach out if you attempt to look at it -- will do what I can to aid you.

But so far, I have only familiarized myself somewhat with the MPC-class itself. As soon as it off-loads to casadi I am in to deep :-)

 

/Joakim

borlum
Offline
Joined: 2016-09-22
Solution

Ok, so I dug in and wrote my own MPC-class which features shifting of external_data -- it works just fine, however I don't micro-manage the solver as much as in Magdalenas MPC-class. I just rely on warm starting. Thought it would be more of more trouble, but the implementation is rather small, so I am pretty happy with it.

But thanks for considering my problems :-)

/Joakim

fredrik
Offline
Joined: 2011-08-26
I am glad to hear you managed

I am glad to hear you managed to find a solution on your own! I may look into supporting mutable external data in the MPC class in the future.

Login or register to post comments