1

I am trying to solve an iterative optimization problem in cplex opl using main function. The optimization objective and constraints are written in subvaluenew.mod.

float maxOfx = ...;
dvar float x;
int z=...;
maximize x+z;
subject to {
  x<=maxOfx;
}

execute
{
writeln("x= ",x);
}

and the main script is written in examplenew.mod file.

main {
      var source = new IloOplModelSource("subvaluenew.mod");
      var cplex = new IloCplex();
      var def = new IloOplModelDefinition(source);
     
     
     
      for(var k=1;k<=10;k++)
      {
      var opl = new IloOplModel(def,cplex);
      var data = new IloOplDataSource("examplenew.dat");
      var data2= new IloOplDataElements();
      data2.maxOfx=k;
      opl.addDataSource(data2);
      opl.generate();

      if (cplex.solve()) {  
         opl.postProcess();
         writeln("OBJ = " + cplex.getObjValue());
      } else {
         writeln("No solution");
      }
     opl.end();
    }  
     
    }

One of the parameter that is used in objective function is read from the excel file in examplenew.dat file.

SheetConnection Data("C:\\Users\\subha\\Downloads\\rk.xlsx");
 z from SheetRead (Data, "sheet3!F18:F18");

I am getting error in this code. If I have to use the .dat file to load the parameter data, how can I eliminate this error. The error showing is : data element z is not defined. However, I am defining the parameter z in subvaluenew.mod file. Please help me in solving this error.

1 Answer 1

1

In the main model

opl.addDataSource(data);

Is missing

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

Comments

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.