-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ Introduces passing tests for new functionality
- Loading branch information
Showing
15 changed files
with
204 additions
and
44 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
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
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
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
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
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
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
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
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,37 @@ | ||
/** | ||
* @file PisPerformanceTest.cpp | ||
* @author Alejandro Marrero (amarrerd@ull.edu.es) | ||
* @brief | ||
* @version 0.1 | ||
* @date 2023-10-23 | ||
* | ||
* @copyright Copyright (c) 2023 | ||
* | ||
*/ | ||
|
||
#include <dignea/generator/evaluations/PisPerformance.h> | ||
|
||
#include <algorithm> | ||
#include <catch2/catch_all.hpp> | ||
#include <random> | ||
#include <vector> | ||
|
||
using namespace std; | ||
|
||
TEST_CASE("Pisinger Performance evaluator tests", "[PisPerformance]") { | ||
std::random_device rd; | ||
std::mt19937 gen(rd()); | ||
std::uniform_real_distribution<> dis(1.0, 15.0); | ||
vector<float> runtimes(100); | ||
std::generate(runtimes.begin(), runtimes.end(), [&]() { return dis(gen); }); | ||
runtimes[0] = 0.05f; // Best runtime | ||
|
||
SECTION("Compute fitness of PisPerormance data") { | ||
auto minRuntime = | ||
*std::min_element(runtimes.begin() + 1, runtimes.end()); | ||
auto difference = minRuntime - runtimes[0]; | ||
PisPerformance evaluator; | ||
float result = evaluator.compute(runtimes); | ||
REQUIRE(result == difference); | ||
} | ||
} |
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,74 @@ | ||
// | ||
// Created by amarrero on 5/7/21. | ||
// | ||
|
||
#include <dignea/distances/Euclidean.h> | ||
#include <dignea/generator/domains/KPDomain.h> | ||
#include <dignea/generator/instances/KPInstance.h> | ||
#include <dignea/searches/NSPerformance.h> | ||
|
||
#include <algorithm> | ||
#include <catch2/catch_all.hpp> | ||
#include <nlohmann/json.hpp> | ||
#include <random> | ||
#include <vector> | ||
|
||
TEST_CASE("NSPerformance Searchs tests", "[NSPerformance Search]") { | ||
auto threshold = 30; | ||
auto pSize = 50; | ||
auto nVars = 100; | ||
auto portfolioSize = 4; | ||
auto problem = make_unique<KPDomain>(nVars); | ||
std::random_device rd; | ||
std::mt19937 gen(rd()); | ||
std::uniform_real_distribution<> dis(0.0, 500.0); | ||
|
||
auto inds = std::vector<KPInstance>{}; | ||
for (int i = 0; i < pSize; i++) { | ||
auto solution = problem->createSolution(); | ||
vector<float> fitness(portfolioSize); | ||
std::generate(fitness.begin(), fitness.end(), | ||
[&]() { return dis(gen); }); | ||
solution.setAvgConfigFitness(fitness); | ||
inds.push_back(solution); | ||
} | ||
|
||
SECTION("Check NSp-EIG run can calculate diversity") { | ||
auto dist = make_unique<Euclidean<float>>(); | ||
auto ns = | ||
make_unique<NSPerformance<KPInstance>>(move(dist), threshold, 3); | ||
vector result = ns->run(inds, problem.get()); | ||
REQUIRE(result == inds); | ||
long unsigned int inserted = 0; | ||
for (auto &ind : inds) { | ||
REQUIRE(ind.getDiversity() != 0); | ||
if (ind.getDiversity() > threshold) { | ||
ns->insertIntoArchive(ind); | ||
inserted++; | ||
} | ||
} | ||
REQUIRE(ns->getArchive().size() == | ||
inserted); // Some solutions should've been | ||
// inserted into the archive | ||
} | ||
|
||
SECTION("Check NSp-EIG inserts") { | ||
auto dist = make_unique<Euclidean<float>>(); | ||
auto ns = | ||
make_unique<NSPerformance<KPInstance>>(move(dist), threshold, 1); | ||
auto solution = KPInstance{100}; | ||
solution.setAvgConfigFitness({100, 0, 10, 0}); | ||
ns->insertIntoArchive(solution); | ||
REQUIRE(1 == ns->getArchive().size()); | ||
} | ||
|
||
SECTION("Check NSp-EIG to_json") { | ||
auto dist = make_unique<Euclidean<float>>(); | ||
auto ns = make_unique<NSPerformance<KPInstance>>(move(dist)); | ||
using json = nlohmann::json; | ||
json data = ns->to_json(); | ||
REQUIRE("NSPerformance" == data["name"]); | ||
REQUIRE(2000 == data["threshold"]); | ||
REQUIRE(15 == data["k"]); | ||
} | ||
} |
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
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
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
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
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