This paper was converted on www.awesomepapers.org from LaTeX by an anonymous user.
Want to know more? Visit the Converter page.

Train Scheduling with Hybrid Answer Set Programmingthanks: This is a substantially extended and revised version of (Abels et al. 2019).thanks: This work was partially funded by DFG grants SCHA 550/9 and 11.

DIRK ABELS    JULIAN JORDI
SBB
   Switzerland    MAX OSTROWSKI
Potassco Solutions
   Germany    TORSTEN SCHAUB
Potassco Solutions
Affiliated with Simon Fraser University, Canada, and Griffith University, Australia.
   Germany    and University of Potsdam    Germany    AMBRA TOLETTI
SBB
   Switzerland    PHILIPP WANKO
Potassco Solutions
   Germany    and University of Potsdam    Germany
Abstract

We present a solution to real-world train scheduling problems, involving routing, scheduling, and optimization, based on Answer Set Programming (ASP). To this end, we pursue a hybrid approach that extends ASP with difference constraints to account for a fine-grained timing. More precisely, we exemplarily show how the hybrid ASP system clingo[DL] can be used to tackle demanding planning-and-scheduling problems. In particular, we investigate how to boost performance by combining distinct ASP solving techniques, such as approximations and heuristics, with preprocessing and encoding techniques for tackling large-scale, real-world train scheduling instances.

1 Introduction

Densely-populated railway networks transport millions of people and carry millions of tons of freight daily; and this traffic is expected to increase even further. Hence, for using a railway network to capacity, it is important to schedule trains in a flexible and global way. This is however far from easy since the generation of railway timetables is already known to be intractable for a single track [Caprara et al. (2002)]. Moreover, hundreds of train lines on a densely connected railway network lead to complex inter-dependencies due to connections between trains and resource conflicts.

We take up this challenge and show how to address real-world train scheduling with hybrid Answer Set Programming (ASP [Lifschitz (1999)]). Our hybrid approach allows us to specifically account for the different types of constraints induced by routing, scheduling, and optimization. While we address paths and conflicts with regular ASP, we use difference constraints (over integers) to capture fine timings. Similarly, to boost (multi-objective) optimization, we study approximations of delay functions of varying granularity. This is complemented by domain-specific heuristics aiming at improving feasibility checking. Moreover, we introduce preprocessing techniques to reduce the problem size and search space, and provide redundant constraints improving propagation. This lifts our approach to a level that allows us to create high quality train schedules spanning six hours for a portion of Switzerland within minutes.

In current practice, train schedules evolve by only minor adjustments year-over-year. The basic structure of the schedule has been shown to be more or less feasible in practice. The current scheduling tools offer limited support for conflict detection and no support for automatic conflict resolution. When additional trains are ordered by railway companies during the year, or when capacity is reduced because of maintenance work, it is up to the professional experience and ingenuity of the planner to find a producible schedule or to reduce the number of services if no feasible solution can be found. In a first step, the solution described in this paper are intended to be used by the industrial partner in a decision support system providing planners with conflict-free schedules for adding additional trains into an existing schedule structure. The planner only has to enter the commercial requirements for the additional train, everything else shall be taken care of by the system. In later steps, it is hoped that our solution can be scaled to eventually generate complete, conflict free schedules from scratch for the whole country and also continually optimize them during operations to account for deviations and disruptions.

We implement our approach with the hybrid ASP system clingo[DL] [Janhunen et al. (2017)], an extension of clingo [Gebser et al. (2019)] with difference constraints. To begin with, we introduce in Section 3 a dedicated formalization of the train scheduling problem. This is indispensable to master the complex inter-dependencies of the problem. We present our solution in terms of hybrid ASP encodings, including a detailed description of preprocessing, encoding and heuristic techniques in Section 4. Finally, we evaluate our approach on real-word instances in Section 5.

2 Background

We rely on a basic acquaintance with ASP. The syntax of our logic programs follows the one of clingo [Gebser et al. (2015)]; its semantics is detailed in [Gebser et al. (2015)].

The system clingo[DL] extends the input language of clingo by (theory) atoms representing difference constraints. That is, atoms of the form

&diff{u\,u-vv\,} <= dd

where u,vu,v are symbolic terms and dd is a numeral term, represent difference constraints such as ‘uvdu-v\leq d’, where u,vu,v serve as integer variables and dd stands for an integer.111Strictly speaking, we had to distinguish the integer from its representation. For instance, assume that ‘&diff{e(T)-b(T)} <= D’ stands for the condition that the time between the end and the beginning of a task T must be less or equal than some duration DD. This may get instantiated to ‘&diff{e(7)-b(7)} <= 42’ to require that e(7) and b(7) take integer values such that ‘𝚎(𝟽)𝚋(𝟽)42\mathtt{e(7)}-\mathtt{b(7)}\leq 42’. Note that u,vu,v can be arbitrary terms. We exploit this below and use instances of pairs like (T,N) to denote integer variables. Among the alternative semantic couplings between (theory) atoms and constraints offered by clingo[DL] (cf. [Janhunen et al. (2017), Gebser et al. (2016)]), we follow the defined, non-strict approach (i) tolerating theory atoms in rule heads and (ii) enforcing their corresponding constraints only if the atoms are derivable. Hence, if a theory atom is false, its associated constraint is ignored. This approach has the advantage that we only need to consider difference constraints occurring in the encoding and not their complements. Obviously, one great benefit of using such constraints is that their variables are not subject to grounding.

For boosting performance, we take advantage of clingo’s heuristic directives of form

#heuristic aa:BB. [ww,sign]

where aa is an atom and BB is a body; ww is a numeral term and sign a heuristic modifier, indicating how the solver’s heuristic treatment of aa should be changed whenever BB holds. Whenever aa is chosen by the solver, sign enforces that it becomes either true or false depending on whether ww is positive or negative, respectively. See [Gebser et al. (2013), Gebser et al. (2015)] for a comprehensive introduction to heuristic modifiers in clingo.

3 Real-world train scheduling

3.1 Problem introduction

The train scheduling problem can essentially be divided into three distinct tasks: routing, conflict resolution and scheduling.

1p=1p=123581011124769connection t2t_{2} to t3t_{3}connection t1t_{1} to t3t_{3}𝑠𝑤1\mathit{sw}_{1}𝑠𝑤2\mathit{sw}_{2}t1t_{1}t2t_{2}t3t_{3}
Figure 1: Routing of three train lines through a railway network.

First, train lines are routed through a railway network. One such network is given in Figure 1. By and large, it is a directed graph containing nodes 1 through 12 with edges in between, for instance, (2,3)(2,3) and (10,12)(10,12). Given this directed graph, we assign paths through the network to three train lines, viz. t1t_{1}, t2t_{2} and t3t_{3}. Each train line is assigned an acyclic subgraph capturing its travel trajectory. In our example, the subgraphs for t1t_{1}, t2t_{2} and t3t_{3} are indicated by solid, dotted and dashed edges, respectively. Note that (10,12)(10,12) belongs to the subgraph of both t1t_{1} and t3t_{3}. We see that t1t_{1} has several different start nodes, viz. 1 and 2, and end nodes, viz. 11 and 12, whereas t2t_{2} and t3t_{3} have no alternative routes. One possible solution to the routing task in Figure 1 is represented by edges colored blue, red and green marking valid paths for t1t_{1}, t2t_{2} and t3t_{3}, respectively

Second, edges in the network are assigned resources representing, for example, the physical tracks or junctions that can only be passed by a single train at once. Whenever two train lines share edges assigned the same resource, a decision has to be made which train line passes first. In our example, we assume that each edge is assigned a resource representing the physical track. Furthermore, we have two junctions, 𝑠𝑤1\mathit{sw}_{1} and 𝑠𝑤2\mathit{sw}_{2}, that are assigned five edges each. More precisely, 𝑠𝑤1\mathit{sw}_{1} is assigned to (1,3),(2,3),(3,5),(3,6)(1,3),(2,3),(3,5),(3,6) and (4,3)(4,3), and 𝑠𝑤2\mathit{sw}_{2} to (8,10),(9,10),(10,11),(10,12)(8,10),(9,10),(10,11),(10,12) and (10,7)(10,7). The junctions highlight a common structural property of train scheduling instances on which we rely heavily to reduce the amount of decisions that have to be made to resolve resource conflicts. Let us focus on 𝑠𝑤2\mathit{sw}_{2} and the resource conflicts of the three train lines in edges (8,10),(9,10),(10,7),(10,11)(8,10),(9,10),(10,7),(10,11) and (10,12)(10,12). Instead of deciding each pair of edges with shared resources individually, we can decide which train line enters a set of edges assigned 𝑠𝑤2\mathit{sw}_{2} first. More precisely, we decide in which order t1t_{1}, t2t_{2} and t3t_{3} enter {(8,10),(10,11),(10,12)}\{(8,10),(10,11),(10,12)\}, {(10,7)}\{(10,7)\} and {(9,10),(10,12)}\{(9,10),(10,12)\}, respectively. This is possible because train lines using the same resource cannot overtake each other once they are within these sets of edges. We call such sets resource areas. Note that while it is obvious in our example what said areas are (they are equal to the full set of assigned edges for each resource and train line), this may not be the case in general. For instance, there are many alternative paths in complex train stations, and thus shared resources might be visited several times enabling train lines to overtake one another.

Finally, a schedule has to be created that assigns each train line an arrival time at all nodes in its path. A valid schedule has to respect a variety of timing constraints, ranging from earliest and latest arrival times at nodes, traveling and waiting times on edges, resource conflicts between train lines, to connections between train lines.

t1t_{1}23581011t2t_{2}10743t3t_{3}3691012VVtt720720600600480480360360240240120120dt1d_{t_{1}}dt2d_{t_{2}}dt3d_{t_{3}}
Figure 2: Scheduling of three train lines.

Figure 2 shows the earliest and latest arrival times for nodes of the valid paths of Figure 1. This is indicated by the light blue, red and green areas for train lines t1t_{1}, t2t_{2} and t3t_{3}, respectively. For instance, t2t_{2} may arrive at node 10 at the earliest at time point 0 and at the latest at time point 360 or t1t_{1} at node 5 between 360 and 660. Furthermore, Figure 2 shows a valid schedule for train lines t1t_{1}, t2t_{2} and t3t_{3} as indicated by the blue, red and green lines, respectively. This schedule results from the decisions that t2t_{2} and t3t_{3} enter 𝑠𝑤1\mathit{sw}_{1} before t1t_{1} and, conversely, that t1t_{1} enters 𝑠𝑤2\mathit{sw}_{2} before t3t_{3}. Each resource conflict is resolved by a timing constraint indicating that the following train line enters the resource only after the preceding train line has left it plus a safety period. In our example, this safety period, as well as the travel time for each edge, is 60 seconds. This is reflected in the schedule since t2t_{2} starts at 0 in node 10 and proceeds to node 7 at 60, and t1t_{1} only enters 𝑠𝑤1\mathit{sw}_{1} at node 2 a minute after t3t_{3} has left it at node 6.

In our example, there are three connections. Our concept of connections captures transfer of passengers and cargo in various contexts, as well as the transfer of physical trains between train lines. The latter enables us to express cyclic train movements as can be seen with the connection of t2t_{2} to t3t_{3} on edges (4,3)(4,3) and (3,6)(3,6). We call such a connection collision-free since resource conflicts are disregarded on all connected edges that share the same resource, and the connection furthermore requires both train lines to arrive at node 3 at the exact same time point. This connection expresses that the same physical train is used for train line t2t_{2} and t3t_{3} and seamlessly transitions at node 3.222For simplicity, we assume that collision-free connections are already given with a transitive closure of all adjacent edges of the same resource and all possible other collision-free connections of other trains of that resource. The results are reflected in the connected paths in Figure 1 and the same arrival time at node 3 in Figure 2. The two other connections from t1t_{1} to t3t_{3} on either edges (10,11)(10,11) and (10,12)(10,12) or (10,12)(10,12) and (10,12)(10,12), on the other hand, capture a possible transfer of passengers or cargo from train line t1t_{1} to t3t_{3}. The connection requires t3t_{3} not to arrive at 12 before t1t_{1} has arrived by at least one minute at 10 so that a transfer is possible. Since this connection does not disable resource conflicts, this can only be achieved if t1t_{1} precedes t2t_{2} through 𝑠𝑤2\mathit{sw}_{2} which makes t2t_{2} wait between nodes 6 and 9 until t1t_{1} has left.

After obtaining a valid routing and scheduling, the solution is evaluated regarding the delay of the train lines and the quality of the paths they have taken. The former is calculated by summing up the delay of each train line at each node in their paths. For that purpose, a time point is defined after which the train line is considered delayed at a node. In Figure 2, these time points are indicated by lines dt1,dt2d_{t_{1}},d_{t_{2}} and dt3d_{t_{3}}. For instance, t3t_{3} is delayed at nodes 9, 10 and 12, thus accumulating a penalty of 120+120+120=360120+120+120=360. For the quality of the routes, penalties are assigned to edges and accumulated for every train line traveling that edge. Such penalties may indicate tracks that can manage less workload, are in need of maintenance, or are known to be a detour, and therefore to be avoided if possible. In our example, only edge (1,3)(1,3) is assigned a penalty of one, other edges are assumed to have a penalty of zero, therefore our routing is optimal and accumulates no routing penalties.

3.2 Problem formalization

We formalize the train scheduling problem as a tuple (N,T,C,F)(N,T,C,F) having the following components:

  • NN stands for the railway network (V,E,R,m,a,b)(V,E,R,m,a,b), where

    • (V,E)(V,E) is a directed graph,

    • RR is a set of resources,

    • m:Em:E\rightarrow\mathbb{N} assigns the minimum travel time of an edge,

    • a:R2Ea:R\rightarrow 2^{E} associates resources with edges in the railway network, and

    • b:Rb:R\rightarrow\mathbb{N} gives the time a resource is blocked after it was accessed by a train line.

  • TT is a set of train lines to be scheduled on network NN.

    Each train in TT is represented as a tuple (S,L,e,l,w)(S,L,e,l,w), where

    • (S,L)(S,L) is an acyclic subgraph of (V,E)(V,E),

    • e:Se:S\rightarrow\mathbb{N} gives the earliest time a train may arrive at a node,

    • l:S{}l:S\rightarrow\mathbb{N}\cup\{\infty\} gives the latest time a train may arrive at a node, and

    • w:Lw:L\rightarrow\mathbb{N} is the time a train has to wait on an edge.

    Note that all functions are total unless specified otherwise and we use seconds as time unit.

  • CC contains connections requiring that a certain train line tt^{\prime} must not arrive at node nn^{\prime} before another train line tt has arrived at node nn for at least α\alpha and at most ω\omega seconds.

    More precisely, each connection in CC is of form (t,(v,v),t,(u,u),α,ω,n,n)(t,(v,v^{\prime}),t^{\prime},(u,u^{\prime}),\alpha,\omega,n,n^{\prime}) such that t=(S,L,e,l,w)Tt=(S,L,e,l,w)\in T and t=(S,L,e,l,w)Tt^{\prime}=(S^{\prime},L^{\prime},e^{\prime},l^{\prime},w^{\prime})\in T, ttt\neq t^{\prime}, (v,v)L(v,v^{\prime})\in L, (u,u)L(u,u^{\prime})\in L^{\prime}, {α,ω}{,}\{\alpha,\omega\}\subseteq\mathbb{Z}\cup\{\infty,-\infty\}, and either n=vn=v or n=vn=v^{\prime}, as well as, either n=un^{\prime}=u or n=un^{\prime}=u^{\prime}.

  • Finally, FF contains collision-free resource points for each connection in CC.

    We represent it as a family (Fc)cC(F_{c})_{c\in C}.

    Each resource point in FcF_{c} is of form (t,(v,v),t,(u,u),r)(t,(v,v^{\prime}),t^{\prime},(u,u^{\prime}),r) and expresses that two train lines tt and tt^{\prime} are allowed to share the same resource rr on edges (v,v)(v,v^{\prime}) and (u,u)(u,u^{\prime}). Connections removing collision detection are used to model splitting (or merging) of trains, as well as reusing the whole physical train between two train lines. More importantly, this allows us to alleviate the restriction that subgraphs for train lines are acyclic, as we can use two train lines forming a cycle that are connected via such connections. This can be observed in Figure 1, where t2t_{2} and t3t_{3} are connected like so.

    We suppose the following conditions

    (t,(n,v),t,(u,u),r)\displaystyle(t,(n,v),t^{\prime},(u,u^{\prime}),r) Fc, if (n,v)La(r),\displaystyle\in F_{c},\text{ if }(n,v)\in L\cap a(r),
    (t,(v,n),t,(u,u),r)\displaystyle(t,(v^{\prime},n^{\prime}),t^{\prime},(u,u^{\prime}),r) Fc, if (v,n)La(r),\displaystyle\in F_{c},\text{ if }(v^{\prime},n^{\prime})\in L\cap a(r),
    (t,(v,v),t,(m,u),r)\displaystyle(t,(v,v^{\prime}),t^{\prime},(m,u),r) Fc, if (m,u)La(r), and\displaystyle\in F_{c},\text{ if }(m,u)\in L^{\prime}\cap a(r),\text{ and}
    (t,(v,v),t,(u,m),r)\displaystyle(t,(v,v^{\prime}),t^{\prime},(u^{\prime},m^{\prime}),r) Fc, if (u,m)La(r).\displaystyle\in F_{c},\text{ if }(u^{\prime},m^{\prime})\in L^{\prime}\cap a(r).

    These assumptions ensure that adjacent edges sharing the same resource are always collision-free resource points for that connection, because otherwise the connections could not be made if resources span over several edges. To illustrate this, consider two trains lines ta=({1,2},{(1,2)},e,l,w)t_{a}=(\{1,2\},\{(1,2)\},e,l,w) and tb=({2,3,4},{(2,3),(3,4)},e,l,w)t_{b}=(\{2,3,4\},\{(2,3),(3,4)\},e^{\prime},l^{\prime},w^{\prime}) that reuse one physical train. All edges have a minimal travel time of six seconds and the same resource rr with a block time of ten seconds. To facilitate a seamless transition from one train line to another, a connection (ta,(1,2),tb,(2,3),0,0,2,2)(t_{a},(1,2),t_{b},(2,3),0,0,2,2) is used where both train lines blend into each other. As both train lines ought to use the same physical train, a collision-free point (ta,(1,2),tb,(2,3),r)(t_{a},(1,2),t_{b},(2,3),r) is needed to allow the connection at the given edges. This collision-free point alone is not sufficient, since tbt_{b} would have to wait for four seconds at edge (3,4)(3,4) for the release of the resource rr, blocked by tat_{a} at edge (1,2)(1,2). This is due to the fact that the blocked time of ten seconds is larger than the minimal travel time of six seconds. Therefore, the collision-free point ((ta,(1,2),tb,(3,4),r))((t_{a},(1,2),t_{b},(3,4),r)) is necessary to correctly execute the connection as intended, that is, modeling one physical train among multiple train lines.

For our example in Figure 1 and Figure 2, the train scheduling problem is defined as

  • V={1,,12}V=\{1,\dots,12\},

    • E={(1,3),(2,3),,(10,11),(10,12)}E=\{(1,3),(2,3),\dots,(10,11),(10,12)\},

    • R={𝑠𝑤1,𝑠𝑤2}{reeE}R=\{\text{$\mathit{sw}_{1}$},\text{$\mathit{sw}_{2}$}\}\cup\{r_{e}\mid e\in E\},

    • m(e)=60m(e)=60 and a(re)={e}a(r_{e})=\{e\} for eEe\in E,

    • a(𝑠𝑤1)={(1,3),(2,3),(4,3),(3,5),(3,6))}a(\mathit{sw}_{1})=\{(1,3),(2,3),(4,3),(3,5),(3,6))\},

    • a(𝑠𝑤2)={(8,10),(10,7),(9,10),(10,11),(10,12)}a(\mathit{sw}_{2})=\{(8,10),(10,7),(9,10),(10,11),(10,12)\},

    • b(r)=60b(r)=60 for rRr\in R,

  • T={t1,t2,t3}T=\{t_{1},t_{2},t_{3}\} with

    • t1=(S1,L1,e1,l1,w1)t_{1}=(S_{1},L_{1},e_{1},l_{1},w_{1}),

    • t2=(S2,L2,e2,l2,w2)t_{2}=(S_{2},L_{2},e_{2},l_{2},w_{2}),

    • t3=(S3,L3,e3,l3,w3)t_{3}=(S_{3},L_{3},e_{3},l_{3},w_{3}),

    where (S1,L1)(S_{1},L_{1}), (S2,L2)(S_{2},L_{2}) and (S3,L3)(S_{3},L_{3}) are nodes of edges and edges themselves that are solid, dotted or dashed in Figure 1, respectively, and

    • e1,l1,e2,l2,e3,l3e_{1},l_{1},e_{2},l_{2},e_{3},l_{3} give the upper and lower coordinates of the colored areas in Figure 2,

    • w1(e)=w2(e)=w3(e)=0w_{1}(e)=w_{2}(e)=w_{3}(e)=0 for eEe\in E,

  • C={c1,c2,c3}C=\{c_{1},c_{2},c_{3}\} with

    • c1=(t2,(4,3),t3,(3,6),0,0,3,3)c_{1}=(t_{2},(4,3),t_{3},(3,6),0,0,3,3),

    • c2=(t1,(10,12),t3,(10,12),60,,10,12)c_{2}=(t_{1},(10,12),t_{3},(10,12),60,\infty,10,12),

    • c3=(t1,(10,11),t3,(10,12),60,,10,12)c_{3}=(t_{1},(10,11),t_{3},(10,12),60,\infty,10,12),

    and

  • F=(Fc1,Fc2,Fc3)F=(F_{c_{1}},F_{c_{2}},F_{c_{3}}) where Fc1={(t2,(4,3),t3,(3,6),𝑠𝑤1)}F_{c_{1}}=\{(t_{2},(4,3),t_{3},(3,6),\mathit{sw}_{1})\} and Fc2=Fc3=F_{c_{2}}=F_{c_{3}}=\emptyset.

A solution (P,A)(P,A) to a train scheduling problem (N,T,C,F)(N,T,C,F) is a pair consisting of

  1. 1.

    a function PP assigning to each train line the path it takes through the network, and

  2. 2.

    an assignment AA of arrival times to each train line at each node on their path.

A path is a sequence of nodes, pair-wise connected by edges. We write vpv\in p and (v,v)p(v,v^{\prime})\in p to denote that node vv or edge (v,v)(v,v^{\prime}) are contained in path p=(v1,,vn)p=(v_{1},\dots,v_{n}), that is, whenever v=viv=v_{i} for some 1in1\leq i\leq n or this and additionally v=vi+1v^{\prime}=v_{i+1}, respectively.

A path P(t)=(v1,,vn)P(t)=(v_{1},\dots,v_{n}) for t=(S,L,e,l,w)Tt=(S,L,e,l,w)\in T has to satisfy:

viS for 1in\displaystyle v_{i}\in S\text{ for }1\leq i\leq n (1)
(vj,vj+1)L for 1jn1\displaystyle(v_{j},v_{j+1})\in L\text{ for }1\leq j\leq n-1 (2)
𝑖𝑛(v1)=0 and 𝑜𝑢𝑡(vn)=0,\displaystyle\mathit{in}(v_{1})=0\text{ and }\mathit{out}(v_{n})=0, (3)

where 𝑖𝑛\mathit{in} and 𝑜𝑢𝑡\mathit{out} give the in- and out-degree of a node in graph (S,L)(S,L), respectively. Intuitively, conditions (1) and (2) enforce paths to be connected and feasible for the train line in question and Condition (3) ensures that each path is between a possible start and end node.

An assignment AA is a partial function T×VT\times V\rightarrow\mathbb{N}, where A(t,v)A(t,v) is undefined whenever vP(t)v\not\in P(t). Given path function PP, an assignment AA has to satisfy the conditions in (4) to (8):

A(t,vi)\displaystyle A(t,v_{i}) e(vi)\displaystyle\geq e(v_{i}) (4)
A(t,vi)\displaystyle A(t,v_{i}) l(vi)\displaystyle\leq l(v_{i}) (5)
A(t,vj)+m((vj,vj+1))+w((vj,vj+1))\displaystyle A(t,v_{j})+m((v_{j},v_{j+1}))+w((v_{j},v_{j+1})) A(t,vj+1)\displaystyle\leq A(t,v_{j+1}) (6)

for all t=(S,L,e,l,w)Tt=(S,L,e,l,w)\in T and P(t)=(v1,,vn)P(t)=(v_{1},\dots,v_{n}) such that 1in,1jn11\leq i\leq n,1\leq j\leq n-1,

either

A(t,v)+b(r)A(t,u) or A(t,u)+b(r)A(t,v)\displaystyle A(t,v^{\prime})+b(r)\leq A(t^{\prime},u)\ \text{ or }\ A(t^{\prime},u^{\prime})+b(r)\leq A(t,v) (7)

for all rR,{t,t}T,tt,(v,v)P(t),(u,u)P(t)r\in R,\{t,t^{\prime}\}\subseteq T,t\neq t^{\prime},(v,v^{\prime})\in P(t),(u,u^{\prime})\in P(t^{\prime}) with {(v,v),(u,u)}a(r)\{(v,v^{\prime}),(u,u^{\prime})\}\subseteq a(r) whenever for all (t,(x,x),t,(y,y),α,ω,n,n)C(t,(x,x^{\prime}),t^{\prime},(y,y^{\prime}),\alpha,\omega,n,n^{\prime})\in C such that (x,x)P(t),(y,y)P(t)(x,x^{\prime})\in P(t),(y,y^{\prime})\in P(t^{\prime}), we have (t,(v,v),t,(u,u),r)Fc(t,(v,v^{\prime}),t^{\prime},(u,u^{\prime}),r)\not\in F_{c},

and finally

αA(t,n)A(t,n)ω\displaystyle\alpha\leq A(t^{\prime},n^{\prime})-A(t,n)\leq\omega (8)

for all (t,(v,v),t,(u,u),α,ω,n,n)C(t,(v,v^{\prime}),t^{\prime},(u,u^{\prime}),\alpha,\omega,n,n^{\prime})\in C if (v,v)P(t)(v,v^{\prime})\in P(t) and (u,u)P(t)(u,u^{\prime})\in P(t^{\prime}).

Intuitively, conditions (4), (5) and (6) ensure that a train line arrives at nodes neither too early nor too late and that waiting and traveling times are accounted for. Furthermore, Condition (7) resolves conflicts between two train lines that travel edges sharing a resource, so that one train line can only enter after another has left for a specified time span. This condition does not have to hold if the two trains use a connection that defines a collision-free resource point for the given edges and resource. Finally, Condition (8) ensures that train line tt connects to tt^{\prime} at node nn and nn^{\prime}, respectively, within a time interval from α\alpha to ω\omega. Note that this is only required if both train lines use the specific edges specified in the connections. Furthermore, note that it is feasible that nn and nn^{\prime} are visited but no connection is required since one or both train lines took alternative routes.

For our solution in Figure 2, we have

  • P(t1)=(2,3,5,8,10,11)P(t_{1})=(2,3,5,8,10,11), P(t2)=(10,7,4,3)P(t_{2})=(10,7,4,3), and P(t3)=(3,6,9,10,12)P(t_{3})=(3,6,9,10,12), and

  • A(t1,2)=300,,A(t1,11)=600A(t_{1},2)=300,\dots,A(t_{1},11)=600,

    A(t2,10)=0,,A(t2,3)=180A(t_{2},10)=0,\dots,A(t_{2},3)=180, and

    A(t3,3)=180,A(t3,6)=240,A(t3,9)=660,,A(t3,12)=780A(t_{3},3)=180,A(t_{3},6)=240,A(t_{3},9)=660,\dots,A(t_{3},12)=780.

To determine the quality of a solution, both the aggregated delay of all train lines as well as the quality of the paths through the network are taken into account. For that purpose, we consider two functions: the delay function dd and route penalty function 𝑟𝑝\mathit{rp}. Given a train line t=(S,L,e,l,w)Tt=(S,L,e,l,w)\in T and a node sSs\in S, d(t,s)d(t,s)\in\mathbb{N} returns the time point after which the train line tt is considered late at node ss. Note that e(s)d(t,s)l(s)e(s)\leq d(t,s)\leq l(s). Given an edge eEe\in E, 𝑟𝑝(e)\mathit{rp}(e)\in\mathbb{N} is the penalty a solution receives for each train line traveling edge ee. With this, the quality of a solution (P,A)(P,A) is determined via the following pair:

(((t,v),a)Amax{(ad(t,v)),0}/60,e{upP,up,eE}𝑟𝑝(e))\displaystyle\textstyle\big{(}\sum_{((t,v),a)\in A}{\max\{(a-d(t,v)),0\}/60},\ \sum_{e\in\{u\mid p\in P,u\in p,e\in E\}}\mathit{rp}(e)\big{)} (9)

Since delay is the more important criteria, optimization of the quality amounts to lexicographic minimization considering delay first and route penalty second. As mentioned, our example has an accumulated delay of 360 and 0 route penalty and therefore a quality of (360/60,0)=(6,0)(360/60,0)=(6,0).

4 An ASP-based solution to real-world train scheduling

In this section, we present our hybrid ASP-based approach for solving the train scheduling problem. It relies on dedicated preprocessing techniques to reduce the problem size as well as additional constraints and domain-specific heuristics to reduce the search space and improve solving performance. This constitutes a significant improvement over our previous approach [Abels et al. (2019)] that, while similar in principle, does not scale to the largest instances available. We start by presenting said preprocessing techniques that mainly exploit redundancy in the resource distribution in the railway network. Following that, we describe the actual hybrid encoding that makes use of this preprocessing and furthermore reduces the amount of timing constraints by using a compressed representation of the graph. Finally, we present optional constraints and domain-specific heuristics aiming at further improving solving performance.

4.1 Preprocessing

We present two techniques that reduce the complexity of the problem at hand. While resource subsumption detects redundant resources that can safely be removed, resource areas are used to simplify conflict resolution on resource conflicts.

4.1.1 Resource subsumption

An analysis of real-world instances revealed that resources are often contained within others, thus posing redundant constraints. In a preprocessing step, we detect such subsumed resources and remove them from the problem specification. Given a railway network (V,E,R,m,a,b)(V,E,R,m,a,b), a resource r1Rr_{1}\in R is subsumed by another resource r2Rr_{2}\in R, if a(r1)a(r2)a(r_{1})\subseteq a(r_{2}) and b((v,v))b((u,u))b((v,v^{\prime}))\leq b((u,u^{\prime})) for all (v,v)a(r1)(v,v^{\prime})\in a(r_{1}) and (u,u)a(r2)(u,u^{\prime})\in a(r_{2}), and there is no collision-free resource point (t,(v,v),t,(u,u),r2)Fc(t,(v,v^{\prime}),t^{\prime},(u,u^{\prime}),r_{2})\in F_{c} for any cCc\in C.333If several resources are exactly the same, we keep one of them. Intuitively, subsumed resources are contained within another resource that induces the same or stronger timing constraints due to higher or equal blocked time and no conflict-free resource points in the overlapping area. In our example, we can safely remove resources {r(10,7),r(10,11),r(8,10),r(9,10),r(10,12)}\{r_{(10,7)},r_{(10,11)},r_{(8,10)},r_{(9,10)},r_{(10,12)}\} as each of them is subsumed by 𝑠𝑤2\mathit{sw}_{2}. Note that we cannot remove any resources covered by 𝑠𝑤1\mathit{sw}_{1}, as it is used in the collision-free resource point (t2,(4,3),t3,(3,6),𝑠𝑤1)(t_{2},(4,3),t_{3},(3,6),\mathit{sw}_{1}) of c1c_{1}. The collision-free resource point disables conflict resolution on 𝑠𝑤1\mathit{sw}_{1} for the trains t1t_{1} and t2t_{2}, hence, conflicts for other resources topologically contained within 𝑠𝑤1\mathit{sw}_{1} are not redundant and have to be taken into account individually.

4.1.2 Resource areas

As seen in our example, resources covering several edges can be exploited by identifying areas, for which it is enough to determine the order of train lines passing through (rather than doing pair-wise conflict resolution on edges, as done in [Abels et al. (2019)]). We call them resource areas. Every train line has its own set of resource areas. It is required that every possible path through the resource area contains only edges assigned the original resource. More precisely, a resource area ArtA^{t}_{r} over resource rRr\in R and train line t=(S,L,e,l,w)t=(S,L,e,l,w) is a maximal set of edges Arta(r)LA^{t}_{r}\subseteq a(r)\cap L such that there is no path p=(v1,,vn)p=(v_{1},\dots,v_{n}) in (S,L)(S,L) with (u,u)p(u,u^{\prime})\in p but (u,u)a(r)(u,u^{\prime})\notin a(r) between two edges {(v,v1),(vn,v)}Art\{(v,v_{1}),(v_{n},v^{\prime})\}\in A^{t}_{r}. Intuitively, this means that a resource area can only be occupied by one train at a time independently of their chosen paths through the resource area. Thus, other train lines using the same resource may only enter once the entire area is free. Note that there may exist several resource areas for a resource and a train.

We define a resource coverage 𝒜rt\mathcal{A}^{t}_{r} as a set of resource areas over resource rr and train line tt such that A𝒜rtA=a(r)L\bigcup_{A\in\mathcal{A}^{t}_{r}}A=a(r)\cap L and AA=A\cap A^{\prime}=\emptyset for {A,A}𝒜rt\{A,A^{\prime}\}\subseteq\mathcal{A}^{t}_{r}. A resource coverage 𝒜\mathcal{A} over sets of resources RR and train lines TT is defined as 𝒜=rR,tT𝒜rt\mathcal{A}=\bigcup_{r\in R,t\in T}\mathcal{A}^{t}_{r}. Intuitively, a resource coverage distributes resource areas so that every edge is covered and no edge is in two resource areas per resource and train line.

In our example, we have the resource coverage

𝒜=\displaystyle\mathcal{A}=\ {{(v,v)}r(v,v)ttT,r(v,v)R}\displaystyle\{\{(v,v^{\prime})\}^{t}_{r_{(v,v^{\prime})}}\mid t\in T,r_{(v,v^{\prime})}\in R\}\ \cup
{{(1,3),(2,3),(3,5)}𝑠𝑤1t1,{(8,10),(10,11),(10,12)}𝑠𝑤2t1}\displaystyle\{\{(1,3),(2,3),(3,5)\}^{t_{1}}_{\mathit{sw}_{1}},\{(8,10),(10,11),(10,12)\}^{t_{1}}_{\mathit{sw}_{2}}\}\ \cup
{{(4,3)}𝑠𝑤1t2},{(10,7)}𝑠𝑤2t2}\displaystyle\{\{(4,3)\}^{t_{2}}_{\mathit{sw}_{1}}\},\{(10,7)\}^{t_{2}}_{\mathit{sw}_{2}}\}\ \cup
{{(3,6)}𝑠𝑤1t3,{(9,10),(10,12)}𝑠𝑤2t3},\displaystyle\{\{(3,6)\}^{t_{3}}_{\mathit{sw}_{1}},\{(9,10),(10,12)\}^{t_{3}}_{\mathit{sw}_{2}}\},

where TT and RR are the train lines and resources of the example in Figure 1, respectively.

We have three non singleton sets in the coverage. Given the train lines t1t_{1}, t3t_{3} and resource 𝑠𝑤2\mathit{sw}_{2} from our example, we have to decide whether t1t_{1} enters {(8,10),(10,11),(10,12)}𝑠𝑤2t1\{(8,10),(10,11),(10,12)\}^{t_{1}}_{\mathit{sw}_{2}} first or t3t_{3} enters {(9,10),(10,12)}𝑠𝑤2t3\{(9,10),(10,12)\}^{t_{3}}_{\mathit{sw}_{2}} first. Without the use of resource areas, we would need to make a decision for every element in the cross product {(8,10),(10,11),(10,12)}𝑠𝑤2t1×{(9,10),(10,12)}𝑠𝑤2t3\{(8,10),(10,11),(10,12)\}^{t_{1}}_{\mathit{sw}_{2}}\times\{(9,10),(10,12)\}^{t_{3}}_{\mathit{sw}_{2}}, leaving us with 6 decisions instead of one. Note that there is no unique resource coverage for every graph, but different maximal subsets could be chosen.

Input : Resource rr and train line t=(S,L,e,l,w)t=(S,L,e,l,w).
Output : A resource coverage ArtA^{t}_{r}.
1 ArtA^{t}_{r}\leftarrow\emptyset;
2 while AArtAa(r)S\bigcup_{A\in A^{t}_{r}}{A}\neq a(r)\cap S do
3       AA\leftarrow\emptyset;
4       foreach (v,v)(a(r)S)AArtA(v,v^{\prime})\in(a(r)\cap S)\setminus\bigcup_{A\in A^{t}_{r}}{A} do
5             if isRA(A{(v,v)},r,S,L)\textit{isRA}(A\cup\{(v,v^{\prime})\},r,S,L) then
6                   AA{(v,v)}A\leftarrow A\cup\{(v,v^{\prime})\};
7                  
8            
9       end foreach
10      
11 end while
Figure 3: Algorithm to compute resource coverage.

To determine resource areas, we use the greedy algorithm in Figure 3 for every resource rr and train line t=(S,L,e,l,w)t=(S,L,e,l,w). We incrementally create a resource area AA by adding yet unused edges (v,v)(v,v^{\prime}) to it in Line 3. The function isRA(A,r,S,L)\textit{isRA}(A,r,S,L) in Line 3 checks that no path in (S,L)(S,L) between edges in AA contains edges not assigned rr. Intuitively, this means that once a train line entered a resource area, it is not able to leave it and reenter it again. If this is the case, (v,v)(v,v^{\prime}) is added to AA in Line 3. This is repeated until we cannot add further edges to the current resource area and then restart the procedure creating a new area in lines 3 and 3 until we achieve full resource coverage.

We outline how we use resource areas to derive solutions fulfilling Condition (7) in Section 4.3.

4.2 Fact format

A train scheduling problem (N,T,C,F)(N,T,C,F) with N=(V,E,R,m,a,b)N=(V,E,R,m,a,b) is represented by the facts

tl(tt). edge(tt,vv,vv^{\prime}). m((v,v)(v,v^{\prime}),m((v,v))m((v,v^{\prime}))). w(tt,(v,v)(v,v^{\prime}),m((v,v))m((v,v^{\prime}))).

for each t=(S,L,e,l,w)Tt=(S,L,e,l,w)\in T and (v,v)L(v,v^{\prime})\in L.

For every sSs\in S, we add

e(tt,ss,e(s)e(s)). l(tt,ss,l(s)l(s)).

Additionally, either

start(tt,ss). or end(tt,ss).

is added, if 𝑖𝑛(s)=0\mathit{in}(s)=0 or 𝑜𝑢𝑡(s)=0\mathit{out}(s)=0 in (S,L)(S,L), respectively. We assign unique terms to each train line for identifiability.

For example, the facts

tl(t1). edge(t1,1,3). m((1,3),60). w(t1,(1,3),0).
e(t1,1,240). l(t1,1,540).
start(t1,1).

express that train line t1 may travel between nodes 1 and 3 taking at least 60 seconds, waiting on this edge for 0 seconds, and arrives between time points 240 and 540 at node 1, which is a possible start node.

Furthermore, we add

resource(rr,(vv,vv^{\prime})). b(rr,b(r)b(r)).

for rRr\in R and (v,v)a(r)(v,v^{\prime})\in a(r). Akin to train lines, resources are assigned unique terms to distinguish them.

For example, facts

resource(sw1,(1,3)). resource(sw1,(4,3)). b(sw1,60).

assign resource sw1 to edges (1,3)(1,3) and (4,3)(4,3) and the resource is blocked for 60 seconds after a train line has left it.

Finally, we add

connection(cc,tt,(vv,vv^{\prime}),tt^{\prime},(uu,uu^{\prime}),α\alpha,ω\omega,nn,nn^{\prime}).

for all (t,(v,v),t,(u,u),α,ω,n,n)C(t,(v,v^{\prime}),t^{\prime},(u,u^{\prime}),\alpha,\omega,n,n^{\prime})\in C, where cc acts as an identifier, and

free(cc,tt,(vv,vv^{\prime}),tt^{\prime},(uu,uu^{\prime}),rr).

for all (t,(v,v),t,(u,u),r)Fc(t,(v,v^{\prime}),t^{\prime},(u,u^{\prime}),r)\in F_{c}.

For instance, the transfer of the physical train from train line t2 to t3 at node 33 is encoded by connection(1,t2,(4,3),t3,(3,6),0,0,3,3). This requires both train lines to be at node 3 at the exact same time. Thus, we have to additionally provide the fact free(1,t2,(4,3),t3,(3,6),sw1) to allow for a shared use of the resource, so that the train lines can connect. This can be done safely since in reality only one train exists for both train lines, which rules out collisions.

For a resource area A𝒜rtA\in\mathcal{A}^{t}_{r}, we generate facts

ra(tt,rr,aa,(vv,vv^{\prime})).

for (v,v)A(v,v^{\prime})\in A, resource rRr\in R and train line t=(S,L,e,l,w)Tt=(S,L,e,l,w)\in T. We assign a unique term aa to distinguish resource areas for the same resource and train line. Furthermore, for every resource area A𝒜rtA\in\mathcal{A}^{t}_{r}, we add

e_ra(tt,rr,aa,ee). l_ra(tt,rr,aa,ll).

where e=min{e(v))(v,v)A}e=min\{e(v))\mid(v,v^{\prime})\in A\} and l=max{l(v)(v,v)A}l=max\{l(v^{\prime})\mid(v,v^{\prime})\in A\} to represent the earliest entry and latest exit times for that resource area. In our example, the earliest entry time for resource area {(1,3),(2,3),(3,5)}𝑠𝑤1t1\{(1,3),(2,3),(3,5)\}^{t_{1}}_{\mathit{sw}_{1}} is 0, while the latest exit time is 660.

Given delay and route penalty functions dd and 𝑟𝑝\mathit{rp}, we add

potlate(tt,ss,uu,pp). penalty(mm,𝑟𝑝(m)\mathit{rp}(m)).

for t=(S,L,e,l,w)T,sS,mLt=(S,L,e,l,w)\in T,s\in S,m\in L with {u,p},d(t,s)<ul(t,s)\{u,p\}\subseteq\mathbb{N},d(t,s)<u\leq l(t,s) to evaluate a solution.

The collection of facts for our example instance can be found in A in Listing 9.

4.3 Encoding

In the following, we describe the general problem encoding. We separate it into three parts handling path constraints, conflict resolution and scheduling.

11 { visit(T,V) : start(T,V) } 1 :- tl(T).
21 { route(T,(V,V’)) : edge(T,V,V’) } 1 :- visit(T,V),
3 not end(T,V).
4visit(T,V’) :- route(T,(V,V’)).
Listing 1: Encoding of path constraints.

The first part of the encoding in Listing 1 covers routing. First, exactly one valid start node is chosen for each train line to be visited (Line 1). From a node that is visited by a train line and is not an end node, an edge in the relevant subgraph is chosen as the next route (Line 3). The new route in turn leads to a node being visited by the train line (Line 4). This way, each train line is recursively assigned a valid path. Since those paths begin at a start node, finish at an end node and are connected via edges valid for the respective train lines, conditions (2) and (3) are ensured.

5enter_ra(T,R,A,V) :-
6 ra(T,R,A,(V,V’)), route(T,(V,V’)),
7 1 #sum {1 : edge(T,V’’,V), not ra(T,R,A,(V’’,V));
8 1 : start(T,V)},
9 not route(T,(V’’,V)) : ra(T,R,A,(V’’,V)).
10leave_ra(T,R,A,V’) :-
11 ra(T,R,A,(V,V’)), route(T,(V,V’)),
12 1 #sum {1 : edge(T,V’,V’’), not ra(T,R,A,(V’,V’’));
13 1 : end(T,V’)},
14 not route(T,(V’,V’’)) : ra(T,R,A,(V’,V’’)).
15
16free_a(T,T’,R,A,A’) :- free(I,T,(V,V’),T’,(U,U’),R),
17 ra(T,R,A,(V,V’)), ra(T’,R,A’,(U,U’)),
18 connection(I,T,(X,X’),T’,(Y,Y’),_,_,_,_),
19 route(T,(X,X’)), route(T’,(Y,Y’)).
20
21shared(T,T’,R,A,A’) :- e_ra(T,R,A,E), e_ra(T’,R,A’,E’),
22 not free_a(T,T’,R,A,A’),
23 l_ra(T,R,A,L), b(R,B), T != T’,
24 E <= E’, E < L+B.
25shared(T’,T,R,A’,A) :- shared(T,T’,R,A,A’).
26
27{ seq(T,T’,R,A,A’) } :- shared(T,T’,R,A,A’), T < T’.
28 seq(T’,T,R,A’,A) :- shared(T,T’,R,A,A’),
29 not seq(T,T’,R,A,A’).
Listing 2: Encoding of conflict resolution.

The next part of the encoding shown in Listing 2 detects and resolves resource conflicts. Basically, a resource conflict exists, if two train lines each have an edge in their respective subgraph that is assigned the same resource, and time intervals overlap in which the train lines enter and leave the edges in question, extended by the time the resource is blocked. We improve upon this edge-centric conflict resolution via resource areas. In lines 514, we first compute entry and exit nodes leading in and out of a resource area (depending on the chosen route). A conflict is possible, if two train lines each have a resource area in their respective subgraph that is assigned the same resource, and the time intervals overlap in which the train lines may enter and leave the areas in question, extended by the time the resource is blocked (lines 2125). We resolve the conflict by making a choice which train line passes through this area first (lines 27 and 29).

As a collision-free resource point (t,(v,v),t,(u,u),r)(t,(v,v^{\prime}),t^{\prime},(u,u^{\prime}),r) does not trigger a resource conflict, we prevent the involved resource areas ArtA^{t}_{r} and ArtA^{t^{\prime}}_{r} with (v,v)Art(v,v^{\prime})\in A^{t}_{r} and (u,u)Art(u,u^{\prime})\in A^{t^{\prime}}_{r} from creating conflicts by deriving collision-free resource areas in lines 1619. It is safe to do so, as it is necessary for a collision-free connection that all edges adjacent to (v,v)(v,v^{\prime}) or (u,u)(u,u^{\prime}) with the same resource are also collision-free resource points (recall Section 3.2). We exclude these areas from the conflict resolution in Line 22.

Note that we require much less decisions for resolving resource conflicts by using resource areas. It is possible that several or even all edges in two resource areas with the same resource induce a conflict. Naively, a decision would have to be made for all possible combination of those edges. Instead of having this quadratic blowup, we only have to resolve the resource conflict between entire resource areas. For our example, this reduces the number of decisions necessary to resolve all possible conflicts from 15 to 5.

To represent the arrival time of a train line t=(S,L,e,l,w)t=(S,L,e,l,w) at node vSv\in S, we project the graph (S,L)(S,L) to a possibly smaller version of it using a topological ordering. In essence, instead of assigning an arrival time to each possible node a train line could visit, we assign the arrival time to the progress the train line has made relative to its subgraph. For that purpose, we utilize the height of a node that indicates the maximum number of edges the train line has to travel to reach this node, (or, in other words, in an acyclic graph, the height of a node is the length of the longest path from any root node to this node). Obviously, several nodes can have the same height whenever they are on parallel paths through the subgraph. Formally, the height of a node vSv\in S for train line tt is defined as follows:

ht(v)={0if 𝑖𝑛(v)=0max{ht(v))(v,v)L}+1otherwiseh^{t}(v)=\begin{cases*}0&if $\mathit{in}(v)=0$\\ \max\{h^{t}(v^{\prime}))\mid(v^{\prime},v)\in L\}+1&otherwise\end{cases*}

The arrival times are now represented using integer variables designated by pairs of form (tt,ht(v)h^{t}(v)) indicating arrival time of train line tt at height ht(v)h^{t}(v)444Cf. Section 2 on using pairs as identifiers. This reduces the number of variables and difference constraints needed whenever trains are routed over nodes with the same height. For the running example, nodes 1 and 2 from train line t1t_{1} now collapse to one variable (t1,0)(t_{1},0), as only one of the two nodes can be used in a final routing of the train line. Instead of introducing arrival times for node 1 and 2, we only introduce an arrival time (t1,0)(t_{1},0) where 0=ht1(1)=ht1(2)0=h^{t_{1}}(1)=h^{t_{1}}(2), independent of the chosen path. The number of integer variables for the arrival times of t1t_{1} is therefore reduced from 8 to 6 in contrast to using node names such as (tt,vv).

Note that we use ground terms in the remainder of this paper to describe our rules, while their actual encoding uses variables. Also, we sometimes mix mathematical notation for train lines and nodes (italic) and their identifying terms in the encoding (typewriter) and use them interchangeably.

30h(T,V,0) :- start(T,V).
31h(T,V,M+1) :- edge(T,_,V),
32 M = #max {N : h(T,V’,N), edge(T,V’,V)}, M != #inf.
33
34min_e(T,N,M) :- h(T,_,N),
35 M != #sup, M = #min {E : h(T,V,N), e(T,V,E)}.
36max_l(T,N,M) :- h(T,_,N),
37 M != #inf, M = #max {L : h(T,V,N), l(T,V,L)}.
38&diff{ 0-(T,N) } <= -E :- min_e(T,N,E).
39&diff{ (T,N)-0 } <= L :- max_l(T,N,L).
40&diff{ 0-(T,N) } <= -E :- e(T,V,E), visit(T,V), h(T,V,N),
41 min_e(T,N,M), M<E.
42&diff{ (T,N)-0 } <= L :- l(T,V,L), visit(T,V), h(T,V,N),
43 max_l(T,N,M), M>L.
44
45time(T,(V,V’),(N,N’),D) :- edge(T,V,V’), h(T,V,N), h(T,V’,N’),
46 D=#sum{ M,m : m((V,V’),M);
47 W,w : w(T,(V,V’),W) }.
48min_time(T,(N,N’),M) :-
49 edge(T,V,V’), h(T,V,N), h(T,V’,N’),
50 not edge(T,U,U’) : h(T,U,N), h(T,U’,O), O != N’;
51 not edge(T,U,U’) : h(T,U,O), h(T,U’,N’), O != N;
52 M = #min {D : time(T,_,(N,N’),D)}.
53&diff{ (T,N)-(T,N’) } <= -D :- min_time(T,(N,N’),D).
54&diff{ (T,N)-(T,N’) } <= -D :-
55 route(T,(V,V’)), h(T,V,N), h(T,V’,N’),
56 time(T,(V,V’),(N,N’),D),
57 D > #max {#inf; M : min_time(T,(N,N’),M)}.
58
59&diff{ (T,N)-(T’,N’) } <= -B :-
60 seq(T,T’,R,A,A’), shared(T,T’,R,A,A’),
61 h(T,V,N), h(T’,U,N’),
62 leave_ra(T,R,A,V), enter_ra(T’,R,A’,U), b(R,B).
63
64&diff{ (T,N)-(T’,N’) } <= -M :-
65 connection(I,T,(V,V’),T’,(U,U’),M,_,X,Y),
66 h(T,X,N), h(T’,Y,N’), route(T,(V,V’)), route(T’,(U,U’)).
67&diff{ (T’,N’)-(T,N) } <= M :-
68 connection(I,T,(V,V’),T’,(U,U’),_,M,X,Y), M != #inf,
69 h(T,X,N), h(T’,Y,N’), route(T,(V,V’)), route(T’,(U,U’)).
Listing 3: Encoding of scheduling.

Listing 3 displays the encoding of scheduling via difference constraints. An atom h(tt,vv,nn) assigns a node vv its height n=ht(v)n=h^{t}(v) for train line tt and is computed in lines 30 and 32. Note that we use pairs (t,h)(t,h) as names for integer variables whose values indicate the arrival time of train tt at height hh. The next part of the encoding ensures that earliest and latest arrival times, viz. e(v)e(v) and l(v)l(v), for a train line t=(S,L,e,l,w)t=(S,L,e,l,w) on a node vSv\in S are respected by setting lower and upper bounds for the integer variable (tt,ht(v)h^{t}(v)) (lines 40-43). Even though, the lower and upper bound of variable (tt,hh) depend on the node that is actually visited as there possibly exist several nodes vSv\in S on alternative paths with the same height hh (the same maximum path length from a root node), we can take advantage of the height-based naming scheme by setting the lower and upper bound of variable (tt,hh) to min{e(v)vS,ht(v)=h}min\{e(v)\mid v\in S,h^{t}(v)=h\} and max{l(v)vS,ht(v)=h}max\{l(v)\mid v\in S,h^{t}(v)=h\}, respectively, independently of the chosen route. For all nodes with a greater time for the earliest arrival (lesser time for the latest arrival), an additional constraint is derived depending on whether such a node is visited. This restricts the search space in two ways. First, constraints for earliest and latest arrival times are independent of routing for nodes with a minimal earliest or maximal latest arrival time, second, regardless of routing, a constraint is added constituting the lower bound of the earliest (upper bound for the latest) arrival time at a certain height. Lines 34 to 37 compute said minimal and maximal arrival times for a train line at a certain height. Difference constraints representing these upper and lower bounds are derived in lines 38 and 39 and are independent of the chosen route. More precisely, for train line tt at height hh, we derive

&diff{0-(t,h)(t,h)} <= e-e and &diff{0-(t,h)(t,h)}<= l-l ,

where e=min{e(v)vS,ht(v)=h}e=\min\{e(v)\mid v\in S,h^{t}(v)=h\} and l=max{l(v)vS,ht(v)=h}l=\max\{l(v)\mid v\in S,h^{t}(v)=h\}. For nodes vv, where e(v)=ee(v)=e and l(v)=ll(v)=l, we therefore ensure e(v)(t,ht(v))l(v)e(v)\leq(t,h^{t}(v))\leq l(v) and in turn condition (4) and (5). In case train line tt visits a node vv for which either e(v)>ee(v)>e or l(v)<ll(v)<l, we have to additionally derive

&diff{0-(t,ht(v))(t,h^{t}(v))} <= e(v)-e(v) or &diff{(t,ht(v))(t,h^{t}(v))-0} <= l(v)l(v) , respectively.

This again ensures e(v)(t,ht(v))l(v)e(v)\leq(t,h^{t}(v))\leq l(v) and in turn condition (4) and (5) to hold.

The next part of the encoding guarantees the travel and waiting time between two nodes (v,v)L(v,v^{\prime})\in L for a train line t=(S,L,e,l,w)t=(S,L,e,l,w). We call adjacent heights (n,n+1)=(ht(v),ht(v))(n,n+1)=(h^{t}(v),h^{t}(v^{\prime})) exclusively connected, if there is no edge (u,u)L(u,u^{\prime})\in L such that ht(u)=nh^{t}(u)=n and ht(u)n+1h^{t}(u^{\prime})\neq n+1 or ht(u)=n+1h^{t}(u^{\prime})=n+1 and ht(u)nh^{t}(u)\neq n. For these heights (n,n+1)(n,n+1) the minimum of the travel plus waiting time can be set independently of the chosen route. An exclusively connected pair (n,n+1)(n,n+1) represents a set of edges {(v1,v2),,(vm1,vm)}L\{(v_{1},v_{2}),\dots,(v_{m-1},v_{m})\}\subseteq L of which at most one edge can be visited by a train line. The minimum of travel plus waiting time of these edges can therefore be guaranteed independently of routing, as it constitutes a lower bound. For any edge (v,v)L(v,v^{\prime})\in L, where either the travel plus waiting time is greater than the minimum across all edges for exclusively connected heights (ht(v),ht(v))(h^{t}(v),h^{t}(v^{\prime})), or (ht(v),ht(v))(h^{t}(v),h^{t}(v^{\prime})) is not exclusively connected, the constraint for minimal distance between (t,v)(t,v) and (t,v)(t,v^{\prime}) depends on the routing. In the worst case, no exclusively connected heights exist and all constraints are dependent on the routing. In our running example, edges (1,3)(1,3) and (2,3)(2,3) for train line t1t_{1} result in the same pair of exclusively connected heights (0,1)(0,1). This means that the condition (t1,0)+60(t1,1)(t_{1},0)+60\leq(t_{1},1) holds independently of routing, as 60 is the minimum of travel plus waiting time for these edges. If edge (2,3)(2,3) had a waiting time w((2,3))=10w((2,3))=10, the condition (t1,0)+70(t1,1)(t_{1},0)+70\leq(t_{1},1) needs to hold additionally, if edge (2,3)(2,3) is visited. Note that the route independent constraint only poses a lower bound on the relation of the two arrival times and is therefore subsumed by this new constraint. Given a train line t=(S,L,e,l,w)t=(S,L,e,l,w), lines 4552, first, compute the travel plus waiting time 𝑡𝑖𝑚𝑒(v,v)t=m((v,v))+w((v,v))\mathit{time}^{t}_{(v,v^{\prime})}=m((v,v^{\prime}))+w((v,v^{\prime})) for all edges (v,v)L(v,v^{\prime})\in L, secondly, the minimum of travel plus waiting time 𝑚𝑖𝑛_𝑡𝑖𝑚𝑒(n,n+1)t=min{𝑡𝑖𝑚𝑒(v,v)t(v,v)L,ht(v)=n,ht(v)=n+1}\mathit{min\_time}^{t}_{(n,n+1)}=\min\{\mathit{time}^{t}_{(v,v^{\prime})}\mid(v,v^{\prime})\in L,h^{t}(v)=n,h^{t}(v^{\prime})=n+1\} for all exclusively connected heights (n,n+1)(n,n+1), and finally, the difference constraint atom

&diff{(t,n)(t,n)-(t,n+1)(t,n+1)}<= min_time(n,n+1)t-min\_time^{t}_{(n,n+1)}

is derived in Line 53. For any edge (v,v)L(v,v^{\prime})\in L, where either time(v,v)t>min_time(ht(v),ht(v))ttime^{t}_{(v,v^{\prime})}>min\_time^{t}_{(h^{t}(v),h^{t}(v^{\prime}))} holds, or (ht(v),ht(v))(h^{t}(v),h^{t}(v^{\prime})) are not exclusively connected, the difference constraint atom

&diff{(t,ht(v))(t,h^{t}(v))-(t,ht(v))(t,h^{t}(v^{\prime}))} <= time(v,v)t-time^{t}_{(v,v^{\prime})}

is derived, whenever the train line is actually routed over edge (v,v)(v,v^{\prime}) (lines 5457). For all exclusively connected heights (n,n+1)(n,n+1), the condition (t,n)+𝑚𝑖𝑛_𝑡𝑖𝑚𝑒(n,n+1)t(t,n+1)(t,n)+\mathit{min\_time}^{t}_{(n,n+1)}\leq(t,n+1) is provided. This satisfies Condition (6) for all edges (v,v)L(v,v^{\prime})\in L, where ht(v)=nh^{t}(v)=n, ht(v)=n+1h^{t}(v^{\prime})=n+1 and 𝑚𝑖𝑛_𝑡𝑖𝑚𝑒(n,n+1)t=m((v,v))+w((v,v))\mathit{min\_time}^{t}_{(n,n+1)}=m((v,v^{\prime}))+w((v,v^{\prime})). As the minimum time is a lower bound, no constraints are violated if these edges are not visited. For all visited edges (v,v)L(v,v^{\prime})\in L where ht(v)=nh^{t}(v)=n, ht(v)=n+1h^{t}(v^{\prime})=n+1 and 𝑚𝑖𝑛_𝑡𝑖𝑚𝑒(n,n+1)t<m((v,v))+w((v,v))\mathit{min\_time}^{t}_{(n,n+1)}<m((v,v^{\prime}))+w((v,v^{\prime})) or (ht(v),ht(v))(h^{t}(v),h^{t}(v^{\prime})) is not exclusively connected, condition (t,n)+m(v,v)+w((v,v))(t,n+1)(t,n)+m(v,v^{\prime})+w((v,v^{\prime}))\leq(t,n+1) for all visited edges (v,v)(v,v^{\prime}) has to hold. This ensures Condition (6). As for the earliest and latest arrival times above, by using a formulation based on heights, we may either gain a lower bound or provide timing constraints independently of the routing, thus restricting the search space.

The rule in lines 5962 in Listing 3 utilizes conflict detection and resolution from Listing 2. We derive the difference constraint atom

&diff{(t,ht(v))(t,h^{t}(v))-(t,ht(u))(t^{\prime},h^{t^{\prime}}(u))} <= b(r)-b(r)

expressing that tt leaves the resource area ArtA^{t}_{r} using a node vv before tt^{\prime} enters ArtA^{t^{\prime}}_{r} via a node uu, given the blocked time b(r)b(r) of a resource rr and the decision that train line tt on resource area ArtA^{t}_{r} takes precedence over tt^{\prime} on resource area ArtA^{t^{\prime}}_{r}. As all edges in these resource areas have the same resource rr, and once inside a resource area a train cannot leave the resource area again, the order of passing all edges is the same. Therefore, this constraint supersedes all constraints (t,ht(v))+b(r)(t,ht(u))(t,h^{t}(v))+b(r)\leq(t,h^{t^{\prime}}(u^{\prime})) for all edges (v,v)Art(v,v^{\prime})\in A^{t}_{r}, (u,u)Art(u,u^{\prime})\in A^{t^{\prime}}_{r}, and captures Condition (7).

Finally, lines 6469 handle connections (c,t,(v,v),t,(u,u),α,ω,v′′,u′′)C(c,t,(v,v^{\prime}),t^{\prime},(u,u^{\prime}),\alpha,\omega,v^{\prime\prime},u^{\prime\prime})\in C. Difference constraint atoms

&diff{(t,ht(v′′))(t,h^{t}(v^{\prime\prime}))-(t,ht(u′′))(t^{\prime},h^{t^{\prime}}(u^{\prime\prime}))} <= α-\alpha and
&diff{(t,ht(u′′))(t^{\prime},h^{t^{\prime}}(u^{\prime\prime}))-(t,ht(v′′))(t,h^{t}(v^{\prime\prime}))} <= ω\omega

are derived (lines 66 and 69) guaranteeing α(t,ht(u′′))(t,ht(v′′))ω\alpha\leq(t^{\prime},h^{t^{\prime}}(u^{\prime\prime}))-(t,h^{t}(v^{\prime\prime}))\leq\omega, and thus Condition (8), if (v,v)(v,v^{\prime}) is visited by train line tt and (u,u)(u,u^{\prime}) is visited by tt^{\prime}.

4.4 Optimization

As mentioned above, we use instances of potlate/4 to indicate when a train line is considered late at a node and how to penalize its delay. For this purpose, we choose sets Dt,vD_{t,v}\subseteq\mathbb{N} whose elements act as thresholds for arrival time of train line tt at node vv. Given delay function dd, d(t,v)ul(v)d(t,v)\leq u\leq l(v) for every uDt,vu\in D_{t,v}, train line t=(S,L,e,l,w)Tt=(S,L,e,l,w)\in T and vSv\in S. We create facts potlate(tt,vv,uu,uuu-u^{\prime}) for u,uDt,vu,u^{\prime}\in D_{t,v} with u<uu^{\prime}<u such that there is no u′′Dt,vu^{\prime\prime}\in D_{t,v} with u<u′′<uu^{\prime}<u^{\prime\prime}<u. We add potlate(tt,vv,uu,ud(t,v)u-d(t,v)) for u=min(Dt,v)u=\min(D_{t,v}). Intuitively, we choose the penalty of a potential delay as the difference to the previous potential delay, or, if there is no smaller threshold, the difference to the time point after which the train is considered delayed. This way, the sum of penalties amounts to a lower bound on the train line’s actual delay in seconds. For example, for Dt,v={6,10,14}D_{t,v}=\{6,10,14\} and d(t,v)=5d(t,v)=5, we create facts potlate(tt,vv,6,1), potlate(tt,vv,10,4) and potlate(tt,vv,14,4). Now, if tt arrives at vv at 12, it is above thresholds 6 and 10 and should receive a penalty of 5. This penalty is a lower bound on the actual delay of 7, and we know that the value has to be between 5 and 9 since the next threshold adds a penalty of 4. This method approximates the exact objective function in (9) in two ways. First, we do not divide by 60 and penalize in minutes since this would lead to rounding problems. Second, our penalty only gives a lower bound to the actual delay if thresholds are more than one second apart. While our method allows us to be arbitrarily precise in theory, in practice, creating a threshold for each possible second of delay leads to an explosion in size. We employ two schemes for generating sets Dt,vD_{t,v} given t=(S,L,e,l,w)Tt=(S,L,e,l,w)\in T, vSv\in S and delay function dd.

4.4.1 Binary approximation

Binary approximation detects if a train is a second late and penalizes it by one, therefore, only the occurrence of a delay is detected while its amount is disregarded.

We set Dt,v=𝐵𝑖𝑛t,v={d(t,v)+1}D_{t,v}=\mathit{Bin}_{t,v}=\{d(t,v)+1\}.

4.4.2 Linear approximation

Linear approximation evenly distributes thresholds mm seconds apart across the time span in which a delay might occur. Here, if train line tt arrives at or after nm+d(t,v)n*m+d(t,v) at vv, we know that the real delay is between nmn*m and (n+1)m(n+1)*m for n{0}n\in\mathbb{N}\setminus\{0\}. We also add 𝐵𝑖𝑛t,v\mathit{Bin}_{t,v} to detect solutions without delay.

Accordingly, we set Dt,v=𝐵𝑖𝑛t,v𝐿𝑖𝑛t,vmD_{t,v}=\mathit{Bin}_{t,v}\cup\mathit{Lin}^{m}_{t,v} with 𝐿𝑖𝑛t,vm={yy=xm+d(t,v),x{0},yl(v)}\mathit{Lin}^{m}_{t,v}=\{y\in\mathbb{N}\mid y=x*m+d(t,v),x\in\mathbb{N}\setminus\{0\},y\leq l(v)\}.

4.4.3 Encoding

70%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
71% This part optimizes the delay of each train.
72%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73
74{ late(T,V,D,W) : visit(T,V) } :- potlate(T,V,D,W).
75
76next(T,V,D,D’) :- potlate(T,V,D,_), potlate(T,V,D’,_), D<D’,
77 not potlate(T,V,D’’,_) : potlate(T,V,D’’,_),
78 D’’>D, D’’<D’.
79:- not late(T,V,D,_), late(T,V,D’,_), next(T,V,D,D’).
80
81topo_late(T,N,D,W) :- late(T,V,D,W), h(T,V,N).
82
83&diff{ 0-(T,N) } <= -D :- topo_late(T,N,D,W).
84&diff{ (T,M)-0 } <= N :- not topo_late(T,M,D,W),
85 potlate(T,V,D,W),
86 N=D-1, visit(T,V), h(T,V,M).
87
88#minimize{ W@1,T,N,D : topo_late(T,N,D,W) }.
89#minimize{ P@0,T,E : penalty(E,P), route(T,E) }.
Listing 4: Delay and routing penalty minimization.

Given thresholds Dt,vD_{t,v} for all train lines and nodes and the corresponding instances of predicate potlate/4, Listing 4 shows the implementation of the delay minimization. The basic idea is to use regular atoms to choose whether a train line is delayed on its path for every potential delay (Line 74 in Listing 4). In lines 7679, we order the given thresholds for every train line and node. By enforcing downwards adjacent thresholds to hold as well (being late for 4 minutes implies being late for 3 minutes which in turn implies being late for 2 minutes etc.), we immediately exclude solutions where this semantic condition fails, thus improving propagation. Originally, the semantics of the late atoms (being late for xx minutes) is only given via the difference constraint atom introduced later. By directly encoding the implicit ordering of natural numbers using regular ASP atoms, we leverage the efficient Boolean constraint solving techniques of the ASP solver. Line 81 adjusts the late atoms to the topological ordering. In our example, this means that train line t1t_{1} being late 1 minute on node 11 uses the same variable as being late 1 minute on node 12 thus reducing the amount of variables that are needed to capture delay. Finally, we derive difference constraint atoms expressing this information (lines 8386), and ultimately using the regular atoms in a standard minimize statement (Line 88). In detail, for every atom potlate(tt,vv,uu,ww), an atom late(tt,vv,uu,ww) can be chosen if tt visits vv. For every late(tt,vv,uu,ww) we derive topo_late(tt,ht(v)\mathit{h}_{t}(v),uu,ww). If topo_late(tt,ht(n)\mathit{h}_{t}(n),uu,ww) is chosen to be true, a difference constraint atom &diff{0-(t,ht(v))(t,\mathit{h}_{t}(v))}<= u-u is derived expressing (t,ht(v))u(t,\mathit{h}_{t}(v))\geq u and, therefore, that tt is delayed at the visited node vv at threshold uu. Otherwise, &diff{(t,ht(v))(t,\mathit{h}_{t}(v))-0}<= u1u-1 becomes true so that (t,ht(v))<u\texttt{$(t,\mathit{h}_{t}(v))$}<u holds. The difference constraint atoms ensure that if the truth value of a late atom is decided, the schedule has to reflect this information. The minimize statement then sums up and minimizes the penalties of the late atoms that are true.

Finally, Line 89 shows the straightforward encoding of the routing penalty minimization. The minimize statement merely collects the paths of the train lines, sums up their penalties, and minimizes this sum. This is done on a lower level than delay minimization leading to lexicographic optimization minimizing delay first and route penalty second.

4.5 Optional Constraints and Heuristics

While the above encoding can be used as is, additional constraints can be added to further restrict the search space in the hope of improving solving performance. To this end, we rely on the fact that clingo[DL] consists of a Boolean search engine (clingo) and a dedicated difference constraints propagator. While some atoms are purely Boolean, others have a semantics in terms of difference constraints. In the following, we transfer the knowledge represented in these difference constraints (such as transitivity and acyclicity) back to the logic program, thereby improving the search in the ASP part of the problem. Finally, a domain-specific heuristic is represented that prefers sequences of train lines reducing the likelihood of conflicts.

4.5.1 Resource overlap I

Resource areas with different resources overlap if both contain at least one common edge. If two train lines are each routed over such an overlap, the sequence of entering the respective pairs of resource areas has to be the same since it is not possible for trains to overtake each other throughout both overlapping resource areas. We exploit this by detecting such overlaps and using them to add constraints that remove solution candidates for which the sequences do not match, thus reducing the search space. More precisely, given two resources rr and rr^{\prime}, train lines tt and tt^{\prime}, and resource areas A𝒜rtA\in\mathcal{A}^{t}_{r}, A𝒜rtA^{\prime}\in\mathcal{A}^{t}_{r^{\prime}}, B𝒜rtB\in\mathcal{A}^{t^{\prime}}_{r}, and B𝒜rtB^{\prime}\in\mathcal{A}^{t^{\prime}}_{r^{\prime}}, if train line tt leaves resource area AA before train tt^{\prime} enters its resource area BB, tt visits an edge (v,v)AA(v,v^{\prime})\in A\cap A^{\prime} and tt^{\prime} visits and edge from (u,u)BB(u,u^{\prime})\in B\cap B^{\prime} (i.e. both trains use the overlapping areas), then train tt also has to leave resource area AA^{\prime} before train tt^{\prime} enters resource area BB^{\prime}.

As an example, we use a straight line of three tracks, where nodes are ordered adjacently from left to right. Consider train lines ta=(S,L,e,l,w)t_{a}=(S,L,e,l,w), tb=(S,L,e,l,w)t_{b}=(S,L,e^{\prime},l^{\prime},w^{\prime}) and tc=(S,L,e′′,l′′,w′′)t_{c}=(S,L^{\prime},e^{\prime\prime},l^{\prime\prime},w^{\prime\prime}) over nodes S={1,2,3,4}S=\{1,2,3,4\}, and edges L={(1,2),(2,3),(3,4)}L=\{(1,2),(2,3),(3,4)\}, and L={(4,3),(3,2),(2,1)}L^{\prime}=\{(4,3),(3,2),(2,1)\}. Furthermore, let a(rl)={(1,2),(2,3),(3,2),(2,1)}a(r_{l})=\{(1,2),(2,3),(3,2),(2,1)\} and a(rr)={(2,3),(3,4),(4,3),(3,2)}a(r_{r})=\{(2,3),(3,4),(4,3),(3,2)\}, meaning that rlr_{l} forms a resource area covering the left and middle part of the graph while rrr_{r} forms a resource area covering the middle and right part of the graph. The resources overlap in the middle on edges (2,3)(2,3) and (3,2)(3,2). Consider train line tat_{a} entering resource area {(1,2),(2,3)}\{(1,2),(2,3)\} via edge (1,2)(1,2), using resource rlr_{l}, before train line tbt_{b} enters this edge; it immediately follows that tat_{a} also has to enter edge (2,3)(2,3) before train line tbt_{b}. Given that edge (2,3)(2,3) is also in the resource area {(2,3),(3,4)}\{(2,3),(3,4)\}, it is impossible for train line tbt_{b} to overtake tat_{a}, and the sequence of entering these resource areas is the same. The same holds for train lines tat_{a} and tct_{c}. Once tat_{a} enters resource area {(1,2),(2,3)}\{(1,2),(2,3)\} before tct_{c} enters resource area {(3,2),(2,1)}\{(3,2),(2,1)\}, it follows that tat_{a} also has to enter resource area {(2,3),(3,4)}\{(2,3),(3,4)\} before train line tct_{c} can enter resource area {(4,3),(3,2)}\{(4,3),(3,2)\}, as both trains cannot get past each other because their respective resource areas overlap.

86ra_overlap(T,R,A,R’,A’) :-
87 ra(T,R,A,(V,V’)), ra(T,R’,A’,(V,V’)), R != R’.
88:- seq(T,T’,R,A,A’), not seq(T,T’,R’,B,B’),
89 ra_overlap(T,R,A,R’,B), ra_overlap(T’,R,A’,R’,B’),
90 1 #sum {1 : route(T,(V,V’)),
91 ra(T,R,A,(V,V’)), ra(T,R’,B,(V,V’)),
92 route(T’,(U,U’)),
93 ra(T’,R,A’,(U,U’)), ra(T’,R’,B’,(U,U’))},
94 1 #sum {1 : shared(T,T’,R’,B,B’);
95 1 : decided(T,T’,R’,B,B’);
96 1 : decided(T’,T,R’,B’,B)}.
Listing 5: Optional overlap constraints (part I).

In Listing 5, we first compute pairs of resource areas that overlap in lines 86 and 87 by deriving atoms ra_overlap(tt,rr,aa,rr^{\prime},aa^{\prime}) representing that for a train line tt, resource areas A𝒜rtA\in\mathcal{A}^{t}_{r} and A𝒜rtA^{\prime}\in\mathcal{A}^{t}_{r^{\prime}} share at least one edge for distinct resources rr and rr^{\prime}. Note that aa and aa^{\prime} are used as identifiers for resource areas AA and AA^{\prime}, respectively. The integrity constraint in lines 8896 enforces that train lines routed over an overlap have the same sequence over both pairs of resource areas. Lines 9093 require that both train lines visit at least one edge that is shared by the overlapping resource areas. We ensure that the sequence is only enforced, if a resource conflict is possible between these two train lines in lines 9496. The predicate decided is used to extend this constraint to other cases, where we can exploit overlap to reduce the search space. We examine such a case in the following section.

4.5.2 Resource overlap II

We improve the optional overlap constraint from Listing 5 in Listing 6 by additionally considering sequences over resource areas which can be determined before search.

97decided(T,T’,R,A,A’) :-
98 l_ra(T,R,A,L), e_ra(T’,R,A’,E), T != T’, L < E.
99decided(T,T’,R,A,A’) :-
100 ra(T,R,A,(V,V’)), set(T,(V,V’)), l(T,V’,L), T != T’,
101 ra(T’,R,A’,(U,U’)), set(T’,(U,U’)), e(T’,U,E), L < E.
102seq(T,T’,R,A,A’) :- decided(T,T’,R,A,A’).
Listing 6: Optional overlap constraints (part II).

Given a resource rr, the sequence how two different trains t=(S,L,e,l,w)t=(S,L,e,l,w) and t=(S,L,e,l,w)t^{\prime}=(S^{\prime},L^{\prime},e^{\prime},l^{\prime},w^{\prime}) leave and enter their respective resource areas ArtA^{t}_{r} and Art{A}^{t^{\prime}}_{r} is already decided if either

  1. 1.

    the latest entry time of train line tt into resource area ArtA^{t}_{r} is before the earliest entry time of train line tt^{\prime} into resource area ArtA^{t^{\prime}}_{r} (cf. lines 97 and 98), or

  2. 2.

    there exist two edges (v,v)Art(v,v^{\prime})\in A^{t}_{r} and (u,u)Art(u,u^{\prime})\in A^{t^{\prime}}_{r} that are included in every possible path of train line tt and tt^{\prime}, respectively, where the latest entry time l(v)l(v^{\prime}) is before the earliest entry time e(u)e^{\prime}(u) (cf. lines 99101).

For the latter case, we use precomputed atoms set(tt,(vv,vv^{\prime})) to denote edges (v,v)(v,v^{\prime}) that are already set to be in every path of a train line tt. Reconsider our previous example with train lines ta=(S,L,e,l,w)t_{a}=(S,L,e,l,w) and tb=(S,L,e,l,w)t_{b}=(S,L,e^{\prime},l^{\prime},w^{\prime}) where S={1,2,3,4}S=\{1,2,3,4\} and L={(1,2),(2,3),(3,4)}L=\{(1,2),(2,3),(3,4)\}. Given that l(3)<e(1)l(3)<e^{\prime}(1), it is already decided that train line tat_{a} leaves resource area {(1,2),(2,3)}\{(1,2),(2,3)\} before tbt_{b} enters this resource area. By deriving this information in Listing 6, Listing 5 ensures that the same sequence is used for resource area {(2,3),(3,4)}\{(2,3),(3,4)\}.

No matter which case holds, we derive the atom decided(tt,tt^{\prime},rr,aa,aa^{\prime}) to state that train line tt leaves resource area ArtA^{t}_{r} before train line tt^{\prime} enters resource area Art{A^{\prime}}^{t^{\prime}}_{r}. Converting these atoms into sequences in Line 102 enhances propagation of the rules in Listing 5, as these already decided sequences can be used in the integrity constraint in Line 88 to derive the truth value of additional sequences. Note that since the additional instances of the seq/55 predicate serialize resource areas where the time intervals do not overlap, solutions of the encodings in listings 2 and 3 remain unchanged.

4.5.3 Sequence acyclicity

Whenever more than two train lines have to be serialized on a resource, the resulting sequence can never be cyclic. In more detail, given a resource rr and three train lines t1t_{1}, t2t_{2}, and t3t_{3}, if t1t_{1} leaves resource area Art1A^{t_{1}}_{r} before t2t_{2} enters resource area Art2A^{t_{2}}_{r}, and t2t_{2} leaves resource area Art2A^{t_{2}}_{r} before t3t_{3} enters resource area Art3A^{t_{3}}_{r}, it follows that t1t_{1} leaves area Art1A^{t_{1}}_{r} before t3t_{3} enters area Art3A^{t_{3}}_{r} as well. This is guaranteed by the constraints in Condition (7) and realized by the difference constraint atoms in Listing 3 lines 5962.

103:- seq(T,T’,R,A,A’), seq(T’,T’’,R,A’,A’’),
104 shared(T,T’’,R,A,A’’), not seq(T,T’’,R,A,A’’).
Listing 7: Optional acyclicity constraints.

While this condition would be eventually derived by the difference constraints propagator, we immediately restrict the search space by providing this explicit constraint, realized in Listing 7. Furthermore, by expressing this timing-related condition in terms of regular ASP atoms, we can leverage the propagation mechanism of state-of-the-art ASP solving technology, which is currently faster and more sophisticated compared to the one used in the difference constraints propagator.

4.5.4 Sequence heuristic

105#heuristic seq(T,T’,R,A,A’) :
106 shared(T,T’,R,A,A’),
107 e_ra(T,R,A,E), e_ra(T’,R,A’,E’),
108 l_ra(T,R,A,L), l_ra(T’,R,A’,L’). [E’-E - (L-L’),sign]
Listing 8: Heuristic that orders conflicting train lines by their possible arrival times.

The heuristic in Listing 8 attempts to order conflicting train lines by their possible arrival times at the areas where the conflict is located. In essence, we analyze how the time intervals of the train lines are situated and prefer their sequence accordingly. Given two train lines tt and tt^{\prime} with intervals [e,l][e,l] and [e,l][e^{\prime},l^{\prime}] at the conflicting areas, respectively, we calculate s=ee(ll)s=e^{\prime}-e-(l-l^{\prime}) to determine whether tt should be scheduled before tt^{\prime}. If ss is positive, the preferred sign of the sequence atom is also positive, thus preferring tt to go before tt^{\prime}, if it is negative, the opposite is expressed. In detail, eee^{\prime}-e is positive if tt^{\prime} may arrive later than tt thus making it more likely that tt can go first without delaying tt^{\prime}. Similarly, if lll-l^{\prime} is negative, tt^{\prime} may leave later, suggesting tt to go first. If the results of both expressions have the same sign, one interval is contained in the other and if the difference is positive, the center of the interval of tt is located earlier than the center of the interval of tt^{\prime}. For example, in Figure 2, we see that t1t_{1} and t2t_{2} share resource 𝑠𝑤1\mathit{sw}_{1} in Node 3 and the time intervals in which they potentially arrive at those edges are [300,600][300,600] and [180,540][180,540], respectively. Given that 180300(600540)=180180-300-(600-540)=-180, we prefer t2t_{2} to be scheduled before t1t_{1}, which in the example is clearly the correct decision, since t2t_{2} precedes t1t_{1} without delaying t1t_{1}.

5 Experiments

We evaluate our train scheduling solution using the hybrid ASP system clingo[DL] v1.1, which is built upon the API of clingo 5.3.555Both are development versions available on https://github.com/potassco/{clingoDL,clingo}/ with commit hashs #f1a185e and #f8a51134, respectively. As benchmark set, we use 25 real-world instances crafted by domain experts at Swiss Federal Railways (SBB). The instances capture parts of the railway network between three Swiss cities, namely Zürich, Chur and Luzern, and vary in number of train lines, size and depths of railway network and timing constraints. The biggest instances contain the whole railway network and up to 467 train lines taken from long distance, regional, suburban and freight traffic between these three cities. Thus, we tackle instances with approximately six hours of the full train schedule on a railway network covering approximately 200 km. For brevity, we omit slight grounding and propagation optimizations in the encoding presented in Section 4; the full encoding and instance set is available at https://github.com/potassco/train-scheduling-with-hybrid-asp/. We use the best optimization configuration determined in [Abels et al. (2019)]. In detail, we use two threads, one running with a model-guided optimization strategy iteratively producing models of descending cost until the optimum is found, and the other with a core-guided optimization strategy [Andres et al. (2012)] relying on successively identifying and relaxing unsatisfiable cores until a model is obtained. Furthermore, the delay minimization is modeled by setting Dt,v=𝐵𝑖𝑛t,v𝐿𝑖𝑛t,v180D_{t,v}=\mathit{Bin}_{t,v}\cup\mathit{Lin}^{180}_{t,v} for each train line tt at node vv, thus, there are six thresholds in total, one if there is any delay at all, and five with a distance of 180 seconds in between with the last one being at 15 minutes. We use lexicographic optimization minimizing delay first and route penalty second.

As a preliminary step, we benchmark each domain-specific heuristic and optional constraints individually, and removed the ones that did not yield any improvement compared to clingo[DL]’s default setting. 666In particular, we dropped two heuristics proposed in [Abels et al. (2019)] since they did not improve solving performance with the new resource area and height-based encoding. This might be either due to the fact that the search space was too drastically reduced and as such less impact can be achieved by the branching heuristics, or that the switch to lexicographic optimization made some heuristics obsolete.

In total, we examined four optional encoding parts, one domain-specific heuristic and three optional constraints, and all their combinations. More precisely, we consider the sequence heuristic (hs), resource overlap I (ol1), resource overlap II (ol2), and sequence acyclicity (ac), and all seven possible combinations (given that ol1 is contained in ol2). We compare the results to clingo[DL]’s default settings without optional encoding parts and domain-specific heuristic (def).

All benchmarks ran on Linux with a Xeon E3-1260L quad-core 2.9 GHz processors and 32 GB RAM; each run limited to 3 hours and 32GB RAM. For all our experiments, we asked clingo[DL] to return one optimal solution, and we then validate feasibility and quality via an external tool provided by SBB.777https://github.com/potassco/train-scheduling-with-hybrid-asp/.

Table 5 shows the average runtime (t) over all 25 instances, which includes grounding and solving, grounding time (gt), choices (ch) and conflicts (co) for individual domain-specific heuristics and optional constraints; their combinations are given in Table 5. The best results in a row are marked bold. Note that for all configurations and instances, clingo[DL] was able to find an optimal solution, thus, no time- or memory-outs blur average time as a means for comparing the performance of the different configurations. Grounding the largest instances within the time limit is enabled by our preprocessing and the height-based naming scheme for the integer variables, due to their significant impact on reducing grounding size.

conf t gt ch co
def 550 45 242516740 9135
hs 162 45 51933286 7363
ol1 118 53 13003796 4038
ol2 105 62 8377540 3530
ac 435 46 116873540 8755
Table 1: Average runtime (t), grounding time (gt), choices (ch) and conflicts (co) for individual domain-specific heuristics and optional constraints.

We clearly see in Table 5 that ol2 by itself improves solving performance the most, drastically reducing choices and conflicts compared to def and displaying the lowest average runtime overall. This is closely followed by ol1. The heuristic hs still clearly improves the solving performance while optional constraint ac only slightly improves upon the default. We can observe that grounding time is higher for all optional constraints, especially for ol2. This is to be expected as additional rules and integrity constraint are added to the encoding. The improvement in solving performance through the reduced search space vastly outweighs the decrease in grounding performance though.

Table 2: Average runtime (t), grounding time (gt), choices (ch) and conflicts (co) for combinations of domain-specific heuristics and optional constraints.

As for the composite configurations in Table 5, we observe that all of them are an improvement over the individual heuristics and optional constraints. The largest combinations also yield the best performance overall. Here, we see that, while hs/ol2/ac traverses the search space most effectively (yielding least choices and conflicts), hs/ol1/ac has a slightly better runtime performance due to lower grounding time. This shows, first, that the combination hs/ol1/ac alleviate some weaknesses compared to the individual configurations, as ol1 alone was slower than ol2. And second, that both composite configurations might prove useful in the future since for harder instances the improvement in terms of the search might outweigh the decrease in grounding performance. The last row vbs displays the virtual best solver that averages the best performance regarding runtime among all configurations. We see that the performance of vbs is close to the best configurations and as such choosing one among hs/ol1/ac, hs/ol2/acand hs/ol1 should be a good choice as default configuration for most instances.

Table 3: Detailed information and best results for all benchmark instances.

In the following, we analyze the 25 real-world instances in detail and highlight the best results that we could achieve using the different configurations of our train scheduling solution. This information is presented in Table 5. Row ins contains the names of the 25 instances. Instance names starting with p are the nine instances originally used in [Abels et al. (2019)] that were published by SBB; they only contain part of the railway network between Zürich, Chur and Luzern. Two instances among them are marked with r and are reduced versions of the largest instance, viz. p9. Instances starting with t, on the other hand, cover the whole test area between the three cities. Furthermore, instance names containing s and l cover a shorter (about two hours) or longer time span (about six hours), respectively, which is reflected in the amount of train lines. With our problem formulation, one can express different settings of the train scheduling problem. Normally, all train lines are considered as new and to be taken into account evenly. Another problem variation is the rescheduling after adding or changing one extra train line. This is achieved by closely restricting earliest and latest arrival times around the old schedule for existing and unchanged train lines, while the extra train line is given more freedom. Instances containing an e are such rescheduling instances. Similarly, most instances have a uniform time span between the point after which a train line is delayed and the latest possible arrival time. Unlike this, for names including i, this time span is different for each train line, i.e., different train lines have different capacities for delay. Instances of the same class mostly vary in the depths of the railway network, i.e., how many alternative routes are available to each train line, but also slightly in number of train lines, resources and timing constraints.

The following nine columns analyze structural attributes of the instances, and how much preprocessing and encoding techniques reduce the instance size and search space. Column #tl shows the number of train lines for each instance. Column #r gives the number of resources, and Column #sr the number of subsumed resources. Subsumed resources can be observed in all instances and constitute on average 34%, which can then be safely removed. Column #rtl sums up resources on each edge in each subgraph of all train lines, which essentially constitutes the basis for resource conflicts using the edge-based conflict resolution. Column #ra then shows into how many resource areas those individual edges could be distributed. The difference from #rtl to #ra is on average 83%, thus drastically reducing resource entities that might induce conflicts. The following columns #ec and #rac display the number of resource conflicts based on single edges and resource ares, respectively. They highlight the benefit of introducing resource areas. We reduce the number of resource conflicts, and thus the decisions that have to be made to serialize the train lines, on average by 92%. Finally, #vnn and #vhn shows the number of integer variables needed using node- and height-based naming scheme, respectively. We save 25% of variables on average switching to the height-based naming scheme.

In the last three columns, we present the virtual best results regarding runtime across all configurations presented in Table 5 and 5. In more detail, we show the runtime per instance in Column t, and the approximated and exact quality as a pair of delay penalty in minutes and route penalty in Columns aqu and Column qu, respectively. The approximated quality amounts to the value returned by the ASP system, which is optimal for all instances, while the exact quality is returned by a tool of SBB. We were able to solve all instances with a maximum time of about 3 minutes. We calculated solutions without any delay for all instances where this was possible. For instances where this was not the case, experts at SBB deemed the incurred delay as close to optimal. Of course, we are not able to prove true optimality in all cases since we use an approximation of the delay function. Note that, for example for instance tl10, we have a rather high difference between approximated delay and actual delay of about 11 minutes. This is due to the fact that the ASP system only considers a lower bound on delay. If the approximated optimal value is for example 3 seconds, this could mean that there are three instances of delay. The amount of delay though could be as much as 3179=5373*179=537 seconds since the next threshold is at 180 seconds in our configuration of the approximation. Completely avoiding this drawback of the approximation is currently only possible by introducing a threshold for every second, which deteriorates solving performance. We judge our current solution to be a good trade-off between solving performance and quality, since the quality of the results is sanctioned by Swiss Federal Railways and we are able to solve all real-world instances within minutes.

6 Discussion

At its core, train scheduling is similar to classical scheduling problems that were already tackled by ASP. Foremost, job shop scheduling [Taillard (1993)] is also addressed by clingo[DL] and compared to other hybrid approaches in [Janhunen et al. (2017)]; solutions based on SMT, CP and MILP are given in [Janhunen et al. (2011), Bofill et al. (2012), Baptiste et al. (2012), Liu et al. (2012)]. In fact, job shop scheduling can be seen as a special case of our setting, in which train paths are known beforehand. Solutions to this restricted variant using MILP and CP are presented in [Oliveira and Smith (2000), Rodriguez (2007)]. The difference to our setting is twofold: first, resource conflicts are not known beforehand since we take routing and scheduling simultaneously into account. Second, our approach encompasses a global view of arbitrary precision, i.e., we model all routing and scheduling decisions across hundreds of trains lines down to inner-station conflict resolution and allow for expressing complex connections that also accommodate cyclic train movements. Furthermore, using hybrid ASP with difference constraints gives us inherent advantages over pure ASP and MILP. First, we show in [Gebser et al. (2016)] that ASP is not able to solve most shop scheduling instances since grounding all integer variables leads to an explosion in problem size. We avoid this bottleneck by encapsulating scheduling in difference constraints and, hence, avoid grounding integer variables. Second, while difference constraints are less expressive than linear constraints in MILP, they are sufficient for expressing the timing constraint needed for train scheduling while being solvable in polynomial time. Finally, routing and conflict resolution require Boolean variables and disjunctions for which ASP has effective means.

In this work, we contribute a flexible and holistic ASP-based encoding of the train scheduling problem based on a precise formalization. On the one hand, since we produce timetables from scratch, our train scheduling approach can be characterized as tactical scheduling [Törnquist (2006)]. On the other hand, without changing encoding or problem formalization, we can easily accommodate problem variations like rescheduling without loosing performance, as we show for three instances in our empirical evaluation.

As seen in Section 5, all instances available to us can be solved within minutes. These instances represent sections of a test area in Switzerland, with the largest one capturing a complex, interconnected railway network spanning in length about 200 km and involving up to 467 train lines with local, regional and cargo railway traffic among them. This is possible in part due to dedicated preprocessing techniques, such as resource subsumption and resource areas, that exploit structural redundancies within the railway network as well as graph compressing methods, which drastically reduce the size of the problem representation. Furthermore, we reduce the search space and leverage advanced propagation mechanisms of our state-of-the-art ASP solving technology by transferring implicit knowledge about difference constraints into the logic program. Some of these techniques may also be candidates to improve performance for other scheduling problems like the related job shop scheduling.

To advance our approach, multi-shot solving [Gebser et al. (2019)] can be used to incrementally increase train line intervals or dynamically replan schedules by adding or removing train lines. While our hybrid ASP approach already tackles some real-world instances that are on the larger side, scalability, for example, to the entirety of Switzerland is still an issue. For that purpose, we are looking into decomposition techniques, so that smaller areas using our approach can be combined to solutions for entire countries.

References

  • Abels et al. (2019) Abels, D., Jordi, J., Ostrowski, M., Schaub, T., Toletti, A., and Wanko, P. 2019. Train scheduling with hybrid ASP. In Proceedings of the Fifteenth International Conference on Logic Programming and Nonmonotonic Reasoning (LPNMR’19), M. Balduccini, Y. Lierler, and S. Woltran, Eds. Lecture Notes in Artificial Intelligence, vol. 11481. Springer-Verlag, 3–17.
  • Andres et al. (2012) Andres, B., Kaufmann, B., Matheis, O., and Schaub, T. 2012. Unsatisfiability-based optimization in clasp. In Technical Communications of the Twenty-eighth International Conference on Logic Programming (ICLP’12), A. Dovier and V. Santos Costa, Eds. Vol. 17. Leibniz International Proceedings in Informatics (LIPIcs), 212–221.
  • Baptiste et al. (2012) Baptiste, P., Pape, C. L., and Nuijten, W. 2012. Constraint-based scheduling: applying constraint programming to scheduling problems. Vol. 39. Springer Science+Business Media.
  • Bofill et al. (2012) Bofill, M., Palahí, M., Suy, J., and Villaret, M. 2012. Solving constraint satisfaction problems with sat modulo theories. Constraints 17, 3, 273–303.
  • Caprara et al. (2002) Caprara, A., Fischetti, M., and Toth, P. 2002. Modeling and solving the train timetabling problem. Operations Research 50, 851–861.
  • Gebser et al. (2015) Gebser, M., Harrison, A., Kaminski, R., Lifschitz, V., and Schaub, T. 2015. Abstract Gringo. Theory and Practice of Logic Programming 15, 4-5, 449–463. Available at http://arxiv.org/abs/1507.06576.
  • Gebser et al. (2015) Gebser, M., Kaminski, R., Kaufmann, B., Lindauer, M., Ostrowski, M., Romero, J., Schaub, T., and Thiele, S. 2015. Potassco User Guide, 2 ed. University of Potsdam.
  • Gebser et al. (2016) Gebser, M., Kaminski, R., Kaufmann, B., Ostrowski, M., Schaub, T., and Wanko, P. 2016. Theory solving made easy with clingo 5. In Technical Communications of the Thirty-second International Conference on Logic Programming (ICLP’16), M. Carro and A. King, Eds. OpenAccess Series in Informatics (OASIcs), vol. 52. Schloss Dagstuhl–Leibniz-Zentrum fuer Informatik, 2:1–2:15.
  • Gebser et al. (2019) Gebser, M., Kaminski, R., Kaufmann, B., and Schaub, T. 2019. Multi-shot ASP solving with clingo. Theory and Practice of Logic Programming 19, 1, 27–82.
  • Gebser et al. (2013) Gebser, M., Kaufmann, B., Otero, R., Romero, J., Schaub, T., and Wanko, P. 2013. Domain-specific heuristics in answer set programming. In Proceedings of the Twenty-Seventh National Conference on Artificial Intelligence (AAAI’13), M. desJardins and M. Littman, Eds. AAAI Press, 350–356.
  • Janhunen et al. (2017) Janhunen, T., Kaminski, R., Ostrowski, M., Schaub, T., Schellhorn, S., and Wanko, P. 2017. Clingo goes linear constraints over reals and integers. Theory and Practice of Logic Programming 17, 5-6, 872–888.
  • Janhunen et al. (2011) Janhunen, T., Liu, G., and Niemelä, I. 2011. Tight integration of non-ground answer set programming and satisfiability modulo theories. In Proceedings of the First Workshop on Grounding and Transformation for Theories with Variables (GTTV’11), P. Cabalar, D. Mitchell, D. Pearce, and E. Ternovska, Eds. 1–13.
  • Lifschitz (1999) Lifschitz, V. 1999. Answer set planning. In Proceedings of the International Conference on Logic Programming (ICLP’99), D. de Schreye, Ed. MIT Press, 23–37.
  • Liu et al. (2012) Liu, G., Janhunen, T., and Niemelä, I. 2012. Answer set programming via mixed integer programming. In Proceedings of the Thirteenth International Conference on Principles of Knowledge Representation and Reasoning (KR’12), G. Brewka, T. Eiter, and S. McIlraith, Eds. AAAI Press, 32–42.
  • Oliveira and Smith (2000) Oliveira, E. and Smith, B. 2000. A job-shop scheduling model for the single-track railway scheduling problem. LU SCS RR 21, University of Leeds, School of Computer Studies.
  • Rodriguez (2007) Rodriguez, J. 2007. A constraint programming model for real-time train scheduling at junctions. Transportation Research Part B: Methodological 41, 2, 231–245.
  • Taillard (1993) Taillard, E. 1993. Benchmarks for basic scheduling problems. European Journal of Operational Research 64, 2, 278–285.
  • Törnquist (2006) Törnquist, J. 2006. Computer-based decision support for railway traffic scheduling and dispatching: A review of models and algorithms. In Proceedings of Fifth Workshop on Algorithmic Methods and Models for Optimization of Railways (ATMOS’05), L. G. Kroon and R. H. Möhring, Eds. OpenAccess Series in Informatics (OASIcs), vol. 2. Schloss Dagstuhl–Leibniz-Zentrum fuer Informatik.

Appendix A Example instance

tl(t1). tl(t2). tl(t3).
edge(t1,1,3). edge(t1,2,3). edge(t1,3,5). edge(t1,5,8).
edge(t1,8,10). edge(t1,10,11). edge(t1,10,12).
edge(t2,10,7). edge(t2,7,4). edge(t2,4,3).
edge(t3,3,6). edge(t3,6,9). edge(t3,9,10). edge(t3,10,12).
e(t1,1,240). l(t1,1,540). e(t1,2,240). l(t1,2,540).
e(t1,3,300). l(t1,3,600). e(t1,5,360). l(t1,5,660).
e(t1,8,420). l(t1,8,720). e(t1,10,480). l(t1,10,780).
e(t1,11,540). l(t1,11,840). e(t1,12,540). l(t1,12,840).
start(t1,1). start(t1,2). end(t1,11). end(t1,12).
e(t2,10,0). l(t2,10,360). e(t2,7,60). l(t2,7,420).
e(t2,4,120). l(t2,4,480). e(t2,3,180). l(t2,3,540).
start(t2,10). end(t2,3).
e(t3,3,180). l(t3,3,540). e(t3,6,240). l(t3,6,600).
e(t3,9,300). l(t3,9,660). e(t3,10,360). l(t3,10,720).
e(t3,12,420). l(t3,12,780).
start(t3,3). end(t3,12).
potlate(t1,1,451,1). potlate(t1,2,451,1). penalty((1,3),1).
potlate(t2,10,241,1). potlate(t3,3,421,1).
resource(sw1,(1,3)). resource(sw1,(2,3)).
resource(sw1,(4,3)). resource(sw1,(3,5)).
resource(sw1,(3,6)). resource(sw2,(8,10)).
resource(sw2,(9,10)). resource(sw2,(10,7)).
resource(sw2,(10,11)). resource(sw2,(10,12)).
connection(1,t2,(4,3),t3,(3,6),0,0,3,3).
free(1,t2,(4,3),t3,(3,6),sw1).
connection(2,t1,(10,11),t3,(10,12),60,#inf,10,12).
connection(3,t1,(10,12),t3,(10,12),60,#inf,10,12).
set(t1,(3,5)). set(t1,(5,8)). set(t1,(8,10)).
set(t2,(10,7)). set(t2,(7,4)). set(t2,(4,3)).
set(t3,(3,6)). set(t3,(6,9)). set(t3,(9,10)).
set(t3,(10,12)).
resource(r(1,3),(1,3)). resource(r(2,3),(2,3)).
resource(r(3,5),(3,5)). resource(r(5,8),(5,8)).
resource(r(7,4),(7,4)). resource(r(4,3),(4,3)).
resource(r(3,6),(3,6)). resource(r(6,9),(6,9)).
ra(t1,sw1,0,(1,3)). ra(t1,r(1,3),0,(1,3)).
ra(t1,sw1,0,(2,3)). ra(t1,r(2,3),0,(2,3)).
ra(t1,sw1,0,(3,5)). ra(t1,r(3,5),0,(3,5)).
ra(t1,r(5,8),0,(5,8)). ra(t1,sw2,0,(8,10)).
ra(t1,sw2,0,(10,11)). ra(t1,sw2,0,(10,12)).
ra(t2,sw2,0,(10,7)). ra(t2,r(7,4),0,(7,4)).
ra(t2,sw1,0,(4,3)). ra(t2,r(4,3),0,(4,3)).
ra(t3,sw1,0,(3,6)). ra(t3,r(3,6),0,(3,6)).
ra(t3,r(6,9),0,(6,9)). ra(t3,sw2,0,(9,10)).
ra(t3,sw2,0,(10,12)).
potlate(t1,3,511,1). potlate(t1,5,571,1).
potlate(t1,8,631,1). potlate(t1,10,691,1).
potlate(t1,11,751,1). potlate(t1,12,751,1).
potlate(t2,7,301,1). potlate(t2,4,361,1).
potlate(t2,3,421,1). potlate(t3,6,481,1).
potlate(t3,9,541,1). potlate(t3,10,601,1).
potlate(t3,12,661,1).
l_ra(t1,sw1,0,660). l_ra(t1,r(1,3),0,600).
l_ra(t1,r(2,3),0,600). l_ra(t1,r(3,5),0,660).
l_ra(t1,r(5,8),0,720). l_ra(t1,sw2,0,840).
l_ra(t2,sw2,0,420). l_ra(t2,r(7,4),0,480).
l_ra(t2,sw1,0,540). l_ra(t2,r(4,3),0,540).
l_ra(t3,sw1,0,600). l_ra(t3,r(3,6),0,600).
l_ra(t3,r(6,9),0,660). l_ra(t3,sw2,0,780).
e_ra(t1,sw1,0,240). e_ra(t1,r(1,3),0,240).
e_ra(t1,r(2,3),0,240). e_ra(t1,r(3,5),0,300).
e_ra(t1,r(5,8),0,360). e_ra(t1,sw2,0,420).
e_ra(t2,sw2,0,0). e_ra(t2,r(7,4),0,60).
e_ra(t2,sw1,0,120). e_ra(t2,r(4,3),0,120).
e_ra(t3,sw1,0,180). e_ra(t3,r(3,6),0,180).
e_ra(t3,r(6,9),0,240). e_ra(t3,sw2,0,300).
b(sw1,60). b(sw2,60). b(r(1,3),60). b(r(2,3),60).
b(r(3,5),60). b(r(5,8),60). b(r(7,4),60). b(r(4,3),60).
b(r(3,6),60). b(r(6,9),60).
w(t1,(1,3),0). w(t1,(2,3),0). w(t1,(3,5),0). w(t1,(5,8),0).
w(t1,(8,10),0). w(t1,(10,11),0). w(t1,(10,12),0).
w(t2,(10,7),0). w(t2,(7,4),0). w(t2,(4,3),0).
w(t3,(3,6),0). w(t3,(6,9),0). w(t3,(9,10),0). w(t3,(10,12),0).
m((1,3),60). m((2,3),60). m((3,5),60). m((5,8),60).
m((8,10),60). m((10,11),60). m((10,12),60). m((10,7),60).
m((7,4),60). m((4,3),60). m((3,6),60). m((6,9),60).
m((9,10),60).
Listing 9: Facts representing example instance (figures 1 and 2).