Optimization With Genetic Algorithm. Could not define objective Function!
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello everyone,
I am working on a project where i do maximization. I m having trouble with genetic algorithm solver. It is my first time to use both genetic algorithm solver and MATLAB! I have done my research but could not solve a few problems i have. So here are my questions and problems:
1: My problem is an indexed problem where i have multiple matrices (36x36) and my decision variable is x is also a matrix (36x36) so i have 1296 decision variables! I have learned that the solver excepts a vector and gives scalar output. And it is okey But further in the constraints section i need decision variables as a matrix so i can write my constraints. ( Because they also have summation operation).
2: another point is that i have another decsision variable which is not in the objective function directly but in the constraints. This variable is dependent to the x variable. Where the column summation of x is equal to y(j). So i need my x's to be a matrix not an row vector.
3: My objective function does not works! If i just write my variables and parameters as a row vector it gives' not enough input argument error' ! But if i wirte them as matrix's with dimensions 36x36 it gives 'Index in poisiton 1 exceeds array bounds. Index must not exceed 1' error. Just unable to do it right!!!
4: Also my decsision variable should be binary (1 or 0). I have searched this topic but couldnt find any useful information sadly.
Any solution suggestions and opinions are welcome. The file will be attached! Thank you in advance,
Best,
Beyza.
0 Commenti
Risposte (2)
Matt J
il 20 Mar 2022
Modificato: Matt J
il 20 Mar 2022
1: But further in the constraints section i need decision variables as a matrix so i can write my constraints. ( Because they also have summation operation).
You are free to reshape() your variables and/or assign them to separate variables within inside the body of your objective and nonlinear constraint functions.
2: another point is that i have another decsision variable which is not in the objective function directly but in the constraints. This variable is dependent to the x variable. Where the column summation of x is equal to y(j). So i need my x's to be a matrix not an row vector.
x and y must be concatenated together and organized as a row vector when passed to your obejctive and constraints, but again, you can reshape and reorganize them any way you wish inside the workspace of those functions.
3: My objective function does not works! If i just write my variables and parameters as a row vector it gives' not enough input argument error' ! But if i wirte them as matrix's with dimensions 36x36 it gives 'Index in poisiton 1 exceeds array bounds. Index must not exceed 1' error. Just unable to do it right!!!
Your functions should have only one input argument, a row vector containing both x and y.
4: Also my decsision variable should be binary (1 or 0). I have searched this topic but couldnt find any useful information sadly.
Use the intcon input argument to force certain variables to be integers. Use the lb and ub argument to force them to lie between 0 and 1.
Burhan Burak AKMAN
il 20 Mar 2022
Hello,
I try solve your problem. I detected problem int the your local functions. Because dimensions of xij,rij and ai is not same,
xij is 1x1296, rij is 36x36 and ai is 36x1 so that function give error. So that I changed you objective funtion at line 140 like below code. After that code is running.
function z = objectivefunc(xij,rij,ai)
% wanna sum x*r*aii for each i and j indices. So there is double summation
% here. The answer i want is around 5k-6k.
for i = 36
for j = 1:36
z = (-1)*(xij(36*i+j-36)*rij(i,j)*ai(i,1));
end
end
end
Vedere anche
Categorie
Scopri di più su Genetic Algorithm in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!