Topic
  • 21 replies
  • Latest Post - ‏2013-09-05T14:31:51Z by Puppy26
Puppy26
Puppy26
17 Posts

Pinned topic Including Time Period in Optimization Model

‏2013-08-31T10:26:38Z |

Hi all,

I'm a new user of CPLEX and using it for my thesis work. I would like to model a program in the following way. Say for example, I have two warehouses with time period of 5 months. One warehouse will be opened throughout the 5 months and other warehouse will be opened for the first 3 months and will be closed for the rest of the time period. Could some one please help me how I should write the code now. I tried to look in google but I couldn't get any sample model.

Any sample example would be really helpful. 

Many thanks!

  • ol
    ol
    35 Posts

    Re: Including Time Period in Optimization Model

    ‏2013-09-02T10:34:08Z  

    Hello,

    you can have a look at the warehouse example in the opl directory. There is no time in this example, you may want to extend it to take into account your specific needs. From your question, it is enough to solve 2 warehouse problems, one for the first 3 months, one for the last 2 months. If the needs are more complex, can you detail them a little bit more?

    Regards,

    Olivier

  • Puppy26
    Puppy26
    17 Posts

    Re: Including Time Period in Optimization Model

    ‏2013-09-02T11:05:57Z  
    • ol
    • ‏2013-09-02T10:34:08Z

    Hello,

    you can have a look at the warehouse example in the opl directory. There is no time in this example, you may want to extend it to take into account your specific needs. From your question, it is enough to solve 2 warehouse problems, one for the first 3 months, one for the last 2 months. If the needs are more complex, can you detail them a little bit more?

    Regards,

    Olivier

    Hi Olivier,

    Yeah I have already looked into warehouse problem in opl directory but there is no time limit as you said.

    Right now, I have developed the model for a single time period which means all the Depots are opened throughout the operation.

    Now, I want to model the project for multiple time period. say for example 6 months.

    My plan is to construct the model in such a way set of Depots(3 Depots out of 5 Depots) should be opened on all the time period of 6 months and last 2 depots should be opened for first 3 months and last 3 months the depots should be closed hence there won't be any supply from and to those closed depots in the last 3 months.

    I have been trying to model this for 3 weeks but getting errors always.

    Hope my above explanation is clear and If you want I can give you more explanation.

    For your reference, I have attached the model.

    Many thanks!

     

    Attachments

  • ol
    ol
    35 Posts

    Re: Including Time Period in Optimization Model

    ‏2013-09-02T13:00:22Z  
    • Puppy26
    • ‏2013-09-02T11:05:57Z

    Hi Olivier,

    Yeah I have already looked into warehouse problem in opl directory but there is no time limit as you said.

    Right now, I have developed the model for a single time period which means all the Depots are opened throughout the operation.

    Now, I want to model the project for multiple time period. say for example 6 months.

    My plan is to construct the model in such a way set of Depots(3 Depots out of 5 Depots) should be opened on all the time period of 6 months and last 2 depots should be opened for first 3 months and last 3 months the depots should be closed hence there won't be any supply from and to those closed depots in the last 3 months.

    I have been trying to model this for 3 weeks but getting errors always.

    Hope my above explanation is clear and If you want I can give you more explanation.

    For your reference, I have attached the model.

    Many thanks!

     

    ok, but what are the constraints involving time? I do not see such constraints in your problem.

    If the periods are independent, the most efficient approach is certainly to consider each period as a different problem:

    solve period 1 with the 5 depots open, and solve period 2 with only 3 depots open.

    Or do you have some constraints between the periods? like at a given period there is a cost for modifying the solution found at the previous period? In this case you can link the variables of the period 1 to the variables of the period 2 for building a cost expression for example.

    Also, something weird in your file, in the constraint:

            forall (d in Depots)

          ctEachDepotHasOneDepot:

            sum (d in Depots)

              DDSupply [d][d] ==1;

    d is used twice. I think you mean:

            forall (d in Depots)

          ctEachDepotHasOneDepot:

            sum (d1 in Depots)

              DDSupply [d][d1] ==1;

     

    Regards

    Olivier

     

  • Puppy26
    Puppy26
    17 Posts

    Re: Including Time Period in Optimization Model

    ‏2013-09-02T13:36:43Z  
    • ol
    • ‏2013-09-02T13:00:22Z

    ok, but what are the constraints involving time? I do not see such constraints in your problem.

    If the periods are independent, the most efficient approach is certainly to consider each period as a different problem:

    solve period 1 with the 5 depots open, and solve period 2 with only 3 depots open.

    Or do you have some constraints between the periods? like at a given period there is a cost for modifying the solution found at the previous period? In this case you can link the variables of the period 1 to the variables of the period 2 for building a cost expression for example.

    Also, something weird in your file, in the constraint:

            forall (d in Depots)

          ctEachDepotHasOneDepot:

            sum (d in Depots)

              DDSupply [d][d] ==1;

    d is used twice. I think you mean:

            forall (d in Depots)

          ctEachDepotHasOneDepot:

            sum (d1 in Depots)

              DDSupply [d][d1] ==1;

     

    Regards

    Olivier

     

    Hi Olivier,

    Exactly, you're right.

    Currently, I have not mentioned any time periods in the constraints. The time periods are independent as you mentioned. Since I dont have much background on programming, could you help me.

    Coud you please show me one model as how to use time period to show all depots are open during the time period 1 and hence it involves all movements of the depots in that period and another model to show only 3 depots are open during the time period 2 so there will be movements for the 3 depots and no movements on depots 4 and 5.

    Just to give more explanation, if the depot is closed, there won't be any movements from consignees to depot, depot to shippers, terminals to depots and vice versa.

    About your correction, thanks for it I have included it and it works perfect now.

    Many thanks!

  • ol
    ol
    35 Posts

    Re: Including Time Period in Optimization Model

    ‏2013-09-02T14:27:14Z  
    • Puppy26
    • ‏2013-09-02T13:36:43Z

    Hi Olivier,

    Exactly, you're right.

    Currently, I have not mentioned any time periods in the constraints. The time periods are independent as you mentioned. Since I dont have much background on programming, could you help me.

    Coud you please show me one model as how to use time period to show all depots are open during the time period 1 and hence it involves all movements of the depots in that period and another model to show only 3 depots are open during the time period 2 so there will be movements for the 3 depots and no movements on depots 4 and 5.

    Just to give more explanation, if the depot is closed, there won't be any movements from consignees to depot, depot to shippers, terminals to depots and vice versa.

    About your correction, thanks for it I have included it and it works perfect now.

    Many thanks!

     

    Let us take the notation of the warehouse opl example.

    you have the variables:

    dvar boolean Open[Warehouses];

     

    For limitng the number of open warehouses for your period you simply add:

         sum( w in  Warehouses ) Open[w] <= maxOpenForThisPeriod

     

    Note that the following constraint in the model guarantees that only open warehouses are used:

      forall( w in Warehouses, s in Stores )
        ctUseOpenWarehouses:
          Supply[s][w] <= Open[w];

    You need to adapt it to your consignees, depots, shippers, terminals,...

     

    Regards,

    Olivier

     

     

     

  • Puppy26
    Puppy26
    17 Posts

    Re: Including Time Period in Optimization Model

    ‏2013-09-02T18:14:15Z  
    This reply was deleted by Puppy26 2013-09-03T09:53:50Z.

    Hi Olivier,

    I just played around with the formula and I got it now. Thanks for your feedback.

    The problem now is I'm getting some strange results. 

    I wrote the equation as 

    forall (c in Consignees, d in Depots)
        DepotLimit:
          sum (d1 in Depots) Open [d1]<=2;

    In the result, It shows there is no movements between Consignees and Depots but in the case of movement between Depot and shipper, Depot and depot, I'm getting results as I expected. 

    In the case of Depot and Terminals, there is always some movements even though depot is closed. I'm going crazy with this results. Could you please look around the code I have attached and let me know where I made the mistakes.

    Many thanks!

    Attachments

  • Puppy26
    Puppy26
    17 Posts

    Re: Including Time Period in Optimization Model

    ‏2013-09-03T09:54:42Z  
    • Puppy26
    • ‏2013-09-02T18:14:15Z

    Hi Olivier,

    I just played around with the formula and I got it now. Thanks for your feedback.

    The problem now is I'm getting some strange results. 

    I wrote the equation as 

    forall (c in Consignees, d in Depots)
        DepotLimit:
          sum (d1 in Depots) Open [d1]<=2;

    In the result, It shows there is no movements between Consignees and Depots but in the case of movement between Depot and shipper, Depot and depot, I'm getting results as I expected. 

    In the case of Depot and Terminals, there is always some movements even though depot is closed. I'm going crazy with this results. Could you please look around the code I have attached and let me know where I made the mistakes.

    Many thanks!

    Any tips or clue to improve the solution will be very helpful.

     

    Many thanks!

     

  • ol
    ol
    35 Posts

    Re: Including Time Period in Optimization Model

    ‏2013-09-03T13:44:49Z  
    • Puppy26
    • ‏2013-09-03T09:54:42Z

    Any tips or clue to improve the solution will be very helpful.

     

    Many thanks!

     

    Hello,

    when you write:

    forall (c in Consignees, d in Depots)
        DepotLimit:
          sum (d1 in Depots) Open [d1]<=2;

    the constraint sum (d1 in Depots) Open [d1]<=2 is added for each pair c,d. As these variables do not appear in the constraint, the same constraint is added c*d too much times! Just post the constraint without forall.

    In your file, the first constraint:

       forall (c in Consignees)

         ctEachDepotHasOneConsignee:

           sum (d in Depots)

             CDSupply[c][d] ==1;

    is probably not what you want. Instead, it should be:

       forall (d in Depots)

         ctEachDepotHasOneConsignee:

           sum (c in Consignees)

             CDSupply[c][d] ==1;

    The inversion appears in other constraints in your file.

    An other problem, as you said: "there is always some movements even though depot is closed"

    This is quite expected as the constraints in the model force "movements", i.e. Supply variables to take values, even when the depot is closed.

    You must write a constraint to express what you have in mind.

    But first, you need to answer the question of which value to give to the different variables (for example DTSupply[d][t]) when the depot d is closed. Then, translating this answer as constraints in the model is the easy part.

    Regards,

    Olivier

  • Puppy26
    Puppy26
    17 Posts

    Re: Including Time Period in Optimization Model

    ‏2013-09-03T14:17:36Z  
    • ol
    • ‏2013-09-03T13:44:49Z

    Hello,

    when you write:

    forall (c in Consignees, d in Depots)
        DepotLimit:
          sum (d1 in Depots) Open [d1]<=2;

    the constraint sum (d1 in Depots) Open [d1]<=2 is added for each pair c,d. As these variables do not appear in the constraint, the same constraint is added c*d too much times! Just post the constraint without forall.

    In your file, the first constraint:

       forall (c in Consignees)

         ctEachDepotHasOneConsignee:

           sum (d in Depots)

             CDSupply[c][d] ==1;

    is probably not what you want. Instead, it should be:

       forall (d in Depots)

         ctEachDepotHasOneConsignee:

           sum (c in Consignees)

             CDSupply[c][d] ==1;

    The inversion appears in other constraints in your file.

    An other problem, as you said: "there is always some movements even though depot is closed"

    This is quite expected as the constraints in the model force "movements", i.e. Supply variables to take values, even when the depot is closed.

    You must write a constraint to express what you have in mind.

    But first, you need to answer the question of which value to give to the different variables (for example DTSupply[d][t]) when the depot d is closed. Then, translating this answer as constraints in the model is the easy part.

    Regards,

    Olivier

    Hi Olivier,

    Thats's great piece of idea. Now the model is almost perfect except one constraint that is CDSupply.

    I tried so many possiblities from the morning. Even though the value of other constraints changes with some changes but the value of CDSupply remains the same as [[0 0 0 0 0][0 0 0 0 0][0 0 0 0 0][0 0 0 0 0][0 0 0 0 0]] on every time.

    Now rest of the model is perfect. I'm still trying to play around with CDSupply to get the value I expect.

    For your reference, I've attached the updated code. If you could have some time, please have a look and let me know where do I make mistake in the case of CDSupply constraint.

    Many thanks!

     

    Attachments

  • ol
    ol
    35 Posts

    Re: Including Time Period in Optimization Model

    ‏2013-09-03T14:38:10Z  
    • Puppy26
    • ‏2013-09-03T14:17:36Z

    Hi Olivier,

    Thats's great piece of idea. Now the model is almost perfect except one constraint that is CDSupply.

    I tried so many possiblities from the morning. Even though the value of other constraints changes with some changes but the value of CDSupply remains the same as [[0 0 0 0 0][0 0 0 0 0][0 0 0 0 0][0 0 0 0 0][0 0 0 0 0]] on every time.

    Now rest of the model is perfect. I'm still trying to play around with CDSupply to get the value I expect.

    For your reference, I've attached the updated code. If you could have some time, please have a look and let me know where do I make mistake in the case of CDSupply constraint.

    Many thanks!

     

    if you want CDSupply[d] to be all 0 when d is closed and to have exactly one 1 when d is open, try to replace

    forall(d in Depots)

         ctEachDepotHasOneConsignee:

           sum (c in Consignees)

             CDSupply[c][d] <=1;

    and

    forall(d in Depots)

        ctUseContoDepot:

          sum (c in Consignees) CDSupply[c][d] <= Open [d];

    by

    forall(d in Depots)

         ctEachDepotHasOneConsignee:

           sum (c in Consignees)

             CDSupply[c][d] =Open [d];

     

    Regards,

    Olivier

     

  • Puppy26
    Puppy26
    17 Posts

    Re: Including Time Period in Optimization Model

    ‏2013-09-03T14:56:52Z  
    • ol
    • ‏2013-09-03T14:38:10Z

    if you want CDSupply[d] to be all 0 when d is closed and to have exactly one 1 when d is open, try to replace

    forall(d in Depots)

         ctEachDepotHasOneConsignee:

           sum (c in Consignees)

             CDSupply[c][d] <=1;

    and

    forall(d in Depots)

        ctUseContoDepot:

          sum (c in Consignees) CDSupply[c][d] <= Open [d];

    by

    forall(d in Depots)

         ctEachDepotHasOneConsignee:

           sum (c in Consignees)

             CDSupply[c][d] =Open [d];

     

    Regards,

    Olivier

     

    Hi Olivier,

    That's exactly I was working for. Works so perfect. Thanks a ton dude.

    Could you please say me how can I include multiple time period in this case now.

    Like for example, I have 6 months of operations. In the first 3 months, all the depots are opened and hence there are all the movements between consignees, shippers, depots and terminals.

    From the beginning of 4th month till 6th month, only 3 depots are opened and hence there is only movements for the opened depots that's the model we have developed now.

    My doubt is how and where should I include time period so that I can get the summarized single results for all 6 months.

    Is it possible?

    Any clue will be very helpful.

    Many thanks!

  • ol
    ol
    35 Posts

    Re: Including Time Period in Optimization Model

    ‏2013-09-03T15:14:07Z  
    • Puppy26
    • ‏2013-09-03T14:56:52Z

    Hi Olivier,

    That's exactly I was working for. Works so perfect. Thanks a ton dude.

    Could you please say me how can I include multiple time period in this case now.

    Like for example, I have 6 months of operations. In the first 3 months, all the depots are opened and hence there are all the movements between consignees, shippers, depots and terminals.

    From the beginning of 4th month till 6th month, only 3 depots are opened and hence there is only movements for the opened depots that's the model we have developed now.

    My doubt is how and where should I include time period so that I can get the summarized single results for all 6 months.

    Is it possible?

    Any clue will be very helpful.

    Many thanks!

    As we already discussed, if the periods are independent, just solve one period at a time, and collect the data you want. Then your expression can be evaluated on the data, no need to have a solver there!

    If the expression can be constrained, then the different periods are not independent, and you need a solver. You can add one dimension to your variables, e.g. CDSupply[c][d][period], and modify the constraints accordingly (forall period...)

    Regards,

    Olivier

  • Puppy26
    Puppy26
    17 Posts

    Re: Including Time Period in Optimization Model

    ‏2013-09-03T21:27:18Z  
    • ol
    • ‏2013-09-03T15:14:07Z

    As we already discussed, if the periods are independent, just solve one period at a time, and collect the data you want. Then your expression can be evaluated on the data, no need to have a solver there!

    If the expression can be constrained, then the different periods are not independent, and you need a solver. You can add one dimension to your variables, e.g. CDSupply[c][d][period], and modify the constraints accordingly (forall period...)

    Regards,

    Olivier

    Hi Olivier, 

    With help of your above idea, I have reworked on my model.

    All the constraints are fine and works good but I'm bit confused about how to construct the constraint for opening and closing of Depots as I mentioned earlier. If I use the below constraint

    forall (d in Depots, y in Years)
        Depotstaysclosed:
         sum (d in Depots) Open [d][y]<= 3;  

    The completely whole two depots are getting closed for a particular time which it shouldn't be.

    Do we need to use for loop or do loop? 

    Could you give me some more tips or clue to construct this constraint please.

    Many thanks!

     

     

    Attachments

  • Puppy26
    Puppy26
    17 Posts

    Re: Including Time Period in Optimization Model

    ‏2013-09-04T07:08:32Z  
    • Puppy26
    • ‏2013-09-03T21:27:18Z

    Hi Olivier, 

    With help of your above idea, I have reworked on my model.

    All the constraints are fine and works good but I'm bit confused about how to construct the constraint for opening and closing of Depots as I mentioned earlier. If I use the below constraint

    forall (d in Depots, y in Years)
        Depotstaysclosed:
         sum (d in Depots) Open [d][y]<= 3;  

    The completely whole two depots are getting closed for a particular time which it shouldn't be.

    Do we need to use for loop or do loop? 

    Could you give me some more tips or clue to construct this constraint please.

    Many thanks!

     

     

    Hi Olivier,

    Any tips or clue to improve the constraint will be very helpful.

  • ol
    ol
    35 Posts

    Re: Including Time Period in Optimization Model

    ‏2013-09-04T08:18:45Z  
    • Puppy26
    • ‏2013-09-04T07:08:32Z

    Hi Olivier,

    Any tips or clue to improve the constraint will be very helpful.

    Hello,

    just rewrite:

    forall (d in Depots, y in Years)
        Depotstaysclosed:
         sum (d in Depots) Open [d][y]<= 3; 

    as:

    forall (y in Years)
        Depotstaysclosed:
         sum (d in Depots) Open [d][y]<= maxNumberOfOpenDepotsForYear[y]; 

     

    Regards,

    Olivier

  • Puppy26
    Puppy26
    17 Posts

    Re: Including Time Period in Optimization Model

    ‏2013-09-04T09:11:41Z  
    • ol
    • ‏2013-09-04T08:18:45Z

    Hello,

    just rewrite:

    forall (d in Depots, y in Years)
        Depotstaysclosed:
         sum (d in Depots) Open [d][y]<= 3; 

    as:

    forall (y in Years)
        Depotstaysclosed:
         sum (d in Depots) Open [d][y]<= maxNumberOfOpenDepotsForYear[y]; 

     

    Regards,

    Olivier

    Hi Olivier,

    I have declared maxNumberOfOpenDepotsForYear as float and used the constraint and I got an error as Not an array type so I have removed [y] from the maxNumberOfOpenDepotsForYear and declared as

    forall (y in Years)
        Depotstaysclosed:
         sum (d in Depots) Open [d][y]<= maxNumberOfOpenDepotsForYear; 

    But I'm getting same results as when I used

    forall (d in Depots, y in Years)
        Depotstaysclosed:
         sum (d in Depots) Open [d][y]<= 3; 

    As mentioned earlier

     I have 6 years of operations. In the first 3 years, all the depots are opened and hence there are all the movements between consignees, shippers, depots and terminals.

    From the beginning of 4th years till 6th years, only 3 depots are opened and hence there is only movements for the opened depots. Hope I'm not confusing or using wrong logic here.

     

     

  • Puppy26
    Puppy26
    17 Posts

    Re: Including Time Period in Optimization Model

    ‏2013-09-04T11:39:59Z  
    • Puppy26
    • ‏2013-09-04T09:11:41Z

    Hi Olivier,

    I have declared maxNumberOfOpenDepotsForYear as float and used the constraint and I got an error as Not an array type so I have removed [y] from the maxNumberOfOpenDepotsForYear and declared as

    forall (y in Years)
        Depotstaysclosed:
         sum (d in Depots) Open [d][y]<= maxNumberOfOpenDepotsForYear; 

    But I'm getting same results as when I used

    forall (d in Depots, y in Years)
        Depotstaysclosed:
         sum (d in Depots) Open [d][y]<= 3; 

    As mentioned earlier

     I have 6 years of operations. In the first 3 years, all the depots are opened and hence there are all the movements between consignees, shippers, depots and terminals.

    From the beginning of 4th years till 6th years, only 3 depots are opened and hence there is only movements for the opened depots. Hope I'm not confusing or using wrong logic here.

     

     

    Hi,

    In one of the example in OPL Directory (Mining Plan), I saw a constraint like

    // Once closed, a mine stays closed

    forall (m in Mines, y in 1..NbYears-1)

    ctstaysclosed: Open[m][y+1]<=Open[m][y];

     

    It looks like what I have it in my mind but If i use this constraint, Depots is opened on all the time period.

    Do I need to any modification in this constrint for my requirements?

    Please do correct me.

    Many thanks!

     

  • ol
    ol
    35 Posts

    Re: Including Time Period in Optimization Model

    ‏2013-09-05T08:57:47Z  
    • Puppy26
    • ‏2013-09-04T11:39:59Z

    Hi,

    In one of the example in OPL Directory (Mining Plan), I saw a constraint like

    // Once closed, a mine stays closed

    forall (m in Mines, y in 1..NbYears-1)

    ctstaysclosed: Open[m][y+1]<=Open[m][y];

     

    It looks like what I have it in my mind but If i use this constraint, Depots is opened on all the time period.

    Do I need to any modification in this constrint for my requirements?

    Please do correct me.

    Many thanks!

     

    Hello,

    of course maxNumberOfOpenDepotsForYear is an array, containig the max Number Of Open Depots For each Year.

    so just declare it as an array and fill it!

    to declare an int array t:

    int t[1..size]=...;

    just have a look at the file you wrote, there are several examples of this.

    I repeat again:

    1. either you can solve the different period separately, this will be the most efficient way.

    2 or you need to introduce an other dimension to take the period into account. (for some reason after a while you started to use "year" instead of "period", so I answered with "year". If there is no differences between a year and the following year there is no need to separate them. Thus prefer period, you will have much smaller problems to solve.

    So you seem to have chosen (2). Just put the constraint as I sent yesterday (better with periods), and fill the array with your data, and that's it.

    Also, please do not post the same question everywhere!

    Regards,

    Olivier

     

  • Puppy26
    Puppy26
    17 Posts

    Re: Including Time Period in Optimization Model

    ‏2013-09-05T12:08:33Z  
    • ol
    • ‏2013-09-05T08:57:47Z

    Hello,

    of course maxNumberOfOpenDepotsForYear is an array, containig the max Number Of Open Depots For each Year.

    so just declare it as an array and fill it!

    to declare an int array t:

    int t[1..size]=...;

    just have a look at the file you wrote, there are several examples of this.

    I repeat again:

    1. either you can solve the different period separately, this will be the most efficient way.

    2 or you need to introduce an other dimension to take the period into account. (for some reason after a while you started to use "year" instead of "period", so I answered with "year". If there is no differences between a year and the following year there is no need to separate them. Thus prefer period, you will have much smaller problems to solve.

    So you seem to have chosen (2). Just put the constraint as I sent yesterday (better with periods), and fill the array with your data, and that's it.

    Also, please do not post the same question everywhere!

    Regards,

    Olivier

     

    Hi olivier,

    Well thanks for your feedback. About the name change from period to year. It's just name but the concept is still the same.

    But sorry I'm totally confused here.

    I'm getting an error as syntax error, unexpected (integer-literal) when i declare int y[1...size]=...;

    How about this constraint!

    forall(d in Depots, y in 1..NbYears-1)

    Depotstayclosed: Open [d][y] <= Open [d][y+1];

    In this case, I'm getting the result as

    Name        Year 1     Year 2       Year 3        Year 4       Year 5
    Depot1      Closed       Closed       Open          Open         Open
    Depot 2     Closed       Closed       Open          Open         Open
    Depot 3     Closed       Closed       Open          Open         Open        

    but I want my result should be like this

    Name        Year 1     Year 2       Year 3        Year 4       Year 5
    Depot1      Open       Open         Open          Open         Open
    Depot 2     Open       Open         Open          Open         Open
    Depot 3     Open       Open         Open          Closed       Closed

    I know I have almost got the answer but just need some small modification for fine tuning. Could you please help me here!!

    Many thanks!

     

  • ol
    ol
    35 Posts

    Re: Including Time Period in Optimization Model

    ‏2013-09-05T12:43:04Z  
    • Puppy26
    • ‏2013-09-05T12:08:33Z

    Hi olivier,

    Well thanks for your feedback. About the name change from period to year. It's just name but the concept is still the same.

    But sorry I'm totally confused here.

    I'm getting an error as syntax error, unexpected (integer-literal) when i declare int y[1...size]=...;

    How about this constraint!

    forall(d in Depots, y in 1..NbYears-1)

    Depotstayclosed: Open [d][y] <= Open [d][y+1];

    In this case, I'm getting the result as

    Name        Year 1     Year 2       Year 3        Year 4       Year 5
    Depot1      Closed       Closed       Open          Open         Open
    Depot 2     Closed       Closed       Open          Open         Open
    Depot 3     Closed       Closed       Open          Open         Open        

    but I want my result should be like this

    Name        Year 1     Year 2       Year 3        Year 4       Year 5
    Depot1      Open       Open         Open          Open         Open
    Depot 2     Open       Open         Open          Open         Open
    Depot 3     Open       Open         Open          Closed       Closed

    I know I have almost got the answer but just need some small modification for fine tuning. Could you please help me here!!

    Many thanks!

     

    no, the concept year is not equivalent to the concept period, a period and the previous one differ, otherwise there would be only one period. In your case you have 2 periods. not 5.

    Also by taking period instead of year, you do not need to have this constraint:

        forall(d in Depots, y in 1..NbYears-1)

        Depotstayclosed: Open [d][y] <= Open [d][y+1];

    remove it. Anyway, it looks as you copied it from another problem, and I do not see in what you said why it shoud match your problem.

     

    For the syntax error:

    Last time you were declaring an array as a float! 

    I told you to declare it as an array.

    Now, it seems you are declaring the index of an array as array!!

    If your are so confused, it will help you a lot to read a little bit the documentation.

    Regards,

    Olivier 

     

  • Puppy26
    Puppy26
    17 Posts

    Re: Including Time Period in Optimization Model

    ‏2013-09-05T14:31:51Z  
    • ol
    • ‏2013-09-05T12:43:04Z

    no, the concept year is not equivalent to the concept period, a period and the previous one differ, otherwise there would be only one period. In your case you have 2 periods. not 5.

    Also by taking period instead of year, you do not need to have this constraint:

        forall(d in Depots, y in 1..NbYears-1)

        Depotstayclosed: Open [d][y] <= Open [d][y+1];

    remove it. Anyway, it looks as you copied it from another problem, and I do not see in what you said why it shoud match your problem.

     

    For the syntax error:

    Last time you were declaring an array as a float! 

    I told you to declare it as an array.

    Now, it seems you are declaring the index of an array as array!!

    If your are so confused, it will help you a lot to read a little bit the documentation.

    Regards,

    Olivier 

     

    well,I'm reading some documentation too.. Could you please help me to develop the constraint for the below case. I'm trying many methods but I couldn't get the result.

    Name        Year 1     Year 2       Year 3        Year 4       Year 5
    Depot1      Open       Open         Open          Open         Open
    Depot 2     Open       Open         Open          Open         Open
    Depot 3     Open       Open         Open          Closed       Closed

    Hope to get some help from you please.-

    Regards

    Puppy