Skip to content

Commit

Permalink
Merge pull request nojhan#17 from IOHprofiler/developing
Browse files Browse the repository at this point in the history
Developing: Fix bugs, make transformation methods independent from IOHprofiler_problem, record evaluations of the last iteration, and handle warning info
  • Loading branch information
FurongYe authored Sep 20, 2019
2 parents 62e6a1c + 380ecd0 commit 05f5a16
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 80 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CC=g++
LDFLAGS += -lm -lboost_system -lboost_filesystem
LDFLAGS =
CCFLAGS = -g -std=c++11 -Wall -Wno-unused-variable -Wno-sign-compare -Wno-unused-function -O2
SUBDIRS=src
ROOT_DIR=$(shell pwd)
Expand Down
2 changes: 1 addition & 1 deletion build/Cpp/IOHprofiler_run_suite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void _run_suite() {
std::shared_ptr<IOHprofiler_problem<int>> problem;

/// Problems are tested one by one until 'get_next_problem' returns NULL.
while (problem = pbo.get_next_problem()) {
while ((problem = pbo.get_next_problem()) != nullptr) {
logger->target_problem(problem->IOHprofiler_get_problem_id(),
problem->IOHprofiler_get_number_of_variables(),
problem->IOHprofiler_get_instance_id(),
Expand Down
2 changes: 1 addition & 1 deletion src/Problems/f_leading_ones_dummy2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
///
/// \author Furong Ye
/// \date 2019-06-27
#ifndef _F_LEADING_ONES_DUMMYTWI_H
#ifndef _F_LEADING_ONES_DUMMYTWO_H
#define _F_LEADING_ONES_DUMMYTWO_H

#include "../Template/IOHprofiler_problem.hpp"
Expand Down
2 changes: 1 addition & 1 deletion src/Template/Experiments/IOHprofiler_experimenter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ template <class InputType> class IOHprofiler_experimenter {
this->config_csv_logger->target_suite(this->configSuite->IOHprofiler_suite_get_suite_name());

/// Problems are tested one by one until 'get_next_problem' returns NULL.
while (current_problem = configSuite->get_next_problem()) {
while ((current_problem = configSuite->get_next_problem()) != nullptr) {
std::clock_t c_start = std::clock();
info = "f";
info += std::to_string(current_problem->IOHprofiler_get_problem_id());
Expand Down
67 changes: 20 additions & 47 deletions src/Template/IOHprofiler_problem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ template <class InputType> class IOHprofiler_problem

IOHprofiler_problem() {};
IOHprofiler_problem(int instance_id, int dimension){};
~IOHprofiler_problem(){};
virtual ~IOHprofiler_problem(){};

IOHprofiler_problem(const IOHprofiler_problem&) = delete;
IOHprofiler_problem &operator=(const IOHprofiler_problem&) = delete;
Expand Down Expand Up @@ -69,11 +69,11 @@ template <class InputType> class IOHprofiler_problem
std::vector<double> evaluate_multi(std::vector<InputType> x) {
++this->evaluations;

variables_transformation(x);
transformation.variables_transformation(x,this->instance_id);
this->raw_objectives = internal_evaluate_multi(x);

this->transformed_objectives = this->raw_objectives;
objectives_transformation(this->transformed_objectives);
transformation.objectives_transformation(this->transformed_objectives,this->instance_id);
if (compareObjectives(this->transformed_objectives,this->best_so_far_transformed_objectives)) {
this->best_so_far_transformed_objectives = this->transformed_objectives;
this->best_so_far_transformed_evaluations = this->evaluations;
Expand All @@ -99,17 +99,18 @@ template <class InputType> class IOHprofiler_problem
double evaluate(std::vector<InputType> x) {
++this->evaluations;

variables_transformation(x);
transformation.variables_transformation(x,this->instance_id);
this->raw_objectives[0] = internal_evaluate(x);
/// todo. make it as vector assign.

this->transformed_objectives[0] = this->raw_objectives[0];
objectives_transformation(this->transformed_objectives);
transformation.objectives_transformation(this->transformed_objectives,this->instance_id);
if (compareObjectives(this->transformed_objectives,this->best_so_far_transformed_objectives)) {
this->best_so_far_transformed_objectives = this->transformed_objectives;
this->best_so_far_transformed_evaluations = this->evaluations;
this->best_so_far_raw_objectives = this->raw_objectives;
this->best_so_far_raw_evaluations = this->evaluations;

/// todo. add a function for this.
}

if (compareVector(this->transformed_objectives,this->optimal)) {
Expand All @@ -130,7 +131,7 @@ template <class InputType> class IOHprofiler_problem
void evaluate_multi(std::vector<InputType> x, std::vector<double> &y) {
++this->evaluations;

variables_transformation(x);
transformation.variables_transformation(x,this->instance_id);
y = internal_evaluate_multi(x);

this->raw_objectives = y;
Expand All @@ -139,7 +140,7 @@ template <class InputType> class IOHprofiler_problem
this->best_so_far_raw_evaluations = this->evaluations;
}

objectives_transformation(y);
transformation.objectives_transformation(y,this->instance_id);
if (compareObjectives(y,this->best_so_far_transformed_objectives)) {
this->best_so_far_transformed_objectives = y;
this->best_so_far_transformed_evaluations = this->evaluations;
Expand All @@ -161,12 +162,12 @@ template <class InputType> class IOHprofiler_problem
void evaluate(std::vector<InputType> x, double &y) {
++this->evaluations;

variables_transformation(x);
transformation.variables_transformation(x,this->instance_id);
y = internal_evaluate(x);

this->raw_objectives = y;

objectives_transformation(y);
transformation.objectives_transformation(y,this->instance_id);
if (y > this->best_so_far_transformed_objectives[0]) {
this->best_so_far_transformed_objectives[0] = y;
this->best_so_far_transformed_evaluations = this->evaluations;
Expand All @@ -186,13 +187,14 @@ template <class InputType> class IOHprofiler_problem
/// It will be revoked after setting dimension (number_of_variables) or instance_id.
void calc_optimal() {
if (this->best_variables.size() == this->number_of_variables) {
/// todo. Make Exception.
/// Do not apply transformation on best_variables as calculating optimal
if (this->number_of_objectives == 1) {
this->optimal[0] = internal_evaluate(this->best_variables);
} else {
this->optimal = internal_evaluate_multi(this->best_variables);
}
objectives_transformation(this->optimal);
transformation.objectives_transformation(this->optimal,this->instance_id);
}
else {
this->optimal.clear();
Expand All @@ -202,37 +204,6 @@ template <class InputType> class IOHprofiler_problem
}
};

/// \fn void variables_transformation(std::vector<InputType> &x)
/// \brief Transformation operations on variables.
///
/// For instance_id in ]1,50], xor operation is applied.
/// For instance_id in ]50,100], \sigma function is applied.
void variables_transformation(std::vector<InputType> &x) {
if (instance_id > 1 && instance_id <= 50) {
transformation.transform_vars_xor(x,this->instance_id);
} else if (instance_id > 50 && instance_id <= 100) {
transformation.transform_vars_sigma(x,this->instance_id);
}
};

/// \fn void objectives_transformation(std::vector<double> &y)
/// \brief Transformation operations on objectives (a * f(x) + b).
void objectives_transformation(std::vector<double> &y) {
if (instance_id > 1) {
transformation.transform_obj_scale(y,this->instance_id);
transformation.transform_obj_shift(y,this->instance_id);
}
};

/// \fn void objectives_transformation(std::vector<double> &y)
/// \brief Transformation operations on objectives (a * f(x) + b).
void objectives_transformation(double &y) {
if (instance_id > 1) {
transformation.transform_obj_scale(y,this->instance_id);
transformation.transform_obj_shift(y,this->instance_id);
}
};

/// \todo To support constrained optimization.
virtual std::vector<double> constraints() {
std::vector<double> con;
Expand Down Expand Up @@ -506,7 +477,7 @@ template <class InputType> class IOHprofiler_problem
int instance_id = DEFAULT_INSTANCE; /// < evaluate function is validated with instance and dimension. set default to avoid invalid class.

std::string problem_name;
std::string problem_type; /// todo. eet it as enum.
std::string problem_type; /// todo. make it as enum.

std::vector<InputType> lowerbound;
std::vector<InputType> upperbound;
Expand All @@ -517,20 +488,22 @@ template <class InputType> class IOHprofiler_problem
std::size_t number_of_variables = DEFAULT_DIMENSION; /// < evaluate function is validated with instance and dimension. set default to avoid invalid class.
std::size_t number_of_objectives;

std::vector<InputType> best_variables;
std::vector<InputType> best_variables; /// todo. comments, rename?
std::vector<InputType> best_transformed_variables;
std::vector<double> optimal;
std::vector<double> optimal; /// todo. How to evluate distance to optima. In global optima case, which optimum to be recorded.
bool optimalFound = false;

std::vector<double> raw_objectives; /// < to record objectives before transformation.
std::vector<double> transformed_objectives; /// < to record objectives after transformation.
int transformed_number_of_variables; /// < intermediate variables in evaluate.
int transformed_number_of_variables; /// < intermediate variables in evaluate.
/// todo. check.
std::vector<InputType> transformed_variables; /// < intermediate variables in evaluate.

/// todo. constrainted optimization.
std::size_t number_of_constraints;

size_t evaluations = 0; /// < to record optimization process.
std::size_t evaluations = 0; /// < to record optimization process.
/// todo. rename number_of_evaluations.
std::vector<double> best_so_far_raw_objectives; /// < to record optimization process.
int best_so_far_raw_evaluations = 0; /// < to record optimization process.
std::vector<double> best_so_far_transformed_objectives; /// < to record optimization process.
Expand Down
4 changes: 2 additions & 2 deletions src/Template/IOHprofiler_random.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ class IOHprofiler_random {
}

private:
long _seed[32];
//long _seed[32];
size_t _seed_index;

double rand_r;
//double rand_r;

const long a = 16807; /// < multiplier.
const long m = 2147483647; /// < modulus.
Expand Down
33 changes: 33 additions & 0 deletions src/Template/IOHprofiler_transformation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,40 @@

/// \brief A class consisting of transformation methods.
class IOHprofiler_transformation: public IOHprofiler_random {
/// todo. No inheritance here.
public:

/// \fn void variables_transformation(std::vector<InputType> &x)
/// \brief Transformation operations on variables.
///
/// For instance_id in ]1,50], xor operation is applied.
/// For instance_id in ]50,100], \sigma function is applied.
void variables_transformation(std::vector<int> &x, const int instance_id) {
if (instance_id > 1 && instance_id <= 50) {
this->transform_vars_xor(x,instance_id);
} else if (instance_id > 50 && instance_id <= 100) {
this->transform_vars_sigma(x,instance_id);
}
};

/// \fn void objectives_transformation(std::vector<double> &y)
/// \brief Transformation operations on objectives (a * f(x) + b).
void objectives_transformation(std::vector<double> &y, const int instance_id) {
if (instance_id > 1) {
this->transform_obj_scale(y,instance_id);
this->transform_obj_shift(y,instance_id);
}
};

/// \fn void objectives_transformation(std::vector<double> &y)
/// \brief Transformation operations on objectives (a * f(x) + b).
void objectives_transformation(double &y, const int instance_id) {
if (instance_id > 1) {
this->transform_obj_scale(y,instance_id);
this->transform_obj_shift(y,instance_id);
}
};


/// \fn xor_compute(const int x1, const int x2)
///
Expand Down
Loading

0 comments on commit 05f5a16

Please sign in to comment.