How to add to the code a transporation cost and a possibility of producing for e
ID: 3581884 • Letter: H
Question
How to add to the code a transporation cost and a possibility of producing for exporting??
{string} Products = ...;
int NbMonths = ...;
range Months = 1..NbMonths;
float Cost[Months][Products] = ...;
dvar float+ Produce[Months];
dvar float+ Use[Months][Products];
dvar float+ Buy[Months][Products];
dvar float Store[Months][Products] in 0..1000;
maximize
sum( m in Months )
(150 * Produce[m]
- sum( p in Products )
Cost[m][p] * Buy[m][p]
- 5 * sum( p in Products )
Store[m][p]);
subject to {
forall( p in Products )
ctStore:
Store[NbMonths][p] == 500;
forall( m in Months ) {
ctUse1:
Use[m]["v1"] + Use[m]["v2"] <= 200;
ctUse2:
Use[m]["o1"] + Use[m]["o2"] + Use[m]["o3"] <= 250;
ctUse3:
3 * Produce[m] <=
8.8 * Use[m]["v1"] + 6.1 * Use[m]["v2"] +
2 * Use[m]["o1"] + 4.2 * Use[m]["o2"] + 5 * Use[m]["o3"];
ctUse4:
8.8 * Use[m]["v1"] + 6.1 * Use[m]["v2"] +
2 * Use[m]["o1"] + 4.2 * Use[m]["o2"] + 5 * Use[m]["o3"]
<= 6 * Produce[m];
ctUse5:
Produce[m] == sum( p in Products ) Use[m][p];
}
forall( m in Months )
forall( p in Products ) {
ctUse6:
if (m == 1) {
500 + Buy[m][p] == Use[m][p] + Store[m][p];
}
else {
Store[m-1][p] + Buy[m][p] == Use[m][p] + Store[m][p];
}
}
};
execute DISPLAY {
writeln(" Maximum profit = " , cplex.getObjValue());
for (var i in Months) {
writeln(" Month ", i, " ");
write(" . Buy ");
for (var p in Products)
write(Buy[i][p], " ");
writeln();
write(" . Use ");
for (p in Products)
write(Use[i][p], " ");
writeln();
write(" . store ");
for (p in Products)
write(Store[i][p], " ");
writeln();
}
}
Explanation / Answer
{string} Products = ...;
int NbMonths = ...;
range Months = 1..NbMonths;
float Cost[Months][Products] = ...;
dvar float+ Produce[Months];
dvar float+ Use[Months][Products];
dvar float+ Buy[Months][Products];
dvar float Store[Months][Products] in 0..1000;
dexr float+ transcost=sum(m in months )
sum(p in products)cost[m][p]-sum(m in months) produce[m];
maximize
sum( m in Months )
(150 * Produce[m]
- sum( p in Products )
Cost[m][p] * Buy[m][p]
- 5 * sum( p in Products )
Store[m][p]);
subject to {
forall( p in Products )
ctStore: Store[NbMonths][p] == 500;
forall( m in Months ) {
ctUse1: Use[m]["v1"] + Use[m]["v2"] <= 200;
ctUse2: Use[m]["o1"] + Use[m]["o2"] + Use[m]["o3"] <= 250;
ctUse3: 3 * Produce[m] <=8.8 *Use[m]["v1"] + 6.1 *Use[m]["v2"] +2*Use[m]["o1"] + 4.2 *Use[m]["o2"] + 5 *Use[m]["o3"];
ctUse4: 8.8 * Use[m]["v1"] + 6.1 * Use[m]["v2"] +2* Use[m]["o1"] + 4.2 * Use[m]["o2"] + 5 * Use[m]["o3"]<= 6 * Produce[m];
ctUse5: Produce[m] == sum( p in Products ) Use[m][p];
}
forall( m in Months )
forall( p in Products ) {
ctUse6:
if (m == 1) {
500 + Buy[m][p] == Use[m][p] + Store[m][p];
}
else {
Store[m-1][p] + Buy[m][p] == Use[m][p] + Store[m][p];
}
}
};
execute DISPLAY {
writeln("transport cost of the produced products= ",transcost);
writeln(" Maximum profit = " , cplex.getObjValue());
for(m in months)
writeln("monthwise Production: ",produce[m]);
for (var i in Months) {
writeln(" Month ", i, " ");
write(" . Buy ");
for (var p in Products)
write(Buy[i][p], " ");
writeln();
write(" . Use ");
for (p in Products)
write(Use[i][p], " ");
writeln();
write(" . store ");
for (p in Products)
write(Store[i][p], " ");
writeln();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.