2025-05-24 23:22:59 +02:00
|
|
|
int numberOfMachineTypes = ...;
|
|
|
|
|
int numberOfMonths = ...;
|
|
|
|
|
int numberOfProductsTypes = ...;
|
2025-05-24 17:15:34 +02:00
|
|
|
|
2025-05-24 23:22:59 +02:00
|
|
|
int numberOfHoursInFactory = ...;
|
|
|
|
|
int numberOfScenarios = ...;
|
2025-05-24 17:15:34 +02:00
|
|
|
|
2025-05-24 23:22:59 +02:00
|
|
|
{int} machines = asSet(1..numberOfMachineTypes);
|
|
|
|
|
{int} months = asSet(1..numberOfMonths);
|
|
|
|
|
{int} products = asSet(1..numberOfProductsTypes);
|
|
|
|
|
{int} scenarios = asSet(1..numberOfScenarios);
|
2025-05-24 17:15:34 +02:00
|
|
|
|
|
|
|
|
int machineCount[machines] = ...;
|
2025-05-24 23:22:59 +02:00
|
|
|
float timeToProduce[machines][products] = ...;
|
|
|
|
|
int maxProductsInMonth[months][products] = ...;
|
2025-05-24 17:15:34 +02:00
|
|
|
|
|
|
|
|
int storageMax[products] = ...;
|
|
|
|
|
int storageCost = ...;
|
|
|
|
|
int storageStart[products] = ...;
|
|
|
|
|
|
|
|
|
|
int mu[products] = ...;
|
|
|
|
|
int sigma[products][products] = ...;
|
|
|
|
|
|
|
|
|
|
float sellProfit[scenarios][products] = ...;
|
|
|
|
|
|
2025-05-25 14:53:18 +02:00
|
|
|
float minimalAverageProfit = ...;
|
2025-05-24 17:15:34 +02:00
|
|
|
|
2025-05-24 23:54:18 +02:00
|
|
|
dvar int produce[months][products];
|
|
|
|
|
dvar int sell[months][products];
|
|
|
|
|
dvar int stock[months][products];
|
2025-05-24 17:15:34 +02:00
|
|
|
|
|
|
|
|
dvar float workTime[months][machines][products];
|
|
|
|
|
|
|
|
|
|
dvar boolean if80prec[months][products];
|
|
|
|
|
|
|
|
|
|
dvar float lowerProfit[scenarios][months][products];
|
|
|
|
|
|
|
|
|
|
dexpr float profit[i in scenarios] = sum(m in months, p in products)
|
|
|
|
|
(sell[m][p]*sellProfit[i][p]-lowerProfit[i][m][p]- stock[m][p]*storageCost);
|
|
|
|
|
|
2025-05-24 23:54:18 +02:00
|
|
|
dexpr float averageProfit = sum(i in scenarios)(profit[i])/numberOfScenarios;
|
2025-05-24 17:15:34 +02:00
|
|
|
|
|
|
|
|
dexpr float risk[i in scenarios] = sum (t in scenarios) (
|
2025-05-24 23:22:59 +02:00
|
|
|
0.5 * abs(profit[i] - profit[t]) * 1/numberOfScenarios
|
2025-05-24 17:15:34 +02:00
|
|
|
);
|
|
|
|
|
|
2025-05-24 23:54:18 +02:00
|
|
|
dexpr float riskMeasureGini = sum (t1 in scenarios, t2 in scenarios ) (
|
2025-05-24 23:22:59 +02:00
|
|
|
0.5 * abs(profit[t1] - profit[t2]) * 1/numberOfScenarios * 1/numberOfScenarios
|
2025-05-24 17:15:34 +02:00
|
|
|
);
|
|
|
|
|
|
2025-05-24 23:54:18 +02:00
|
|
|
maximize averageProfit;
|
2025-05-24 17:15:34 +02:00
|
|
|
|
|
|
|
|
subject to {
|
|
|
|
|
forall(i in scenarios, m in months, mc in machines, p in products) {
|
|
|
|
|
workTime[m][mc][p] >= 0;
|
|
|
|
|
produce[m][p] >= 0;
|
|
|
|
|
sell[m][p] >= 0;
|
|
|
|
|
stock[m][p] >= 0;
|
|
|
|
|
lowerProfit[i][m][p] >= 0;
|
|
|
|
|
}
|
|
|
|
|
forall(m in months, mc in machines) {
|
2025-05-24 23:22:59 +02:00
|
|
|
sum(p in products) (workTime[m][mc][p]) <= (machineCount[mc]*numberOfHoursInFactory);
|
2025-05-24 17:15:34 +02:00
|
|
|
}
|
|
|
|
|
forall(m in months, p in products, mc in machines) {
|
2025-05-24 23:22:59 +02:00
|
|
|
workTime[m][mc][p] == produce[m][p]*timeToProduce[mc][p];
|
2025-05-24 17:15:34 +02:00
|
|
|
}
|
|
|
|
|
forall(m in months, p in products) {
|
2025-05-24 23:22:59 +02:00
|
|
|
sell[m][p] <= maxProductsInMonth[m][p];
|
2025-05-24 17:15:34 +02:00
|
|
|
}
|
|
|
|
|
forall(m in months, p in products) {
|
2025-05-24 23:22:59 +02:00
|
|
|
sell[m][p] <= 0.8*maxProductsInMonth[m][p] + 1000000 * if80prec[m][p];
|
|
|
|
|
sell[m][p] >= 0.8*maxProductsInMonth[m][p] * if80prec[m][p];
|
2025-05-24 17:15:34 +02:00
|
|
|
}
|
|
|
|
|
forall (i in scenarios,m in months, p in products) {
|
|
|
|
|
lowerProfit[i][m][p] <= 1000000 * if80prec[m][p];
|
|
|
|
|
lowerProfit[i][m][p] <= 0.2 * sell[m][p]*sellProfit[i][p];
|
|
|
|
|
0.2 * sell[m][p]*sellProfit[i][p] - lowerProfit[i][m][p] + 1000000 * if80prec[m][p] <= 1000000;
|
|
|
|
|
}
|
|
|
|
|
forall(m in months, p in products) {
|
|
|
|
|
if(m == 1) { //pierwszy miesiac
|
|
|
|
|
sell[m][p] <= produce[m][p]+storageStart[p];
|
|
|
|
|
stock[m][p]==(produce[m][p] + storageStart[p])-sell[m][p];
|
|
|
|
|
}else { // kolejne miesiace
|
|
|
|
|
sell[m][p] <= produce[m][p] + stock[m-1][p];
|
|
|
|
|
stock[m][p]==(produce[m][p] + stock[m-1][p])-sell[m][p];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
forall(m in months, p in products) {
|
|
|
|
|
stock[m][p] <= storageMax[p];
|
|
|
|
|
if(m == 3) {
|
|
|
|
|
stock[m][p] >= 50;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-05-24 23:54:18 +02:00
|
|
|
averageProfit>=minimalAverageProfit;
|
2025-05-24 17:15:34 +02:00
|
|
|
|
2025-05-24 23:54:18 +02:00
|
|
|
}
|
2025-05-24 17:15:34 +02:00
|
|
|
|
|
|
|
|
main {
|
2025-05-24 23:54:18 +02:00
|
|
|
var fileProfit = new IloOplOutputFile("results-minimalAverageProfit-FSD-profit_two.txt");
|
|
|
|
|
var fileRisk = new IloOplOutputFile("results-minimalAverageProfit-FSD-risk_two.txt");
|
2025-05-24 17:15:34 +02:00
|
|
|
|
|
|
|
|
var mod = thisOplModel;
|
|
|
|
|
var def = mod.modelDefinition;
|
|
|
|
|
var data = mod.dataElements;
|
2025-05-24 23:19:12 +02:00
|
|
|
var maxAvgProfit = 11031;
|
2025-05-24 17:15:34 +02:00
|
|
|
var i = 1;
|
2025-05-24 23:54:18 +02:00
|
|
|
fileProfit.writeln("minimalAverageProfit;averageProfit;riskMeasureGini;m1_prod_P1;m1_prod_P2;m1_prod_P3;m1_prod_P4;m2_prod_P1;m2_prod_P2;m2_prod_P3;m2_prod_P4;m3_prod_P1;m3_prod_P2;m3_prod_P3;m3_prod_P4;m1_stock_P1;m1_stock_P2;m1_stock_P3;m1_stock_P4;m2_stock_P1;m2_stock_P2;m2_stock_P3;m2_stock_P4;m3_stock_P1;m3_stock_P2;m3_stock_P3;m3_stock_P4");
|
|
|
|
|
fileRisk.writeln("minimalAverageProfit;averageProfit;riskMeasureGini;m1_prod_P1;m1_prod_P2;m1_prod_P3;m1_prod_P4;m2_prod_P1;m2_prod_P2;m2_prod_P3;m2_prod_P4;m3_prod_P1;m3_prod_P2;m3_prod_P3;m3_prod_P4;m1_stock_P1;m1_stock_P2;m1_stock_P3;m1_stock_P4;m2_stock_P1;m2_stock_P2;m2_stock_P3;m2_stock_P4;m3_stock_P1;m3_stock_P2;m3_stock_P3;m3_stock_P4");
|
2025-05-24 17:15:34 +02:00
|
|
|
|
2025-05-24 23:54:18 +02:00
|
|
|
data.minimalAverageProfit = 8450.97;
|
2025-05-24 17:15:34 +02:00
|
|
|
|
|
|
|
|
mod = new IloOplModel (def, cplex);
|
|
|
|
|
mod.addDataSource(data);
|
|
|
|
|
mod.generate();
|
|
|
|
|
|
2025-05-24 23:54:18 +02:00
|
|
|
writeln("First solution: ");
|
2025-05-24 23:19:12 +02:00
|
|
|
cplex.tilim = 60;
|
2025-05-24 17:15:34 +02:00
|
|
|
cplex.solve();
|
|
|
|
|
|
2025-05-24 23:54:18 +02:00
|
|
|
writeln(i," minimalAverageProfit: ",data.minimalAverageProfit," averageProfit: ",mod.averageProfit,", riskMeasureGini: ",mod.riskMeasureGini);
|
|
|
|
|
fileProfit.writeln(data.minimalAverageProfit,";",mod.averageProfit,";",mod.riskMeasureGini,";",mod.produce[1][1],";",mod.produce[1][2],";",mod.produce[1][3],";",mod.produce[1][4], ";",mod.produce[2][1],";",mod.produce[2][2],";",mod.produce[2][3],";",mod.produce[2][4],";",mod.produce[3][1],";",mod.produce[3][2], ";",mod.produce[3][3],";",mod.produce[3][4],";",mod.stock[1][1],";",mod.stock[1][2],";",mod.stock[1][3],";",mod.stock[1][4], ";",mod.stock[2][1],";",mod.stock[2][2],";",mod.stock[2][3],";",mod.stock[2][4],";",mod.stock[3][1],";",mod.stock[3][2], ";",mod.stock[3][3],";",mod.stock[3][4]);
|
|
|
|
|
fileRisk.writeln(data.minimalAverageProfit,";",mod.averageProfit,";",mod.riskMeasureGini,";",mod.produce[1][1],";",mod.produce[1][2],";",mod.produce[1][3],";",mod.produce[1][4], ";",mod.produce[2][1],";",mod.produce[2][2],";",mod.produce[2][3],";",mod.produce[2][4],";",mod.produce[3][1],";",mod.produce[3][2], ";",mod.produce[3][3],";",mod.produce[3][4],";",mod.stock[1][1],";",mod.stock[1][2],";",mod.stock[1][3],";",mod.stock[1][4], ";",mod.stock[2][1],";",mod.stock[2][2],";",mod.stock[2][3],";",mod.stock[2][4],";",mod.stock[3][1],";",mod.stock[3][2], ";",mod.stock[3][3],";",mod.stock[3][4]);
|
2025-05-24 17:15:34 +02:00
|
|
|
|
2025-05-24 23:19:12 +02:00
|
|
|
i = 1;4
|
2025-05-24 23:54:18 +02:00
|
|
|
fileProfit.writeln("averageProfit: ");
|
2025-05-24 23:22:59 +02:00
|
|
|
while (i<=data.numberOfScenarios) {
|
2025-05-24 17:15:34 +02:00
|
|
|
fileProfit.writeln(mod.profit[i]);
|
|
|
|
|
i++;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
i = 1;
|
|
|
|
|
fileRisk.writeln("Risk: ");
|
2025-05-24 23:22:59 +02:00
|
|
|
while (i<=data.numberOfScenarios) {
|
2025-05-24 17:15:34 +02:00
|
|
|
fileRisk.writeln(mod.risk[i]);
|
|
|
|
|
i++;
|
|
|
|
|
};
|
|
|
|
|
|
2025-05-24 23:54:18 +02:00
|
|
|
fileProfit.writeln("minimalAverageProfit;averageProfit;riskMeasureGini;m1_prod_P1;m1_prod_P2;m1_prod_P3;m1_prod_P4;m2_prod_P1;m2_prod_P2;m2_prod_P3;m2_prod_P4;m3_prod_P1;m3_prod_P2;m3_prod_P3;m3_prod_P4;m1_stock_P1;m1_stock_P2;m1_stock_P3;m1_stock_P4;m2_stock_P1;m2_stock_P2;m2_stock_P3;m2_stock_P4;m3_stock_P1;m3_stock_P2;m3_stock_P3;m3_stock_P4");
|
|
|
|
|
fileRisk.writeln("minimalAverageProfit;averageProfit;riskMeasureGini;m1_prod_P1;m1_prod_P2;m1_prod_P3;m1_prod_P4;m2_prod_P1;m2_prod_P2;m2_prod_P3;m2_prod_P4;m3_prod_P1;m3_prod_P2;m3_prod_P3;m3_prod_P4;m1_stock_P1;m1_stock_P2;m1_stock_P3;m1_stock_P4;m2_stock_P1;m2_stock_P2;m2_stock_P3;m2_stock_P4;m3_stock_P1;m3_stock_P2;m3_stock_P3;m3_stock_P4");
|
2025-05-24 23:19:12 +02:00
|
|
|
|
2025-05-24 23:54:18 +02:00
|
|
|
data.minimalAverageProfit = 8983.38;
|
2025-05-24 17:15:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
mod = new IloOplModel (def, cplex);
|
|
|
|
|
mod.addDataSource(data);
|
|
|
|
|
mod.generate();
|
|
|
|
|
|
2025-05-24 23:54:18 +02:00
|
|
|
writeln("Second solution: ");
|
2025-05-24 17:15:34 +02:00
|
|
|
cplex.solve();
|
|
|
|
|
|
2025-05-24 23:54:18 +02:00
|
|
|
writeln(i," minimalAverageProfit: ",data.minimalAverageProfit," averageProfit: ",mod.averageProfit,", riskMeasureGini: ",mod.riskMeasureGini);
|
|
|
|
|
fileProfit.writeln(data.minimalAverageProfit,";",mod.averageProfit,";",mod.riskMeasureGini,";",mod.produce[1][1],";",mod.produce[1][2],";",mod.produce[1][3],";",mod.produce[1][4], ";",mod.produce[2][1],";",mod.produce[2][2],";",mod.produce[2][3],";",mod.produce[2][4],";",mod.produce[3][1],";",mod.produce[3][2], ";",mod.produce[3][3],";",mod.produce[3][4],";",mod.stock[1][1],";",mod.stock[1][2],";",mod.stock[1][3],";",mod.stock[1][4], ";",mod.stock[2][1],";",mod.stock[2][2],";",mod.stock[2][3],";",mod.stock[2][4],";",mod.stock[3][1],";",mod.stock[3][2], ";",mod.stock[3][3],";",mod.stock[3][4]);
|
|
|
|
|
fileRisk.writeln(data.minimalAverageProfit,";",mod.averageProfit,";",mod.riskMeasureGini,";",mod.produce[1][1],";",mod.produce[1][2],";",mod.produce[1][3],";",mod.produce[1][4], ";",mod.produce[2][1],";",mod.produce[2][2],";",mod.produce[2][3],";",mod.produce[2][4],";",mod.produce[3][1],";",mod.produce[3][2], ";",mod.produce[3][3],";",mod.produce[3][4],";",mod.stock[1][1],";",mod.stock[1][2],";",mod.stock[1][3],";",mod.stock[1][4], ";",mod.stock[2][1],";",mod.stock[2][2],";",mod.stock[2][3],";",mod.stock[2][4],";",mod.stock[3][1],";",mod.stock[3][2], ";",mod.stock[3][3],";",mod.stock[3][4]);
|
2025-05-24 17:15:34 +02:00
|
|
|
|
|
|
|
|
i = 1;
|
2025-05-24 23:54:18 +02:00
|
|
|
fileProfit.writeln("averageProfit: ");
|
2025-05-24 23:22:59 +02:00
|
|
|
while (i<=data.numberOfScenarios) {
|
2025-05-24 17:15:34 +02:00
|
|
|
fileProfit.writeln(mod.profit[i]);
|
|
|
|
|
i++;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
i = 1;
|
|
|
|
|
fileRisk.writeln("Risk: ");
|
2025-05-24 23:22:59 +02:00
|
|
|
while (i<=data.numberOfScenarios) {
|
2025-05-24 17:15:34 +02:00
|
|
|
fileRisk.writeln(mod.risk[i]);
|
|
|
|
|
i++;
|
|
|
|
|
};
|
|
|
|
|
|
2025-05-24 23:54:18 +02:00
|
|
|
fileProfit.writeln("minimalAverageProfit;averageProfit;riskMeasureGini;m1_prod_P1;m1_prod_P2;m1_prod_P3;m1_prod_P4;m2_prod_P1;m2_prod_P2;m2_prod_P3;m2_prod_P4;m3_prod_P1;m3_prod_P2;m3_prod_P3;m3_prod_P4;m1_stock_P1;m1_stock_P2;m1_stock_P3;m1_stock_P4;m2_stock_P1;m2_stock_P2;m2_stock_P3;m2_stock_P4;m3_stock_P1;m3_stock_P2;m3_stock_P3;m3_stock_P4");
|
|
|
|
|
fileRisk.writeln("minimalAverageProfit;averageProfit;riskMeasureGini;m1_prod_P1;m1_prod_P2;m1_prod_P3;m1_prod_P4;m2_prod_P1;m2_prod_P2;m2_prod_P3;m2_prod_P4;m3_prod_P1;m3_prod_P2;m3_prod_P3;m3_prod_P4;m1_stock_P1;m1_stock_P2;m1_stock_P3;m1_stock_P4;m2_stock_P1;m2_stock_P2;m2_stock_P3;m2_stock_P4;m3_stock_P1;m3_stock_P2;m3_stock_P3;m3_stock_P4");
|
2025-05-24 17:15:34 +02:00
|
|
|
|
2025-05-24 23:54:18 +02:00
|
|
|
data.minimalAverageProfit = 9515.79;
|
2025-05-24 17:15:34 +02:00
|
|
|
|
|
|
|
|
mod = new IloOplModel (def, cplex);
|
|
|
|
|
mod.addDataSource(data);
|
|
|
|
|
mod.generate();
|
|
|
|
|
|
2025-05-24 23:54:18 +02:00
|
|
|
writeln("Third solution: ");
|
2025-05-24 17:15:34 +02:00
|
|
|
cplex.solve();
|
|
|
|
|
|
2025-05-24 23:54:18 +02:00
|
|
|
writeln(i," minimalAverageProfit: ",data.minimalAverageProfit," averageProfit: ",mod.averageProfit,", riskMeasureGini: ",mod.riskMeasureGini);
|
|
|
|
|
fileProfit.writeln(data.minimalAverageProfit,";",mod.averageProfit,";",mod.riskMeasureGini,";",mod.produce[1][1],";",mod.produce[1][2],";",mod.produce[1][3],";",mod.produce[1][4], ";",mod.produce[2][1],";",mod.produce[2][2],";",mod.produce[2][3],";",mod.produce[2][4],";",mod.produce[3][1],";",mod.produce[3][2], ";",mod.produce[3][3],";",mod.produce[3][4],";",mod.stock[1][1],";",mod.stock[1][2],";",mod.stock[1][3],";",mod.stock[1][4], ";",mod.stock[2][1],";",mod.stock[2][2],";",mod.stock[2][3],";",mod.stock[2][4],";",mod.stock[3][1],";",mod.stock[3][2], ";",mod.stock[3][3],";",mod.stock[3][4]);
|
|
|
|
|
fileRisk.writeln(data.minimalAverageProfit,";",mod.averageProfit,";",mod.riskMeasureGini,";",mod.produce[1][1],";",mod.produce[1][2],";",mod.produce[1][3],";",mod.produce[1][4], ";",mod.produce[2][1],";",mod.produce[2][2],";",mod.produce[2][3],";",mod.produce[2][4],";",mod.produce[3][1],";",mod.produce[3][2], ";",mod.produce[3][3],";",mod.produce[3][4],";",mod.stock[1][1],";",mod.stock[1][2],";",mod.stock[1][3],";",mod.stock[1][4], ";",mod.stock[2][1],";",mod.stock[2][2],";",mod.stock[2][3],";",mod.stock[2][4],";",mod.stock[3][1],";",mod.stock[3][2], ";",mod.stock[3][3],";",mod.stock[3][4]);
|
2025-05-24 17:15:34 +02:00
|
|
|
|
|
|
|
|
i = 1;
|
2025-05-24 23:54:18 +02:00
|
|
|
fileProfit.writeln("averageProfit: ");
|
2025-05-24 23:22:59 +02:00
|
|
|
while (i<=data.numberOfScenarios) {
|
2025-05-24 17:15:34 +02:00
|
|
|
fileProfit.writeln(mod.profit[i]);
|
|
|
|
|
i++;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
i = 1;
|
|
|
|
|
fileRisk.writeln("Risk: ");
|
2025-05-24 23:22:59 +02:00
|
|
|
while (i<=data.numberOfScenarios) {
|
2025-05-24 17:15:34 +02:00
|
|
|
fileRisk.writeln(mod.risk[i]);
|
|
|
|
|
i++;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fileProfit.close();
|
|
|
|
|
fileRisk.close();
|
|
|
|
|
}
|