Add optimization constraint using the maximum value of decision variables

Hi, I need to add the following optimization constraint:
Const.png
Where D_ij is a constant matrix and X_ij is a decision variable matrix.
I tried using:
max(D.*X,[],1)
but its output was :
Error using max
Invalid data type. First argument must be numeric or logical.
Does anyone know how to include it, please?
Thank you.

댓글 수: 4

More context is needed. What code was used to generate X and D?
Sure:
% Create a new model
prob = optimproblem;
% Create variables
X = optimvar('X', n, v,'Type','integer','LowerBound',0,'UpperBound',1);
W = optimvar('W', v,'Type','integer','LowerBound',0,'UpperBound',1);
M = optimvar('M', v,'Type','integer','LowerBound',0);
Z = optimvar('Z', p, v, v,'Type','integer','LowerBound',0,'UpperBound',1);
R = optimvar('R', v,'Type','integer','LowerBound',0);
N = optimvar('N', v,'Type','integer','LowerBound',0);
De = optimvar('De', v,'Type','integer','LowerBound',0);
% Set objective
prob.Objective = (C_T*sum(sum(X,2).*d) + ...
F_h * sum(W) + ...
C_LEV * sum(M) + ...
C_T * sum(sum(reshape(sum(Z,1),[v,v]).*D)));
D is the matrix representing the distance between clients and hubs. D in R^(n,v)
Thanks!
I see you define an optimization variable R, and I see that you appear to be wanting to constrain R, but I do not see you use R anywhere?
R is used in other restriction:
R.png
This constraint is the 'difficult part' of the model, but I didn't imagine that it was difficult to implement the max restriction :/

댓글을 달려면 로그인하십시오.

 채택된 답변

Matt J
Matt J 2019년 12월 31일
편집: Matt J 2019년 12월 31일

1 개 추천

Your constraints are outside the scope of what the problem-based solver can handle. You will probably need to resort to ga(), which gives you a lot more freedom in the form of objectives and constraints that can be processed.

댓글 수: 5

I have a question please, if I use ga() to solve this model, x is going to represent all the decision variables?
Thanks
You must write objective and nonlinear constraint functions that accept a single input vector containing all of your decision variables concatenated together. You can, of course, unpack the vector into separate, more convenient vectors inside the code for these functions.
You must also supply matrices Aineq,bineq,Aeq,beq to implement any linear in/equality constraints that you have,
Aineq*x<=bineq
Aeq*x=beq
where again x is understood to be a column vector containing all the unknowns in the problem.
Yes.
Note: if you try to use intcon with ga then you will be pretty restricted as to what constraints you can add. This is because ga implements integer constraints by using the constraint and crossover and mutation and creation functions. The only logic that ga has for integer constraints is checking to make sure that you did not try to override those functions, and injecting appropriate functions in and calling the solvers.
Thank you for your reply.
Please, I have the same problem.
can you please clarify what exactly Should be replaced in the above maximization equation to git rid of the above code.? I will be very grateful for your help.
Do you have exactly the same max(Dij.Xij) optimization? With the same R constraint?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2019년 12월 31일
편집: Walter Roberson 2019년 12월 31일

0 개 추천

max() is not a supported operation on optimization variables or in forming optimization constraints.
In order to implement what you want, you will need to use solver based optimization and non-linear equality constraints (and possibly non-linear inequality constraints for other variables.)

댓글 수: 1

And you will need to use a differentiable approximation to the max() operator, e.g., the softmax function
That's assuming you pursue a solution with fmincon. Global Optimization toolbox solvers like ga() and patternsearch() don't care.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by