Algorithm

Algorithm Class #

File position: /EMOC/src/algorithm/algorithm.h and /EMOC/src/algorithm/algorithm.cpp

class Algorithm(int thread_id)

The parent class of all algorithms in EMOC. It provides some useful functions for subclasses such as population evaluation and copy.

Parameter:
thread_id: int, default=0
    Index of current thread index. EMOC reserved an array of Global objects. Each object is owned by an unique thread. This index is used to refer to the correpsonding Global object for algorithm class to get some current run's settings easily.
Member variables:
(protected) g_GlobalSettings: Global*
    The pointer to the Global object set according to thread_id. It is used to retrieve the parameter settings directly in algorithm implementations when necessary.

(protected) thread_id_: int
    The index of current thread. It is equal to the given thread_id_.

(protected) real_popnum_: int
    The size of the optimized population. Note that the population size may not eaqual to the setting number when using decomposition based algorithms.

(protected) runtime_: double
    Total time for the algorithm to optimize the problem.

Public Methods:

void Solve()

Optimization process of the algorithm.

It is a pure virtual function which must be implemented in subclass.

Parameter:
void
Returns:
void
void PrintPop()

Display the population information in the screen.

Parameter:
void
Returns:
void
int GetRealPopNum()

Get the real size of population.

Parameter:
void
Returns:
real_popnum_: int
    The size of the current population.
double GetRuntime()

Get the runtime of current run.

Parameter:
void
Returns:
runtime_: double
    Total time for the algorithm to optimize the problem.

Protected Methods:

bool IsTermination()

Get the execution state of current run.

Parameter:
void
Returns:
is_terminated: bool
    Whether the execution is terminated.
void EvaluateInd(Individual* ind)

Evaluate the given individual.

Parameter:
ind: Individual *, default=None
    The pointer to the individual which need to be evaluated.
Returns:
void
void EvaluatePop(Individual** pop, int pop_num)

Evaluate the given population

Parameter:
pop: Individual**, default=None
    The population which need to be evaluated. It's an array of Individual* where each Individual* is a pointer to a individual in the population.

pop_num: int, default=None
    The size of the given population.
Returns:
void
void SwapIndividual(Individual* ind1, Individual* ind2)

Swap the two given individual.

Parameter:
ind1: Individual*, default=None
    Pointer to the first individual.

ind2: Individual*, default=None
    Pointer to the second individual.
Returns:
void
void CopyIndividual(Individual* ind_src, Individual* ind_dest)

Copy the individual ind_src to the indvidual ind_dest.

Parameter:
ind_src: Individual*, default=None
    Pointer to the source individual.

ind_dest: Individual*, default=None
    Pointer to the destination individual.
Returns:
void
int MergePopulation(Individual** pop_src1, int pop_num1, Individual** pop_src2, int pop_num2, Individual** pop_dest)

Get the runtime of current run.

Parameter:
pop_src1: Individual**, default=None
    First source population. It's an array of Individual* where each Individual* is a pointer to a individual in the population.

pop_num1: int, default=None
    Size of the first source population.

pop_src2: Individual**, default=None
    Second source population. It's an array of Individual* where each Individual* is a pointer to a individual in the population.

pop_num2: int, default=None
    Size of the second source population.

pop_dest: Individual**, default=None
    Destination population. It's an array of Individual* where each Individual* is a pointer to a individual in the population.

Returns:
mixed_popnum: int
    Size of the mixed population.