A PBQP problem graph. More...
#include <pbqp/graph.h>
Classes | |
| struct | Ends |
Public Member Functions | |
Add Nodes, Edges, and Costs | |
| NodeId | add (fe::View< Cost > costs) |
| Add a node with the given cost vector. | |
| EdgeId | link (NodeId m, NodeId n, MatrixView costs) |
| Link m and n with a num_options(m) × num_options(n) matrix. | |
| EdgeId | add_edge_costs (NodeId m, NodeId n, MatrixView costs) |
| Like link, but sums costs onto an existing edge between m and n, whichever way it points. | |
| void | set_node_costs (NodeId n, fe::View< Cost > costs) |
| Replace a cost vector; the option count must not change. | |
| void | set_edge_costs (EdgeId e, MatrixView costs) |
| Replace a cost matrix, src options as rows. | |
Getters | |
| fe::View< Cost > | node_costs (NodeId n) const |
| MatrixView | edge_matrix (EdgeId e) const |
| Row-major with the src option as the row. | |
| MatrixView | edge_matrix (EdgeId e, NodeId from) const |
| The options of from, an end of e, are the rows. | |
| size_t | num_options (NodeId n) const |
| fe::View< EdgeId > | incident_edges (NodeId n) const |
| Ends | edge (EdgeId e) const |
| EdgeId | edge (NodeId m, NodeId n) const |
| The edge between m and n, or npos. | |
| auto | nodes () const |
| All node ids. | |
| auto | edges () const |
| All edge ids. | |
| size_t | num_nodes () const |
| size_t | num_edges () const |
| size_t | num_matrices () const |
| Number of distinct edge matrices ever linked or set; edges with equal matrices share one copy. | |
Static Public Attributes | |
| static constexpr EdgeId | npos = static_cast<EdgeId>(-1) |
A PBQP problem graph.
Every node carries a cost vector with one entry per option. Every edge carries a cost matrix indexed by the options of its endpoints:
matrix[src_option, dst_option]
The total cost of an assignment x is
sum_n c_n(x_n) + sum_{mn} M_mn(x_m, x_n)
A node holds at most one edge to any other node, so parallel edges have to be merged by summing their matrices first. A Graph only grows; ids are handed out consecutively from 0.
| struct pbqp::Graph::Ends |
| EdgeId pbqp::Graph::add_edge_costs | ( | NodeId | m, |
| NodeId | n, | ||
| MatrixView | costs ) |
Like link, but sums costs onto an existing edge between m and n, whichever way it points.
Sums saturate and Cost::inf absorbs.
Definition at line 32 of file graph.cpp.
References edge(), edge_matrix(), link(), npos, and set_edge_costs().
Definition at line 303 of file graph.h.
References edge().
Referenced by add_edge_costs(), pbqp::conflicts(), edge(), edge_matrix(), edge_matrix(), pbqp::evaluate(), link(), pbqp::write_dot(), and pbqp::write_json().
The edge between m and n, or npos.
Definition at line 54 of file graph.cpp.
References edges(), npos, and num_nodes().
|
inlinenodiscard |
Row-major with the src option as the row.
Definition at line 287 of file graph.h.
References edge(), and num_options().
Referenced by add_edge_costs(), pbqp::conflicts(), edge_matrix(), pbqp::evaluate(), set_edge_costs(), pbqp::write_dot(), and pbqp::write_json().
|
inlinenodiscard |
The options of from, an end of e, are the rows.
Definition at line 294 of file graph.h.
References edge(), and edge_matrix().
|
inlinenodiscard |
All edge ids.
Definition at line 310 of file graph.h.
References num_edges().
Referenced by pbqp::conflicts(), edge(), pbqp::evaluate(), pbqp::write_dot(), and pbqp::write_json().
| EdgeId pbqp::Graph::link | ( | NodeId | m, |
| NodeId | n, | ||
| MatrixView | costs ) |
Link m and n with a num_options(m) × num_options(n) matrix.
Requires distinct nodes that are not linked yet.
Definition at line 18 of file graph.cpp.
References pbqp::BasicMatrix< T >::cols(), edge(), npos, num_nodes(), num_options(), and pbqp::BasicMatrix< T >::rows().
Referenced by add_edge_costs().
Definition at line 284 of file graph.h.
Referenced by pbqp::conflicts(), pbqp::evaluate(), num_options(), pbqp::write_dot(), and pbqp::write_json().
|
inlinenodiscard |
All node ids.
Definition at line 309 of file graph.h.
References num_nodes().
Referenced by pbqp::conflicts(), pbqp::evaluate(), pbqp::write_dot(), and pbqp::write_json().
|
inlinenodiscard |
|
inlinenodiscard |
|
inlinenodiscard |
Definition at line 312 of file graph.h.
Referenced by edge(), link(), nodes(), pbqp::solve(), pbqp::write_dot(), and pbqp::write_json().
|
inlinenodiscard |
Definition at line 300 of file graph.h.
References node_costs().
Referenced by edge_matrix(), link(), and set_node_costs().
| void pbqp::Graph::set_edge_costs | ( | EdgeId | e, |
| MatrixView | costs ) |
Replace a cost matrix, src options as rows.
Definition at line 48 of file graph.cpp.
References pbqp::BasicMatrix< T >::cols(), edge_matrix(), and pbqp::BasicMatrix< T >::rows().
Referenced by add_edge_costs().
Replace a cost vector; the option count must not change.
Definition at line 43 of file graph.cpp.
References num_options().
Definition at line 259 of file graph.h.
Referenced by add_edge_costs(), edge(), link(), and pbqp::solve().