Skip to content

Commit 75b103e

Browse files
committed
- Merge tearing changes
- Added offsetImage method to PWMap
1 parent c0913d2 commit 75b103e

24 files changed

Lines changed: 492 additions & 307 deletions

algorithms/tearing/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ target_sources(
33
PRIVATE
44
tearing_impl.cpp
55
tearing.cpp
6-
tearing_fact.cpp
6+
tearing_data.cpp
7+
tearing_v1.cpp
78
)

algorithms/tearing/tearing.cpp

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,41 +17,44 @@
1717
1818
******************************************************************************/
1919

20-
#include <chrono>
21-
2220
#include "algorithms/tearing/tearing.hpp"
21+
#include "algorithms/tearing/tearing_data.hpp"
22+
#include "algorithms/tearing/tearing_impl.hpp"
23+
#include "algorithms/tearing/tearing_v1.hpp"
24+
#include "sbg/directed_sbg.hpp"
25+
#include "util/debug.hpp"
2326
#include "util/logger.hpp"
27+
#include "util/time_profiler.hpp"
2428

2529
namespace SBG {
2630

2731
namespace LIB {
2832

2933
////////////////////////////////////////////////////////////////////////////////
30-
// Auxiliary structures --------------------------------------------------------
34+
// Tearing Algorithm ---------------------------------------------------------------
3135
////////////////////////////////////////////////////////////////////////////////
3236

33-
TearingData::TearingData(DSBG dsbg, PWMap rmap, PWMap tearIOMap)
34-
: dsbg_(dsbg), rmap_(rmap), tearIOMap_(tearIOMap) {}
35-
36-
const DSBG& TearingData::dsbg() const { return dsbg_; }
37-
const PWMap& TearingData::rmap() const { return rmap_; }
38-
const PWMap& TearingData::tearIOMap() const { return tearIOMap_; }
39-
40-
////////////////////////////////////////////////////////////////////////////////
41-
// Tearing Algorithm Abstract Strategy Constructors --------------------------------
42-
////////////////////////////////////////////////////////////////////////////////
43-
44-
TearingStrategy::TearingStrategy() {}
45-
46-
////////////////////////////////////////////////////////////////////////////////
47-
// Tearing Algorithm Interface -----------------------------------------------------
48-
////////////////////////////////////////////////////////////////////////////////
49-
50-
Tearing::Tearing(TearingStratPtr strat) : strategy_(std::move(strat)) {}
37+
Tearing::Tearing() : _impl()
38+
{
39+
TearingKind kind = TEARING_IMPL.kind();
40+
switch (kind) {
41+
case TearingKind::kTearingV1: {
42+
_impl = detail::TearingImpl{};
43+
break;
44+
}
45+
46+
default: {
47+
Util::ERROR("Unsupported Tearing implementation");
48+
break;
49+
}
50+
}
51+
}
5152

52-
TearingData Tearing::calculate(const DSBG& dsbg)
53+
TearingData Tearing::calculate(const DirectedSBG& dsbg)
5354
{
54-
return strategy_->calculate(dsbg);
55+
Util::Internal::TimeProfiler profiler{"Total SCC execution time: "};
56+
57+
return std::visit([&](auto& a) { return a.calculate(dsbg); }, _impl);
5558
}
5659

5760
} // namespace LIB

algorithms/tearing/tearing.hpp

Lines changed: 17 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** @file scc.hpp
1+
/** @file tearing.hpp
22
33
@brief <b>SBG Tearing Algorithm Abstract Interface</b>
44
@@ -21,69 +21,44 @@
2121
2222
******************************************************************************/
2323

24-
#ifndef SBG_TEARING_HPP
25-
#define SBG_TEARING_HPP
24+
#ifndef SBGRAPH_ALGORITHMS_TEARING_TEARING_HPP_
25+
#define SBGRAPH_ALGORITHMS_TEARING_TEARING_HPP_
2626

2727
#include "sbg/directed_sbg.hpp"
28+
#include "algorithms/tearing/tearing_v1.hpp"
29+
30+
#include <variant>
2831

2932
namespace SBG {
3033

3134
namespace LIB {
3235

33-
////////////////////////////////////////////////////////////////////////////////
34-
// Auxiliary classures --------------------------------------------------------
35-
////////////////////////////////////////////////////////////////////////////////
36-
37-
/**
38-
* @brief Saves input and output data from a Tearing algorithm run.
39-
*/
40-
struct TearingData {
41-
public:
42-
TearingData(DSBG dsbg, PWMap rmap, PWMap tearIOMap);
43-
44-
const DSBG& dsbg() const;
45-
const PWMap& rmap() const;
46-
const PWMap& tearIOMap() const;
47-
48-
private:
49-
DSBG dsbg_; ///< Original input directed SBG
50-
PWMap rmap_; ///< Resulting SCCs
51-
PWMap tearIOMap_; ///< Paired tearing vertices
52-
};
36+
namespace detail {
5337

5438
////////////////////////////////////////////////////////////////////////////////
55-
// Tearing Algorithm Abstract Strategy ---------------------------------------------
39+
// Tearing Algorithm implementations -------------------------------------------
5640
////////////////////////////////////////////////////////////////////////////////
5741

58-
class TearingStrategy;
42+
using TearingImpl = std::variant<TearingV1>;
5943

60-
typedef std::unique_ptr<TearingStrategy> TearingStratPtr;
61-
62-
class TearingStrategy {
63-
public:
64-
virtual ~TearingStrategy() = default;
65-
66-
TearingStrategy();
67-
68-
virtual TearingData calculate(const DSBG& dsbg) = 0;
69-
};
44+
} // namespace detail
7045

7146
////////////////////////////////////////////////////////////////////////////////
72-
// Tearing Algorithm Interface (context) -------------------------------------------
47+
// Tearing Algorithm -----------------------------------------------------------
7348
////////////////////////////////////////////////////////////////////////////////
7449

7550
class Tearing {
76-
public:
77-
Tearing(TearingStratPtr strat);
51+
public:
52+
Tearing();
7853

79-
TearingData calculate(const DSBG& dsbg);
54+
TearingData calculate(const DirectedSBG& dsbg);
8055

81-
private:
82-
TearingStratPtr strategy_;
56+
private:
57+
detail::TearingImpl _impl;
8358
};
8459

8560
} // namespace LIB
8661

8762
} // namespace SBG
8863

89-
#endif
64+
#endif // SBGRAPH_ALGORITHMS_TEARING_TEARING_HPP_
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*******************************************************************************
2+
3+
This file is part of Set--Based Graph Library.
4+
5+
SBG Library is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published by
7+
the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
SBG Library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with SBG Library. If not, see <http://www.gnu.org/licenses/>.
17+
18+
******************************************************************************/
19+
20+
#include "algorithms/tearing/tearing_data.hpp"
21+
22+
namespace SBG {
23+
24+
namespace LIB {
25+
26+
TearingData::TearingData(DirectedSBG dsbg, PWMap rmap, PWMap tearIOMap)
27+
: _dsbg(dsbg), _rmap(rmap), _tearIOMap(tearIOMap) {}
28+
29+
const DirectedSBG& TearingData::dsbg() const { return _dsbg; }
30+
31+
const PWMap& TearingData::rmap() const { return _rmap; }
32+
33+
const PWMap& TearingData::tearIOMap() const { return _tearIOMap; }
34+
35+
} // namespace LIB
36+
37+
} // namespace SBG
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/** @file tearing_data.hpp
2+
3+
@brief <b>Tearing Input and Ouput data structure</b>
4+
5+
<hr>
6+
7+
This file is part of Set--Based Graph Library.
8+
9+
SBG Library is free software: you can redistribute it and/or modify
10+
it under the terms of the GNU General Public License as published by
11+
the Free Software Foundation, either version 3 of the License, or
12+
(at your option) any later version.
13+
14+
SBG Library is distributed in the hope that it will be useful,
15+
but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
GNU General Public License for more details.
18+
19+
You should have received a copy of the GNU General Public License
20+
along with SBG Library. If not, see <http://www.gnu.org/licenses/>.
21+
22+
******************************************************************************/
23+
24+
#ifndef SBGRAPH_ALGORITHMS_TEARING_TEARING_DATA_HPP_
25+
#define SBGRAPH_ALGORITHMS_TEARING_TEARING_DATA_HPP_
26+
27+
#include "sbg/directed_sbg.hpp"
28+
#include "sbg/pw_map.hpp"
29+
30+
namespace SBG {
31+
32+
namespace LIB {
33+
34+
////////////////////////////////////////////////////////////////////////////////
35+
// Tearing Factory implementations ---------------------------------------------
36+
////////////////////////////////////////////////////////////////////////////////
37+
38+
/**
39+
* @brief Saves input and output data from a Tearing algorithm run.
40+
*/
41+
class TearingData {
42+
public:
43+
TearingData(DirectedSBG dsbg, PWMap rmap, PWMap tearIOMap);
44+
45+
const DirectedSBG& dsbg() const;
46+
const PWMap& rmap() const;
47+
const PWMap& tearIOMap() const;
48+
49+
private:
50+
DirectedSBG _dsbg; ///< Original input directed SBG
51+
PWMap _rmap; ///< Resulting SCCs
52+
PWMap _tearIOMap; ///< Paired tearing vertices
53+
};
54+
55+
} // namespace LIB
56+
57+
} // namespace SBG
58+
59+
#endif // SBGRAPH_ALGORITHMS_TEARING_TEARING_DATA_HPP_

algorithms/tearing/tearing_fact.cpp

Lines changed: 0 additions & 61 deletions
This file was deleted.

0 commit comments

Comments
 (0)