graph-theory

NoSQL Solution for Persisting Graphs at Scale

▼魔方 西西 提交于 2019-12-02 14:01:56
I'm hooked on using Python and NetworkX for analyzing graphs and as I learn more I want to use more and more data (guess I'm becoming a data junkie :-). Eventually I think my NetworkX graph (which is stored as a dict of dict) will exceed the memory on my system. I know I can probably just add more memory but I was wondering if there was a way to instead integrate NetworkX with Hbase or a similar solution? I looked around and couldn't really find anything but I also couldn't find anything related to allowing a simple MySQL backend as well. Is this possible? Does anything exist to allow for

Graph coloring with intervals Gurobi constraints

家住魔仙堡 提交于 2019-12-02 14:01:15
问题 I'm trying to fix some constraints for the Graph coloring problem using networkx and gurobi. For each i ∈ V, we define the following set of intervals. Each interval [l,u] ∈ Ii represents a possible pair of minimum color l and maximum color u for the set of edges incident to vertex i. Also, for each k∈K , we represent the set of intervals for vertex i ∈ V which include color k by : Intervals variable This is all the code that i wrote: import networkx as nx import gurobi as gb from itertools

How can I find the shortest path between 100 moving targets? (Live demo included.)

自作多情 提交于 2019-12-02 14:00:23
Background This picture illustrates the problem: I can control the red circle. The targets are the blue triangles. The black arrows indicate the direction that the targets will move. I want to collect all targets in the minimum number of steps. Each turn I must move 1 step either left/right/up or down. Each turn the targets will also move 1 step according to the directions shown on the board. Demo I've put up a playable demo of the problem here on Google appengine . I would be very interested if anyone can beat the target score as this would show that my current algorithm is suboptimal. (A

Difference between DFS vs BFS in this example?

不想你离开。 提交于 2019-12-02 09:44:57
I am bit confused after reading examples at DFS where output is printed in different fashion for both DFS approaches though both are said to be DFS. In fact DFS recursion approach print the output just in same fashion as BFS . Then what's the difference ? Is recursion approach given here not an example of DFS ? Using Stack // Iterative DFS using stack public void dfsUsingStack(Node node) { Stack<Node> stack=new Stack<Node>(); stack.add(node); node.visited=true; while (!stack.isEmpty()) { Node element=stack.pop(); System.out.print(element.data + " "); List<Node> neighbours=element.getNeighbours

Recording predecessors in a DFS search in an undirected graph

寵の児 提交于 2019-12-02 08:26:29
I was trying to use the code from this thread: Boost DFS back_edge , to record the cycles in an undirected graph. To do this I need to store the predecessors for each dfs tree when it finds a back_edge. Since this is an undirected graph I think we can not use directly on_back_edge() from EventVisitor Concept . So I was thinking to record the predecessors in the void back_edge() method of below code. But I am not sure how to do this and return the cycle vertices. Here is the code and the part I added for recording predecessors: #include <boost/config.hpp> #include <boost/graph/adjacency_list

Graph coloring with intervals Gurobi constraints

穿精又带淫゛_ 提交于 2019-12-02 04:17:50
I'm trying to fix some constraints for the Graph coloring problem using networkx and gurobi. For each i ∈ V, we define the following set of intervals. Each interval [l,u] ∈ Ii represents a possible pair of minimum color l and maximum color u for the set of edges incident to vertex i. Also, for each k∈K , we represent the set of intervals for vertex i ∈ V which include color k by : Intervals variable This is all the code that i wrote: import networkx as nx import gurobi as gb from itertools import combinations, chain import pygraphviz as pygv import os import matplotlib.pyplot as plt from

Algorithm to find 'maximal' independent set in a simple graph

老子叫甜甜 提交于 2019-12-01 23:49:18
in words, can someone post directions towards finding the 'maximal' independent set in a simple graph? I read up something from ETH site which said one can find such in O(n) by simply picking a random vertex v and than scanning the rest and attempting to find if there's an edge from v to the rest. Thanks Yes, by definition, a maximal indpendent set is an independent set to which no more vertices can be added without violating the 'independence' condition. So just picking vertices till you can pick no more would give you a maximal independent set, can be done in linear time (i.e. linear in |V|

Find all simple path from node A to node B in direct weighted graph with the sum of weighs less a certain value?

心已入冬 提交于 2019-12-01 14:13:08
I have a directed weighted graph G=(V,E), which may have loops . I am trying to determine the best time efficient algorithm to accomplish task: t o find all simple path in G between source and target node with total weight of edges in this path less than certain value (for convenience we denote this value as PATH_WEIGHT_LIMIT) All weights is positive and can be float. So, a prototype of my function will be: def find_paths(G, source, target, path_weight_limit) Result paths may overlap, its fine. Much like those discussed here, e.g.: algorithm for finding NUMBER of distinct paths from A to B in

How do I find all polygons in an undirected graph?

坚强是说给别人听的谎言 提交于 2019-12-01 13:45:27
Given an undirected graph, what would be an algorithm to find all polygons within such graph? Here is an example graph with polygons in colour. Note that there is a polygon ABCIHGJKLMLKA, which includes the nodes KLM, but the polygon CDEG does not include F. I have read of solutions to this problem, but without the leaf requirement that I have. Some axioms that exist in previous solutions is that each edge is only used twice, however dead-end edges would need to be traversed four times in total. That is, there exists a polygon that contains all the outer nodes ABCDEFGJKLMLKA, however it is

Solving Chinese Postman algorithm with eulerization

天涯浪子 提交于 2019-12-01 12:25:11
问题 I'm would like to solve Chinese Postman problem in a graph where an eulerian cycle does not exist. So basically I'm looking for a path in a graph which visits every edge exactly once, and starts and ends at the same node. A graph will have an euler cycle if and only if every node has same number of edges entering into and going out of it. Obviously my graph doesn't . I found out that Eulerization (making a graph Eulerian) could solve my question LINK. Can anyone suggest a script to add