- Index
- » Users
- » florian-d
- » Profile
Posts
Posts
Hi ! I am working on an optimization problem with OpenModelica and Optimica and I would like the number of optimization variables to be flexible. I tried to use a for loop to do it but OMedit crashes when I use the for loop instead of the "non for loop expression". Do you have any idea where does the problem come from ?
Best,
Florian
code below :
**************************
model optim_debug2
Real totalCost annotation(isMayer = true);
parameter Integer nb_variables=3; //number of optimization variables
input Real x[nb_variables](each min=0,each max=1); //array of optimization variables
Real power_input[nb_variables];
Real power_output;
algorithm
power_output:=0;
power_input[1]:=20;
power_input[2]:=10;
power_input[3]:=5;
power_output:=x[1]*power_input[1]+x[2]*power_input[2]+x[3]*power_input[3];
/*for i in 1:nb_variables loop
power_output:=power_output+x[i]*power_input[i];
end for;*/
//Problem : OMedit crashes when trying to replace line 18 (power_output:=x[1]...) by for loop (lines 21-23)
totalCost:=(power_output-22)^2; //the objective is to obtain power_output=22
annotation(experiment(StartTime = 0, StopTime = 1, Tolerance = 1e-07, Interval = 1),
__OpenModelica_simulationFlags(s="optimization", optimizerNP="1"),
__OpenModelica_commandLineOptions="+g=Optimica");
end optim_debug2;
*********************
- Index
- » Users
- » florian-d
- » Profile