How to use an optimization expression if in a function?

4 Ansichten (letzte 30 Tage)
Diego Cecchinato
Diego Cecchinato am 17 Jul. 2020
Bearbeitet: Diego Cecchinato am 20 Jul. 2020
Hi everyone!
I'm new to Matlab and i'm trying to write a function that is used in a problem based optimization.
This is the code that i wrote:
function [array] = getmax (matrix)
row = size(matrix,1);
column = size(matrix,2);
array = optimexpr;
for i=1:1:row
maxr = 0;
for j=1:1:column
if matrix(i,j) >= maxr
maxr = matrix(i,j)
end
end
array(i,1) = maxr;
end
end
Matrix is an optimization expression (es. 4 row and 5 column)
Array is the optimization expression that i want to get as the result of the function. (in this example it should be 4 row 1 column with tha max value of each matrix's row).
If i run this code i get "Conversion to logical from optim.problemdef.OptimizationInequality is not possible" in the if line.
I read about the big-M method, but i can't apply that method to my problem. (There's a lot about the big-M method for constrain but not a lot for function).
Can someone help me? I think it's a very simple function but i'm a newbie :(
Thanks

Akzeptierte Antwort

Matt J
Matt J am 17 Jul. 2020
You cannot express such an operation through the problem-based framework. If you are trying to solve a minimax problem, then you should use fminimax()
  1 Kommentar
Diego Cecchinato
Diego Cecchinato am 20 Jul. 2020
Bearbeitet: Diego Cecchinato am 20 Jul. 2020
Thank you Matt J.
You made me save lot of time.
I try to explain my problem, maybe if you want to read you can give me some good advices.
I'm trying to solve a Warehouse allocation problem.
I have n components, n locations and m kits (n>m).
A kit is a group of code.
The binary array "Kitconfig" (m*n) tells which components is part of the kit (see the image to undestand).
I also have two other array:
  • Distance (1*n) with the distance of every location to a specific point
  • Qnt (1*m) with the quantity request every year for each kit
In reality workers will receive the list of components that make up the kit; then they will reach the location associated with the components and they will pick them up.
The objective function i want to minimize is the total distance travelled in a year.
The decision variable x is a binary array (n*n) with 1 if the cod is associated with the location. (something like this:)
(as you can see a location is associated with only one component, and every component is associated with only one location).
Total Distance = qnt * Dkit (for every kit)
Dkit = // distance of most far component that is part of the kit// (<- this is what i was trying to get with the function i describe previously).
Dcod = x*Distance (for every components)
I hope you understand my problem, i tried to explain it as simple as possible.
Do you think i can solve this with Matlab? It's a problem based optimization or a minmax problem? Every advice will be appreciate :)
Thanks in advance for your help. (I will certainly mention you in the thanks of my degree thesis).

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by