-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement infrastructure for IND algorithms
Co-authored-by: Chizhov Anton <[email protected]>
- Loading branch information
1 parent
615ab74
commit fd4b07f
Showing
4 changed files
with
135 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,25 @@ | ||
#include "ind.h" | ||
|
||
#include <sstream> | ||
|
||
namespace model { | ||
|
||
std::string CCToString(IND::ColumnCombination const& cc) { | ||
std::vector<AttributeIndex> const& col_ids = cc.GetColumnIndices(); | ||
std::stringstream ss; | ||
for (size_t i = 0; i != col_ids.size(); ++i) { | ||
if (i != 0) { | ||
ss << ", "; | ||
} | ||
ss << cc.GetTableIndex() << '.' << col_ids[i]; | ||
} | ||
return ss.str(); | ||
} | ||
|
||
std::string IND::ToString() const { | ||
std::stringstream ss; | ||
ss << CCToString(GetLhs()) << " -> " << CCToString(GetRhs()); | ||
return ss.str(); | ||
} | ||
|
||
} // namespace model |
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,46 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
#include <string> | ||
#include <vector> | ||
|
||
namespace model { | ||
|
||
using AttributeIndex = unsigned int; | ||
|
||
class IND { | ||
public: | ||
class ColumnCombination { | ||
protected: | ||
size_t table_index_; | ||
std::vector<AttributeIndex> column_indices_; | ||
|
||
public: | ||
ColumnCombination(size_t table_index, std::vector<AttributeIndex> col_indices) | ||
: table_index_(table_index), column_indices_(std::move(col_indices)) {} | ||
|
||
size_t GetTableIndex() const { | ||
return table_index_; | ||
} | ||
std::vector<AttributeIndex> const& GetColumnIndices() const { | ||
return column_indices_; | ||
} | ||
}; | ||
|
||
private: | ||
std::shared_ptr<ColumnCombination> lhs, rhs; | ||
|
||
public: | ||
IND(std::shared_ptr<ColumnCombination> lhs, std::shared_ptr<ColumnCombination> rhs) | ||
: lhs(std::move(lhs)), rhs(std::move(rhs)) {} | ||
|
||
ColumnCombination const& GetLhs() const { | ||
return *lhs; | ||
} | ||
ColumnCombination const& GetRhs() const { | ||
return *rhs; | ||
} | ||
std::string ToString() const; | ||
}; | ||
|
||
} // namespace model |
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,14 @@ | ||
#include "ind_algorithm.h" | ||
|
||
#include "config/names_and_descriptions.h" | ||
#include "config/tabular_data/input_tables/option.h" | ||
|
||
namespace algos { | ||
|
||
INDAlgorithm::INDAlgorithm(std::vector<std::string_view> phase_names) | ||
: Algorithm(std::move(phase_names)) { | ||
RegisterOption(config::TablesOpt(&input_tables_)); | ||
MakeOptionsAvailable({config::TablesOpt.GetName()}); | ||
} | ||
|
||
} // namespace algos |
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,50 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
#include <string> | ||
#include <string_view> | ||
#include <vector> | ||
|
||
#include "algorithms/algorithm.h" | ||
#include "ind.h" | ||
#include "tabular_data/input_tables_type.h" | ||
#include "util/primitive_collection.h" | ||
|
||
namespace algos { | ||
|
||
class INDAlgorithm : public Algorithm { | ||
public: | ||
using IND = model::IND; | ||
|
||
private: | ||
util::PrimitiveCollection<IND> ind_collection_; | ||
|
||
void ResetState() final { | ||
ind_collection_.Clear(); | ||
ResetINDAlgorithmState(); | ||
} | ||
|
||
virtual void ResetINDAlgorithmState() = 0; | ||
|
||
protected: | ||
constexpr static std::string_view kDefaultPhaseName = "IND mining"; | ||
|
||
config::InputTables input_tables_; | ||
|
||
explicit INDAlgorithm(std::vector<std::string_view> phase_names); | ||
|
||
virtual void RegisterIND(std::shared_ptr<IND::ColumnCombination> lhs, | ||
std::shared_ptr<IND::ColumnCombination> rhs) { | ||
ind_collection_.Register(std::move(lhs), std::move(rhs)); | ||
} | ||
virtual void RegisterIND(IND ind) { | ||
ind_collection_.Register(std::move(ind)); | ||
} | ||
|
||
public: | ||
std::list<IND> const& IndList() const noexcept { | ||
return ind_collection_.AsList(); | ||
} | ||
}; | ||
|
||
} // namespace algos |