フィルターのクリア

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?

3 ビュー (過去 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
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
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
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"
Amerul Rosle
Amerul Rosle 2017 年 11 月 15 日
Thank you Walter, much appreciated.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by