Special case of coloring a weighted graph - complexity-theory

The problem is: I have a graph G, where each vertex is labelled by some non-negative number (a weight), and I have to find the subset S of non-adjacent vertices (an independent set of G) that maximizes the sum of their labels (let's call it W(S), the weight of the subset S).
It comes to my mind the world of graph coloring, but in this case, the problem is coloring the graph using only two colors, white for choosen verteces, and black otherwise, so that only white verteces must be non-adjacent while their total weight is maximized (or minimized if we make all labels negative).
Has this specific problem a name? The closest thing I have found is cocoloring, but they don't apply to weighted graphs.

Have a look at independent sets (https://en.wikipedia.org/wiki/Independent_set_(graph_theory)). Your particular problem is the maximum weight independent set problem.

Related

Find best path by arbitrary weight function?

How can I find the best path by an arbitrary weight function? That means a function that says how "good" a path is, for example number of edge colors. The function will never score a path "better" than all of its subpaths.
I used the Dijkstra-Algorithm but with the score function instead of the length determining which path will be expanded next, but Im not sure if it is the best solution or if there are cases where the best path will never be found.
The particular problem you're describing - finding a path between two nodes that minimizes the number of colors used - is NP-hard. This means that, assuming P ≠ NP, there is no polynomial-time algorithm for solving this problem, and in particular Dijkstra's algorithm won't work here.
Here's a reduction that shows this, which is based on this excellent answer by Paul Hankin for a related problem. We're going to reduce the hitting set problem to the problem of finding the least-colorful s-t path in a graph. In the hitting set problem, you're given a collection of sets S1, ..., Sn containing a total of m elements and a number k, then asked whether it's possible to pick k elements such that each set Si contains at least one of them.
The reduction works as follows. We're going to build a graph and color the nodes one of m+1 colors. The first color (we'll call it black) is a neutral color with no meaning. The remaining m colors will then correspond to the different elements from the sets.
We'll construct a chain of "gadgets," one per set Si, which correspond to choosing some element from Si. Here's how each gadget works:
Each gadget has a start node si, colored black, and an end node fi, also colored black.
For each element x ∈ Si, we add a new node xi given the color associated with element x. We then add an edge from si to xi and from xi and ti.
Now, imagine walking from si to ti. You have to take two steps to do this, visiting two black nodes (si and ti) and one node of a different color. Walking through that colored node corresponds to selecting xi as one of the elements of your hitting set.
To finish things up, wire up all the gadgets in series by linking f1 to s2, f2 to s3, etc. Now, look at any path from s1 to fn. If you can find a path through the graph that uses at most k+1 colors, one of those colors will be black, and the other k colors correspond to a collection of k elements that collectively contain one element out of each of the sets Si. You've found your hitting set - great! On the flipside, imagine you have a hitting set of size k. Then walk from s1 to fn, making the choice at each point at which you have to pick a colored node corresponding to one of the items from the hitting set. Then you'll use at most k+1 colors: black plus the hitting set colors.
This graph contains 2n nodes for the si and ti nodes, plus one node for each element of each set, with a linear number of edges. It's therefore polynomially-sized with respect to the instance of hitting set, so this is a polynomial-time reduction from hitting set to your problem.
Sorry for the (probably) negative result!

Partially coloring a graph with 1 color

I just started reading graph theory and was reading about graph coloring. This problem popped in my mind:
We have to color our undirected graph(not completely) with only 1 color so that number of colored nodes are maximized. We need to find this maximum number. I was able to formulate an approach for non cyclic graphs :
My approach : First we divide graph into isolated components and do this for each component. We make a dfs tree and make 2 dp arrays while traversing it so that root comes last :
dp[0][u]=sum(dp[1][visited children])
dp[1][u]=sum(dp[0][visited children])
ans=max(dp[1][root],dp[0][root])
dp[0][i] , dp[1][i] are initialized to 0,1 respectively.
Here 0 signifies uncolored and 1 signifies colored.
But this does not work for cyclic graphs as I have assumed that no visited children are connected.
Can someone guide me in the right direction on how to solve this problem for cyclic graphs(not by brute force)? Is it possible to modify my approach or do we need to come up with a different approach? Would a greedy approach like coloring a nodes with least edges work?
This problem is NP-Hard as well, and is known as maximum independent set problem.
A set S<=V is said to be Independent Set in a graph if for each two vertices u,v in S, there is no edge (u,v).
The maximum size of S (which is the number you are seeking) is called the independence number of the graph, and unfortunately finding it is NP-Hard.
So, unless P=NP, your algorithm fails for general purposes graphs.
Proving it is fairly simple, given a graph G=(V,E), create the complementary graph G'=(V,E') where (u,v) is in E' if and only if (u,v) is NOT in E.
Now, given a graph G, there is a clique of size k if and only if there is an independent set of size k in G', using the same vertices (since if (u,v) are two vertices the independent set, there is no edge (u,v) in E', and by definition there is an edge in E. Repeat for all vertices in the independent set, and you got a clique in G).
Since clique problem is NP-Hard, this makes this one such as well.

Seeking a graph algorithm: how to make the graph happy?

Background:
As you can see below, there is an undirected graph on the left of the figure. Vertices are represented by S1,S2 ... S6, and edges are represented by line segments between vertices. Every edge has a weight (the number near the edge), either positive or negative.
Definitions:
In the graph, a simple cycle is called a conflicting cycle if it has an odd number of negative edges, and a concordant cycle if an even (or zero) number of negative edges. On the left of the figure below, for example, the graph has two conflicting cycles(S1-S2-S3-S1 and S2-S3-S4-S2), and other cycles are concordant. A graph is called happy if it has no conflicting cycle.
Objective:
Make the graph happy by removing some edges, meanwhile ensuring the cost(the sum of absolute values of weights of removed edges) is lowest. In the figure below, for example, after removing the edge (red line segment), there is no conflicting cycles. So the graph becomes happy, and the cost is only 2.
This problem is NP-hard by reduction from maximum cut. Given an instance of maximum cut, multiply all of the edge weights by -1. The constraints of this problem dictate that edges be removed so as to eliminate all odd cycles, i.e., we need to find the maximum-weight bipartite subgraph.
This problem in fact is equivalent to a 2-label unique label cover problem. The goal is to color each vertex black or white so as to minimize the sum of costs for (i) positive edges that connect vertices of different colors (ii) negative edges that connect vertices of the same color. Deleting all of these edges is a valid solution to the original problem. Conversely, given a valid set of edges to delete, we can determine a coloring. I expect that there's an approximation algorithm based on semidefinite programming (and the relaxation could be used for branch and bound).
Unless you're familiar with combinatorial optimization, however, the algorithm that I would suggest is integer programming. Let x(e) be 1 if we delete edge e and let x(e) be 0 if we don't.
minimize sum_{edges e} cost(e) x(e)
subject to
for every simple cycle C with an odd number of negative edges,
sum_{edges e in C} x(e) >= 1
for each edge e, x(e) in {0, 1}
The solver will do most of the work. The problem is handling the exponential number of constraints that I've written. The crudest thing to do is to generate all simple cycles and give the solver the whole program. Another possibility is to solve to optimality with a subset of the constraints, test whether the solution is actually valid, and, if not, introduce one or more missing constraints. To do the test, attempt to two-color the undeleted subgraph such that vertices joined by a positive edge have identical colors and vertices joined by a negative edge have different colors. Color greedily; if we get stuck, then there's an odd cycle at fault.
With more sophistication, it's possible to solve the program as written via a technique called column generation.
I've written a solver for this problem (under the name "Signed Graph Balancing"). It is based on a fixed-parameter algorithm that is fast if only few edges need to be deleted. The method is described in the paper "Separator-based data reduction for signed graph balancing".

Introduction to algorithms A creative approach Exercise 5.25

Below is the exercise 5.25 in 《Introduction to algorithms, a creative approach》. After reading it several times, I still can't understand what it means. I can color a tree with 2 colors very easily and directly using the method it described, not 1+LogN colors.
《Begin》
This exercise is related to the wrong algorithm for determining whether a graph is bipartite, described in Section 5.11.In some sense, this exercise shows that not only is the algorithm wrong, but also the simple approach can not work. Consider the more general problem of graph coloring: Given an undirected graph G=(V,E), a valid coloring of G is an assignment of colors to the vertices such that no two adjacent vertices have the same color. The problem is to find a valid coloring, using as few colors as possible. (In general, this is a very difficult problem; it is discussed in Chapter 11.)
Thus, a graph is bipartite if it can be colored with two colors.
A. Prove by induction that trees are always bipartite.
B. We assume that the graph is a tree(which means that the graph is bipartite). We want to find a partition of the vertices into the two subsets such that there are no edges connecting vertices within one subset.
Consider again the wrong algorithm for determining whether a graph is bipartite, given in Section 5.11: We take an arbitrary vertex, remove it, color the rest(by induction), and then color the vertex in the best possible way. That is, we color the vertex with the oldest possible color, and add a new color only if the vertex is connected to vertices of all the old colors. Prove that, if we color one vertex at a time regardless of the global connections, we may need up to 1+logN colors.
You should design a construction that maximizes the number of colors for every order of choosing vertices. The construction can depend on the order in the following way.
The algorithm picks a vertex as a next vertex and starts checking the vertex’s edges. At that point, you are allowed to add edges incident to this vertex as you desire, provided that the graph remains a tree, such that, at the end, the maximal number of colors will be required. You can not remove an edge after it is put in(that would be cleanining the algorithm, which has already seen the edge). The best way to achieve this construction is by induction. Assume that you know a construction that requires<=k colors with few vertices, and build one that requires k+1 colors without adding too many new vertices.
《End》

Maximum Independent Subset of 2D Grid Subgraph

In the general case finding a Maximum Independent Subset of a Graph is NP Hard.
However consider the following subset of graphs:
Create an NxN grid of unit square cells.
Build a graph G by creating a vertex corresponding to every cell. Notice that there are N^2 vertices.
Create an edge between two vertices if their cells share a side. Notice there are 2N(N-1) edges.
A Maximum Independent Subset of G is obviously a checker pattern. A cell at the Rth row and Cth column is part of it if R+C is odd.
Now we create a graph G' by copying G and removing some vertices and edges. (If you remove a vertex also remove all edges it ended of course. Also note you can remove an edge without removing one of the vertices it ends.)
By what algorithm can we find a Maximum Independent Subset of G' ?
Read up here. I think you're still hosed, it remains NP-hard.
Since your degree is at most 4, the simple greedy algorithm obtains an approximation ratio of 2. Your resulting graph is also planar, so there is a good approximation algorithm (any fixed approximation ratio in poly time).

Resources