Skip to content

Commit

Permalink
Merge pull request #26 from ligerdev/JoaoConstraintHandling
Browse files Browse the repository at this point in the history
Constraint handling feature for surrogate based optimisation and DACE surrogate model
  • Loading branch information
jaduro authored Jan 2, 2021
2 parents f02894d + 0e45d27 commit 0ec8f1d
Show file tree
Hide file tree
Showing 151 changed files with 8,223 additions and 1,646 deletions.
213 changes: 182 additions & 31 deletions src/libs/tigon/Algorithms/ParEGO.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/****************************************************************************
**
** Copyright (C) 2012-2018 The University of Sheffield (www.sheffield.ac.uk)
** Copyright (C) 2012-2020 The University of Sheffield (www.sheffield.ac.uk)
**
** This file is part of Liger.
**
Expand All @@ -21,8 +21,10 @@
#include <tigon/Operators/Fitness/ConstraintPenalty.h>
#include <tigon/Operators/Fitness/UncertainMonteCarloRobustness.h>
#include <tigon/Operators/Fitness/UncertainConfidenceRobustness.h>
#include <tigon/Operators/AlgorithmSpecific/parego/DirectionFitnessFiltration.h>
#include <tigon/Operators/AlgorithmSpecific/ParEGO/DirectionFitnessFiltration.h>
#include <tigon/Operators/AlgorithmSpecific/ParEGO/ConstraintDirectionFitnessFiltration.h>
#include <tigon/Operators/Composites/SurrogateBasedOptimizer.h>
#include <tigon/Operators/Composites/ConstrainedSurrogateBasedOptimizer.h>
#include <tigon/Representation/Sets/ISet.h>
#include <tigon/Representation/Mappings/IMapping.h>
#include <tigon/tigonengineregistry.h>
Expand Down Expand Up @@ -54,76 +56,140 @@ void ParEGO::initialise()
new SimplexLatticeDirectionIterator(this);
/*1*/ GeneralizedDecomposition* scal = new GeneralizedDecomposition(this);
/*2*/ ConstraintPenalty* cnstr = new ConstraintPenalty(this);
/*3*/ DirectionFitnessFiltration* filt = new DirectionFitnessFiltration(this);
/*4*/ SurrogateBasedOptimizer* opt = new SurrogateBasedOptimizer(this);
/*3*/ //DirectionFitnessFiltration* filt = new DirectionFitnessFiltration(this);
/*3*/ ConstraintDirectionFitnessFiltration* filt =
new ConstraintDirectionFitnessFiltration(this);
/*4*/ ConstrainedSurrogateBasedOptimizer* opt =
new ConstrainedSurrogateBasedOptimizer(this);

appendOperator(dirs);
appendOperator(scal);
appendOperator(cnstr);
appendOperator(filt);
appendOperator(opt);

TP_defineConstraintHandlingMethod(Tigon::SurrogateBased);
scal->TP_defineScalarisingFunction(Tigon::WeightedChebyshevAugmented);
scal->TP_defineWeightScopeApproach(Tigon::GlobalWeight);
opt->TP_defineErrorMethod(Tigon::ErrDensityBased);
filt->TP_defineMaxSolutions(Tigon::DefaultMaxSolutionsSurrogateModelling);
opt->TP_defineErrorMethod(Tigon::ErrConfidenceIntervalBased);
//opt->TP_defineErrorMethod(Tigon::ErrDensityBased);

// Changing the following parameter to 1 delivers better results for the
// tasks of training and searching the surrogate, but it will take longer
// for the optimization task to complete
opt->TP_defineOptimizationSearchQuality(0);

addProperty("maxSolutions"
, TString("Maximum number of samples for the surrogate model.\n"
"If there are more evaluated solutions than this, "
"the sample is constructed according to the direction "
"of the objective vector, and the scalarised function "
"value.")
, typeid(int).hash_code());
, getTType(int));
}

void ParEGO::TP_defineMaxSolutions(int n)
void ParEGO::defineOptimizationSearchQuality(int mode)
{
static_cast<DirectionFitnessFiltration*>(operators().at(3))->
TP_defineMaxSolutions(n);
static_cast<ConstrainedSurrogateBasedOptimizer*>(operators().at(4))->
TP_defineOptimizationSearchQuality(mode);
}

int ParEGO::TP_maxSolutions() const
int ParEGO::optimizationSearchQuality() const
{
return static_cast<DirectionFitnessFiltration*>(operators().at(3))->
TP_maxSolutions();
return static_cast<ConstrainedSurrogateBasedOptimizer*>(operators().at(4))->
TP_optimizationSearchQuality();
}

void ParEGO::TP_defineErrorMethod(Tigon::ErrorHandlingMethod err)
{
static_cast<ConstrainedSurrogateBasedOptimizer*>(operators().at(4))->
TP_defineErrorMethod(err);
}

Tigon::ErrorHandlingMethod ParEGO::TP_errorMethod() const
{
return static_cast<ConstrainedSurrogateBasedOptimizer*>(operators().at(4))->
TP_errorMethod();
}

void ParEGO::TP_defineConstraintHandlingMethod(Tigon::ConstraintHandlingMethod chm)
{
m_constraintHandlingMethod = chm;
switch(chm) {
case Tigon::NoConstraintHandling:
static_cast<ConstraintPenalty*>(operators().at(2))->
defineOutputTags(TStringList({TString("DO_NO_OPERATE")}));
static_cast<ConstrainedSurrogateBasedOptimizer*>(operators().at(4))->
TP_defineDisableConstraintHandling(true);
break;

case Tigon::PenaltyBased:
static_cast<ConstraintPenalty*>(operators().at(2))->
defineOutputTags(TStringList({Tigon::TFitness}));
static_cast<ConstrainedSurrogateBasedOptimizer*>(operators().at(4))->
TP_defineDisableConstraintHandling(true);
break;

case Tigon::SurrogateBased:
default:
static_cast<ConstraintPenalty*>(operators().at(2))->
defineOutputTags(TStringList({TString("DO_NO_OPERATE")}));
static_cast<ConstrainedSurrogateBasedOptimizer*>(operators().at(4))->
TP_defineDisableConstraintHandling(false);
break;
}
}

void ParEGO::TP_defineNeighbourhoodRadius(double r)
Tigon::ConstraintHandlingMethod ParEGO::TP_constraintHandlingMethod()
{
static_cast<SurrogateBasedOptimizer*>(operators().at(4))->
TP_defineNeighbourhoodRadius(r);
return m_constraintHandlingMethod;
}

double ParEGO::TP_neighbourhoodRadius() const
void ParEGO::TP_defineMaxSolutions(int n)
{
static_cast<DirectionFitnessFiltration*>(operators().at(3))->
TP_defineMaxSolutions(n);
}

int ParEGO::TP_maxSolutions() const
{
return static_cast<SurrogateBasedOptimizer*>(operators().at(4))->
TP_neighbourhoodRadius();
return static_cast<DirectionFitnessFiltration*>(operators().at(3))->
TP_maxSolutions();
}

TVector<IMappingSPtr> ParEGO::evaluatedMappings() const
{
TVector<IMappingSPtr> pop = operators().at(4)->outputSet(0)->all();
TVector<IMappingSPtr> ret;
for(int i=0; i<pop.size(); i++) {
if(pop[i]->isEvaluated()) {
ret.push_back(pop[i]);
for(auto sol : pop) {
if(sol->isEvaluated()) {
ret.push_back(sol);
}
}

return ret;
}

TVector<IMappingSPtr> ParEGO::newMappings() const
TVector<IMappingSPtr> ParEGO::newMappings() const
{
TVector<IMappingSPtr> pop = operators().at(4)->outputSet(0)->all();
TVector<IMappingSPtr> ret;
for(int i=0; i<pop.size(); i++) {
if(!pop[i]->isEvaluated()) {
ret.push_back(pop[i]);
for(auto sol : pop) {
if(!sol->isEvaluated()) {
ret.push_back(sol);
}
}

return ret;
}

TVector<IMappingSPtr> ParEGO::surrogateMappings() const
{
TVector<IMappingSPtr> pop = operators().at(3)->outputSet(0)->all();
return pop;
}

void ParEGO::defineReferenceSetSize(int s)
{
static_cast<SimplexLatticeDirectionIterator*>(operators().at(0))->
Expand All @@ -136,16 +202,100 @@ int ParEGO::referenceSetSize() const
TP_referenceSetSize();
}

void ParEGO::defineBudgetPerVariable(int n)
void ParEGO::defineBudgetPerVariableSS(int n)
{
static_cast<ConstrainedSurrogateBasedOptimizer*>(operators().at(4))->
TP_defineBudgetPerVariableSS(n);
}

int ParEGO::budgetPerVariableSS() const
{
return static_cast<ConstrainedSurrogateBasedOptimizer*>(operators().at(4))->
TP_budgetPerVariableSS();
}

void ParEGO::defineInitialPopsizePerVariableSS(int popsize)
{
static_cast<ConstrainedSurrogateBasedOptimizer*>(operators().at(4))->
TP_defineInitialPopsizePerVariableSS(popsize);
}

int ParEGO::initialPopsizePerVariableSS() const
{
return static_cast<ConstrainedSurrogateBasedOptimizer*>(operators().at(4))->
TP_initialPopsizePerVariableSS();
}

void ParEGO::defineStallIterationsSS(int iter)
{
static_cast<ConstrainedSurrogateBasedOptimizer*>(operators().at(4))->
TP_defineStallIterationsSS(iter);
}

int ParEGO::stallIterationsSS() const
{
return static_cast<ConstrainedSurrogateBasedOptimizer*>(operators().at(4))->
TP_stallIterationsSS();
}

void ParEGO::defineBudgetPerVariableTS(int n)
{
static_cast<ConstrainedSurrogateBasedOptimizer*>(operators().at(4))->
TP_defineBudgetPerVariableTS(n);
}

int ParEGO::budgetPerVariableTS() const
{
return static_cast<ConstrainedSurrogateBasedOptimizer*>(operators().at(4))->
TP_budgetPerVariableTS();
}

void ParEGO::defineInitialPopsizePerVariableTS(int popsize)
{
static_cast<SurrogateBasedOptimizer*>(operators().at(4))->
TP_defineBudgetPerVariable(n);
static_cast<ConstrainedSurrogateBasedOptimizer*>(operators().at(4))->
TP_defineInitialPopsizePerVariableTS(popsize);
}

int ParEGO::budgetPerVariable() const
int ParEGO::initialPopsizePerVariableTS() const
{
return static_cast<SurrogateBasedOptimizer*>(operators().at(4))->
TP_budgetPerVariable();
return static_cast<ConstrainedSurrogateBasedOptimizer*>(operators().at(4))->
TP_initialPopsizePerVariableTS();
}

void ParEGO::defineStallIterationsTS(int iter)
{
static_cast<ConstrainedSurrogateBasedOptimizer*>(operators().at(4))->
TP_defineStallIterationsTS(iter);
}

int ParEGO::stallIterationsTS() const
{
return static_cast<ConstrainedSurrogateBasedOptimizer*>(operators().at(4))->
TP_stallIterationsTS();
}

void ParEGO::defineNumberIterations(int iter)
{
static_cast<ConstrainedSurrogateBasedOptimizer*>(operators().at(4))->
TP_defineNumberIterations(iter);
}

int ParEGO::numberIterations() const
{
return static_cast<ConstrainedSurrogateBasedOptimizer*>(operators().at(4))->
TP_numberIterations();
}

void ParEGO::defineMultiObjectivization(bool isMultiObjectivizationUsedOrNot)
{
static_cast<ConstrainedSurrogateBasedOptimizer*>(operators().at(4))->
TP_defineMultiObjectivization(isMultiObjectivizationUsedOrNot);
}

bool ParEGO::multiObjectivization() const
{
return static_cast<ConstrainedSurrogateBasedOptimizer*>(operators().at(4))->
TP_multiObjectivization();
}

void ParEGO::defineScalarisingFunction(Tigon::ScalarisationType t, double p)
Expand Down Expand Up @@ -174,4 +324,5 @@ TString ParEGO::description()
} // namespace Algorithms
} // namespace Tigon


REGISTER_IPSET_FACTORY(Algorithms, ParEGO)
52 changes: 43 additions & 9 deletions src/libs/tigon/Algorithms/ParEGO.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/****************************************************************************
**
** Copyright (C) 2012-2018 The University of Sheffield (www.sheffield.ac.uk)
** Copyright (C) 2012-2020 The University of Sheffield (www.sheffield.ac.uk)
**
** This file is part of Liger.
**
Expand Down Expand Up @@ -46,31 +46,65 @@ class LIGER_TIGON_EXPORT ParEGO : public IAlgorithm
TString name();
TString description();

// Algrithm-level properties
void TP_defineMaxSolutions(int n);
int TP_maxSolutions() const;
// Algorithm-level properties
void TP_defineErrorMethod(Tigon::ErrorHandlingMethod err);
Tigon::ErrorHandlingMethod TP_errorMethod() const;

void TP_defineNeighbourhoodRadius(double r);
double TP_neighbourhoodRadius() const;
void TP_defineConstraintHandlingMethod(Tigon::ConstraintHandlingMethod chm);
Tigon::ConstraintHandlingMethod TP_constraintHandlingMethod();

// Properties found in the operators of the Algorithm
void TP_defineMaxSolutions(int n);
int TP_maxSolutions() const;

// General functions
TVector<IMappingSPtr> evaluatedMappings() const;
TVector<IMappingSPtr> newMappings() const;
TVector<IMappingSPtr> surrogateMappings() const;

// These methods are the operators' properties, and are exposed in Liger
// through introspection. They are here for easy interfacing in tests.
void defineReferenceSetSize(int s);
int referenceSetSize() const;

void defineBudgetPerVariable(int n);
int budgetPerVariable() const;
// Parameters for the optimizer to search the surrogate
void defineBudgetPerVariableSS(int n);
int budgetPerVariableSS() const;

void defineInitialPopsizePerVariableSS(int popsize);
int initialPopsizePerVariableSS() const;

void defineStallIterationsSS(int iter);
int stallIterationsSS() const;

// Parameters for the optimizer to train the surrogate
void defineBudgetPerVariableTS(int n);
int budgetPerVariableTS() const;

void defineInitialPopsizePerVariableTS(int popsize);
int initialPopsizePerVariableTS() const;

void defineStallIterationsTS(int iter);
int stallIterationsTS() const;


void defineNumberIterations(int iter);
int numberIterations() const;

void defineMultiObjectivization(bool isMultiObjectivizationUsedOrNot);
bool multiObjectivization() const;

// TODO: change this property according to the remaining budget
void defineScalarisingFunction(Tigon::ScalarisationType t, double p=1.0);
Tigon::ScalarisationType scalarisingFunction() const;
Tigon::ScalarisationType scalarisingFunction() const;

void defineOptimizationSearchQuality(int mode);
int optimizationSearchQuality() const;

private:
void initialise();

Tigon::ConstraintHandlingMethod m_constraintHandlingMethod;
};

} // namespace Algorithms
Expand Down
Loading

0 comments on commit 0ec8f1d

Please sign in to comment.