How to avoid repmat in problem-based optimization?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Abdolkarim Mohammadi
el 28 de Ag. de 2020
Comentada: Abdolkarim Mohammadi
el 28 de Ag. de 2020
I am using the problem-based workflow of the Optimization toolbox for solving a MILP problem. Variables x's size is 1xn.
x = optimvar ('x', [1,n]);
Matrix D's size is mxn. I want to create efficient problem-based optimization problem (described here) by avoiding for loops and defining equations in a vectorized fashion. I used either of the following:
Eq1 = D .* x <= 1;
and
Eq1 = x .* D <= 1;
And got the following error.
% Argument dimensions 20-by-3 and 1-by-3 must agree.
It seems like the problem-based optimization setup does not support automatic expansion of optimization variables, and I had to manually expand x for the program to work:
Eq1 = D .* repmat(x,[m,1]) <= 1;
My question is that, although I was able to solve the problem, is there a way to do define such equations without explicit expansion? Like what MATLAB does for doubles.
Thanks in advance.
0 comentarios
Respuestas (1)
Matt J
el 28 de Ag. de 2020
Editada: Matt J
el 28 de Ag. de 2020
You can do things like,
Eq1 = D.*(ones(m,1)*x)<= 1;
I don't think it will matter much, though. The use of the problem-based framework is itself inefficient, and the use of repmat will probably just be an extra drop in the bucket.
If you really care about maximizing efficiency, you would set up the optimization directly in solver form. The problem-based framework is really just a convenient conversion tool, allowing you to set-up the problem with more intuitive syntax. Ultimately, everything gets translated into solver-based form, so it will be more but efficeint if you just set the problem up directly in the solver-based domain yourself.
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!