0

在 jDE 中,每个人都有自己的 F 和 CR 值。如何以编程方式将这些值分配给每个人。如何更新这些值。

伪代码会有所帮助。

4

1 回答 1

0

如果您希望每个人都有自己的 F 和 CR 值,您可以简单地将其保存在列表中。(伪代码:Python)

ID_POS = 0
ID_FIT = 1
ID_F = 2
ID_CR = 3

def create_solution(problem_size):
    pos = np.random.uniform(lower_bound, upper_bound, problem_size)
    fit = fitness_function(pos)
    F = your_values
    CR = your values 
    return [pos, fit, F, CR]
    
def training(problem_size, pop_size, max_iteration):
    # Initialization
    pop = [create_solution(problem_size) for _ in range(0, pop_size)]
    
    # Evolution process
    for iteration in range(0, max_iteration):
        for i in range(0, pop_size):
            # Do your stuff here
            pos_new = ....
            fit_new = ....
            F_new = ...
            CR_new = ...
            
            if pop[i][ID_FIT] < fit_new:    # meaning the new solution has better fitness than the old one.
                pop[i][ID_F] = F_new 
                pop[i][ID_CR] = CR_new      # This is how you update F and CR for every individual.
            ...

你可以在这里查看我的回购包含大多数最先进的元启发式方法。 https://github.com/thieunguyen5991/metaheuristics

于 2020-07-11T06:46:03.223 回答