Questions tagged [weighted-graph]

144 questions
19
votes
3 answers

Create a histogram for weighted values

If I have a vector (e.g., v<-runif(1000)), I can plot its histogram (which will look, more or less, as a horizontal line because v is a sample from the uniform distribution). However, suppose I have a vector and its associated weights (e.g.,…
sds
  • 58,617
  • 29
  • 161
  • 278
15
votes
3 answers

R igraph convert parallel edges to weight attribute

I'm working with igraph for R. My graph is based on an edgelist which includes parallel edges (more than one edge with the same source and target). I would like to convert these parallel edges to an edge attribute weight. Is there an eay way to do…
supersambo
  • 811
  • 1
  • 9
  • 25
8
votes
1 answer

weighted graph from a data frame

I have an edgelist that I want to convert it to a weighted graph. I used the below code: edgelist <- read.table(text = " V1 v2 weights A B 1 B C 8 C D 6 D E 9 C F 12 F G 15",header=T) g<-graph_from_data_frame(edgelist) g It makes the weights as…
minoo
  • 555
  • 5
  • 20
7
votes
2 answers

Assign edge weights to a networkx graph using pandas dataframe

I am contructing a networkx graph in python 3. I am using a pandas dataframe to supply the edges and nodes to the graph. Here is what I have done : test = pd.read_csv("/home/Desktop/test_call1", delimiter = ';') g_test =…
Anand Nautiyal
  • 245
  • 2
  • 5
  • 11
6
votes
3 answers

Does networkx has a function to calculate the length of the path considering weights?

I am working with networkx to calculate the k-shortest simple paths. nx.shortest_simple_paths(G, source, target, weight=weight) returns the list of paths in the increasing order of cost (cumulative path length considering weights). I am interested…
PPR
  • 395
  • 1
  • 5
  • 17
6
votes
0 answers

Find shortest path in a weighted digraph with GraphFrames Spark

The graphFrames package of spark is great. I can find the shortest path from "a" to "d" with the command val results = g.shortestPaths.landmarks(Seq("a", "d")).run() but what how can I define a weighted graph and compute shortest path between two…
rahram
  • 560
  • 1
  • 7
  • 21
4
votes
1 answer

Edge weight in networkx

How do I assign to each edge a weight equals to the number of times node i and j interacted from an edge list? import pandas as pd import numpy as np import matplotlib.pyplot as plt import networkx as nx import scipy.sparse df =…
4
votes
1 answer

How to create random graph where each node has at least 1 edge using Networkx

I've managed to create a random undirected weighted graph for testing with Dijkstra's algorithm, but how can I make it so each node has at least one edge that connects them to the graph? I'm using Networkx and my graph generator is as…
Koala-tastic21
  • 43
  • 1
  • 1
  • 5
4
votes
0 answers

Calculating a threshold based on the connectedness of a weighted graph

Given a matrix like the one that follows (but a lot bigger) that describes a weighted undirected graph, structure(list(from = c("TPM1", "TPM1", "TPM1", "TPM1", "TPM1", "TPM1", "TPM1", "TPM1", "TPM1", "TPM1", "TPM1", "TPM1", "TPM1", "TPM1", "TPM1",…
J. Doe
  • 619
  • 4
  • 16
3
votes
1 answer

How to make a weighted graph of the London Underground

I was wondering if anyone had any advice on how to go about making a weighted graph of the London underground. It is for a project so that it can be used within Dijkstra's algorithm for the shortest path. The Dijkstra algorithm part is fine and…
Hopvine
  • 65
  • 4
3
votes
2 answers

Given a weighted graph and natural number k how to find the cheapest path from node s to t that can be divided by k?

Given a weighted graph G=(V,E) which doesnt include negative cycles, a natural number k, and two verticles: s,t. How can I find the cheapest route from s to t which its length can be divied by k?
3
votes
1 answer

R iGraph: How to get weighted adjacency matrix from a graph?

While there are some questions dealing with creating a graph from an adjacency matrix, I haven't found much about extracting the weighted adjacency matrix from a weighted graph. Say I have the following graph: library(igraph) nodes <-…
Nonancourt
  • 559
  • 2
  • 10
  • 21
3
votes
2 answers

Error using networkx weighted edgelist

I have created a weighted edge list that I am trying to use to generate a weighted undirected graph: The data is in a csv which looks like the following in excel: node1 node2 weight a b 0.1 a c 0.3 As recommended by other…
codegurl
  • 33
  • 1
  • 3
3
votes
3 answers

Centralities in networkx weighted graph

I am not able to compute centralities for a simple NetworkX weighted graph. Is it normal or I am rather doing something wrong? I add edges with a simple add_edge(c[0],c[1],weight = my_values), where c[0],c[1] are strings (names of the nodes) and…
jjrr
  • 1,038
  • 2
  • 13
  • 26
3
votes
4 answers

A BFS Algorithm for Weighted Graphs - To Find Shortest Distance

I've seen quite a few posts (viz. post1, post2, post3) on this topic but none of the posts provides an algorithm to back up respective queries. Consequently I'm not sure to accept the answers to those posts. Here I present a BFS based shortest-path…
KGhatak
  • 6,995
  • 1
  • 27
  • 24
1
2 3
9 10