Skip to content

Commit

Permalink
Merge branch 'master' into v1.17---Isomorphism
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-87 committed Mar 5, 2017
2 parents 7669aae + b359d54 commit 8eef886
Show file tree
Hide file tree
Showing 9 changed files with 308 additions and 97 deletions.
8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ addons:
- ubuntu-toolchain-r-test
- boost-latest
packages:
- libboost1.55-all-dev
- libboost1.54-all-dev
- cmake

install:
- sudo apt-get install -qq g++-4.9
- export CXX="g++-4.9"
- sudo apt-get install -qq g++-4.8
- export CXX="g++-4.8"

before_script:
- cmake CMakeLists.txt

script: make

after_script:
- ./HypergraphLib --version
83 changes: 0 additions & 83 deletions src/algorithm/Connected.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,89 +158,6 @@ Connected::isEdgeVisited(std::vector<unsigned int>& list, unsigned int edge) con
return ret;
}

/*
void
Connected::runAlgorithme() {
LibType::ListHyperVertex listVertex( _ptrHypergrapheAbstrait->getHyperVertexList() );
LibType::ListHyperEdge listeEdge ( _ptrHypergrapheAbstrait->getHyperEdgeList() );
_result.setBooleanResult( true );
///
for(unsigned int i=0; i<_ptrHypergrapheAbstrait->getHyperEdgeById(0).getHyperVertexList().size(); i++) {
if( _ptrHypergrapheAbstrait->getHyperEdgeById(0).containVertex(_ptrHypergrapheAbstrait->getHyperEdgeById(0).getHyperVertexList().at(i)) ) {
std::cout << "0 contient " << _ptrHypergrapheAbstrait->getHyperEdgeById(0).getHyperVertexList().at(i).getIdentifier() << std::endl;
}
}
///
for(unsigned int i=0; i<listVertex.size(); i++) {
for(unsigned int j=i+1; j<listVertex.size(); j++) {
if( !isPath(listVertex.at(i), listVertex.at(j)) ) {
_result.setBooleanResult( false );
return;
}
}
}
}
bool
Connected::isPath(HyperVertex& vSource, HyperVertex& vDest) const {
std::stack<HyperEdge> listEdge;
std::vector<HyperEdge> visitedEdge;
for(unsigned int i=0; i<vSource.getHyperEdgeList().size(); i++) {
listEdge.push( vSource.getHyperEdgeList().at(i) );
}
while( !listEdge.empty() ) {
while( isVisited( visitedEdge, listEdge.top() ) ) {
listEdge.pop();
}
if( listEdge.empty() )return false;
HyperEdge e( listEdge.top() );
listEdge.pop();
std::cout << "Test de " << e.getIdentifier() << " source: "
<< vSource.getIdentifier()
<< " -> "
<< vDest.getIdentifier() << " #"
<< e.getIdentifier() << std::endl;
if( e.containVertex(vDest) ) {
std::cout << "FOUND: " << vSource.getIdentifier() << " " << vDest.getIdentifier() << std::endl;
return true;
}
for(unsigned int i=0; i<e.getHyperVertexList().size(); i++) {
for(unsigned int j=0; j<e.getHyperVertexList().at(i).getHyperEdgeList().size(); j++) {
if( !isVisited(visitedEdge, e.getHyperVertexList().at(i).getHyperEdgeList().at(j)) ) {
listEdge.push( e.getHyperVertexList().at(i).getHyperEdgeList().at(j) );
}
}
}
visitedEdge.push_back( e );
};
std::cout << "NOT FOUND: " << vSource.getIdentifier() << " " << vDest.getIdentifier() << std::endl;
return false;
}
bool
Connected::isVisited(std::vector<HyperEdge>& list, const HyperEdge& e) const {
for(unsigned int i=0; i<list.size(); i++) {
if( list.at(i)==e )return true;
}
return false;
}
*/
RStructure
Connected::getResult() const {
return _result;
Expand Down
113 changes: 113 additions & 0 deletions src/algorithm/Path.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@

#include <boost/foreach.hpp>
#include "include/Path.hh"
#include "../model/include/HyperVertex.hh"
#include "../model/include/HyperEdge.hh"

Path::Path(boost::shared_ptr<HypergrapheAbstrait>& ptrHypergrapheAbstrait) :
_ptrHypergrapheAbstrait( ptrHypergrapheAbstrait ), _limite(0) {
}

RStructure
Path::getResult() const {
return _result;
}

RStructurePath
Path::getPathResult() const {
return _result;
}

void
Path::setLimit(unsigned int limite) {
_limite = limite;
}

unsigned int
Path::getLimit() const {
return _limite;
}

void
Path::setHyperVertex(boost::shared_ptr<HyperVertex>& source, boost::shared_ptr<HyperVertex>& destination) {
_source = source;
_destination = destination;
}

void Path::runAlgorithme() {

LibType::PathList pathList( new boost::container::vector<LibType::ListHyperVertex>() );

if( _source == _destination ) {
LibType::ListHyperVertex listHyperVertex;
listHyperVertex.push_back( _source );
listHyperVertex.push_back( _destination );
_result.setPathResult(pathList);
return;
}

LibType::ListHyperVertex toVisitVertex;
LibType::ListHyperVertex visitedVertex;
LibType::ListHyperVertex currentPath;

toVisitVertex.push_back(_source);

while( (toVisitVertex.size() > 0) && (_limite > pathList->size() || _limite==0) ) {

boost::shared_ptr<HyperVertex> currentHyperVertex( toVisitVertex.back() );
visitedVertex.push_back( currentHyperVertex );
toVisitVertex.pop_back();

if( currentHyperVertex == _destination ) {
currentPath.push_back( currentHyperVertex );
buildPathToPathList(pathList, currentPath);
currentPath.clear();
currentHyperVertex = _source;
toVisitVertex.clear();
toVisitVertex.push_back(_source);
}

for(unsigned int cn = 0; cn < currentHyperVertex->getHyperEdgeList().size(); cn++) {
addVertexList(visitedVertex, toVisitVertex, currentHyperVertex->getHyperEdgeList().at(cn) );
}

currentPath.push_back( currentHyperVertex );
}

_result.setPathResult(pathList);
}

void
Path::buildPathToPathList(LibType::PathList& pList, LibType::ListHyperVertex& vList) {

LibType::ListHyperVertex tmpList;

BOOST_FOREACH(boost::shared_ptr<HyperVertex> vPtr, vList) {
tmpList.push_back(vPtr);
}

pList->push_back(tmpList);
}

void
Path::addVertexList(LibType::ListHyperVertex& noListe, LibType::ListHyperVertex& liste, const boost::shared_ptr<HyperEdge>& hyperEdge) const {
for(unsigned int i=0; i < hyperEdge->getHyperVertexList().size(); i++) {
if( !vertexContained(noListe, hyperEdge->getHyperVertexList().at(i)) ) {
liste.push_back( hyperEdge->getHyperVertexList().at(i) );
}
}
}

bool
Path::vertexContained(LibType::ListHyperVertex& liste, boost::shared_ptr<HyperVertex>& vertex) const {
for(unsigned int i=0; i<liste.size(); i++) {
if( vertex == liste.at(i) ) {
return true;
}
}
return false;
}


Path::~Path() {
}
104 changes: 104 additions & 0 deletions src/algorithm/include/Path.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/**
* Définition de l'algorithme décidant de l'ensemble des chemins dans un hypergraphe
* reliant un Vertex e1 à un Vertex e2.
*/

#ifndef ALGORITHM_INCLUDE_PATH_HH_
#define ALGORITHM_INCLUDE_PATH_HH_

#include "../../model/include/HypergrapheAbstrait.hh"
#include "../../model/include/AlgorithmeAbstrait.hh"
#include "../../model/include/RStructurePath.hh"

class Path : public AlgorithmeAbstrait {

public:

/*
* Constructeur.
* @param boost::shared_ptr<HypergrapheAbstrait> Pointeur partagé vers l'hypergraphe.
*/
Path(boost::shared_ptr<HypergrapheAbstrait>&);

/**
* Configurer les vertex à utiliser pour lister les chemins
*/
void setHyperVertex(boost::shared_ptr<HyperVertex>&, boost::shared_ptr<HyperVertex>&);

/**
* Obtenir la structure de résultats.
*/
RStructure getResult() const;

/**
* Obtenir la structure de résultats.
*/
RStructurePath getPathResult() const;

/**
* Fixer la limite du nombre de chemins. Par défaut 0, non-définit.
*/
void setLimit(unsigned int);

/**
* Lire la valeur limite.
*/
unsigned int getLimit() const;

/**
* Destructeur.
*/
~Path();


protected:

/**
* Lancement de l'algorithme
*/
void runAlgorithme();

/**
* Vérifie si l'HyperVertex est contenu dans la liste
*/
bool vertexContained(LibType::ListHyperVertex&, boost::shared_ptr<HyperVertex>&) const;

/**
* Ajoute les HyperVertex d'un HyperEdge dans la liste mentionnée.
*/
void addVertexList(LibType::ListHyperVertex&, LibType::ListHyperVertex&, const boost::shared_ptr<HyperEdge>&) const;


void buildPathToPathList(LibType::PathList&, LibType::ListHyperVertex&);

protected:

/**
* Pointeur partagé vers l'hypergraphe.
*/
boost::shared_ptr<HypergrapheAbstrait>
_ptrHypergrapheAbstrait;

/**
* Vertex source
*/
boost::shared_ptr<HyperVertex> _source;

/**
* Vertex destination
*/
boost::shared_ptr<HyperVertex> _destination;

/**
* Structure de résultat.
*/
RStructurePath _result;

/**
* Valeur limite.
*/
unsigned int _limite;
};


#endif /* SRC_ALGORITHM_INCLUDE_PATH_HH_ */
32 changes: 31 additions & 1 deletion src/client/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
#include "include/Client.hh"
#include "include/RandomHypergraphe.hh"

#include "../model/include/LibType.hh"
#include "../model/include/Hypergraphe.hh"
#include "../model/include/HyperFactory.hh"
#include "../model/include/HyperVertex.hh"
#include "../model/include/HyperEdge.hh"
#include "../model/include/MotorAlgorithm.hh"

#include "../algorithm/include/Dual.hh"
#include "../algorithm/include/Path.hh"
#include "../algorithm/include/Helly.hh"
#include "../algorithm/include/kRegular.hh"
#include "../algorithm/include/kUniform.hh"
Expand Down Expand Up @@ -56,7 +58,10 @@ int main(int argc, char *argv[]) {
("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");
("stat", "Retourne les statistiques de l'hypergraphe")
("path", "Retourne le chemins")
("source", boost::program_options::value<int>(), "Source de la reherche de chemins")
("destination", boost::program_options::value<int>(), "Destination de la recherche de chemins");

boost::program_options::variables_map vm;
boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
Expand Down Expand Up @@ -251,6 +256,31 @@ int main(int argc, char *argv[]) {
return 0;
}

if(vm.count("path") ) {
boost::shared_ptr<Path> pathAlgo( new Path( ptrHpg ) );

pathAlgo->setHyperVertex(
ptrHpg->getHyperVertexById(vm["source"].as<int>()),
ptrHpg->getHyperVertexById(vm["destination"].as<int>() )
);

boost::shared_ptr<AlgorithmeAbstrait> algoPathAbstrait( pathAlgo );

MotorAlgorithm::setAlgorithme( algoPathAbstrait );
MotorAlgorithm::runAlgorithme();

RStructurePath r( pathAlgo->getPathResult() );

for(unsigned int i=0; i<r.getPathResult()->size(); i++) {
LibType::ListHyperVertex hvl( r.getPathResult()->at(i) );
for(unsigned int j=0; j<hvl.size(); j++) {
std::cout << hvl.at(j)->getIdentifier() << " ";
}
std::cout << std::endl;
}

}

if( vm.count("connexe") ) {
NewAlgorithm(algoConnected, Connected, ptrHpg);

Expand Down
Loading

0 comments on commit 8eef886

Please sign in to comment.