Exemplo n.º 1
0
from models import AdaptiveGA
from optproblems import cec2005
from os import makedirs
import statistics
import csv

if __name__ == '__main__':

    dims = 10
    bounds = [ [-100 for i in range(dims)], [100 for i in range(dims)] ]
    functions = [ cec2005.F1(dims), cec2005.F2(dims), cec2005.F3(dims), cec2005.F4(dims), cec2005.F5(dims)]
    optimums = [-450, -450, -450, -450, -310]
    FESThresholds = [0, 0.001, 0.01, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1]
    numRuns = 25


    # Creating result path
    pathName = "Results/AGA"
    makedirs(pathName, exist_ok=True)

    # Initializing result files

    tableFileName = pathName + "/AGA_" + str(dims) + "D.csv"

    with open(tableFileName, "w") as resultsFile:

        writer = csv.writer(resultsFile, delimiter = ',')

        writer.writerow( ["Fi_10D", "Best", "Worst", "Median", "Mean", "Std_Dev", "Success_Rate"] )

Exemplo n.º 2
0
                    "avgFits": avgFits}

        except KeyboardInterrupt:
            return


if __name__ == '__main__':

    # Test of the ABC's performance over CEC2005's F1 (shifted sphere)

    import time
    from optproblems import cec2005
    # np.seterr("raise") # any calculation error immediately stops the execution
    dims = 10

    bounds = [ [-100 for i in range(dims)], [100 for i in range(dims)] ] # 10-dimensional sphere (optimum: 0)

    start = time.time()

    # Initialization
    ABC = ArtificialBeeColony(cec2005.F1(dims), bounds, popSize=50, workerOnlookerSplit=0.5, limit=None, numScouts=1, optimum=-450) # F5: -310 / others: -450
    ABC.execute()
    results = ABC.results

    print("ABC: for criterion = " + ABC.crit + ", reached optimum of " + str(results["bestFits"][-1]) +
    " (error of " + str(results["errors"][-1]) + ") (points " + str(results["bestPoints"][-1]) + ") with " + str(results["generations"][-1]) + " generations" +
    " and " + str(results["FESCounts"][-1]) + " fitness evaluations" )

    end = time.time()
    print("time:" + str(end - start))
Exemplo n.º 3
0
        newPop.extend(self.pop)
        self.pop = newPop[:self.popSize]  # cuts the worst individuals here


if __name__ == '__main__':

    # Test of the GA's performance over CEC2005's F1 (shifted sphere)

    import time
    from optproblems import cec2005

    bounds = [[-100 for i in range(10)],
              [100 for i in range(10)]]  # 10-dimensional sphere (optimum: 0)

    func = cec2005.F1(10)
    start = time.time()

    # Initialization
    GA = GeneticAlgorithm(func,
                          bounds,
                          crit="min",
                          optimum=-450,
                          tol=1e-08,
                          eliteSize=1,
                          matingPoolSize=100,
                          popSize=100)  #F5 = -310

    GA.setParentSelection(GA.tournamentSelection, (True, ))
    GA.setCrossover(GA.blxAlphaCrossover, (0.5, 1))  # alpha, prob
    # GA.setMutation(GA.creepMutation, (1, 0, 1)) # prob, mean, sigma
Exemplo n.º 4
0
from models import ArtificialBeeColony
from optproblems import cec2005
from os import makedirs
import statistics
import csv

if __name__ == '__main__':

    dims = 10
    bounds = [[-100 for i in range(dims)], [100 for i in range(dims)]]
    functions = [
        cec2005.F1(dims),
        cec2005.F2(dims),
        cec2005.F3(dims),
        cec2005.F4(dims),
        cec2005.F5(dims)
    ]
    optimums = [-450, -450, -450, -450, -310]
    FESThresholds = [
        0, 0.001, 0.01, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1
    ]
    numRuns = 25

    # Creating result path
    pathName = "Results/ABC"
    makedirs(pathName, exist_ok=True)

    # Initializing result files

    tableFileName = pathName + "/ABC_" + str(dims) + "D.csv"
Exemplo n.º 5
0
if __name__ == '__main__':
    # Test of the SSA's performance over CEC2005's F1 (shifted sphere)

    import time
    from optproblems import cec2005
    # np.seterr("raise") # any calculation error immediately stops the execution
    dims = 10

    bounds = [[-100 for i in range(dims)],
              [100 for i in range(dims)]]  # 10-dimensional sphere (optimum: 0)

    start = time.time()

    # Initialization
    SSA = SocialSpiderAlgorithm(cec2005.F1(dims),
                                bounds,
                                popSize=10,
                                vibrationConstant=-700,
                                attenuationRate=1,
                                maskChangeProb=0.7,
                                maskOneProb=0.1,
                                optimum=-450)  # F5: -310 / others: -450
    #compare normalizing and non-normalizing
    #compare populations of 20, 30 and 50
    SSA.execute()
    results = SSA.results

    print("SSA: for criterion = " + SSA.crit + ", reached optimum of " +
          str(results["bestFits"][-1]) + " (error of " +
          str(results["errors"][-1]) + ") (points " +
Exemplo n.º 6
0
elitism_bool = True
elitism_number = 1
hiper_parameters_dict = {
    "cross_method": "aritmetic",
    "cross_ratio": crossover_ratio,
    "cross_alpha": alpha,
    "mutation_method": "gauss",
    "mutation_ratio": mutation_ratio,
    "elitism_bool": True,
    "selection_method": "tournment"
}

savePathParameters = "ag_function1.csv"
global_min = -450.0

function1 = cec2005.F1(n_genes)

ag = Genetic_Algorithm(Func_obj1,
                       n_genes,
                       bounds,
                       pop_size,
                       n_epochs,
                       hiper_parameters_dict,
                       optimum=global_min,
                       max_obj=False)

n_runs = 25
error_list = []
success_count = 0

for n in range(1):