investigate linear infeasibilities -凯发k8网页登录
this example shows how to investigate the linear constraints that cause a problem to be infeasible. for further details about these techniques, see chinneck [1] and [2].
if linear constraints cause a problem to be infeasible, you might want to find a subset of the constraints that is infeasible, but removing any member of the subset makes the rest of the subset feasible. the name for such a subset is irreducible infeasible subset of constraints, abbreviated iis. conversely, you might want to find a maximum cardinality subset of constraints that is feasible. this subset is called a maximum feasible subset, abbreviated maxfs. the two concepts are related, but not identical. a problem can have many different iiss, some with different cardinality.
this example shows two ways of finding an iis, and two ways of obtaining a feasible set of constraints. the example assumes that all given bounds are correct, meaning the lb
and ub
arguments have no errors.
infeasible example
create a random matrix a
representing linear inequalities of size 150-by-15. set the corresponding vector b
to a vector with entries of 10, and change 5% of those values to –10.
n = 15;
rng default
a = randn([10*n,n]);
b = 10*ones(size(a,1),1);
aeq = [];
beq = [];
b(rand(size(b)) <= 0.05) = -10;
f = ones(n,1);
lb = -f;
ub = f;
check that problem
is infeasible.
[x,fval,exitflag,output,lambda] = linprog(f,a,b,aeq,beq,lb,ub);
no feasible solution found. linprog stopped because no point satisfies the constraints.
deletion filter
to identify an iis, perform the following steps. given a set of linear constraints numbered 1 through n, where all problem constraints are infeasible:
for each i
from 1 to n
:
temporarily remove constraint
i
from the problem.test the resulting problem for feasibility.
if the problem is feasible without constraint
i
, return constrainti
to the problem.if the problem is not feasible without constraint
i
, do not return constrainti
to the problem
continue to the next i
(up to value n
).
at the end of this procedure, the constraints that remain in the problem form an iis.
for matlab® code that implements this procedure, see the deletionfilter
helper function at the end of this example.
note: if you use the live script file for this example, the deletionfilter
function is already included at the end of the file. otherwise, you need to create this function at the end of your .m file or add it as a file on the matlab path. the same is true for the other helper functions used later in this example.
see the effect of deletionfilter
on the example data.
[ineqs,eqs,ncall] = deletionfilter(a,b,aeq,beq,lb,ub);
the problem has no equality constraints. find the indices for the inequality constraints and the value of b(iis)
.
iis = find(ineqs)
iis = 114
b(iis)
ans = -10
only one inequality constraint causes the problem to be infeasible, along with the bound constraints. the constraint is
a(iis,:)*x <= b(iis)
.
why is this constraint infeasible together with the bounds? find the sum of the absolute values of that row of a
.
disp(sum(abs(a(iis,:))))
8.4864
due to the bounds, the x
vector has values between –1 and 1, and so a(iis,:)*x
cannot be less than b(iis)
= –10.
how many linprog
calls did deletionfilter
perform?
disp(ncall)
150
the problem has 150 linear constraints, so the function called linprog
150 times.
elastic filter
as an alternative to the deletion filter, which examines every constraint, try the elastic filter. this filter works as follows.
first, allow each constraint i
to be violated by a positive amount e(i)
, where equality constraints have both additive and subtractive positive elastic values.
next, solve the associated linear programming problem (lp)
subject to the listed constraints and with .
if the associated lp has a solution, remove all constraints that have a strictly positive associated , and record those constraints in a list of indices (potential iis members). return to the previous step to solve the new, reduced associated lp.
if the associated lp has no solution (is infeasible) or has no strictly positive associated , exit the filter.
the elastic filter can exit in many fewer iterations than the deletion filter, because it can bring many indices at once into the iis, and can halt without going through the entire list of indices. however, the problem has more variables than the original problem, and its resulting list of indices can be larger than an iis. to find an iis after running an elastic filter, run the deletion filter on the result.
for matlab® code that implements this filter, see the elasticfilter
helper function at the end of this example.
see the effect of elasticfilter
on the example data.
[ineqselastic,eqselastic,ncall] = ...
elasticfilter(a,b,aeq,beq,lb,ub);
the problem has no equality constraints. find the indices for the inequality constraints.
iiselastic = find(ineqselastic)
iiselastic = 5×1
2
60
82
97
114
the elastic iis lists five constraints, whereas the deletion filter found only one. run the deletion filter on the returned set to find a genuine iis.
a_1 = a(ineqselastic > 0,:); b_1 = b(ineqselastic > 0); [dineq_iis,deq_iis,ncall2] = deletionfilter(a_1,b_1,aeq,beq,lb,ub); iiselasticdeletion = find(dineq_iis)
iiselasticdeletion = 5
the fifth constraint in the elastic filter result, inequality 114, is the iis. this result agrees with the answer from the deletion filter. the difference between the approaches is that the combined elastic and deletion filter approach uses many fewer linprog
calls. display the total number of linprog
calls used by the elastic filter followed by the deletion filter.
disp(ncall ncall2)
7
remove iis in a loop
generally, obtaining a single iis does not enable you to find all the reasons that your optimization problem fails. to correct an infeasible problem, you can repeatedly find an iis and remove it from the problem until the problem becomes feasible.
the following code shows how to remove one iis at a time from a problem until the problem becomes feasible. the code uses an indexing technique to keep track of constraints in terms of their positions in the original problem, before the algorithm removes any constraints.
the code keeps track of the original variables in the problem by using a boolean vector activea
to represent the current constraints (rows) of the a
matrix, and a boolean vector activeaeq
to represent the current constraints of the aeq
matrix. when adding or removing constraints, the code indexes into a
or aeq
so that the row numbers do not change, even though the number of constraints changes.
running this code returns idx2
, a vector of the indices of the nonzero elements in activea
:
idx2 = find(activea)
suppose that var
is a boolean vector that has the same length as idx2
. then
idx2(find(var))
expresses var
as indices into the original problem variables. in this way, the indexing can take a subset of a subset of constraints, work with only the smaller subset, and still unambiguously refer to the original problem variables.
opts = optimoptions('linprog','display',"none"); activea = true(size(b)); activeaeq = true(size(beq)); [~,~,exitflag] = linprog(f,a,b,aeq,beq,lb,ub,opts); ncl = 1; while exitflag < 0 [ineqselastic,eqselastic,ncall] = ... elasticfilter(a(activea,:),b(activea),aeq(activeaeq,:),beq(activeaeq),lb,ub); ncl = ncl ncall; idxaa = find(activea); idxae = find(activeaeq); tmpa = idxaa(find(ineqselastic)); tmpae = idxae(find(eqselastic)); aa = a(tmpa,:); bb = b(tmpa); ae = aeq(tmpae,:); be = beq(tmpae); [ineqs,eqs,ncall] = ... deletionfilter(aa,bb,ae,be,lb,ub); ncl = ncl ncall; activea(tmpa(ineqs)) = false; activeaeq(tmpae(eqs)) = false; disp(['removed inequalities ',int2str((tmpa(ineqs))'),' and equalities ',int2str((tmpae(eqs))')]) [~,~,exitflag] = ... linprog(f,a(activea,:),b(activea),aeq(activeaeq,:),beq(activeaeq),lb,ub,opts); ncl = ncl 1; end
removed inequalities 114 and equalities removed inequalities 97 and equalities removed inequalities 64 82 and equalities removed inequalities 60 and equalities
fprintf('number of linprog calls: %d\n',ncl)
number of linprog calls: 28
notice that the loop removes inequalities 64 and 82 simultaneously, which indicates that these two constraints form an iis.
find maxfs
another approach for obtaining a feasible set of constraints is to find a maxfs directly. as chinneck [1] explains, finding a maxfs is an np-complete problem, meaning the problem does not necessarily have efficient algorithms for finding a maxfs. however, chinneck proposes some algorithms that can work efficiently.
use chinneck's algorithm 7.3 to find a cover set of constraints that, when removed, gives a feasible set. the algorithm is implemented in the generatecover
helper function at the end of this example.
[coversetineq,coverseteq,nlp] = generatecover(a,b,aeq,beq,lb,ub)
coversetineq = 5×1
114
97
60
82
2
coverseteq = []
nlp = 40
remove these constraints and solve the lp.
usemeineq = true(size(b)); usemeineq(coversetineq) = false; % remove inequality constraints usemeeq = true(size(beq)); usemeeq(coverseteq) = false; % remove equality constraints [xs,fvals,exitflags] = ... linprog(f,a(usemeineq,:),b(usemeineq),aeq(usemeeq),beq(usemeeq),lb,ub);
optimal solution found.
notice that the cover set is exactly the same as the iiselastic
set from elastic filter. in general, the elastic filter finds too large a cover set. chinneck's algorithm 7.3 starts with the elastic filter result and then retains only the constraints that are necessary.
chinneck's algorithm 7.3 takes 40 calls to linprog
to complete the calculation of a maxfs. this number is a bit more than 28 calls used earlier in the process of deleting iis in a loop.
also, notice that the inequalities removed in the loop are not exactly the same as the inequalities removed by algorithm 7.3. the loop removes inequalities 114, 97, 82, 60, and 64, while algorithm 7.3 removes inequalities 114, 97, 82, 60, and 2. check that inequalities 82 and 64 form an iis (as indicated in remove iis in a loop), and that inequalities 82 and 2 also form an iis.
usemeineq = false(size(b)); usemeineq([82,64]) = true; ineqs = deletionfilter(a(usemeineq,:),b(usemeineq),aeq,beq,lb,ub); disp(ineqs)
1 1
usemeineq = false(size(b)); usemeineq([82,2]) = true; ineqs = deletionfilter(a(usemeineq,:),b(usemeineq),aeq,beq,lb,ub); disp(ineqs)
1 1
references
[1] chinneck, j. w. feasibility and infeasibility in optimization: algorithms and computational methods. springer, 2008.
[2] chinneck, j. w. "feasibility and infeasibility in optimization." tutorial for cp-ai-or-07, brussels, belgium. available at .
helper functions
this code creates the deletionfilter
helper function.
function [ineq_iis,eq_iis,ncalls] = deletionfilter(aineq,bineq,aeq,beq,lb,ub) ncalls = 0; [mi,n] = size(aineq); % number of variables and linear inequality constraints f = zeros(1,n); me = size(aeq,1); % number of linear equality constraints opts = optimoptions("linprog","algorithm","dual-simplex","display","none"); ineq_iis = true(mi,1); % start with all inequalities in the problem eq_iis = true(me,1); % start with all equalities in the problem for i=1:mi ineq_iis(i) = 0; % remove inequality i [~,~,exitflag] = linprog(f,aineq(ineq_iis,:),bineq(ineq_iis),... aeq,beq,lb,ub,opts); ncalls = ncalls 1; if exitflag == 1 % if now feasible ineq_iis(i) = 1; % return i to the problem end end for i=1:me eq_iis(i) = 0; % remove equality i [~,~,exitflag] = linprog(f,aineq,bineq,... aeq(eq_iis,:),beq(eq_iis),lb,ub,opts); ncalls = ncalls 1; if exitflag == 1 % if now feasible eq_iis(i) = 1; % return i to the problem end end end
this code creates the elasticfilter
helper function.
function [ineq_iis,eq_iis,ncalls,fval0] = elasticfilter(aineq,bineq,aeq,beq,lb,ub) ncalls = 0; [mi,n] = size(aineq); % number of variables and linear inequality constraints me = size(aeq,1); aineq_r = [aineq -1.0*eye(mi) zeros(mi,2*me)]; aeq_r = [aeq zeros(me,mi) eye(me) -1.0*eye(me)]; % two slacks for each equality constraint lb_r = [lb(:); zeros(mi 2*me,1)]; ub_r = [ub(:); inf(mi 2*me,1)]; ineq_slack_offset = n; eq_pos_slack_offset = n mi; eq_neg_slack_offset = n mi me; f = [zeros(1,n) ones(1,mi 2*me)]; opts = optimoptions("linprog","algorithm","dual-simplex","display","none"); tol = 1e-10; ineq_iis = false(mi,1); eq_iis = false(me,1); [x,fval,exitflag] = linprog(f,aineq_r,bineq,aeq_r,beq,lb_r,ub_r,opts); fval0 = fval; ncalls = ncalls 1; while exitflag == 1 && fval > tol % feasible and some slacks are nonzero c = 0; for i = 1:mi j = ineq_slack_offset i; if x(j) > tol ub_r(j) = 0.0; ineq_iis(i) = true; c = c 1; end end for i = 1:me j = eq_pos_slack_offset i; if x(j) > tol ub_r(j) = 0.0; eq_iis(i) = true; c = c 1; end end for i = 1:me j = eq_neg_slack_offset i; if x(j) > tol ub_r(j) = 0.0; eq_iis(i) = true; c = c 1; end end [x,fval,exitflag] = linprog(f,aineq_r,bineq,aeq_r,beq,lb_r,ub_r,opts); if fval > 0 fval0 = fval; end ncalls = ncalls 1; end end
this code creates the generatecover
helper function. the code uses the same indexing technique for keeping track of constraints as the remove iis in a loop code.
function [coversetineq,coverseteq,nlp] = generatecover(aineq,bineq,aeq,beq,lb,ub) % returns the cover set of linear inequalities, the cover set of linear % equalities, and the total number of calls to linprog. % adapted from chinneck [1] algorithm 7.3. step numbers are from this book. coversetineq = []; coverseteq = []; activea = true(size(bineq)); activeaeq = true(size(beq)); % step 1 of algorithm 7.3 [ineq_iis,eq_iis,ncalls] = elasticfilter(aineq,bineq,aeq,beq,lb,ub); nlp = ncalls; ninf = sum(ineq_iis(:)) sum(eq_iis(:)); if ninf == 1 coversetineq = ineq_iis; coverseteq = eq_iis; return end holdsetineq = find(ineq_iis); holdseteq = find(eq_iis); candidateineq = holdsetineq; candidateeq = holdseteq; % step 2 of algorithm 7.3 while sum(candidateineq(:)) sum(candidateeq(:)) > 0 minsinf = inf; ineqflag = 0; for i = 1:length(candidateineq(:)) activea(candidateineq(i)) = false; idx2 = find(activea); idx2eq = find(activeaeq); [ineq_iis,eq_iis,ncalls,fval] = elasticfilter(aineq(activea,:),bineq(activea),aeq(activeaeq,:),beq(activeaeq),lb,ub); nlp = nlp ncalls; ineq_iis = idx2(find(ineq_iis)); eq_iis = idx2eq(find(eq_iis)); if fval == 0 coversetineq = [coversetineq;candidateineq(i)]; return end if fval < minsinf ineqflag = 1; winner = candidateineq(i); minsinf = fval; holdsetineq = ineq_iis; if numel(ineq_iis(:)) numel(eq_iis(:)) == 1 nextwinner = ineq_iis; nextwinner2 = eq_iis; nextwinner = [nextwinnner,nextwinner2]; else nextwinner = []; end end activea(candidateineq(i)) = true; end for i = 1:length(candidateeq(:)) activeaeq(candidateeq(i)) = false; idx2 = find(activea); idx2eq = find(activeaeq); [ineq_iis,eq_iis,ncalls,fval] = elasticfilter(aineq(activea,:),bineq(activea),aeq(activeaeq,:),beq(activeaeq),lb,ub); nlp = nlp ncalls; ineq_iis = idx2(find(ineq_iis)); eq_iis = idx2eq(find(eq_iis)); if fval == 0 coverseteq = [coverseteq;candidateeq(i)]; return end if fval < minsinf ineqflag = -1; winner = candidateeq(i); minsinf = fval; holdseteq = eq_iis; if numel(ineq_iis(:)) numel(eq_iis(:)) == 1 nextwinner = ineq_iis; nextwinner2 = eq_iis; nextwinner = [nextwinnner,nextwinner2]; else nextwinner = []; end end activeaeq(candidateeq(i)) = true; end % step 3 of algorithm 7.3 if ineqflag == 1 coversetineq = [coversetineq;winner]; activea(winner) = false; if nextwinner coversetineq = [coversetineq;nextwinner]; return end end if ineqflag == -1 coverseteq = [coverseteq;winner]; activeaeq(winner) = false; if nextwinner coverseteq = [coverseteq;nextwinner]; return end end candidateineq = holdsetineq; candidateeq = holdseteq; end end
see also
related topics
- (global optimization toolbox)