|
1 |
| - |
| 1 | +<p align="center"> |
| 2 | + <img src="assets/graphosaurus-512.png" alt="Petgraph Logo"/> |
| 3 | +</p> |
2 | 4 |
|
3 |
| -# petgraph |
| 5 | +petgraph |
| 6 | +=== |
| 7 | +Petgraph provides fast, flexible graph data structures and algorithms |
| 8 | +in Rust. Supporting both directed and undirected graphs with arbitrary |
| 9 | +node and edge data. It comes with: |
4 | 10 |
|
5 |
| -Graph data structure library. Please read the [API documentation here][]. |
| 11 | +* **Multiple Graph Types**: Graph, StableGraph, GraphMap, and |
| 12 | + MatrixGraph to suit various use cases. |
6 | 13 |
|
7 |
| -Supports Rust 1.64 and later. |
| 14 | +* **Algorithms Included & Extensible**: For tasks like path-finding, |
| 15 | + minimum spanning trees, graph isomorphisms, and more - with traits |
| 16 | + exposed for implementing custom algorithms. |
| 17 | + |
| 18 | +* **Graph Visualization support**: Export/import graphs |
| 19 | + to/from [DOT][dot-url] format for visualization with |
| 20 | + [Graphviz][graphviz-url]. |
| 21 | + |
| 22 | +Supports Rust 1.64 and later. This will only change on major releases. |
8 | 23 |
|
9 | 24 | [![Crates.io][crates-badge]][crates-url]
|
10 |
| -[![docs.rs][docsrs-badge]][docsrs-url] |
| 25 | +[![docs.rs][docsrs-badge]][docsrs] |
11 | 26 | ![MSRV][msrv-badge]
|
12 | 27 | [![Discord chat][discord-badge]][discord-url]
|
13 |
| -[![build_status][]](https://github.com/petgraph/petgraph/actions) |
| 28 | +[![Build Status][build-status]][ci-url] |
| 29 | + |
| 30 | +## Example |
| 31 | + |
| 32 | +For more examples, see |
| 33 | +the [documentation on docs.rs][docsrs-examples]. |
| 34 | + |
| 35 | +```rust |
| 36 | +use petgraph::graph::UnGraph; |
| 37 | +use petgraph::algo::{dijkstra, min_spanning_tree}; |
| 38 | +use petgraph::data::FromElements; |
| 39 | +use petgraph::dot::{Dot, Config}; |
| 40 | +use petgraph::visit::NodeIndexable; |
| 41 | + |
| 42 | +fn main() { |
| 43 | + // Create an undirected graph with associated data |
| 44 | + // of type `i32` for the nodes and `()` for the edges. |
| 45 | + let g = UnGraph::<i32, ()>::from_edges(&[ |
| 46 | + (0, 1), (1, 2), (2, 3), (0, 3) |
| 47 | + ]); |
| 48 | + |
| 49 | + // The graph looks like this: |
| 50 | + // 0 -- 1 |
| 51 | + // | | |
| 52 | + // 3 -- 2 |
| 53 | + |
| 54 | + // Find the shortest path from `0` to `2` using `1` as the cost for every edge. |
| 55 | + let node_map = dijkstra(&g, 0.into(), Some(2.into()), |_| 1); |
| 56 | + assert_eq!(&2i32, node_map.get(&g.from_index(2)).unwrap()); |
| 57 | + |
| 58 | + // Get the minimum spanning tree of the graph as a new graph, and check that |
| 59 | + // one edge was trimmed. |
| 60 | + let mst = UnGraph::<_, _>::from_elements(min_spanning_tree(&g)); |
| 61 | + assert_eq!(g.raw_edges().len() - 1, mst.raw_edges().len()); |
| 62 | + |
| 63 | + // Output the tree to `graphviz` `DOT` format |
| 64 | + println!("{:?}", Dot::with_config(&mst, &[Config::EdgeNoLabel])); |
| 65 | + // graph { |
| 66 | + // 0 [ label = "0" ] |
| 67 | + // 1 [ label = "0" ] |
| 68 | + // 2 [ label = "0" ] |
| 69 | + // 3 [ label = "0" ] |
| 70 | + // 0 -- 1 [ ] |
| 71 | + // 2 -- 3 [ ] |
| 72 | + // 1 -- 2 [ ] |
| 73 | + // } |
| 74 | +} |
| 75 | +``` |
| 76 | + |
| 77 | +## Documentation |
14 | 78 |
|
15 |
| -Crate feature flags: |
| 79 | +* [API documentation on docs.rs][docsrs] |
| 80 | +* [Examples on docs.rs][docsrs-examples] |
| 81 | +* [Changelog][changelog] |
16 | 82 |
|
17 |
| -- `graphmap` (default) enable `GraphMap`. |
18 |
| -- `stable_graph` (default) enable `StableGraph`. |
19 |
| -- `matrix_graph` (default) enable `MatrixGraph`. |
20 |
| -- `serde-1` (optional) enable serialization for `Graph, StableGraph, GraphMap` |
21 |
| - using serde 1.0. Requires Rust version as required by serde. |
22 |
| -- `rayon` (optional) enable parallel iterators for the underlying data in `GraphMap`. Requires Rust version as required by Rayon. |
23 |
| -- `dot_parser` (optional) enable parsing graph from [DOT/Graphviz](https://www.graphviz.org/doc/info/lang.html) strings and files. |
| 83 | +### Crate features |
24 | 84 |
|
25 |
| -## Recent Changes |
| 85 | +petgraph is built with these features enabled by default: |
26 | 86 |
|
27 |
| -See [CHANGELOG][] for a list of changes. The minimum supported rust |
28 |
| -version will only change on major releases. |
| 87 | +- `graphmap` enable [`GraphMap`][docsrs-graph-map]. |
| 88 | +- `stable_graph` enable [`StableGraph`][docsrs-stable-graph]. |
| 89 | +- `matrix_graph` enable [`MatrixGraph`][docsrs-matrix-graph]. |
| 90 | + |
| 91 | +Optionally, the following features can be enabled: |
| 92 | + |
| 93 | +- `serde-1` enable serialization for |
| 94 | + `Graph, StableGraph, GraphMap` |
| 95 | + using [serde 1.0][docsrs-serde]. Requires Rust version as required |
| 96 | + by serde. |
| 97 | +- `rayon` enable parallel iterators for the underlying data |
| 98 | + in `GraphMap`. Requires Rust version as required |
| 99 | + by [rayon][docsrs-rayon]. |
| 100 | +- `dot_parser` enable parsing graph |
| 101 | + from [DOT/Graphviz][dot-url] |
| 102 | + strings and files. |
| 103 | + |
| 104 | +## Getting Help |
| 105 | + |
| 106 | +First, see if the answer to your question can be found in the |
| 107 | +[API documentation][docsrs]. If the answer is not there, feel free |
| 108 | +to ask your question on the [discussions page][github-discussions]. |
| 109 | +We would be happy to try to answer your question. If you find a bug, |
| 110 | +or have a feature request, please [open an issue][github-new-issue]. |
| 111 | + |
| 112 | +## Contributing |
| 113 | + |
| 114 | +🦕 Thanks for your help improving the project! We are so happy to have |
| 115 | +you! We have a [contributing guide][contributing] to help you get |
| 116 | +started. |
29 | 117 |
|
30 | 118 | ## Logo
|
31 | 119 |
|
32 |
| -The mascot is named "Sir Paul Rustory Graphosaurus" (close friends call him Paul). |
| 120 | +The mascot is named "Sir Paul Rustory Graphosaurus" (close friends |
| 121 | +call him Paul). |
33 | 122 | The logo has been created by the talented Aren.
|
34 | 123 |
|
35 | 124 | ## License
|
36 | 125 |
|
37 | 126 | Dual-licensed to be compatible with the Rust project.
|
38 | 127 |
|
39 |
| -Licensed under the Apache License, Version 2.0 |
40 |
| -<http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
41 |
| -<http://opensource.org/licenses/MIT>, at your option. This file may not |
42 |
| -be copied, modified, or distributed except according to those terms. |
| 128 | +Licensed under the [Apache License, Version 2.0][apache-license] or |
| 129 | +the [MIT license][mit-license], at your option. This file may |
| 130 | +not be copied, modified, or distributed except according to those |
| 131 | +terms. |
| 132 | + |
| 133 | +[apache-license]: http://www.apache.org/licenses/LICENSE-2.0 |
| 134 | + |
| 135 | +[build-status]: https://github.com/petgraph/petgraph/actions/workflows/ci.yml/badge.svg |
| 136 | + |
| 137 | +[changelog]: CHANGELOG.md |
| 138 | + |
| 139 | +[ci-url]: https://github.com/petgraph/petgraph/actions/workflows/ci.yml |
| 140 | + |
| 141 | +[contributing]: CONTRIBUTING.rst |
43 | 142 |
|
44 |
| -[API documentation here]: https://docs.rs/petgraph/ |
45 |
| -[build_status]: https://github.com/petgraph/petgraph/workflows/Continuous%20integration/badge.svg?branch=master |
46 |
| -[docsrs-badge]: https://img.shields.io/docsrs/petgraph |
47 |
| -[docsrs-url]: https://docs.rs/petgraph/latest/petgraph/ |
48 | 143 | [crates-badge]: https://img.shields.io/crates/v/petgraph.svg
|
| 144 | + |
49 | 145 | [crates-url]: https://crates.io/crates/petgraph
|
| 146 | + |
50 | 147 | [discord-badge]: https://img.shields.io/discord/1166289348384280616?logo=discord&style=flat
|
| 148 | + |
51 | 149 | [discord-url]: https://discord.gg/n2tc79tJ4e
|
52 |
| -[msrv-badge]: https://img.shields.io/badge/rustc-1.64+-blue.svg |
53 |
| -[CHANGELOG]: CHANGELOG.md |
| 150 | + |
| 151 | +[docsrs]: https://docs.rs/petgraph/latest/petgraph/ |
| 152 | + |
| 153 | +[docsrs-badge]: https://img.shields.io/docsrs/petgraph |
| 154 | + |
| 155 | +[docsrs-examples]: https://docs.rs/petgraph/latest/petgraph/index.html#example |
| 156 | + |
| 157 | +[docsrs-graph-map]: https://docs.rs/petgraph/latest/petgraph/stable_graph/struct.StableGraph.html |
| 158 | + |
| 159 | +[docsrs-matrix-graph]: https://docs.rs/petgraph/latest/petgraph/matrix_graph/struct.MatrixGraph.html |
| 160 | + |
| 161 | +[docsrs-rayon]: https://docs.rs/rayon/latest/rayon/ |
| 162 | + |
| 163 | +[docsrs-serde]: https://docs.rs/serde/latest/serde/index.html |
| 164 | + |
| 165 | +[docsrs-stable-graph]: https://docs.rs/petgraph/latest/petgraph/stable_graph/struct.StableGraph.html |
| 166 | + |
| 167 | +[dot-url]: https://www.graphviz.org/doc/info/lang.html |
| 168 | + |
| 169 | +[github-discussions]: https://github.com/petgraph/petgraph/discussions |
| 170 | + |
| 171 | +[github-new-issue]: https://github.com/petgraph/petgraph/issues/new |
| 172 | + |
| 173 | +[graphviz-url]: https://www.graphviz.org/ |
| 174 | + |
| 175 | +[mit-license]: http://opensource.org/licenses/MIT |
| 176 | + |
| 177 | +[msrv-badge]: https://img.shields.io/badge/rustc-1.64+-blue.svg |
0 commit comments