Skip to content

Commit

Permalink
Add more API usage examples to the documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
vahancho committed Dec 4, 2023
1 parent f2e2ca2 commit a19ff3a
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,46 @@ not only the shortest path, but the path that corresponds to the minimal overall

## API and usage

```cpp
// Declare a graph with nodes as integer values
Graphene<int> graph;

graph.addNode(0);
graph.addNode(42);

graph.addEdge(0, 42);
graph.addEdge(1, 2);

```

Calculate the shortest path between two nodes

```cpp

// 1--2--5--8
// \ \/
// 10---6---7
//
Graphene<int> graph;

auto weightFunction = [](int x, int y) -> int {
return std::abs(x - y);
};

graph.addEdge(1, 2);
graph.addEdge(2, 5);
graph.addEdge(5, 6);
graph.addEdge(5, 8);
graph.addEdge(8, 6);
graph.addEdge(1, 10);
graph.addEdge(10, 6);
graph.addEdge(6, 7);

path = graph.shortestPath(1, 6, weightFunction);
// path = {1, 2, 5, 6}

```

## Example (California road network)

# See also
Expand Down

0 comments on commit a19ff3a

Please sign in to comment.