ALPS Project: lattice library

Header file: lattice/graph_helper.h

defines a class graph_helper which given a set of parameters and an XML file containing lattices creates a lattice graph and provides easy access to its properties. By deriving from this class, all the graph functionality can easily be included in a simulation program.

Synopsis

namespace alps {
{

template <class G=coordinate_graph_type>
class graph_helper : public LatticeLibrary
{
public:
typedef G graph_type;

typedef typename graph_traits<graph_type>::vertex_iterator vertex_iterator;
typedef typename graph_traits<graph_type>::edge_iterator edge_iterator;
typedef typename graph_traits<graph_type>::out_edge_iterator out_edge_iterator;
typedef typename graph_traits<graph_type>::in_edge_iterator in_edge_iterator;
typedef typename graph_traits<graph_type>::edge_descriptor edge_descriptor;
typedef typename graph_traits<graph_type>::vertex_descriptor vertex_descriptor;
typedef typename graph_traits<graph_type>::vertices_size_type vertices_size_type;
typedef typename graph_traits<graph_type>::edges_size_type edges_size_type;
typedef typename graph_traits<graph_type>::degree_size_type degree_size_type;
typedef typename graph_traits<graph_type>::adjacency_iterator adjacency_iterator;

typedef typename graph_traits<graph_type>::site_iterator site_iterator;
typedef typename graph_traits<graph_type>::bond_iterator bond_iterator;
typedef typename graph_traits<graph_type>::neighbor_bond_iterator neighbor_bond_iterator;
typedef typename graph_traits<graph_type>::bond_descriptor bond_descriptor;
typedef typename graph_traits<graph_type>::site_descriptor site_descriptor;
typedef typename graph_traits<graph_type>::sites_size_type sites_size_type;
typedef typename graph_traits<graph_type>::bonds_size_type bonds_size_type;
typedef typename graph_traits<graph_type>::neighbors_size_type neighbors_size_type;
typedef typename graph_traits<graph_type>::neighbor_iterator neighbor_iterator;

typedef typename lattice_traits<lattice_type>::unit_cell_type unit_cell_type;
typedef typename lattice_traits<lattice_type>::cell_descriptor cell_descriptor;
typedef typename lattice_traits<lattice_type>::offset_type offset_type;
typedef typename lattice_traits<lattice_type>::vector_type vector_type;
typedef typename lattice_traits<lattice_type>::size_type size_type;
typedef typename lattice_traits<lattice_type>::cell_iterator cell_iterator;
typedef typename lattice_traits<lattice_type>::cell_iterator momentum_iterator;
typedef typename lattice_traits<lattice_type>::cell_iterator basis_vector_iterator;
typedef typename lattice_traits<lattice_type>::cell_iterator boundary_crossing_type;


graph_helper(std::istream& in, const Parameters& p);
graph_helper(const alps::Parameters& p);
~graph_helper();

lattice_type& lattice();
const lattice_type& lattice() const;

graph_type& graph();
const graph_type& graph() const;

size_type volume() const;
const unit_cell_type& unit_cell() const;
cell_descriptor cell(const offset_type& o) const;
std::pair<cell_iterator,cell_iterator> cells() const;
const offset_type& offset(const cell_descriptor& c) const;
bool on_lattice(const offset_type& o) const;
std::pair<bool,boundary_crossing_type> shift(offset_type& o, const offset_type& s) const;
size_type index(const cell_descriptor& c) const;
std::pair<basis_vector_iterator,basis_vector_iterator> basis_vectors() const;
std::pair<basis_vector_iterator,basis_vector_iterator> reciprocal_basis_vectors() const;
vector_type origin(const cell_descriptor& c) const;
vector_type coordinate(const cell_descriptor& c, const vector_type& p) const;
vector_type momentum(const vector_type& m) const;

sites_size_type num_sites() const;
bonds_size_type num_bonds() const;
std::pair<site_iterator,site_iterator> sites() const;
std::pair<bond_iterator,bond_iterator> bonds() const;
bond_descriptor bond(bonds_size_type i) const;
neighbors_size_type num_neighbors (const site_descriptor& v) const;
std::pair<neighbor_bond_iterator,neighbor_bond_iterator> neighbor_bonds (const site_descriptor& v) const;
std::pair<neighbor_iterator,neighbor_iterator> neighbors (const site_descriptor& v) const;
site_descriptor neighbor (const site_descriptor& v, neighbors_size_type i) const;

site_descriptor source(const edge_descriptor& b) const;
site_descriptor target(const edge_descriptor& b) const;

vertices_size_type num_vertices() const;
edges_size_type num_edges() const;
std::pair<vertex_iterator,vertex_iterator> vertices() const;
std::pair<edge_iterator,edge_iterator> edges() const;
degree_size_type out_degree (const vertex_descriptor& v) const;
degree_size_type in_degree (const vertex_descriptor& v) const;
degree_size_type degree (const vertex_descriptor& v) const;
out_edge_iterator out_edges (const vertex_descriptor& v) const;
in_edge_iterator in_edges (const vertex_descriptor& v) const;
std::pair<adjacency_iterator,adjacency_iterator> adjacent_vertices (const site_descriptor& v) const;

vertex_descriptor vertex(vertices_size_type i) const;
site_descriptor site(sites_size_type i) const;

double parity(const site_descriptor& v) const;
bool is_bipartite() const;

unsigned int bond_type(const bond_descriptor& b) const;
unsigned int edge_type(const edge_descriptor& e) const;
unsigned int site_type(const site_descriptor& s) const;
unsigned int vertex_type(const vertex_descriptor& v) const;
const vector_type& bond_vector(const bond_descriptor& b) const;
const vector_type& bond_vector_relative(const bond_descriptor& b) const;

size_type index(const vertex_descriptor& ) const;
size_type index(const edge_descriptor& ) const;

unsigned int inhomogeneous_edge_type(const edge_descriptor& e) const;
unsigned int inhomogeneous_bond_type(const bond_descriptor& b) const;
unsigned int inhomogeneous_vertex_type(const vertex_descriptor& v) const;
unsigned int inhomogeneous_site_type(const site_descriptor& s) const;

bool inhomogeneous() const;
bool inhomogeneous_sites() const;
bool inhomogeneous_bonds() const;
bool inhomogeneous_vertices() const;
bool inhomogeneous_edges() const;

const std::vector<double>& coordinate(const site_descriptor& s) const;
Parameters coordinate_as_parameter(const bond_descriptor& e) const;
Parameters coordinate_as_parameter(const site_descriptor& v) const;
};

}

The graph_helper class

is derived from LatticeLibrary and templated on the graph type, which defaults to coordinate_graph_type. An application deriving from this class gets easy construction of a graph from parameters and XML lattice specifications as well as easy access the the graph's properties.

Type members

  typedef G graph_type;
is the type of graphs created by the graph_helper.
  typedef lattice_graph<hypercubic_lattice<coordinate_lattice<simple_lattice<GraphUnitCell> > >,graph_type> lattice_type;
is the type of lattice currently supported by the graph_helper. Addition of new lattuce types (besides hypercubic_lattice) will require redesigning this class.
  typedef typename graph_traits<graph_type>::vertex_iterator vertex_iterator;
typedef typename graph_traits<graph_type>::edge_iterator edge_iterator;
typedef typename graph_traits<graph_type>::out_edge_iterator out_edge_iterator;
typedef typename graph_traits<graph_type>::in_edge_iterator in_edge_iterator;
typedef typename graph_traits<graph_type>::edge_descriptor edge_descriptor;
typedef typename graph_traits<graph_type>::vertex_descriptor vertex_descriptor;
typedef typename graph_traits<graph_type>::vertices_size_type vertices_size_type;
typedef typename graph_traits<graph_type>::edges_size_type edges_size_type;
typedef typename graph_traits<graph_type>::degree_size_type degree_size_type;
typedef typename graph_traits<graph_type>::adjacency_iterator adjacency_iterator;
are typedefs for the common types associated with graphs, obtained from the graph_traits class.
  typedef typename graph_traits<graph_type>::site_iterator site_iterator;
typedef typename graph_traits<graph_type>::bond_iterator bond_iterator;
typedef typename graph_traits<graph_type>::neighbor_bond_iterator neighbor_bond_iterator;
typedef typename graph_traits<graph_type>::bond_descriptor bond_descriptor;
typedef typename graph_traits<graph_type>::site_descriptor site_descriptor;
typedef typename graph_traits<graph_type>::sites_size_type sites_size_type;
typedef typename graph_traits<graph_type>::bonds_size_type bonds_size_type;
typedef typename graph_traits<graph_type>::neighbors_size_type neighbors_size_type;
typedef typename graph_traits<graph_type>::neighbor_iterator neighbor_iterator;
are typedefs using the alternative lattice model language of sites and bonds instead of vertices and edges, as discussed under the graph_traits class.
  typedef typename lattice_traits<lattice_type>::unit_cell_type unit_cell_type;
typedef typename lattice_traits<lattice_type>::cell_descriptor cell_descriptor;
typedef typename lattice_traits<lattice_type>::offset_type offset_type;
typedef typename lattice_traits<lattice_type>::vector_type vector_type;
typedef typename lattice_traits<lattice_type>::size_type size_type;
typedef typename lattice_traits<lattice_type>::cell_iterator cell_iterator;
typedef typename lattice_traits<lattice_type>::cell_iterator momentum_iterator;
typedef typename lattice_traits<lattice_type>::cell_iterator basis_vector_iterator;
typedef typename lattice_traits<lattice_type>::cell_iterator boundary_crossing_type;
are typedefs for the common types associated with lattices, obtained from the the lattice_traits class.

Constructors and Destructor

  graph_helper(std::istream& in, const Parameters& p);

constructs the graph_helper and builds a graph, given an input stream in and a set of parameters p.

The  input stream is expected to be in XML format,  containing a <LATTICES> element, as given by the Lattice XML schema on http://xml.comp-phys.org. This is used to construct a LatticeLibrary. Once the LatticeLibrary is constructed, the graph is constructed. The graph is picked in the following way:

If both or none of these parameters are set, or there is not a graph or lattice with the name, a std::runtime_error is thrown.

  graph_helper(const alps::Parameters& p);

this constructor first checks for a LATTICE_LIBRARY parameter and opens the file given by the parameter. If no such parameter is defined, it tries to open a file called "lattices.xml". Then the contents of the file are read into a LatticeLibrary, and the graph created as discussed above.

  ~graph_helper();

destroys the lattuce library and the graph.

Member functions

  lattice_type& lattice();
const lattice_type& lattice() const;

provide access to the lattice, if the graph was constructed from a lattice.

  graph_type& graph();
const graph_type& graph() const;

provide access to the graph.

  bool inhomogeneous_sites() const;
bool inhomogeneous_vertices() const;

return true if the lattice has site disorder.

  bool inhomogeneous_bonds() const;
bool inhomogeneous_edges() const;

return true if the lattice has bond disorder.

  bool inhomogeneous() const;

returns true if the lattice has either site or bond disorder.

  Parameters coordinate_as_parameter(const site_descriptor& v) const;

returns a Parameters object setting the values of the x, y (for 2-and 3-dimensional graphs), and z (for 3-dimensional graphs) to the values of the x, y, and z coordinate of the site (vertex) passed to the function.

  Parameters coordinate_as_parameter(const bond_descriptor& e) const;

returns a Parameters object setting the values of the x, y (for 2-and 3-dimensional graphs), and z (for 3-dimensional graphs) to the values each of the mean value of the x, y, and z coordinate of the sites (vertices) connected by the bond (edge) passed to the function.

Lattice member functions

  size_type volume() const;
const unit_cell_type& unit_cell() const;
cell_descriptor cell(const offset_type& o) const;
std::pair<cell_iterator,cell_iterator> cells() const;
const offset_type& offset(const cell_descriptor& c) const;
bool on_lattice(const offset_type& o) const;
std::pair<bool,boundary_crossing_type> shift(offset_type& o, const offset_type& s) const;
size_type index(const cell_descriptor& c) const;
std::pair<basis_vector_iterator,basis_vector_iterator> basis_vectors() const;
std::pair<basis_vector_iterator,basis_vector_iterator> reciprocal_basis_vectors() const;
vector_type origin(const cell_descriptor& c) const;
vector_type coordinate(const cell_descriptor& c, const vector_type& p) const;
vector_type momentum(const vector_type& m) const;
provide shortcuts to the corresponding lattuce  library functions in lattice.h which take the lattice as additional argument.

Graph member functions

  vertices_size_type num_vertices() const;
edges_size_type num_edges() const;
std::pair<vertex_iterator,vertex_iterator> vertices() const;
std::pair<edge_iterator,edge_iterator> edges() const;
degree_size_type out_degree (const vertex_descriptor& v) const;
degree_size_type in_degree (const vertex_descriptor& v) const;
degree_size_type degree (const vertex_descriptor& v) const;
out_edge_iterator out_edges (const vertex_descriptor& v) const;
in_edge_iterator in_edges (const vertex_descriptor& v) const;
std::pair<adjacency_iterator,adjacency_iterator> adjacent_vertices (const site_descriptor& v) const;
 site_descriptor source(const edge_descriptor& b) const;
site_descriptor target(const edge_descriptor& b) const;

provide shortcuts to the corresponding Boost graph library functions which take the graph as additional argument.

  sites_size_type num_sites() const;
bonds_size_type num_bonds() const;
std::pair<site_iterator,site_iterator> sites() const;
std::pair<bond_iterator,bond_iterator> bonds() const;
bond_descriptor bond(bonds_size_type i) const;
neighbors_size_type num_neighbors (const site_descriptor& v) const;
std::pair<neighbor_bond_iterator,neighbor_bond_iterator> neighbor_bonds (const site_descriptor& v) const;
std::pair<neighbor_iterator,neighbor_iterator> neighbors (const site_descriptor& v) const;
site_descriptor neighbor (const site_descriptor& v, neighbors_size_type i) const;

are the same as above, but using the lattice model notation instead of the Boost graph library notation, as discussed under the graph_traits class.

  vertex_descriptor vertex(vertices_size_type i) const;
site_descriptor site(sites_size_type i) const;

creates a vertex (site) descriptor for the i-th vertex (site) on the graph.

  bool is_bipartite() const;

checks whether the graph is bipartite.

  double parity(const site_descriptor& v) const;

reads the parity_t property of the graph and returns +1 or -1 depending on whcih sublattice the site vertex) is located on.

  type_type bond_type(const bond_descriptor& b) const;
type_type edge_type(const edge_descriptor& e) const;

returns the bond type (same as edge type) of the bond (edge) passed by reading the bond_type_t (same as edge_type_t) property. Note that, even when disorder has been applied to the graph, this still returns the original type. The return type type_type is defined under graphproperties.h.

  type_type site_type(const site_descriptor& s) const;
type_type vertex_type(const edge_descriptor& v) const;

returns the site type (same as vertex type) of the site vertex) passed by reading the site_type_t (same as vertex_type_t) property. Note that, even when disorder has been applied to the graph, this still returns the original type. The return type type_type is defined under graphproperties.h.

  type_type inhomogeneous_bond_type(const bond_descriptor& b) const;
type_type inhomogeneous_edge_type(const edge_descriptor& e) const;

returns the bond_type (egde_type) of a bond (edge) of the graph, after optional disordering has been applied. For homogeneous graphs this is the same as bond_type(b) or edge_type(e). The return type type_type is defined under graphproperties.h.

  type_type inhomogeneous_vertex_type(const vertex_descriptor& v) const;
type_type inhomogeneous_site_type(const site_descriptor& s) const;

returns the site_type (vertex_type) of a site (vertex) of the graph, after optional disordering has been applied. For homogeneous graphs this is the same as site_type(s) or vertex_type(v). The return type type_type is defined under graphproperties.h.

  const std::coordinate_type& coordinate(const site_descriptor& s) const;

returns the coordinate of a site or vertex. The return type coordinate_type is defined under graphproperties.h.

  const vector_type& bond_vector(const bond_descriptor& b) const;

returns the vector connecting the two sites of the bond

  const vector_type& bond_vector_relative(const bond_descriptor& b) const;

returns the vector connecting the two sites of the bond, each coordinate represents the component in the direction of the corresponding basis vector of the lattice and the length is relative to the extent of the lattice in that direction.

  size_type index(const vertex_descriptor& ) const;
size_type index(const edge_descriptor& ) const;

return the index (number) of the vertex or edge in the graph by accessing the vertex_index_t or edge_index_t property map.


copyright (c) 1994-2010 by Matthias Troyer

Distributed under the Boost Software License, Version 1.0. (See http://www.boost.org/LICENSE_1_0.txt)