How can I implement a constraint on any subset of columns in a matrix optimisation variable?

1 ビュー (過去 30 日間)
I am attempting to construct an optimisation problem using the problem based solver approach, and I am having difficulty formulating one specific constraint to the problem.
A simplified version of my optimisation problem is below - I have additional constraints but I have removed them to highlight my issue more clearly. I am summing the result of the optimisation variable x, and then subtracting a 1x50 array y which values correspond to each column in x.
lb = zeros(144,50);
ub = 7*ones(144,50);
prob = optimproblem('ObjectiveSense','maximize');
x = optimvar('x',144,50,'Type','continuous','LowerBound',lb,'UpperBound',ub);
% The objective doesn't really matter as I am using the optimisation to test the feasibility of a set of inputs
prob.Objective = sum(ones(1,144)*x);
result = sum(x,1) - y; % y is 1x50 array
result is non-negative. However, I want to add a constraint on x that means that at least a certain number, say 10, values in result are equal to zero. I want it so that any of the values in result can be 0, it does not have to be the first 10, however I want to make sure that at least 10 values are equal to 0. Such as:
prob.Constraint.cons1 = sum(result==0) >= 10;
However, Matlab produces an error when I try to implement this - saying that sum can only be used on numerical or logical values, and as result is an optimisation expression it cannot be used. I am also not sure whether the syntax of result==0 is valid in this context.
Can anyone help me formulate this constraint in a way that is accepted by the solver? Please let me know if anything is unclear.
Many Thanks!


Alan Weiss
Alan Weiss 2021 年 11 月 24 日
You need to use some of the ideas in Integer and Logical Modeling. Create an auxiliary binary variable tf the same size as result. This variable allows you to create the expression
consval = sum(tf) <= 40; % or whatever constraint makes sense for you
You need to have the tf variable be equal to 1 exactly when result is equal to 1. You do this using big-M formulations.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
  1 件のコメント
Huw Thomas
Huw Thomas 2021 年 11 月 24 日
Thank you! Looks like it could be more complex than I first imagined, thanks I will have to get my head around the link you provided.


その他の回答 (0 件)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by