I've been reading some papers on multicut algorithms for segmenting graph structures. I'm specifically interested in this work which proposes an algorithm to solve an extension of the multicut problem:
https://www.cv-foundation.org/openaccess/content_iccv_2015/papers/Keuper_Efficient_Decomposition_of_ICCV_2015_paper.pdf
Regarding the edge costs, it says:
...for any pair
of nodes, a real-valued cost (reward) to all decompositions
for which these nodes are in distinct components
Fair enough. It further says that the solution to the multicut problem is a simple binary vector of length equal to the number of edges in the graph, in which a '1' indicates that the corresponding edge separates two vertices belonging to distinct graph components:
for every edge vw ∈ E ∪ F , y(v,w) = 1 if and only if v and w
are in distinct components of G.
But then the optimization problem is written as:
This doesn't seem to make sense. If the edge weights depict rewards for that edge connecting nodes in distinct components, shouldn't this be a maximization problem? And in either case, if all edge weights are positive, wouldn't that lead to a trivial solution where y is an all-zeros vector? The above expression is followed by some constraints in the paper, but I couldn't figure out how any of those prevent this outcome.
Furthermore, when it later tries to generate an initial solution using Greedy Additive Edge Contraction, it says:
Alg. 1 starts from the decomposition into
single nodes. In every iteration, a pair of neighboring components is joined for which the join decreases the objective
value maximally. If no join strictly decreases the objective
value, the algorithm terminates.
Again, if edge weights are rewards for keeping nodes separate, wouldn't joining any two nodes reduce the reward? And even if I assume for a second that edge weights are penalties for keeping nodes separate, wouldn't this method simply lump all the nodes into a single component?
The only way I see where this would work is if the edge weights are a balanced combination of positive and negative values, but I'm pretty sure I'm missing something because this constraint isn't mentioned anywhere in literature.
Just citing this multicut lecture
Minimum Multicut. The input consists of a weighted, undirected graph G
= (V,E) with a non-negative weight c_k for every edge in E, and a set of terminal pairs {(s1,t1);(s2,t2)...(sk,tk)}. A multicut is a set of
edges whose removal disconnects each of the terminal pairs.
I think from this definition it is clear that the multicut problem is a minimization problem for the accumulated weight which is defined by the selection of edges to cut. Maximizing the weight would of course be trivial (removing all edges). No?
Better late than never, here's the answer:
The weights c_e for cutting the edge e are not restricted to be positive as defined in Definition 1. In fact, Equation (7) specifies that they are log-ratios of two complementary probabilities. That means if the estimated probability for edge e being cut is greater than 0.5, then c_e will be negative. If it's smaller, then c_e will be positive.
While the trivial "all edges cut" solution is still feasible, it is quite unlikely that it is also optimal in any "non-toy" instance where you will have edges that are more likely to be cut while others are more likely to remain.
Related
I have a weighted graph, and I want to compute a new weighting function for the graph, such that the edge weights are distinct, and every MST in the new graph corresponds to an MST in the old graph.
I can't find a feasible algorithm. I doubled all the weights, but that won't make them distinct. I also tried doubling the weights and adding different constants to edges with the same weights, but that doesn't feel right, either.
The new graph will have only 1 MST, since all edges are distinct.
Very simple: we multiply all weights by a factor K large enough to ensure that our small changes cannot affect the validity of an MST. I'll go overboard on this one:
K = max(<sum of all graph weights>,
<quantity of edges>)
+ 1
Number the N edges in any order, 0 through N-1. To each edge weight, add the edge number. It's trivial to show that
the edge weights are now unique (new difference between different weights is larger than the changes);
any MST in the new graph maps directly to a corresponding MST in the
old one (each new path sum is K times the old one, plus a quantity smaller than K -- the comparison (less or greater than) on any two paths cannot be affected).
Yes, this is overkill: you can restrict the value of K quite a bit. However, making it that large reduces the correctness proofs to lemmas a junior-high algebra student can follow.
We definitely cannot guarantee that all of the MSTs in the old graph are MSTs in the new graph; a counterexample is the complete graph on three vertices where all edges have equal weights. So I assume that you do not require the construction to give all MSTs, as that is not possible in the general case.
Can we always make it so that the new graph's MSTs are a subset of the old graph's? This would be easy if we could construct a graph without a MST. Of course, that doesn't make any sense and is impossible, since all graphs have at least one MST. Is it possible to change edge weights so that only one of the old graph's MSTs is an MST for the new graph? I propose that this is possible in general.
Determine some MST of the old graph.
Construct a new graph with the same edges and vertices, but with weights assigned as follows:
if the edge in the new graph belongs to the MST determined in step 1, give it a unique weight between 1 and n, the number of edges in the graph.
otherwise, give the edge in the new graph a unique weight greater than or equal to n^2, the square of the number of edges in the graph.
Without proof, it seems like this should guarantee that only the nominated MST from the old graph is an MST of the new graph, and therefore every MST in the new graph (there is just the one) is an MST in the old graph.
Now, one could ask whether we can do the deed with additional restrictions:
Can you do it if you only want to change the values of edges that are not unique in the old graph?
Can you do it if you want to keep relative weights the same for edges which were unique in the old graph?
One could even pose optimization problems:
What is the minimum number of edge weights that must be changed to guarantee it?
What is the weighting with minimum distance (according to some metric) from the old weighting that guarantees it?
What is the weighting that minimizes the average change while also guaranteeing it?
I am hesitant to attempt these, what I believe to be much more difficult, problems.
My question is similar to an existing one: https://math.stackexchange.com/questions/1691013/how-does-one-join-two-graphs-in-graph-theory
But I'm specifically wondering what would be the new edge's costs, if the two graphs already have some traversal cost associated to them?
Specification: Construct a directed graph where the nodes are labeled. The edges of the graph are labeled with a traversal cost. They also obey the usual triangle inequality. That is, in a triangle such as the triangle inequality x + y ≥ z where x, y, and z are the costs associated with traversing these edges. The costs are real numbers may not exceed some specified cost interval. At a minimum, your library should be able to add edges to a graph, join two graphs that operate on the same cost interval and disjoint sets of nodes, and compute whether there is a path from one node to another and, if so, its cost.
I understood all the other requirements of the specification except for joining two graphs where the edges have traversal costs.
My understanding: While joining the two graphs, I should still maintain the triangle equality but the new edge cost will be a value in this range: [min cost that satisfies triangle in equality, cost interval].
I'm doing this project as for my practice and got the specification from an internet source.
Comment if you like to know any more information.
I'd like to solve a harder version of the minimum spanning tree problem.
There are N vertices. Also there are 2M edges numbered by 1, 2, .., 2M. The graph is connected, undirected, and weighted. I'd like to choose some edges to make the graph still connected and make the total cost as small as possible. There is one restriction: an edge numbered by 2k and an edge numbered by 2k-1 are tied, so both should be chosen or both should not be chosen. So, if I want to choose edge 3, I must choose edge 4 too.
So, what is the minimum total cost to make the graph connected?
My thoughts:
Let's call two edges 2k and 2k+1 a edge set.
Let's call an edge valid if it merges two different components.
Let's call an edge set good if both of the edges are valid.
First add exactly m edge sets which are good in increasing order of cost. Then iterate all the edge sets in increasing order of cost, and add the set if at least one edge is valid. m should be iterated from 0 to M.
Run an kruskal algorithm with some variation: The cost of an edge e varies.
If an edge set which contains e is good, the cost is: (the cost of the edge set) / 2.
Otherwise, the cost is: (the cost of the edge set).
I cannot prove whether kruskal algorithm is correct even if the cost changes.
Sorry for the poor English, but I'd like to solve this problem. Is it NP-hard or something, or is there a good solution? :D Thanks to you in advance!
As I speculated earlier, this problem is NP-hard. I'm not sure about inapproximability; there's a very simple 2-approximation (split each pair in half, retaining the whole cost for both halves, and run your favorite vanilla MST algorithm).
Given an algorithm for this problem, we can solve the NP-hard Hamilton cycle problem as follows.
Let G = (V, E) be the instance of Hamilton cycle. Clone all of the other vertices, denoting the clone of vi by vi'. We duplicate each edge e = {vi, vj} (making a multigraph; we can do this reduction with simple graphs at the cost of clarity), and, letting v0 be an arbitrary original vertex, we pair one copy with {v0, vi'} and the other with {v0, vj'}.
No MST can use fewer than n pairs, one to connect each cloned vertex to v0. The interesting thing is that the other halves of the pairs of a candidate with n pairs like this can be interpreted as an oriented subgraph of G where each vertex has out-degree 1 (use the index in the cloned bit as the tail). This graph connects the original vertices if and only if it's a Hamilton cycle on them.
There are various ways to apply integer programming. Here's a simple one and a more complicated one. First we formulate a binary variable x_i for each i that is 1 if edge pair 2i-1, 2i is chosen. The problem template looks like
minimize sum_i w_i x_i (drop the w_i if the problem is unweighted)
subject to
<connectivity>
for all i, x_i in {0, 1}.
Of course I have left out the interesting constraints :). One way to enforce connectivity is to solve this formulation with no constraints at first, then examine the solution. If it's connected, then great -- we're done. Otherwise, find a set of vertices S such that there are no edges between S and its complement, and add a constraint
sum_{i such that x_i connects S with its complement} x_i >= 1
and repeat.
Another way is to generate constraints like this inside of the solver working on the linear relaxation of the integer program. Usually MIP libraries have a feature that allows this. The fractional problem has fractional connectivity, however, which means finding min cuts to check feasibility. I would expect this approach to be faster, but I must apologize as I don't have the energy to describe it detail.
I'm not sure if it's the best solution, but my first approach would be a search using backtracking:
Of all edge pairs, mark those that could be removed without disconnecting the graph.
Remove one of these sets and find the optimal solution for the remaining graph.
Put the pair back and remove the next one instead, find the best solution for that.
This works, but is slow and unelegant. It might be possible to rescue this approach though with a few adjustments that avoid unnecessary branches.
Firstly, the edge pairs that could still be removed is a set that only shrinks when going deeper. So, in the next recursion, you only need to check for those in the previous set of possibly removable edge pairs. Also, since the order in which you remove the edge pairs doesn't matter, you shouldn't consider any edge pairs that were already considered before.
Then, checking if two nodes are connected is expensive. If you cache the alternative route for an edge, you can check relatively quick whether that route still exists. If it doesn't, you have to run the expensive check, because even though that one route ceased to exist, there might still be others.
Then, some more pruning of the tree: Your set of removable edge pairs gives a lower bound to the weight that the optimal solution has. Further, any existing solution gives an upper bound to the optimal solution. If a set of removable edges doesn't even have a chance to find a better solution than the best one you had before, you can stop there and backtrack.
Lastly, be greedy. Using a regular greedy algorithm will not give you an optimal solution, but it will quickly raise the bar for any solution, making pruning more effective. Therefore, attempt to remove the edge pairs in the order of their weight loss.
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".
I have this question from Robert Sedgewick's book on algorithms.
Critical edges. An MST edge whose deletion from the graph would cause the
MST weight to increase is called a critical edge. Show how to find all critical edges in a
graph in time proportional to E log E. Note: This question assumes that edge weights
are not necessarily distinct (otherwise all edges in the MST are critical).
Please suggest an algorithm that solves this problem.
One approach I can think of does the job in time E.V.
My approach is to run the kruskal's algorithm.
But whenever we encounter an edge whose insertion in the MST creates a cycle and if that
cycle already contains an edge with the same edge weight, then, the edge already inserted will not be a critical edge (otherwise all other MST edges are critical edges).
Is this algorithm correct? How can I extend this algorithm to do the job in time E log E.
The condition you suggest for when an edge is critical is correct I think. But it's not necessary to actually find a cycle and test each of its edges.
The Kruskal algorithm adds edges in increasing weight order, so the sequence of edge additions can be broken into blocks of equal-weight edge additions. Within each equal-weight block, if there is more than one edge that joins the same two components, then all of these edges are non-critical, because any one of the other edges could be chosen instead. (I say they are all non-critical because we are not actually given a specific MST as part of the input -- if we were then this would identify a particular edge to call non-critical. The edge that Kruskal actually chooses is just an artefact of initial edge ordering or how sorting was implemented.)
But this is not quite sufficient: it might be that after adding all edges of weight 4 or less to the MST, we find that there are 3 weight-5 edges, connecting component pairs (1, 2), (2, 3) and (1, 3). Although no component pair is joined by more than 1 of these 3 edges, we only need (any) 2 of them -- using all 3 would create a cycle.
For each equal-weight block, having weight say w, what we actually need to do is (conceptually) create a new graph in which each component of the MST so far (i.e. using edges having weight < w) is a vertex, and there is an edge between 2 vertices whenever there is a weight-w edge between these components. (This may result in multi-edges.) We then run DFS on each component of this graph to find any cycles, and mark every edge belonging to such a cycle as non-critical. DFS takes O(nEdges) time, so the sum of the DFS times for each block (whose sizes sum to E) will be O(E).
Note that Kruskal's algorithm takes time O(Elog E), not O(E) as you seem to imply -- although people like Bernard Chazelle have gotten close to linear-time MST construction, TTBOMK no one has got there yet! :)
Yes, your algorithm is correct. We can prove that by comparing the execution of Kruskal's algorithm to a similar execution where the cost of some MST edge e is changed to infinity. Until the first execution considers e, both executions are identical. After e, the first execution has one fewer connected component than the second. This condition persists until an edge e' is considered that, in the second execution, joins the components that e would have. Since edge e is the only difference between the forests constructed so far, it must belong to the cycle created by e'. After e', the executions make identical decisions, and the difference in the forests is that the first execution has e, and the second, e'.
One way to implement this algorithm is using a dynamic tree, a data structure that represents a labelled forest. One configuration of this ADT supports the following methods in logarithmic time.
MakeVertex() - constructs and returns a fresh vertex.
Link(u, c, v) - vertices u and v must not be connected. Creates an unmarked edge from vertex u to vertex v with cost c.
Mark(u, v) - vertices u and v must be endpoints of an edge e. Marks e.
Connected(u, v) - indicates whether vertices u and v are connected.
FindMax(u, v) - vertices u and v must be connected. Returns the endpoints of an unmarked edge on the unique path from u to v with maximum cost, together with that cost. The endpoints of this edge are given in the order that they appear on the path.
I make no claim that this is a good algorithm in practice. Dynamic trees, like Swiss Army knives, are versatile but complicated and often not the best tool for the job. I encourage you to think about how to take advantage of the fact that we can wait until all of the edges are processed to figure out what the critical edges are.