Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonChern committed Sep 18, 2023
1 parent e243efe commit aaa9ce8
Show file tree
Hide file tree
Showing 19 changed files with 178 additions and 7,548,893 deletions.
34 changes: 33 additions & 1 deletion src/core/algorithms/gfd/egfd_validation.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,42 @@
#include <iostream>
#include <boost/graph/vf2_sub_graph_iso.hpp>
#include "egfd_validation.h"
#include "config/equal_nulls/option.h"
#include "config/names_and_descriptions.h"
#include "config/option_using.h"
#include "config/tabular_data/input_table/option.h"

namespace algos {

void EGFDValidation::FitInternal(model::IDatasetStream& data_stream) {}
EGFDValidation::EGFDValidation() : Algorithm({}) {
RegisterOptions();
MakeOptionsAvailable({config::names::kGFDData, config::names::kCsvPath});
};

void EGFDValidation::RegisterOptions() {
using namespace config::names;
using namespace config::descriptions;
DESBORDANTE_OPTION_USING;

RegisterOption(config::Option{&gfd_paths_, kGFDData, kDGFDData});
RegisterOption(config::Option{&graph_path_, kCsvPath, kDCsvPath});
}

void EGFDValidation::LoadDataInternal() {
std::ifstream f(graph_path_);
GFDtools::Parser::read_graph(f, this->graph);
f.close();
for (const auto& path : gfd_paths_) {
auto gfd_path = path;
f.open(gfd_path);
GFD gfd = GFD();
GFDtools::Parser::read_gfd(f, gfd);
f.close();
this->gfds.push_back(gfd);
}
}

void EGFDValidation::ResetState() {}

void EGFDValidation::CFdecompose(const graph_t& graph, std::set<vertex_t>& core, std::vector<std::set<vertex_t>>& forest) {
if (boost::num_vertices(graph) == (boost::num_edges(graph) + 1)) {
Expand Down
13 changes: 11 additions & 2 deletions src/core/algorithms/gfd/egfd_validation.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
#pragma once
#include "algorithms/algorithm.h"
#include "gfd.h"
#include "parser.h"
#include "config/names_and_descriptions.h"

namespace algos {

typedef std::map<std::pair<vertex_t, vertex_t>, std::map<vertex_t, std::set<vertex_t>>> CPI;

class EGFDValidation : public Algorithm {
private:
std::filesystem::path graph_path_;
std::vector<std::string> gfd_paths_;

graph_t graph;
std::vector<GFD> gfds;
std::vector<GFD> result;
Expand Down Expand Up @@ -41,10 +46,14 @@ class EGFDValidation : public Algorithm {
bool check(CPI& cpi, const graph_t& graph, const GFD& gfd, const std::set<vertex_t>& core,
const std::vector<std::set<vertex_t>>& forest, const std::map<vertex_t, vertex_t>& parent, const std::set<edge_t>& nte);

void FitInternal(model::IDatasetStream& data_stream);
unsigned long long ExecuteInternal();

void ResetState() final;
void LoadDataInternal() final;

void RegisterOptions();
public:
EGFDValidation() : Algorithm({}) {};
EGFDValidation();
EGFDValidation(graph_t graph_, std::vector<GFD> gfds_)
: Algorithm({}),
graph(graph_), gfds(gfds_) { ExecutePrepare(); }
Expand Down
35 changes: 34 additions & 1 deletion src/core/algorithms/gfd/gfd_validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,43 @@

#include "gfd_validation.h"
#include "balancer.h"
#include "config/equal_nulls/option.h"
#include "config/names_and_descriptions.h"
#include "config/option_using.h"
#include "config/tabular_data/input_table/option.h"

namespace algos {

void GFDValidation::FitInternal(model::IDatasetStream& data_stream) {}
GFDValidation::GFDValidation() : Algorithm({}) {
processors_num = std::thread::hardware_concurrency();
RegisterOptions();
MakeOptionsAvailable({config::names::kGFDData, config::names::kCsvPath});
};

void GFDValidation::RegisterOptions() {
using namespace config::names;
using namespace config::descriptions;
DESBORDANTE_OPTION_USING;

RegisterOption(config::Option{&gfd_paths_, kGFDData, kDGFDData});
RegisterOption(config::Option{&graph_path_, kCsvPath, kDCsvPath});
}

void GFDValidation::LoadDataInternal() {
std::ifstream f(graph_path_);
GFDtools::Parser::read_graph(f, this->graph);
f.close();
for (const auto& path : gfd_paths_) {
auto gfd_path = path;
f.open(gfd_path);
GFD gfd = GFD();
GFDtools::Parser::read_gfd(f, gfd);
f.close();
this->gfds.push_back(gfd);
}
}

void GFDValidation::ResetState() {}

std::vector<std::vector<vertex_t>> GFDValidation::getPartition(const std::vector<vertex_t>& candidates) {
std::vector<std::vector<vertex_t>> result = {};
Expand Down
12 changes: 10 additions & 2 deletions src/core/algorithms/gfd/gfd_validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "algorithms/algorithm.h"
#include "gfd.h"
#include "parser.h"
#include "config/names_and_descriptions.h"

namespace algos {

Expand All @@ -11,6 +12,9 @@ typedef std::tuple<int, vertex_t, vertex_t> Message;

class GFDValidation : public Algorithm {
private:
std::filesystem::path graph_path_;
std::vector<std::string> gfd_paths_;

graph_t graph;
std::vector<GFD> gfds;
std::vector<GFD> result;
Expand All @@ -23,12 +27,16 @@ class GFDValidation : public Algorithm {
void calculateMessages(const graph_t& graph, const std::vector<Request>& requests, std::map<int, std::vector<Message>>& weighted_messages);
void calculateUnsatisfied(const graph_t& graph, const std::vector<Message>& messages, const std::map<int, GFD>& indexed_gfds, std::set<int>& unsatisfied);

void FitInternal(model::IDatasetStream& data_stream);
unsigned long long ExecuteInternal();

void ResetState() final;
void LoadDataInternal() final;

void RegisterOptions();
public:
std::vector<GFD> generateSatisfiedGFDs(const graph_t& graph, const std::vector<GFD>& gfds);

GFDValidation() : Algorithm({}) { processors_num = std::thread::hardware_concurrency(); };
GFDValidation();
GFDValidation(graph_t graph_, std::vector<GFD> gfds_)
: Algorithm({}),
graph(graph_), gfds(gfds_) { ExecutePrepare(); }
Expand Down
2 changes: 1 addition & 1 deletion src/core/config/all_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ boost::program_options::options_description AlgoOptions() {

po::options_description egfdvalid_options("Efficient GFD validation options");
egfdvalid_options.add_options()
(names::kEGFDData, po::value<std::vector<std::string>>(), desc::kDGFDData)
(names::kGFDData, po::value<std::vector<std::string>>(), desc::kDGFDData)
;
// clang-format on

Expand Down
3 changes: 2 additions & 1 deletion src/core/config/descriptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,6 @@ constexpr auto kDWeight =
constexpr auto kDBumpsLimit = "max considered intervals amount. Pass 0 to remove limit";
constexpr auto kDIterationsLimit = "limit for iterations of sampling";
constexpr auto kDACSeed = "seed, needed for choosing a data sample";
constexpr auto kDGFDData = "Path to file with GFD, relative to ./input_data";
// constexpr auto kDGraphPath = "Path to .dot-file with Graph";
constexpr auto kDGFDData = "Path to file with GFD";
} // namespace config::descriptions
2 changes: 1 addition & 1 deletion src/core/config/names.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ constexpr auto kCfdColumnsNumber = "columns_number";
constexpr auto kCfdTuplesNumber = "tuples_number";
constexpr auto kCfdMaximumLhs = "cfd_max_lhs";
constexpr auto kCfdSubstrategy = "cfd_substrategy";
// constexpr auto kGraphPath = "graph_path";
constexpr auto kGFDData = "gfd";
constexpr auto kEGFDData = "egfd";
} // namespace config::names
43 changes: 43 additions & 0 deletions src/tests/test_egfd_validation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>

#include "algorithms/algo_factory.h"
#include "algorithms/gfd/gfd_validation.h"
#include "config/names.h"
#include "datasets.h"

using namespace algos;
using algos::StdParamsMap;

namespace {

auto current_path = test_data_dir / "graph_data";

std::unique_ptr<EGFDValidation> CreateEGFDValidationInstance(std::filesystem::path const& graph_path, const std::vector<std::string>& gfd_paths) {
StdParamsMap optionMap = {{config::names::kCsvPath, graph_path},{config::names::kGFDData, gfd_paths}};
return algos::CreateAndLoadAlgorithm<EGFDValidation>(optionMap);
}

TEST(EGFDValidationTest, TestTrivially) {
auto graph_path = current_path / "quadrangle.dot";
auto gfd_path = current_path / "quadrangle_gfd.dot";
std::vector<std::string> gfd_paths = { gfd_path };
auto algorithm = CreateEGFDValidationInstance(graph_path, gfd_paths);
int expected_size = 1;
algorithm->Execute();
std::vector<GFD> GFDList = algorithm->GFDList();
ASSERT_EQ(expected_size, GFDList.size());
}

TEST(EGFDValidationTest, TestExistingMatches) {
auto graph_path = current_path / "directors.dot";
auto gfd_path = current_path / "directors_gfd.dot";
std::vector<std::string> gfd_paths = { gfd_path };
auto algorithm = CreateEGFDValidationInstance(graph_path, gfd_paths);
int expected_size = 0;
algorithm->Execute();
std::vector<GFD> GFDList = algorithm->GFDList();
ASSERT_EQ(expected_size, GFDList.size());
}

}
43 changes: 43 additions & 0 deletions src/tests/test_gfd_validation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>

#include "algorithms/algo_factory.h"
#include "algorithms/gfd/gfd_validation.h"
#include "config/names.h"
#include "datasets.h"

using namespace algos;
using algos::StdParamsMap;

namespace {

auto current_path = test_data_dir / "graph_data";

std::unique_ptr<GFDValidation> CreateGFDValidationInstance(std::filesystem::path const& graph_path, const std::vector<std::string>& gfd_paths) {
StdParamsMap optionMap = {{config::names::kCsvPath, graph_path},{config::names::kGFDData, gfd_paths}};
return algos::CreateAndLoadAlgorithm<GFDValidation>(optionMap);
}

TEST(GFDValidationTest, TestTrivially) {
auto graph_path = current_path / "quadrangle.dot";
auto gfd_path = current_path / "quadrangle_gfd.dot";
std::vector<std::string> gfd_paths = { gfd_path };
auto algorithm = CreateGFDValidationInstance(graph_path, gfd_paths);
int expected_size = 1;
algorithm->Execute();
std::vector<GFD> GFDList = algorithm->GFDList();
ASSERT_EQ(expected_size, GFDList.size());
}

TEST(GFDValidationTest, TestExistingMatches) {
auto graph_path = current_path / "directors.dot";
auto gfd_path = current_path / "directors_gfd.dot";
std::vector<std::string> gfd_paths = { gfd_path };
auto algorithm = CreateGFDValidationInstance(graph_path, gfd_paths);
int expected_size = 0;
algorithm->Execute();
std::vector<GFD> GFDList = algorithm->GFDList();
ASSERT_EQ(expected_size, GFDList.size());
}

}
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit aaa9ce8

Please sign in to comment.