This is a comprehensive Rust library for creating, manipulating, and analyzing graphs. In addition to basic graph data structures, the library implements a variety of graph algorithms and methods. It also includes functionality to read and write graph data from and to files in specific formats.
Graphs should be represented in the file in the following format:
- Start a line with
*vertices <amount of vertices>. - The following lines should represent vertices by
<index> <label>.
- Start a line with
*arcsor*edges. - The edges will be represented by
<u_index> <v_index> <weight (float)>.
*vertices 3
1 A
2 B
3 C
*edges
1 2 0.5
2 3 1.0
To load a graph from a file, use the read_from_file function. The function takes the full path to the file starting from the root of the project and returns a Result with the Graph if the file was correctly parsed, else a &str with the error message.
fn main() {
match Graph::read_from_file("full/path/to/data.net") {
Ok(graph) => {
// Use the graph
},
Err(e) => {
eprintln!("Failed to read graph: {}", e);
}
}
}