From 93e603843c8674e98cbdb66d22d37d420c765f9f Mon Sep 17 00:00:00 2001 From: Alexis LG Date: Fri, 10 Mar 2017 21:12:42 +0100 Subject: [PATCH] Adding rank/co-rank methods in adjacent matrix, fixing warnings unsigned/signed in Isomorph --- src/algorithm/HyperGraphStat.cpp | 11 ++---- src/algorithm/Isomorph.cpp | 6 +-- src/lib/LightTreeLib.hpp | 2 +- src/model/AdjacentMatrix.cpp | 59 ++++++++++++++++++++++++----- src/model/Hypergraphe.cpp | 2 - src/model/include/AdjacentMatrix.hh | 4 +- 6 files changed, 58 insertions(+), 26 deletions(-) diff --git a/src/algorithm/HyperGraphStat.cpp b/src/algorithm/HyperGraphStat.cpp index f933e72..ad0d462 100644 --- a/src/algorithm/HyperGraphStat.cpp +++ b/src/algorithm/HyperGraphStat.cpp @@ -1,6 +1,7 @@ #include #include "include/HyperGraphStat.hh" +#include "../model/include/AdjacentMatrix.hh" HyperGraphStat::HyperGraphStat(const boost::shared_ptr& ptrHypergrapheAbstrait) { _ptrHypergrapheAbstrait = ptrHypergrapheAbstrait; @@ -46,14 +47,8 @@ HyperGraphStat::runAlgorithme() { AdjacentMatrix m( _ptrHypergrapheAbstrait->getAdjacentMatrix() ); LibType::ListHyperEdge eList( _ptrHypergrapheAbstrait->getHyperEdgeList() ); - _coRang = _nhEdge; - - BOOST_FOREACH( auto& hEdge, eList ) { - _nhLink += m.getEdgeSize(hEdge); - if( m.getEdgeSize(hEdge) > _rang ) _rang = m.getEdgeSize(hEdge); - if( m.getEdgeSize(hEdge) < _coRang ) _coRang = m.getEdgeSize(hEdge); - } - + _rang = m.getRank(); + _coRang = m.getCoRank(); } RStructure diff --git a/src/algorithm/Isomorph.cpp b/src/algorithm/Isomorph.cpp index 858a9ba..88e3831 100644 --- a/src/algorithm/Isomorph.cpp +++ b/src/algorithm/Isomorph.cpp @@ -66,9 +66,9 @@ Isomorph::hypergraphTranspose(const boost::shared_ptr& hpg, v[id] = *i; } - for(int u=0; ugetHyperEdgeList().size(); u++ ) { - for(int h=0; hgetHyperEdgeList().at(u)->getHyperVertexList().size(); h++) { - for(int q=0; qgetHyperEdgeList().at(u)->getHyperVertexList().at(h)->getHyperEdgeList().size(); q++) { + for(unsigned int u=0; ugetHyperEdgeList().size(); u++ ) { + for(unsigned int h=0; hgetHyperEdgeList().at(u)->getHyperVertexList().size(); h++) { + for(unsigned int q=0; qgetHyperEdgeList().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 ); diff --git a/src/lib/LightTreeLib.hpp b/src/lib/LightTreeLib.hpp index c1adbe3..8651a31 100644 --- a/src/lib/LightTreeLib.hpp +++ b/src/lib/LightTreeLib.hpp @@ -9,7 +9,7 @@ #include #include -template +template class LightTree { public: diff --git a/src/model/AdjacentMatrix.cpp b/src/model/AdjacentMatrix.cpp index 800cc89..ef9dcb9 100644 --- a/src/model/AdjacentMatrix.cpp +++ b/src/model/AdjacentMatrix.cpp @@ -28,11 +28,6 @@ AdjacentMatrix::addHyperVertex(const boost::shared_ptr& hyperVertex for(unsigned int u=0; u < heList.size(); u++)_adjacentMatrixBool[id][heList[u]->getIdentifier()] = true; -/* - BOOST_FOREACH( auto he, heList ) { - _adjacentMatrixBool[id][he->getIdentifier()] = true; - }; -*/ } void @@ -43,11 +38,6 @@ AdjacentMatrix::addHyperEdge(const boost::shared_ptr& hyperEdge) { for(unsigned int u=0; u < hvList.size(); u++)_adjacentMatrixBool[hvList[u]->getIdentifier()][id] = true; -/* - BOOST_FOREACH( HyperVertex& hv, hvList ) { - _adjacentMatrixBool[hv->getIdentifier()][id] = true; - }; -*/ } unsigned int AdjacentMatrix::getVertexDegree(const boost::shared_ptr& hyperVertex) const { @@ -92,6 +82,55 @@ AdjacentMatrix::isEdgeInVertex(const int& edgeId, const int& vertexId) const { return _adjacentMatrixBool[edgeId][vertexId]; } +bool +AdjacentMatrix::isEdgeInVertex(const boost::shared_ptr& hEdge, const boost::shared_ptr& hVertex) const { + return isEdgeInVertex(hEdge->getIdentifier(), hVertex->getIdentifier()); +} + +bool +AdjacentMatrix::isVertexInEdge(const boost::shared_ptr& hVertex, const boost::shared_ptr& hEdge) const { + return isVertexInEdge(hVertex->getIdentifier(), hEdge->getIdentifier()); +} + +unsigned int +AdjacentMatrix::getCoRank() const { + + auto edgeSize = [&](const int& edgeId) { + unsigned int sum( 0 ); + for(unsigned int i=0; i < _n; i++) { + sum += _adjacentMatrixBool[i][edgeId]; + } + return sum; + }; + + unsigned int corank( -1 ); + for(unsigned int i=0; i < _m; i++) { + corank = (edgeSize(i) < corank ? edgeSize(i) : corank); + } + + return corank; +} + + +unsigned int +AdjacentMatrix::getRank() const { + + auto edgeSize = [&](const int& edgeId) { + unsigned int sum( 0 ); + for(unsigned int i=0; i < _n; i++) { + sum += _adjacentMatrixBool[i][edgeId]; + } + return sum; + }; + + unsigned int rank(0); + for(unsigned int i=0; i < _m; i++) { + rank = (edgeSize(i) > rank ? edgeSize(i) : rank); + } + + return rank; +} + LibType::AdjacentMatrixContainerBool& AdjacentMatrix::getBoolAdjacentMatrix() { return _adjacentMatrixBool; diff --git a/src/model/Hypergraphe.cpp b/src/model/Hypergraphe.cpp index b6af30e..1ea0188 100644 --- a/src/model/Hypergraphe.cpp +++ b/src/model/Hypergraphe.cpp @@ -31,7 +31,6 @@ Hypergraphe::getHyperVertexById(const unsigned int& id) { BOOST_FOREACH(auto& e, _listHyperVertex) { if(e->getIdentifier() == id )return e; } - //return nullptr; } boost::shared_ptr& @@ -41,7 +40,6 @@ Hypergraphe::getHyperEdgeById(const unsigned int& id) { BOOST_FOREACH(auto& e, _listHyperEdge) { if(e->getIdentifier() == id )return e; } - //return nullptr; } void diff --git a/src/model/include/AdjacentMatrix.hh b/src/model/include/AdjacentMatrix.hh index cbbc244..9a50701 100644 --- a/src/model/include/AdjacentMatrix.hh +++ b/src/model/include/AdjacentMatrix.hh @@ -114,13 +114,13 @@ public: * Obtenir le co-rang de l'hypergraphe. * @return Un entie correspondant au co-rang. */ - int getCoRank() const; + unsigned int getCoRank() const; /** * Obtenir le rang de l'hypergraphe. * @return Un entie correspondant au rang. */ - int getRank() const; + unsigned int getRank() const; /** * Obtenir les dimensions de la matrice d'adjacence.