-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from alex-87/v1.17---Isomorphism
V1.17 isomorphism
- Loading branch information
Showing
6 changed files
with
227 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
|
||
#include "include/Isomorph.hh" | ||
#include "../model/include/Hypergraphe.hh" | ||
#include "../model/include/HyperVertex.hh" | ||
#include "../model/include/HyperEdge.hh" | ||
#include <boost/graph/isomorphism.hpp> | ||
|
||
Isomorph::Isomorph(const boost::shared_ptr<HypergrapheAbstrait>& ptrHypergrapheAbstraitA, | ||
const boost::shared_ptr<HypergrapheAbstrait>& ptrHypergrapheAbstraitB) | ||
: _ptrHypergrapheAbstraitA(ptrHypergrapheAbstraitA), | ||
_ptrHypergrapheAbstraitB(ptrHypergrapheAbstraitB) { | ||
|
||
} | ||
|
||
void | ||
Isomorph::runAlgorithme() { | ||
|
||
bool ret = false; | ||
graph_t graphA( _ptrHypergrapheAbstraitA->getHyperEdgeList().size() ), | ||
graphB( _ptrHypergrapheAbstraitB->getHyperEdgeList().size() ); | ||
|
||
#pragma omp parallel sections | ||
{ | ||
|
||
#pragma omp section | ||
{ | ||
hypergraphTranspose(_ptrHypergrapheAbstraitA, graphA); | ||
} | ||
|
||
#pragma omp section | ||
{ | ||
hypergraphTranspose(_ptrHypergrapheAbstraitB, graphB); | ||
} | ||
|
||
} | ||
|
||
std::vector<boost::graph_traits<graph_t>::vertex_descriptor> f( _ptrHypergrapheAbstraitA->getHyperEdgeList().size() ); | ||
|
||
boost::property_map<graph_t, boost::vertex_index_t>::type | ||
v_index_map = get(boost::vertex_index, graphA); | ||
|
||
ret = boost::isomorphism( | ||
graphA, | ||
graphB, | ||
boost::isomorphism_map( | ||
boost::make_iterator_property_map(f.begin(), v_index_map, f[0]) | ||
) | ||
); | ||
|
||
_result.setBooleanResult( ret ); | ||
} | ||
|
||
void | ||
Isomorph::hypergraphTranspose(const boost::shared_ptr<HypergrapheAbstrait>& hpg, graph_t& graphOut) { | ||
|
||
std::vector<boost::graph_traits<graph_t>::vertex_descriptor> | ||
v(hpg->getHyperEdgeList().size()); | ||
|
||
boost::property_map<graph_t, boost::vertex_index_t>::type | ||
v_index_map = get(boost::vertex_index, graphOut); | ||
|
||
boost::graph_traits<graph_t>::vertex_iterator i, end; | ||
int id = 0; | ||
for (boost::tie(i, end) = boost::vertices(graphOut); i != end; ++i, ++id) { | ||
put(v_index_map, *i, id); | ||
v[id] = *i; | ||
} | ||
|
||
for(int u=0; u<hpg->getHyperEdgeList().size(); u++ ) { | ||
for(int h=0; h<hpg->getHyperEdgeList().at(u)->getHyperVertexList().size(); h++) { | ||
for(int q=0; q<hpg->getHyperEdgeList().at(u)->getHyperVertexList().at(h)->getHyperEdgeList().size(); q++) { | ||
boost::add_edge(v[hpg->getHyperEdgeList().at(u)->getHyperVertexList().at(h)->getIdentifier()], | ||
v[hpg->getHyperEdgeList().at(u)->getHyperVertexList().at(h)->getHyperEdgeList().at(q)->getIdentifier()], | ||
graphOut ); | ||
} | ||
} | ||
} | ||
} | ||
|
||
RStructure | ||
Isomorph::getResult() const { | ||
return _result; | ||
} | ||
|
||
Isomorph::~Isomorph() { | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
|
||
#ifndef ALGORITHM_INCLUDE_ISOMORPHISM_HH_ | ||
#define ALGORITHM_INCLUDE_ISOMORPHISM_HH_ | ||
|
||
#include <boost/config.hpp> | ||
#include <boost/shared_ptr.hpp> | ||
#include <boost/graph/adjacency_list.hpp> | ||
#include <boost/graph/graph_utility.hpp> | ||
|
||
#include "../../model/include/HypergrapheAbstrait.hh" | ||
#include "../../model/include/AlgorithmeAbstrait.hh" | ||
|
||
class Isomorph : public AlgorithmeAbstrait { | ||
|
||
public: | ||
|
||
Isomorph(const boost::shared_ptr<HypergrapheAbstrait>&, const boost::shared_ptr<HypergrapheAbstrait>&); | ||
|
||
RStructure getResult() const; | ||
|
||
~Isomorph(); | ||
|
||
protected: | ||
|
||
typedef boost::adjacency_list<boost::vecS, boost::listS, boost::undirectedS, boost::property<boost::vertex_index_t, int> > | ||
graph_t; | ||
|
||
void hypergraphTranspose(const boost::shared_ptr<HypergrapheAbstrait>&, graph_t&); | ||
|
||
void runAlgorithme(); | ||
|
||
protected: | ||
|
||
boost::shared_ptr<HypergrapheAbstrait> | ||
_ptrHypergrapheAbstraitA; | ||
|
||
boost::shared_ptr<HypergrapheAbstrait> | ||
_ptrHypergrapheAbstraitB; | ||
|
||
RStructure _result; | ||
|
||
}; | ||
|
||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* LightTreeLib - Small C++ Template library - Used in HypergraphLib | ||
* | ||
*/ | ||
|
||
#ifndef LIGHTTREELIB_HPP_ | ||
#define LIGHTTREELIB_HPP_ | ||
|
||
#include <map> | ||
#include <boost/shared_ptr.hpp> | ||
|
||
template<class T> | ||
class LightTree { | ||
|
||
public: | ||
|
||
LightTree(const T& t) : _t( t ) { | ||
_cnt = 0; | ||
} | ||
|
||
void | ||
setElement(const T& t) { | ||
_t = t; | ||
} | ||
|
||
void | ||
addNode(boost::shared_ptr<LightTree<T> >& lightTree) { | ||
_mapNode[_cnt] = lightTree; | ||
_cnt++; | ||
} | ||
|
||
boost::shared_ptr<LightTree<T> >& | ||
getNode(unsigned int nodeId) { | ||
return _mapNode[nodeId]; | ||
} | ||
|
||
unsigned int | ||
getCardinal() const { | ||
return _cnt; | ||
} | ||
|
||
T& | ||
getElement() { | ||
return _t; | ||
} | ||
|
||
~LightTree() { | ||
} | ||
|
||
private: | ||
|
||
T _t; | ||
unsigned int _cnt; | ||
std::map<unsigned int, boost::shared_ptr<LightTree<T> > > _mapNode; | ||
|
||
}; | ||
|
||
|
||
#endif /* LIGHTTREELIB_HPP_ */ |