Namespaces | |
| namespace | json |
Classes | |
| class | BasicMatrix |
| A view of a cost matrix over row-major storage owned elsewhere; transposed() views the same storage column-major. More... | |
| class | Cost |
| A saturating cost; Cost::inf forbids an option or option pair. More... | |
| class | Graph |
| A PBQP problem graph. More... | |
| struct | Instance |
| A graph together with the optional rn_priority for solve. More... | |
| class | Matrix |
| An owning row-major cost matrix; it views its own storage, so writes go through span(). More... | |
| struct | Solution |
| A complete assignment of options to nodes. More... | |
| struct | Statistics |
| How often solve applied each reduction. More... | |
Typedefs | |
| using | MatrixSpan = BasicMatrix<Cost> |
| using | MatrixView = BasicMatrix<const Cost> |
Ids | |
Node and edge ids are dense and stable: nothing is ever removed from a Graph. | |
| using | NodeId = size_t |
| Identifier of a node in a Graph. | |
| using | EdgeId = size_t |
| Identifier of an edge in a Graph. | |
| using | OptionId = size_t |
| Index of an option within a node's cost vector. | |
PBQP Vectors & Matrices | |
PBQP vectors and matrices are small, so they live inline; a Matrix views such storage row-major. | |
| using | Costs = fe::Vector<Cost, 4> |
| using | Edges = fe::Vector<EdgeId, 4> |
| using | Choices = fe::Vector<OptionId, 8> |
| One option per node, indexed by node id. | |
Functions | |
| void | write_dot (std::ostream &out, const Graph &graph, fe::View< OptionId > choices={}) |
| Write graph in Graphviz DOT format with cost vectors and matrices as HTML-like labels. | |
| void | read_json (std::istream &in, Instance &instance, const std::filesystem::path &path="<input>") |
| Read a PBQP instance into the empty instance: | |
| void | write_json (std::ostream &out, const Graph &graph, fe::View< size_t > rn_priority={}) |
| Write the format that read_json reads. | |
| Cost | evaluate (const Graph &graph, fe::View< OptionId > choices) |
| All solver functions are safe to call concurrently on a graph that nobody mutates meanwhile. | |
| fe::Bitset | conflicts (const Graph &graph, fe::View< OptionId > choices) |
| Nodes whose choice is Cost::inf in their cost vector or, given the neighbour's choice, in an incident matrix. | |
| Solution | solve (const Graph &graph, fe::View< size_t > rn_priority={}) |
| Heuristic PBQP solver. | |
| std::optional< Solution > | solve_exhaustive (const Graph &graph, size_t max_combinations=10 '000 '000, unsigned num_threads=0) |
| Brute-force optimum, useful to cross-check small instances. | |
| std::ostream & | operator<< (std::ostream &out, Cost cost) |
| struct pbqp::Instance |
A graph together with the optional rn_priority for solve.
| Class Members | ||
|---|---|---|
| Graph | graph | |
| Vector< size_t > | rn_priority | Empty, or one entry per node id. |
| struct pbqp::Statistics |
| using pbqp::Choices = fe::Vector<OptionId, 8> |
| using pbqp::Costs = fe::Vector<Cost, 4> |
| using pbqp::EdgeId = size_t |
| using pbqp::Edges = fe::Vector<EdgeId, 4> |
| using pbqp::MatrixSpan = BasicMatrix<Cost> |
| using pbqp::MatrixView = BasicMatrix<const Cost> |
| using pbqp::NodeId = size_t |
| using pbqp::OptionId = size_t |
Nodes whose choice is Cost::inf in their cost vector or, given the neighbour's choice, in an incident matrix.
These are the candidates to spill or split when an assignment is infeasible. Requires a valid option for every node.
Definition at line 607 of file solver.cpp.
References conflicts(), pbqp::Graph::edge(), pbqp::Graph::edge_matrix(), pbqp::Graph::edges(), pbqp::Graph::node_costs(), and pbqp::Graph::nodes().
Referenced by conflicts().
All solver functions are safe to call concurrently on a graph that nobody mutates meanwhile.
Cost of choices under graph; Cost::inf if it picks a Cost::inf entry or the total saturates. Requires a valid option for every node.
Definition at line 591 of file solver.cpp.
References pbqp::Graph::edge(), pbqp::Graph::edge_matrix(), pbqp::Graph::edges(), evaluate(), pbqp::Graph::node_costs(), and pbqp::Graph::nodes().
Referenced by evaluate(), and solve().
| std::ostream & pbqp::operator<< | ( | std::ostream & | out, |
| Cost | cost ) |
| void pbqp::read_json | ( | std::istream & | in, |
| Instance & | instance, | ||
| const std::filesystem::path & | path = "<input>" ) |
Read a PBQP instance into the empty instance:
{
"nodes": [{"costs": [0, "inf"]}, {"costs": [7, 0, 2]}],
"edges": [{"src": 1, "dst": 0, "rows": 3, "cols": 2, "costs": [1, "inf", -5, 0, 4, 2]}],
"rn_priority": [5, 9]
}
The position of a node in nodes is its id. Edge costs are row-major with src as the row; rows and cols are optional and only checked. "inf" is Cost::inf, rn_priority is optional, and unknown keys are skipped. Throws fe::Error::Bail, a std::exception, on malformed input; path only names the input in its message.
Definition at line 440 of file json.cpp.
References read_json().
Referenced by read_json().
Heuristic PBQP solver.
Reduces degree 0, 1 (RI) and 2 (RII) nodes exactly and higher-degree nodes with the RN heuristic. Normalization keeps intermediate costs relative, so they saturate only where option costs differ by Cost::inf. Short of that, the result is optimal whenever no RN step is needed, e.g. on trees. RN decides the node with the highest rn_priority[n] first; ties go to the highest degree, then the widest cost spread. SSA-based register allocation passes PEO positions, so coloring cannot fail (Buchwald et al. 2011). Requires rn_priority to be empty or to cover every node id.
Definition at line 629 of file solver.cpp.
References evaluate(), pbqp::Graph::npos, pbqp::Graph::num_nodes(), and solve().
Referenced by solve().
|
nodiscard |
Brute-force optimum, useful to cross-check small instances.
The search space is split across num_threads threads (0 = hardware concurrency). Returns nothing if there are more than max_combinations candidate assignments.
Definition at line 691 of file solver.cpp.
References pbqp::Solution::cost, and solve_exhaustive().
Referenced by solve_exhaustive().
Write graph in Graphviz DOT format with cost vectors and matrices as HTML-like labels.
Edge matrices are titled src × dst, i.e. rows × columns. Highlights the entries picked by choices, which must be empty or cover every node id.
Definition at line 23 of file dot.cpp.
References pbqp::BasicMatrix< T >::cols(), pbqp::Graph::edge(), pbqp::Graph::edge_matrix(), pbqp::Graph::edges(), pbqp::Graph::node_costs(), pbqp::Graph::nodes(), pbqp::Graph::num_nodes(), pbqp::BasicMatrix< T >::rows(), and write_dot().
Referenced by write_dot().
| void pbqp::write_json | ( | std::ostream & | out, |
| const Graph & | graph, | ||
| fe::View< size_t > | rn_priority = {} ) |
Write the format that read_json reads.
Requires rn_priority to be empty or to have one entry per node.
Definition at line 447 of file json.cpp.
References pbqp::BasicMatrix< T >::cols(), pbqp::BasicMatrix< T >::data(), pbqp::Graph::edge(), pbqp::Graph::edge_matrix(), pbqp::Graph::edges(), pbqp::Graph::node_costs(), pbqp::Graph::nodes(), pbqp::Graph::num_nodes(), pbqp::BasicMatrix< T >::rows(), pbqp::BasicMatrix< T >::size(), and write_json().
Referenced by write_json().