Imagine a bidirectional meshed network graph with multiple sinks and multiple sources.
Let's say nodes 6 and 20 are sources and nodes 4, 11, 12 and 21 are sinks in this example.
Now imagine some sort of fluid passing through this network from sources to sinks.
Is there an algorithm to find the flow direction for any given link between two nodes?
This problem can be described as a multi-commodity flow problem, like #Luka mentioned.
In multi-commodity flow problems one or more commodities need to be distributed from sources to sinks in the network. Unlike many other graph algorithms, multiple sinks and sources are allowed. The multi-commodity flow problem can be solved using linear optimization. Gurobi has a great example script implemented in Python.
If you need it to work with bi-directional edges in your graph, just include both directions when initializing the edges, capacities and costs. Otherwise this example works great for the use case from the question.
For people that do not have / cannot get a Gurobi license (academic is free for a year), check out this repo instead.
Related
I want to learn more about graph and node algorithms and how to improve the health of the graph. The graph I am thinking about would be something akin to a hub and spoke layout. The improvements I'd like to make would be:
Segment the graph into clusters and find clusters that are not well connected to each other, than improve this by making various connections between the clusters
Find desirable endpoints to the graph (hubs that send/receive a lot of traffic) and create more efficient routes between them and other hubs, and/or them and clusters of spokes/nodes that are many hops away from them
Evaluate the “centrality” of a node
What are some methods for evaluating the best connections I can make from a node I control to improve the overall connectivity of this (loosely defined) graph?
Any information about graphs, algorithms, or distributed computing that might be useful is welcome (for example I understand Dijkstra's algo for finding the shortest path). I'm happy to add more detail, not trying to be obscure, I'm just in a don't know what I don't know state.
Thanks!
It all depends on what you mean by improving the overall connectivity of a graph.
For example:
The graph might have two or more disconnected parts. The connectivity will be improved if your node has a connection to one node in each disconnected part.
You might want to measure the longest path. Then your node should have connections to the start and end nodes, reducing the longest path to 2 hops.
... The possibilities are endless, unless you clarify what you mean.
Am doing some research on traffic flow and such , am having some troubles in representing a two way road on the network ... first though was to use directed graphs and this means I'll be having two directed edges between two nodes , I want to know if this is a good representation and if graph analysis(centrality,betweenness etc...) would apply to such graph
Virtually all researchers concentrate on directed and undirected graphs, and not on the more general model - mixed graph. This is since directed graph can theoretically represent mixed graphs by adding any bi-directed (or non-directed, depending on your semantics) relationship as two directed edges.
However, this attitude is far from optimal for some applications, where the mixed model is much more practical, such as street networks (e.g. supporting both one-way and two-way streets), M*3 networks (e.g. multi-relational social networks), and many other use cases.
Nothing stops one for developing algorithms, metrics (e.g. centrality metrics), libraries, etc. that support mixed graphs directly. Nevertheless, mixed graphs never gained popularity. Take for example the most popular C++ graph libraries - The Boost Graph Library, LEMON Graph Library, STINGER, MTGL and igraph - none of these support mixed graphs natively. Even most graph databases don't support mixed graphs, but there are exceptions - Sparsity DEX for example.
In most cases, if you're looking for some metrics or algorithms - you'll have to implement from scratch - due to the lack of both theory and practical implementations. I hope we'll see some change in the near future.
Representation
Consider representing a road network with a directed graph in the following way.
Road segments are nodes in your graph.
If a road segment is 2-way, there are 2 nodes for each direction.
If a road segment is 1-way, there is only 1 node.
There is an edge from road segment A to road segment B if and only if:
The end of A is the start of B.
Proceeding from A to B makes sense physically.
This let's you model things such as intersections where a left turn is not allowed, or the inability at a T junction to make a U-turn.
Example
Consider the following example. Here there are 5 road segments shown and 1 intersection. Coming from below is a 1-way street, and only right turns are allowed at the end. Drivers drive on the right side of the roadway.
The blue dots are the 5 nodes in the directed graph - one for each road segment. The orange arrows are the 3 possible transitions from road segment to road segment that are permissible.
Road networks can be represented as a graph. One could see a map as a graph where the nodes are places which can be visited (towns, buildings, etc) and the edges are roads.
That being said, the effectiveness of your approach would depend on what type of information you include in your graph, for instance, an edge between nodes N1 and N2 would mean that there is a path between N1 and N2, however, that information on its own does not provide any insight on how much heavy traffic does the particular street see.
To go round this problem, you could use weighted directed graphs, in which you could use the weights of the edges to determine the traffic on the roads and thus being able to yield a more complete analysis.
Is there an algorithm that, when given a graph, computes the vertex connectivity of that graph (the minimum number of vertices to remove in order to separate the graph into two connected graphs). (Note that the graph may be already be disconnected). Thanks!
See:
Determining if a graph is K-vertex-connected
k-vertex connectivity of a graph
When you combine this with binary search you are done.
This book chapter should have everything you need to get started; it is basically a survey over algorithms to determine the edge connectivity and vertex connectivity of graphs, with pseudo code for the algorithms described in it. Page 12 has an overview over the available algorithms alongside complexity analyses and references. Most of the solutions for the general case are flow-based, with the exception of one randomized algorithm. The different general solutions optimize for different properties of the graph, so you can choose the most asymptotically efficient one beforehand. Also, for some classes of graphs, there exist specialized algorithms with better complexity than the general solutions provide.
In the context of social networks, what is a good measure of strength of a link between two nodes? I am currently thinking that the following should give me what I want:
For two nodes A and B:
Strength(A,B) = (neighbors(A) intersection neighbors(B))/neighbors(A)
where neighbors(X) gives the total number of nodes directly connected to X and the intersection operation above gives the number of nodes that are connected to both A and B.
Of course, Strength(A,B) != Strength(B,A).
Now knowing this, is there a good way to determine the influence of a node? I was initially using the Degree Centrality of a node to determine its "influence" but I somehow think its not a good idea because just because a node has a lot of outgoing links does not mean anything. Those links should be powerful as well. In that case, maybe using an aggregate of the strengths of each node connected to this node is a good idea to estimate its influence? Am I in the right direction? Does anyone have any suggestions?
My Philosophy (and understanding of the terms):
Strength indicates how far A is
willing to do what B has already done
Influence indicates how far A can make B do something (persuasion perhaps?)
Constraints:
Access to only a subgraph. I mean, I am trying to be realistic here because social networks are huge and having a complete view is not so practical.
you might want to check out some more sophisticated notions of distance.
A really cool one is "resistance distance", which lets you view distance as how likely a random path from one node will lead you to another
there are several days of lecture notes plus references to further reading at http://www.cs.yale.edu/homes/spielman/462/.
Few thoughts on this:
When you talk about influence of a node in a graph one centrality measurement that comes to mind it closeness centrality. Closeness centrality looks at the number of shortest paths in a graph the node is on. From an influence point of view, the node that is on the most shortest paths is the node that can share information the easiest, ie its nearer to more nodes than any other.
You also mention using the strengths of each node connected to a node. Maybe you should look at eigenvector centrality which ranks a node highly if its connected to other high degree nodes. This is an undirected version of PageRank.
Some questions that might affect you choice here are:
Is you graph directed?
Do you edges have weight? You mention strength... do you mean weights of some kind?
If you do have weights maybe the next step from a simple degree centrality would be to try a weighted degree centrality approach. Thus, just having a high number of connections doesn't automatically make you the most influential.
I am given a network defined by nodes and links. I have to search all loops in the network. No coordinates will be given for the nodes.
Is there any existing algorithm or library that can do this. Or can you please give me some idea how I can approach this problem? I am programming in .NET.
I draw a diagram to illustrate what I need here
Try Distance vector Routing.
This algorithm finds the shortest path to all other nodes in a network from a node.
On the assumption that your edges are not directed and that there is a maximum of one edge between nodes then a http://en.wikipedia.org/wiki/Spanning_tree Depth-first spanning tree will cover all nodes and indicate where the cycles (which is what I think you mean by loops) will occur. We use this algorithm for finding "rings" in chemical structures. There are many implementations in many languages - here's a tutorial with an applet (http://oneweb.utc.edu/~Christopher-Mawata/petersen2/lesson20.htm)
The loops are called cycles, and this answer has a lot of informations for you.