Questions tagged [petgraph]

`petgraph` is a graph data structure library for Rust

petgraph is a graph data structure library for Rust. It provides graph types and graph algorithms.

Documentation

Repository

crates.io

26 questions
2
votes
1 answer

Mutable access to two nodes in petgraph

I am using the petgraph crate to implement a dataflow graph. I would like to copy data from an edge source node to its target node. For that I would need a mutable reference to the target node and an immutable reference to the source node. However…
vuilehaid
  • 342
  • 2
  • 8
1
vote
1 answer

How do I make an unweighted, undirected graph with string nodes in Rust?

I would like to create an unweighted, undirected graph with string nodes in Rust. I've been trying to use petgraph and the from_edges construction method provided on UnGraph, but I am unable to do so because &str is not a valid NodeIndex. Is there…
1
vote
0 answers

How to make OwningRef work with iterators?

I have a RwLock protected global WORLD, and I want to write a function that read locks it and returns an iterator (of type Neighbors) that iterates over edges in a petgraph::stable_graph::StableGraph that is stored inside the global. I'm using…
Joseph Garvin
  • 20,727
  • 18
  • 94
  • 165
1
vote
1 answer

How do I return a reference to an iterator using conservative_impl_trait?

I have a petgraph::Graph structure onto which I have imposed a tree structure by giving every node weight a parent_edge_idx which is an Option of the edge that connects from its parent to itself. I need to iterate over a node's children. I…
masonk
  • 9,176
  • 2
  • 47
  • 58
1
vote
1 answer

Return all petgraph connected components in a hashtable

I'm using petgraph and I would like to extract connected components. I want to have a HashMap> with a u32 as the identifier for the connected component and a Vec as a container with references to all nodes in…
RomainL.
  • 997
  • 1
  • 10
  • 24
0
votes
0 answers

Error with type annotation in variable when using petgraph

The code below defines a directed graph using petgraph extern crate petgraph; use petgraph::graph::DiGraph; fn main() { // Define the list of edges. Each edge is in the format (source, target, edge weight). let edge_list = vec![(0, 1), (0,…
TKS0113
  • 1
  • 1
0
votes
1 answer

Merging two nodes: cannot borrow graph becuase it is also borrowed as immutable

I have a struct that contains a graph as a member; specifically, a StableGraph from the petgraph crate. I am trying to implement a function that merges two nodes in this graph. fn merge(&mut self, to_keep: NodeIndex, to_drop: NodeIndex) { …
Nim
  • 13
  • 3
0
votes
1 answer

How to declare generic types for a function that computes k-shortest-paths using Yen's algorithm and petgraph?

I have implemented Yen's algorithm Wikipedia using petgraph in Rust. In a main function, the code looks like this: use std::collections::BinaryHeap; use std::cmp::Reverse; use std::collections::HashSet; use petgraph::{Graph, Undirected}; use…
0
votes
1 answer

Iterating over a vector gives me a different value than what is inside the vector Rust

I have been using Petgraph recently to make simple graphs with Structs for nodes and custom edges, but I have come across a problem which I am unsure if it comes from the library or Rust. I have a graph, in which I have multiple nodes, each nodes…
GuiGui
  • 83
  • 8
0
votes
1 answer

How can you modify edge weights for a filtered Petgraph graph?

I am using an edge filter for my graph and want to update an edge weight: use petgraph::prelude::*; use petgraph::graph; use petgraph::visit::{Dfs, EdgeFiltered, IntoEdges}; fn filter_edges(edge: graph::EdgeReference) -> bool { match…
curiousdannii
  • 1,658
  • 1
  • 25
  • 40
0
votes
1 answer

Random walk using petgraph

I am trying to implement a random walk on a directed graph using the petgraph crate. So far, I have defined a RandomWalk struct which implements the Walker trait: extern crate petgraph; // 0.4.13 use petgraph::visit::{GraphBase, Walker}; use…
fuji
  • 1,173
  • 1
  • 10
  • 27
1
2