Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Error when adding constraints using cplex in java

    Posted 04/21/18 06:42 PM

    Originally posted by: Ahlem


    Hello, 

    I have two problems:

    The first one is that i can't get the product of two integers variable with the cplex.prod command. Is there another command that I can use?

    And the second  one is when i add a constraint between two expressions of type IloLinearNumExpr with the command cplex.addLe. Is there another command that I can use?

      (I add my code)  
        //the first problem 
        
        int x[][][] = new int[job][][];
        for (int i = 0; i < job; i++) { //Initialize p[i][j][k]
    
                                            int[][] MatBinaire = MG.get(m).get(i).getMatrice();
                                            int[][] mat = benchmrak.get(i).getMatrice();
                                            int[][][] p = new int[job][MG.get(m).get(i).getX()][MG.get(m).get(i).getY()];
                                            
                                            for (int j = 0; j < MG.get(m).get(i).getX(); j++) {
                                                    
                                                    for (int k = 0; k < ressource; k++) {
    
                                                            if (MatBinaire[j][k] ==1) {
    
                                                                    int duree = mat[j][k];
                                                                    p[i][j][k] = duree;
                                                            }
                                                            
                                                            if (MatBinaire[j][k] == 1) {
                                                                    x[i][j][k] = 1;
    
                                                            } else {
                                                                    x[i][j][k] = 0;
                                                            }
                                                            
                                                            IloLinearNumExpr expr = cplex.linearNumExpr();  
                                                            expr.addTerm(1.0, c[i][j][k]);
                                                            cplex.addGe(expr,
                                                                            cplex.sum(s[i][j][k], p[i][j][k] ,
                                                                                            cplex.prod(-(1-x[i][j][k]), L))); //here the problem of prod
                                                    }
                                                    
                                            }
                                    }
        
        
        //the second problem
        for (int i2 = 0; i2 < job; i2++) {
                                            
                                            IloLinearNumExpr[][][] expr = new IloLinearNumExpr[job][MG.get(m).get(i2).getX()][ressource];
                                            IloLinearNumExpr[][][] expr1 = new IloLinearNumExpr[job][MG.get(m).get(i2).getX()][ressource];
                                            for (int j2 = 0; j2 < MG.get(m).get(i2).getX(); j2++) {
                                                                                                    
                                                    for (int k = 0; k < ressource; k++) {
    
                                                            expr[i2][j2][k] = cplex.linearNumExpr();
                                                            
                                                            for (int i1 = 0; i1 < job; i1++) {
    
                                                                    for (int j1 = 0; j1 < MG.get(m).get(i1).getX(); j1++) {
                                                                    
                                                                            expr[i2][j2][k].addTerm(1.0, y[i1][j1][i2][j2][k]);     
                                                                            expr1[i2][j2][k].addTerm(1.0, y[i2][j2][i1][j1][k]);
                                                                    
                                                                    }
                                                                    
                                                            }
                                                            
                                                            cplex.addLe(expr, expr1); //Constaint there is a problem anywhere 
                                                            
                                                    }
                                            }
                                    }
    

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Error when adding constraints using cplex in java

    Posted 04/22/18 03:23 AM

    In addLe() you are passing arrays of expressions rather than expressions. If you look at the function's signature you will see that it only takes single expressions. So you will have to create a loop that calls addLe() for each pair of expressions.

    In prod() the problem is not with prod() itself but with this expression: -(1 - x[i][j][k]). This is doing arithmetics with integers and objects and that is illegal. You will have to create an IloLinearNumExpr instance to represent this expression, then prod() should work as expected.


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Error when adding constraints using cplex in java

    Posted 04/22/18 04:50 AM

    Originally posted by: Ahlem


    In prod() you mean that i do this ? 

     

    IloLinearNumExpr expr = cplex.linearNumExpr();
    expr.addTerm(-1, 1-x[i][j][k]);
    cplex.addGe(expr, cplex.sum(s[i][j][k], p[i][j][k] ,cplex.prod(expr, L))); 

    But, the method addTerm(double, IloNumVar) in the type IloLinearNumExpr is not applicable for the arguments (int, int).

     

    And for the addLe(), i don't understand you how can i create a loop that calls addLe() for each pair of expressions ? 


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Error when adding constraints using cplex in java

    Posted 04/25/18 05:11 AM

    In '1 - x[i][j][k]' you are still trying to do arithmetic with a number and an object. That is still not supported. To create an expression that represents '-(1 - x[i]j][k])' you can do

    cplex.diff(x[i][j][k], 1.0)

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Error when adding constraints using cplex in java

    Posted 04/25/18 10:08 AM

    Originally posted by: Ahlem


    But the method diff(IloNumExpr, double) in the type IloCplexModeler is not applicable for the arguments (int, double) because x[i][j][k] in our case is int 


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Error when adding constraints using cplex in java

    Posted 04/25/18 10:24 AM

    So x is an array of ints, not an array of IloNumVar? Then you can directly do the arithmetic. It seems I got your initial problem wrong. Can you please elaborate on the initial problem with prod()? What are the types of x and L? What is the exact error message you get?


    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: Error when adding constraints using cplex in java

    Posted 04/25/18 11:00 AM

    Originally posted by: Ahlem


    X and L  are int. The program shows me this error : 

     

    Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    The method prod(int, IloIntExpr) in the type IloCplexModeler is not applicable for the arguments (int, int)

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: Error when adding constraints using cplex in java

    Posted 04/25/18 12:27 PM

    If x and L are both int, then why bother with prod()? Why not just write

    (-(1-x[i][j][k])) * L)

    ?


    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: Error when adding constraints using cplex in java

    Posted 04/25/18 12:59 PM

    Originally posted by: Ahlem


    Because the cplex.sum method becomes incorrect. The method sum(IloNumExpr[], int, int) in the type IloCplexModeler is not applicable for the arguments (IloNumVar, int, int).

    I remind you  my constraint : 

      
      
                           IloLinearNumExpr expr = cplex.linearNumExpr(); 
                                                            expr.addTerm(1.0, c[i][j][k]);
                                                            cplex.addGe(expr,
                                                                            cplex.sum(s[i][j][k], p[i][j][k] ,
                                                                                            (-(1-x[i][j][k])) * L));
    

     

    If there are other methods (i mean gives the same results as cplex.addGe , cplex.addLe, cplex.sum  cplex.prod etc. )to compare integers and make it produce and the sum of integers and reals using cplex in java please Send them to me.

    It's very difficult to be stuck by this methods.


    #CPLEXOptimizers
    #DecisionOptimization


  • 10.  Re: Error when adding constraints using cplex in java

    Posted 04/25/18 02:08 PM

    I suggest you take a good look at the reference documentation and the examples shipped with CPLEX.

    '(-(1-x[i][j][k]))*L' is a constant (of type int or double). To add this to an expression you have to use expr.setConstant(). To use this in sum() together with other expressions you first have to create an expression that represents that constant. This can be done via cplex.linearNumExpr((-(1-x[i][j][k])) * L).


    #CPLEXOptimizers
    #DecisionOptimization


  • 11.  Re: Error when adding constraints using cplex in java

    Posted 04/25/18 11:00 AM

    Originally posted by: Ahlem


    X and L  are int. The program shows me this error : 

     

    Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    The method prod(int, IloIntExpr) in the type IloCplexModeler is not applicable for the arguments (int, int)

     


    #CPLEXOptimizers
    #DecisionOptimization