I have an optimization problem where i need to minimize the Total_Cost. I have the equations in AMPL format and i need to convert it to MATLAB. Can anybody help and correct my answer?
조회 수: 2 (최근 30일)
이전 댓글 표시
This is the first equation in AMPL:
minimize Total_Cost:
sum {i in CONTROLLER} kappa_c[i] *
sum {j in LOCATION} tcn[i, j]
*tcn is a binary variable
This is after i tried convert it to MATLAB form:
% these values are given%
CONTROLLER = 9;
kappa_c = {1,2,3,4,5,6,7,8,9};
LOCATION = 9;
sum = 0;
for i = 1:CONTROLLER
sum = sum + kappa_c{i};
sum1 = 0;
for j = 1:LOCATION
sum1 = sum1 + tcn{i;j};
end
ans1 = sum1 * sum ;
end
display(ans1)
댓글 수: 1
Walter Roberson
2017년 11월 15일
Your AMPL definition uses j as the loop control variable twice, and uses the undefined variable i . Your translation of it into MATLAB would be for the slightly different
minimize Total_Cost:
sum {i in CONTROLLER} kappa_c[i] *
sum {j in LOCATION} tcn[i, j]
답변 (1개)
Yogananda Jeppu
2017년 11월 11일
sum1 = sum1 + tcn{i;j}; The ';' should be perhaps a ','. It is easier if you can represent as a matrix with [] square brackets. Use the sum function in matlab and .* to multiply elements instead of matrices.
댓글 수: 9
Walter Roberson
2017년 11월 15일
tcn = randi([0 1], 9, 9);
If none of the entries are negative, then the tcn that minimizes will always be the all-zero tcn, which would give a cost of 0. With no negative entries it is not possible for the cost to be below 0, so all-zero minimizes.
The exception to this is if you have constraints such as "at least 2 locations must be turned on for each controller"
참고 항목
카테고리
Help Center 및 File Exchange에서 Multivariate Models에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!