-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
84320d4
commit ac2be63
Showing
2 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <http://www.gnu.org/licenses/>. | ||
******************************************************************************/ | ||
|
||
#include "sbg/sbg.hpp" | ||
|
||
namespace SBG { | ||
|
||
namespace LIB { | ||
|
||
template<typename Set> | ||
SBGraph<Set>::SBGraph() : V_(), Vmap_(), E_(), map1_(), map2_(), Emap_() {} | ||
template<typename Set> | ||
SBGraph<Set>::SBGraph(Set V, PWMap<Set> Vmap, PWMap<Set> map1, PWMap<Set> map2, PWMap<Set> Emap) | ||
: V_(V), Vmap_(Vmap), map1_(map1), map2_(map2), Emap_(Emap) {} | ||
|
||
template<typename Set> | ||
PWMap<Set> connectedComponents(SBGraph<Set> g) | ||
{ | ||
PWMap<Set> rmap, old_rmap; | ||
|
||
if (isEmpty(g.E())) return rmap; | ||
|
||
do { | ||
old_rmap = rmap; | ||
|
||
PWMap<Set> ermap1 = composition(rmap, g.map1()); | ||
PWMap<Set> ermap2 = composition(rmap, g.map2()); | ||
|
||
PWMap<Set> rmap1 = minAdjMap(ermap1, ermap2); | ||
PWMap<Set> 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** @file sbg.hpp | ||
@brief <b>Set-based graph implementation</b> | ||
<hr> | ||
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 <http://www.gnu.org/licenses/>. | ||
******************************************************************************/ | ||
|
||
#ifndef SBG_SBG_HPP | ||
#define SBG_SBG_HPP | ||
|
||
#include "sbg/pw_map.hpp" | ||
|
||
namespace SBG { | ||
|
||
namespace LIB { | ||
|
||
template<typename Set> | ||
struct SBGraph { | ||
// Vertex definitions | ||
member_class(Set, V); | ||
member_class(PWMap<Set>, Vmap); | ||
|
||
// Edge definitions | ||
member_class(Set, E); | ||
member_class(PWMap<Set>, map1); | ||
member_class(PWMap<Set>, map2); | ||
member_class(PWMap<Set>, Emap); | ||
|
||
SBGraph(); | ||
SBGraph(Set V, PWMap<Set> VMap, PWMap<Set> map1, PWMap<Set> map2, PWMap<Set> Emap); | ||
}; | ||
template<typename Set> | ||
std::ostream &operator<<(std::ostream &out, const SBGraph<Set> &pw); | ||
|
||
template<typename Set> | ||
PWMap<Set> connectedComponents(SBGraph<Set> g); | ||
|
||
typedef SBGraph<UnordSet> BaseSBG; | ||
typedef SBGraph<OrdSet> CanonSBG; | ||
|
||
} // namespace LIB | ||
|
||
} // namespace SBG | ||
|
||
#endif |