gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-252-gf9a3f78
a Global And Modular Bsm Inference Tool
Gambit::ModelHierarchy Class Reference

Model hierarchy tree class. More...

#include <modelgraph.hpp>

Collaboration diagram for Gambit::ModelHierarchy:

Classes

class  colorWriter
 Helper class for drawing the model hierarchy graph (edges) More...
 
struct  edge_color_t
 Property tag for adding color property to edges. More...
 
class  labelWriter
 Helper class for drawing the model hierarchy graph (labels) More...
 

Private Types

typedef std::vector< primary_model_functor * > primodel_vec
 Shorthand for vector of pointers to primary model functors. More...
 
typedef boost::property< edge_color_t, std::string > EdgeColor
 Typedefs for central boost (model) graph. More...
 
typedef boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, functor *, EdgeColorModelGraphType
 
typedef boost::graph_traits< ModelGraphType >::vertex_descriptor ModelVertexID
 
typedef boost::graph_traits< ModelGraphType >::edge_descriptor ModelEdgeID
 
typedef boost::property_map< ModelGraphType, boost::vertex_index_t >::type ModelIndexMap
 

Private Attributes

const Models::ModelFunctorClawboundClaw
 The model claw that provides all the model info. More...
 
str filename
 Output filename. More...
 
bool verbose
 Turn on verbose operation. More...
 
ModelGraphType modelGraph
 The central boost graph object for the model hierarchy. More...
 
void addFunctorsToGraph (const primodel_vec &)
 Add model functors (vertices) to model hierarchy graph. More...
 
void makeGraph (const primodel_vec &)
 Add edges (relationships) to model hierarchy graph. More...
 
 ModelHierarchy (const Models::ModelFunctorClaw &, const primodel_vec &, str, bool)
 Constructor. More...
 

Detailed Description

Model hierarchy tree class.

Definition at line 36 of file modelgraph.hpp.

Member Typedef Documentation

◆ EdgeColor

typedef boost::property<edge_color_t, std::string> Gambit::ModelHierarchy::EdgeColor
private

Typedefs for central boost (model) graph.

Definition at line 43 of file modelgraph.hpp.

◆ ModelEdgeID

typedef boost::graph_traits<ModelGraphType>::edge_descriptor Gambit::ModelHierarchy::ModelEdgeID
private

Definition at line 46 of file modelgraph.hpp.

◆ ModelGraphType

typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, functor*, EdgeColor> Gambit::ModelHierarchy::ModelGraphType
private

Definition at line 44 of file modelgraph.hpp.

◆ ModelIndexMap

typedef boost::property_map<ModelGraphType,boost::vertex_index_t>::type Gambit::ModelHierarchy::ModelIndexMap
private

Definition at line 47 of file modelgraph.hpp.

◆ ModelVertexID

typedef boost::graph_traits<ModelGraphType>::vertex_descriptor Gambit::ModelHierarchy::ModelVertexID
private

Definition at line 45 of file modelgraph.hpp.

◆ primodel_vec

Shorthand for vector of pointers to primary model functors.

Definition at line 51 of file modelgraph.hpp.

Constructor & Destructor Documentation

◆ ModelHierarchy()

Gambit::ModelHierarchy::ModelHierarchy ( const Models::ModelFunctorClaw claw,
const primodel_vec pmv,
str  file,
bool  talky 
)

Constructor.

ModelHierarchy method definitions Creates a graph of the model hierarchy for visualisation purposes.

Constructor

Definition at line 50 of file modelgraph.cpp.

References makeGraph().

51  : boundClaw(&claw), filename(file), verbose(talky)
52  {
53  makeGraph(pmv);
54  }
str filename
Output filename.
Definition: modelgraph.hpp:92
bool verbose
Turn on verbose operation.
Definition: modelgraph.hpp:95
const Models::ModelFunctorClaw * boundClaw
The model claw that provides all the model info.
Definition: modelgraph.hpp:89
void makeGraph(const primodel_vec &)
Add edges (relationships) to model hierarchy graph.
Definition: modelgraph.cpp:57
Here is the call graph for this function:

Member Function Documentation

◆ addFunctorsToGraph()

void Gambit::ModelHierarchy::addFunctorsToGraph ( const primodel_vec primaryModelFunctors)
private

Add model functors (vertices) to model hierarchy graph.

Add model functors to the modelGraph.

Definition at line 137 of file modelgraph.cpp.

References modelGraph.

Referenced by makeGraph().

138  {
139  // - model functors go into modelGraph
140  for (std::vector<primary_model_functor *>::const_iterator
141  it = primaryModelFunctors.begin();
142  it != primaryModelFunctors.end(); ++it)
143  {
144  //if ( (*it)->status() != 0 )
145  boost::add_vertex(*it, modelGraph);
146  }
147  }
ModelGraphType modelGraph
The central boost graph object for the model hierarchy.
Definition: modelgraph.hpp:98
Here is the caller graph for this function:

◆ makeGraph()

void Gambit::ModelHierarchy::makeGraph ( const primodel_vec primaryModelFunctors)
private

Add edges (relationships) to model hierarchy graph.

Figure out relationships between primary model functors.

Definition at line 57 of file modelgraph.cpp.

References addFunctorsToGraph(), boundClaw, filename, Gambit::Printers::HDF5::get, Gambit::Models::ModelFunctorClaw::get_best_friends(), Gambit::Models::ModelFunctorClaw::get_parent(), modelGraph, and verbose.

Referenced by ModelHierarchy().

58  {
59  boost::graph_traits<ModelGraphType>::vertex_iterator vi, vi_end;
60  std::map<str, ModelVertexID> vertexIDmap;
61  str model;
62  // The property map which holds the edge colors:
63  boost::property_map<ModelGraphType, edge_color_t>::type color(boost::get(edge_color_t(),modelGraph));
64 
65  if (verbose) std::cout<<std::endl<<"Determining model hierarchy graph..."<<std::endl;
66 
67  // Add all primary model functors to the model hierarchy graph
68  addFunctorsToGraph(primaryModelFunctors);
69 
70  // Loop over all vertices (models) in modelGraph and create a map from
71  // model names to vertex IDs.
72  for (boost::tie(vi, vi_end) = boost::vertices(modelGraph);
73  vi != vi_end; ++vi)
74  {
75  model = (*modelGraph[*vi]).origin();
76  vertexIDmap[model] = *vi;
77  if (verbose) std::cout<<" Vertex added: "<<model<<std::endl;
78  }
79 
80  // Loop over all vertices (models) in vertexIDmap, look up the 'parent'
81  // of each one in the parents database boundClaw->myParentsDB, and add
82  // an edge from parent to child in the model graph. Do the same with
83  // direct (best) friends.
84  typedef std::map<str, ModelVertexID>::iterator vertexIDmap_it;
85  for (vertexIDmap_it vimap = vertexIDmap.begin();
86  vimap != vertexIDmap.end(); vimap++)
87  {
88  model = vimap->first;
89  str parent = boundClaw->get_parent(model);
90  if (verbose) std::cout<<model<<"; parent: "<<parent<<std::endl;;
91  // If there is a parent, add an edge between parent and child
92  if (parent != "none")
93  {
94  boost::add_edge(vertexIDmap[parent], vertexIDmap[model], modelGraph);
95  if (verbose) std::cout<<" Edge added: "<<model<<" ---> "<<parent<<std::endl;
96  }
97  // Add edges with all this model's best friends. Might want to make these another colour in future.
98  std::set<str> friends = boundClaw->get_best_friends(model);
99  for (auto it = friends.begin(); it != friends.end(); ++it)
100  {
101  boost::add_edge(vertexIDmap[*it], vertexIDmap[model], modelGraph);
102 
103  // Get the descriptor for the edge we just added
104  ModelEdgeID e = boost::edge(vertexIDmap[*it], vertexIDmap[model], modelGraph).first;
105 
106  // Set the color property for this edge to "red"
107  boost::put(color,e,"red");
108 
109  if (verbose)
110  {
111  std::cout<<model<<"; friend: "<<*it<<std::endl;;
112  std::cout<<" Edge added: "<<model<<" ---> "<<*it<<std::endl;
113  }
114  }
115  }
116  if (verbose) std::cout<<std::endl;
117 
118 #ifdef HAVE_GRAPHVIZ
119  // Property writer for graph; see http://www.boost.org/doc/libs/1_36_0/libs/graph/doc/write-graphviz.html
120  // Also for valid properties see http://www.graphviz.org/pdf/dotguide.pdf
121  struct graphWriter
122  {
123  void operator()(std::ostream& out) const
124  {
125  out << "rankdir = LR;" << std::endl; // Turn graph orientation left to right.
126  out << "edge [dir=back];" << std::endl; // Reverse all the arrows
127  }
128  };
129  // Generate graphviz plot
130  std::ofstream outf(filename);
131  // args: output stream, vertex list, vertex property writer (PW), edge PW, graph PW.
132  write_graphviz(outf, modelGraph, labelWriter(&modelGraph), colorWriter(&modelGraph), graphWriter());
133 #endif
134  }
str filename
Output filename.
Definition: modelgraph.hpp:92
bool verbose
Turn on verbose operation.
Definition: modelgraph.hpp:95
boost::graph_traits< ModelGraphType >::edge_descriptor ModelEdgeID
Definition: modelgraph.hpp:46
str get_parent(const str &) const
Retrieve the parent model for a given model.
Definition: models.cpp:244
const Models::ModelFunctorClaw * boundClaw
The model claw that provides all the model info.
Definition: modelgraph.hpp:89
std::string str
Shorthand for a standard string.
Definition: Analysis.hpp:35
std::set< str > get_best_friends(const str &model) const
Retrieve the best friends for a given model.
Definition: models.cpp:262
ModelGraphType modelGraph
The central boost graph object for the model hierarchy.
Definition: modelgraph.hpp:98
void addFunctorsToGraph(const primodel_vec &)
Add model functors (vertices) to model hierarchy graph.
Definition: modelgraph.cpp:137
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ boundClaw

const Models::ModelFunctorClaw* Gambit::ModelHierarchy::boundClaw
private

The model claw that provides all the model info.

Definition at line 89 of file modelgraph.hpp.

Referenced by makeGraph().

◆ filename

str Gambit::ModelHierarchy::filename
private

Output filename.

Definition at line 92 of file modelgraph.hpp.

Referenced by makeGraph().

◆ modelGraph

ModelGraphType Gambit::ModelHierarchy::modelGraph
private

The central boost graph object for the model hierarchy.

Definition at line 98 of file modelgraph.hpp.

Referenced by addFunctorsToGraph(), and makeGraph().

◆ verbose

bool Gambit::ModelHierarchy::verbose
private

Turn on verbose operation.

Definition at line 95 of file modelgraph.hpp.

Referenced by makeGraph().


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