diff --git a/sbg/sbg.cpp b/sbg/sbg.cpp new file mode 100755 index 0000000..12989e5 --- /dev/null +++ b/sbg/sbg.cpp @@ -0,0 +1,64 @@ +/******************************************************************************* + + This file is part of Set--Based Graph Library. + + SBG Library is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + SBG Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with SBG Library. If not, see . + + ******************************************************************************/ + +#include "sbg/sbg.hpp" + +namespace SBG { + +namespace LIB { + +template +SBGraph::SBGraph() : V_(), Vmap_(), E_(), map1_(), map2_(), Emap_() {} +template +SBGraph::SBGraph(Set V, PWMap Vmap, PWMap map1, PWMap map2, PWMap Emap) + : V_(V), Vmap_(Vmap), map1_(map1), map2_(map2), Emap_(Emap) {} + +template +PWMap connectedComponents(SBGraph g) +{ + PWMap rmap, old_rmap; + + if (isEmpty(g.E())) return rmap; + + do { + old_rmap = rmap; + + PWMap ermap1 = composition(rmap, g.map1()); + PWMap ermap2 = composition(rmap, g.map2()); + + PWMap rmap1 = minAdjMap(ermap1, ermap2); + PWMap rmap2 = minAdjMap(ermap2, ermap1); + rmap1 = rmap1.combine(rmap); + rmap2 = rmap2.combine(rmap); + + PWMap aux_rmap = minMap(rmap1, rmap2); + rmap = minMap(rmap, aux_rmap); + + if (!(rmap == old_rmap)) { + rmap = aux_rmap; + rmap = mapInf(rmap); + } + } while (rmap == old_rmap); + + return rmap; +} + +} // namespace LIB + +} // namespace SBG diff --git a/sbg/sbg.hpp b/sbg/sbg.hpp new file mode 100755 index 0000000..635cf43 --- /dev/null +++ b/sbg/sbg.hpp @@ -0,0 +1,61 @@ +/** @file sbg.hpp + + @brief Set-based graph implementation + +
+ + This file is part of Set--Based Graph Library. + + SBG Library is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + SBG Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with SBG Library. If not, see . + + ******************************************************************************/ + +#ifndef SBG_SBG_HPP +#define SBG_SBG_HPP + +#include "sbg/pw_map.hpp" + +namespace SBG { + +namespace LIB { + +template +struct SBGraph { + // Vertex definitions + member_class(Set, V); + member_class(PWMap, Vmap); + + // Edge definitions + member_class(Set, E); + member_class(PWMap, map1); + member_class(PWMap, map2); + member_class(PWMap, Emap); + + SBGraph(); + SBGraph(Set V, PWMap VMap, PWMap map1, PWMap map2, PWMap Emap); +}; +template +std::ostream &operator<<(std::ostream &out, const SBGraph &pw); + +template +PWMap connectedComponents(SBGraph g); + +typedef SBGraph BaseSBG; +typedef SBGraph CanonSBG; + +} // namespace LIB + +} // namespace SBG + +#endif