How to avoid repmat in problem-based optimization?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Matt J
2020-8-28
编辑:Matt J
2020-8-28
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with Optimization Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!