Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  How to use CPXbinvarow.

    Posted 05/22/10 09:05 PM

    Originally posted by: RaguNasu


    I want add gomery cut by myself.
    So I need to use CPXbinvarow.
    But I don't know how to use.
    ILOG Optimization Documentation don't have enough example.
    I want a sample code by c++.(really c++ example)
    My concert is concert21.

    Thanks.
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: How to use CPXbinvarow.

    Posted 05/22/10 11:03 PM

    Originally posted by: QiuFeng


    here is the function in my code printing tableau, hope it help.
    int OptModel::printTableau(string tableauFileName)
    {
                    int num_rows = CPXgetnumrows(cpxenv,  cpxlp);
                    int num_cols  = CPXgetnumcols(cpxenv,  cpxlp) ; // need to know why
                    int surplus;
                    vector<string> varNames;
     
                    int status = CPXgetcolname (cpxenv, cpxlp, NULL, NULL, 0, &surplus, 0,num_cols-1);
                    int cur_colnamespace = - surplus;
                    if ( cur_colnamespace > 0 ) {
                            char          **cur_colname      = (char **) malloc (sizeof(char *)*(num_cols));
                            char          *cur_colnamestore = (char *)  malloc (cur_colnamespace);
                            if ( cur_colname      == NULL ||
                                    cur_colnamestore == NULL   ) {
                                            fprintf (stderr, "Failed to get memory for column names.\n");
                                            status = -1;
                                            cout<< endl <<" error in printTableau"<<endl;
                                            return 0;
                            }
                            status = CPXgetcolname (cpxenv, cpxlp, cur_colname, cur_colnamestore, 
                                    cur_colnamespace, &surplus, 0, num_cols-1);
                            // map name with column index
                            for (int i = 0; i <num_cols ; i ++)
                            {
                                    string varName = cur_colname[i];
                                    varNames.push_back(varName);
                            }
                            free_and_null(cur_colname);
                            // free_and_null((char **)&cur_colnamestore);
     
                    }
     
                    /***************get head ****************************/
                    int* head = new int[num_rows]; // head is the 0-th column of the tableau
                    double *head_val = new double[num_rows];
                    status = CPXgetbhead (cpxenv, cpxlp, head, head_val);
     
                    ofstream log(tableauFileName.c_str() ,ios_base::app);
                    streambuf * old_buf = std::cout.rdbuf(log.rdbuf()); 
     
                    double *objval_p = new double;
                    status = CPXgetobjval(cpxenv, cpxlp,  objval_p);
                    cout<<"objective value, " << *objval_p<<endl;
     
                    double* tabealu;
                    tabealu = (double*)malloc(num_rows*num_cols*sizeof(double));
                    for (int i = 0; i < num_rows; i++)
                    {
                            CPXbinvarow(cpxenv, cpxlp, i, tabealu+i*num_cols);
                    }
     
                    cout << endl;
                    cout << "Tableau, x, " ;
                    for ( int j = 0; j < num_cols ; j ++)
                    {
                            cout << varNames[j] << ", ";
                    }
                    cout << endl;
                    for (int i = 0; i < num_rows; i++)
                    {
                            if (head[i] < 0)
                            {
                                    cout << head[i] <<", " << head_val[i]<< ", ";
                            }
                            else{
                                    cout << varNames[head[i]] <<", " << head_val[i]<< ", ";
                            }
                            for (int j = 0; j < num_cols ; j ++)
                            {
                                    cout << tabealu[i*num_cols +j] << ", " ;
                            }
                            cout<<endl;
                    }
                    cout << endl;
                    cout.rdbuf( old_buf);
     
                    delete []head;
                    delete []head_val;
                    delete objval_p;
                    free_and_null((char**) &tabealu);
                    return 1;
     
    }
    

    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: How to use CPXbinvarow.

    Posted 05/22/10 11:05 PM

    Originally posted by: QiuFeng


    sorry, I didn't notice that you want a c++ example, I haven't found the corresponding functions in Concert.
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: How to use CPXbinvarow.

    Posted 05/22/10 11:34 PM

    Originally posted by: RaguNasu


    IS cpxlp ILOCPLEX or ILOMODEL?
    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: How to use CPXbinvarow.

    Posted 05/24/10 03:12 AM

    Originally posted by: QiuFeng


    it's IloCplex.
    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: How to use CPXbinvarow.

    Posted 05/24/10 03:14 AM

    Originally posted by: QiuFeng


    I should say, it's CPXLPptr which corresponds to IloCplex
    #CPLEXOptimizers
    #DecisionOptimization