11 #define BOOST_NO_CXX11_RVALUE_REFERENCES 12 #define BOOST_NO_CXX11_REF_QUALIFIERS 15 #include <boost/graph/graph_traits.hpp> 16 #include <boost/graph/adjacency_list.hpp> 17 #include <boost/graph/dijkstra_shortest_paths.hpp> 18 #include <boost/graph/breadth_first_search.hpp> 21 #include "fwAtomsPatch/exceptions/UnknownVersion.hpp" 23 #include "fwAtomsPatch/VersionsGraph.hpp" 32 VertexVisitor(std::vector< std::string >* vector) : m_vector(vector)
36 void discover_vertex(VersionsGraph::NodeIDType n, VersionsGraph::GraphType g)
38 m_vector->push_back( g[n].getVersionName());
42 std::vector< std::string >* m_vector;
60 NodeIDType newNode = this->createOrUpdateNode(node);
61 m_nodes[node] = newNode;
69 EdgeIDType newEdge = this->createEdge(edge);
70 m_edges[edge] = newEdge;
76 const std::string& target)
78 NodeIDType originID = this->getNode(origin);
79 NodeIDType targetID = this->getNode(target);
80 return this->shortestPath(this->getNode(originID), this->getNode(targetID));
87 VersionSeriesType serie;
92 std::vector< NodeIDType > predecessor( ::boost::num_vertices(m_graph) );
93 std::vector< int > distances( ::boost::num_vertices(m_graph) );
95 const NodeIDType& vOrig = m_nodes[origin];
96 ::boost::dijkstra_shortest_paths(m_graph, vOrig,
97 ::boost::weight_map(
get(&EdgeType::m_weight, m_graph))
98 .predecessor_map(&predecessor[0])
99 .distance_map(::boost::make_iterator_property_map(distances.begin(),
100 ::boost::get(::
boost::
105 NodeIDType current = m_nodes[target];
107 while(current != predecessor[current])
109 serie.insert(serie.begin(), current);
110 current = predecessor[current];
121 return m_graph[nodeID];
129 ExistingNodesType::const_iterator it;
130 for(it = m_nodes.begin(); it != m_nodes.end(); ++it)
132 if(it->first.getVersionName() == name)
138 if(it == m_nodes.end())
140 throw ::fwAtomsPatch::exceptions::UnknownVersion(
"There is no version named \"" + name +
"\".");
151 bool success =
false;
153 ::boost::tie(edgeID,success) = ::boost::edge(origin, target, m_graph);
154 OSLM_ASSERT(
"There is no edge between '" << m_graph[origin].getVersionName() <<
"' and '" 155 << m_graph[target].getVersionName() <<
"'.", success);
156 return m_graph[edgeID];
164 NodeType origin = this->getNode(originID);
165 NodeType target = this->getNode(targetID);
166 EdgeType edge = this->getEdge(originID, targetID);
168 bool success =
false;
170 LinkDescriptor::LinksType::const_iterator linkIt;
174 linkIt = links.find(current);
175 if(linkIt != links.end())
177 result = linkIt->second;
183 VersionDescriptor::VersionsType::const_iterator versIt;
184 VersionDescriptor::VersionsType::const_iterator versItEnd = target.
getVersions().end();
185 for(versIt = target.
getVersions().begin(); versIt != versItEnd; ++versIt)
188 if(current.first == versIt->first)
197 return std::make_pair(result, success);
202 VersionsGraph::NodeIDType VersionsGraph::createOrUpdateNode(
const NodeType& node)
204 ExistingNodesType::const_iterator cIt = m_nodes.find(node);
205 if(cIt != m_nodes.end())
212 NodeIDType v = ::boost::add_vertex(m_graph);
220 VersionsGraph::EdgeIDType VersionsGraph::createEdge(
const EdgeType& edge)
226 bool success =
false;
228 ::boost::tie(newEdge, success) = ::boost::add_edge(origin, target, edge, m_graph);
240 std::vector< std::string > vector;
245 VersionsGraph::NodeIDType nodeId = this->getNode(currentVersion);
246 ::boost::breadth_first_search( m_graph, nodeId, ::boost::visitor(vis) );
247 vector.erase(vector.begin());
FWATOMSPATCH_API ~VersionsGraph()
#define OSLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
const VersionsType & getVersions() const
Returns versions.
const std::string & getOriginVersion() const
Returns origin version.
Version descriptor used to identify a version.
Contains base functionalities used to transform objects from a version to another.
::boost::unique_lock< ReadWriteMutex > WriteLock
Defines a lock of write type for read/write mutex.
Thrown when a given object version is unknown and can't be processed.
FWATOMSPATCH_API std::vector< std::string > getConnectedVersions(const std::string ¤tVersion)
Get connected versions.
FWATOMSPATCH_API LinkedVersionType getLinkedVersion(const NodeIDType &originID, const NodeIDType &targetID, LinkDescriptor::VersionIDType current)
Returns the linked version of the current version and a boolean to say if a match has been found...
FWATOMSPATCH_API NodeType getNode(const NodeIDType &nodeID)
Returns the node matching given node ID.
const std::string & getTargetVersion() const
Returns target version.
Link descriptor used to identify a link between two versions.
::boost::shared_lock< ReadWriteMutex > ReadLock
Defines a lock of read type for read/write mutex.
FWATOMSPATCH_API void addNode(NodeType node)
Add a new version described by the given node.
FWATOMSPATCH_API EdgeType getEdge(const NodeIDType &origin, const NodeIDType &target)
Returns the edge located between given node IDs.
std::pair< std::string, std::string > VersionIDType
VersionID used to link type and version.
FWATOMSPATCH_API VersionsGraph()
std::map< VersionIDType, VersionIDType > LinksType
Links used to link two versions.
const LinksType & getLinks() const
Returns map of links between versions.
FWATOMSPATCH_API void addEdge(EdgeType edge)
Add a new edge described by the given edge.
FWATOMSPATCH_API VersionSeriesType shortestPath(const std::string &origin, const std::string &target)
Compute shortest path between two data version (i.e nodes).
This file defines SpyLog macros. These macros are used to log messages to a file or to the console du...