Skip to content

Commit

Permalink
Merge pull request #5 from alex-87/v1.17---Isomorphism
Browse files Browse the repository at this point in the history
V1.17   isomorphism
  • Loading branch information
alex-87 committed Mar 5, 2017
2 parents b359d54 + 8eef886 commit c5d3007
Show file tree
Hide file tree
Showing 6 changed files with 227 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
HyperGraphLib [![Build Status](https://travis-ci.org/alex-87/HyperGraphLib.svg?branch=master)](https://travis-ci.org/alex-87/HyperGraphLib)
-------------
![hypergraph](http://alex-87.github.io/HyperGraphLib/images/hypergraph.png)

How to compile HyperGraphLib
-------------
Expand Down
87 changes: 87 additions & 0 deletions src/algorithm/Isomorph.cpp
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() {
}

46 changes: 46 additions & 0 deletions src/algorithm/include/Isomorph.hh
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
31 changes: 31 additions & 0 deletions src/client/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "../algorithm/include/Linear.hh"
#include "../algorithm/include/Connected.hh"
#include "../algorithm/include/HyperGraphStat.hh"
#include "../algorithm/include/Isomorph.hh"

#include "../io/include/WriterFile.hh"
#include "../io/include/ReaderFile.hh"
Expand All @@ -56,6 +57,7 @@ int main(int argc, char *argv[]) {
("simple", "Décide si l'hypergraphe est simple")
("helly", "Décide si un hypergraphe possède la propriété de Helly")
("connexe", "Décide si l'hypergraphe est connexe")
("isomorph", boost::program_options::value<std::string>(), "Décide si deux hypergraphes sont isomorphe")
("stat", "Retourne les statistiques de l'hypergraphe")
("path", "Retourne le chemins")
("source", boost::program_options::value<int>(), "Source de la reherche de chemins")
Expand Down Expand Up @@ -104,6 +106,35 @@ int main(int argc, char *argv[]) {
ptrHpg = fReader.getHypergraphe();
}

// Isomorphism special parameters configuration
if( vm.count("isomorph") && vm.count("inputfile") ) {

boost::shared_ptr<HypergrapheAbstrait> ptrHpg2;

std::ifstream ifs(vm["isomorph"].as<std::string>(), std::ifstream::in);

ReaderFile fReader;
fReader.readHypergraphe( ifs );
ifs.close();

ptrHpg2 = fReader.getHypergraphe();

NewAlgorithm2(isomorphHpg, Isomorph, ptrHpg, ptrHpg2);

MotorAlgorithm::setAlgorithme( isomorphHpg );
MotorAlgorithm::runAlgorithme();

RStructure r( isomorphHpg->getResult() );

if( r.getBooleanResult() ) {
std::cout << "L'hypergraphe est isomorphe." << std::endl;
} else {
std::cout << "L'hypergraphe n'est pas isomorphe." << std::endl;
}

return 0;
}

if( vm.count("random") ) {
RandomHypergraphe rHyp;
rHyp.generateHypergraphe(vm["random"].as<int>(), vm["random"].as<int>());
Expand Down
5 changes: 3 additions & 2 deletions src/client/include/Client.hh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
#define CLIENT_INCLUDE_CLIENT_HH_

#define VERSION_MAJOR 0
#define VERSION_MINOR 16
#define VERSION_BUILD 2
#define VERSION_MINOR 17
#define VERSION_BUILD 1

#define NewAlgorithm(a, b, c) boost::shared_ptr<AlgorithmeAbstrait> a( new b( c ) );
#define NewAlgorithm2(a, b, c, d) boost::shared_ptr<AlgorithmeAbstrait> a( new b( c , d ) );


#endif /* CLIENT_INCLUDE_CLIENT_HH_ */
59 changes: 59 additions & 0 deletions src/lib/LightTreeLib.hpp
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_ */

0 comments on commit c5d3007

Please sign in to comment.