Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-87 committed Sep 22, 2015
1 parent 4df289e commit 46597d1
Show file tree
Hide file tree
Showing 49 changed files with 5,841 additions and 0 deletions.
17 changes: 17 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
cmake_minimum_required( VERSION 2.8 )

find_package( Boost 1.54 )
find_package( Boost COMPONENTS program_options REQUIRED )

set(Boost_DEBUG off)

set( CMAKE_CXX_FLAGS "-O3 -fopenmp -std=c++11" )

file(GLOB psrc ./src/*/*.cpp)
add_executable(HypergraphLib ${psrc})

if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
target_link_libraries(HypergraphLib ${Boost_LIBRARIES})
endif()

2,362 changes: 2,362 additions & 0 deletions doxyfile

Large diffs are not rendered by default.

247 changes: 247 additions & 0 deletions src/algorithm/Connected.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@

#include "include/Connected.hh"
#include "../model/include/Hypergraphe.hh"
#include "../model/include/HyperVertex.hh"
#include "../model/include/HyperEdge.hh"
#include <iostream>
#include <stack>

#define TRACE_ALGORITHM_CONNECTED 1

Connected::Connected(boost::shared_ptr<HypergrapheAbstrait>& ptrHypergrapheAbstrait) :
_ptrHypergrapheAbstrait(ptrHypergrapheAbstrait) {

}

void
Connected::runAlgorithme() {

if( _ptrHypergrapheAbstrait->getHyperVertexList().size()==0 )return;

LibType::AdjacentMatrixContainerBool matrix( _ptrHypergrapheAbstrait->getAdjacentMatrix().getBoolAdjacentMatrix() );

std::stack<unsigned int> stackHyperVertex;
std::stack<unsigned int> stackHyperEdge;

std::vector<unsigned int> listConnectedVisited;
std::vector<unsigned int> listHyperEdgeVisited;

_result.setBooleanResult(false);
stackHyperVertex.push( _ptrHypergrapheAbstrait->getHyperVertexList().at(0).getIdentifier() );

#if(TRACE_ALGORITHM_CONNECTED)
std::cout << "PUSH [vertex]: " << _ptrHypergrapheAbstrait->getHyperVertexList().at(0).getIdentifier() << std::endl;
#endif

while( !stackHyperVertex.empty() || !stackHyperEdge.empty() ) {
#if(TRACE_ALGORITHM_CONNECTED)
std::cout << "Purge[vrtx]...";
#endif
while( !stackHyperVertex.empty() && isVertexVisited(listConnectedVisited, stackHyperVertex.top()) ) {
stackHyperVertex.pop();
}
#if(TRACE_ALGORITHM_CONNECTED)
std::cout << " ok." << std::endl;

std::cout << "*** size(Stack[vrtx]): " << stackHyperVertex.size() << std::endl;
#endif
if( !stackHyperVertex.empty() ) {

unsigned int u( stackHyperVertex.top() );

stackHyperVertex.pop();
#if(TRACE_ALGORITHM_CONNECTED)
std::cout << "POP [vertex]: " << u << std::endl;
#endif
exploreVertical(listHyperEdgeVisited, stackHyperEdge, u);
#if(TRACE_ALGORITHM_CONNECTED)
std::cout << "STOR [vertex]: " << u << std::endl;
#endif
listConnectedVisited.push_back( u );
}
#if(TRACE_ALGORITHM_CONNECTED)
std::cout << "Purge[edge]...";
#endif
while( !stackHyperEdge.empty() && isEdgeVisited(listHyperEdgeVisited, stackHyperEdge.top()) ) {
stackHyperEdge.pop();
}
#if(TRACE_ALGORITHM_CONNECTED)
std::cout << " ok." << std::endl;
std::cout << "*** size(Stack[edge]): " << stackHyperEdge.size() << std::endl;
#endif
if( !stackHyperEdge.empty() ) {

unsigned int v( stackHyperEdge.top() );

stackHyperEdge.pop();
#if(TRACE_ALGORITHM_CONNECTED)
std::cout << "POP [edge]: " << v << std::endl;
#endif
exploreHorizontal(listConnectedVisited, stackHyperVertex, v);
#if(TRACE_ALGORITHM_CONNECTED)
std::cout << "STOR [edge]: " << v << std::endl;
#endif
listHyperEdgeVisited.push_back( v );
}
#if(TRACE_ALGORITHM_CONNECTED)
std::cout << "*** Stack[edge]: " << stackHyperEdge.size() << " elements" << std::endl;
std::cout << "*** Stack[vrtx]: " << stackHyperVertex.size() << " elements" << std::endl;
#endif
}
#if(TRACE_ALGORITHM_CONNECTED)
std::cout << "Finished: " << listConnectedVisited.size() << " =?= " << _ptrHypergrapheAbstrait->getHyperVertexList().size() << std::endl;
#endif
_result.setBooleanResult( listConnectedVisited.size() == _ptrHypergrapheAbstrait->getHyperVertexList().size() );
}

void
Connected::exploreVertical(std::vector<unsigned int>& listVisited, std::stack<unsigned int>& stack, unsigned int idVert) {

LibType::AdjacentMatrixContainerBool
matrix( _ptrHypergrapheAbstrait->getAdjacentMatrix().getBoolAdjacentMatrix() );

boost::tuple<unsigned int, unsigned int>
dim( _ptrHypergrapheAbstrait->getAdjacentMatrix().getMatrixDimension() );

for(unsigned int i=0; i<dim.get<0>(); i++) {
if( matrix[idVert][i] && !isEdgeVisited(listVisited, i ) ) {
#if(TRACE_ALGORITHM_CONNECTED)
std::cout << "-> PUSH [edge]: " << i << std::endl;
#endif
stack.push( i );
}
}
}

void
Connected::exploreHorizontal(std::vector<unsigned int>& listVisited, std::stack<unsigned int>& stack, unsigned int idHor) {

LibType::AdjacentMatrixContainerBool
matrix( _ptrHypergrapheAbstrait->getAdjacentMatrix().getBoolAdjacentMatrix() );

boost::tuple<unsigned int, unsigned int>
dim( _ptrHypergrapheAbstrait->getAdjacentMatrix().getMatrixDimension() );

for(unsigned int i=0; i<dim.get<1>(); i++) {
if( matrix[i][idHor] && !isVertexVisited(listVisited, i ) ) {
#if(TRACE_ALGORITHM_CONNECTED)
std::cout << "-> PUSH [vertex]: " << i << std::endl;
#endif
stack.push( i );
}
}
}

bool
Connected::isVertexVisited(std::vector<unsigned int>& list, unsigned int vertex) const {

bool ret( false );
#pragma omp for schedule(dynamic)
for(unsigned int i=0; i<list.size(); i++) {
if(list[i]==vertex)ret = true;
}
return ret;
}

bool
Connected::isEdgeVisited(std::vector<unsigned int>& list, unsigned int edge) const {

bool ret( false );
#pragma omp for schedule(dynamic)
for(unsigned int i=0; i<list.size(); i++) {
if(list[i]==edge)ret = true;
}
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;
}

Connected::~Connected() {

}
21 changes: 21 additions & 0 deletions src/algorithm/Diameter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

#include "include/Diameter.hh"


Diameter::Diameter(boost::shared_ptr<HypergrapheAbstrait>& ptrHypergrapheAbstrait) : _ptrHypergrapheAbstrait(ptrHypergrapheAbstrait) {

}

void
Diameter::runAlgorithme() {

}

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

Diameter::~Diameter() {

}
74 changes: 74 additions & 0 deletions src/algorithm/Dual.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@

#include "include/Dual.hh"
#include "../model/include/HyperFactory.hh"
#include "../model/include/Hypergraphe.hh"
#include "../model/include/HyperEdge.hh"
#include "../model/include/HyperVertex.hh"
#include <boost/foreach.hpp>


Dual::Dual(const boost::shared_ptr<HypergrapheAbstrait>& ptrHypergrapheAbstrait) : _ptrDualHypergraphe( new Hypergraphe() ) {
_ptrHypergrapheAbstrait = ptrHypergrapheAbstrait;
}

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

void
Dual::runAlgorithme() {

LibType::IndexerHyperVertex indexVertex ( _ptrHypergrapheAbstrait->getIndexHyperVertex() );
LibType::IndexerHyperEdge indexEdge ( _ptrHypergrapheAbstrait->getIndexHyperEdge() );

LibType::ListHyperVertex listVertex;
LibType::ListHyperEdge listEdge;

HyperFactory::startSession(_ptrDualHypergraphe);
#pragma omp parallel sections
{
#pragma omp section
{
for(unsigned int i=0; i<indexVertex.size(); i++) {
listEdge.push_back( *HyperFactory::newHyperEdge().get() );
}
}
#pragma omp section
{
for(unsigned int i=0; i<indexEdge.size(); i++) {
listVertex.push_back( *HyperFactory::newHyperVertex().get() );
}
}
}
BOOST_FOREACH(auto& itemVertex, listVertex) {
BOOST_FOREACH(auto& itemEdge, listEdge) {
if( _ptrHypergrapheAbstrait->getAdjacentMatrix().isVertexInEdge(itemEdge.getIdentifier(), itemVertex.getIdentifier())) {
HyperFactory::link(itemVertex, itemEdge);
}
}
}

#pragma omp parallel sections
{
#pragma omp section
{
BOOST_FOREACH(auto& itemVertex, listVertex) {
_ptrDualHypergraphe->addHyperVertex(itemVertex);
}
}
#pragma omp section
{
BOOST_FOREACH(auto& itemEdge, listEdge) {
_ptrDualHypergraphe->addHyperEdge(itemEdge);
}
}
}
HyperFactory::closeSession();

_ptrDualHypergraphe->flush();
_result.setHypergrapheResult( _ptrDualHypergraphe );
}

Dual::~Dual() {
}
Loading

0 comments on commit 46597d1

Please sign in to comment.