Decision Optimization

Decision Optimization

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

 View Only
Expand all | Collapse all

Minimizing Problem

ALEX FLEISCHER

ALEX FLEISCHERThu June 30, 2016 09:21 AM

ALEX FLEISCHER

ALEX FLEISCHERWed July 27, 2016 03:34 AM

  • 1.  Minimizing Problem

    Posted Thu June 30, 2016 08:20 AM

    Originally posted by: Treee


    Hello,

     

    i am trying to find the optimal solution of my minimizing problem.

    I have a distance matrix which gives the distances to the "places"(in a storage yard) in the matrix. My goal is to put for example 4 containers to the storage yard at minimum distance costs. The positions should be shown in the matrix "placed" and set to 1.

    my .dat so far ; 

    AmountOfContainers = 4;
    Rows = 4;
    Columns = 5; 
    Distance = [ 
           [ 1, 7, 13, 19, 25 ], 
           [ 3, 9, 15, 21, 27 ],
           [ 5, 11, 17, 23, 29 ],
           [  7, 13, 19, 29, 35 ]];

    and my .mod:

    int AmountOfContainers=...;

    range Container = 1..AmountOfContainers;
    int Rows = ...;
    range Row = 1..Rows;
    int Columns = ...;
    range Column = 1..Columns;
    int Distance [Row][Column] = ...;
    dvar boolean placed[Row][Column];

    minimize
      sum(r in Row, c in Column)
       Distance[r][c]*placedt[r][c]
        ;
        
     subject to {
     }

    execute DISPLAY_RESULTS {
    };

     

    how i have to change my program to place the 4 containers at the lowest distance costs and display the summed distance costs?

    the "placed" matrix should be like :

    Placed= [ 
           [ 1, 1, 0, 0, 0 ], 
           [ 1, 1, 0, 0, 0 ],
           [ 0, 0, 0, 0, 0 ],
           [  0,0, 0, 0, 0 ]];

     

    thanks and kind regards

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Minimizing Problem

    Posted Thu June 30, 2016 09:21 AM

    Hi,

    you could try

    int AmountOfContainers=...;

    range Container = 1..AmountOfContainers;
    int Rows = ...;
    range Row = 1..Rows;
    int Columns = ...;
    range Column = 1..Columns;
    int Distance [Row][Column] = ...;
    dvar boolean placed[Row][Column];

    minimize
      sum(r in Row, c in Column)
       Distance[r][c]*placed[r][c]
        ;
        
     subject to {
     sum(r in Row, c in Column) placed[r][c]==AmountOfContainers;
     
     }

    execute DISPLAY_RESULTS {
    writeln(placed);

    };

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: Minimizing Problem

    Posted Tue July 26, 2016 07:59 AM

    Originally posted by: Treee


    thank you again!

    Sorry for the late answer, but i had some internet issues and holidays.

    Your suggestion worked fine, thanks!

    Now i want to split the containers into two types. "Type One" and "Type Two".

    "Type One" containers should just be stores in the first 2 columns, the "type two" containers in the other columns.

     

    I would suggest to make an array of the different types : 

    AmountOfContainers = [5,2];      // 5 containers of "type one" and 2 containers of "type 2"

     

    But how do I limit the "Type One" Containers to the first 2 columns?

    And how do I show, that a certain position is occupied by a container?

    Should there be a constraint, that a container can not be placed at a position which value is 1?

     

    Many thanks and kind regards

     

     

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: Minimizing Problem

    Posted Wed July 27, 2016 03:34 AM

    Hi,

    then you could write:

    .mod

    int

     

    nbTypesOfContainers=...;

     

    range

     

    containerTypes=1..nbTypesOfContainers;

     

     

     

    int AmountOfContainers[containerTypes]=...;

     

     

     

    int Rows = ...;

     

    range Row = 1..Rows;

     

    int Columns = ...;

     

    range Column = 1..Columns;

     

    int Distance [Row][Column] = ...;

     

     

    dvar boolean placed[containerTypes][Row][Column];

     

     

    minimize

     

    sum(r in Row, c in Column, t in containerTypes)

     

    Distance[r][c]*placed[t][r][c]

    ;

     

     

    subject to {

     

    forall(t in containerTypes)

     

    sum(r in Row, c in Column) placed[t][r][c]==AmountOfContainers[t];

     

     

    // Max one container at a location

     

    forall(r in Row, c in Column) sum(t in containerTypes) placed[t][r][c]<=1;

     

    }

     

     

    execute DISPLAY_RESULTS {

     

    writeln(placed);

     

    };

    .dat

    nbTypesOfContainers

     

    =2;

    AmountOfContainers

     

    =[5,2];

    Rows

     

    = 4;

    Columns

     

    = 5;

    Distance

     

    = [

    [ 1, 7, 13, 19, 25 ],

    [ 3, 9, 15, 21, 27 ],

    [ 5, 11, 17, 23, 29 ],

    [ 7, 13, 19, 29, 35 ]];

     

    regards

    NB:

    to get a nice display you could get ideas at

    https://www.ibm.com/developerworks/community/forums/html/topic?id=84ac39db-dcaf-4661-aebd-eeeb89cb4b62&ps=25

    and get a 2D display with different colors according to the kind of container

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: Minimizing Problem

    Posted Thu July 28, 2016 03:11 AM

    PS:

    So in the .mod if at the end you add

    tuple sequence_like {
       int start;
       int end;
       string label;
       int type;
     };  
     
    int placedDisplay[i in Row][j in Column]=maxl(0,max(t in containerTypes:placed[t][i][j]!=0) t);
     

     

    {sequence_like} array2[i in Row] = {<j-1,j," ",2*placedDisplay[i][j]> | j in Column: placedDisplay[i][j]!=0};

     
      execute noname {
        
       array2;
    }
       

    and then click array2 you will see in the gantt the positions of the containers

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer