Decision Optimization

Decision Optimization

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

 View Only
Expand all | Collapse all

Cplex model variable problem, Uninitialised value was created by a heap allocation

  • 1.  Cplex model variable problem, Uninitialised value was created by a heap allocation

    Posted Sun August 04, 2019 12:15 PM

    Originally posted by: mido199


    Hello, 

     

    I am using CPLEX 12.8 to solve a MIP, howver I am getting a segmentation fault when I try to set the name of one of my variables. When I run valgrind, I get: Use of uninitialised value of size 8 at line written in bold in the code below, I run again Valgrind with --track-origins=yes, I get Uninitialised value was created by a heap allocation. Do I need to initialize variables in CPLEX ? I really don't understand this error. 

     

        m = IloArray<IloArray<IloNumVarArray>>(env, (int)moves.size());

        for(int l=0; l<moves.size(); l++)
        {
            printf("l: %d \n",l);
            MoveConfig<Node,Driver,MoveAgv> mo = moves[l];
            m[mo.config_index] = IloArray<IloNumVarArray>(env,  mo.NbrOfNodes );


                for(int i = mo.start_node_pos; i<mo.start_node_pos + mo.NbrOfNodes; i++)
                {
                    Node * n = request_to_insert->GetNode(i);             
                    m[mo.config_index][n->no] = IloNumVarArray(env, 1, 0, 1, ILOINT);             
                    char name[40];
                    sprintf(name,"m%d_%d_%d",mo.config_index,n->no,mo.move.prev->no);
                    m[mo.config_index][n->no][mo.move.prev->no].setName(name);
        
                }    
            
        }


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Cplex model variable problem, Uninitialised value was created by a heap allocation

    Posted Sun August 04, 2019 01:16 PM

    Originally posted by: T_O


    Might it be that for some reason, n->no is not initialized?


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Cplex model variable problem, Uninitialised value was created by a heap allocation

    Posted Sun August 04, 2019 02:53 PM

    Originally posted by: mido199


    Hello T_O, 

     

    Thank you for your answer. I printed out the content of mo.config_index and n->no, it was displayed correctly. It is a strange error !!! 


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Cplex model variable problem, Uninitialised value was created by a heap allocation

    Posted Sun August 04, 2019 03:03 PM

    Originally posted by: T_O


    Ok. Let's for a while forget about the valgrind problem.

    Did you try to use a debugger to find out where exactly the segmentation fault occurs? (This is not necessarily the same line as your valgrind problem. Maybe something like mo.move.prev->no is missing.)


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Cplex model variable problem, Uninitialised value was created by a heap allocation

    Posted Sun August 04, 2019 03:15 PM

    Originally posted by: mido199


    Yes I tried with GDB, here is the output: 

     

    Program received signal SIGSEGV, Segmentation fault.
    0x0000555555619cab in ExactInsertMIP::Init (this=0x7fffffffd460, s=..., moves=std::vector of length 65, capacity 128 = {...})
        at ./Agv/ExactInsertMIP.cpp:120
    120                    m[mo.config_index][n->no] = IloNumVarArray(env, 1, 0, 1, ILOINT);
     

    note that, ExactInsertMIP::Init is the function where I build my MIP. according to gdb, the problem is in the line: m[mo.config_index][n->no] = IloNumVarArray(env, 1, 0, 1, ILOINT)


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Cplex model variable problem, Uninitialised value was created by a heap allocation

    Posted Sun August 04, 2019 03:24 PM

    Originally posted by: T_O


    Hmm, ok.

    What is the value of mo.NbrOfNodes and what is the value of n->no when the segmentation fault occurs? Maybe, m[mo.config_index] is too short.


    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: Cplex model variable problem, Uninitialised value was created by a heap allocation

    Posted Sun August 04, 2019 07:21 PM

    Originally posted by: mido199


    Here are the values: 

    mo.start_node_pos = 0

    mo.NbrOfNodes = 1 

    mo.config_index = 0

    n->no = 130

    mo.move.prev->no = 0 

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: Cplex model variable problem, Uninitialised value was created by a heap allocation

    Posted Sun August 04, 2019 11:52 PM

    Originally posted by: T_O


    That's it.

    m[mo.config_index] has a size of 1 (because of "m[mo.config_index] = IloArray<IloNumVarArray>(env,  mo.NbrOfNodes )").

    Then you cannot write to index 130 (m[mo.config_index][n->no]).


    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: Cplex model variable problem, Uninitialised value was created by a heap allocation

    Posted Mon August 05, 2019 12:11 AM

    Originally posted by: mido199


    Yeah , you are right, I also realized it when you asked me the question about the values. Thank you so much for the help. 


    #CPLEXOptimizers
    #DecisionOptimization