Average Optimization using GA or intlinprog algorithms

1 vue (au cours des 30 derniers jours)
Mehmet
Mehmet le 16 Mar 2024
Modifié(e) : Torsten le 23 Mar 2024
Guys i need to figure out the algorithm to model a question. Question is here: I have to pickup 30 balls that are in 10 different colors. Number of the balls are in the first column of the input matrice. Only requirement here is i have to pick at least one for each color.Every balls have different numbers of holes and spike on them. These are column 2 and 3 input respectively. I want to solve the problem for min and max average spike count. What is the algorithm here? Intlingprog does not seem to help, used ga solver but it takes about 5 mins. I want to drop the runtime to 10 secs at worst. Thanks!
  1 commentaire
Mehmet
Mehmet le 21 Mar 2024
Modifié(e) : Mehmet le 23 Mar 2024
Let me explain the problem clearly. I asked it as an anology for my real case. If i remember extra constraints that must be met i will edit the code but this is it for now.
a = excel_mat1; % rocks in diff shapes and materials and contain [0,0] row (size 30x3)
b = excel_mat2; % rocks in diff shapes and materials and contain [0,0] row (size 30x3)
c = excel_mat3; % rocks in diff shapes and materials and contain [0,0] row (size 30x3)
d = excel_mat4; % rocks in diff shapes and materials and contain [0,0] row (size 30x3)
e = excel_mat5; % rocks in diff shapes and materials and contain [0,0] row (size 30x3)
f = excel_mat6; % rocks in diff shapes and materials and contain [0,0] row (size 30x3)
g = excel_mat7; % rocks in diff shapes and materials and contain [0,0] row (size 30x3)
h = excel_mat8; % rocks in diff shapes and materials and contain [0,0] row (size 30x3)
i = excel_mat9, % rocks in diff shapes and materials and contain [0,0] row (size 30x3)
j = excel_mat10; % fluid types (size 10x3)
%% [Volume;density;ID] for all
aa = size(a,1);
bb = size(b,1);
cc = size(c,1);
dd = size(d,1);
ee = size(e,1);
ff = size(f,1);
gg = size(g,1);
hh = size(h,1);
ii = size(i,1);
max_bucket_vol = user_defined_value;
%% this bucket has various things whose values are known inside
volume_initial = vol1; %constant volume of materials inside bucket at first
density_initial= den1; %constant density of materials inside bucket at first
number_of_rocks = size([a;b;c;d;e;f;g;h;i],1);
available_fluids = size(j,1);
max_volume_of_available_fluids = j(:,1);
max_weight_of_available_fluids = j(:,1).*j(:,2); %density in second column
ings = [a;b;c;d;e;f;g;h;i];
volume_vector = ings(:,1);
density_vector= ings(:,2);
optchoice = optimproblem;
optrocksol = optimvar('optrocksol',number_of_rocks,'Type','integer','LowerBound',0,'UpperBound',1);
optfluidsol= optimvar('optfluidsol',available_fluids,'LowerBound',0,'UpperBound',1);
optchoice.Objective = (sum(optrocksol.*volume_vector.*density_vector)+sum(optfluidsol.*max_weight_of_available_fluids)+vol1*den1)...
/(sum(optrocksol.*volume_vector)+sum(optfluidsol.*j(:,1)+vol1);
optchoice.Constraints.s0 = sum(optrocksol.*volume_vector)+sum(optfluidsol.*j(:,1)+vol1 <= max_bucket_vol;
optchoice.Constraints.s1 = sum(optrocksol(1:aa)) == 1;
optchoice.Constraints.s2 = sum(optrocksol(aa+1:aa+bb)) == 1;
optchoice.Constraints.s3 = sum(optrocksol(aa+bb+1:aa+bb+cc)) == 1;
optchoice.Constraints.s4 = sum(optrocksol(aa+bb+cc+1:aa+bb+cc+dd)) == 1;
optchoice.Constraints.s5 = sum(optrocksol(aa+bb+cc+dd+1:aa+bb+cc+dd+ee)) == 1;
optchoice.Constraints.s6 = sum(optrocksol(aa+bb+cc+dd+ee+1:aa+bb+cc+dd+ee+ff)) == 1;
optchoice.Constraints.s7 = sum(optrocksol(aa+bb+cc+dd+ee+ff+1:aa+bb+cc+dd+ee+ff+gg)) == 1;
optchoice.Constraints.s8 = sum(optrocksol(aa+bb+cc+dd+ee+ff+gg+1:aa+bb+cc+dd+ee+ff+gg+hh)) == 1;
optchoice.Constraints.s9 = sum(optrocksol(aa+bb+cc+dd+ee+ff+gg+hh+1:aa+bb+cc+dd+ee+ff+gg+hh+ii)) == 1;
s = solve(optchoice); % solving for most dense or least dense bucket for defined max volume

Connectez-vous pour commenter.

Réponses (2)

Torsten
Torsten le 16 Mar 2024
  9 commentaires
Mehmet
Mehmet le 23 Mar 2024
I added the real problem. Yeah that formula was compromising but not sufficient to simulate the case.
Torsten
Torsten le 23 Mar 2024
Modifié(e) : Torsten le 23 Mar 2024
Then you will either use "ga" right from the beginning or start "ga" from a solution obtained by "intlinprog" that will be at least feasible and where the objective is a linear approximation of the nonlinear "average function".
Just out of interest: How large is aa*bb*cc*...*ii ?

Connectez-vous pour commenter.


John D'Errico
John D'Errico le 20 Mar 2024
This is not an optimization problem. You only look at it in that way. It is purely a problem of a Monte Carlo simulation, to compute the distribution of average spike count. It sounds like you want min and max.
You need to choose 30 balls, from 10 different colors. The only requirement as you state is that you need to choose at least ONE of each color. The solution seems simple. Choose ONE of each color ball FIRST. Remove them from the set of unchosen balls.
Having done that, now you need to choose 20 more balls, but there is no constraint on them. So choose randomly from those that remain.
Now just compute the desired information on that chosen set. Repeat as many times as you wish. The above scheme can be done in a tiny fraction of a second, not minutes, or even seconds.
If this does not solve your problem, then you need to explain what in your question was incomplete.
  2 commentaires
Mehmet
Mehmet le 23 Mar 2024
I added the real problem.
John D'Errico
John D'Errico le 23 Mar 2024
Sorry. I cannot/will not chase a moving target, especially one that is highly likely to continue its rapid motion. I've left my answer because it does answer the question you initially posed.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Linear and Nonlinear Regression dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by