Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  objective within a forall loop

    Posted 07/17/15 07:51 AM

    Originally posted by: Cplex


    Hey guys!

    I have a problem modelling a light robust warehouse location problem in CPLEX. I don't know how to formulate the objective function.

     

    In XPRESS it looks like this:


    forall(f in 1..17) do
        FixC := sum (i in M) (c(i)*x (f,i))
        VarC := sum (i in M, j in N) (d(i,j)*y(f,i,j))

        z := FixC+ VarC
        
         minimize (z)
       
    end-do

     

    You see...there's a forall loop that contains the objective. Is it possible to formulate this in CPLEX?


    Any hints are highly appreciated!

    Thanks in advance!


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: objective within a forall loop

    Posted 07/17/15 01:07 PM

    Hi,

    you could have a look at the example

    CPLEX_Studio1261\opl\examples\opl\sched_stochastic_jobshop

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: objective within a forall loop

    Posted 07/21/15 08:31 AM

    Originally posted by: Cplex


    Thanks, but they're using the CP optimizer in this example. I'm currently working with the CPLEX optimizer, because it's not a complex problem.
    Is there a possibility to put the objective function in a forall or while loop (in CPLEX)?

     

    Thanks in advance!


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: objective within a forall loop

    Posted 07/22/15 10:58 AM

    Hi,

    yes you can use the objective in a forall:

    dvar float obj;

    minimize obj;
    subject to
    {
    forall(i in 1..3) obj>=i;
    }

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: objective within a forall loop

    Posted 07/23/15 03:28 AM

    Originally posted by: Cplex


    Yes, but I need to use the minimization of the objective within the forall loop. Is that possible as well?


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: objective within a forall loop

    Posted 07/23/15 03:35 AM

    Hi,

    do you want to minimize one objective or a set of objectives ?

    If the latter, do you want to minimize on average or in the worst case ?

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: objective within a forall loop

    Posted 07/23/15 03:40 AM

    Originally posted by: Cplex


    I have to minimize a set of objectives. There are several scenarios and I have to minimize the costs for each of the scenarios. So it's neither the average nor the worst case.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 8.  Re: objective within a forall loop

    Posted 07/23/15 04:37 AM

    Hi

    but the decision variables are per scenario or shared by all scenarii ?

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 9.  Re: objective within a forall loop

    Posted 07/23/15 04:51 AM

    Originally posted by: Cplex


    The decision variables are per scenario.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 10.  Re: objective within a forall loop

    Posted 07/23/15 08:05 AM

    Hi,

    then this small example that I derived from scalableWarehouse could help you:

    execute
    {
    cplex.epgap=0.01;
    }


    int nbScenarii=10;
    range scenarii=1..nbScenarii;
    int Fixed        = 10;
    int NbWarehouses = 50;
    int NbStores     = 200;

    assert( NbStores > NbWarehouses );

    range Warehouses = 1..NbWarehouses;
    range Stores     = 1..NbStores;
    int Capacity[w in Warehouses] =
      NbStores div NbWarehouses +
      w % ( NbStores div NbWarehouses );
    int SupplyCost[scenario in scenarii][s in Stores][w in Warehouses] =
      1 + ( ( s + 10 * w ) % 100 ) + scenario*20;
    dvar int Open[scenarii][Warehouses] in 0..1;
    dvar float Supply[scenarii][Stores][Warehouses] in 0..1;
    dexpr int TotalFixedCost[scenario in scenarii] = sum( w in Warehouses ) Fixed * Open[scenario][w];
    dexpr float TotalSupplyCost[scenario in scenarii] = sum( w in Warehouses, s in Stores )  SupplyCost[scenario][s][w] * Supply[scenario][s][w];
    minimize sum(scenario in scenarii)
    (TotalFixedCost[scenario] + TotalSupplyCost[scenario]);

    subject to {
    forall(scenario in scenarii)
      {

      forall( s in Stores )
        ctStoreHasOneWarehouse:
          sum( w in Warehouses )
            Supply[scenario][s][w] == 1;
      forall( w in Warehouses )
        ctOpen:
          sum( s in Stores )
            Supply[scenario][s][w] <= Open[scenario][w] * Capacity[w];
            
          }        
    }

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 11.  Re: objective within a forall loop

    Posted 07/28/15 06:42 AM

    Originally posted by: Cplex


    Yes, now it's working. Thank you very much!


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 12.  Re: objective within a forall loop

    Posted 08/11/15 03:09 PM

    Originally posted by: Cplex


    Now I'm facing another problem. In this case I can't minimize or maximize the sum because the runtime of the model is getting too large.

     

    My problem looks more or less like that:

     

    forall (k in K) {

         z[k] == 0;

                forall (l in K| l > k) {

                         z[l] == 0;

                            solve model

                               z[l] == 1;   

                               z[k] == 1; }}                                           (after solving the model, before solving the model for the next k)

     

    How can I do solve the model inside such a loop?

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer