# Several Questions about the result and speed of optimization

1 post / 0 new
wor5113
Offline
Joined: 2017-08-25
Several Questions about the result and speed of optimization

Hi, I'm new to JModelica and python. lately I am using this to process some static optimization questions.The origin code is

model TwoForce

Real fk[2,3];

Modelica.SIunits.Torque Tao_ori[2];

input Real F_total[3];

input Real jacobian[2,3];

parameter Modelica.SIunits.Torque Tao_max = 5;

input Real n[3];

end TwoForce;

optimization TwoOp (objective=(fk[1,1]+fk[2,1]-F_total[1])^2+(fk[1,2]+fk[2,2]-F_total[2])^2+(fk[1,3]+fk[2,3]-F_total[3])^2,static=true)

extends TwoForce(Tao_ori={1,1},jacobian={{1,1,1},{1,1,1}},n={0,1,0});

constraint

jacobian[1,1:3]*fk[1,1:3] <= Tao_max-Tao_ori1];

jacobian[2,1:3]*fk[2,1:3] <= Tao_max+Tao_ori[2] ;

fk[1,1:3]*n[1:3] >=0;

fk[2,1:3]*n[1:3] >=0;

end TwoOp;

By using this ,I do the optimization,and the time cost of solution is 0.48s, but when I change the optimization into

optimization opt (objective=(x[1,1]+x[2,1])^2+(x[1,2]+x[2,2]-5)^2+(x[1,3]+x[2,3])^2,static=true)
Real x[2,3];
constraint
x[1,1]+x[1,2]+x[1,3] <=4;
x[2,1]+x[2,2]+x[2,3]<=4;
x[1,2]>=0;
x[2,2]>=0;
end opt;

the time cost of solution is just 0.07s.

So how can I speed up the first optimization？

Besides that , when I use python to get the result of optimization, for examle fk[1,1].I will get a vector with maybe 150 elements but not just one. How to solve this problem?