Decision Optimization

Decision Optimization

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

 View Only
  • 1.  SetVectors nullreferenceexception c#

    Posted Wed March 25, 2015 02:48 AM

    Originally posted by: xuxiaoming


    Hi all,

    I have a problem when I use SetVectors method. Please look at the following code. " SetVectors(_a[i], _A[i], null, null); and SetVectors(_myu[i][k], _Myu[i][k], null, null);" can pass the debug. However " SetVectors(_xiaa[i][j], _xiAA[i][j], null, null); etc" can not pass. The debug information shows that something is null. Then give a nullreferenceexception. I check every Inumvar carefully. And all of them are non-null. I spent two days to dweal with this problem.  However, I can't solve it.

    So, can you help me?

    Thanks a lot!

    Xiaoming

     if (!_done)
                    {
                        for (int i = 0; i < _A.GetLength(0); i++)
                        {
                            SetVectors(_a[i], _A[i], null, null);
                            SetVectors(_d[i], _D[i], null, null);
                        }
    
                        //for (int i = 0; i < _xiAA.GetLength(0); i++)
                        //    for (int j = 0; j < _xiAA[i].GetLength(0); j++)
                        //    {
                        //        SetVectors(_xiaa[i][j], _xiAA[i][j], null, null);
                        //        SetVectors(_xidd[i][j], _xiDD[i][j], null, null);
                        //        SetVectors(_xiad[i][j], _xiAD[i][j], null, null);
                        //        SetVectors(_xida[i][j], _xiDA[i][j], null, null);
                        //    }
    
                        for (int i = 0; i < _Myu.GetLength(0); i++)
                            for (int k = 0; k < _Myu[i].GetLength(0); k++)
                                SetVectors(_myu[i][k], _Myu[i][k], null, null);
    
                        //for (int i = 0; i < _Omega.GetLength(0); i++)
                        //    for (int j = 0; j < _Omega[i].GetLength(0); j++)
                        //        for (int k = 0; k < _Omega[i][j].GetLength(0); k++)
                        //            SetVectors(_omega[i][j][k], _Omega[i][j][k], null, null);
    
                        _done = true;
                    }
    
     at ILOG.CPLEX.CpxNumVar.GetVarIndexValue()
       at ILOG.CPLEX.CpxOptimizationCallback.GetVarIndexValue(INumVar var)
       at ILOG.CPLEX.CpxSolveCallback.SetStart(Double[] x, INumVar[] var, Int32 xstart, Int32 xnum, Double[] pi, IRange[] rng, Int32 cstart, Int32 cnum)
       at ILOG.CPLEX.Cplex.SolveCallback.SetVectors(Double[] x, INumVar[] var, Int32 xstart, Int32 xnum, Double[] pi, IRange[] rng, Int32 cstart, Int32 cnum)
       at ILOG.CPLEX.Cplex.SolveCallback.SetVectors(Double[] x, INumVar[] var, Double[] pi, IRange[] rng)
       at LB_TS_Project.CUSING_CPLEX.Solve.Main() in d:......._CPLEX.cs:line 618
       at ILOG.CPLEX.CpxCallback.Callmain() 

    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: SetVectors nullreferenceexception c#

    Posted Wed March 25, 2015 03:05 AM

    Could it be that one of the arrays you are passing in is null itself? If the INumVar array is good, then maybe the double[] array is null?

    Also, I am wondering about the context of your code? Is this in a solve callback? I am asking because Cplex class does not have an overload of SetVectors() that only takes four arguments.

    Note that SetVectors() has been deprecated since version 12.5.


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: SetVectors nullreferenceexception c#

    Posted Wed March 25, 2015 03:23 AM

    Originally posted by: xuxiaoming


    Thanks for your help! The double[] array is also non-null! Yes the cods is in a solve callback. I have used SetStart method. But it also did not work. So, is there anything I can do to improve my code? Thanks a lot!

     

    I got the slotution for the post problem.

    Reference https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000014530212

    see below

    The exception is thrown when you attempt to get the value of a variable or a constraint that is not part of the model.

    Each variable for which you invoke getValue() must appear in at least one constraint or in the objective function.
    Double check your model and make sure that the variables for which you want to obtain the value are indeed part of the model.
    If, for some reason, the variable does not occur in the objective function nor in any constraint but you still want to be able to get its value (although this value will be useless) then do cplex.extract(variable) before you do cplex.solve(). After this cplex.getValue(variable) should work without throwing an exception.


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: SetVectors nullreferenceexception c#

    Posted Fri March 27, 2015 05:52 AM

    Hm, the post you cited was about an UnknownObjectException, not a null pointer exception. So which of the two exceptions did you observe?


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: SetVectors nullreferenceexception c#

    Posted Fri March 27, 2015 07:05 PM

    Originally posted by: xuxiaoming


    Hi, DanielJunglas

    In fact, when I want to get the value of an array, sometimes an UnknownObjectException is throwed out.  So I searched for the solution for this problem, then, the solution method in the reference  is found, and it did work. Therefore, I think the null pointer exception problem may have the same bug. I corrected my code according the same solution.  Fortunately, the null pointer exception problem is also solved.

    •  

    #CPLEXOptimizers
    #DecisionOptimization