Decision Optimization

 View Only
  • 1.  Conversion IloNumVar to int

    Posted Wed April 25, 2018 10:27 AM

    Originally posted by: Ahlem


    Is it possible to fill an array of  IloNumVar with integer values using cplex in java ?

    Because, I have a variable declared with this way: IloNumVar[][][] c = new IloNumVar[job][][]; 

    and I want to fill it with integer values. 

    How can i do this ?

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Conversion IloNumVar to int

    Posted Wed April 25, 2018 11:52 AM

    You cannot. An IloNumVar is an object. What is the semantics of assigning a number to such an object? Why not declare the array to be an array of ints if you want to assign integers?


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Conversion IloNumVar to int

    Posted Wed April 25, 2018 12:40 PM

    Originally posted by: Ahlem


    Because I can not use it (the array of ints) after in my constraints. The program does not accept. 

    Is there another method I can use? (To more explain I have attached my constraint )

    //My ilonumvar is c[i][j][k]
    IloNumVar[][][] c = new IloNumVar[job][][];
    int [][][] p= new int[job][][];
    IloNumVar[][][][][] y = new IloNumVar[job][][][][];
    int L =10000;
    
    cplex.addGe(c[i1][j1][k],
                             cplex.sum(c[i2][j2][k], cplex.prod(y[i1][j1][i2][j2][k], p[i1][j1][k]),
                                                                                            cplex.sum(-L, cplex.prod(L, y[i2][j2][i1][j1][k]))));
    

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Conversion IloNumVar to int

    Posted Thu April 26, 2018 04:02 AM

    You should

    • Take a look at the various examples shipped with CPLEX,
    • Take a look at the reference documentation
    • Try to better understand the error messages your compiler gives you

    Either 'c' is a variable subject to optimization or it is a constant. Apparently, in your case it is a variable. That is a property that cannot change. If you try to feed 'c' to a function and then get an error then the fix is not to change the type of 'c' from variable to constant! Instead you should check whether there is another function you can use or whether you have to do things in a different way.

    In your code I don't see a problem with the way you use 'c'. But I see a problem with how you use 'L': This is an integer constant and cannot be mixed with objects that represent linear expressions in all cases. You may want to use something like cplex.linearNumExpr(L) and cplex.linearNumExpr(-L) to create expression objects that represents these constants.


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Conversion IloNumVar to int

    Posted Thu April 26, 2018 07:22 AM

    Originally posted by: Ahlem


    Thanx you Smile

    You know how can i convert an OPL coded model to Java? 

    I have a code in cplex but I want to convert it automatically just to test it with java. is there a quick solution or should I rewrite it?


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Conversion IloNumVar to int

    Posted Fri April 27, 2018 02:07 AM

    There is no automatic tool for that, so you have to do it by hand.

    But note that you can solve OPL models also from Java, see opl/examples/opl_interfaces/java/oplrunsample.


    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: Conversion IloNumVar to int

    Posted Fri April 27, 2018 08:43 AM

    Originally posted by: Ahlem


    Hi, 

    But, eclipse shows me this error 

    I think because this two error in cplex : i have two errors : 

    The first : OPL runtime not available, please check your PATH

    The second : 

    Please help me how can i resolve them ? 

    Regards.

     


    #DecisionOptimization


  • 8.  Re: Conversion IloNumVar to int

    Posted Mon April 30, 2018 01:25 AM

    Can you please show the full command line with which you invoke the JVM? In particular, the setting of java.library.path? What operating system are you running on? Windows, Linux, ...?


    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: Conversion IloNumVar to int

    Posted Thu May 03, 2018 06:14 AM

    Originally posted by: Ahlem


    The problem of the error in eclipse is solved. Thanx you Smile

    Sorry, but I have one more question. Can i help me please in this problem : https://www.ibm.com/developerworks/community/forums/html/topic?id=dbbb788c-f978-499a-9d09-5d63fabd2206 

     


    #CPLEXOptimizers
    #DecisionOptimization