Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Function for combine two variables

    Posted 10/30/16 08:13 AM

    Originally posted by: franzi_ich


    Hello everyone,

    I'm very new to CPLEX and I've got a question. I have a scheduling problem. Before solving it could be checked, if the type of product is available in the stock or not. There is one product each is defined by model and color. In CPLEX I write that:

    int model[I] = [1,2,2,1,2,1,1,1,2,1];

    int color[I] = [1,1,1,1,1,2,2,2,2,1];

    So there are 10 products. In stock there is one product per type ((1,1) or (1,2)). Now I need a function, which combines the model and color, and which check if the product is in stock or not. 

    Please help me. If you need more information, ask me.

    Thank you.


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Function for combine two variables

    Posted 10/30/16 03:29 PM

    Hi

    range I=1..10;
    int model[I] = [1,2,2,1,2,1,1,1,2,1];
    int color[I] = [1,1,1,1,1,2,2,2,2,1];

    dexpr int exists2[m in 1..3][c in 1..3]=sum(i in I)(model[i]==m && color[i]==c);
    dexpr int exists[m in 1..3][c in 1..3]=(exists2[m][c]>=1);

    subject to
    {

    }

    execute
    {
    writeln(exists[1][1]);
    writeln(exists[3][1]);
    }

    regards


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Function for combine two variables

    Posted 10/31/16 05:41 AM

    Originally posted by: franzi_ich


    Hi,

    Thank you for this information. But I have another question: Is it possible to check this for each i in I? I need this information because if the product is not available in stock, it should be defined as a requirement and only the requirements are necessary for the scheduling problem.

    Can you understand what I mean?

    Regards.


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Function for combine two variables

    Posted 10/31/16 05:52 AM

    Hi,

    but do you also have some sort of

    int stock[I];

    ?

    regards


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Function for combine two variables

    Posted 10/31/16 06:37 AM

    Originally posted by: franzi_ich


    Hi,

    no in stock there is a list of products (each type once). I try to give you an example: There is a list of the ten products:

    i model color
    1 1 1
    2 2 1
    3 2 1
    4 1 1
    5 2 1
    6 1 2
    7 1 2
    8 1 2
    9 2 2
    10 1 1

     

    Then there is another list how often each type is available in stock:

    model color number of products in stock
    1 1 1
    1 2 1
    2 1 1
    2 2 1

     

    The first step of my model is to check for each i in I if the product is available in stock or not. Is it possible to solve this via CPLEX?

     

    Regards.


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Function for combine two variables

    Posted 10/31/16 07:59 AM

    Is this what you want?

    range I = 1..10;
    int model[I] = [1,2,2,1,2,1,1,1,2,1]; // Column 'model' from the table
    int color[I] = [1,1,1,1,1,2,2,2,2,1]; // Column 'color' from the table
    // The second table in your post. First index is model, second index is color
    int instock[1..2][1..2] = [ [ 1, // model=1, color=1,
                                  1  // model=1 color=2
                                ],
                                [ 1, // model=2, color=2
                                  1  // model=2, color=2
                                ] ];
    // Number of items in stock for product i
    dexpr int numstock[i in I] = instock[model[i]][color[i]];
    

    While this sort of preprocessing or data mangling is doable in CPLEX, it may be easier to do it in the application that creates the tables.


    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: Function for combine two variables

    Posted 10/31/16 08:41 AM

    Actually, you can define numstock as (no dexpr)

    int numstock[i in I] = instock[model[i]][color[i]];

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: Function for combine two variables

    Posted 11/01/16 03:56 AM

    Originally posted by: franzi_ich


    Hi,

    thank you for this information. I don't get any mistake. But now I need this for my problem, but I don't know what the line mean. Is it a normal number, like 1,2,3 or is it a boolean like 0 if the product is available in stock or 1 if not?

    Regards.


    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: Function for combine two variables

    Posted 11/01/16 09:47 AM

    The values in numstock are just the values from the instock table, so they are plain integers. You can also see this by the fact that the type of the data is 'int'. If you want a boolean value that tells whether any of the products is on stock then you just have to compare '>0'.

    If these things are not clear to you then it might be a good idea to start with the many examples that are shipped with CPLEX to get more familiar with the OPL language.


    #CPLEXOptimizers
    #DecisionOptimization


  • 10.  Re: Function for combine two variables

    Posted 11/02/16 04:47 AM

    Originally posted by: franzi_ich


    Thank you so much, know I get the point. 

    Have a nice day.

    Regards.


    #CPLEXOptimizers
    #DecisionOptimization