Decision Optimization

Decision Optimization

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


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

error C2678 ( problem of conversion )

  • 1.  error C2678 ( problem of conversion )

    Posted 04/04/13 01:20 PM

    Originally posted by: SystemAdmin


    Hi ;
    when i compile this code :
    ////////////////////////////////////////////////////////
    IloInt som =0 ;

    for (k=0 ; k<nbmachines-1;k++)
    {for (j=0 ;j<nbjobs;j++)
    { IloConversion conversion = IloConversion (env ,x[j][0] ,ILOINT ) ;
    som = som + conversion ;

    }
    }
    //////////////////////////////////////////
    i have this error :

    1>.\shop.cpp(61) : error C2678: '+' binaire : aucun opérateur trouvé qui accepte un opérande de partie gauche de type 'IloInt' (ou il n'existe pas de conversion acceptable)
    !!!!!!!
    what can i do to solve it ?
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: error C2678 ( problem of conversion )

    Posted 04/05/13 05:28 AM

    Originally posted by: SystemAdmin


    The preferred language on this Forum is English, so to obtain best help you should translate the error messages into English :-) Luckily, I know enough French to understand it anyway.
    What are you trying to do with the IloConversion object? An IloConversion changes the type of a variable in an optimization model. It does not make any sense to sum up objects of type IloConversion.
    Are you trying to round or truncate the value of the variables? In that case you need to do
    IloRound(cplex.getValue(x[j][0]));
    

    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: error C2678 ( problem of conversion )

    Posted 04/05/13 07:12 AM

    Originally posted by: SystemAdmin


    Hello ^^
    sorry I forgot to translate the error message ^ ^ ( ps : I'm not very good in english :/ i speak frech )

    What i want to do is :
    1 / calculate the sum of I nbmachines[i] , where i=1...nbjobs-1

    I is an array of variable , for exemple , if nbjobs=3, and nbmachines=3 , then we have an array of 2 dimension ( number of line=nbmachines and number of column=nbjobs ), and each case ( I[1][1],I[1][2],I[1][3],I[2][1],I[2][2],I[2][3], I[3][1],I[3][2],I[3][3] ) , is a variable whose its value is between 0 and 10000

    so in my program i wrote :
    
    typedef IloArray<IloNumVarArray> NumVarMatrix; NumVarMatrix  I(env, nbmachines-1); 
    
    for (j = 0; j < nbmachines-1; j++) 
    { I[j] = IloNumVarArray (env,nbjobs-1,0,100000,ILOFLOAT); 
    }
    


    2 / i want to calculate :
    double sum of (x [i][1] time p[i][j] ) ,for i=1..nbjobs , and j=1..nbmachines-1

    such that :
    x is an array of variable , like I , of 2 dimension (number of line =nbjobs ,number of column =nbjobs)
    and p[i][j] is a constante array of 2 dimension
    in my code i have :

    // for x :
    
    typedef IloArray<IloNumVarArray> NumVarMatrix; NumVarMatrix x(env, nbjobs); 
    
    for (j = 0; j < nbjobs; j++) 
    { x[j] = IloNumVarArray(env, nbjobs, 0.0, 1.0, ILOFLOAT); 
    }
    

    //for p :
    
    
    
    int tab[nbjobs][nbmachines]; 
    
    for (k=0;k<nbmahines;k++) 
    {
    
    for (j=0;j<nbjobs;j++) 
    {   tab [j][k]=rand()%99; cout << tab[j][k] <<
    " "; 
    } cout << 
    " " << 
    "\n" ;   
    }
    


    ^^
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: error C2678 ( problem of conversion )

    Posted 04/05/13 07:50 AM

    Originally posted by: SystemAdmin


    i used IloConversion , for convert X[i][1] to an integer , because when i sum X[i][1] without conversion , i have an error !!!
    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: error C2678 ( problem of conversion )

    Posted 04/05/13 11:43 AM

    Originally posted by: SystemAdmin


    It is still not clear to me. There are two different kind of sums you can build:
    1. You can sum up instances of IloNumVar. The result is an instance of IloExpr and that sum can be used in a model to define constraints. To create such a sum you can directly sum up the variables x.
    2. You can sum up the values that a solve() found for variables. The result is a plain number. To get the value of a variable you need to use function IloCplex::getValue().
    You can not sum up instances of IloNumVar to obtain a plain number.

    Maybe it is a good idea to look at the tutorials and the examples that come with the CPLEX distribution to get a better idea about how things work. In particular this chapter may be helpful.
    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: error C2678 ( problem of conversion )

    Posted 04/05/13 12:17 PM

    Originally posted by: SystemAdmin


    :-(
    Listen I am a beginner, so sorry :/

    I have a formulation of a problem, I defined variables, as I have already said, and it remains to write the constraints and the objective function.

    for the objective function ,it is composed of the two sums that I wrote earlier, so as I am a beginner ,I don't know how to interpret it,
    I think you know better than me what to do ..

    it 's the same for constraints

    is it clear now ? :-(

    ps :
    for the tutorial, I will see it now !!
    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: error C2678 ( problem of conversion )

    Posted 04/05/13 01:12 PM

    Originally posted by: SystemAdmin


    OK, much clearer now.
    As you will see in the tutorials, you need to use IloExpr instead of IloInt for the sum. For the code from your initial post you would do
    IloExpr som(env);
     
    for (k=0 ; k<nbmachines-1;k++) {
      for (j=0 ;j<nbjobs;j++) {
        som += x[j][0]; // or som += x[j][0] * p[j][0] for constants p[j][0]
      }
    }
    

    and to add the constraint to an instance of IloModel:
    model.add(som <= 1); // requires som to be less than or equal to 1
    som.end();           // destructs som (releases memory)
    

    This would add the constraint
    x[0][0] + x[0][1] + ... + x[0][njobs-1] + ... + x[nmachines-1][njobs-1] <= 1
    

    to your model.
    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: error C2678 ( problem of conversion )

    Posted 04/05/13 01:11 PM

    Originally posted by: SystemAdmin


    i try this code for writing constraint :

    IloExpr expr(env);
    for (int k=0;k<nbjobs;k++)
    {
    for (int i = 0; i <nbjobs; i++)
    {
            exp +=x[i][k] ;
    }
    }
    


    and i have this error :
    1>.\shop.cpp(61) : error C2677: '+=' binary: no global operator found which accepts the type 'IloNumVar' (or there is no acceptable conversion)

    :-( :-(
    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: error C2678 ( problem of conversion )

    Posted 04/05/13 01:14 PM

    Originally posted by: SystemAdmin


    Do you really have 'exp' in this statement
    exp +=x[i][k];
    

    If so then this is a typo. It should be 'expr'. The rest looks good to me.
    #CPLEXOptimizers
    #DecisionOptimization


  • 10.  Re: error C2678 ( problem of conversion )

    Posted 04/05/13 01:20 PM

    Originally posted by: SystemAdmin


    oups :$

    I wrote exp instead of expr

    i think that i understand now ^^ , think's a lot

    I hope find you here if I block again ^^^
    #CPLEXOptimizers
    #DecisionOptimization


  • 11.  Re: error C2678 ( problem of conversion )

    Posted 04/05/13 02:00 PM

    Originally posted by: SystemAdmin


    hello problems :-(

    I finished writing the model , and then Then I wrote :
    IloCplex cplex(model);
    cplex.solve ();
    cplex.getStatus ();
    


    ( ps : I followed the tutorial )
    when I generate the solution , i have 0 erros , but when i start the debugger , i have this message :
    Unhandled exception in 0x00186c4f in flowshop of permutation.exe: 0xC0000005: Access violation when reading location 0x00000004.
    

    I made a screenshot!!!
    #CPLEXOptimizers
    #DecisionOptimization


  • 12.  Re: error C2678 ( problem of conversion )

    Posted 04/05/13 02:04 PM

    Originally posted by: SystemAdmin


    screenshot
    #CPLEXOptimizers
    #DecisionOptimization


  • 13.  Re: error C2678 ( problem of conversion )

    Posted 04/05/13 04:51 PM

    Originally posted by: SystemAdmin


    ps : my full program is

    
    #include 
    "ilcplex\ilocplex.h" #include <stdlib.h> #include <time.h > #include <stdio.h> #include <iostream> using namespace std ; typedef IloArray<IloNumVarArray> NumVarMatrix;       ILOSTLBEGIN   
    
    int main(
    
    int argc, char** argv) 
    { srand(time(NULL)); IloEnv env; IloInt nbjobs=5; IloInt nbmachines=2; IloInt j,k; 
    
    int tab[5][2]; cout << 
    "la matrice des temsp de traitement est " << endl ; 
    
    for (k=0;k<2;k++) 
    {
    
    for (j=0;j<5;j++) 
    {   tab [j][k]=rand()%99; cout << tab[j][k] <<
    " "; 
    } cout << 
    " " << 
    "\n" ;   
    } IloModel model(env); 
    ///////////////////////////////////////////////////////////////////////////////////////// 
    // création des variables  NumVarMatrix x(env, nbjobs); 
    // création de [.,.,.,.,.] NumVarMatrix  I(env, nbmachines-1); NumVarMatrix  w(env, nbmachines-1); 
    
    for (j = 0; j < nbjobs; j++) 
    { x[j] = IloNumVarArray(env, nbjobs, 0,1, ILOINT); 
    } 
    
    for (j = 0; j < nbmachines-1; j++) 
    { I[j] = IloNumVarArray (env,nbjobs-1,0,100000,ILOFLOAT); w[j] = IloNumVarArray (env,nbjobs-1,0,100000,ILOFLOAT) ; 
    }   
    /////////////////////////////////////////////////////////////////////////////////// IloExpr expr(env); 
    
    for (
    
    int k=0;k<nbjobs;k++) 
    { 
    
    for (
    
    int i = 0; i <nbjobs; i++) 
    { expr +=x[i][k] ; 
    } model.add(expr == 1); expr.end(); 
    } IloExpr expr1(env);   
    
    for (
    
    int i = 0; i <nbjobs; i++) 
    { 
    
    for (
    
    int k=0;k<nbjobs;k++) 
    { expr1 +=x[i][k] ; 
    } model.add(expr1 == 1); expr1.end(); 
    }   IloExpr expr2(env); 
    
    for (
    
    int k=0;k<nbjobs-1;k++) 
    { expr2 =I[1][k] ; model.add(expr2 == 0); expr2.end(); 
    }   IloExpr expr3(env); 
    
    for (
    
    int k=0;k<nbmachines-1;k++) 
    { expr3 =w[k][1] ; model.add(expr3 == 0); expr3.end(); 
    } IloExpr expr4(env); IloExpr expr5(env); IloExpr expr6(env); IloExpr expr7(env); 
    
    for (
    
    int j=0;j<nbmachines-1;j++) 
    { 
    
    for (
    
    int k=0;k<nbjobs-1;k++) 
    {
    
    for (
    
    int i=0;i<nbjobs;i++) 
    { expr4 +=x[i][k+1]*tab[i][j] ; expr6 += x[i][k]*tab[i][j+1]; 
    } expr5 = expr4 + w[j][k+1]+I[j][k]; expr7=expr6+w[j][k]+I[j+1][k] ; model.add(expr5 == expr7); expr4.end(); expr5.end(); expr6.end(); expr7.end(); 
    } 
    } 
    ///////////////////////////////////////////////////////////////////////////  IloExpr expr8(env);   
    
    for (
    
    int i = 0; i <nbjobs; i++) 
    { 
    
    for (
    
    int j=0;j<nbmachines-1;j++) 
    { expr8 +=x[i][1]*tab[i][j] ; 
    } 
    } IloExpr expr9(env); 
    
    for (
    
    int i=0;i<nbjobs-1;i++) 
    { expr9 +=I[nbmachines][i]; 
    } model.add(IloMinimize(env, expr8+expr9)); expr8.end(); expr9.end();   
    ///////////////////////////////////////////////////////////////////////////// IloCplex cplex(model); cplex.solve (); cplex.getStatus ();   env.end(); system (
    "pause"); 
    } 
    // END main
    

    #CPLEXOptimizers
    #DecisionOptimization