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 commentaires

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 :/

Connectez-vous pour commenter.

 Réponse acceptée

Matt J
Matt J le 31 Déc 2019
Modifié(e) : Matt J le 31 Déc 2019
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 commentaires

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?

Connectez-vous pour commenter.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 31 Déc 2019
Modifié(e) : Walter Roberson le 31 Déc 2019
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 commentaire

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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Linear Programming and Mixed-Integer Linear Programming dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by