Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions QPALM/interfaces/mex/qpalm.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
properties (SetAccess = private, Hidden = true)
n;
m;
A_sparsity;
Q_sparsity;
% objectHandle % Handle to underlying C instance
end
methods(Static)
Expand Down Expand Up @@ -102,6 +104,7 @@ function delete(this)
Q = sparse(Q);
% Q = full(Q(:,:));
end
this.Q_sparsity = logical(Q);
if (isempty(q))
q = zeros(n, 1);
else
Expand All @@ -113,6 +116,7 @@ function delete(this)
(~isempty(A) && (isempty(bmin) && isempty(bmax)))
error('A must be supplied together with at least one bound l or u');
end
this.A_sparsity = logical(A);

if (~isempty(A) && isempty(bmin))
bmin = -Inf(m, 1);
Expand Down Expand Up @@ -212,6 +216,25 @@ function update_q(this, q)
qpalm.qpalm_mex('update_q', q);
end

function update_Q_A(this, Q, A)
% UPDATE_Q_A update the matrices Q and A
%
% update_Q_A(Q, A)

if (isempty(A))
A = zeros(this.m, this.n);
else
A = full(A);
end
if (isempty(Q))
Q = zeros(this.n);
else
Q = full(Q);
end
Qxi = this.Q_sparsity & triu(true(this.n));
qpalm.qpalm_mex('update_Q_A', Q(Qxi), A(this.A_sparsity));
end

function update_bounds(this, bmin, bmax)
% UPDATE_BOUNDS update the lower and upper bounds of the linear
% constraints. Use empty matrices to denote bounds that are not
Expand Down
18 changes: 17 additions & 1 deletion QPALM/interfaces/mex/src/qpalm_mex.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#define MODE_WARM_START "warm_start"
#define MODE_UPDATE_BOUNDS "update_bounds"
#define MODE_UPDATE_LINEAR "update_q"
#define MODE_UPDATE_MATRICES "update_Q_A"
#define MODE_SOLVE "solve"
#define MODE_DELETE "delete"

Expand Down Expand Up @@ -186,7 +187,7 @@ void mexFunction(int nlhs, mxArray * plhs [], int nrhs, const mxArray * prhs [])
char cmd[64];

if (nrhs < 1 || mxGetString(prhs[0], cmd, sizeof(cmd)))
mexErrMsgTxt("First input should be a command string less than 64 characters long.");
mexErrMsgTxt("First input should be a command string less than 64 characters long.");

// report the default settings
if (strcmp(cmd, MODE_DEFAULT_SETTINGS) == 0) {
Expand Down Expand Up @@ -351,6 +352,21 @@ void mexFunction(int nlhs, mxArray * plhs [], int nrhs, const mxArray * prhs [])
mexWarnMsgTxt("Update q: Empty q has no effect.");
}

} else if (strcmp(cmd, MODE_UPDATE_MATRICES) == 0) {

if (nlhs != 0 || nrhs != 3){
mexErrMsgTxt("Update Q and A : wrong number of inputs / outputs");
}
if(!qpalm_work){
mexErrMsgTxt("Work is not setup.");
}

if (!mxIsEmpty(prhs[1])) {
qpalm_update_Q_A(qpalm_work, mxGetPr(prhs[1]), mxGetPr(prhs[2]));
} else {
mexWarnMsgTxt("Update Q and A: Empty Q has no effect.");
}

} else if (strcmp(cmd, MODE_SOLVE) == 0) { // SOLVE

if (nlhs != 5 || nrhs != 1){
Expand Down