graph-theory

Creating clique graph to determine independent set

好久不见. 提交于 2019-12-08 08:32:35
问题 Trying to transform an s-clique into a s-independent set. Below is code and the function at the very bottom 'independent_set_decision(H,s)' is what I am struggling with. I understand that I need to create a complement of the graph and then check if that graph is a clique. However, the function I wrote isn't creating the graph as intended. Anyone have any advice please on what's wrong with that code? # Returns a list of all the subsets of a list of size k def k_subsets(lst, k): if len(lst) < k

Find path between two nodes in graph, according to given criteria - optimization task

不羁岁月 提交于 2019-12-08 07:59:37
问题 I have the following problem. I have cyclic, undirected, weighted graph G=(V,E). I need to find the simple path (without cycles) between two given nodes according to these rules: Finding minimal weight value in edges set of each possible path Select this path, which has maximal min value among selected minimal values from found paths E.g we have graph presented below: We can try to find simple path from node 1 to node 8. There are two possible pathes, listed below: 1 -> 3 -> 5 -> 8, minimal

Dominance-directed (tournament) graph metrics

眉间皱痕 提交于 2019-12-08 05:50:47
问题 I am interested in deriving dominance metrics (as in a dominance hierarchy) for nodes in a dominance directed graph, aka a tournament graph. I can use R and the package igraph to easily construct such graphs, e.g. library(igraph) create a data frame of edges the.froms <- c(1,1,1,2,2,3) the.tos <- c(2,3,4,3,4,4) the.set <- data.frame(the.froms, the.tos) set.graph <- graph.data.frame(the.set) plot(set.graph) This plotted graph shows that node 1 influences nodes 2, 3, and 4 (is dominant to them)

How can I efficiently create a user graph based on transaction data using Python?

霸气de小男生 提交于 2019-12-08 03:40:29
问题 I'm attempting to create a graph of users in Python using the networkx package. My raw data is individual payment transactions, where the payment data includes a user, a payment instrument, an IP address, etc. My nodes are users, and I am creating edges if any two users have shared an IP address. From that transaction data, I've created a Pandas dataframe of unique [user, IP] pairs. To create edges, I need to find [user_a, user_b] pairs where both users share an IP. Let's call this DataFrame

Algorithm for counting connected components of a graph in Python

依然范特西╮ 提交于 2019-12-08 03:32:27
I try to write a script that counts connected components of a graph and I can't get the right solution. I have a simple graph with 6 nodes (vertexes), nodes 1 and 2 are connected, and nodes 3 and 4 are connected (6 vertexes; 1-2,3-4,5,6). So the graph contains 4 connected components. I use following script to count connected components, but I get wrong result (2). nodes = [[1, [2], False], [2, [1], False], [3, [4], False], [4, [3], False], [5, [], False], [6, [], False]] # 6 nodes, every node has an id, list of connected nodes and boolean whether the node has already been visited

Find all tuples related to a certain string in Python

佐手、 提交于 2019-12-08 02:01:51
问题 I am trying to find all tuples related to a string, not just matched to it. Here is what I made: from itertools import chain data = [('A','B'),('B','C'),('B','D'),('B','F'),('F','W'),('W','H'),('G','Z')] init = 'A' filtered_init = [item for item in data if item[0] == init or item[1] == init] elements = list(dict.fromkeys([ i for i in chain(*filtered_init)])) elements.remove(init) dat = [] for i in elements: sync = [item for item in data if item[0] == i or item[1] == i] dat.append(sync) print

Visit all nodes in a graph with least repeat visits

独自空忆成欢 提交于 2019-12-08 01:40:46
问题 I have a tile based map where several tiles are walls and others are walkable. the walkable tiles make up a graph I would like to use in path planning. My question is are their any good algorithms for finding a path which visits every node in the graph, minimising repeat visits? For example: map example http://img220.imageshack.us/img220/3488/mapq.png If the bottom yellow tile is the starting point, the best path to visit all tiles with least repeats is: path example http://img222.imageshack

What if I do not use G transpose in calculating Strongly Connected Components?

不打扰是莪最后的温柔 提交于 2019-12-07 19:35:53
问题 I am reading Introduction to Algorithms. In 22.5 Strongly Connected Component, the algorithm STRONGLY-CONNECTED-COMPONENT(G) is defined as: Call DFS(G) to compute finishing times u.f for each vertex u Compute G transpose Call DFS(G transpose), but in the main loop of DFS, consider the vertices in order of decreasing u.f(as computed in line 1) Output the vertices of each tree in the depth-first forest formed in line 3 as a separate strongly connected component If I change the alogrithm to just

OrientDB GraphED - SQL insert edge between two (select vertex RID)s? Or alternative approach for very large import

醉酒当歌 提交于 2019-12-07 17:42:41
问题 For example, two simple vertices in an OrientDB Graph: orientdb> CREATE DATABASE local:/databases/test admin admin local graph; Creating database [local:/databases/test] using the storage type [local]... Database created successfully. Current database is: local:/graph1/databases/test orientdb> INSERT INTO V (label,in,out) VALUES ('vertexOne',[],[]); Inserted record 'V#6:0{label:vertexOne,in:[0],out:[0]} v0' in 0.001000 sec(s). orientdb> INSERT INTO V (label,in,out) VALUES ('vertexTwo',[],[]);

Finding all possible paths in graph

纵然是瞬间 提交于 2019-12-07 11:43:14
问题 I'm looking for some algorithm which will help me find all possible paths in a graph. Everything I found so far is not fully satisfying. Let's imagine we have a graph (tree) like this one: And let's use some algorithm like Breadth-First Search or Depth-First Search . In return we'll get something like 1, 2, 4, (2), 5, (2), 6, (2), (1), 3, 7, 8, (7), 9 Which is how we go through this tree and this is not what I'm looking for. I'd love to get all paths, like: 1 1, 2 1, 2, 4 1, 2, 5 1, 2, 6 1, 3