how to use parfor for optim constraints?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I'm using optimisation toolbox ver 9.3 and have parallel computing toolbox 7.6
I have a lot of constraints equations to write and formulation only will take a lot of time. Many equations are in 3 nested loops .
I'm writing one of the equation.
y_uij and x_uij are binary variable already been defined. Nodes.all and flight_name_set_0 are in string format. flight_set_0 is an array of structure.
how would you suggest to write such that I can use parfor to speed up the formulation.
y1 = optimconstr(Nodes.all, flight_name_set_0, flight_name_set_0);
for n = 1:length(Nodes.all)
u = Nodes.all(n);
for f1 = 1:length(flight_set_0)
i = flight_set_0(f1).name;
for f2 = 1:length(flight_set_0)
j = flight_set_0(f2).name;
common_node = any(ismember(flight_set_0(f1).nodes,u)) & any(ismember(flight_set_0(f2).nodes,u));
if (f1 ~= f2) && common_node
y1(u,i,j) = y_uij(u,i,j) >= x_uij(u,i,j);
end
end
end
end
0 comentarios
Respuestas (1)
Alan Weiss
el 22 de Dic. de 2022
Unfortunately, your version of Optimization Toolbox does not have the latest upgrade which uses "static analysis" to speed the creation of optimization expressions and constraints. To see the potential benefit to upgrading, see Static Analysis of Optimization Expressions, Create for Loop for Static Analysis, and Convert Constraints in for Loops for Static Analysis.
I don't mean to sound like I'm selling an upgrade, it is just that the latest software addresses exactly your issue.
Meanwhile, perhaps it is possible for you to vectorize your expressions to eliminate some for loops. I don't immediately see how to do that for your loops, but that is the thing that might speed things up enormously. For an example where I used a vectorized call to eliminate one nesting level of for loops, see Constrained Electrostatic Nonlinear Optimization Using Optimization Variables, in particular the section Define Objective Function.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
2 comentarios
Alan Weiss
el 23 de Dic. de 2022
No, the benefits to using external for lops in static analysis apply to all solvers, including intlinprog.
Alan Weiss
MATLAB mathematical toolbox documentation
Ver también
Categorías
Más información sobre Problem-Based Optimization Setup en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!