-/* Copyright (C) 2006-2008 Joris Mooij [j dot mooij at science dot ru dot nl]
- Radboud University Nijmegen, The Netherlands
-
+/* Copyright (C) 2006-2008 Joris Mooij [joris dot mooij at tuebingen dot mpg dot de]
+ Radboud University Nijmegen, The Netherlands /
+ Max Planck Institute for Biological Cybernetics, Germany
+
This file is part of libDAI.
libDAI is free software; you can redistribute it and/or modify
*/
+/// \file
+/// \brief Defines classes Region, FRegion and RegionGraph
+/// \todo Improve documentation
+
+
#ifndef __defined_libdai_regiongraph_h
#define __defined_libdai_regiongraph_h
/// A Region is a set of variables with a counting number
class Region : public VarSet {
- protected:
+ private:
/// Counting number
double _c;
/// Construct Region from a VarSet and a counting number
Region(const VarSet & x, double c) : VarSet(x), _c(c) {}
-
- /// Copy constructor
- Region(const Region & x) : VarSet(x), _c(x._c) {}
-
- /// Assignment operator
- Region & operator=(const Region & x) {
- if( this != &x ) {
- VarSet::operator=(x);
- _c = x._c;
- }
- return *this;
- }
/// Provide read access to counting number
const double & c() const { return _c; }
/// A FRegion is a factor with a counting number
class FRegion : public Factor {
- protected:
+ private:
/// Counting number
double _c;
/// Constructs FRegion from a Factor and a counting number
FRegion( const Factor & x, double c ) : Factor(x), _c(c) {}
-
- /// Copy constructor
- FRegion( const FRegion & x ) : Factor(x), _c(x._c) {}
-
- /// Assignment operator
- FRegion & operator=(const FRegion & x) {
- if( this != &x ) {
- Factor::operator=(x);
- _c = x._c;
- }
- return *this;
- }
/// Provide read access to counting number
const double & c() const { return _c; }
/// A RegionGraph is a bipartite graph consisting of outer regions (type FRegion) and inner regions (type Region)
class RegionGraph : public FactorGraph {
public:
+ /// Stores the neighborhood structure
BipartiteGraph G;
+
+ /// The outer regions (corresponding to nodes of type 1)
std::vector<FRegion> ORs;
+
+ /// The inner regions (corresponding to nodes of type 2)
std::vector<Region> IRs;
- protected:
- /// Give back the OR index that corresponds to a factor index
+ /// Stores for each factor index the index of the outer region it belongs to
std::vector<size_t> fac2OR;
/// Constructs a RegionGraph from a FactorGraph, a vector of outer regions, a vector of inner regions and a vector of edges
RegionGraph( const FactorGraph &fg, const std::vector<Region> &ors, const std::vector<Region> &irs, const std::vector<std::pair<size_t,size_t> > &edges );
-
+
/// Constructs a RegionGraph from a FactorGraph and a vector of outer VarSets (CVM style)
RegionGraph( const FactorGraph &fg, const std::vector<VarSet> &cl );
- /// Copy constructor
- RegionGraph( const RegionGraph &x ) : FactorGraph(x), G(x.G), ORs(x.ORs), IRs(x.IRs), fac2OR(x.fac2OR) {}
-
- /// Assignment operator
- RegionGraph & operator=( const RegionGraph &x ) {
- if( this != &x ) {
- FactorGraph::operator=( x );
- G = x.G;
- ORs = x.ORs;
- IRs = x.IRs;
- fac2OR = x.fac2OR;
- }
- return *this;
- }
-
- /// Create (virtual default constructor)
- virtual RegionGraph* create() const {
- return new RegionGraph();
- }
-
- /// Clone (virtual copy constructor)
- virtual RegionGraph* clone() const {
- return new RegionGraph(*this);
- }
+ /// Clone *this (virtual copy constructor)
+ virtual RegionGraph* clone() const { return new RegionGraph(*this); }
/// Set the content of the I'th factor and make a backup of its old content if backup == true
virtual void setFactor( size_t I, const Factor &newFactor, bool backup = false ) {
- FactorGraph::setFactor( I, newFactor, backup );
- RecomputeOR( I );
+ FactorGraph::setFactor( I, newFactor, backup );
+ RecomputeOR( I );
}
/// Set the contents of all factors as specified by facs and make a backup of the old contents if backup == true
VarSet ns;
for( std::map<size_t, Factor>::const_iterator fac = facs.begin(); fac != facs.end(); fac++ )
ns |= fac->second.vars();
- RecomputeORs( ns );
+ RecomputeORs( ns );
}
/// Recompute all outer regions involving factor I
void RecomputeOR( size_t I );
- /// Send RegionGraph to output stream
+ // Friends
friend std::ostream & operator << ( std::ostream & os, const RegionGraph & rg );
};