# **Geatpy2**
The Genetic and Evolutionary Algorithm Toolbox for Python with high performance.
[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/geatpy-dev/geatpy/build-and-test)](https://github.com/geatpy-dev/geatpy/actions)
[![Package Status](https://img.shields.io/pypi/status/geatpy.svg)](https://pypi.org/project/geatpy/)
![Python](https://img.shields.io/badge/python->=3.5-green.svg)
![Pypi](https://img.shields.io/badge/pypi-2.7.0-blue.svg)
[![Download](https://img.shields.io/pypi/dm/geatpy.svg)](https://pypi.python.org/pypi/geatpy)
[![License](https://img.shields.io/pypi/l/geatpy.svg)](https://github.com/geatpy-dev/geatpy/blob/master/LICENSE)
[![Gitter](https://badges.gitter.im/geatpy2/community.svg)](https://gitter.im/geatpy2/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
## Introduction
* **Website (including documentation)**: http://www.geatpy.com
* **Demo** : https://github.com/geatpy-dev/geatpy/tree/master/demo
* **Pypi page** : https://pypi.org/project/geatpy/
* **Contact us**: http://geatpy.com/index.php/about/
* **Bug reports**: https://github.com/geatpy-dev/geatpy/issues
* **Notice**: http://geatpy.com/index.php/notice/
* **FAQ**: http://geatpy.com/index.php/faq/
The features of Geatpy:
* Capability of solving single-objective, multi-objectives, many-objectives and combinatorial optimization problems fast.
* A huge number of operators with high performance of evolutionary algorithms (selection, recombination, mutation, migration...).
* Support numerous encodings for the chromosome of the population.
* Many evolutionary algorithm templates, including GA, DE, ES for single/multi-objective(s) evolution.
* Multiple population evolution.
* Support polysomy evolution.
* Parallelization and distribution of evaluations.
* Testbeds containing most common benchmarks functions.
* Support tracking analysis of the evolution iteration.
* Many evaluation metrics of algorithms.
## Improvement of Geatpy 2.7.0
* Add a new way to define the aim function of the problem.
* Support calculating objectives and constraints for the variables of only one individual.
* Add a optimize function to do the optimization more convenient.
* Add new open-source plotting functions.
* Remove the dependency on scipy.
* A new and faster core.
## Installation
1.Installing online:
pip install geatpy
2.From source:
python setup.py install
or
pip install <filename>.whl
**Attention**: Geatpy requires numpy>=1.17.0 and matplotlib>=3.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 **Python**3.5, 3.6, 3.7, 3.8, 3.9, or 3.10 in Windows x32/x64, Linux x64 or MacOS x64.
There are different versions for **Windows**, **Linux** and **Mac**, you can download them from http://geatpy.com/
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 --upgrade --user geatpy
Quick start
-----------
Here is the UML figure of Geatpy2.
![image](https://github.com/geatpy-dev/geatpy/blob/master/structure.png)
For solving a multi-objective optimization problem, you can use **Geatpy** mainly in two steps:
1.Write down the aim function and some relevant settings in a derivative class named **MyProblem**, which is inherited from **Problem** class:
```python
"""MyProblem.py"""
import numpy as np
import geatpy as ea
class MyProblem(ea.Problem): # Inherited from Problem class.
def __init__(self, M): # M is the number of objects.
name = 'DTLZ1' # Problem's name.
maxormins = [1] * M # All objects are need to be minimized.
Dim = M + 4 # Set the dimension of decision variables.
varTypes = [0] * Dim # Set the types of decision variables. 0 means continuous while 1 means discrete.
lb = [0] * Dim # The lower bound of each decision variable.
ub = [1] * Dim # The upper bound of each decision variable.
lbin = [1] * Dim # Whether the lower boundary is included.
ubin = [1] * Dim # Whether the upper boundary is included.
# Call the superclass's constructor to complete the instantiation
ea.Problem.__init__(self, name, M, maxormins, Dim, varTypes, lb, ub, lbin, ubin)
def aimFunc(self, pop): # Write the aim function here, pop is an object of Population class.
Vars = pop.Phen # Get the decision variables
XM = Vars[:,(self.M-1):]
g = np.array([100 * (self.Dim - self.M + 1 + np.sum(((XM - 0.5)**2 - np.cos(20 * np.pi * (XM - 0.5))), 1))]).T
ones_metrix = np.ones((Vars.shape[0], 1))
pop.ObjV = 0.5 * np.fliplr(np.cumprod(np.hstack([ones_metrix, Vars[:,:self.M-1]]), 1)) * np.hstack([ones_metrix, 1 - Vars[:, range(self.M - 2, -1, -1)]]) * np.tile(1 + g, (1, self.M))
def calReferObjV(self): # Calculate the theoretic global optimal solution here.
uniformPoint, ans = ea.crtup(self.M, 10000) # create 10000 uniform points.
realBestObjV = uniformPoint / 2
return realBestObjV
```
2.Instantiate **MyProblem** class and a derivative class inherited from **Algorithm** class in a Python script file "main.py" then execute it. **For example**, trying to find the pareto front of **DTLZ1**, do as the following:
```python
"""main.py"""
import geatpy as ea # Import geatpy
from MyProblem import MyProblem # Import MyProblem class
if __name__ == '__main__':
M = 3 # Set the number of objects.
problem = MyProblem(M) # Instantiate MyProblem class
# Instantiate a algorithm class.
algorithm = ea.moea_NSGA3_templet(problem,
ea.Population(Encoding='RI', NIND=100), # Set 100 individuals.
MAXGEN=500, # Set the max iteration number.
logTras=1) # Set the frequency of logging. If it is zero, it would not log.
# Do the optimization
res = ea.optimize(algorithm, verbose=False, drawing=1, outputMsg=True, drawLog=True, saveFlag=True)
```
Run the "main.py" and the part of the result is:
![image](https://github.com/geatpy-dev/geatpy/blob/master/testbed/moea_test/result/Pareto%20Front%20Plot.svg)
Execution time: 0.3650233745574951 s
Evaluation number: 45500
The number of non-dominated solutions is: 91
gd: 0.00033
igd: 0.02084
hv: 0.84061
spacing: 0.00158
For solving another problem: **Ackley-30D**, which has only one object and 30 decision variables, what you need to do is almost the same as above.
1.Write the aim function in "MyProblem.py".
```python
import numpy as np
import geatpy as ea
class Ackley(ea.Problem): # Inherited from Problem class.
def __init__(self, D = 30):
name = 'Ackley' # Problem's name.
M = 1 # Set the number of objects.
maxormins = [1] * M # All objects are need to be minimized.
Dim = D # Set the dimension of decision variables.
varTypes = [0] * Dim # Set the types of decision variables. 0 means continuous while 1 means discrete.
lb = [-32.768] * Dim # The lower bound of each decision variable.
ub = [32.768] * Dim # The upper bound of each decision variable.
lbin = [1] * Dim # Whether the lower boundary is included.
ubin = [1] * Dim # Whether the upper boundary is included.
# Call the superclass's constructor to complete the instantiation
ea.Problem.__init__(self, name, M, maxormins, Dim, varTypes, lb, ub, lbin, ubin)
def aimFunc(self, pop): # Write the aim function here, pop is an object of Population class.
x = pop.Phen # Get the decision variables
n = self.Dim
f = np.array([-20 * np.exp(-0.2*np.sqrt(1/n*np.sum(x**2, 1))) - np.exp(1/n * np.s
没有合适的资源?快使用搜索试试~ 我知道了~
Python的高性能进化算法工具箱和框架_Python_下载.zip
共410个文件
py:192个
so:75个
pyd:75个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 118 浏览量
2023-04-30
10:28:21
上传
评论
收藏 19.17MB ZIP 举报
温馨提示
Python的高性能进化算法工具箱和框架_Python_下载.zip
资源推荐
资源详情
资源评论
收起资源包目录
Python的高性能进化算法工具箱和框架_Python_下载.zip (410个子文件)
data.csv 152KB
Phen.csv 16KB
Chrom.csv 16KB
rand400.csv 7KB
ObjV.csv 7KB
Field.csv 4KB
ch130.csv 3KB
ts225.csv 2KB
Field.csv 2KB
a280.csv 2KB
rat195.csv 1KB
Chrom.csv 1KB
Phen.csv 1KB
kroD100.csv 911B
Chrom.csv 763B
Phen.csv 763B
Field.csv 525B
att48.csv 468B
eil76.csv 447B
st70.csv 407B
eil51.csv 300B
ObjV.csv 25B
FitnV.csv 25B
ObjV.csv 25B
FitnV.csv 25B
iris.data 4KB
iris_train.data 3KB
iris_test.data 2KB
.flake8 88B
Objective Value Trace Plot.gif 825KB
Objective Value Trace Plot.gif 825KB
.gitignore 2KB
MANIFEST.in 53B
LICENSE 7KB
README.md 9KB
bug_report.md 834B
feature_request.md 595B
structure.png 188KB
Algorithm.py 36KB
PsyPopulation.py 21KB
Population.py 17KB
Problem.py 12KB
moea_PPS_MOEAD_DE_archive_templet.py 12KB
optimize.py 10KB
__init__.py 9KB
soea_multi_SEGA_templet.py 9KB
moea_MOEAD_archive_templet.py 8KB
moea_psy_RVEA_RES_templet.py 7KB
soea_psy_studGA_templet.py 7KB
soea_psy_GGAP_SGA_templet.py 7KB
moea_psy_NSGA2_archive_templet.py 7KB
PointScatter.py 7KB
moea_RVEA_RES_templet.py 7KB
moea_MOEAD_templet.py 6KB
soea_psy_steadyGA_templet.py 6KB
soea_psy_SEGA_templet.py 6KB
soea_GGAP_SGA_templet.py 6KB
moea_NSGA2_archive_templet.py 6KB
moea_MOEAD_DE_templet.py 6KB
moea_psy_NSGA2_templet.py 6KB
soea_psy_EGA_templet.py 6KB
ParCoordPlotter.py 6KB
moea_psy_awGA_templet.py 6KB
moea_psy_RVEA_templet.py 6KB
soea_steadyGA_templet.py 6KB
moea_psy_NSGA3_templet.py 6KB
soea_psy_SGA_templet.py 6KB
soea_SEGA_templet.py 5KB
moea_NSGA2_DE_templet.py 5KB
moea_NSGA2_templet.py 5KB
soea_studGA_templet.py 5KB
soea_EGA_templet.py 5KB
soea_DE_targetToBest_1_bin_templet.py 5KB
soea_DE_targetToBest_1_L_templet.py 5KB
moea_NSGA3_DE_templet.py 5KB
WFG1.py 5KB
soea_ES_1_plus_1_templet.py 5KB
soea_DE_currentToBest_1_L_templet.py 5KB
soea_DE_rand_1_L_templet.py 5KB
soea_DE_currentToBest_1_bin_templet.py 5KB
soea_DE_best_1_L_templet.py 5KB
moea_RVEA_templet.py 5KB
soea_DE_rand_1_bin_templet.py 5KB
soea_DE_best_1_bin_templet.py 5KB
moea_NSGA3_templet.py 5KB
soea_SGA_templet.py 5KB
moea_awGA_templet.py 5KB
soea_ES_miu_plus_lambda_templet.py 5KB
MyProblem.py 5KB
WFG2.py 5KB
MyProblem.py 5KB
soea_DE_currentToRand_1_templet.py 5KB
WFG5.py 4KB
MyProblem.py 4KB
WFG4.py 4KB
WFG3.py 4KB
MyProblem.py 4KB
MyProblem.py 3KB
MyProblem.py 3KB
MyProblem.py 3KB
共 410 条
- 1
- 2
- 3
- 4
- 5
资源评论
快撑死的鱼
- 粉丝: 1w+
- 资源: 9154
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功