Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Cplex Java LP with 2 Index

    Posted 09/12/15 02:15 PM

    Originally posted by: Torben-Ger-1988


    Hey there,

    i am trying to optimize a simple Form.

    The picture shows you what i'd like to minimize.
    Basicly there are two poissibilties how to do something. These possibilities are destribed with x_i
    In different locations we have to check which possibility would be smaller. Therefor i added the letter "w".
    y_i_w stands for the number of actings you got to do, to finish your work.

    For excample:
    Location A Possibilty 1: 300 actings
    Locations A Possibilty 2: 350 actings

    Location B Possibilty 1: 50 actings
    Locations B Possibilty 2: 20 actings

    I'd like to use the LP to Minimize the Problem. Therefor i added some constrains:

    At the moment i entered my code like this:
    My main Problem is how do i get my Data into the  objective funktion??

                for (int j = 0; j < w; w++) {
                    for (int k = 0; k < i; k++) {
                            Kapa.addTerm(1.0, y[j][k]);
                            Deci.addTerm(1.0, x[j][k]);  

     

    public static void solveMe() {
            
            int i = 2; //possibilities
            int w = 56; //locations
            
            final double M = 99999999;

            //model
            try {

                
                
                IloCplex cplex = new IloCplex();
                
                IloNumVar[][] y = new IloNumVar[w][];

                for (int j = 0; j < w; j++) {
                    y[j] = cplex.numVarArray(i, 0, Double.MAX_VALUE);  //actings between 0 and max..
                }
                
                IloNumVar[][] x = new IloNumVar[w][];
                for (int j = 0; j < w; j++) {
                    x[j] = cplex.boolVarArray(i);              //xiw either 0 or 1
                }
                
                // Objective Function: Minimize Kapazität
                IloLinearNumExpr Kapa = cplex.linearNumExpr ();
                IloLinearNumExpr Deci = cplex.linearNumExpr();
                for (int j = 0; j < w; w++) {
                    for (int k = 0; k < i; k++) {
                            Kapa.addTerm(1.0, y[j][k]);
                            Deci.addTerm(1.0, x[j][k]);  
                    }
                }
                
                cplex.addMinimize(cplex.sum(Kapa, Deci));
                
                
                //constraint between Xit and Yit
                for (int j = 0; j < w; j++) {
                    for (int k = 0; k < w; k++)
                    {
                        cplex.addLe(y[j][k], cplex.prod(M, x[j][k]));
                    }
                }
                
            
                //solve model
                cplex.solve();
                //end
                cplex.end();
                
            } catch (IloException e) {
                e.printStackTrace();
                
            }
        }


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Cplex Java LP with 2 Index

    Posted 09/13/15 03:09 AM

    I think there is a typo in your loop header

    for (int j = 0; j < w; w++) {

    should probably be (note: j++, not w++)

    for (int j = 0; j < w; j++) {

    The current loop will just keep adding terms until Java runs out of memory.

    There seems to be a similar typo in the loop that sets up the constraints between Xit and Yit:: k should only run up to i, not to w, otherwise you will get an ArrayIndexOutOfBoundsException.


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Cplex Java LP with 2 Index

    Posted 09/14/15 03:07 AM

    Originally posted by: Torben-Ger-1988


    Hey Daniel,

     

    thanks for your advise and fast reply :)

     

    Have you got an idea how i fill in my data?

    Maybe i'm describing my problem way too bad or its way too easy :D

    How do i have to enter my Data that my cplex optimization implements it to its LP?

     

    Cheerfully regards Torben


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Cplex Java LP with 2 Index

    Posted 09/14/15 04:02 AM

    Sorry, I don't understand what your problem is. The code you presented looks like it creates the problem you want to create.

    I am unclear what you mean by "Data" and what data you want to get into your model. Maybe you can describe what is currently missing from your code/model?


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Cplex Java LP with 2 Index

    Posted 09/14/15 04:53 AM

    Originally posted by: Torben-Ger-1988


    Hey Daniel,

     

    Well my Problem is at the moment how i implement my data in cplex codes.

    My Code needs the data of y[i][w] to decide if it takes alternative x[1][w] or x[2][w]

    But somehow i need to get my Data into cplex that it's able to compare them.

    For example i'd like to input the following data:

    int y_1_1 = 300;

    int y_2_1 = 250;

    int y_1_2 = 100;

    int y_2_2 = 250;

     

    and the LP should print out the choosen alternatives (x)

    Hope it helps :)

    Many Thanks!!


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Cplex Java LP with 2 Index

    Posted 09/14/15 11:30 AM

    I am still not sure I understand correctly. You want to fix (some of the) y variables and then solve the restricted problem?

    In order to fix a variable you can fix its lower and upper bound to the same values:

    y[0][0].setLB(300);
    y[0][0].setUB(300);

    Is that what you are looking for?

    Btw, it looks like you are German? If I still did not get you correctly and you feel things are easier to explain in German, then feel free to drop an email in German to daniel(dot)junglas(at)de(dot)ibm(dot)com.


    #CPLEXOptimizers
    #DecisionOptimization