Skip to content

Commit

Permalink
Removed locFunsCas dependency from files that do not need to know abo…
Browse files Browse the repository at this point in the history
…ut casadi #84

- tested against morenet example
  • Loading branch information
timueh committed Mar 31, 2020
1 parent ff08cca commit baa5bd3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
1 change: 1 addition & 0 deletions examples/example_main.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
% addpath(genpath('../tools/'))
% import casadi.*

addpath(genpath('../../numerical-differentiation'))
global use_fmincon
use_fmincon = false;

Expand Down
24 changes: 14 additions & 10 deletions src/core/createLocalSolvers.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
error('currently not supported.');
end

funs = sProb.locFuns;
z0 = sProb.zz0;

for i=1:NsubSys
nnxi{i} = size(sProb.AA{i},2);
nngi{i} = size(sProb.locFunsCas.ggi{i},1);
nnhi{i} = size(sProb.locFunsCas.hhi{i},1);
nngi{i} = size(funs.ggi{i}(z0{i}), 1);
nnhi{i} = size(funs.hhi{i}(z0{i}), 1);

% set up bounds for equalities/inequalities
gBounds.llb{i} = [zeros(nngi{i},1); -inf*ones(nnhi{i},1)];
Expand All @@ -26,6 +29,7 @@
funs = sProb.locFuns;
solve_nlp = @(x, z, rho, lambda, Sigma, pars)build_local_NLP(funs.ffi{i}, funs.ggi{i}, funs.hhi{i}, sProb.AA{i}, lambda, rho, z, Sigma, x, sProb.llbx{i}, sProb.uubx{i});
else
assert(isfield(sProb, 'locFunsCas'), 'locFunsCas field is missing')
nlp_reference = build_nlp_reference(sProb.xxCas{i},...
sProb.locFunsCas.ffi{i},...
sProb.locFunsCas.ggi{i},...
Expand Down Expand Up @@ -59,14 +63,14 @@
end

function res = build_nlp_with_casadi(x, z, rho, lambda, Sigma, pars, nlp, lbx, ubx, lbg, ubg)
sol = nlp('x0',x,...
'lam_g0', pars.lam_g0,...
'lam_x0', pars.lam_x0,...
'p', [rho; lambda; z; Sigma(:)],...
'lbx', lbx,...
'ubx', ubx,...
'lbg', lbg, ...
'ubg', ubg);
sol = nlp( 'x0', x,...
'lam_g0', pars.lam_g0,...
'lam_x0', pars.lam_x0,...
'p', [rho; lambda; z; Sigma(:)],...
'lbx', lbx,...
'ubx', ubx,...
'lbg', lbg, ...
'ubg', ubg);
res.x = sol.x;
res.lam_g = sol.lam_g;
res.lam_x = sol.lam_x;
Expand Down
7 changes: 5 additions & 2 deletions src/core/createSens.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
import casadi.*
NsubSys = length(sProb.AA);

funs = sProb.locFuns;
z0 = sProb.zz0;

for i=1:NsubSys
nngi{i} = size(sProb.locFunsCas.ggi{i},1);
nnhi{i} = size(sProb.locFunsCas.hhi{i},1);
nngi{i} = size(funs.ggi{i}(z0{i}), 1);
nnhi{i} = size(funs.hhi{i}(z0{i}), 1);

% Lagrange multipliers for nonlinear constraints
kkappCas = opts.sym('kapp',nngi{i}+nnhi{i},1);
Expand Down
7 changes: 5 additions & 2 deletions src/core/initializeVariables.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
iter.lam = sProb.lam0;
iter.delxs = inf;

funs = sProb.locFuns;
z0 = sProb.zz0;

for j=1:NsubSys
nngi{j} = size(sProb.locFunsCas.ggi{j},1);
nnhi{j} = size(sProb.locFunsCas.hhi{j},1);
nngi{j} = size(funs.ggi{j}(z0{j}), 1);
nnhi{j} = size(funs.hhi{j}(z0{j}), 1);

iter.KKapp{j} = zeros(nngi{j}+nnhi{j},1);
iter.LLam_x{j}= zeros(length(iter.loc.xx{j}),1);
Expand Down

0 comments on commit baa5bd3

Please sign in to comment.