graph-theory

Find the most expensive path from s to t using DFS

百般思念 提交于 2019-12-25 08:03:05
问题 In a given graph G=(V,E) each edge has a cost c(e) . We have a starting node s and a target node t. How can we find the most expensive path from s to t using following DFS algorithm? DFS(G,s): foreach v in V do color[v] <- white; parent[v] <- nil DFS-Visit(s) DFS-Visit(u) color[u] <- grey foreach v in Adj[u] do if color[v] = white then parent[v] = u; DFS-Visit(v) color[u] <- black What I have tried: So first we create an array to maintain the cost to each node: DFS(G,s,t): foreach v in V do

Perform Centrality Functions on all Nodes using Cytoscape.js

跟風遠走 提交于 2019-12-25 08:01:28
问题 I need to calculate degree, closeness and betweenness centrality for every node on a graph. I'm currently using the functions built into Cytoscape.js on each node after the cy.ready() event. However, as the graphs are quite large (250+ Nodes, 650+ Connections) it's taking too long to compute. Can anyone suggest a more efficient method? var calculateSNA = function() { // Don't run if already set... if(data.sna) return false console.log('Running SNA') _.map(nodes, function(node) { var target =

How to build a graph of resolved instances with Autofac?

家住魔仙堡 提交于 2019-12-25 03:27:19
问题 After all registrations, I am doing ContainerBuilder.RegisterCallback and subscribing to all IComponentRegistration.Preparing and IComponentRegistration.Activating events to be able to handle all activations. With this two events I am able to build a tree, the order of events looks like this: Preparing: Root Preparing: FirstLevel_A Activating: FirstLevel_A Preparing: FirstLevel_B Preparing: SecondLevel_C Activating: SecondLevel_C Activating: FirstLevel_B Activating: Root But what if some

Display and add methods for adjacency list graph

谁说胖子不能爱 提交于 2019-12-25 03:24:14
问题 This is my third time for creating a graph using adjacency list in c++. It's important to use OOP. I feel like the answer to this problem is really simple, but I can't manage to fix and improve my code. There is it: #include <iostream> #include <algorithm> #include <fstream> #include <vector> using namespace std; struct Edge { int begin; int end; }; class Graph { private: int numOfNodes; vector<vector<int>> baseVec; public: Graph(int numOfNodes) { //baseVec->resize(numOfNodes, vector<int>

Maximum weighted bipartite matching for two sets of vertices of drastically different sizes

邮差的信 提交于 2019-12-25 01:46:04
问题 The abstract problem I want to find the best maximum matching in a complete weighted bipartite graph where the two sets of vertices differ drastically in size, i.e. one set of vertices is very large and the other one very small. The Hungarian algorithm is not a good approach for this problem since it adds dummy vertices to the smaller set such that the two sets have the same size, so I lose all the potential efficiency gains from one of the vertex sets being only very small. More concretely I

how to fit a graph inside a grid?

大兔子大兔子 提交于 2019-12-24 20:44:54
问题 My question is if we have graph and each node knows its coordinates. how can we place that graph inside a grid such that each edge knows which grid or grids it passes. and we could compare the proximity of grids. I think the grid structure should like this: typedef std::pair<int, int> Point; class Grid { int size; public: vector<vector<Point>> grid; Grid(int size) :size(size), grid(size, vector<Point>(size)) { for (size_t y = 0; y < grid.size(); y++) { vector<Point> loc; for (size_t x = 0; x

SPOJ - INUMBER (Can't seem to develop a solution within the time limit)

折月煮酒 提交于 2019-12-24 11:36:23
问题 I'm trying to solve this problem on SPOJ INUMBER. Problem statement is as follows: For the given number n find the minimal positive integer divisable by n , with the sum of digits equal to n . INPUT t – the number of test cases, then t test cases follow. (t <= 50) Test case description: n - integer such that 0 < n <= 1000 OUTPUT For each test case output the required number (without leading zeros). EXAMPLE: Input: 2 1 10 Output: 1 190 I can only think of a brute force solution emulating the

Which algorithm to find the nearest node reachable from the other one by all the outoging paths

纵饮孤独 提交于 2019-12-24 08:47:32
问题 Which algorithm do you recommend to find out the nearest node which can be reached from the specific one by all the paths coming out the node. The graph is directed unweight. I'm trying to analyze control flow diagram and when there is a 'IF' block I want to find the block which "closes" the 'IF'. 回答1: Run a set of breadth-first searches in parallel, one from each out-path of the start node, and each time you examine a node increment its count by one. (Note: "parallel" here means that you

Neo4j: find degree of connection

寵の児 提交于 2019-12-24 06:49:51
问题 I'm using Neo4j to find the degree of connection between users. I have data in the follower shape: (user)-[:INTERACTS_WITH]->(user) So if user_1 interact with user_2 and user_2 interacts with user_3, then user_1 and user_3 share a second-degree connection. Ideally, I would like to get the following dataset like this in return: degree count NULL 123 1 1050 2 3032 3 2110 ... ... Is there a better way to do this than to simply run shortestPath() function for every pair of users? If not, then

Array of structs with dynamic allocation runs very slow in C in comparison to Python

天大地大妈咪最大 提交于 2019-12-24 06:36:04
问题 I "glue" together (with a help of other SO users) a small C program that maps string labels to integer labels in a edgelist data structure. For instance, for input file Mike Andrew Mike Jane John Jane the program outputs 1 2 1 3 4 3 However, I mapped huge edgelist files and unfortunately the program runs very slow in comparison to Python alternative. Below I pasted both programs, in C and Python. I kindly ask for a pointers how to improve speed of the C program. #include <stdio.h> #include