Giter Site home page Giter Site logo

divpopga's Introduction

divpopga

Diverse Population Genetic Algorithm for Real-valued Optimization

Installation

] add https://github.com/jbytecode/divpopga

or

julia> using Pkg
julia> Pkg.add(PackageSpec(url = "https://github.com/jbytecode/divpopga"))

Update

] update

or

julia> using Pkg
julia> Pkg.update()

Examples

See https://github.com/jbytecode/divpopga/tree/main/example

divpopga's People

Contributors

akadal avatar jbytecode avatar

Watchers

 avatar

Forkers

akadal

divpopga's Issues

Early termination

Hi @akadal

Now, ga terminates when a target cost is achieved:

using DivPopGa
import DivPopGa.ClusteredGa as CLGA 

# BENT CIGAR FUNCTION
function cec2017f1(x::Array{Float64, 1})::Float64
    term1 = x[1]^2
    term2 = 0
    for i in 2:length(x)
        term2 = term2 + x[i]^2
    end
    term2 = term2 * 1000000

    return (term1 + term2)
end

popsize = 100
generations = 10000
mutationParameter1 = 5.0
mutationParameter2 = 0.05
num_elitists = 1
num_variables = 50
lower = ones(Float64, num_variables) * -100.0
upper = ones(Float64, num_variables) * 100.0

mutatefn  = CLGA.makerandommutation(lower, upper, 0.001)
crossfn = CLGA.makelinearcrossover(cec2017f1)



res_ga = CLGA.ga(
    popsize,
    generations,
    lower,      
    upper,      
    cec2017f1,     
    crossfn,    
    mutatefn,   
    CLGA.GA_TYPE_CLUSTER, 
    elitism = num_elitists,
    verbose = true,
    targetcost = 10.0
)

@info res_ga.best.cost res_ga.best.genes res_ga.generations  

here targetcost is the target, which is 10.0. When the algorithm encounters a cost value of 10.0, it terminates.

The ga function now returns a GAResult object:

struct GAResult 
    population::Array{Chromosome, 1}
    best::Chromosome
    generations::Int 
end

f1 func

function:

# BENT CIGAR FUNCTION
function cec2017f1(x::Array{Float64, 1})::Float64
    
    term1 = x[1]^2
    term2 = 0
    for i in 2:length(x)
        term2 = term2 + x[i]^2
    end
    term2 = term2 * 1000000

    return (term1 + term2)

end

specs:

const popsize = 100
const generations = 10000
const mutationParameter1 = 5.0
const mutationParameter2 = 0.05
const num_elitists = 5
const num_variables = [50]
mutatefn  = CLGA.makerandommutation(repeat([-100.0], outer=50), repeat([100.0], outer=50), 0.05)
crossfn = CLGA.makeweightedcrossover()

run:

res_ga = CLGA.ga(
    popsize,
    generations,
    repeat([-100.0], outer=numV),      
    repeat([100.0], outer=numV),      
    costfn,     
    crossfn,    
    mutatefn,   
    CLGA.GA_TYPE_CLASSIC, 
    elitism = num_elitists
)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.