Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
Expand all | Collapse all

cannot add properties to this value: null.

  • 1.  cannot add properties to this value: null.

    Posted 05/29/17 02:07 PM

    Originally posted by: behi


    Hi

     

    when I try to save the optimal value of an opl decision variable (z[j][k])  in to a variable (currentz[j][k]) in script I got the following error:

    "cannot add properties to this value: null." I checked that z takes value and is type of Boolean in opl.

    Also when I try to update the data using element:  currentvv=sub2.vv sometimes I get the following error: 

    "cannot convert to a number: [a IloNumVar]." 

    but when I write currentvv=Math.round(sub2.vv);   the error is resolved! please advise me...

    thank you in advance.

     

     

    this is part of my code:

         

           var currentvv;
           var currentteta;
           var currentc= new Array;
           var currenttt= new Array;
           var currentttp=new Array;
           var currentz=new Array;

      var source2 = new IloOplModelSource("sub2.mod");
            var Def2 = new IloOplModelDefinition(source2);
            var sub2 = new IloOplModel(Def2,cplex);
            var sub2Data= new IloOplDataSource("sub2.dat");
            sub2.addDataSource(sub2Data);
            sub2.generate();
            sub2Data=sub2.dataElements;
            
            sub2Data.teta[1]=currentteta;
            for (var j in sub2.part)
            {
             sub2Data.c[j]=currentc[j];
            } 
           if (cplex.solve())
           {      
              for (var k in sub2.batch)
            {
              currenttt[k]=Math.round(sub2.tt[k]);
              currentttp[k]=Math.round(sub2.ttp[k]);

                       
              for (var j in sub2.part)
            {
                 currentz[j][k]=sub2.z[j][k]; <<<Error>>> "cannot add properties to this value: null."
            }
            } 
             currentvv=Math.round(sub2.vv);      
            var z1=Math.round(sub2.z1);
            UB=Ilomin(UB,z1+teta2);


            writeln("UB obtained from sub2=",UB);
          }               
            else
            {
              writeln("No solution3");
            }        
              sub2.end();

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: cannot add properties to this value: null.

    Posted 05/29/17 02:28 PM

    Hi,

    can you post a full example so that other users Could try ?

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: cannot add properties to this value: null.

    Posted 05/29/17 03:10 PM

    Originally posted by: behi


    Here I attached the full example including .mod and . dat files. and the script file named "main decompose"


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: cannot add properties to this value: null.

    Posted 05/30/17 03:08 AM

    Hi,

    let me solve 2 issues:

    You wrote

    var currentz=new Array();

    but I would rewrite

    var currentz=new Array(10);
           for(var i=0;i<=10;i++) currentz[i]=new Array(10);

    in order to solve your first issue.

    Later you use IloMin but I d rather write

    UB=Opl.minl(UB,z1+teta2);

    and line 61 instead of

    var teta2=master0.teta2;

    I would write

    var teta2=master0.teta2.solutionValue;

    Let me attach a better .mod with the fixes and you ll start from there

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: cannot add properties to this value: null.

    Posted 05/30/17 03:25 AM

    Originally posted by: behi


    thank you so much,


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: cannot add properties to this value: null.

    Posted 05/30/17 03:44 AM

    Originally posted by: behi


    One more question about this, I encounter error "c0000005 EXCEPTION_ACCESS_VIOLATION" what this error is and how it can be resolved?

    I checked it with different systems but it remains.

    thank you s much

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: cannot add properties to this value: null.

    Posted 05/30/17 04:11 AM

    Hi,

    I wrote I had solved some issues, not all of them. Right ?

    So let me go further.

    I attached a .mod with no errors.

    regards

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 8.  Re: cannot add properties to this value: null.

    Posted 05/30/17 04:53 AM

    Originally posted by: behi


    thanks a lot... How did you resolve it, can you explain plz?


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 9.  Re: cannot add properties to this value: null.

    Posted 05/30/17 05:02 AM

    Hi,

    you used objects that you had deleted so I disactivated end:

    thisOplModel.settings.mainEndEnabled = false;

    You may find useful links at

    https://www.ibm.com/developerworks/community/forums/html/topic?id=0d0b2396-3b48-4638-b032-3b9ea74f1a11&ps=25

    regards

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 10.  Re: cannot add properties to this value: null.

    Posted 05/30/17 05:23 AM

    Originally posted by: behi


    Yes many thanks.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 11.  Re: cannot add properties to this value: null.

    Posted 06/06/17 02:49 PM

    Originally posted by: behi


    Dear Alex

     

    I have run an script which is containing a loop. in this loop a unique model and data are called, but each time the data is modified using data element, and solved by cplex.solve, but it seems that the cplex.solve doesn't work properly, and only once it is solved and in the other iterations it only reports the solutions obtained in the first iteration. how we can force it to solve the model in each iteration?

    I attached the codes...


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 12.  Re: cannot add properties to this value: null.

    Posted 06/07/17 07:21 AM

    Hi,

    if you add

    writeln("external data");
            writeln(mmodel.printExternalData());

    before

    if (cplex.solve()) {

    you ll be able to check which data is used

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 13.  Re: cannot add properties to this value: null.

    Posted 06/08/17 06:05 AM

    Originally posted by: behi


    Dear Alexa

     

    Thank you for your reply.

    Actually I used the debug feature of Cplex to check that whether the data is updated or not, and I almost sure that the command cplex.solve doesn't work in next iterations. parameter dData.teta is in fact the coefficients of the objective function, and despite these data updated in each iteration of loop, but the cplex.solve doesn't work and only report the solution of the previous step by new coefficients.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 14.  Re: cannot add properties to this value: null.

    Posted 06/08/17 06:16 AM

    Ok,

    can you move the generate after the change ?

     dData = mmodel.dataElements;
            dData.M[1] = 1000000;
            dData.M[2] = 1000000;
            for ( var i in mmodel.Nb) {
              if (Teta == i) {
                dData.teta[i] = 1;
              } else {
                dData.teta[i] = 0;
              }
            }
            mmodel.generate();

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 15.  Re: cannot add properties to this value: null.

    Posted 06/08/17 06:52 AM

    Originally posted by: behi


    thanks a lot, it works! Do you think that I have to apply this change in all other codes I have? because I saw this current order of commands in an example in CPLEX.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 16.  Re: cannot add properties to this value: null.

    Posted 06/08/17 07:02 AM

    Hi,

    well I cannot say because I do not see all your codes ...

    But do the changes before the generate.

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer