Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  CPLEX inside CLASS

    Posted 03/20/15 06:30 PM

    Originally posted by: AMurshed


    Hello,

    I would like to create a class that has all the constants, variables, and constraints with its objective function in CPLEX with c++ API.

    The skeleton of my code is like this:

    class CS{
    private:
    IloEnv env;IloModel model; IloCplex cplex; IloNumArray3 r1;

    IloNumArrayVar2 rr1;

    public:
       CS()
        {
          env(); model(env); cplex(modl); r1(env, 10); rr1(env,10, 0,20,ILOINT);
            //input r1;  
        }

       void buildModel();
       void output();
    };

    CS::buildModel(){
       //building model
        }

    CS::output(){
       //solve model
       //output results
       }

    /////////////////////////////

    Thanks in advance.


    #DecisionOptimization
    #MathematicalProgramming-General


  • 2.  Re: CPLEX inside CLASS

    Posted 03/22/15 04:03 AM

    And what exactly is your problem/question?

    BTW, your code is just plain wrong C++ code. For example, the implementation of buildModel() and output() are lacking a return value, and the initialization in the constructor should rather look something like this:

    CS()
    : env(), model(env), cplex(model), r1(env, 10), rr1(env, 10, 0, 20, ILOINT)
    {
    }
    


    Also note that you should have a destructor that calls end.end(). Otherwise you will be leaking memory.


    #DecisionOptimization
    #MathematicalProgramming-General


  • 3.  Re: CPLEX inside CLASS

    Posted 03/22/15 06:56 AM

    Originally posted by: AMurshed


    Thanks for the reply Daniel.

    My problem is that, I would like to solve Incremental scheduling model for different networks where a message goes through a number of networks. Hence, I would like to create model class for each network with its own constraints and inputs with objective function and then call their instances from the main program.

    Regarding the return of the functions, (buildModel and output) they are actually void functions where I just wanted to change the variables inside the class and do not want to return something.

    I forgot also to mention the destructor which has the (env.end();).

     

    I couldn't create such model, it gave me a number of errors.

     

    Can you please give me an example on using Class which has all CPLEX objects (variables, constraints, objective function).

     

    Thanks in advance.

     


    #DecisionOptimization
    #MathematicalProgramming-General


  • 4.  Re: CPLEX inside CLASS

    Posted 03/23/15 01:59 AM

    I still don't understand what your issue is. If you fix the C++ errors in the code you posted then this class should give you exactly what you want, or not? What is missing from that class?


    #DecisionOptimization
    #MathematicalProgramming-General