The type of problem instance should be class derived from the base class
problem
.
Definition
A problem object must:
- define how to initialize the added data members (e.g., optimal solutions and search domain) in
initialize()
; - define a default initialization method for decision variables of a given solution in
initialize_solution(s)
; - define how to calculate the objective values and the constraint violation of a given solution in
evaluate_(s)
; - define the distance between two decision variables or two solutions in
variable_distance(x1, x2)
orvariable_distance(s1, s2)
; - define how to check whether two solutions are the same in
same(s1, s2)
.
For a combinatorial optimization algorithm, just make it inherited from problem
:
class one_max : public problem {
protected:
optima<variable_vector<int>, real> m_optima;
public:
void initialize() override ; // Initialize m_optima
void initialize_solution(solution_base&) const override;
evaluation_tag evaluate_(solution_base&, caller, bool, bool) override;
real variable_distance(const solution_base&, const solution_base&) const override;
real variable_distance(const variable_base&, const variable_base&) const override;
bool same(const solution_base&, const solution_base&) const override;
For a continuous optimization problem, it is recommended to make it inherited from continuous
or function
(which is derived from continuous
).
class sphere : public function {
public:
void initialize() override; // Initialize m_domain m_optima
void evaluate_objective(real*, vector<real>&) override;
}
m_domain
andm_optima
are added incontinuous
;initialize_solution(s)
variable_distance(s1, s2)
variable_distance(x1, x2)
same(s1, s2)
have been given incontinuous
;evaluate_(s)
has been given incontinuous
as a mixture ofevaluate_objective(x, obj)
andevaluate_obj_nd_con(x, obj, con)
;
Registration
- In the file “/run/include_problem.h” include the header file:
#include "../instance/problem/combination/one_max/one_max.h" #include "../instance/problem/continuous/global/classical/sphere.h"
- In the file “/run/user_initialization.cpp”, use the
REGISTER(...)
macro to register:REGISTER(problem, one_max, "ComOP_One_Max", std::set<problem_tag>({ problem_tag::ONEMAX, problem_tag::ComOP })); REGISTER(problem, sphere, "GOP_CLASSICAL_sphere", std::set<problem_tag>({ problem_tag::GOP,problem_tag::ConOP }));
- the 3rd parameter is the name string to call the problem in command line arguments;
- the 4th parameter marks the tags of the problem.