Decision Optimization

Decision Optimization

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

 View Only
  • 1.  Problem with setLinearCoef

    Posted Thu August 16, 2012 12:42 PM

    Originally posted by: JDalal


    I am not much familiar in using setLinearCoef(). So, issue may be something trivial that I am missing. I am using c++/concert.
    First, brief description of my problem: I am solving a MIP, one of the constraints is : sum_j{a[i][j]x[i][j]} =1 for all i.
    I solve the MIP with different discrete values of a parameter d in set D, and the a[i][j] values change depending on d.
    Now, I solve the MIP with my Lagrangean Relaxation (LR) implementation. So, to summarize, I choose different d values, construct a[i][j] matrix and call my routine exec(...), with necessary paparemeter to run LR. Since I don't want to construct my Lagrangean LB and UB models in each iteration, I construct them once and my idea is to set the a[i][j] values using setLinearCoef.
    I am giving my pseudocode and some code snippets, avoiding pasting numerous lines of code at the beginning. Please suggest if some error is there in the flow.

    //construct LR problem's LB and UB model
    ....
    //here I am constructing the parameters and adding to LB model for LR (similarly done for UB model)
    {'code'}
    IloExtractableArray eq_lb_arr(env_lb1,num_h); //initialize iloextractable array.
    for(int i=0;i<num_h;i++){
    IloExpr expr(env_lb1);
    for(int j = 0; j < num_s; j++) {
    expr+= x[i][j];
    }
    IloRange r_lb1(env_lb1,1,expr,1);
    eq_lb_arr[i] = r_lb1;
    model_lb1.add(eq_lb_arr[i]);
    }
    {'code'}
    ....
    //here is the outer loop..(pseudo code)
    for each d in D
    {
    A_matrix <- makeAmatrix(); // construct a[i][j] matrix, depending on d value
    exec(A_matrix,...other params)
    }

    Now inside exec(), setting coeffs as follows:
    
    
    
    for(
    
    int i=0;i<num_habitat;i++)
    { 
    
    for(
    
    int j=0;j<num_shelter;j++)
    { IloRange r1(dynamic_cast<IloRangeI *>(r_lb1[i].getImpl())); IloRange r2(dynamic_cast<IloRangeI *>(r_ub[i].getImpl())); r1.setLinearCoef(x[i][j], A_matrix[i][j]); r2.setLinearCoef(x_ub[i][j], A_matrix[i][j]); 
    } 
    }
    


    Then solving the LB, UB models, performing Lagrangean iterations as per algorithm.
    It works fine with the first d in set D, all iterations of LR are correct, so, setLinearCoef() works correctly. But, for the next d value (outer loop), when I construct a next set of a[i][j] values and try to set them within exec() method, I get runtime error! Is there any error in referencing, should I put end() for "eq_lb_arr", r1, r2 or anything missing ???
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Problem with setLinearCoef

    Posted Thu August 16, 2012 12:47 PM

    Originally posted by: JDalal


    One mistake:

    "//here I am constructing the parameters and adding to LB model for LR (similarly done for UB model)"

    Of course, I meant to say "constraints" , not "parameters"... my mistake!
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Problem with setLinearCoef

    Posted Thu August 16, 2012 02:18 PM

    Originally posted by: JDalal


    solved!... some other error, not related to setLinearCoef.
    #CPLEXOptimizers
    #DecisionOptimization