Optimisation sampling in order to model uncertainty in temperature prediction(MPC)

50 views
Skip to first unread message

Kevin

unread,
Sep 6, 2018, 4:52:37 AM9/6/18
to YALMIP
Hi,

I'm working on an economic MPC in order to control the temperature in a building. 
The internal prediction model is an ARX model, which is converted to state space. 
The output of this model is the room temperature. 
However, there is some uncertainty in the prediction, so I added an uncertainty variable:

  for k=1:N
        x(:,k+1) = idssModel.A*x(:,k)+idssModel.B(1:nx,nv+1:nv+nu)*Us(:,k)+idssModel.B(1:nx, 1:nv)*Vs(:,k);
        TRoom(k) = idssModel.C*x(:,k)+idssModel.D(1, 1:nv)*Vs(:,k)+idssModel.D(1, nv+1:nv+nu)*Us(:,k);
  end
  TRoom(N+1) = idssModel.C*x(:,N+1)+idssModel.D(1, 1:nv)*Vs(:,N)+idssModel.D(1, nv+1:nv+nu)*Us(:,N);
  TRoom = TRoom + predictionUncertainty;


 constraints = [constraints, 0 <= syBound];
 constraints = [constraints, (TComfort_lower - syBound) <= TRoom(2:N+1) <= (TComfort_upper + syBound)];
 constraints = [constraints, uncertain(predictionUncertainty, 'norm', mean(ModelError,2)', std(ModelError,0,2)')];





Where ModelError is a n*p matrix which contains the error at every prediction step (n) and every simulation time step (p). 

I tried the following:
 parameters_in = {predictionUncertainty, lastMV, x(:,1), v(:,:), conQheater_min, conQheater_max, prevHPon, dT, TComfort_lower(:), TComfort_upper(:), conQsol_min(:), conQsol_max(:), conQven_min(:), conQven_max(:), historyHPon, heatingMode, coolingMode};



inputs = {[], lastU, xState, MD, Qheater_min, Qheater_max, hpState(end), [ones(1,N)*ycurrent-5; ones(1,N)*ycurrent+5], TComfLow, TComfUpp, Qsol_min, Qsol_max, mVen_min, mVen_max, any(hpState), 1, 0};

test = sample(MPC(inputs, 'nosolve'),2);

test() --> error

test = sample(MPC(inputs),2);
test() --> error

test = sample(MPC(inputs));
test() --> working



I get the following error:

Error using gurobi
Incorrect size(model.sense)

Error in callgurobi (line 13)
result = gurobi(model,model.params);

Error in optimizer/subsref (line 326)
                eval(['output = ' self.model.solver.call '(self.model);']);

Error in optimizer/subsref (line 9)
    [varargout{1:nargout}] = subsref(self,subs);
 

Furthermore, I had to place the uncertainty variable at the first place in the cell array, otherwise sample didn't work at all (don't know if this is a bug?).

How can I solve this? Or is there a better way to tackle the uncertainty in the forecast?

Thanks in advance!


Johan Löfberg

unread,
Sep 6, 2018, 7:00:02 AM9/6/18
to YALMIP
You would have to supply reproducible code that can be run


Kevin

unread,
Sep 6, 2018, 8:18:09 AM9/6/18
to YALMIP
This should reproduce the error.
part_MPC.m
required_data.mat

Johan Löfberg

unread,
Sep 6, 2018, 8:47:42 AM9/6/18
to YALMIP
This is weird model as you have predictionUncertainty as both uncertainty (and thus it is supposed to be eliminated when YALMIP derive the robust counterpart), and then you list is as a parameter, i.e. you are supposed to call the optimizer object with specific values on it. You appear to miss the point of either robust optimization, or the optimizer framework

btw, optimizer lowers the verbosity level one level vs optimize, so you don't have to explicitly set it to 0

Kevin

unread,
Sep 6, 2018, 8:51:07 AM9/6/18
to YALMIP
But in https://yalmip.github.io/randomextension/ you have the following code:
Model = [v'*x <= 1, uncertain(v,'unif',[-1;-1],[1;1])];
OneHyperPlaneModel = optimizer(Model, -sum(x),ops,v,x);

Here the uncertain variable is also a parameter?

Johan Löfberg

unread,
Sep 6, 2018, 9:00:14 AM9/6/18
to YALMIP
Ah, I missed the fact that you used the sample framework.

Hmm, I don't have the ident toolbox installed on this machine (oh the irony considering Lennart sits 3 meters down the corridor...) so I cannot run it. Can you refactor your code so that it uses standard data and I will have a look at it. This framework is still under development and little tested (but fun that you found it!)

Johan Löfberg

unread,
Sep 6, 2018, 9:02:46 AM9/6/18
to YALMIP
but note that  sample(MPC(inputs),2) is doomed to give you an infeasible problem (as the uncertainty enters an equality constraint, hence it can only be satisfied for 1 sample). It could be that you actually wnted to assign, not constrain

TRoom = (Ys+predictionUncertainty - yPS.ymean).*(yPS.xstd./yPS.ystd)+yPS.xmean

Kevin

unread,
Sep 6, 2018, 9:18:45 AM9/6/18
to YALMIP
It looks like that was the problem for the error. At least it gives something back now, which isn't an error. Thanks!

Johan Löfberg

unread,
Sep 6, 2018, 9:34:49 AM9/6/18
to YALMIP
Good to hear. Let me know if there's anything more. As I said, very little used parts of YALMIP but will be extended
Reply all
Reply to author
Forward
0 new messages