Python DLL

Python Dynamic Link Library #

In Quick Start section, we give a brief introduction on how to use EMOC in python language. Basically speaking, several fundamental classes are exported into python. So the users can utilize these classes to define their own problem and solve it with available algorithms in EMOC.

In this section, we will give the detailed definition of these exported classes to help users understand the python dynamic link library of EMOC.

Exported Classes #

Problem #

This class is basically the same as original class in C++ except some member variable names.

class Problem(int dec_num, int obj_num)

The parent class of all test problems in EMOC. The custom problem in python need to inherit form this class.

Parameter:
dec_num: int, default=None
    The number of decision variables setting for the problem.

obj_num: int, default=None
    The number of objective functions setting for the problem.
Member variables:
(public) dec_num: int
    The number of decision variables set by users. It is equal to the given dec_num.

(public) obj_num: int
    The number of objective functions set by users. It is equal to the given obj_num.

(public) lower_bound: std::vector<double>
    The lower bound of each decision variable. The size of this std::vector is dec_num.

(public) upper_bound: std::vector<double>
    The upper bound of each decision variable. The size of this std::vector is dec_num.

Public Member Functions:

void CalObj(Individual* ind)

Calculate the objective function values.

This function is a pure virtual function which must be implemented in custom problem in python.

Parameter:
ind: Individual*, default=None
    Pointer to the individual which need to calculate the objectives.
Returns:
void

Individual #

This class is basically the same as original class in C++ except some member variable names.

class Individual(int dec_num, int obj_num)

The class for each individual in the population.

Parameter:
dec_num: int, default=None
    The number of decision variables.

obj_num: int, default=None
    The number of objectives.
Member variables:
(public) dec: std::vector<double>
    Decision variables of this individual. The size of this std::vector is dec_num.

(public) obj: std::vector<double>
    Objectives of this individual. The size of this std::vector is obj_num.

EMOCManager #

class EMOCManager()

EMOCManager is the manager class of EMOC which controls the execution of EMOC. Most original member variables in C++ definition are omitted. Because they are not needed in python.

Parameter:
void
Member variables:
void

Public Methods:

void Run()

Start this optimization with current parameters.

Parameter:
void
Returns:
void
void SetTaskParameters(const EMOCParameters& para)

Set the parameters of this execution

Parameter:
para: const EMOCParameters&, default=None
    Parameters of this run.
Returns:
void
EMOCGeneralResult GetPythonResult()

Get the optimization results of this run.

Parameter:
void
Returns:
result: EMOCGeneralResult
    Optimization results of this run.

EMOCParameters #

class EMOCParameters()

EMOCParameters is a simple structure consists of basic parameter settings variables and two public interface for configuring custom problem and initial population

Parameter:
void
Member variables:
(public) algorithm_name: string
    Algorithm name.

(public) problem_name: string
    Problem name.

(public) population_num: int
    The size of population.

(public) decision_num: int
    The number of decision variables.

(public) objective_num: int
    The number of objectives.

(public) max_evaluation: int
    The max evaluation times of this optimization.

(public) output_interval: int
    Save interval in generation.

Public Methods:

void SetProblem(Problem* problem)

Set the custom problem.

Parameter:
problem: Problem*, default=None
    Pointer to the custom problem. This can be an problem object in python.
Returns:
void
void SetInitialPop(std::vector<std::vector<double>> initial_pop)

Set the custom initial population.

Parameter:
initial_pop: std::vector<std::vector<double>>, default=None
    The custom initial population. It's basically a 2D array of double. Each row is the decision variables of an individual.
Returns:
void

EMOCGeneralResult #

class EMOCGeneralResult()

The class for the optimization results which can get by EMOCManager::GetResult().

Parameter:
void
Member variables:
(public) igd: double
    IGD value of this optimization. This is only valid in multi-objective optimization problem.

(public) gd: double
    GD value of this optimization. This is only valid in multi-objective optimization problem.

(public) hv: double
    HV value of this optimization. This is only valid in multi-objective optimization problem.

(public) spacing: double
    Spacing value of this optimization. This is only valid in multi-objective optimization problem.

(public) igdplus: double
    IGD Plus value of this optimization. This is only valid in multi-objective optimization problem.

(public) gdplus: double
    GD Plus value of this optimization. This is only valid in multi-objective optimization problem.

(public) best_value: double
    Best found value. This is only valid in single-objective optimization problem.

(public) runtime: double
    The run time of this run.

(public) pop_num: int
    The size of the final population.

(public) pop_decs: 2D list
    Decision variables of final population.

(public) pop_objs: 2D list
    Objectives of final population.