0

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, and ratio[3]= to start with. Then, I want my code to increment only ratio[3] from 0.1 to 0.7.

The problem is that when the tool writes my results to my Excel file, I get the following results for my variables IloNumExp and IloNumVar in my Excel file.

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.

Parameter:

  • 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.

minimize W1 *S1*((TOTALCOST-estiMinCost)/(estiMaxCost-estiMinCost)) +     W2*S2*((Cmax-estiMinTime)/(estiMaxTime-estiMinTime)) - W3*S3*((QTEREMP-estiMinQTEM)/(estiMaxQTEM-estiMinQTEM));

//Constrait....
subject to {
...
}


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;     
                
                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");
                    }
                 }
        }
    }

enter image description here

Any solution ?

1 Answer 1

1

In your model, I guess you have not solved yet when you do the display or write into a file.

For example,

dvar int x;
dexpr int obj=2*x;

subject to
{
  x==1;
  obj==2*x;
}

main
{
  thisOplModel.generate();
  //cplex.solve();
  writeln(thisOplModel.x);
  writeln(thisOplModel.obj);
}

gives

[a IloNumVar]
[a IloNumExpr]

But as soon as you uncomment

cplex.Solve();

You get

1
2
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you ! I have another problem now, but this one is gone. Thank you again !
Perhaps you could also help me with another error in this code. When I added your solution “thisOplModel.generate();”, my Excel file finally had some entries. However, I noticed that my parameters W1, W2, W3, ratio[1], ratio[2], and ratio[3] are never modified. Do you have any idea how I can modify the parameter values in my code? I tried adding thisOplModel.W1, but I got the error message: Scripting runtime error: Element “W1” cannot be modified from main scripting. I am using version 22.1.1. I tried creating a scenarios.ops file, but that didn't work either. Thanks in advance.
Can you log a new question in stackoverflow ?
Done. Thank you !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.