Directed Graph to DAG - graph

Does anyone have an algorithm for this problem? :
"Suppose we have a directed graph with n vertices and we want to make it acyclic.
How many sets of edges can we pick so that reversing the edges inside any one of those sets will make the graph acyclic?"
I can find the loops inside a graph,but i'm wondering if reversing one of edges of a loop , will produce another loop.

Related

algorithm for 'generalized' matching in complete graphs

My problem is a generalization of a task solved by [Blossom algorithm] by Edmonds. The original task is the following: given a complete graph with weighted undirected edges, find a set of edges such that
1) every vertex of the graph is adjacent to only one edge from this set (i.e. vertices are grouped into pairs)
2) sum over weights of edges in this set is minimal.
Now, I would like to modify the first goal into
1') vertices are grouped into sets of 3 vertices (or in general, d vertices), and leave condition 2) unchanged.
My questions:
Do you know if this 'generalised' problem has a name?
Do you know about an algorithm solving it in number of steps being polynomial of number of vertices (like Blossom algorithm for an original problem)? I don't see a straightforward generalisation of Blossom algorithm, as it is based on looking for augmenting paths on a graph compressed to a bipartite graph (and uses here Hungarian algorithm). But augmenting paths do not seem to point to groups of vertices different than pairs.
Best regards,
Paweł

Trying to reverse a MetaGraph in Julia

I am currently working on Julia with the MetaGraphs.jl package.
I have created the Graph with a dataset, the characteristic of the graph is that there's one start vertex and one end vertex. However the graph is created by creating all possible options so some edges which "take too much time" don't reach the final vertex. In order to have a decent graph for my next step/ an optimization problem.
I am cleaning the graph by simply going through all edges and those who don't reach the end vertex are deleted. But this method is costly in time and I know a wiser way to do it.
The method is simple:
1.reversing the graph (end vertex becomes start vertex)
2.Calculating the distance of all vertices from the start vertex
3.erase the vertices which don't have a defined distance with the start vertex
I have created an example of a small digraph that would be the same type as mine:
module EssaiModule
using LightGraphs, MetaGraphs
g = DiGraph(8)
mg = MetaDiGraph(g, 1.0)
add_vertex!(mg)
add_edge!(mg,1,2)
add_edge!(mg,1,3)
add_edge!(mg,1,4)
add_edge!(mg,2,4)
add_edge!(mg,2,5)
add_edge!(mg,3,5)
add_edge!(mg,5,6)
add_edge!(mg,4,6)
add_edge!(mg,3,7)
add_edge!(mg,4,8)
rg=reverse(mg)
end
the end vertex is number 6 so normally I would like to erase edges 3->7 and 4->8
But I can't even start my function because I simply cannot reverse this graph.
I get the error message "LoadError: type MetaDiGraph has no field badjlist"
I know it's because the graph is a metaGraph and not a lightGraph but shouldn't we be able to reverse a metagraph? it seems like a basic function that could be useful on many occasions while working with graphs.
Thanks for your help!

Finding all maximal transitive closured subgraphs in given graph

I'm trying to solve the following problem:
I have an directed graph G = (E,V) which has a low number of edges. Now I try to find all subgraphs in it which are transitive closured and maximal which means there should be no subgraph which ist part of another subgraph.
The first idea I had was to start at every Node doing a DFS and on every step look if all edges for the closure exists but the performance is horrible. So I wonder if there is any faster algorithm

Coloring a graph using Depth first traversal

I know that for coloring graph nodes, backtracking/brute force is a common solution. But I was wondering if using DFS I can also achieve a solution ?
Backtracking gives you the opportunity to go back and try other color possibility in order to paint all the nodes with N colors
DFS will start from one node and color it, then jump to its neighbor and color it in different color than its neighbors etc ...
I did a search about using this method but I didn't find an algorithm that uses this.
Question: Is using DFS possible for coloring graph nodes. If yes, is it more efficient than backtracking ?
Thank you
I believe there is some confusion when comparing backtracking and DFS wrt vertex coloring. DFS traversal for a graph gives full enumeration of its vertices in a sequence related to its structure. It does not, however, constitute a full enumeration for the vertex coloring problem, which would require taking into account the possible colors of the vertices.
Thus, if I understand correctly, what you have implemented is a greedy heuristic coloring for a graph directed by DFS.
On the other hand, a backtracking/brute force solution as you name it (such as [Randall-Brown 72]) will provide an exact solution for the minimum coloring problem since it considers every possible vertex coloring. Note that DFS traversal could be used to sort the vertices initially (topological sort) and feed that order to the exact solver.

how to find the original directed graph?

I was thinking on a homework question given to me, it is as follows:
If you are given with a BFS and DFS traversal of a directed( or un-directed graph),
how would you find the original graph ?
Is it possible in either case?
thankyou
If I understand it correctly, it is not possible, since BFS and DFS produce a tree, and tree has |V|-1 edges. So, in these two trees you have at most 2|V|-2 different edges, and original graph can have up to |V|(|V|-1) edges for directed, and |V|(|V|-1)/2 for undirected graph.

Resources