The graph policy is a class which implements the graph interface of its host class (cage). A graph is defined by its vertex and edge property through template arguments and its graph description as constructor argument. The following defintion of a graph is defined by a city property which represents a vertex and a road property which represents an edge:
The following property is a very simple and basic property for edges and vertices which does not contain any further information. Therefore, it is called SimpleProperty. The SimpleProperty is used when no other property is specified.
struct SimpleProperty {
};
A property can be user defined and can contain arbitrary data:
struct City {
std::string cityName;
unsigned nInhabitants;
};
struct Road {
std::string roadName;
};
The following source code provides the full skeleton of a graph policy. Nevertheless, the predefined boost graph library graph policy (graybat::graphPolicy::BGL) is a good starting point to be used in a cage. A custom implementation might only be necessary if there exist some special requirements.
namespace graphPolicy {
template <class T_VertexProperty, class T_EdgeProperty>
class GraphPolicySkeleton {
using VertexProperty = T_VertexProperty;
using EdgeProperty = T_EdgeProperty;
using VertexDescription = ...;
using EdgeDescription = ...;
using GraphDescription = ...;
using InEdgeIter = ...;
using OutEdgeIter = ...;
using AdjacentVertexIter = ...;
using AllVertexIter = ...;
GraphPolicySkeleton(GraphDescription description) {...}
std::pair<AllVertexIter, AllVertexIter> getVertices() {...}
std::pair<EdgeID, bool> getEdge(const VertexID source, const VertexID target) {...}
std::pair<AdjacentVertexIter, AdjacentVertexIter> getAdjacentVertices(const VertexID id) {...}
std::pair<OutEdgeIter, OutEdgeIter> getOutEdges(const VertexID id) {...}
std::pair<InEdgeIter, InEdgeIter> getInEdges(const VertexID id){...}
std::pair<VertexID, VertexProperty>& getVertexProperty(const VertexID vertex) {...}
std::pair<EdgeID, EdgeProperty>& getEdgeProperty(const EdgeID edge) {...}
VertexID getEdgeTarget(const EdgeID edge) {...}
VertexID getEdgeSource(const EdgeID edge) {...}
}
}
}
Further Links