I am having trouble automating the testing of several scenarios with CPLEX.
I want to test several scenarios where I play around with the weight of the weighted sum of my objective function and the ratio.
Example: W1=0.2, W2 = 0.7, and W3=0.1 with
ratio\[1\]=0
ratio\[2\]=0
ratio\[3\]=0
to start with. Then, I want my code to increment only ratio[3] from 0.1 to 0.7.
The problem I have is that my code only executes the first base value. It writes all the different W and ratio[i] values to my Excel file, but it always keeps the same value for my parameters. How can I link my constraints to the main? Compared to my first message, I have indicated how I declare my variables and parameters for clarity. In addition, I tried adding thisOplModel.W1 = currentW[1], but this gives me an error message.
Here are my variables:
COUTTOTAL: Total cost to complete the project.
Cmax: Time to complete the project.
QTEREMP: Quantity reused. Compared to the other two, we want to maximize this variable.
Parameters:
W1, W2, and W3 are the weights assigned by the user.
S1, S2, and S3 are correction factors to ensure that each variable has the same degree of importance.
esti***: Maximum and minimum values depending on whether I maximize or minimize just one variable.
FYI: I tried using Gemini to help me execute the automation portion. I can change that part without any problems.
code.mod
float estiTempsMax =...;
float estiCoutMax=...;
float estiTempsMin =...;
float estiCoutMin=...;
float estiQTEMin=...;
float estiQTEMax=...;
float W1;
float W2;
float W3;
float WMAX=...;
float S1=W1/WMAX;
float S2=W2/WMAX;
float S3=W3/WMAX;
float W_combinaisons[Mode][Mode]=...;
float ratio[Mode];
float ratio_script[Mode]= [0, 0, 0];
dvar int Cmax;
dvar float QTEREMP;
dvar float COUTTOTAL;
dexpr float TestCOU = ctCont+ ctLiv + ctMO + ctDecMat + ctEquip + ENF +ctRecyc - gain;
dexpr float TestQTE = sum(m in Mat) Qm[3][m];
minimize W1 *S1*((TOTALCOST-estiMinCost)/(estiMaxCost-estiMinCost)) + W2*S2*((Cmax-estiMinTime)/(estiMaxTime-estiMinTime)) - W3*S3*((QTEREMP-estiMinQTEM)/(estiMaxQTEM-estiMinQTEM));
//Constrait....
subject to {
...
forall(i in Mode)
CtRatioLiaison: ratio[i] == ratio_script[i]; //I'M TRYING TO LINK MY PARAMETERS WITH THE MAIN
...
}
main {
var ofile = new IloOplOutputFile("resultats_scenarios_ratio2_varie.csv");
ofile.writeln("W1;W2;W3;ratio[1];ratio[2];ratio[3];Objectif;COUTTOTAL;Cmax;QTEREMP");
var r2_start = 0.0;
var r2_end = 0.2;
var r2_step = 0.1;
for (var r2_val = r2_start; r2_val <= r2_end + 0.0001; r2_val += r2_step) {
for (var w_index = 1; w_index <= 3; w_index++) {
var currentW = thisOplModel.W_combinaisons[w_index];
W1 = currentW[1];
W2 = currentW[2];
W3 = currentW[3];
for (var r3 = 0.0; r3 <= 0.7 + 0.0001; r3 += 0.1) {
var tempRatio = new Array(4); // Taille 4 pour supporter les index 1, 2, 3
tempRatio[1] = 0.0;
tempRatio[2] = r2_val;
tempRatio[3] = r3;
thisOplModel.generate()
writeln("--- Résolution : R2=", ratio_script[2], ", W=(", W1, ", ", W2, ", ", W3, ") et R3=", ratio_script[3], " ---");
if (cplex.solve()) {
ofile.writeln(W1, ";", W2, ";", W3, ";",
//CORRECTION : Utiliser ratio_script au lieu de ratio
ratio_script[1], ";", ratio_script[2], ";",ratio_script[3], ";",cplex.getObjValue(), ";", thisOplModel.TestCOU, ";", thisOplModel.Cmax, ";", thisOplModel.QTEREMP);
}
else {
ofile.writeln(W1, ";", W2, ";", W3, ";",
ratio_script[1], ";", ratio_script[2], ";", ratio_script[3], ";",
"No Solution", ";", "N/A", ";", "N/A", ";", "N/A");
}
}
}
}
Any solution ?
