A Constraint Logic Programming Approach to the

1 downloads 0 Views 198KB Size Report
the Constraint Logic Programming paradigm (CLP), but exploiting an e ective ... petitions among Italian universities, in order to promote the design of e ective ...
A Constraint Logic Programming Approach to the Crew Rostering Problem Filippo Focacci, Evelina Lamma, Paola Mello, Michela Milano DEIS - Universita' di Bologna Viale Risorgimento 2 I-40136 Bologna, Italy

felamma,

g

pmello, mmilano @deis.unibo.it [email protected]

Abstract

In this paper, we present a constraint based approach to the Crew Rostering Problem. A solution to this problem is the optimal sequencing of a given set of duties into rosters in order to satisfy a set of constraints. The optimality criterion concerns the minimization of the number of crews needed to cover the duties. This kind of problem has been traditionally solved with Operations Research (OR) techniques. We have used a mixed approach based mainly on the Constraint Logic Programming paradigm (CLP), but exploiting an e ective lower bound procedure taken from the OR. In this way, we can solve very large instances of the problem by maintaining the advantages of CLP such as declarativeness and rapid prototyping, while overcoming the limitations of CLP in dealing with large sized instances of hard problems.

1 Introduction The Crew Rostering Problem has been widely investigated in the eld of Operations Research (OR), [9, 2, 3, 12]. It concerns the construction of rosters by sequencing duties, which can be, for example, daily activities. Duties are characterized by their starting and ending time and other attributes which determine the diculty of the task. Duties should be sequenced in accordance with a set of constraints. Typical constraints concern the diculty of the whole roster and the period of time between two duties. This application is part of a wider problem of the Italian Railway Company, whose goal concerns the optimization of the daily assignment of trips to employees. Characteristics of this problem are the very large number of trips to be handled (up to 5000), the large number of constraints, and the fact that trips are activities to be considered every day. Such a problem is usually solved in two phases. The rst phase, called crew scheduling, is a short-term scheduling problem where trips are grouped in daily activities called duties. An example of a duty can be the sequence of trips Bologna ! Parma, Parma ! Milano, Milano ! Bologna; it represents a single activity that has to be executed every day. In the second phase, namely the crew rostering, duties have to be scheduled in rosters: a roster is a cyclic sequence of duties and represents a (monthly) working plan for a set of crews. The construction of rosters has to satisfy the constraints imposed by company regulations and labour laws. While the crew scheduling problem has been previously handled with Constraint Logic Programming (CLP) techniques (see [6]), to our knowledge, the crew rostering has never been solved either with CLP techniques or with a mixture of CLP and OR techniques1 . In 1994 Italian Railway Company, jointly with AIRO (Italian Operation Research Society), organized two competitions among Italian universities, in order to promote the design of e ective heuristic codes for the crew scheduling and rostering phases. On the second competition, called FARO (Ferrovie Airo Rostering Optimization), two prizes 1

In this paper, we present an approach to a crew rostering problem by mixing CLP (for the most part) and OR techniques, in particular a lower bound procedure taken from [2]. CLP [8] is a powerful programming paradigm combining the advantages of logic programming and the eciency of constraint solving. Many real life applications, such as scheduling, planning, sequencing and assignment problems, have been e ectively solved by using CLP techniques (see [10, 11, 7]). On the other hand, encapsulating Operational Research techniques in a CLP program makes it possible to develop ecient algorithms for large size and hard problems. The paper is organized as follows. Section 2 presents a description of the problem. Section 3 describes the modeling of the problem in terms of variables, data structures and constraints. Section 4 presents the structure of the algorithm and the heuristic adopted. Some experimental results are shown in section 4. Discussion and a mention of future works follow.

2 The problem domain A crew rostering problem is described as follows: Given a set of duties, the problem is to create a set of rosters such that all the duties are covered. A roster is a set of n weeks ; a week is a group of 6 consecutive days, the sixth of which is always a rest day. Each duty has to be assigned to one and only one roster; to assign a duty means to state in which day of which week of the roster the duty will be executed. Rosters are preferably composed of 5 weeks (= 30 days); since rosters are considered cyclic groups, the last week precedes the rst on the same roster. Once we have obtained the set of rosters, we can provide a working plan to each crew. In fact, since each duty is assigned once for every roster, while a duty should be executed every day, therefore we need, for each roster, a number of crews equal to the number of days in the roster. For example, suppose a crew starts a roster by executing its rst day on the 1st January 1997. There must be another crew starting the same roster by executing its second day on the 1st January 1997; another crew starting the same roster by executing its third day and so on. Therefore, we need a number of crews equal to the number of days in the roster. Each duty, identi ed by a number i, has input attributes which identify it and de ne its diculty. These attributes are: start time si and end time fi ; working time wi and paid time pi 2 (the paid time can be greater then the working time); external rest, overnight, heavy overnight and long duty, which are boolean parameters de ning the heaviness of a duty. Therefore, we can describe each duty as a tuple:

duty(i; si; fi; wi; pi; ext resti ; longi; overnighti; heavy overi ): For example, the duty characterized by the following tuple:

duty(5; 245; 468; 223; 223; 0; 0; 1; 0): is a (non heavy ) overnight duty starting at 4:05 a.m., nishing at 7:48 a.m. with working time and paid time of 3 hours and 43 minutes. were to be assigned to the codes giving the best and the second best solution on three instances with up to 1,000 duties. The OR group of the University of Bologna took part in the FARO competition and won the rst prize giving the best solution for all the instances, following a pure OR approach. 2 Since a duty is never longer then 24 hours, s , f , w , and p are all integer numbers between 0 and 1440 (= 24 i i i i hrs  60 mins).

A weekly rest is a time interval always containing the sixth day; if it contains at least two complete days (a complete day is a time interval 24 hours long (1440 minutes) starting at midnight) it is called double weekly rest ; otherwise it is called single weekly rest. A technical interval is a rest day between two duties in the same week.

2.1 Constraints

One of the characteristics of this problem is the large number of constraints to be considered. Sequencing rules

 The minimum rest between two duties is 18 hours, unless both duties are overnight, in which     

case the minimum rest is 22 hours. Every weekly rest must be at least 48 hours long3 . Each heavy overnight duty cannot be followed by another heavy overnight duty. Each pair of consecutive overnight duties cannot be followed by another duty starting earlier than 22 hours from the end of the second duty of the pair. If an overnight duty precedes a single weekly rest, then the rst duty of the next week cannot start earlier than 6.30 a.m. For each duty starting before 6 a.m. following a double weekly rest, the weekly rest must span at least three days.

Week's constraints

For each week there can be no more than two duties with external rest, no more than one long duty and no more than two overnight duties. Roster's constraints

For each roster the average weekly rest time must be at least equal to 58 hours; the number of double weekly rests must be at least equal to 40% of the total number of weekly rests. Cyclic constraints

For each cyclic group of 30 days within a roster there can be no more than 7 duties with external rest, and the total paid time of all the included duties cannot exceed 170 hours. For each cyclic group of 7 consecutive days within a roster, the total working time of the included duties cannot exceed 36 hours.

2.2 Problem objective

The objective is to nd a feasible set of rosters covering all the duties minimizing the total number of weeks used. A secondary objective is to minimize the number of technical intervals. Note that even if each weekly rest must be at least 48 hours long, it does not mean that it contains two complete days. For example, a weekly rest starting at 5 p.m. on Wednesday and nishing at 5 p.m. on Friday, is a single weekly rest because it does not contain two complete days. 3

3 The modeling of the problem

3.1 Domain variables'

The structure used to identify the temporal location of a duty is the following:

duty location(Nro; [Day; Week; Rost; Time]; Prev duty; Next) where Nro identi es the duty. Day , Week, Rost and Time are domain variables used to assign a time and a roster to the duty. The domain variable Next is used to identify the duty that follows; it can also assume the values -2, -1 and 0 which represent, respectively, a double or single weekly rest or a technical interval. Prev duty is used to maintain some information about the preceding duty. It is worth noting that this representation allows us to express all the constraints in the most natural way. However, it is a redundant representation since, for example, the variable Time gives complete information about when the duty has to be executed. Therefore, knowing such variable, all the others (Day , Week and Rost) are known by means of the constraints4:

Time = 6Week + Day Rost = (Week ? 1) div 5 + 1

This redundancy introduces an overhead due to the propagation of the above constraints. However, it simpli es the problem representation and the constraint handling. 3.1.1 Constraints de nitions

Constraints involved in the problem have been de ned in section 2.1. In this section, we formalize these constraints and present some implementation details. Constraints can be divided in three groups according to the way they are handled during the computation:  Preprocessing constraints;  Local constraints;  Research constraints; The rst kind of constraints can be satis ed during the preprocessing phase, which will be further explained in section 5, and these constraints do not play any role during the search. The constraints imposed during this step are the following: a. The minimum rest between two duties is 18 hours, unless both duties are overnight. In this case the minimum rest is 22 hours. It is possible to prove that the formalization for these constraints is: (fi > 24h ? 18h) ^ (sj < fi + 18h ? 24h) ) Nexti 6= j

Overnighti ^ Overnightj ^ (fi > 24 ? 22h) ^ (sj < fi + 22 ? 24h) ) Nexti 6= j

b. Each heavy overnight duty cannot be followed by another heavy overnight duty:

HeavyOveri ^ HeavyOverj ) Nexti 6= j 4

The constraint Time = 6Week + Day allows us to compute Week and Day if Time is known and vice versa.

c. No more then one long duty per week is allowed5

Longi ^ Longj ) Nexti 6= j d. The following constraint is not explicitly de ned by the problem but it is implicit in the fact that a week is a sequence of 6 days, the 6th of which is always a rest.

(fi < si ) ) Dayi 6= 5 Local constraints are stated and propagated within a single roster. Most of them can be easily formalized by using the user de ned constraint atmost(Nb,[X1, ...Xn ],Val), available in most CLP(FD) solvers like CHIP [4] and ECLi PSe [5]. Declaratively, the constraint atmost(Nb,[X1, ...Xn ],Val) holds i at most Nb elements Xi are equal to Val. For example, the following constraints are implemented as shown: a. For each week there can be no more than 2 duties with external rest, no more then 1 long duty and no more then 2 overnight duties:

atmost(2; WEstRest; N ) atmost(1; WLong; N ) atmost(2; WOver; N ) where WestRest, WLong and WOver are lists containing the domain variables for Week of duties with external rest, long duties and overnight duties, respectively. Variable N represents a number

which identi es the week. b. A similar constraint concerns the roster, and states that no more than 7 duties with external rest can be performed within the same roster. Therefore, if RostEstRest is a list of domain variables of duties with external rest and R a number identifying the roster, the constraint can be formalized as: atmost(7; RostEstRest; R) c. Within a roster, the total paid time of all the included duties cannot exceed 170 hours6

X

i Rosti =N

pi  170h

j

d. Every weekly rest must be at least 48 hours long.

8i i=1::MaxWeek ri  48h j

where ri is the time interval between the end of the last duty in a week and the start of the rst duty in the next week. MaxWeek is the overall number of weeks. e. Each couple of consecutive overnight duties cannot be followed by another duty starting earlier than 22 hours from the end of the second duty of the couple: 5 Since this constraint entails the following formula Longi ^ Longj ) Nexti 6= j , in a preprocessing phase, we can prune the search tree by considering the relaxed constraint. 6 The original constraint is de ned as follows: for each cyclic group of 30 days within a roster, the total paid time of all the included duties cannot exceed 170 hours. However, if we consider rosters of 30 days (this happens in every roster but the last one) the constraint can be reduced to the simpler form shown above.

Overnighti ^ OvernightNext ^ fNext > 24h ? 22h ^ sj < fNext + 22h ? 24h ) NextNext 6= j i

i

i

i

We have two extra constraints which are usually entailed by other stronger constraints: f. For each duty starting before 6 a.m. following a double weekly rest, the weekly rest must span at least three days and g. If an overnight duty precedes a simple weekly rest, then the rst duty of the next week cannot start earlier than 6.30 a.m. Research constraints are usually dynamically stated during the search phase. a. For each cyclic group of 7 consecutive days within a roster the total working time of the included duties cannot exceed 36 hours7 X w  36h i i Dayi =k::k+7 j

b. For each roster the average weekly rest time must be at least equal to 58 hours

P

i Rosti=N ri j

NWeek

 58h

Note that in each roster we have NWeek = 5 except for the last one where NWeek  5.

4 Example In this section, we present an example of a problem instance and the relative solution. Suppose we have the following set of duties: duty(4, 245, 468, 223, 223, 0, 0, 1, 0). duty(5, 255, 594, 339, 339, 0, 0, 1, 0). duty(8, 286, 683, 397, 397, 0, 0, 1, 0). duty(10, 305, 751, 446, 446, 0, 0,0, 0). duty(11, 316, 638, 322, 322, 0, 0, 0, 0). duty(12, 331, 713, 382, 382, 0, 0, 0, 0). duty(14, 358, 749, 391, 391, 0, 0, 0, 0). duty(17, 401, 925, 524, 524, 0, 1, 0, 0). duty(27, 580, 1056, 476, 476, 0, 0, 0, 0).

duty(34, duty(36, duty(38, duty(43, duty(56, duty(65, duty(67, duty(69,

705, 1215, 510, 510, 0, 1, 0, 0). 735, 548, 648, 1253, 1, 0, 1, 0). 755, 518, 714, 1203, 1, 0, 1, 0). 825, 419, 559, 1034, 1, 0, 1, 0). 1020, 406, 370, 826, 1, 0, 1, 0). 1161, 1381, 220, 220, 0, 0, 0, 0). 1161, 8, 287, 287, 0, 0, 1, 0). 1302, 286, 424, 424, 0, 0, 1, 1).

A solution for this problem is depicted in gure 1. We have 5 weeks (6 days each). Grey boxes represent duties. Each duty is numbered by its identi er. The black boxes represent rests. There are two double weekly rests (between the rst and the second week and between the fourth and the fth week) out of ve weekly rests. The average weekly rest time is 59 hours and 53 minutes and the paid time is 120 hours and 32 minutes. This solution represents a roster which can be executed by a crew, starting from the rst day of the rst week. Since duties are activities that should be executed every day, a second crew starts executing the same roster the second day of the rst week, and so on. Therefore, we need a number of crews equal to the number of days in the roster. For this reason, every saved week corresponds to saving six crews. 7 This formalization is quite di erent from the one used in the implementation since Day is a domain variable ranging between 1 and 5. However, the constraint considers 7 consecutive days.

Day 1 1 Week

Day 2

D36

Day 3

D34

2 Week D69

3 Week

Day 5

Day 6

D65 D8

D17 D43

D38

5 Week

D67

D56 D4

D5

4 Week

Day 4

D10

D27 D11

D12

D14

Figure 1: Solution of a crew rostering problem

5 Implementation In this section, we present the structure of the algorithm adopted. The rst step corresponds to a preprocessing phase where the above mentioned preprocessing constraints make it possible to delete variable values which cannot appear in any feasible solution. It is worth noting that these constraints are no longer taken into account during the search. The second step concerns the local constraint de nition. These constraints are user-de ned constraints and play an active role during the search. Rosters are constructed sequentially and independently. Also for each roster, weeks are considered sequentially. In fact, given a certain duty, we rst instantiate the variable Time which gives us complete information on variables Day and Week. Second, we choose the next duty to be performed by instantiating the variable Next. This choice is made according to the least constraining principle which prefers those values which seem most likely to succeed. For eciency reasons, we improved the heuristic on the choice of the next duty by dividing duties into homogeneous groups, i.e., groups with common characteristics. For each group we consider only the few duties which are the most likely to succeed. This improvement allows us, on one hand, to avoid the backtracking thrashing behavior but, on the other hand, leads to an incomplete search algorithm. However, this incompleteness does not prevent us for nding a good solution. In most cases, in fact, we are able to nd the optimal solution since its value corresponds to the lower bound. We also have other heuristics on the construction of weeks based on the evaluation of the number of remaining weeks for the optimal solution. The evaluation is obtained by a lower bound procedure taken from [2]. The lower bound is obtained solving an Assignment Problem which can take into account all the sequencing rules and (in a lagrangian fashion) the constraint imposing a minimum percentage of double weekly rests. Computational experience has shown that for real world instances the optimal value of the objective function (minimum number of weeks used) is very closed to the lower bound. The lower bound is used in order to evaluate the diculty of each constraint. Suppose the lower bound results in 3 remaining weeks and we still have 6 overnight duties to consider. Then we have to assign 2 overnight duties for each week, which corresponds to the maximum number allowed. We can deduce that this constraint is very tight. On the other hand, suppose we have one more long duty to be assigned. Then the constraint on long duties is very loose. In this way, we can exploit a heuristic which is similar to the one used for the bottleneck analysis in scheduling problems [1].

We select rst those duties which play the most important part in the tightest constraints, those being the bottlenecks of our problem. As concerns the problem symmetries, we can identify two di erent kinds: symmetries on the overall rostering, due to the fact that the solution (RosterA , RosterB , RosterC ) is equivalent to the solution (RosterB , RosterC , RosterA ), and symmetries on a single roster, due to the fact that the partial solution (WeekA , WeekB , WeekC ) is equivalent to the partial solution (WeekB , WeekC , WeekA ). In general, the search space is very large and backtracking is never deep enough to nd two equivalent solutions. However, the second kind of symmetry allows us to make some committed choices which do not a ect the completeness of the algorithm but highly increases its eciency. We impose, for example, that the rst duty of the rst week of each roster must start after 6.30 a.m. This choice allows us to satisfy the constraints f and g, de ned in section 3.1.1, between the last and the rst week, which would be otherwise computationally expensive. In this way, we reduce the number of the equivalent solutions generated by the cycles. Another committed choice imposes the position of two double weekly rests in each roster8. Finally, we present a post-optimization procedure which allows us to improve the rst solution found. It is based on the following idea: we evaluate the quality of each roster but the last one (the only roster which can be shorter than ve weeks) by using the lower bound procedure, which gives us an optimistic evaluation of the number of weeks needed. Then we select the worse roster R1 and the one R2 which, together with R1, has the highest probability of improving the solution. Then, we reconsider and solve a crew rostering problem for rosters R1, R2 and the last one. In this way, we can improve the solution mainly because the instance considered is smaller than the original one, and we can use more expensive and accurate heuristics. If the found solution improves the overall solution, we substitute the rosters considered with the new ones and iterate the procedure. Otherwise, we change the pair of rosters considered and restart the post-optimization procedure. Although the results of the post-optimization procedure are encouraging, it is sometimes quite computationally expensive. The improvement of this procedure is the subject of future work.

6 Results We have implemented the system on a Pentium 100 Mz with 16 Mb RAM and the Linux operating system. We have used the constraint logic programming language ECLi PSe and in particular, its nite domain library, while the lower bound procedure is written in C and linked to the CLP program. The CLP paradigm is very suitable for this kind of application since the problem domain can be straightforwardly mapped in a CLP language. Finite domain constraint solvers like ECLi PSe provide a very powerful set of symbolic constraints (as, for example the constraint atmost/3 used in section 3.1.1), and the possibility of writing new user-de ned constraints together with their propagation mechanisms. These capabilities are very useful in dealing with real-life problems because they make it possible to express complex relations between variables and the way of handling them. In the following table, we present some results in terms of computational time and the quality of the solution found. We report the lower bound of the problem (LB), the results of the operational research approach [2] and our approach in terms of number of weeks and CPU time. We present the results of real world problems (for increasing number of duties, N) taken from the Italian Railway Company. 8

The minimal number of double weekly rests in a 5 week roster is 2

N LB OR CLP Duties Weeks Weeks Time (sec) Weeks Time (sec) 21 7 7 8 7 2 33 11 11 17 11 6 69 19 19 650 19 246 134 39 39 365 39 447 164 48 48 106 48 107 360 108 111 342 111 466 386 118 118 443 118 1045 525 164 164 1185 164 1883 The quality of the found solution is the same in the OR and in the CLP approach and in both cases is either the optimal solution (equal to the lower bound) or very close to it. As concerns the performances of the two approaches, they are very similar. Thus, the results are very encouraging since the CLP prototype has been developed in a very short time and the code is concise, readable, extensible and easily modi able. The largest part of the CPU time is used by the post-optimization procedure. In fact, if we accept a slightly worse solution, the computational time dramatically decreases. For example, in the instance with 386 duties the rst solution we reach results in 119 weeks (one week more than the optimal solution) we take 525 seconds. Again, in the instance of the problem with 134 duties we can reach a solution with 40 weeks (again one week more than the optimal solution) in 183 seconds.

7 Conclusions In this paper, we have presented a constraint-based approach to a crew rostering application for the Italian Railways. Previous approaches to this problem were mainly based on Operations Research techniques and on a rigid mathematical formalization of the problem. To our knowledge, there is no other CLP approach to the crew rostering problem. Our approach is mainly based on the CLP paradigm enhanced with a lower bound procedure taken from the Operations Research eld [2]. The use of the lower bound procedure taken from the Operations Research eld allows us to obtain excellent performances even on large sized and hard problems. In addition, we think that by improving some heuristics and the post optimization procedure, we can increase our performances, since we noticed that the largest part of the CPU time is due to the post-optimization procedure. Moreover, by using the CLP approach, we can bene t from the declarative way of programming which leads to short, readable, extensible and easily modi able programs. In addition, the conciseness of programs and the extremely rapid prototyping and testing time make it possible to rapidly develop alternative versions and compare their eciency and usefulness.

8 Acknowledgments We would like to thank Paolo Toth for having provided the lower bound procedure code included in our algorithm and for very fruitful discussions about the problem. In addition, we would like to thank anonymous referees for useful comments on the earlier version of this paper.

References [1] S. Breitinger and H.C.R. Lock. Using Constraint Logic Programming for Industrial Scheduling Problem, chapter 9. Elsevier Science B.V, 1995. [2] A. Carrara, M.Fischetti, P.Toth, and D. Vigo. Models and algorithms for crew rostering problems. Technical report, DEIS Universita di Bologna, 1996. [3] P. Carraresi and G. Gallo. A multilevel bottleneck assignment problem for the bus drivers' rostering problem. European Journal of Operaional Research, 16:163{173, 1984. [4] M. Dincbas, P. Van Hentenryck, H. Simonis, A. Aggoun, T. Graf, and F. Berthier. The Constraint Logic Programming language CHIP. In Proceedings of the International Conference on Fifth Generation Computer System (FGCS88), pages 693{702, 1988. [5] ECRC. ECLi PSe User Manual Release 3.3, 1992. [6] N. Guerinik and M. Van Caneghem. Solving Crew Scheduling Problem by Constraint Programming. In U.Montanari and F.Rossi, editors, Proceedings of the 1st Conference of Principles and Practice of Constraint Programming, pages 481{498, 1995. [7] P. Van Hentenryck. Constraint Satisfaction in Logic Programming. MIT Press, 1989. [8] J. Ja ar and M.J. Maher. Constraint Logic Programming: a Survey. Journal of Logic Programming on 10 years of Logic Programming, 19-20:503{582, 1994. [9] L.Bianco, M.Bielli, A.Mingozzi, S. Ricciarelli, and M.Spadoni. A heuristic procedure for the crew rostering problem. European Journal of Operational Research, 58:272{283, 1992. [10] M.Dincbas, P.Van Hentenryck, and M.Simonis. Solving the car sequencing problems in constraint logic programming. In ECAI88, European Conference on Arti cial Intelligence, 1988. [11] M.Dincbas, P.Van Hentenryck, and M.Simonis. Solving large combinatorial problems in logic programming. Journal of Logic Programming, 8 (1-2):75{93, 1990. [12] D.M. Ryan. The Solution of Massive Generalized Set Partitioning Problem in Air-crew Rostering. Journal of the Operational Research Society, 43:459{467, 1992.