Decision Optimization

Decision Optimization

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


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

Having problem with IloExpr type variable and operand "+="

  • 1.  Having problem with IloExpr type variable and operand "+="

    Posted 03/08/13 05:03 PM

    Originally posted by: SystemAdmin


    I write a function to add constraints to my model.

    void addConstarint(IloEnv env, IloModel &model, IloBoolVarArray y, BoolVarMatrix x)
    /****************************************************/
    /* This function add constarints to the formulation */
    /****************************************************/

    {
    IloExpr constraint(env);
    for (int i = 0; i < nCandidates; i++){
    constraint += y[i];
    }
    cout << constraint << endl;
    model.add(constraint == k);
    for (int j = 0; j < nVoters; j++){
    IloExpr constraint(env);
    for(int i = 0; i < nCandidates; i++){
    constraint+=x[i][j];
    }
    model.add(constraint == 1);
    }
    for(int i = 0; i < nCandidates; i++){
    for (int j = 0; j < nVoters; j++){
    model.add(x[i][j]-y[i] <= 0);
    }
    }
    }

    This is for IP solution and it works fine, but I want to check my LP solution and when I change the type of variables y and x and make them IloNumVarArray and NumVarMatrix in order to get the fractional solution, I got the following error when it reached to line "constraint += y[i];":
    Error :"No source available for "operator+() "

    This is my function for adding constraint to LP model :
    void addConstarintLP(IloEnv env, IloModel &model, IloNumVarArray y, NumVarMatrix x)
    /***********************************************************/
    /* This function add constarints to the formulation for LP */
    /***********************************************************/

    {
    IloExpr constraint(env);
    IloBoolVar v;
    constraint = constraint + v;
    for (int i = 0; i < nCandidates; i++){
    constraint += y[i];
    }
    cout << constraint << endl;
    model.add(constraint == k);
    for (int j = 0; j < nVoters; j++){
    IloExpr constraint(env);
    for(int i = 0; i < nCandidates; i++){
    constraint+=x[i][j];
    }
    model.add(constraint == 1);
    }
    for(int i = 0; i < nCandidates; i++){
    for (int j = 0; j < nVoters; j++){
    model.add(x[i][j]-y[i] <= 0);
    }
    }
    }
    Can someone help me? what is my mistake or what did I forget?
    Thank you.
    #DecisionOptimization
    #MathematicalProgramming-General


  • 2.  Re: Having problem with IloExpr type variable and operand "+="

    Posted 03/11/13 04:21 AM

    Originally posted by: SystemAdmin


    That is a strange error message. How did you define BoolVarMatrix and NumVarMatrix?
    What version of CPLEX do you use? What is your OS?
    #DecisionOptimization
    #MathematicalProgramming-General


  • 3.  Re: Having problem with IloExpr type variable and operand "+="

    Posted 03/11/13 01:06 PM

    Originally posted by: SystemAdmin


    This is how I define the BoolVarMatrix and NumVarMatrix
    \{
    typedef IloArray<IloBoolVarArray> BoolVarMatrix;
    typedef IloArray<IloNumVarArray> NumVarMatrix;
    \}

    My cplex version is 12.2 and I run my program under both MAC OS and Linux (CentOS).
    #DecisionOptimization
    #MathematicalProgramming-General


  • 4.  Re: Having problem with IloExpr type variable and operand "+="

    Posted 03/12/13 03:02 AM

    Originally posted by: SystemAdmin


    With that definition your code works fine here.
    Could you try to write a minimal example and post that verbatim here?
    #DecisionOptimization
    #MathematicalProgramming-General


  • 5.  Re: Having problem with IloExpr type variable and operand "+="

    Posted 03/12/13 03:29 AM

    Originally posted by: SystemAdmin


    Sorry, but what do you mean by minimal example?
    #DecisionOptimization
    #MathematicalProgramming-General


  • 6.  Re: Having problem with IloExpr type variable and operand "+="

    Posted 03/12/13 01:38 PM

    Originally posted by: SystemAdmin


    I create a simple example which end up with error:
    '{

    #include <iostream>
    #include <ilcplex/ilocplex.h>

    ILOSTLBEGIN

    int main()
    {

    IloEnv env;
    try
    {
    IloModel model(env);
    IloNumVarArray y(env,3);
    IloExpr e(env);
    e = y[0];
    }
    catch (IloException& e)
    {
    cerr << "Concert exception caught: " << e << endl;
    }
    catch (...)
    {
    cerr << "Unknown exception caught" << endl;
    }
    env.end();
    return 0;
    }

    '}
    The error is :
    No source available for "IloExpr::IloExpr() "

    but if I change the code to the following, it is OK!

    '{

    #include <iostream>
    #include <ilcplex/ilocplex.h>

    ILOSTLBEGIN

    int main()
    {

    IloEnv env;
    try
    {
    IloModel model(env);
    IloNumVar y(env);
    IloExpr e(env);
    e = y;
    }
    catch (IloException& e)
    {
    cerr << "Concert exception caught: " << e << endl;
    }
    catch (...)
    {
    cerr << "Unknown exception caught" << endl;
    }
    env.end();
    return 0;
    }
    '}
    #DecisionOptimization
    #MathematicalProgramming-General


  • 7.  Re: Having problem with IloExpr type variable and operand "+="

    Posted 03/12/13 01:46 PM

    Originally posted by: SystemAdmin


    I create a simple example which end up with error:
    '{
    #include <iostream>
    #include <ilcplex/ilocplex.h>

    ILOSTLBEGIN

    int main()
    {

    IloEnv env;
    try
    {
    IloModel model(env);
    IloNumVarArray y(env,3);
    IloExpr e(env);
    e = y[0];
    }
    catch (IloException& e)
    {
    cerr << "Concert exception caught: " << e << endl;
    }
    catch (...)
    {
    cerr << "Unknown exception caught" << endl;
    }
    env.end();
    return 0;
    }

    }'
    The error is :
    No source available for "IloExpr::IloExpr() "

    but if I change the code to the following, it is OK!

    '{
    #include <iostream>
    #include <ilcplex/ilocplex.h>

    ILOSTLBEGIN

    int main()
    {

    IloEnv env;
    try
    {
    IloModel model(env);
    IloNumVar y(env);
    IloExpr e(env);
    e = y;
    }
    catch (IloException& e)
    {
    cerr << "Concert exception caught: " << e << endl;
    }
    catch (...)
    {
    cerr << "Unknown exception caught" << endl;
    }
    env.end();
    return 0;
    }
    }'
    #DecisionOptimization
    #MathematicalProgramming-General


  • 8.  Re: Having problem with IloExpr type variable and operand "+="

    Posted 03/12/13 02:35 PM

    Originally posted by: SystemAdmin


    The following code also works fine on my computer!! I only change the IloNumVarArray to IloBoolVarArray !

    '{#include <iostream>
    #include <ilcplex/ilocplex.h>

    ILOSTLBEGIN

    int main()
    {
    IloEnv env;
    try
    {
    IloModel model(env);
    IloBoolVarArray y(env,3);
    IloExpr e(env);
    e = y[0];
    }
    catch (IloException& e)
    {
    cerr << "Concert exception caught: " << e << endl;
    }
    catch (...)
    {
    cerr << "Unknown exception caught" << endl;
    }
    cout << "helllo" << endl;
    env.end();
    return 0;
    } }'
    #DecisionOptimization
    #MathematicalProgramming-General


  • 9.  Re: Having problem with IloExpr type variable and operand "+="

    Posted 03/13/13 02:38 AM

    Originally posted by: SystemAdmin


    All the code examples you provided compile without problem here.
    Can you please specify exactly what machine and OS you use and show us the full compiler command line you use as well as the full compiler output?
    #DecisionOptimization
    #MathematicalProgramming-General


  • 10.  Re: Having problem with IloExpr type variable and operand "+="

    Posted 03/13/13 05:26 PM

    Originally posted by: SystemAdmin


    My machine is OPTIPLEX 755 and my OS is Linux (CentOS), but I have the same problem on my MacBookpro with Lion as an OS. The compiling procedure is fine, but when I run ./mycode, I get "Segmentation fault (core dumped)". By the way How can I format the code nicely, I do '{code}', but it seems it is not working.
    #DecisionOptimization
    #MathematicalProgramming-General


  • 11.  Re: Having problem with IloExpr type variable and operand "+="

    Posted 03/13/13 05:37 PM

    Originally posted by: SystemAdmin


    Do you put the code tag on both sides of the code? (Note that the closing tag is identical to the opening tag, unlike HTML.)

    Paul

    Mathematicians are like Frenchmen: whenever you say something to them, they translate it into their own language, and at once it is something entirely different. (Goethe)
    #DecisionOptimization
    #MathematicalProgramming-General


  • 12.  Re: Having problem with IloExpr type variable and operand "+="

    Posted 03/14/13 02:25 AM

    Originally posted by: SystemAdmin


    Aha, so you get a runtime error (a segmentation fault) and the "no source available for operator+" messages comes from some debugger?

    My first guess for a segmentation fault would that you are either doing an out-of-bounds array access or that you are using an uninitialized Ilo* instance. Did you check both? Maybe the debugger can assist you in checking that. Just displaying a backtrace is often very helpful.
    #DecisionOptimization
    #MathematicalProgramming-General


  • 13.  Re: Having problem with IloExpr type variable and operand "+="

    Posted 03/14/13 09:53 PM

    Originally posted by: SystemAdmin


    I sent you the code, I do not use any uninitialized Ilo*. I also attached the debugger's screenshot.
    #DecisionOptimization
    #MathematicalProgramming-General


  • 14.  Re: Having problem with IloExpr type variable and operand "+="

    Posted 03/19/13 02:27 AM

    Originally posted by: SystemAdmin


    I did not receive any code. Maybe you can just attach the full code here?
    #DecisionOptimization
    #MathematicalProgramming-General


  • 15.  Re: Having problem with IloExpr type variable and operand "+="

    Posted 03/19/13 02:45 AM

    Originally posted by: SystemAdmin


    I already posted the code in this thread, but I post it below

    '{
    #include <iostream>
    #include <ilcplex/ilocplex.h>

    ILOSTLBEGIN

    int main()
    {

    IloEnv env;
    try
    {
    IloModel model(env);
    IloNumVarArray y(env,3);
    IloExpr e(env);
    e = y[0];
    }
    catch (IloException& e)
    {
    cerr << "Concert exception caught: " << e << endl;
    }
    catch (...)
    {
    cerr << "Unknown exception caught" << endl;
    }
    env.end();
    return 0;
    }
    '{
    #DecisionOptimization
    #MathematicalProgramming-General


  • 16.  Re: Having problem with IloExpr type variable and operand "+="

    Posted 03/19/13 03:16 AM

    Originally posted by: SystemAdmin


    From the reference documentation of IloNumVarArray(IloEnv env, int n):
    
    This constructor creates an extensible array of n numeric variables in env. Initially, the n elements are empty handles.
    

    Consequently, in your code the elements in y are just empty handles (not initialized) and trying to assign those uninitialized elements to an IloExpr will throw the exception. You either need to use a constructor that initializes the elements in the array or explicitly initialize them.
    #DecisionOptimization
    #MathematicalProgramming-General