-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Hadrien Godard
committed
Mar 12, 2018
1 parent
d663426
commit a1e1ab2
Showing
24 changed files
with
713 additions
and
146 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,14 +4,16 @@ | |
% Derives the following slack formulation | ||
% | ||
% minimize f(x,s) | ||
% subj to c(x) - s = 0 | ||
% subj to ceq(x) = ceq | ||
% c(x) - s = 0 | ||
% bL <= x <= bU | ||
% cL <= s <= cU | ||
% | ||
% from the inequality-based formulation: | ||
% | ||
% minimize f(x) | ||
% subj to cL <= c(x) <= cU | ||
% subj to ceq(x) = ceq | ||
% cL <= c(x) <= cU | ||
% bL <= x <= bU | ||
% | ||
% Thus, the problem appears as such: | ||
|
@@ -21,8 +23,7 @@ | |
properties | ||
nlp % original inequality-based object | ||
islack % indictor of slack variables | ||
n_I % number of inequality constraints | ||
c_I % inequality constraints | ||
nslack % number of slack variables | ||
end | ||
|
||
properties (SetAccess = private, Hidden = false) | ||
|
@@ -34,23 +35,20 @@ | |
|
||
function self = slackmodel(nlp) | ||
|
||
constraints_I = find(nlp.cL ~= nlp.cU); | ||
nI = size(constraints_I,1); | ||
|
||
% Upper and lower bounds for the variables and slacks. | ||
bL = [ nlp.bL; nlp.cL(constraints_I) ]; | ||
bU = [ nlp.bU; nlp.cU(constraints_I) ]; | ||
bL = [ nlp.bL; nlp.cL(~nlp.iFix) ]; | ||
bU = [ nlp.bU; nlp.cU(~nlp.iFix) ]; | ||
|
||
% The linear and nonlinear constraints are equalities, ie, | ||
% 0 <= c(x) - s <= 0. | ||
cL = nlp.cL; | ||
cL(~nlp.iFix) = zeros(sum(~nlp.iFix), 1); | ||
cU = nlp.cU; | ||
cL(constraints_I) = zeros(nI, 1); | ||
cU(constraints_I) = zeros(nI, 1); | ||
cU(~nlp.iFix) = zeros(sum(~nlp.iFix), 1); | ||
|
||
% Initial point. Set slacks to be feasible. | ||
c = nlp.fcon(nlp.x0); | ||
x0 = [ nlp.x0; c(constraints_I) ]; | ||
x0 = [ nlp.x0; c(~nlp.iFix) ]; | ||
|
||
% Instantiate from the base class. | ||
self = [email protected](nlp.name, x0, cL, cU, bL, bU); | ||
|
@@ -59,18 +57,19 @@ | |
self.linear = nlp.linear; | ||
|
||
% Create an indetifier for slack variables. | ||
self.islack = [ false(nlp.n,1); true(nI,1) ]; | ||
|
||
nS = sum(~nlp.iFix); | ||
self.nslack = nS; | ||
self.islack = [ false(nlp.n,1); true(nS,1) ]; | ||
|
||
% Jacobian sparsity pattern of the slack model. | ||
Jx = nlp.gcon(nlp.x0); | ||
J = [spones(Jx) sparse(nlp.m, nI)]; | ||
J(constraints_I , nlp.n +1: nlp.n + nI) = speye(nI); | ||
self.Jpattern = J; | ||
|
||
J = nlp.gcon(nlp.x0); | ||
Js = sparse(nlp.m,nS); | ||
Js(~nlp.iFix,:) = speye(nS); | ||
self.Jpattern = [spones(J) Js]; | ||
% Hessian sparsity pattern. | ||
y = ones(size(c)); | ||
HL = nlp.hlag(nlp.x0, y); | ||
nS = self.n - nlp.n; | ||
self.Hpattern = [ spones(HL) sparse(nlp.n, nS) | ||
sparse(nS, nlp.n) sparse(nS , nS) ]; | ||
|
||
|
@@ -81,10 +80,6 @@ | |
% Store the original NLP model. | ||
self.nlp = nlp; | ||
|
||
% Store inequality stuff | ||
self.n_I = nI; | ||
self.c_I = constraints_I; | ||
|
||
end | ||
|
||
function f = fobj_local(self, xs) | ||
|
@@ -95,48 +90,74 @@ | |
function g = gobj_local(self, xs) | ||
x = xs(~self.islack,:); | ||
gx = self.nlp.gobj(x); | ||
g = [gx; sparse(self.n_I, 1)]; | ||
g = [gx; zeros(self.nslack, 1)]; | ||
end | ||
|
||
function H = hobj_local(self, xs) | ||
x = xs(~self.islack,:); | ||
Hx = self.nlp.hobj(x); | ||
nmZ = sparse(self.nlp.n, self.n_I); | ||
mmZ = sparse(self.n_I, self.n_I); | ||
nmZ = sparse(self.nlp.n, self.nslack); | ||
mmZ = sparse(self.nslack, self.nslack); | ||
H = [ Hx nmZ | ||
nmZ' mmZ ]; | ||
end | ||
|
||
function c = fcon_local(self, xs) | ||
x = xs(~self.islack,:); | ||
s = xs( self.islack,:); | ||
c = self.nlp.fcon(x) ; | ||
c(self.c_I) = c(self.c_I) - s; | ||
c = self.nlp.fcon(x); | ||
c(~self.nlp.iFix) = c(~self.nlp.iFix) - s; | ||
end | ||
|
||
function J = gcon_local(self, xs) | ||
x = xs(~self.islack,:); | ||
Jx = self.nlp.gcon(x); | ||
J = [Jx sparse(self.nlp.m,self.n_I)]; | ||
J(self.c_I , self.nlp.n +1: self.nlp.n + self.n_I) = -speye(self.n_I); | ||
Js = sparse(self.m, self.nslack); | ||
Js(~self.nlp.iFix,:) = -speye(self.nslack); | ||
J = [Jx Js]; | ||
end | ||
|
||
function [Jprod, Jtprod] = gconprod_local(self, xs) | ||
% J = self.gcon(x); | ||
[Jxprod, Jxtprod] = self.nlp.gconprod(xs(~self.islack,:)); | ||
Js = sparse(self.m, self.nslack); | ||
Js(~self.nlp.iFix,:) = -speye(self.nslack); | ||
n = sum(~self.islack); | ||
|
||
Jprod = @(v) Jxprod(v(1:n)) + Js*v(n+1:end); | ||
Jtprod = @(v) [Jxtprod(v); Js'*v]; | ||
end | ||
|
||
function HL = hlag_local(self, xs, y) | ||
x = xs(~self.islack,:); | ||
H = self.nlp.hlag(x, y); | ||
nmZ = sparse(self.nlp.n, self.nI); | ||
mmZ = sparse(self.nI,self.nI); | ||
nmZ = zeros(self.nlp.n, self.nslack); | ||
mmZ = zeros(self.nslack); | ||
HL = [ H nmZ | ||
nmZ' mmZ ]; | ||
end | ||
|
||
function Hv = hconprod_local(self, xs, y, vv) | ||
x = xs(~self.islack); | ||
v = vv(~self.islack); | ||
Hv = zeros(self.n, 1); | ||
Hv(~self.islack) = self.nlp.hconprod(x, y, v); | ||
end | ||
|
||
function Hv = hlagprod_local(self, xs, y, vv) | ||
x = xs(~self.islack); | ||
v = vv(~self.islack); | ||
Hv = sparse(self.n, 1); | ||
Hv = zeros(self.n, 1); | ||
Hv(~self.islack) = self.nlp.hlagprod(x, y, v); | ||
end | ||
|
||
function z = ghivprod_local(self, xs, gxs, vxs) | ||
x = xs (~self.islack); | ||
g = gxs(~self.islack); | ||
v = vxs(~self.islack); | ||
z = self.nlp.ghivprod(x, g, v); | ||
end | ||
|
||
end % methods | ||
|
||
end % classdef |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
end | ||
|
||
methods | ||
function o = K1x(slack, options) | ||
function o = K1x(options) | ||
o.diagHess = true; | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.