Skip to content

Commit

Permalink
cleaned up iterateAL in the spirit of
Browse files Browse the repository at this point in the history
  • Loading branch information
timueh committed Apr 17, 2020
1 parent 3464fe0 commit a640297
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 36 deletions.
3 changes: 1 addition & 2 deletions src/core/createLocSolAndSens.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
end

% create local solvers
% [ sProb.nnlp, sProb.gBounds, sProb.rhoCas, sProb.lamCas, sProb.SSig ] = ...
% createLocalSolvers(sProb, opts);
% [ sProb.nnlp, sProb.gBounds, sProb.rhoCas, sProb.lamCas, sProb.SSig ] = createLocalSolvers(sProb, opts);

% compute sensitivities (gradient, Jacobian, ...)
sProb.rhoCas = opts.sym('rho',1,1);
Expand Down
67 changes: 33 additions & 34 deletions src/core/iterateAL.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,16 @@
iterTimer = tic;
i = 1;
iter.i = 1;
while (i <= opts.maxiter) && ( (strcmp(opts.term_eps,'false')) || (iter.logg.consViol(i) >= opts.term_eps))

while (i <= opts.maxiter) && ( (strcmp(opts.term_eps,'false')) || (iter.logg.consViol(i) >= opts.term_eps))
% solve local NLPs and evaluate sensitivities
if (strcmp( opts.parfor, 'true' ))
if (strcmp(opts.parfor, 'true' ))
[ iter.loc, timers, opts ] = parallelStepDecentral( sProb, iter, timers, opts );
else
[ timers, opts, iter ] = parallelStepCentral( sProb, iter, timers, opts );
end
% set up and solve the coordination QP
tic
iter.lamOld = iter.lam;
if strcmp(opts.innerAlg, 'none')
% update scaling matrix for consensus violation slack
if strcmp(opts.DelUp,'true')
if i > 2
[opts.Del, iter.consViol] = computeDynSig(opts.Del,...
[sProb.AA{:}]*vertcat(iter.yy{:}),iter.consViol, 'Del');
else
iter.consViol = [sProb.AA{:}]*vertcat(iter.yy{:});
end
end

% set up and solve coordination QP
[ HQP, gQP, AQP, bQP] = createCoordQP( sProb, iter, opts );
[ xs, lamTot] = solveQP(HQP,gQP,AQP,bQP,opts.solveQP);
[ iter.ddelx iter.lam ] = decomposeX(xs, lamTot, iter, opts);
else
% solve coordination QP decentrally
iter.loc.cond = condenseLocally(sProb, iter);
% solve condensed QP by decentralized CG/ADMM
[ iter.llam, iter.lam, iter.comm ] = ...
solveQPdecNew(iter.loc.cond, iter.lam, opts);
% [ iter.llam, iter.lam ] = solveQPdecOld(iter.loc.cond, iter.lam, ...
% opts, iter, sProb );
% expand again locally based on computed \lamda
iter.ddelx = expandLocally(iter.llam, iter.loc.cond);
end
iter = setup_and_solve_QP(sProb, iter, opts, i);
timers.QPtotTime = timers.QPtotTime + toc;

% do a line search on the QP step?
Expand All @@ -53,7 +26,7 @@
end

% compute the ALADIN step
iter.yyOld = iter.yy;
iter.yyOld = iter.yy;
[ iter.yy, iter.lam ] = computeALstep( iter );

% rho update
Expand All @@ -67,18 +40,18 @@

% logging of variables?
loggFl = true;
if loggFl == true
if loggFl
logValues;
end

% plot iterates?
if strcmp(opts.plot,'true')
if opts.plot
tic
plotIterates;
timers.plotTimer = timers.plotTimer + toc;
end

i = i+1;
i = i+1;
iter.i = i;
end
timers.iterTime = toc(iterTimer);
Expand All @@ -89,3 +62,29 @@

end

function iter = setup_and_solve_QP(prob, iter, opts, i)
iter.lamOld = iter.lam;
if strcmp(opts.innerAlg, 'none')
% update scaling matrix for consensus violation slack
if strcmp(opts.DelUp,'true')
if i > 2
[opts.Del, iter.consViol] = computeDynSig(opts.Del,...
[prob.AA{:}]*vertcat(iter.yy{:}),iter.consViol, 'Del');
else
iter.consViol = [prob.AA{:}]*vertcat(iter.yy{:});
end
end
% set up and solve coordination QP
[ HQP, gQP, AQP, bQP] = createCoordQP( prob, iter, opts );
[ xs, lamTot] = solveQP(HQP, gQP, AQP, bQP, opts.solveQP);
[ iter.ddelx, iter.lam ] = decomposeX(xs, lamTot, iter, opts);
else
% solve coordination QP decentrally
iter.loc.cond = condenseLocally(prob, iter);
% solve condensed QP by decentralized CG/ADMM
[ iter.llam, iter.lam, iter.comm ] = solveQPdecNew(iter.loc.cond, iter.lam, opts);
% expand again locally based on computed \lamda
iter.ddelx = expandLocally(iter.llam, iter.loc.cond);
end
end

0 comments on commit a640297

Please sign in to comment.