Parameterized Mixed Graph Coloring

Coloring of mixed graphs that contain both directed arcs and undirected edges is relevant for scheduling of unit-length jobs with precedence constraints and conflicts. The classic GHRV theorem (attributed to Gallai, Hasse, Roy, and Vitaver) relates graph coloring to longest paths. It can be extended to mixed graphs. In the present paper we further extend the GHRV theorem to weighted mixed graphs. As a byproduct this yields a kernel and a parameterized algorithm (with the number of undirected edges as parameter) that is slightly faster than the brute-force algorithm. The parameter is natural since the directed version is polynomial whereas the undirected version is NP-complete. Furthermore we point out a new polynomial case where the edges form a clique.


Mixed Graph Coloring
A mixed graph G = (V , A ∪ E) consists of a set V of n vertices, a set A of k directed arcs, and a set E of m undirected edges. We always use the terms arc and edge in this sense and omit the attribute [un]directed. We denote edges by uv and arcs by u → v, if not said otherwise. By a path or cycle we always mean a directed path or cycle consisting of arcs (not edges!). Moreover, it is understood that paths and cycles are simple, that is, no vertex is visited more than once. The length of a path is the number of its arcs. A directed graph is acyclic if it has no (directed) cycles. An orientation of a mixed graph replaces every edge with an arc that joins the same vertices, i.e., it decides on some direction of every edge. Already existing arcs are not changed. An orientation is called acyclic if the resulting directed graph is acyclic.
A coloring of a mixed graph is a function c assigning to every vertex v a color c(v) from the set of the first χ positive integers {1, . . . , χ}, such that c(u) = c(v) holds for all edges uv ∈ E, and c(u) < c(v) holds for all arcs u → v ∈ A. The Mixed Graph Coloring problem asks for a coloring that uses the smallest possible number χ of colors, called the chromatic number of the mixed graph.
We remark that the following statements are equivalent for any mixed graph G = (V , A ∪ E): G admits a coloring; G admits an acyclic orientation; (V , A) is acyclic.
One well known motivation of Mixed Graph Coloring is makespan minimization in batch scheduling of unit-length jobs: some pairs of jobs have precedence constraints and some others have conflicts. For instance, requesting access to the same resource forbids the simultaneous execution of certain jobs, whereas their order is arbitrary. Jobs are modelled as vertices, time slots as colors, precedence constraints as arcs, and conflicts as edges.

Related literature and complexity status
The Mixed Graph Coloring problem dates back to Sotskov and Tanaev (1976) and has been introduced again in Hansen et al. (1997) in the present form where every directed edge implies a strong inequality of colors. The latter paper provides some general bounds on the chromatic number and an O(n 2 ) time algorithm for trees. Further work has been devoted to heuristics for general mixed graphs and their applications, fast algorithms on special graph classes, as well as several hardness results (Al-Anzi et al. 2006;Furmanczyk et al. 2007;Gendron et al. 2007;Kouider et al. 2017;Ries and de Werra 2008;Sotskov et al. 2001). To mention one example, Mixed Graph Coloring restricted to bipartite graphs is NP-complete even with 3 colors and further restrictions, and it is solvable in polynomial time when only 2 colors are permitted (Ries 2007(Ries , 2010. It is also known that colorings of mixed graphs are nicely related to longest paths. The classic Gallai-Hasse-Roy-Vitaver (GHRV) theorem, named after the authors that rediscovered it several times, states the following, first only for directed graphs.
Theorem 1 (GHRV theorem) In any undirected graph, consider an acyclic orientation that minimizes the maximum length of all paths. For this value of , the chromatic number of the graph is χ = + 1.
The GHRV theorem can be extended literally to mixed graphs, and still the proof is simple (Hansen et al. 1997).
Coloring a directed graph is equivalent to checking whether it is acyclic, and if so, computing a longest path. All this can be done in linear time by standard algorithms. By way of contrast, coloring undirected graphs is well known to be NP-hard.
This situation suggests a natural bridge between the two problems: Mixed Graph Coloring parameterized by the number m of edges. To our best knowledge, Mixed Graph Coloring has not been studied before from the parameterized point of view.
[The oriented graph coloring problem considered in Ganian (2009) In the rest of the paper let G = (V , A ∪ E) be a mixed graph with acyclic directed part (V , A), as our input to the Mixed Graph Coloring problem. Remember that acyclicity is necessary and sufficient for a coloring to exist, and that m = |E| and k = |A|. We can assume that G has no isolated vertices (participating neither in edges nor in arcs), as they could be trivially colored arbitrarily. Therefore n = |V | is bounded by O(k + m).
We presume that the reader is familiar with fixed-parameter tractability (FPT). Briefly, an FPT algorithm solves a problem with input size n and another input parameter m in O( f (m) · p(n)) time, where f is some computable function and p is some polynomial. The time bound can be written as O * ( f (m)), suppressing the polynomial factor. A kernel is an equivalent problem instance which is computable in polynomial time and whose size is bounded by some function of m. A concept that is perhaps less well known is the notion of annotated kernels proposed in Abu- Khzam and Fernau (2006). On a high level, an annotated kernelization transforms any instance of the given problem to an instance (whose size is again bounded by some function of m) of a more general problem. Intuitively, the instance gets "annotations", that is, additional data items. [We refer to Abu-Khzam and Fernau (2006) for the exact technical definition.] In our case, we will go from mixed graphs to mixed graphs with arc lengths.
We will also use some standard facts that can be retrieved in any textbook on algorithms: a topological order of a directed graph is an order of the vertex set such that all arcs are oriented in one direction (say "from left to right"). A directed graph is acyclic if and only if it possesses a topological order. Furthermore, one can compute a topological order in linear time (in the number of arcs), as well as the lengths of longest paths from any fixed vertex to all other vertices to the right in the topological order.
Using the aforementioned GHRV theorem generalized to mixed graphs (Hansen et al. 1997), membership of Mixed Graph Coloring with parameter m in FPT becomes pretty obvious: we first examine each of the at most 2 m orientations of E, check whether the resulting directed graph is acyclic, and if so, compute a longest path, in O(k + m) time. Finally we take an orientation that minimizes the maximum path length and color the directed graph accordingly. This costs O((k + m)2 m ) time in total. As a special case, undirected graphs with m edges can be colored optimally in O(m · 2 m ) time.

Contributions
We give a structural result that can be viewed as a further extension of the classic GHRV theorem, to mixed graphs with integer arc lengths. In a sense, we compress the directed part of the mixed graph, and this yields an annotated kernel for Mixed Graph Coloring parameterized by m. The result as such is not difficult (and neither is the original GHRV theorem), but it provides some benefits.
As a byproduct we solve Mixed Graph Coloring in O(m 2 · 2 m + mk) time. For the problem parameterized by m (that is, for any fixed m but with arbitrarily large k), this is faster than the brute-force bound O((k + m)2 m ). More important than this slight improvement in the time bound is the structural insight that, informally speaking, the entire difficulty of Mixed Graph Coloring is in the undirected part, and the information needed to eventually find the longest path can be squeezed into O(m 2 ) space. Moreover, the time bound is actually only O(m 2 ) times the number of acyclic orientations to consider, and the factor 2 m is put here only as the worst case. It remains open whether the exponential term 2 m can be improved, but any further work in this direction needs to consider the annotated kernel only.
We also devise a proper kernel of polynomial size, by constructing an equivalent instance with small arc lengths and simply replacing its weighted arcs with paths of unit-length arcs. A quote from Abu- Khzam and Fernau (2006), referring to a different problem, says: "In that particular example, we could produce a reduction rule that gets rid of the annotation . . . So, this gives us an example where a kernel for an annotated version could be used to produce a kernel for the original version of the problem. It would be interesting to see if there are more examples along this venue or if the notion of an annotated kernel should be standing as a notion on its own right." So here is another natural example. Actually we are not aware of uses of annotated kernels since the publication of Abu- Khzam and Fernau (2006).
Moreover we study some special case which turn out to be solvable in polynomial time: if the edges form a clique, with the mild additional assumption that no edge is redundant, we can solve the problem in O(mk) time. Although this is a polynomial bound, we make use of the annotated kernel, as the basis of a greedy algorithm.

Weighted Mixed Graph Coloring
Let G = (V , A ∪ E) be the given mixed graph with acyclic directed part (V , A). We add to V two dummy vertices s and t, called source and sink, respectively, and we add to A the arcs s → v and v → t for all vertices v ∈ V , v = s, t. In the following, G = (V , A ∪ E) refers to this graph extended by a source and a sink.
For formal reasons we must therefore rephrase the Mixed Graph Coloring problem as follows. A coloring assigns to every vertex v a color c(v) from {0, 1, . . . , χ}, such that c(u) = c(v) holds for all edges uv ∈ E, and c(u) < c(v) holds for all arcs u → v ∈ A (as before), and c(s) = 0. The chromatic number χ is now the smallest possible value c(t). Obviously this formulation is equivalent, except that the chromatic number increases by 1.
Any two distinct vertices u and v, real or dummy, are said to be in relationship u ⇒ v if there exists a path from u to v. (Remember that a "path" always means a directed path of arcs from A.) We can interpret the ordered pairs u ⇒ v as another type of arcs. Whenever u ⇒ v, let l(u, v) denote the length of a longest path from u to v in G. If u ⇒ v does not hold, then l(u, v) remains undefined.
We can assume that no two vertices are joined by both an arc and an edge, because the edge is then redundant and may be deleted. Similarly, if two vertices u and v with u ⇒ v are joined by an edge or arc, we may delete this edge or arc as redundant.

Definition 1 Given a mixed graph
-W is the set of all vertices in V being incident to any edges of E, plus the source s and the sink t.
Note that the ⇒ arcs in H do not form cycles.

Lemma 1 The weighted mixed graph H in Definition 1 can be computed from the mixed graph G in O(mk) time.
Proof Since A has k arcs, they can involve at most 2k vertices. First we construct a topological order of (V , A) in O(k) time. Next we take every fixed w and compute l(w, v) for all v ∈ W together. This can be done as follows. By, e.g., breadth-first search we collect all vertices that can be reached from w via arcs in A. Note that these are O(k) vertices. In the graph induced by this vertex set we use the topological order and the standard algorithm for computing longest paths to all vertices, starting in w. Clearly it costs O(k) time, and since we do this for every w in the set W of size O(m), the total running time is O(mk).
Next we extend the concept of coloring to weighted mixed graphs without directed cycles. This concept will be a central tool for our algorithms.
Definition 2 A coloring of a weighted mixed graph H = (W , B ∪ E, l) with source s and sink t is a function c assigning to every vertex w ∈ W a color c(w), such that all colors are nonnegative integers, The Weighted Mixed Graph Coloring problem takes as input a weighted mixed graph H = (W , B ∪ E, l) (i.e., without directed cycles) and asks to find a coloring where c(t) is minimized.
Definition 3 For a fixed coloring c, of either H or G, we denote by O = O c the orientation obtained by the following rule: every edge uv ∈ E with c(u) < c(v) becomes an arc u → v. We also say that coloring c induces the orientation O c . Furthermore, let H O and G O denote the directed graph obtained in this way from H and G, respectively. When the coloring c is understood from context, we omit the subscript c and denote the orientation simply by O. Note that H O remains a weighted graph.
Note also that H O contains two types of arcs: the oriented edges from E and the arcs from B. (We stress that B is unchanged, and still defined by the paths from A only.) We still distinguish the two types of arcs, i.e., the oriented edges from E and the arcs from B, by symbols → and ⇒, respectively.
So every coloring yields an acyclic orientation as specified in Definition 3. Next we also do the converse step: we take any acyclic orientation of our weighted mixed graph and construct a function c that will turn out to be a coloring. , l) and H = (W , B ∪ E, l) be defined as above. Let O be any orientation such that H O remains acyclic. We construct a function c = c O on V (including s, t) as follows: (Similarly as before, when the orientation O is clear from context, we simply write c for c O .) Note that c(v) is well defined for every vertex: H O is acyclic, and since s ⇒ v and s ∈ W , there exists some w ∈ W satisfying w ⇒ v.
The following theorem can be viewed as an extension of the GHRV theorem beyond the mixed-graph case (Hansen et al. 1997) and might therefore be of independent interest.

Proof Consider any arc
. Such a path exists due to Definition 4. If v occured already on P, then this would create a cycle, contradicting the acyclicity of H O . Thus, P extended by the arc from u to v is a path from s to v, of some length larger than c(u). This shows that c(u) < c(v) holds for every arc in H O .
Next consider any arc u → v from A. Let P be any path from any vertex w ∈ W to u, such that P has length l(w, u), and c(u) = c(w) + l(w, u). Such a path P exists: if u ∈ W , then we choose w = u, therefore, trivially c(u) = c(w) + l(w, u) = c(w) + 0 holds true, and P is chosen as the empty path. If u / ∈ W , then P exists due to Definition 4 again, since we can take some w ∈ W with w ⇒ u that maximizes c(w) + l (w, u).
Similarly as above we conclude further: if v occured already on P, then this would create a cycle, contradicting the acyclicity of (V , A). Thus, P extended by u → v is a path from w to v of length l(w, u) + 1. By Definition 4 this shows c(v) ≥ c(w) + l(w, u) + 1 = c(u) + 1. Now we have established c(u) < c(v) also for every arc in A.
Altogether this shows that the condition of a coloring of a directed graph is satisfied on all arcs of G O , that is, c is a coloring of G O . The last two assertions about minimality are seen as follows.
Let c be any other coloring. For every vertex w ∈ W , the length of any path from s to w in H O is a lower bound on c (w) (since the colors on a path form an ascending sequence of integers). Hence c(w) ≤ c (w), that is, all c(w) are minimal colors. Similarly, for every vertex v / ∈ W , every sum c(w) + l(w, v), w ∈ W , w ⇒ v, is a lower bound on c (v). Hence all colors c(v) are minimal, too.

A parameterized algorithm
Now we use these concepts to devise a parameterized algorithm running faster than the simple O((k + m)2 m )-time algorithm if the parameter m is small. We establish a reduction from Mixed Graph Coloring to Weighted Mixed Graph Coloring. Recall that G is acyclic and has a source s and a sink t.

Lemma 2 G admits a coloring where c(t) = χ if and only if H does. Furthermore, the orientation induced by any χ -coloring of G is also induced by some χ -coloring of H , and vice versa.
Proof Let c be any coloring of G with χ as the largest color. Let O c be the induced orientation of G according to Definition 3. Since c is a coloring, this orientation is acyclic. In H = (W , B ∪ E, l) we apply the same orientation to the edges of E. It turns H into a weighted directed graph H which is acyclic as well. In H we define c (w) for each w ∈ W to be the length of a longest path from s to w.
In every directed acyclic graph with a source, this longest-path function is a coloring. In particular, c is a coloring of H , hence a coloring of H .
For every coloring of G we observe that the color of t is at least the length of a longest path from s to t (since the colors on that path form an ascending sequence of integers). Now the definitions of H and c imply that χ = c(t) ≥ c (t). Thus we have found a coloring of H with colors no larger than χ and inducing the same orientation.
Conversely, let c be any coloring of H with χ as the largest color. Let O = O c be the induced orientation of H according to Definition 3. Again, since c is a coloring, H O (from Definition 3) is acyclic. From Theorem 2 we get that c = c O is a coloring of G O , hence a coloring of G.
By the conditions of weighted coloring (in Definition 2) applied to H O , in every coloring of H O , the color of t is at least the length of a longest path from s to t. Since c is a coloring of H O , too, it follows that χ is at least the length of a longest path from s to t.
As t ∈ W , by the construction of c = c O in Definition 4, we have that c(t) equals the length of a longest path from s to t. The last two statements imply c(t) ≤ χ . Thus we have found a coloring of G with colors no larger than χ and inducing the same orientation.

A kernel for Mixed Graph Coloring
The weighted mixed graph H from Definition 1 can be seen as an annotated kernel for Proof Given a mixed graph G = (V , A ∪ E) with soruce and sink, we first ignore E and define an initial coloring c I of (V , A) by letting c I (v) be the length of a longest path from s to v, for all vertices v ∈ V . Due to Theorem 3, there exists some orientation O of E (called O * in Algorithm WMGC) such that c O is a minimal coloring of G. If O were already known, we could construct c O also in an incremental fashion as follows (not caring about efficiency). We start from c I , insert the edges of E one by one, oriented according to O, and update the lengths and colors accordingly. Upon every insertion, the color of each vertex can increase by at most 1. It follows c O (v) ≤ c I (v) + m for each v ∈ V . Deriving this inequality was the only purpose of this procedure.
Consider the coloring c I restricted to W . Suppose that two colors i, j with j − i ≥ m + 2 are assigned to some vertices in W , but no vertex w ∈ W has i < c I [w] < j. We refer to such a pair of colors i, j as a gap.
Consider any gap i, j. We partition W into the sets W s and W t of vertices with colors at most i and at least j, respectively. By the above inequality, the colors in c O are raised by at most m compared to c I . Therefore the difference between the colors of any vertices in W t and W s is still at least 2 also in c O .
Let F be the set of all arcs in H that go from W s to W t . Assume that F contains an arc uv of length 1. Then, a longest path from s to v in H O cannot have uv as its last arc, because this would imply c O (v) = c O (u) + 1, contradicting the difference at least 2. Hence uv cannot appear either on a longest path from s to any other vertex. That is, we can delete the arc uv without changing c O .
Clearly, every path from s to t contains exactly one arc from F. Thus, if we decrease the length of every arc in F by 1, then c O (t) is also decreased by exactly 1. Note that j is then also decreased by 1.
The above reasoning holds for every orientation O, whereas the gaps are solely determined by c I .
These definitions and structural properties lead to the following Mixed Graph Coloring kernelization algorithm, followed by the correctness arguments and time analysis. Some steps in the above analysis are generous, therefore it may be possible to improve the exponents in Theorem 4, but practically this is not too relevant: the main point with Theorem 4 is the mere existence of a proper kernel of polynomial size. For algorithmic purposes it is better to work with the more natural annotated kernel H that was obtained in O(mk) time.

Edges forming a clique
A more rewarding question than optimizing the kernel is whether the O(2 m ) term in Theorem 3 can be improved. We must avoid examining all 2 m orientations of E. For dense graphs this is easy to do: let h := |W | − 2. Since every acyclic orientation gives rise to a topological order, it suffices to consider the h! permutations of W \{s, t}. Note that h! < 2 m for m = (h log h).
The extremal case of a dense undirected graph spanned by E is a single clique of h vertices. For this case it is natural to ask whether the O * (h!) time bound can be further reduced. Below we will give an affirmative answer.
Suppose that E forms the edge set of a clique C, and no edges are redundant (see Sect. 2). That is, for any two vertices, we suppose that uv ∈ E implies that neither u ⇒ v nor v ⇒ u holds. This case is rather easy to solve; the following "moving bars' reformulation of the problem might also appear in similar form in other contexts.

Theorem 5 Mixed Graph Coloring in the case when the edges are not redundant and form a clique can be solved in O(mk) time.
Proof Our weighted mixed graph H from Definition 1 consists of the said clique C, arcs s ⇒ v and v ⇒ t for all v ∈ C, with lengths l(s, v) and l(v, t), respectively, and an edge s ⇒ t of length l(s, t). Note that l(s, t) ≥ max v∈C (l(s, v) + l(v, t)), and strict inequality is possible.
We can work on a horizontal line and think of each path from v ∈ C to t as a horizontal bar of length l(v, t) that has its left end at coordinate l (s, v). (We prefer the name "bar" to "interval", in order to emphasize the analogy of a movable mechanical object.) The problem of computing the chromatic number is then equivalent to moving some bars to the right, such that the left ends of all bars become pairwise distinct integers, and the maximum coordinate of all their right ends is minimized. The chromatic number equals the maximum of these right end coordinates and of the fixed value l(s, t).
Now we can solve this problem by a greedy algorithm: initially let j := min v∈C l (s, v). If more than one bar has its left end at j, then we move all these bars, except one longest one, by 1 unit to the right. We set j := j + 1 and repeat this step until the increasing j has passed all left ends of bars.
The Since the left ends of bars to the left of j are always distinct, clearly this algorithm produces a valid solution. Below we prove its optimality by an exchange argument.
Consider the greedy solution Gr and some optimal solution Opt. Let j now denote the first position where Gr deviates from Opt. That is, bars with left ends i < j are identical in both solutions, Gr has a bar b with left end j, and Opt has either a shorter bar b or no bar with left end j.
In either case, b appears later in Opt, that is, b has its left end at some position i > j in Opt. We can instead place b such that its left end becomes exactly j, and move b (if it exists) such that its left end becomes i. This exchange operation yields another valid solution and does not move the rightmost right end of the bars further to the right. Iteration of these moves transforms Opt into Gr.
We had assumed that E only consists of irredundant edges, and amazingly this is essential: suppose that E still forms the edge set of a clique C but may contain redundant edges, that is, u ⇒ v may hold for some pairs of vertices u, v ∈ C. It is tempting to modify the above algorithm and keep at j some longest bar v, among all v that are not subject to constraints u ⇒ v, where u is any further bar with a left end i ≥ j. However, then the exchange argument breaks down, since b may be involved in precedence constraints, such that moving b forces us to move more bars to the right. Therefore we cannot simply extend Theorem 5 to this case, and it remains open whether it is still solvable in polynomial time.

Jobs of different lengths
The application of Mixed Graph Coloring to scheduling is not restricted to unitlength jobs. Suppose that the jobs have integer durations, time is still divided in unitlength slots, but jobs may be interrupted and resumed, and conflicting jobs cannot share any time slots. In the case of short durations we can afford their unary encoding: every job of length is then modelled by a path of vertices, and arcs for precedence constraints only join the first and last vertices of these paths, in an obvious way. For modelling a conflict between two jobs of lengths and we insert · edges.
However, if interruptions are prohibited, then this transformation does not work. To see this, consider an example with five jobs, each of length 2, whose pairwise conflicts form an undirected cycle (and no precedence constraints prevail). Since the 5-cycle has chromatic number 3, the shortest schedule needs 3 · 2 = 6 slots. However, one can easily schedule these jobs with some interruptions in only 5 slots. (The more general background is that the fractional chromatic number of the 5-cycle is only 2.5.) That is, the minimal coloring cannot be turned into a schedule of the same length without interruptions. We must therefore modify the Mixed Graph Coloring problem itself.
One possible way to do this is to give each vertex a weight (v) and demand to assign (v) consecutive colors to each vertex v such that the constraints of Mixed Graph Coloring are satisfied for all assigned colors. Alternatively we may model the jobs by arcs of lengths (v) (and their start and end points as vertices) and the conflicts as "edges between arcs", i.e., define some hypergraph with hyperedges of size 4. The colors in these hyperedges must then fulfill some obvious inequalities.
One could also have requirements that executions of conflicting jobs must have certain minimum distances on the time axis. This gives rise to a generalized graph coloring problem in edge-weighted graphs, with arbitrary nonnegative real numbers as edge weights and as vertex "colors": the difference (or absolute value of the difference) between the colors of any two adjacent vertices must be at least the weight of the arc (edge) joining them, and the goal is to minimize the maximum color.
Direct generalizations of our results should yield GHRV-type theorems and, based on them, FPT algorithms for such problem versions, too.
We remark that the undirected real-valued coloring problem is NP-hard already for the case of cliques where the edge weights satisfy the triangle inequality: then the maximum color is the sum of weights between the neighbored vertices in the order sorted by colors, hence we can reduce Travelling Salesman to this problem.

Other research directions
We have shown that we can almost get rid of the directed part of the mixed graph, but perhaps the main open question is: can Mixed Graph Coloring be solved faster than in O * (2 m ) time if the undirected edges form a sparse subgraph, or can one prove lower bounds, e.g., under the Exponential Time Hypothesis? We do not have an answer even in simple cases such as a matching.
Mixed Graph Coloring in the special case when the arcs from two disjoint paths can be interpreted as a job shop scheduling problem and be solved in linear time via a shortest path in a certain grid graph (Hardgrave and Nemhauser 1963;Szwarc 1968;Sotskov 1991). We are wondering about generalizations to similar cases.