I have just been working on chapters of questions from the DPV textbook for my exam preparation. For one of them, I'm having some trouble but I have made some progress:
My solution:
I will be using linear programming to maximize x where
SUM {flow_i(s_i, v) for all i where v are nodes connecting to source s_i} >= x * d_i
subject to the constraints
for each edge e , f1+..fk <= c_e
for each edge e, flow_e >= 0
and some more constraints that I'm unsure of
I think I'm on the right track but I need some help getting a bit further. Should I be considering trying to use a super-node to reduce this to a regular max flow problem?
Any help would be great! Thank you.
Yes, one typical approach to multi-source, multi-sink commodity flow problems is to introduce a super-source and one super-sink. Then connect all the sources s1...sk to the super-source. Connect each sink t1,...tk to the super-sink.
Important: Give a very large capacity to all the edges leaving or entering any of the super-nodes.
Objective: Maximize the total throughoput. (Sum of flows over all edges leaving the sources 1..k)
Constraints:
Edge Capacity Constraints:
You already got this right.
for each edge e , f1+..fk <= c_e
*Flow Conservation (Flow-in == Flow_out):*
for each vertex v, sum of flow into v = sum of flow leaving v
Demand Satisfaction:
for each sink t_i, sum of flow into t_i (all edges ending in t_i) >= demand_i
Non-zero flows, which you already have.
Here's one accessible lecture handout that references your specific problem. Specifically, take a look at Example 2 in the handout.
Related
can any one help me to analysis this algorithm in details
Check the following link:
https://www.geeksforgeeks.org/collect-maximum-coins-before-hitting-a-dead-end/
there is two solutions for this problem the first one is exponential i think without DP, but the other one is O(R.C) with Dynamic programming and memoization.
Where R is the number for rows for the 2D-Array & C the number of columns.
I need to know how i can mathematically find this time complexity O(R.C) in details.
DP solution fills RxCx2 table dpand every cell of dp might be visited not more that five times - initial fill, calculation for this cell, and request from three directions (up, left, right).
So overall complexity is O(R * C)
So I found a problem where a traveller can travel a certain distance in a graph and all bidirectional edges have some length(distance). Suppose when travelling a certain edge(either direction) you get some money/gift (it's given in question for all edges)so you have to find the max money you can collect for the given distance you can travel. Basic problem is how do I find all possible paths with given distance (there might be loops in graph) and after finding all possible paths, path with max money collected will simply be the answer. Note: any possible paths you come up with should not have a loop (straight path).
You are given an undirected connected graph with double weight on the edges (distance and reward).
You are given a fixed number d corresponding to a possible distance.
For each couple of nodes (u,v), u not equal to v, you are looking for
All the paths {P_j} connecting u and v with no repeating nodes whose total distance is d.
The paths {P_hat(j)} subset of {P_j} whose reward is maximal.
To get the first, I would try to use a modified version of the Floyd-Warshall algorithm, where you do not look for the shortest, but for any path.
Floyd-Warshall uses a strategy based on considering a "middle node" w between u and v and recursively finds the path minimising the distance between u and v.
You can do the same, while taking all path instead of excluding the minimisation, taking care of putting to inf the nodes where you have already b visited in the distance matrix and excluding at runtime every partial path in the recursion whose distance is longer than d or that arrives to an end (they connects u and v) and whose distance is shorter than d.
Can be generalised if an interval of possible distances [d, D] is given, instead of a single value d, as in this second case you would probably get the empty set all the time.
For the second step, you simply compare the reward of each of the path found in solving the first step, and you take the best one.
Is more a suggested direction rather than a complete answer, but I hope it helps!
I have a typical friend of friend graph database i.e. a social network database. The requirement is to extract all the nodes as a list in such a way that the least connected nodes appear together in the list and the most connected nodes are placed further apart in the list.
Basically its asking a graph to be represented as a list and I'm not sure if we can really do that. For e.g. if A is related to B with strength 10, B is related to C with strength 80, A to C is 20
then how to place this in a list ?
A, B, C - no because then A is distant from C relatively more than B which is not the case
A, C, B - yes because A and B are less related that A,C and C,B.
With 3 nodes its very simple but with lot of nodes - is it possible to put them in a list based on relationship strength ?
Ok, I think this is maybe what you want. An inverse of the shortestPath traversal with weights. If not, tell me how the output should be.
http://console.neo4j.org/r/n8npue
MATCH p=(n)-[*]-(m) // search all paths
WHERE n <> m
AND ALL (x IN nodes(p) WHERE length([x2 IN nodes(p) WHERE x2=x])=1) // this filters simple paths
RETURN [n IN nodes(p)| n.name] AS names, // get the names out
reduce(acc=0, r IN relationships(p)| acc + r.Strength) AS totalStrength // calculate total strength produced by following this path
ORDER BY length(p) DESC , totalStrength ASC // get the max length (hopefully a full traversal), and the minimum strength
LIMIT 1
This is not going to be efficient for a large graph, but I think it's definitely doable--probably needs using the traversal/graphalgo API shortest path functionality if you need speed on a large graph.
Respected Sir,
I am working with a specific graphical structure representing 2-player normal form games (game theory). I know that I can compute all strongly connected components of the directed graph in O(V+E) via Tarjans, but was wondering what the complexity of computing all of the simple cycles of a strongly connected component is? AND, if there is a known upper bound on the number of such simple cycles given the number of vertices defining the strongly connected component?
I am looking for any literature/algorithms related to both of these problems. THANK YOU!
In your case the number of possible simple 2k-cycles are (n choose k) * (m choose k). If n, m, and k are not small, this grows exponentially.
Enumerating the cycles is not feasible. I doubt that it is possible to count them for an arbitrary graph in reasonable time. Even with dynamic programming techniques this takes exponential time and space (but with a lower exponent than without those techniques).
I am looking for a Dijkstra's algorithm implementation, that also takes into consideration the number of nodes traversed.
What I mean is, a typical Dijkstra's algorithm, takes into consideration the weight of the edges connecting the nodes, while calculating the shortest route from node A to node B. I want to insert another parameter into this. I want the algorithm to give some weightage to the number of nodes traversed, as well.
So that the shortest route computed from A to B, under certain values, may not necessarily be the Shortest Route, but the route with the least number of nodes traversed.
Any thoughts on this?
Cheers,
RD
Edit :
My apologies. I should have explained better. So, lets say, the shortest route from
(A, B) is A -> C -> D -> E -> F -> B covering a total of 10 units
But I want the algorithm to come up with the route A -> M -> N -> B covering a total of 12 units.
So, what I want, is to be able to give some weightage to the number of nodes as well, not just the distance of the connected nodes.
Let me demonstrate that adding a constant value to all edges can change which route is "shortest" (least total weight of edges).
Here's the original graph (a triangle):
A-------B
\ 5 /
2 \ / 2
\ /
C
Shortest path from A to B is via C. Now add constant 2 to all edges. The shortest path becomes instead the single step from A directly to B (owing to "penalty" we've introduced for using additional edges).
Note that the number of edges used is (excluding the node you start from) the same as the number of nodes visited.
The way you can do that is adapt the weights of the edges to always be 1, so that you traverse 5 nodes, and you've gone a distance of "5". The algorithm would be the same at that point, optimizing for number of nodes traversed rather than distance traveled.
If you want some sort of hybrid, you need to determine how much importance to give to traversing a node and the distance. The weight used in calculations should look something like:
weight = node_importance * 1 + (1 - node_importance) * distance
Where node_importance would be a percentage which gauges how much distance is a factor and how much minimum node traversal is important. Though you may have to normalize the distances to be an average of 1.
I'm going to go out on a limb here, but have you tried the A* algorithm? I may have understood your question wrong, but it seems like A* would be a good starting point for what you want to do.
Check out: http://en.wikipedia.org/wiki/A*_search_algorithm
Some pseudo code there to help you out too :)
If i understood the question correctly then its best analogy would be that used to find the best network path.
In network communication a path may not only be selected because it is shortest but has many hop counts(node), thus may lead to distortion, interference and noise due to node connection.
So the best path calculation contains the minimizing the function of variables as in your case Distance and Hop Count(nodes).
You have to derive a functional equation that could relate the distance and node counts with quality.
so something as suppose
1 hop count change = 5 unit distance (which means the impact is same for 5unit distace or 1 node change)
so to minimize the loss you can use it in the linear equation.
minimize(distance + hopcount);
where hopcount can be expressed as distance.