Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  invalid operands to binary expression ('double' and 'IloNumVarArray')

    Posted 04/11/18 07:11 PM

    Originally posted by: JoeBen


    I don't understand why I get this error  : invalid operands to binary expression ('double' and 'IloNumVarArray') ? in this line:

    model.add(0.9*Pg[i]=Plac[i]+Pex[i]*0.8-0.9*Pwt[i]);
    

    and Here is my code :

    #include <stdio.h>
    #include <string.h>
    #include <ilcplex/ilocplex.h>
    #include <ilcplex/ilocplexi.h>
    #include <ilconcert/iloenv.h>
    #include <ilcplex/cplex.h>
    #include <iomanip>
    #include <iostream>
    #include <fstream>
    #include <sstream>
    #include <time.h>
    #include <vector>
    #include <assert.h>
    
    int main(int argc, char** argv){
    
            //déclaration des trois classes principales
    
            IloEnv env; // environnement : permet d utiliser les fonctions de Concert Technology
            IloModel model(env); // modèle : représente le programme linéaire
            IloCplex cplex (model); // classe Cplex : permet d 'accéder aux fonctions d'optimisation
    
            std::ifstream infile("/Users/nabil/Desktop/input.txt");
    
        if(!infile.is_open())
                    {
                    //if file is not opened
                            std::cout<<"Error opening the file"<< std::endl;
    
                    }
    
        if (infile.is_open())
        {
            std::string line;
            std::getline(infile, line);  // skip first line
    
            std::vector<float> Ppv_max;
            std::vector<float> Pwt_max;
            std::vector<float> Pb_max;
            std::vector<float> Plac_max;
            std::vector<float> Pldc_max;
            std::vector<float> Pg_max;
            std::vector<float> Pex_max;
            std::vector<int> Time;
    
    
            //déclaration des trois classes principales
            IloEnv env; // environnement : permet d utiliser les fonctions de Concert Technology
            IloModel model(env); // modèle : représente le programme linéaire
            IloCplex cplex (model); // classe Cplex : permet d 'accéder aux fonctions d'optimisation
            // ----------------------- VARIABLES ----------------------- //déclaration de 2 variables
    
    
    
    
    
            while (std::getline(infile, line))
            {
    
                float temp;
                std::stringstream ss(line);
    
                ss >> temp; // column A
                Time.push_back(temp);
    
                ss >> temp; // column A
                Ppv_max.push_back(temp);
    
                ss >> temp; // column B
                Pwt_max.push_back(temp);
    
                ss >> temp; // column C
                Pb_max.push_back(temp);
    
                ss >> temp; // column A
                Time.push_back(temp);
    
                ss >> temp; // column A
                Plac_max.push_back(temp);
    
                ss >> temp; // column B
                Pldc_max.push_back(temp);
    
                ss >> temp; // column C
                Pg_max.push_back(temp);
    
                ss >> temp; // column C
                Pex_max.push_back(temp);
    
    
            }
            // your product vectors are now populated and you can
            // do whatever you need with the column data here
    
            IloArray<IloFloatVarArray> Ppv(env,(int)Time.size());
            IloArray<IloFloatVarArray> Pwt(env,(int)Time.size());
            IloArray<IloFloatVarArray> Pb(env,(int)Time.size());
            IloArray<IloFloatVarArray> Plac(env,(int)Time.size());
            IloArray<IloFloatVarArray> Pldc(env,(int)Time.size());
            IloArray<IloFloatVarArray> Pg(env,(int)Time.size());
            IloArray<IloFloatVarArray> Pex(env,(int)Time.size());
    
            for(int i=0; i<(int)Time.size(); i++)
            {
    
                    Ppv[i] = IloFloatVarArray(env,(int)Time.size(),0,Ppv_max[i]);
                    Pwt[i] = IloFloatVarArray(env,(int)Time.size(),0,Pwt_max[i]);
                    Pb[i] = IloFloatVarArray(env,(int)Time.size(),0,Pb_max[i]);
                    Plac[i] = IloFloatVarArray(env,(int)Time.size(),0,Plac_max[i]);
                    Pldc[i] = IloFloatVarArray(env,(int)Time.size(),0,Pldc_max[i]);
                    Pg[i] = IloFloatVarArray(env,(int)Time.size(),0,Pg_max[i]);
                    Pex[i] = IloFloatVarArray(env,(int)Time.size(),0,Pex_max[i]);
    
        }
    
       for (int i = 0; i < (int)Time.size(); i++)
        {
       IloNum Epsilon_G, epsilon_in, epsilon_WT;
        model.add(0.9*Pg[i]=Plac[i]+Pex[i]*0.8-0.9*Pwt[i]); 
        model.add(Ppv[i]=Pwt[i]);
         }
    
       for (int i = 0; i < (int)Time.size(); i++)
                  {
    
                    std::cout << ":" << Ppv[i]<< std::endl;
    
                  }
    
            env.end(); //libération de l'environnement
    
        }
        }
    
    
    

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: invalid operands to binary expression ('double' and 'IloNumVarArray')

    Posted 04/11/18 07:30 PM

    Could it be that you are just missing an extra "=" in your expression?

     

    That is, instead of:

    model.add(0.9*Pg[i]=Plac[i]+Pex[i]*0.8-0.9*Pwt[i]);
    

    use:

    model.add(0.9*Pg[i]==Plac[i]+Pex[i]*0.8-0.9*Pwt[i]);
    

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: invalid operands to binary expression ('double' and 'IloNumVarArray')

    Posted 04/11/18 07:34 PM

    Originally posted by: JoeBen


    Thanks for your quick answer and I did but I get the same error is very strange?!
     


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: invalid operands to binary expression ('double' and 'IloNumVarArray')

    Posted 04/11/18 07:41 PM

    Just to be sure, did you fix the line below it too?

     

    Replace:

    model.add(Ppv[i]=Pwt[i]);
    

    with

    model.add(Ppv[i]==Pwt[i]);
    

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: invalid operands to binary expression ('double' and 'IloNumVarArray')

    Posted 04/11/18 07:46 PM

    Originally posted by: JoeBen


    Now I get another second error  :

     

    invalid operands to binary expression ('IloNumVarArray' and 'IloNumVarArray')


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: invalid operands to binary expression ('double' and 'IloNumVarArray')

    Posted 04/12/18 02:35 PM

    In lines 119 and 120, you seem to be trying to add constraints of the form "array == array" (or "array == array expression"). It's been a long time since I used the C++ API, so I might be wrong, but I don't think it supports expression like that. You may need to loop over the arrays and add something like Ppv[i][j] == Pwt[i][j] for each j.


    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: invalid operands to binary expression ('double' and 'IloNumVarArray')

    Posted 04/12/18 02:44 PM

    Originally posted by: JoeBen


    Thanks for the answer, but I have only one column data for each variable so I can't do Pp[i][j], so I can do only Ppv[i]? So I should loop just one time not two...


    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: invalid operands to binary expression ('double' and 'IloNumVarArray')

    Posted 04/12/18 02:52 PM

    The line

    Ppv[i] = IloFloatVarArray(env,(int)Time.size(),0,Ppv_max[i]);
    

    indicates that, for each i, Ppv[i] is a vector of variables, not a single variable. If you want PPv[i] to be a single variable, why are you declaring it this way?


    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: invalid operands to binary expression ('double' and 'IloNumVarArray')

    Posted 04/12/18 03:40 PM

    Originally posted by: JoeBen


    Thanks, because Im very beginner in cplex and C++, do you have any suggestion to correct this?


    #CPLEXOptimizers
    #DecisionOptimization


  • 10.  Re: invalid operands to binary expression ('double' and 'IloNumVarArray')

    Posted 04/12/18 03:52 PM

    I think you want to define Ppv to be IloFloatVarArray rather than IloArray<IloFloatVarArray>, specify the size and bounds in that statement, and get rid of the for loop where you're doing definitions. (Also do the same for the other variables.)


    #CPLEXOptimizers
    #DecisionOptimization


  • 11.  Re: invalid operands to binary expression ('double' and 'IloNumVarArray')

    Posted 04/13/18 07:59 AM

    Originally posted by: JoeBen


    Thanks, I don't get you really can you provide me a simple example code of the use and declaration of IloFloatVarArray with one loop?


    #CPLEXOptimizers
    #DecisionOptimization


  • 12.  Re: invalid operands to binary expression ('double' and 'IloNumVarArray')

    Posted 04/13/18 03:29 PM

    Actually, I may be wrong about your needing a loop at all. Take a look at some of the C++ example files that come with CPLEX (such as blend.cpp). They use IloNumVarArray (which I suspect is what you should be using) rather than IloFloatVarArray, but in any case they should be informative.


    #CPLEXOptimizers
    #DecisionOptimization