Find cycles in force directed graph - d3.js

i want to find cycles in force directed graph. D3JS have method to detect loops in graph (article with method / parameter) . It is possible use this function and visualize loops ? I have graph with arrows (source - taget direction) like is here Graph
Thanks for help!

Related

Transforming Weighted to Unweighted Graph for BFS/DFS

Are there any general or simple algorithms that convert a weighted graph into a non-weighted graph (where each edge has the same weight)?
I know an algorithm called Djikstra's algorithm that works very similar to BFS on a weighted graph when finding the shortest distance between any two vertices in a graph.
But I would like to change the question a little that takes in any weighted graph where each edge is in the set of weights {1,2,3,4,...,n} where each number in the set is a weight of an edge. That way, if every edge is the same weight, I can apply BFS or DFS to it directly.
I want to find a way to modify the graph so that each edge in the modified graph has the same weight (meaning preferably each edge in the modified graph has weight 1). I know that I may have to delete or add edges and add intermediate vertices or delete any vertices to/from the original graph to satisfy this.
Is there a general idea on how to accomplish this? I've never seen a post on StackOverflow that goes over this.
Note: There is nothing about a weighted graph that prevents you from using BFS/DFS.
With that being said you certainly can convert a weighted graph to an unweighted graph by just adding a bunch of intermediate notes. However, I would not recommend that you do this because there are already algorithms like dijkstra's, bellman ford, floyd warshall ... that can compute shortest paths on weighted graphs. Additionally, I would assume that it would be very difficult to represent a weighted graph with negative edges using an unweighted graph.

how to test for bipartite in directed graph

Although we can check a if a graph is bipartite using BFS and DFS (2 coloring ) on any given undirected graph, Same implementation may not work for the directed graph.
So for testing same on directed graph , Am building a new undirected graph G2 using my source graph G1, such that for every edge E[u -> v] am adding an edge [u,v] in G2.
So by applying a 2 coloring BFS I can now find if G2 is bipartite or not.
and same applies for the G1 since these two are structurally same. But this method is costly as am using extra space for graph. Though this will suffice my purpose as of now, I'd like know if there any better implementations for the same.
Thanks In advance.
You can execute the algorithm to find the 2-partition of an undirected graph on a directed graph as well, you just need a little twist. (BTW, in the algorithm below I assume that you will eventually find a 2-coloring. If not, then you will run into a node that is already colored and you find you need to color it to the other color. Then you just exit saying it's not bipartite.)
Start from any node and do the 2-coloring by traversing the edges. If you have traversed every edge and every node in the graph then you have your partition. If not, then you have a component that is 2-colored and there are no edges leaving the component. Pick any node not in the component and repeat. If you get into a situation when you have a few components that are all 2-colored, and there are no edges leaving any of them, and you encounter an edge that originates in a node in the component you are currently building and goes into a node in one of the previous components then you just merge the current component with the older one (and possibly need to flip the color of every node in one of the components -- flip it in the smaller component). After merging just continue. You can do the merge, because at the time of the merge you have scanned only one edge between the two components, so flipping the coloring of one of the components leaves you in a valid state.
The time complexity is still O(max(|N|,|E|)), and all you need is an extra field for every node indicating which component that node is in.

Multiple source shortest path...Embeded plannar graph

The tree on which mssp(multiple source shortest path) can be executed, is stated in many papers that it must be an embeded plannar graph. Does this mean that there can be no edges that overlap each other? If so is possible to change such graph into a plannar graph?
The canonical input to MSSP is a doubly connected edge list or something like it that gives the combinatorial topology of the graph but not the geometry. If you have a straight-line graph that's not planar (i.e., it has edges that cross or overlap), then you need to change the graph somehow. One possibility is to introduce a new vertex everywhere there's an intersection; another is to delete problematic edges.

Data Structures: Wikipedia-like Tree

I am currently in the process of developing an ontology, a web hierarchy of categories of everything (think persons, places, things). The finished product should be something that allows me to navigate from Technology->Computers->Laptops->USB Ports, but also from Movies->Minority Report->Computers->etc.
I need an efficient data structure to group these. I need a tree-like graph, but a special tree that allows child nodes to have multiple parent nodes.
In thinking over this, I have realized that Wikipedia is an imperfect model for this. In fact, they have a hierarchy starting here that is essentially exactly what I need. I see that they used a directed graph, but I am wondering what the differences/drawbacks between this directed graph, a directed acyclic graph, and a polytree are. I have tried researching it, but I don't quite understand the differences. Any help would be greatly appreciated. Thank you!
I think the articles at Wikipedia give a good overview:
A directed graph is a set of nodes connected by edges which have a direction associated with them.
A directed acyclic graph (DAG) is a directed graph with no directed cycles.
A polytree (also called directed tree) is a directed graph with exactly one undirected path between any two vertices. In other words, a polytree is a directed graph whose underlying undirected graph is a tree, or equivalently, a connected directed acyclic graph for which there are no undirected cycles either.
So I think you search for a connected directed acyclic graph. Altough the Wikipedia category system allows cycles, they are unwanted.

Choose Vertex Boost Graph Traversal

I am using boost::graph and the traversal algorithms (BFS / DFS). However, I need to modify the behavior as follows: when at a particular vertex, choose the next adjacent vertex based on some properties of the vertex. I know there are visitor concepts in boost:graph. I could not find a way to use them to determine the next vertex to choose. Any help??
Thanks
It sounds to me as if you are wish to use a heuristic of some kind. Have a look at A-star search:
http://www.boost.org/doc/libs/1_53_0/libs/graph/doc/astar_search.html
http://en.wikipedia.org/wiki/A*_search_algorithm

Resources