Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/raoulluque/dimacs-petgraph-parser

A parser for constructing petgraph graphs from the dimacs format
https://github.com/raoulluque/dimacs-petgraph-parser

dimacs-format graph graphs petgraph rust

Last synced: 5 days ago
JSON representation

A parser for constructing petgraph graphs from the dimacs format

Awesome Lists containing this project

README

        

# Dimacs Petgraph Parser

Basic parser to convert graphs in [dimacs .col](http://lcs.ios.ac.cn/~caisw/Resource/about_DIMACS_graph_format.txt) format to [petgraphs](https://github.com/petgraph/petgraph) with optional treewidth information. The treewidth information is in optional lines in arbirtary order in between the c and p lines in the dimacs.col file:
```
c ...
t TREEWIDTH_NUMBER
l TREEWIDTH_LOWER_BOUND_NUMBER
u TREEWIDTH_UPPER_BOUND_NUMBER
p ...
```
(see examples in [test_graphs](test_graphs))

# Usage / Example

Include this lib in your dependencies in your Cargo.toml:

```toml
dimacs_petgraph_parser = { git = "https://github.com/RaoulLuque/dimacs-petgraph-parser" }
```
Use the read_graph() function. This will return a result with an error if any IO errors occur or the graph is in the wrong format:

```rust
let test_graph_one_file =
File::open("test_graphs/test_graph_one.col").expect("Should be able to read file");
let (test_graph_one, treewidth, lower_bound, upper_bound):
(Graph,
Option,
Option,
Option
) =
read_graph(test_graph_one_file)
.expect("Test Graph One should be readable/in correct format");
```