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 件のコメント

Matt J
Matt J 2019 年 12 月 31 日
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!
Walter Roberson
Walter Roberson 2019 年 12 月 31 日
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?
Julio Cesar Franco Ardila
Julio Cesar Franco Ardila 2019 年 12 月 31 日
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 件のコメント

Julio Cesar Franco Ardila
Julio Cesar Franco Ardila 2019 年 12 月 31 日
I have a question please, if I use ga() to solve this model, x is going to represent all the decision variables?
Thanks
Matt J
Matt J 2019 年 12 月 31 日
編集済み: Matt J 2019 年 12 月 31 日
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.
Walter Roberson
Walter Roberson 2019 年 12 月 31 日
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.
bassant tolba
bassant tolba 2022 年 11 月 5 日
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.
Walter Roberson
Walter Roberson 2022 年 11 月 5 日
編集済み: Walter Roberson 2022 年 11 月 5 日
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 件のコメント

Matt J
Matt J 2019 年 12 月 31 日
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