220 likes | 311 Views
Integrating a Real-World Scheduling Problem into the Basic Algorithms Course. Yana Kortsarts Computer Science Department Widener University, Chester, PA. The SAP Problem.
E N D
Integrating a Real-World Scheduling Problem into the Basic AlgorithmsCourse Yana Kortsarts Computer Science Department Widener University, Chester, PA
The SAP Problem • The shifts assignment problem (SAP) is a scheduling problem that commonly arises in work-force management activities • Input: A collection of shifts and work-force requirements • Output: The number of workers to assign to each shift in order to fulfill a pre-specified staff requirements at every hour.
Definitions • Working hours are denoted by 1, 2, . . , n • The [i, i + 1] hour is called the i-th hour of the day. • The staffing requirement for the i-th hour is bi - the number of persons needed at work from time i until time i + 1. • A shift Ii is a consecutive integral subinterval [si, si + 1, . . . , fi] of [1, . . . , n], si < fi • Shift Ii covers a time j: the shift starts at time j or earlier and ends at time j +1 or later. • If Ii covers j we say that j Ii (time j belongs to shift i)
The SAP Problem Solution • Defines how many persons xi are going to work in each shift Ii. • A solution is feasible if the number of workers present at time j is bj - the load bound for hour j (1 j n,1 i m, m is a number of shifts) : • A feasible solution might not exist.
Example • First hour is 08 : 00 to 09 : 00 and n = 5. • I1=[8:00, 9:00, 10:00] = [1, 2] • I2 = [11 : 00, 12 : 00] = [4] • I3=[10:00, 11:00, 12:00, 13:00] = [3, 4, 5] • The load requirements: 4, 4, 5, 8, 5 • Solution: x1= 4, x2 = 3, x3 = 5 • x2 + x3 = 8
SAP – Integer Linear Programming Problem • Consider shifts Ii as column vectors • A shift Ii (from si to fi ) is represented by a vector that has all 0 entries except the si to fi entries that are 1 • Create a 0, 1 matrix A out of all column vectors Ii. • A isconsecutive 1’s matrix. • Let • The problem is to find a solution for: or determine that no such solution exists.
Example • I1=[8:00, 9:00, 10:00] = [1, 2] • I2 = [11 : 00, 12 : 00] = [ 4] • I3=[10:00, 11:00, 12:00, 13:00] = [3, 4, 5] • The load requirements: 4, 4, 5, 8, 5
SAP – Integer Linear Programming Problem • SAP is an example of an integer linear programming (ILP) problem. • The integer linear programming problem is NP-hard. • Special case of integer linear programming over a consecutive 1’s matrix admits a simple solution by reduction to the max-flow problem
From SAP to Max Flow Problem • Add an all-0 row before the first row to the shifts matrix A and vectorb • A is (n + 1) m matrix. n+1 is the number of hours (including hour 0), the number of columns is m which is the number of shift types. • M is (n+1) (n+1) matrix. M has 1 in the main diagonal, and (−1) in the diagonal immediately above the main diagonal. Other entries are 0.
Multiply the equality Ax = b from the left by matrix M For 0 i < n row i in A is replaced by the row Ai − Ai+1 and row n does not change. A is a consecutive 1’s matrix. Matrix M A has exactly two non-zero entries in every column. M b = B = (-b1, b1 - b2, … bn-1 - bn, bn)T B = (B1, B2, …Bn), Bi= bi – bi+1 The matrix M is invertible M Ax = B is equivalent to Ax = b
EXAMPLE n = 5 (start: 8:00, finish: 12:00) Shifts: I1=[10:00, 11:00, 12:00], I2=[9:00, 10:00, 11:00, 12:00], I3 =[8:00, 9:00, 10:00, 11:00, 12:00], I4 =[12:00, 13:00], I5 = [8:00, 9:00, 10:00, 11:00], I6 = [8:00, 9:00, 10:00] Work load:3, 3, 5, 2, 5
Network Flows • A flow network is a weighted connected directed graph N(V,E) in which each edge (vi, vj) has a nonnegative capacity c(vi, vj) • We also distinguish two vertices in N, a sources and a destination (sink) t • A legal flowf in N is an assignment of a nonnegative real numbers f(e) to each edge e of N that satisfies two conditions: • Capacity constraints: For each edge e, 0 f(e) c(e) • Flow conservation: For each vertex v in N other than s and t, the flow into v equals the flow out of it
Define the flow network N(A, b) The vertices of the network are vi, 0 i n vi corresponds to row (hour) i in the matrix Add a source s and a sink t. The connection of the vertices to the source/sink are defined via the signs and values of B: Bi < 0: add an edge of capacity -Bifrom s to vi Bi > 0: add an edge of capacity Bifrom vi to t
The shifts define the edges between vertices. If shift starts at time q and ends at time p weadd an edge from vq−1 to vp. The edge has infinite capacity. Each column j of the matrix M·A is represented by the edge ej Each ej with (M·A)kj = -1 and (M·A)ij =1 goes out of vk into vi
v4 3 s v5 5 2 v2 v1 t 3 v3 3 v0
SAP admits a feasible solution if and only if there is a saturating flow in N(A, b): there is a legal flow so that the flow along all edges entering t equals their capacity. The flow along edges gives the values to be given to shifts:a flow value f(ej) on edge ejcorresponds to the choice of xj = f(ej) and vice-versa
v4 3/3 5 2 s v5 0 5/5 2/2 v2 0 v1 t 3/3 3/3 0 v3 3 v0 Solution
Teaching SAP • One of the arguments raised at times by students of the basic algorithms classes is that the material taught seems to be “detached” from real-world applications. This claim has some foundation. • It seems useful and encouraging to illustrate for the students the power of the algorithms taught in the basic algorithms course through a real-world problem. A concrete application that is important enough for commercial companies to actually write a code for it.
Teaching SAP • Solving the SAP problem is indeed a component in some real-world software applications, such as the OPA software designed by Ximes Inc. corporation, located in Vienna • Could be integrated into content conventionally taught in the basic algorithms course which includes polynomial time algorithms for the maximum flow problem. • Illustrates practical application of flow algorithms
Teaching SAP • Illustrates the importance of the seemingly abstract topic of linear algebra in real-world problems • Allows to introduce a fundamental problem: integer linear programming, which is a central problem in combinatorial optimization • SAP is an excellent programming project. The students gain experience in important things such as constructing graphs, multiplying matrices, and programming classic algorithms for maximum flow.
References [1] N. Balakrishnan and R.T. Wong, A network model for the rotating workforce scheduling problem, Networks, 20:25–42, 1990. [2] J.J. Bartholdi, J.B. Orlin, and H.D. Ratliff, Cyclic scheduling via integer programs with circular ones, Operations Research, 28:110–118, 1980. [3] T. H. Cormen, C. E. Leiserson, R. L. Rivest, and C. Stein, Introduction to Algorithms, Second Edition. MIT press, 2001. [4] T.G. Crainic, M. Gendreau, and J.M. Farvolden, A simplex-based tabu search for capacitated network design, INFORMS Journal on Computing, 12(3), 2000. [5] J. R. Driscoll, H. N. Gabow, R. Shrairman, and R. E. Tarjan, Relaxed heaps: An alternative to fibonacci heaps with applications to parallel computation, Communications of the ACM, 31(11):1343–1354, 1988. [6] Michael R. Garey and David S. Johnson, Computers and Intractability: A Guide to the Theory of NP-Completeness, Freeman and Co., 1979. [7] Johannes G¨artner, Nysret Musliu, and Wolfgang Slany, Rota: a research project on algorithms for workforce scheduling and shift design optimization, AI Communications: The European Journal on Artificial Intelligence, 14(2):83–92, 2001. [8] Fred Glover and Manuel Laguna, Tabu search, Kluwer Academic Publishers, 1997.
References [9] V. Klee and G. Minty, How good is the simplex algorithm? Academic Press, 1972. In Shisha, O., ed.: Inequalities, Volume III. [10] S. R. Kosaraju and A. L. Delcher, Large-scale assembly of DNA strings and space-efficient construction of suffix trees, In Proceedings of the twenty-seventh annual ACM symposium on Theory of computing, pages 169 – 177, 1995. [11] G. Laporte, The art and science of designing rotating schedules, Journal of the Operational Research Society, 50:1011–1017, 1999. [12] Nysret Musliu, Johannes G¨artner, and Wolfgang Slany, Efficient generation of rotating workforce schedules, Discrete Applied Mathematics, 118(1-2):85–98, 2002. [13] Nysret Musliu, Andrea Schaerf, and Wolfgang Slany, Local search for shift design, European Journal of Operational Research (to appear). [14] Nysret Musliu, Andrea Schaerf, and Wolfgang Slany, Local search for shift design, Technical Report DBAI-TR-2001-45, Technische Universit ¨at Wien, 2001, http://www.dbai.tuwien.ac.at/proj/Rota/DBAI-TR-2001-45.ps. [15] G.M. Thompson, A simulated-annealing heuristic for shift scheduling using non-continuously available employees, Comput. Oper. Res., 23(3):275–288, 1996.