How to avoid repmat in problem-based optimization?

조회 수: 1 (최근 30일)
Abdolkarim Mohammadi
Abdolkarim Mohammadi 2020년 8월 28일
댓글: Abdolkarim Mohammadi 2020년 8월 28일
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.

답변 (1개)

Matt J
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.
  댓글 수: 1
Abdolkarim Mohammadi
Abdolkarim Mohammadi 2020년 8월 28일
Thanks Matt. You are right. I have been using the solver-based in the past years. I have been recently into the problem-based approach and I found it quite useful, especially for colleagues with less experience to have all of our works right in MATLAB. GAMS' gdxmrw is very useful but problem-based optimization can help have many functionalities here. I thought I am doing something wrong by using repmat since I expected the regular automatic array expansion to work here.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Get Started with Optimization Toolbox에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by