Git Product home page Git Product logo

geatpy's Introduction

Geatpy

The Genetic and Evolutionary Algorithm Toolbox for Python

Travis Python Pypi

Introduction

It provides:

  • global optimization capabilities in Python using genetic and evolutionary algorithm to solve problems unsuitable for traditional optimization approaches.

  • a great many of genetic and evolutionary operators, so that you can deal with single or multi-objective optimization problems.

It can work faster with numpy+mkl. If you want to speed your projects, please install numpy+mkl.

Installation

1.Via pip:

pip install geatpy

2.From source:

python setup.py install

or

pip install <filename>.whl

Attention: Geatpy requires numpy>=1.12.1 and matplotlib>=2.0.0, the installation program won't help you install them so that you have to install both of them by yourselves.

Versions

Geatpy must run under Python3.5, 3.6 or 3.7 in x32 or x64 in Windows systems.

The version of Geatpy on github is the latest version suitable for Python >= 3.5

You can also update Geatpy by executing the command:

pip install --upgrade geatpy

If something wrong happened, such as decoding error about 'utf8' of pip, run this command instead or execute it as an administrator:

pip install --user --upgrade geatpy

Quick start

You can use Geatpy mainly in two ways:

  1. Create a script, write all the codes on it and run. It's the easiest way, but it needs much too codes and is not good for reuse. To get some examples, please link to http://www.geatpy.com/tutorials.

  2. Using templets and functional interfaces. For example, we try to find the pareto front of DTLZ1, do as the following:

2.1) Write DTLZ1 function on a file named "aimfuc.py" as a functional interfaces:

"""aimfuc.py"""
# DTLZ1
def DTLZ1(Chrom, LegV): # LegV is legal-sign of the population
    M = 3 # M is the dimensions of DTLZ1
    x = Chrom.T # Chrom is a numpy array standing for the chromosomes of the population
    XM = x[M-1:]
    k = x.shape[0] - M + 1
    gx = 100 * (k + np.sum((XM - 0.5) ** 2 - np.cos(20 * np.pi * (XM - 0.5)), 0))
    ObjV = (np.array([[]]).T) * np.zeros((1, Chrom.shape[0])) # define ObjV to recod function values
    ObjV = np.vstack([ObjV, 0.5 * np.cumprod(x[:M-1], 0)[-1] * (1 + gx)])
    for i in range(2, M):
        ObjV = np.vstack([ObjV, 0.5 * np.cumprod(x[: M-i], 0)[-1] * (1 - x[M-i]) * (1 + gx)])
    ObjV = np.vstack([ObjV, 0.5 * (1 - x[0]) * (1 + gx)])
    return [ObjV.T, LegV] # use '.T' to change ObjV so that each row stands for function values of each individual of the population

2.2) Write the main script using NSGA-II templet of Geatpy to solve the problem.

"""main.py"""
import numpy as np
import geatpy as ga # import geatpy

AIM_M = __import__('aimfuc') # get the address of objective function
AIM_F = 'DTLZ1' # You can set DTL1,2,3 or 4

"""==================================variables setting================================"""
ranges = np.vstack([np.zeros((1,7)), np.ones((1,7))]) # define the ranges of variables in DTLZ1
borders = np.vstack([np.ones((1,7)), np.ones((1,7))]) # define the borders of variables in DTLZ1
FieldDR = ga.crtfld(ranges, borders) # create the FieldDR
"""=======================use sga2_templet to find the Pareto front==================="""
[ObjV, NDSet, NDSetObjV, times] = ga.moea_nsga2_templet(AIM_M, AIM_F, None, None, FieldDR, problem = 'R', maxormin = 1, MAXGEN = 1000, MAXSIZE = 2000, NIND = 50, SUBPOP = 1, GGAP = 1, selectStyle = 'tour', recombinStyle = 'xovdprs', recopt = 0.9, pm = None, distribute = True, drawing = 1)

The partial of the pareto front is:

image

To get more tutorials, please link to http://www.geatpy.com

There are more demos in Geatpy's source. Including ZDT1/2/3/4/6、 DTLZ1/2/3/4、single-objective examples、discrete problem solving and so forth.

geatpy's People

Contributors

geatpy-dev avatar 1061655504 avatar strongwinder avatar

Watchers

James Cloos avatar

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.