MimIR
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
pbqp::Graph Class Reference

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)

Detailed Description

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.

Definition at line 252 of file graph.h.


Class Documentation

◆ pbqp::Graph::Ends

struct pbqp::Graph::Ends

Definition at line 254 of file graph.h.

Class Members
NodeId dst = 0
NodeId src = 0

Member Function Documentation

◆ add()

NodeId pbqp::Graph::add ( fe::View< Cost > costs)

Add a node with the given cost vector.

The vector must not be empty.

Definition at line 12 of file graph.cpp.

◆ add_edge_costs()

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().

◆ edge() [1/2]

Ends pbqp::Graph::edge ( EdgeId e) const
inlinenodiscard

◆ edge() [2/2]

EdgeId pbqp::Graph::edge ( NodeId m,
NodeId n ) const
nodiscard

The edge between m and n, or npos.

Definition at line 54 of file graph.cpp.

References edges(), npos, and num_nodes().

◆ edge_matrix() [1/2]

MatrixView pbqp::Graph::edge_matrix ( EdgeId e) const
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().

◆ edge_matrix() [2/2]

MatrixView pbqp::Graph::edge_matrix ( EdgeId e,
NodeId from ) const
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().

◆ edges()

auto pbqp::Graph::edges ( ) const
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().

◆ incident_edges()

fe::View< EdgeId > pbqp::Graph::incident_edges ( NodeId n) const
inlinenodiscard

Definition at line 302 of file graph.h.

◆ link()

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().

◆ node_costs()

fe::View< Cost > pbqp::Graph::node_costs ( NodeId n) const
inlinenodiscard

◆ nodes()

auto pbqp::Graph::nodes ( ) const
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().

◆ num_edges()

size_t pbqp::Graph::num_edges ( ) const
inlinenodiscard

Definition at line 313 of file graph.h.

Referenced by edges().

◆ num_matrices()

size_t pbqp::Graph::num_matrices ( ) const
inlinenodiscard

Number of distinct edge matrices ever linked or set; edges with equal matrices share one copy.

Definition at line 315 of file graph.h.

◆ num_nodes()

size_t pbqp::Graph::num_nodes ( ) const
inlinenodiscard

Definition at line 312 of file graph.h.

Referenced by edge(), link(), nodes(), pbqp::solve(), pbqp::write_dot(), and pbqp::write_json().

◆ num_options()

size_t pbqp::Graph::num_options ( NodeId n) const
inlinenodiscard

Definition at line 300 of file graph.h.

References node_costs().

Referenced by edge_matrix(), link(), and set_node_costs().

◆ set_edge_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().

◆ set_node_costs()

void pbqp::Graph::set_node_costs ( NodeId n,
fe::View< Cost > costs )

Replace a cost vector; the option count must not change.

Definition at line 43 of file graph.cpp.

References num_options().

Member Data Documentation

◆ npos

EdgeId pbqp::Graph::npos = static_cast<EdgeId>(-1)
staticconstexpr

Definition at line 259 of file graph.h.

Referenced by add_edge_costs(), edge(), link(), and pbqp::solve().


The documentation for this class was generated from the following files: