Skip to content

Commit

Permalink
Implement infrastructure for IND algorithms
Browse files Browse the repository at this point in the history
Co-authored-by: Chizhov Anton <[email protected]>
  • Loading branch information
alexandrsmirn and vs9h committed Nov 24, 2023
1 parent 615ab74 commit fd4b07f
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/core/algorithms/ind/ind.cpp
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
46 changes: 46 additions & 0 deletions src/core/algorithms/ind/ind.h
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
14 changes: 14 additions & 0 deletions src/core/algorithms/ind/ind_algorithm.cpp
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
50 changes: 50 additions & 0 deletions src/core/algorithms/ind/ind_algorithm.h
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

0 comments on commit fd4b07f

Please sign in to comment.