Graph Coloring All Solutions - algorithm

I have a problem that is reducible to graph coloring. However, I am interested in obtaining all valid colorings (not just one) for a given number of colors.
Is there a standard known approach that will not only solve the problem, but also find all valid colorings?

Related

Solving The House Drawing Problem With Graph Theory Algorithms

I was recently given the challenge of drawing a house with an x in the middle without lifting my pen, and without retracing any lines. Link to problem
The link above begins to dive into some of the graph theory related to the problem, however there is no mention of how one might go about solving this problem using graph theory algorithms.
What algorithms could be used here, and what would be the correct way to formulate this problem using graph theory language?
Two specific algorithms for constructing an Eulerian path are mentioned in the Wikipedia article on Eulerian paths. These are Fleury's algorithm and Hierholzer's algorithm.
Note that an algorithm that only finds an Euler cycle can also find an Euler trail by augmenting the graph with another edge that joins the 2 vertices that have an odd degree, then rotating the solution so that the added edge is first or last, then removing this edge from the solution found.

Shortest path that traverses all regions

I have a computational problem where, given a set of observations, I want to determine the minimum set of phenomena (explanations) that account for all observations. Phenomena can cause one another, that is all phenomena can be represented as an unweighed directed graph with causal relationships as edges.
I am given the following:
An exhaustive list of all possible observations O_1 ... O_N
An exhaustive list of all possible phenomena (causes/explanations) C_1, ... C_N
For each observation O_N, a list of the phenomena that can cause it
For each phenomenon C_N, a list of the other phenomena that can cause it
The problem is represented below in graph form (sorry for the quality of the picture). Each node is a phenomenon, and each edge represents a causal relationship between phenomena. Edges are unweighted. Each region outlined by a bigger "bubble" represents a possible observation, with all phenomena lying within the bubble being the subset of phenomena that are known to cause that observation.
The problem, restated, is to find the shortest path that crosses all regions in the graph. (For simplicity, assume there is a unique path that explains all observations - no branching, no need for multiple paths).
My questions are as follows:
Is this a known computational problem, or a variant of a known computational problem?
Are there known algorithms for solving this specific problem (beyond just "use existing shortest path" algorithms)?
If not, how should I approach this problem? Specifically, how do I decompose the problem into simpler (i.e. simple shortest path) problems?
If it helps regarding computational feasibility, the number of observations is on the order of 10,000 and the number of possible phenomena on the order of 100,000.
An phenomenon that causes neither observation nor another phenomenon won't appear in any minimal answer, so we can assume there aren't any of them. In other words, pass one of any algorithm is get rid of these "useless" phenomena.
With that assumption, we treat observations just like any other vertex. Since observations cause nothing, all observations are leaf vertices. Since all phenomenon cause something (see step 1), no phenomenon is a leaf vertex. Thus we can simplify the problem statement and simply talk about the leaf vertices of a directed graph.
In general, there's going to be no single path that hits at least one branch vertex of each leaf. Instead, a better way of posing the problem is seek some kind of minimal graph that spans all the leaf vertices, but need not span the phenomena.
This a variation on the Steiner Tree Problem on graphs. It's NP-complete. Most variations are also NP-complete. The best hope you've got is something good enough, that is, an approximation algorithm.
You don't state this assumption explicitly, but it seems like you're assuming that there's no cyclic causation of phenomena (such as A causes B causes C causes A again). In this case your problem is on a directed acyclic graph, but that doesn't help. The directed problem is as hard as the undirected one.
This is a set-cover probem combined with Hamiltonian path problem. Let me explain: Since each phenomena is related to a group of observations, you can look at each phenomena as a set in the set-cover problem. We need to check each group of phenomena which together cover all observations, to see if a Hamiltonian path exists for this group, that is - there is a simple path which includes all the phenomena in the group.
One approach is to find the smallest set cover (=group of phenomena) and check if a Hamiltonian Path exists for this group. Then continue to the next (equal or larger) set cover, and do the same check, and so on until we find a set cover which has a hamiltonian path. This will be the smallest group of phenomena, which cover all observations, and that has a simple path going over all phenomena in the group.

Rearranging a graph so that certain nodes are not adjacent?

EDIT: Precisely, I am trying to find two disjoint independent sets of known size in a graph shaped like a triangular grid, which may have holes and has a variable perimeter shape.
I'm not very well versed in graph theory, so I'm not sure if there exists an efficient solution for this problem. Consider the following graphs:
The colors of any two nodes can be swapped. The goal is to ensure that no two red nodes are adjacent, and no two green nodes are adjacent. The edges marked with exclamation points are invalid. Basically, I need to write two algorithms:
Determine that the nodes in a given graph can be arranged so that red and green nodes are not adjacent to nodes of the same color.
Actually rearrange the nodes.
I'm a little lost on how to implement this. It's not too difficult to separate the nodes of one color, but repeating the process for the second color may mess up the first color. Without a way to determine whether the graph can actually be arranged properly, this process could loop forever.
Is there some kind of algorithm that I can use/write for this? I'm mainly interested in the first image's graph (a triangular grid), but a generic algorithm would work as well.
First, let's note that the problem is a variant of graph coloring.
Now, if you only dealing with 2 colors (red,green) - coloring a graph with 2 colors is fairly easy, and is basically done by finding out if the graph is bipartite, and coloring each "side" of the graph in one color. Finding if a graph is bipartite is fairly simple.
However, if you want more than two colors, the problem becomes NP-Complete, and is actually a variant of the Graph Coloring Problem.
Graph Coloring Problem:
Given a graph G=(V,E) and a number k determine if there is a
function c:V->{1,2.,,,.k} such that c(v) = v(u) -> (v,u) is not an
edge.
Informally, you can color the graph in k colors, and you need to determine if there is some coloring such that you never color 2 nodes that share an edge with the same color.
Note that while it seems your problem is slightly easier, since you already know what is the number of nodes in each color, it doesn't really make a difference.
Assume you have a polynomial time algorithm A that solves your problem.
Now, given an instance (G,k) of graph coloring - there are only O(n^3) possibilities to #color1,#color2,#color3 - so by examining each of these and invoking A on it, you can find a polynomial time solution to Graph-Coloring. This will mean P=NP, which is most likely (according to most CS researchers) not the case.
tl;dr:
For 2 colors: find out if the graph is bipartite - and give one color to each side of the graph.
For 3 or more colors: There is no known efficient solution, and the general belief is one does not exist.
I thought this problem would be easier for planar graph, but unfortunately it's not the case. Best match for this problem I was able to find is minimum sum coloring and largest bipartite subgraph.
For largest bipartite subgraph, assume that number of reds + number of greens exactly match the size of largest bipartite subgraph. Then this problem is equivalent to your. Paper claims that it's still NP-hard even for planar graphs.
For minimum sum coloring, assume that red color has weight 1, green color has color 2, and we have infinitely many blue* colors with some weight of >graph size. Then if answer is exactly minimal sum coloring, there is no polynomial algorithm to find it (although paper referes to such algorithm for chordal graphs).
Anyway, it seems that the closer your red+green count to the 'optimal' in some sense subgraph, the more difficult problem is.
If you can afford inexact solution, or relaxed solution then you only spearate, say, reds, you have an option. As I said in comment, approximate solution of maximum independent set problem for planar graph. Then color this set into red and blue colors, if it is large enough.
If you know that red+green is much less than total number of vertices, another approximation can work. Look at introduction chapter of this article. It claims that:
For graphs which are promised to have small chromatic number, a better
guarantee is known: given a k-colorable graph, an algorithm due to
Karger et al. [12] uses semidefinite programming (SDP) to find an
independent set of size about Ω(n/∆^(1−2/k)).
Your graph is for sure 4-colorable, so you can count on large enough independent set. The same article states that greedy solution already can find large enough independent set.

Suurballe's algorithm for k-best

I'm interesting in adapting Suurballe's algorithm to find the best K paths from a source to destination instead of just the two best. I think people do it all the time but I've been searching for hours and can't find a paper that explains it clearly. There's a reference to a paper on the Suurballe's wikipedia page that talks about it, but it gives no detail on the extension past the first two (how the graph is modified and results merged, etc.). Incidentally, I'm actually working on the vertex-disjoint problem, not the edge disjoint problem spelled out on wikipedia.
My concise question: How do you extend Suurballe's algorithm beyond two paths?
In the literature this is called the successive shortest paths problem, and it works in essentially the same way, just repeated. You modify each discovered path's weights in the same way as you modified the first.
The Suurballe algorithm is for finding the two edge-disjoint paths with minimum total length. The Suurballe algorithm can't be extended to more then two edges.
The k-shortest path problem is a different problem. Here the shortest paths are

Greedy algorithm for the following

I am trying to solve the following problem using Greedy Algorithm,
We have n friends and we want to give a present to each one of them. But we don't want to give the same present to two person who know each other. (if x knows y, then y knows x). People who do not know each other may take the same gift, it is okay. We want to minimize the number of distinct gifts given.
Here is what I thought, We try to make pairs of people who do not know each other, and give them all the same gift. But I am not sure whether this is a greedy algorithm. Also, we may want to find maximum group of people in which no one knows any other, so we can give hem the same gift. But can we do this? Can we find the maximum group of people who do not know each other?
Can anyone propose a greedy algorithm for the problem?
The problem you have mentioned is a restatement of Graph Coloring problem. You have to label the graph’s vertices with colors such that no two vertices sharing the same edge have the same color. The link given below is to the Greedy Coloring Algorithm.
http://en.wikipedia.org/wiki/Greedy_coloring
This is graph coloring problem, and greedy algorithm for it is straightforward:
a greedy coloring is a coloring of the vertices of a graph formed by
a greedy algorithm that considers the vertices of the graph in sequence
and assigns each vertex its first available color

Resources