Topic
  • 12 replies
  • Latest Post - ‏2013-04-05T20:51:17Z by SystemAdmin
SystemAdmin
SystemAdmin
7929 Posts

Pinned topic error C2678 ( problem of conversion )

‏2013-04-04T17:20:10Z |
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 ?
Updated on 2013-04-05T20:51:17Z at 2013-04-05T20:51:17Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    7929 Posts

    Re: error C2678 ( problem of conversion )

    ‏2013-04-05T09:27:43Z  
    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]));
    
    Updated on 2014-03-24T22:34:06Z at 2014-03-24T22:34:06Z by iron-man
  • SystemAdmin
    SystemAdmin
    7929 Posts

    Re: error C2678 ( problem of conversion )

    ‏2013-04-05T11:11:51Z  
    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
    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr">IloRound(cplex.getValue(x[j][0])); </pre>
    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" ;   
    }
    


    ^^
  • SystemAdmin
    SystemAdmin
    7929 Posts

    Re: error C2678 ( problem of conversion )

    ‏2013-04-05T11:49:42Z  
    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 :
    <pre class="jive-pre"> 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); } </pre>

    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 :
    <pre class="jive-pre"> typedef IloArray<IloNumVarArray> NumVarMatrix; NumVarMatrix x(env, nbjobs); for (j = 0; j < nbjobs; j++) { x[j] = IloNumVarArray(env, nbjobs, 0.0, 1.0, ILOFLOAT); } </pre>
    //for p :
    <pre class="jive-pre"> 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" ; } </pre>

    ^^
    i used IloConversion , for convert X[i][1] to an integer , because when i sum X[i][1] without conversion , i have an error !!!
  • SystemAdmin
    SystemAdmin
    7929 Posts

    Re: error C2678 ( problem of conversion )

    ‏2013-04-05T15:42:33Z  
    i used IloConversion , for convert X[i][1] to an integer , because when i sum X[i][1] without conversion , i have an error !!!
    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.
  • SystemAdmin
    SystemAdmin
    7929 Posts

    Re: error C2678 ( problem of conversion )

    ‏2013-04-05T16:16:44Z  
    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.
    :-(
    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 !!
  • SystemAdmin
    SystemAdmin
    7929 Posts

    Re: error C2678 ( problem of conversion )

    ‏2013-04-05T17:10:46Z  
    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.
    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)

    :-( :-(
    Updated on 2014-03-24T22:31:56Z at 2014-03-24T22:31:56Z by iron-man
  • SystemAdmin
    SystemAdmin
    7929 Posts

    Re: error C2678 ( problem of conversion )

    ‏2013-04-05T17:11:30Z  
    :-(
    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 !!
    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.
    Updated on 2014-03-24T22:31:51Z at 2014-03-24T22:31:51Z by iron-man
  • SystemAdmin
    SystemAdmin
    7929 Posts

    Re: error C2678 ( problem of conversion )

    ‏2013-04-05T17:13:59Z  
    i try this code for writing constraint :

    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr">IloExpr expr(env); for (int k=0;k<nbjobs;k++) { for (int i = 0; i <nbjobs; i++) { exp +=x[i][k] ; } } </pre>

    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)

    :-( :-(
    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.
    Updated on 2014-03-24T22:31:47Z at 2014-03-24T22:31:47Z by iron-man
  • SystemAdmin
    SystemAdmin
    7929 Posts

    Re: error C2678 ( problem of conversion )

    ‏2013-04-05T17:19:33Z  
    Do you really have 'exp' in this statement
    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr">exp +=x[i][k]; </pre>
    If so then this is a typo. It should be 'expr'. The rest looks good to me.
    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 ^^^
  • SystemAdmin
    SystemAdmin
    7929 Posts

    Re: error C2678 ( problem of conversion )

    ‏2013-04-05T17:59:55Z  
    Do you really have 'exp' in this statement
    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr">exp +=x[i][k]; </pre>
    If so then this is a typo. It should be 'expr'. The rest looks good to me.
    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!!!
    Updated on 2014-03-24T22:31:42Z at 2014-03-24T22:31:42Z by iron-man
  • SystemAdmin
    SystemAdmin
    7929 Posts

    Re: error C2678 ( problem of conversion )

    ‏2013-04-05T18:03:40Z  
    hello problems :-(

    I finished writing the model , and then Then I wrote :
    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr">IloCplex cplex(model); cplex.solve (); cplex.getStatus (); </pre>

    ( ps : I followed the tutorial )
    when I generate the solution , i have 0 erros , but when i start the debugger , i have this message :
    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr">Unhandled exception in 0x00186c4f in flowshop of permutation.exe: 0xC0000005: Access violation when reading location 0x00000004. </pre>
    I made a screenshot!!!
    screenshot
  • SystemAdmin
    SystemAdmin
    7929 Posts

    Re: error C2678 ( problem of conversion )

    ‏2013-04-05T20:51:17Z  
    Do you really have 'exp' in this statement
    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr">exp +=x[i][k]; </pre>
    If so then this is a typo. It should be 'expr'. The rest looks good to me.
    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