-
Notifications
You must be signed in to change notification settings - Fork 25
docs: initial documentation #158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This is an initial docs page. It is very incomplete as of now, but it already offers a useful introduction to the library.
akrzemi1
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also shows how I envision each algorithm should be documented. In particular:
- the order of the clauses (the Standard Library is strict about it),
- the clause Constraints instead of concepts in the declarations,
- the presence of section Throws.
|
After some conversations with LEWG members, it is now my understanding that it is ok for the libraries targeting the standard to specify the template constraints in the declarations, so I got rid of the Constraints: clause. |
|
This PR addresses #149. |
pratzl
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A good start. I didn't see anything that was wrong, but a number of refinements and some different views.
doc/algorithms.md
Outdated
| | `G` | | the type of the graph that the algorithm is instantiated for | | ||
| | `vd` | `vertex_info<vertex_id_t<G>, vertex_reference_t<G>, void>` | visited vertex | | ||
| | `ed` | `edge_info<vertex_id_t<G>, true, edge_reference_t<G>, void>` | visited edge | | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing visitor functions:
- on_initialize_vertex(vd)
- on_examine_vertex(vd)
- on_tree_edge(ed)
- on_back_edge(ed)
- on_forward_or_cross_edge(ed)
- on_finish_edge(ed)
See wg21.link/P3128 for descriptions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to stick to the approach where the documentation describes what is present in the library rather than what is present in the paper.
on_initialize_vertex(vd)-- I will document it, but first I would like to understand what this one is for: Use cases for visitors #157on_examine_vertex(vd)-- it is documented- Regarding the last four, these names do not occur even once in the graph-v2 library, at least in branch
master. I would rather describe them when algorithmdepth_first_searchis implemented.
doc/algorithms.md
Outdated
| A number of functions in this section take a _visitor_ as an optional argument. | ||
| As different _events_, related to vertices and edges, occur during the execution of an algorithm, | ||
| a corresponding member function, if present, is called for the visitor. | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some points that might useful to people.
- No runtime overhead occurs if the visitor function isn't defined on the visitor class.
- The visitor functions are the same used by boost::graph.
- Each algorithm defines the visitor functions they support. Additional functions included in the visitor that aren't supported are ignored.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| The distances of each path are returned directly vie the output function argument. | ||
| The paths themselves, if requested, are only returned indirectly by providing for each vertex | ||
| its predecessor in any shortest path. | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggested wording for clarity:
The distances of each edge are returned directly via the output function argument. The paths themselves are returned indirectly in the predecessors vector, where each element is the preceding vertex for the matching vertex.
(My wording still feels a little awkward; just giving ideas)
|
|
||
| The shortest paths algorithm builds on the idea that each edge in a graph has its associated _weight_. | ||
| A path _distance_ is determined by the composition of weights of edges that constitute the path. | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A suggestion:
A path distance is the sum of the edge weights of the path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am reluctant to use word "sum" due to this example: #169.
| #### Customization | ||
|
|
||
| 1. Returns `g.vertices()`, if such member function exists and returns a `std::move_constructible` type. | ||
| 2. Returns `vertices(g)`, if such function is ADL-discoverable and returns a `std::move_constructible` type. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as previous.
|
|
||
| The CPO `vertex_id(g, ui)` is used obtain the _id_ of the vertex, given the iterator. | ||
| We also use its return type to determine the type of the vertex id: `vertex_id_t<G>`. | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine for now. With the addition of descriptors, this is the only function signature that changes. Once that's available, ui becomes u (descriptor).
|
|
||
| #### Coustomization | ||
|
|
||
| 1. Returns `ui->vertex_id(g)`, if this expression is valid and its type is `std::move_constructible`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this will remain valid when descriptors are used. It means that vertex_id(g) would need to be defined on the descriptor, which may be possible.
| #### Coustomization | ||
|
|
||
| 1. Returns `ui->vertex_id(g)`, if this expression is valid and its type is `std::move_constructible`. | ||
| 2. Returns `vertex_id(g, ui)`, if this expression is valid and its type is `std::move_constructible`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the return type is simple like an integral id then this is fine. If we want to extend the id type to be more than integral, like a user-defined type or a string, then we won't want to require move_constructible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that my goal is to document what is in the current library (modulo bugs), rather than a vision for the future.
After a bit of investigation, I conclude that the current Graph Container Interface requires the IDs to be copy_constructible!
Suppose that I have my own graph representation that needs to use non-copyable, non-movable IDs. How am I supposed to customize vertex_id?
ID const& vertex_id(Graph const& g, Graph::const_iterator it) {
return it->first;
}Shall I return by value or by reference to const? If by value, then I need to copy. If by reference, then the CPO vertex_id will do the copying, because its return type is non-reference, and I am returning a reference to const, so even move will not work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filed #174.
|
|
||
| 1. Returns `ui->vertex_id(g)`, if this expression is valid and its type is `std::move_constructible`. | ||
| 2. Returns `vertex_id(g, ui)`, if this expression is valid and its type is `std::move_constructible`. | ||
| 3. Returns <code>static_cast<<em>vertex-id-t</em><G>>(ui - begin(vertices(g)))</code>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vertex_id_(g,u) is used to define vertex_id_t, so there may be a circular definition here (I hope that's not because of the current definition in graph-v2).
I think this needs to be flushed out a little more to define the vertex type based on vertex_t and whether it is a range or not (for #1 & #2 below).
|
Thanks for the feedback!
|
pratzl
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Introducing vd and ed as new conventions doesn't provide much value to me. It might also introduce confusion because it implies something unique. I think the use of u and uv, as is used in the papers and elsewhere, should be sufficient.
This is an initial docs page. It is very incomplete as of now, but it already offers a useful introduction to the library.