8 #include <dignea/core/Problem.h>
13 #include <nlohmann/json.hpp>
28 Front(
const int &nSolutions);
30 Front(
const vector<S> &solutions);
38 void setSolutions(
const vector<S> &solutions);
40 vector<S> getSolutions()
const;
42 void addSolution(
const S &solution);
44 void addSolution(
const S &solution,
const Problem<S> *problem);
58 bool empty()
const {
return solutions.empty(); }
84 : numOfSolutions(sols.size()), solutions{} {
85 copy(sols.begin(), sols.end(), back_inserter(this->solutions));
96 : numOfSolutions(copy.numOfSolutions), solutions(copy.solutions) {}
106 : numOfSolutions(copy->numOfSolutions), solutions(copy->solutions) {}
121 this->solutions.clear();
122 this->solutions = solutions;
123 numOfSolutions = solutions.size();
134 return this->solutions;
145 if (solution.getNumberOfObjs() != 1) {
147 "Using addSolution for single-objective solutions. Please "
148 "consider using addSolution(const S&, const Problem<S>*) instead";
149 throw runtime_error(where);
151 solutions.push_back(solution);
163 if (solution.getNumberOfObjs() == 1) {
164 this->addSolution(solution);
165 std::cerr <<
"Using addSolution for multi-objective solutions. Please "
166 "consider using addSolution(const S& solution) instead"
169 unsigned int idx = 0;
170 while (idx < solutions.size()) {
171 auto dominates =
dominanceTest(solution, solutions[idx], problem);
172 if ((dominates == SECOND_DOMINATES) ||
173 (dominates == NON_DOMINANCES_EQUALS)) {
175 }
else if (dominates == FIRST_DOMINATES) {
177 solutions[idx] = solutions[solutions.size() - 1];
178 solutions.pop_back();
179 this->numOfSolutions--;
183 solutions.push_back(solution);
196 data[
"n_solutions"] = numOfSolutions;
198 for (
auto solution : this->solutions) {
199 data[to_string(i)] = solution.to_json();
int dominanceTest(const S &ind1, const S &ind2, const Problem< S > *problem)
Test whether an individual dominates another. A individual dominates another if all their objectives ...
Definition: Comparator.h:140
nlohmann::json json
Definition: MinKnap.h:85
Front class which stores the final results of an EA execution.
Definition: Front.h:26
Front(const int &nSolutions)
Construct a new Front object.
Definition: Front.h:74
void setSolutions(const vector< S > &solutions)
Resets the front with the solutions in the vector solutions.
Definition: Front.h:120
bool empty() const
Checks whether the front is empty or not.
Definition: Front.h:58
int getNumOfSolutions() const
Gets the number of solutions in the front.
Definition: Front.h:51
void addSolution(const S &solution)
Includes a new solution in the front. This is only for single-objective solutions.
Definition: Front.h:144
json to_json() const
Creates a JSON object with the information of the Front.
Definition: Front.h:194
vector< S > getSolutions() const
Returns the solutions in the front.
Definition: Front.h:133
Class to represent a Problem in the tool. It includes the basic information for a problem a few metho...
Definition: Problem.h:29