Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.

 View Only
  • 1.  Scripting runtime error: unknown property 'getValue'

    Posted Mon April 01, 2013 02:12 AM

    Originally posted by: LindaKing


    Dear all,
    I try to use cplex.getValue to access the value of decision variable after solving the MILP model.
    But I get the error: Scripting runtime error: unknown property 'getValue'.
    I also use the line: cplex.getObjValue(). There is no error.

    Would you please tell me what the reason could be for this problem?
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Scripting runtime error: unknown property 'getValue'

    Posted Tue April 02, 2013 03:15 AM
    Hi,

    let me give you an example:

    dvar float+ Gas[1..1];
    dvar float+ Chloride[1..1];
     
    maximize
      40 * Gas[1] + 50 * Chloride[1];
    subject to {
      
      ctMaxTotal:     
        Gas[1] + Chloride[1] <= 50;
      ctMaxTotal2:    
        3 * Gas[1] + 4 * Chloride[1] <= 180;
      ctMaxChloride:  
        Chloride[1] <= 40;
    }
     
    execute
    {
      writeln(cplex.getObjValue());
      writeln(Gas[1]);
     
    }
    


    To display a value, you only have to use its name such as Gas here.

    regards
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: Scripting runtime error: unknown property 'getValue'

    Posted Wed April 03, 2013 03:11 AM

    Originally posted by: LindaKing


    Hi, thank you for your reply.
    Actually, the value of dvar should be passed to a variable and used in next iteration, not just displayed.
    But I found that accessing dvar after solving couldn't be realized by ILOG script. Is it right?
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: Scripting runtime error: unknown property 'getValue'

    Posted Wed April 03, 2013 04:37 AM
    Hi,

    let me give you an example:

    dvar float+ Gas[1..1];
    dvar float+ Chloride[1..1];
     
    maximize
      40 * Gas[1] + 50 * Chloride[1];
    subject to {
      
      ctMaxTotal:     
        Gas[1] + Chloride[1] <= 50;
      ctMaxTotal2:    
        3 * Gas[1] + 4 * Chloride[1] <= 180;
      ctMaxChloride:  
        Chloride[1] <= 40;
    }
     
    main
    {
      thisOplModel.generate();
      cplex.solve();
      writeln(cplex.getObjValue());
      writeln(thisOplModel.Gas[1]);
            thisOplModel.Gas[1].UB=15;
            cplex.solve();
      writeln(cplex.getObjValue());
      writeln(thisOplModel.Gas[1]);
            
    }
    


    Here you can see that you can after a solve, get a value of a dvar and then say that this dvar should be less than 15 and solve again

    regards
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: Scripting runtime error: unknown property 'getValue'

    Posted Fri December 06, 2019 11:02 AM

    Originally posted by: Mathsg


    Hi Alex,

    i am facing the same problem when updating my master problem for next iteration. i have looked upon all the example and previous post history but i am unable to locate the error where the error is. kindly help me to fix the error.

    i am getting syntax error e.g., Scripting runtime error: data element does not exist when i am going to add the sub model solution value in the master problem for next iteration in script part. Kindly guide me how to get rid of this error. It would be highly appricated and i am looking froward to hearing from my respected seniors and IBM administration team. Thank you very much 

     

    main {
         

      var status = 0;
      thisOplModel.generate();
      
      var RC_EPS = 1.0e-6;

      var masterDef = thisOplModel.modelDefinition;
      var masterCplex = cplex;
      var masterData = thisOplModel.dataElements;
       
      var subSource = new IloOplModelSource("PP_Jan.mod");
      var subDef = new IloOplModelDefinition(subSource);
      var subData = new IloOplDataElements();
      var subCplex = new IloCplex();

      var best;
      var curr = Infinity;

      while ( best != curr ) {
        best = curr;

        var masterOpl = new IloOplModel(masterDef, masterCplex);
        masterOpl.addDataSource(masterData);
        masterOpl.generate();
        masterOpl.convertAllIntVars();
            
        writeln("Solve master.");
        if ( masterCplex.solve() ) {
          curr = masterCplex.getObjValue();
          writeln();
          writeln("OBJECTIVE: ",curr);
        } 
        else {
          writeln("No solution!");
          masterOpl.end();
          break;
        }

      subData.nmbr_routes = masterOpl.nmbr_routes;
      subData.nbnodes = masterOpl.nbnodes;
      subData.flows = masterOpl.flows;
      subData.Lincards = masterOpl.Lincards;
      subData.hope_count = masterOpl.hope_count;
      subData.link = masterOpl.link;
      subData.q = masterOpl.q;
      subData.ECcards = masterOpl.ECcards;
      subData.Duals = masterOpl.Duals;
            
     for (var i in masterOpl.routes) {
     subData.Duals[i] = masterOpl.Const10[i].dual;
     }
        var subOpl = new IloOplModel(subDef, subCplex);
        subOpl.addDataSource(subData);
        subOpl.generate();

        writeln("Solve sub.");
        if ( subCplex.solve() ) {
          writeln();
          writeln("OBJECTIVE: ",subCplex.getObjValue());
        }
        else {
          writeln("No solution!");
          subOpl.end();
          masterOpl.end();
          break;
        }

        if (subCplex.getObjValue() >-RC_EPS) { 
          subOpl.end();
          masterOpl.end();
          break;
        }

        
        // Prepare the next iteration:
       //masterData.routes.add(masterData.routes.size,1,subOpl.getObjValue());
        
        
         for ( var j in subOpl.routes){
            masterData.lemda[j][1][1].add(masterData.lemda[j][1][1].size,1,subOpl.lemda[j][1][1].solutionValue);  // Getting Error here(Scripting runtime error: data element lemda does not exist)
         // writeln("===>",subOpl.f[Opl.first(subOpl.Lincards)][j][1][1].solutionValue);
         }
        //masterData.routes.add(subOpl.getObjValue());
        
      subOpl.end();
      masterOpl.end();
      }
      writeln("Relaxed model search end.");

      masterOpl = new IloOplModel(masterDef,masterCplex);
      masterOpl.addDataSource(masterData);
      masterOpl.generate();   

      writeln("Solve integer master.");  
      if ( masterCplex.solve() ) {
        writeln();
        writeln("OBJECTIVE: ",masterCplex.getObjValue());
        if (Math.abs(masterCplex.getObjValue() - 122)>=0.0001) {
          writeln("Unexpected objective value");
          status = -1;
          
        }
        /*for(i in  masterData.Patterns) {
          if (masterOpl.Cut[i].solutionValue > 0) {
            writeln("Pattern : ", i, " used ", masterOpl.Cut[i].solutionValue << " times");
          }
        }*/
      }
      masterOpl.end();
      status;
    }


    #DecisionOptimization
    #OPLusingCPLEXOptimizer