dignea  1.0.0
Diverse Instance Generator with Novelty Search and Evolutionary Algorithms
Comparator.h File Reference
#include <dignea/core/Problem.h>
#include <dignea/core/Solution.h>
#include <dignea/utilities/exceptions/OutOfRange.h>
#include <numeric>
#include <type_traits>

Go to the source code of this file.

Functions

template<typename S >
int cmpByFitness (const S &ind1, const S &ind2)
 Compares two individuals by their fitness. More...
 
template<typename S >
int cmpByObj (const S &ind1, const S &ind2, const int &nObj, const Problem< S > *problem)
 Compares two individuals by the objective nObj. The problem to solve must be given to check whether the objective is to be Minimize or Maximize. More...
 
template<typename S >
int improves (const S &ind1, const S &ind2)
 Checks whether a solution is improved by a new one. A solution (with constraints) is said to improve an existing one if: More...
 
template<typename S >
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 are "better" (considering maximisation or minimisation) or equal and at least one of them is strictly better. More...
 
template<typename T >
bool areEqual (const vector< T > &v1, const vector< T > &v2)
 Compare whether two vectors are equal within a tolerance. More...
 
template<typename T >
bool areEqual (const T &a, const T &b)
 Compare whether float/double values are equal within a tolerance. More...
 

Variables

static const int FIRST_BEST = -1
 
static const int SECOND_BEST = 1
 
static const int TIE = 0
 
static const int FIRST_DOMINATES = -1
 
static const int SECOND_DOMINATES = 1
 
static const int NON_DOMINANCES_EQUALS = 2
 
static const int NON_DOMINANCES_NOT_EQUALS = 3
 

Detailed Description

Author
Alejandro Marrero (amarr.nosp@m.erd@.nosp@m.ull.e.nosp@m.du.e.nosp@m.s)
Version
0.1
Date
2020-12-02

Function Documentation

◆ areEqual() [1/2]

template<typename T >
bool areEqual ( const T &  a,
const T &  b 
)

Compare whether float/double values are equal within a tolerance.

Template Parameters
T
Parameters
v1
v2
Returns
true
false

◆ areEqual() [2/2]

template<typename T >
bool areEqual ( const vector< T > &  v1,
const vector< T > &  v2 
)

Compare whether two vectors are equal within a tolerance.

Template Parameters
T
Parameters
v1
v2
Returns
true
false

◆ cmpByFitness()

template<typename S >
int cmpByFitness ( const S &  ind1,
const S &  ind2 
)

Compares two individuals by their fitness.

Template Parameters
S
Parameters
ind1
ind2
Returns
FIRST_BEST, SECOND_BEST or TIE.

◆ cmpByObj()

template<typename S >
int cmpByObj ( const S &  ind1,
const S &  ind2,
const int &  nObj,
const Problem< S > *  problem 
)

Compares two individuals by the objective nObj. The problem to solve must be given to check whether the objective is to be Minimize or Maximize.

Template Parameters
S
Parameters
ind1
ind2
nObj
problem
Returns
int

◆ dominanceTest()

template<typename S >
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 are "better" (considering maximisation or minimisation) or equal and at least one of them is strictly better.

Template Parameters
S
Parameters
ind1
ind2
problem
Returns
int

◆ improves()

template<typename S >
int improves ( const S &  ind1,
const S &  ind2 
)

Checks whether a solution is improved by a new one. A solution (with constraints) is said to improve an existing one if:

  • Share the same constraint coefficient by have a better fitness.
  • Have a constraint coefficient lower than the previous solution.
Template Parameters
Problem
S
Parameters
ind1
ind2
Returns
FIRST_BEST if ind1 is the best solution, SECOND_BEST otherwise. If the constraints are the same they are compared by fitness using cmpByFitness.