-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Including formulas for Alpha and Beta #28
Changes from all commits
4d21b49
386d192
40a2d01
d58fbbb
252263d
e19255e
65e9882
0cdfb4c
d902111
47f0d56
95f0f21
0576a5f
197d838
9d3a9c8
7f6eba0
455388e
c2ecd37
415d3de
de919aa
002c845
82b369d
e2e1f3d
dafca87
6af030b
d431c98
9a7ee04
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,8 +91,8 @@ | |
vars.R = -diag(R); | ||
vars.QRi = -[1./diag(Q); 1./diag(R)]; | ||
end | ||
vars.UB = UB; | ||
vars.LB = LB; | ||
% vars.UB = UB; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. Add |
||
% vars.LB = LB; | ||
|
||
% Scaling vectors and operating point | ||
if isa(controller, 'EqualityMPC') | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,17 +96,17 @@ | |
|
||
% Constants | ||
constCell = []; | ||
if size(vars.LB, 2) > 1 | ||
% Different constraints for each prediction step | ||
constCell = add_line(constCell, 'LB0', vars.LB(n+1:end, 1), 1, precision, var_options); | ||
constCell = add_line(constCell, 'UB0', vars.UB(n+1:end, 1), 1, precision, var_options); | ||
constCell = add_line(constCell, 'LB', vars.LB(:, 2:end)', 1, precision, var_options); | ||
constCell = add_line(constCell, 'UB', vars.UB(:, 2:end)', 1, precision, var_options); | ||
defCell = add_line(defCell, 'VAR_BOUNDS', 1, 1, 'int', 'define'); | ||
else | ||
constCell = add_line(constCell, 'LB', vars.LB, 1, precision, var_options); | ||
constCell = add_line(constCell, 'UB', vars.UB, 1, precision, var_options); | ||
end | ||
% if size(vars.LB, 2) > 1 | ||
% % Different constraints for each prediction step | ||
% constCell = add_line(constCell, 'LB0', vars.LB(n+1:end, 1), 1, precision, var_options); | ||
% constCell = add_line(constCell, 'UB0', vars.UB(n+1:end, 1), 1, precision, var_options); | ||
% constCell = add_line(constCell, 'LB', vars.LB(:, 2:end)', 1, precision, var_options); | ||
% constCell = add_line(constCell, 'UB', vars.UB(:, 2:end)', 1, precision, var_options); | ||
% defCell = add_line(defCell, 'VAR_BOUNDS', 1, 1, 'int', 'define'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your changes have disabled the option of having different bounds for each prediction step, which was determined before by the |
||
% else | ||
% constCell = add_line(constCell, 'LB', vars.LB, 1, precision, var_options); | ||
% constCell = add_line(constCell, 'UB', vars.UB, 1, precision, var_options); | ||
% end | ||
if ~solver_options.time_varying | ||
constCell = add_line(constCell, 'Hi', vars.Hi, 1, precision, var_options); | ||
constCell = add_line(constCell, 'Hi_0', vars.Hi_0, 1, precision, var_options); | ||
|
@@ -116,6 +116,7 @@ | |
constCell = add_line(constCell, 'Alpha', vars.Alpha, 1, precision, var_options); | ||
constCell = add_line(constCell, 'Beta', vars.Beta, 1, precision, var_options); | ||
end | ||
constCell = add_line(constCell, 'dummy', 5, 1, precision, var_options); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I imagine the point of this Is this correct? If it is, then we can leave it for now and I will create an Issue to work on solving this bug (because we want to avoid having a |
||
if solver_options.in_engineering | ||
constCell = add_line(constCell, 'scaling_x', vars.scaling_x, 1, precision, var_options); | ||
constCell = add_line(constCell, 'scaling_u', vars.scaling_u, 1, precision, var_options); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ void mexFunction(int nlhs, mxArray *plhs[], | |
double *Q; | ||
double *R; | ||
#endif | ||
double *LB; // Local LB | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We will want to make these optional inputs, so that the user can call the solver as Also, it might be better to change it so that the function is called like |
||
double *UB; // Local UB | ||
double *u_opt; // Local u_opt | ||
double *k; // Local k | ||
double *e_flag; // Local e_flag | ||
|
@@ -34,12 +36,12 @@ void mexFunction(int nlhs, mxArray *plhs[], | |
|
||
// Check number of inputs | ||
#if time_varying == 1 | ||
if(nrhs != 7){ | ||
if(nrhs != 9){ | ||
mexErrMsgIdAndTxt("Spcies:equMPC:nrhs:number", | ||
"Not enough inputs"); | ||
} | ||
#else | ||
if(nrhs != 3){ | ||
if(nrhs != 5){ | ||
mexErrMsgIdAndTxt("Spcies:equMPC:nrhs:number", | ||
"Not enough inputs"); | ||
} | ||
|
@@ -68,25 +70,56 @@ void mexFunction(int nlhs, mxArray *plhs[], | |
} | ||
|
||
#if time_varying == 1 | ||
// Check that A is of the correct dimension | ||
if( !mxIsDouble(prhs[3]) || mxGetNumberOfElements(prhs[3]) != nn*nn ){ | ||
mexErrMsgIdAndTxt("Spcies:laxMPC:nrhs:A", | ||
"A must be of dimension nn by nn"); | ||
} | ||
|
||
// Check that B is of the correct dimension | ||
if( !mxIsDouble(prhs[4]) || mxGetNumberOfElements(prhs[4]) != nn*mm_ ){ | ||
mexErrMsgIdAndTxt("Spcies:laxMPC:nrhs:B", | ||
"A must be of dimension nn by mm"); | ||
} | ||
|
||
|
||
// Check that Q is of the correct dimension | ||
if( !mxIsDouble(prhs[5]) || mxGetNumberOfElements(prhs[5]) != nn ){ | ||
mexErrMsgIdAndTxt("Spcies:laxMPC:nrhs:Q", | ||
"Q must be a diagonal vector of nn elements"); | ||
} | ||
|
||
// Check that R is of the correct dimension | ||
if( !mxIsDouble(prhs[6]) || mxGetNumberOfElements(prhs[6]) != mm_ ){ | ||
mexErrMsgIdAndTxt("Spcies:laxMPC:nrhs:R", | ||
"R must be a diagonal vector of mm elements"); | ||
} | ||
|
||
// Check that LB is of the correct dimension | ||
if( !mxIsDouble(prhs[7]) || mxGetNumberOfElements(prhs[7]) != nm ){ | ||
mexErrMsgIdAndTxt("Spcies:laxMPC:nrhs:LB", | ||
"LB must be a diagonal vector of nm elements"); | ||
} | ||
|
||
// Check that UB is of the correct dimension | ||
if( !mxIsDouble(prhs[8]) || mxGetNumberOfElements(prhs[8]) != nm ){ | ||
mexErrMsgIdAndTxt("Spcies:laxMPC:nrhs:UB", | ||
"UB must be a diagonal vector of nm elements"); | ||
} | ||
|
||
#else | ||
|
||
// Check that LB is of the correct dimension | ||
if( !mxIsDouble(prhs[3]) || mxGetNumberOfElements(prhs[3]) != nm ){ | ||
mexErrMsgIdAndTxt("Spcies:laxMPC:nrhs:LB", | ||
"LB must be a diagonal vector of nm elements"); | ||
} | ||
|
||
// Check that UB is of the correct dimension | ||
if( !mxIsDouble(prhs[4]) || mxGetNumberOfElements(prhs[4]) != nm ){ | ||
mexErrMsgIdAndTxt("Spcies:laxMPC:nrhs:UB", | ||
"UB must be a diagonal vector of nm elements"); | ||
} | ||
|
||
#endif | ||
|
||
// Read input data | ||
|
@@ -134,6 +167,32 @@ void mexFunction(int nlhs, mxArray *plhs[], | |
R = mxGetPr(prhs[6]); | ||
#endif | ||
|
||
#if MX_HAS_INTERLEAVED_COMPLEX | ||
LB = mxGetDoubles(prhs[7]); | ||
#else | ||
LB = mxGetPr(prhs[7]); | ||
#endif | ||
|
||
#if MX_HAS_INTERLEAVED_COMPLEX | ||
UB = mxGetDoubles(prhs[8]); | ||
#else | ||
UB = mxGetPr(prhs[8]); | ||
#endif | ||
|
||
#else | ||
|
||
#if MX_HAS_INTERLEAVED_COMPLEX | ||
LB = mxGetDoubles(prhs[3]); | ||
#else | ||
LB = mxGetPr(prhs[3]); | ||
#endif | ||
|
||
#if MX_HAS_INTERLEAVED_COMPLEX | ||
UB = mxGetDoubles(prhs[4]); | ||
#else | ||
UB = mxGetPr(prhs[4]); | ||
#endif | ||
|
||
#endif | ||
|
||
// Prepare output data | ||
|
@@ -223,9 +282,9 @@ void mexFunction(int nlhs, mxArray *plhs[], | |
|
||
// Call solver | ||
#if time_varying == 1 | ||
equMPC_ADMM(x0, xr, ur, A, B, Q, R, u_opt, k, e_flag, z_opt, v_opt, lambda_opt, update_time_sol, solve_time_sol, polish_time_sol, run_time_sol); | ||
equMPC_ADMM(x0, xr, ur, A, B, Q, R, LB, UB, u_opt, k, e_flag, z_opt, v_opt, lambda_opt, update_time_sol, solve_time_sol, polish_time_sol, run_time_sol); | ||
#else | ||
equMPC_ADMM(x0, xr, ur, u_opt, k, e_flag, z_opt, v_opt, lambda_opt, update_time_sol, solve_time_sol, polish_time_sol, run_time_sol); | ||
equMPC_ADMM(x0, xr, ur, LB, UB, u_opt, k, e_flag, z_opt, v_opt, lambda_opt, update_time_sol, solve_time_sol, polish_time_sol, run_time_sol); | ||
#endif | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't comment this line. Having it in the
vars
variable is useful. In your code right now it is not used, but it will probably be used for default values of the bounds. I would addUB
andLB
back to thevars
structure.