Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  How to program this model??

    Posted 10/23/08 11:02 AM

    Originally posted by: SystemAdmin


    [fatapple_1 said:]

    This is my first time to use OPL. The teacher ask us to use OPL to solve an LP problem.
    My program is as follow:

    int TotalNods = 3;
    range NodsOrder = 0..TotalNods ;
    int DistMatrix[NodsOrder][NodsOrder] = ...;
    int CostMatrix[NodsOrder][NodsOrder] = ...;
    int NodQuantity[NodsOrder] = ...;

    dvar int Road[NodsOrder][NodsOrder];
    dvar int Volumn[NodsOrder];

    minimize
      sum(i in NodsOrder, j in NodsOrder) CostMatrix[i][j]*Road[i][j];
     
    subject to {
      forall( i in NodsOrder)
          sum(i in NodsOrder) Road[0][i] == 1 + Road[0][0] ;                                                (1)
      forall( i in NodsOrder)
          sum(i in NodsOrder) Road[i][0] == 1 + Road[0][0];                                                  (2)
      forall(i in NodsOrder, j in NodsOrder) 
          sum(i in NodsOrder, j in NodsOrder) Road[i][j] == sum(i in NodsOrder) Road[i][i] + 1;    (3)
    };

    Questions:
    a. How to evaluate the 2-dimension array (e.g. DistMatrix[NodsOrder][NodsOrder])
    b. I want the the value of decision variable Road[NodsOrder][NodsOrder] only can choose 0 or 1.
    c. in the constraints equation (3), I want to sum it all while ij. Could my program work?
    d. My LP problem is some Transport problem. There is an example transp4.prj. But some program I can not catch it at all.
    e.g.    {route} Routes = { < p,<o,d> > | <p,o,d,c> in TableRoutes };
              {connection} Connections = { c | <p,c> in Routes };

    Can any one help me, please. Thanks a lot.

    #DecisionOptimization
    #OPLusingCPOptimizer


  • 2.  Re: How to program this model??

    Posted 10/23/08 06:02 PM

    Originally posted by: SystemAdmin


    [jfk said:]

    Hello there,
    well, without learning the OPL syntax you will not get far. I modified the code so it runs and compute some solution, but I don't think the constraints make much sense (sorry I didn't catch the meaning or purpose of your constraint seeds).
    But why do you start with trasnp4.prj which is a more advanced tuple-based modeling? Start with transp1.prj first. The doc describe the problem/modeling as well.
    Looking at transp4.prj you might ask why do we need this complex structure of the data, why don't we have some simpler structure of demand-supply and everything (like in transp1.prj)? Well, the thing is that if you want to get your data from a DB then you may not have a choice on the data structure, you are obliged to get it as it is provided and you have to do the data massaging by yourself. Here the tuples gives you tremendous help and the transp4.prj example shows you how to do  the data transformation which best fits to your opti model. Just compare the data structure in transp1.dat and transp4.dat and you will see that trasnp4.dat is more compact (well, in my view the modeling becomes elegant as well, but it is a personal opinion).

    so the corrected code of yours
    .mod
    --------------start
    int TotalNods = ...;
    range NodsOrder = 0..TotalNods ;
    int DistMatrix[NodsOrder][NodsOrder] = ...;
    int CostMatrix[NodsOrder][NodsOrder] = ...;
    int NodQuantity[NodsOrder] = ...;

    dvar int Road[NodsOrder][NodsOrder] in 0..1;
    dvar int Volumn[NodsOrder];

    minimize
      sum(i in NodsOrder, j in NodsOrder) CostMatrix[i][j]*Road[i][j];
     
    subject to {
      forall( i in NodsOrder)
          sum(j in NodsOrder) Road[i][j] == 1 + Road[0][0] ;
    /*                                                      (1)
      forall( i in NodsOrder)
          sum(i in NodsOrder) Road

        * == 1 + Road[0][0];                                                  //(2)
    /

      forall(i in NodsOrder, j in NodsOrder) 
          sum(i in NodsOrder, j in NodsOrder : i!=j) Road[i][j] == sum(i in NodsOrder) Road[i][j] + 1;    //(3)
    };

    /

    Questions:
    a. How to evaluate the 2-dimension array (e.g. DistMatrix[NodsOrder][NodsOrder]) - see in the code
    b. I want the the value of decision variable Road[NodsOrder][NodsOrder] only can choose 0 or 1. - see in the code
    c. in the constraints equation (3), I want to sum it all while ij. Could my program work? - see in the code
    d. My LP problem is some Transport problem. There is an example transp4.prj. But some program I can not catch it at all.
    e.g.    {route} Routes = { < p,<o,d> > | <p,o,d,c> in TableRoutes };
              {connection} Connections = { c | <p,c> in Routes }; - see ABOVE
    */
    --------------end
    .dat
    --------------start
    otalNods = 3;
    DistMatrix = [[1,2,3],
                  [1,2,3],
                  [1,2,3]];
    CostMatrix = [[111,222,3],
                  [1,222,333],
                  [111,2,333]];
    NodQuantity = [11,22,33];
    --------------end

    BTW 2 questions:
    1. which version of OPL are you using?
    2. would you share with me the name of the University of yours?

    cheers
    #DecisionOptimization
    #OPLusingCPOptimizer


  • 3.  Re: How to program this model??

    Posted 10/24/08 12:55 AM

    Originally posted by: SystemAdmin


    [fatapple_1 said:]

    Hi,

    Thanks for your help.

    I use the ILOG OPL Development Stdio IDE v5.2. I am in Clemson University.

    I can not agree more with you about the OPL syntax problem. But it is hard to find a book for OPL beginner. The help documents are a little bit hard to find the answer (e.g. I can not find [i]sum(i in NodsOrder, j in NodsOrder :[b] i!=j[/b]) Road[j] == + 1;[/i]  in the help document). Can you give me some advise on that.

    my program has a little problem. I changed it as following:
    minimize
      sum(i in NodsOrder, j in NodsOrder) CostMatrix[i][j]*Road[i][j];
    // Road[i][j] is 1 when there the road i to j is in the solution, 0 when it is not.
    // Costmatrix[i][j] is the constant cost on road i to j, e.g. gasoline fee.

    subject to {
    // only 1 way to get out of the original depot
      forall(j in NodsOrder)
          sum(j in NodsOrder : j!=0) Road[0][j] == 1 ;
    // only 1 way to get back to the original depot
      forall( i in NodsOrder)
          sum(i in NodsOrder : i!=0) Road[i][0] == 1;
    // Pass all the Nods
      forall(i in NodsOrder, j in NodsOrder) 
          sum(i in NodsOrder, j in NodsOrder : i!=j) Road[i][j] == 1;    //(3)
    };

    William
    #DecisionOptimization
    #OPLusingCPOptimizer