Effacer les filtres
Effacer les filtres

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?

5 vues (au cours des 30 derniers jours)
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 commentaire
Walter Roberson
Walter Roberson le 15 Nov 2017
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]

Connectez-vous pour commenter.

Réponses (1)

Yogananda Jeppu
Yogananda Jeppu le 11 Nov 2017
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 commentaires
Walter Roberson
Walter Roberson le 15 Nov 2017
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"

Connectez-vous pour commenter.

Catégories

En savoir plus sur Multivariate Models dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by