pymoo
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePymoo - Multi-Objective Optimization in Python
Pymoo - Python中的多目标优化
Overview
概述
Pymoo is a comprehensive Python framework for optimization with emphasis on multi-objective problems. Solve single and multi-objective optimization using state-of-the-art algorithms (NSGA-II/III, MOEA/D), benchmark problems (ZDT, DTLZ), customizable genetic operators, and multi-criteria decision making methods. Excels at finding trade-off solutions (Pareto fronts) for problems with conflicting objectives.
Pymoo是一个全面的Python优化框架,重点关注多目标问题。它采用前沿算法(NSGA-II/III、MOEA/D)、基准测试问题(ZDT、DTLZ)、可定制的遗传算子以及多准则决策方法,可解决单目标和多目标优化问题。在为存在目标冲突的问题寻找权衡解决方案(帕累托前沿)方面表现出色。
When to Use This Skill
适用场景
This skill should be used when:
- Solving optimization problems with one or multiple objectives
- Finding Pareto-optimal solutions and analyzing trade-offs
- Implementing evolutionary algorithms (GA, DE, PSO, NSGA-II/III)
- Working with constrained optimization problems
- Benchmarking algorithms on standard test problems (ZDT, DTLZ, WFG)
- Customizing genetic operators (crossover, mutation, selection)
- Visualizing high-dimensional optimization results
- Making decisions from multiple competing solutions
- Handling binary, discrete, continuous, or mixed-variable problems
本技能适用于以下场景:
- 解决单目标或多目标优化问题
- 寻找帕累托最优解并分析权衡关系
- 实现进化算法(GA、DE、PSO、NSGA-II/III)
- 处理带约束的优化问题
- 在标准测试问题(ZDT、DTLZ、WFG)上进行算法基准测试
- 定制遗传算子(交叉、变异、选择)
- 可视化高维度优化结果
- 从多个竞争方案中做出决策
- 处理二进制、离散、连续或混合变量问题
Core Concepts
核心概念
The Unified Interface
统一接口
Pymoo uses a consistent function for all optimization tasks:
minimize()python
from pymoo.optimize import minimize
result = minimize(
problem, # What to optimize
algorithm, # How to optimize
termination, # When to stop
seed=1,
verbose=True
)Result object contains:
- : Decision variables of optimal solution(s)
result.X - : Objective values of optimal solution(s)
result.F - : Constraint violations (if constrained)
result.G - : Algorithm object with history
result.algorithm
Pymoo为所有优化任务提供了一致的函数:
minimize()python
from pymoo.optimize import minimize
result = minimize(
problem, # 优化目标问题
algorithm, # 优化算法
termination, # 终止条件
seed=1,
verbose=True
)结果对象包含:
- : 最优解的决策变量
result.X - : 最优解的目标函数值
result.F - : 约束违反值(如果存在约束)
result.G - : 包含历史记录的算法对象
result.algorithm
Problem Types
问题类型
Single-objective: One objective to minimize/maximize
Multi-objective: 2-3 conflicting objectives → Pareto front
Many-objective: 4+ objectives → High-dimensional Pareto front
Constrained: Objectives + inequality/equality constraints
Dynamic: Time-varying objectives or constraints
单目标: 一个需要最小化/最大化的目标
多目标: 2-3个相互冲突的目标 → 帕累托前沿
多维多目标: 4个及以上目标 → 高维帕累托前沿
带约束: 目标函数 + 不等式/等式约束
动态: 随时间变化的目标或约束
Quick Start Workflows
快速入门流程
Workflow 1: Single-Objective Optimization
流程1:单目标优化
When: Optimizing one objective function
Steps:
- Define or select problem
- Choose single-objective algorithm (GA, DE, PSO, CMA-ES)
- Configure termination criteria
- Run optimization
- Extract best solution
Example:
python
from pymoo.algorithms.soo.nonconvex.ga import GA
from pymoo.problems import get_problem
from pymoo.optimize import minimize适用场景: 优化单个目标函数
步骤:
- 定义或选择问题
- 选择单目标算法(GA、DE、PSO、CMA-ES)
- 配置终止条件
- 运行优化
- 提取最优解
示例:
python
from pymoo.algorithms.soo.nonconvex.ga import GA
from pymoo.problems import get_problem
from pymoo.optimize import minimizeBuilt-in problem
内置问题
problem = get_problem("rastrigin", n_var=10)
problem = get_problem("rastrigin", n_var=10)
Configure Genetic Algorithm
配置遗传算法
algorithm = GA(
pop_size=100,
eliminate_duplicates=True
)
algorithm = GA(
pop_size=100,
eliminate_duplicates=True
)
Optimize
执行优化
result = minimize(
problem,
algorithm,
('n_gen', 200),
seed=1,
verbose=True
)
print(f"Best solution: {result.X}")
print(f"Best objective: {result.F[0]}")
**See:** `scripts/single_objective_example.py` for complete exampleresult = minimize(
problem,
algorithm,
('n_gen', 200),
seed=1,
verbose=True
)
print(f"最优解: {result.X}")
print(f"最优目标值: {result.F[0]}")
**参考:** 完整示例见`scripts/single_objective_example.py`Workflow 2: Multi-Objective Optimization (2-3 objectives)
流程2:多目标优化(2-3个目标)
When: Optimizing 2-3 conflicting objectives, need Pareto front
Algorithm choice: NSGA-II (standard for bi/tri-objective)
Steps:
- Define multi-objective problem
- Configure NSGA-II
- Run optimization to obtain Pareto front
- Visualize trade-offs
- Apply decision making (optional)
Example:
python
from pymoo.algorithms.moo.nsga2 import NSGA2
from pymoo.problems import get_problem
from pymoo.optimize import minimize
from pymoo.visualization.scatter import Scatter适用场景: 优化2-3个相互冲突的目标,需要获取帕累托前沿
算法选择: NSGA-II(双/三目标问题的标准算法)
步骤:
- 定义多目标问题
- 配置NSGA-II算法
- 运行优化以获取帕累托前沿
- 可视化权衡关系
- (可选)应用决策方法
示例:
python
from pymoo.algorithms.moo.nsga2 import NSGA2
from pymoo.problems import get_problem
from pymoo.optimize import minimize
from pymoo.visualization.scatter import ScatterBi-objective benchmark problem
双目标基准测试问题
problem = get_problem("zdt1")
problem = get_problem("zdt1")
NSGA-II algorithm
NSGA-II算法
algorithm = NSGA2(pop_size=100)
algorithm = NSGA2(pop_size=100)
Optimize
执行优化
result = minimize(problem, algorithm, ('n_gen', 200), seed=1)
result = minimize(problem, algorithm, ('n_gen', 200), seed=1)
Visualize Pareto front
可视化帕累托前沿
plot = Scatter()
plot.add(result.F, label="Obtained Front")
plot.add(problem.pareto_front(), label="True Front", alpha=0.3)
plot.show()
print(f"Found {len(result.F)} Pareto-optimal solutions")
**See:** `scripts/multi_objective_example.py` for complete exampleplot = Scatter()
plot.add(result.F, label="获取的前沿")
plot.add(problem.pareto_front(), label="真实前沿", alpha=0.3)
plot.show()
print(f"找到{len(result.F)}个帕累托最优解")
**参考:** 完整示例见`scripts/multi_objective_example.py`Workflow 3: Many-Objective Optimization (4+ objectives)
流程3:多维多目标优化(4个及以上目标)
When: Optimizing 4 or more objectives
Algorithm choice: NSGA-III (designed for many objectives)
Key difference: Must provide reference directions for population guidance
Steps:
- Define many-objective problem
- Generate reference directions
- Configure NSGA-III with reference directions
- Run optimization
- Visualize using Parallel Coordinate Plot
Example:
python
from pymoo.algorithms.moo.nsga3 import NSGA3
from pymoo.problems import get_problem
from pymoo.optimize import minimize
from pymoo.util.ref_dirs import get_reference_directions
from pymoo.visualization.pcp import PCP适用场景: 优化4个及以上目标
算法选择: NSGA-III(专为多维多目标问题设计)
关键差异: 必须提供参考方向以引导种群进化
步骤:
- 定义多维多目标问题
- 生成参考方向
- 配置带参考方向的NSGA-III算法
- 运行优化
- 使用平行坐标图可视化结果
示例:
python
from pymoo.algorithms.moo.nsga3 import NSGA3
from pymoo.problems import get_problem
from pymoo.optimize import minimize
from pymoo.util.ref_dirs import get_reference_directions
from pymoo.visualization.pcp import PCPMany-objective problem (5 objectives)
多维多目标问题(5个目标)
problem = get_problem("dtlz2", n_obj=5)
problem = get_problem("dtlz2", n_obj=5)
Generate reference directions (required for NSGA-III)
生成参考方向(NSGA-III必需)
ref_dirs = get_reference_directions("das-dennis", n_dim=5, n_partitions=12)
ref_dirs = get_reference_directions("das-dennis", n_dim=5, n_partitions=12)
Configure NSGA-III
配置NSGA-III算法
algorithm = NSGA3(ref_dirs=ref_dirs)
algorithm = NSGA3(ref_dirs=ref_dirs)
Optimize
执行优化
result = minimize(problem, algorithm, ('n_gen', 300), seed=1)
result = minimize(problem, algorithm, ('n_gen', 300), seed=1)
Visualize with Parallel Coordinates
用平行坐标图可视化
plot = PCP(labels=[f"f{i+1}" for i in range(5)])
plot.add(result.F, alpha=0.3)
plot.show()
**See:** `scripts/many_objective_example.py` for complete exampleplot = PCP(labels=[f"f{i+1}" for i in range(5)])
plot.add(result.F, alpha=0.3)
plot.show()
**参考:** 完整示例见`scripts/many_objective_example.py`Workflow 4: Custom Problem Definition
流程4:自定义问题定义
When: Solving domain-specific optimization problem
Steps:
- Extend class
ElementwiseProblem - Define with problem dimensions and bounds
__init__ - Implement method for objectives (and constraints)
_evaluate - Use with any algorithm
Unconstrained example:
python
from pymoo.core.problem import ElementwiseProblem
import numpy as np
class MyProblem(ElementwiseProblem):
def __init__(self):
super().__init__(
n_var=2, # Number of variables
n_obj=2, # Number of objectives
xl=np.array([0, 0]), # Lower bounds
xu=np.array([5, 5]) # Upper bounds
)
def _evaluate(self, x, out, *args, **kwargs):
# Define objectives
f1 = x[0]**2 + x[1]**2
f2 = (x[0]-1)**2 + (x[1]-1)**2
out["F"] = [f1, f2]Constrained example:
python
class ConstrainedProblem(ElementwiseProblem):
def __init__(self):
super().__init__(
n_var=2,
n_obj=2,
n_ieq_constr=2, # Inequality constraints
n_eq_constr=1, # Equality constraints
xl=np.array([0, 0]),
xu=np.array([5, 5])
)
def _evaluate(self, x, out, *args, **kwargs):
# Objectives
out["F"] = [f1, f2]
# Inequality constraints (g <= 0)
out["G"] = [g1, g2]
# Equality constraints (h = 0)
out["H"] = [h1]Constraint formulation rules:
- Inequality: Express as (feasible when ≤ 0)
g(x) <= 0 - Equality: Express as (feasible when = 0)
h(x) = 0 - Convert to
g(x) >= b-(g(x) - b) <= 0
See: for complete examples
scripts/custom_problem_example.py适用场景: 解决特定领域的优化问题
步骤:
- 继承类
ElementwiseProblem - 在中定义问题维度和边界
__init__ - 实现方法以计算目标函数(及约束)
_evaluate - 搭配任意算法使用
无约束示例:
python
from pymoo.core.problem import ElementwiseProblem
import numpy as np
class MyProblem(ElementwiseProblem):
def __init__(self):
super().__init__(
n_var=2, # 变量数量
n_obj=2, # 目标数量
xl=np.array([0, 0]), # 变量下界
xu=np.array([5, 5]) # 变量上界
)
def _evaluate(self, x, out, *args, **kwargs):
# 定义目标函数
f1 = x[0]**2 + x[1]**2
f2 = (x[0]-1)**2 + (x[1]-1)**2
out["F"] = [f1, f2]带约束示例:
python
class ConstrainedProblem(ElementwiseProblem):
def __init__(self):
super().__init__(
n_var=2,
n_obj=2,
n_ieq_constr=2, # 不等式约束数量
n_eq_constr=1, # 等式约束数量
xl=np.array([0, 0]),
xu=np.array([5, 5])
)
def _evaluate(self, x, out, *args, **kwargs):
# 目标函数
out["F"] = [f1, f2]
# 不等式约束(g <= 0 时可行)
out["G"] = [g1, g2]
# 等式约束(h = 0 时可行)
out["H"] = [h1]约束构建规则:
- 不等式约束:表示为(当≤0时可行)
g(x) <= 0 - 等式约束:表示为(当=0时可行)
h(x) = 0 - 将转换为
g(x) >= b-(g(x) - b) <= 0
参考: 完整示例见
scripts/custom_problem_example.pyWorkflow 5: Constraint Handling
流程5:约束处理
When: Problem has feasibility constraints
Approach options:
1. Feasibility First (Default - Recommended)
python
from pymoo.algorithms.moo.nsga2 import NSGA2适用场景: 问题存在可行性约束
可选方法:
1. 可行性优先(默认推荐)
python
from pymoo.algorithms.moo.nsga2 import NSGA2Works automatically with constrained problems
自动适配带约束的问题
algorithm = NSGA2(pop_size=100)
result = minimize(problem, algorithm, termination)
algorithm = NSGA2(pop_size=100)
result = minimize(problem, algorithm, termination)
Check feasibility
检查可行性
feasible = result.CV[:, 0] == 0 # CV = constraint violation
print(f"Feasible solutions: {np.sum(feasible)}")
**2. Penalty Method**
```python
from pymoo.constraints.as_penalty import ConstraintsAsPenaltyfeasible = result.CV[:, 0] == 0 # CV = 约束违反值
print(f"可行解数量: {np.sum(feasible)}")
**2. 惩罚法**
```python
from pymoo.constraints.as_penalty import ConstraintsAsPenaltyWrap problem to convert constraints to penalties
将约束转换为惩罚项,包装原问题
problem_penalized = ConstraintsAsPenalty(problem, penalty=1e6)
**3. Constraint as Objective**
```python
from pymoo.constraints.as_obj import ConstraintsAsObjectiveproblem_penalized = ConstraintsAsPenalty(problem, penalty=1e6)
**3. 约束作为目标**
```python
from pymoo.constraints.as_obj import ConstraintsAsObjectiveTreat constraint violation as additional objective
将约束违反值视为额外的目标函数
problem_with_cv = ConstraintsAsObjective(problem)
**4. Specialized Algorithms**
```python
from pymoo.algorithms.soo.nonconvex.sres import SRESproblem_with_cv = ConstraintsAsObjective(problem)
**4. 专用算法**
```python
from pymoo.algorithms.soo.nonconvex.sres import SRESSRES has built-in constraint handling
SRES内置约束处理机制
algorithm = SRES()
**See:** `references/constraints_mcdm.md` for comprehensive constraint handling guidealgorithm = SRES()
**参考:** 完整约束处理指南见`references/constraints_mcdm.md`Workflow 6: Decision Making from Pareto Front
流程6:基于帕累托前沿的决策
When: Have Pareto front, need to select preferred solution(s)
Steps:
- Run multi-objective optimization
- Normalize objectives to [0, 1]
- Define preference weights
- Apply MCDM method
- Visualize selected solution
Example using Pseudo-Weights:
python
from pymoo.mcdm.pseudo_weights import PseudoWeights
import numpy as np适用场景: 已获取帕累托前沿,需要选择偏好的解决方案
步骤:
- 运行多目标优化
- 将目标函数值归一化到[0,1]区间
- 定义偏好权重
- 应用多准则决策方法
- 可视化选中的解决方案
基于伪权重的示例:
python
from pymoo.mcdm.pseudo_weights import PseudoWeights
import numpy as npAfter obtaining result from multi-objective optimization
完成多目标优化后获取结果
Normalize objectives
归一化目标函数值
F_norm = (result.F - result.F.min(axis=0)) / (result.F.max(axis=0) - result.F.min(axis=0))
F_norm = (result.F - result.F.min(axis=0)) / (result.F.max(axis=0) - result.F.min(axis=0))
Define preferences (must sum to 1)
定义偏好权重(总和需为1)
weights = np.array([0.3, 0.7]) # 30% f1, 70% f2
weights = np.array([0.3, 0.7]) # 30% 权重给f1,70%给f2
Apply decision making
应用决策方法
dm = PseudoWeights(weights)
selected_idx = dm.do(F_norm)
dm = PseudoWeights(weights)
selected_idx = dm.do(F_norm)
Get selected solution
获取选中的解决方案
best_solution = result.X[selected_idx]
best_objectives = result.F[selected_idx]
print(f"Selected solution: {best_solution}")
print(f"Objective values: {best_objectives}")
**Other MCDM methods:**
- Compromise Programming: Select closest to ideal point
- Knee Point: Find balanced trade-off solutions
- Hypervolume Contribution: Select most diverse subset
**See:**
- `scripts/decision_making_example.py` for complete example
- `references/constraints_mcdm.md` for detailed MCDM methodsbest_solution = result.X[selected_idx]
best_objectives = result.F[selected_idx]
print(f"选中的解决方案: {best_solution}")
print(f"目标函数值: {best_objectives}")
**其他多准则决策方法:**
- 妥协规划法:选择最接近理想点的解
- 拐点法:寻找平衡的权衡解决方案
- 超体积贡献法:选择多样性最优的子集
**参考:**
- 完整示例见`scripts/decision_making_example.py`
- 详细多准则决策方法见`references/constraints_mcdm.md`Workflow 7: Visualization
流程7:可视化
Choose visualization based on number of objectives:
2 objectives: Scatter Plot
python
from pymoo.visualization.scatter import Scatter
plot = Scatter(title="Bi-objective Results")
plot.add(result.F, color="blue", alpha=0.7)
plot.show()3 objectives: 3D Scatter
python
plot = Scatter(title="Tri-objective Results")
plot.add(result.F) # Automatically renders in 3D
plot.show()4+ objectives: Parallel Coordinate Plot
python
from pymoo.visualization.pcp import PCP
plot = PCP(
labels=[f"f{i+1}" for i in range(n_obj)],
normalize_each_axis=True
)
plot.add(result.F, alpha=0.3)
plot.show()Solution comparison: Petal Diagram
python
from pymoo.visualization.petal import Petal
plot = Petal(
bounds=[result.F.min(axis=0), result.F.max(axis=0)],
labels=["Cost", "Weight", "Efficiency"]
)
plot.add(solution_A, label="Design A")
plot.add(solution_B, label="Design B")
plot.show()See: for all visualization types and usage
references/visualization.md根据目标数量选择可视化方式:
2个目标:散点图
python
from pymoo.visualization.scatter import Scatter
plot = Scatter(title="双目标结果")
plot.add(result.F, color="blue", alpha=0.7)
plot.show()3个目标:3D散点图
python
plot = Scatter(title="三目标结果")
plot.add(result.F) # 自动渲染为3D图
plot.show()4个及以上目标:平行坐标图
python
from pymoo.visualization.pcp import PCP
plot = PCP(
labels=[f"f{i+1}" for i in range(n_obj)],
normalize_each_axis=True
)
plot.add(result.F, alpha=0.3)
plot.show()方案对比:花瓣图
python
from pymoo.visualization.petal import Petal
plot = Petal(
bounds=[result.F.min(axis=0), result.F.max(axis=0)],
labels=["成本", "重量", "效率"]
)
plot.add(solution_A, label="设计方案A")
plot.add(solution_B, label="设计方案B")
plot.show()参考: 所有可视化类型及用法见
references/visualization.mdAlgorithm Selection Guide
算法选择指南
Single-Objective Problems
单目标问题
| Algorithm | Best For | Key Features |
|---|---|---|
| GA | General-purpose | Flexible, customizable operators |
| DE | Continuous optimization | Good global search |
| PSO | Smooth landscapes | Fast convergence |
| CMA-ES | Difficult/noisy problems | Self-adapting |
| 算法 | 适用场景 | 核心特性 |
|---|---|---|
| GA | 通用场景 | 灵活,算子可定制 |
| DE | 连续变量优化 | 全局搜索能力强 |
| PSO | 平滑搜索空间 | 收敛速度快 |
| CMA-ES | 复杂/含噪声问题 | 自适应调整 |
Multi-Objective Problems (2-3 objectives)
多目标问题(2-3个目标)
| Algorithm | Best For | Key Features |
|---|---|---|
| NSGA-II | Standard benchmark | Fast, reliable, well-tested |
| R-NSGA-II | Preference regions | Reference point guidance |
| MOEA/D | Decomposable problems | Scalarization approach |
| 算法 | 适用场景 | 核心特性 |
|---|---|---|
| NSGA-II | 标准基准测试 | 快速、可靠、经过充分验证 |
| R-NSGA-II | 偏好区域搜索 | 参考点引导 |
| MOEA/D | 可分解问题 | 标量化方法 |
Many-Objective Problems (4+ objectives)
多维多目标问题(4个及以上目标)
| Algorithm | Best For | Key Features |
|---|---|---|
| NSGA-III | 4-15 objectives | Reference direction-based |
| RVEA | Adaptive search | Reference vector evolution |
| AGE-MOEA | Complex landscapes | Adaptive geometry |
| 算法 | 适用场景 | 核心特性 |
|---|---|---|
| NSGA-III | 4-15个目标 | 基于参考方向 |
| RVEA | 自适应搜索 | 参考向量进化 |
| AGE-MOEA | 复杂搜索空间 | 自适应几何 |
Constrained Problems
带约束问题
| Approach | Algorithm | When to Use |
|---|---|---|
| Feasibility-first | Any algorithm | Large feasible region |
| Specialized | SRES, ISRES | Heavy constraints |
| Penalty | GA + penalty | Algorithm compatibility |
See: for comprehensive algorithm reference
references/algorithms.md| 方法 | 算法 | 适用场景 |
|---|---|---|
| 可行性优先 | 任意算法 | 可行区域较大 |
| 专用算法 | SRES、ISRES | 约束严格 |
| 惩罚法 | GA + 惩罚项 | 算法兼容性好 |
参考: 完整算法参考见
references/algorithms.mdBenchmark Problems
基准测试问题
Quick problem access:
快速获取问题:
python
from pymoo.problems import get_problempython
from pymoo.problems import get_problemSingle-objective
单目标
problem = get_problem("rastrigin", n_var=10)
problem = get_problem("rosenbrock", n_var=10)
problem = get_problem("rastrigin", n_var=10)
problem = get_problem("rosenbrock", n_var=10)
Multi-objective
多目标
problem = get_problem("zdt1") # Convex front
problem = get_problem("zdt2") # Non-convex front
problem = get_problem("zdt3") # Disconnected front
problem = get_problem("zdt1") # 凸前沿
problem = get_problem("zdt2") # 非凸前沿
problem = get_problem("zdt3") # 不连续前沿
Many-objective
多维多目标
problem = get_problem("dtlz2", n_obj=5, n_var=12)
problem = get_problem("dtlz7", n_obj=4)
**See:** `references/problems.md` for complete test problem referenceproblem = get_problem("dtlz2", n_obj=5, n_var=12)
problem = get_problem("dtlz7", n_obj=4)
**参考:** 完整测试问题参考见`references/problems.md`Genetic Operator Customization
遗传算子定制
Standard operator configuration:
标准算子配置:
python
from pymoo.algorithms.soo.nonconvex.ga import GA
from pymoo.operators.crossover.sbx import SBX
from pymoo.operators.mutation.pm import PM
algorithm = GA(
pop_size=100,
crossover=SBX(prob=0.9, eta=15),
mutation=PM(eta=20),
eliminate_duplicates=True
)python
from pymoo.algorithms.soo.nonconvex.ga import GA
from pymoo.operators.crossover.sbx import SBX
from pymoo.operators.mutation.pm import PM
algorithm = GA(
pop_size=100,
crossover=SBX(prob=0.9, eta=15),
mutation=PM(eta=20),
eliminate_duplicates=True
)Operator selection by variable type:
按变量类型选择算子:
Continuous variables:
- Crossover: SBX (Simulated Binary Crossover)
- Mutation: PM (Polynomial Mutation)
Binary variables:
- Crossover: TwoPointCrossover, UniformCrossover
- Mutation: BitflipMutation
Permutations (TSP, scheduling):
- Crossover: OrderCrossover (OX)
- Mutation: InversionMutation
See: for comprehensive operator reference
references/operators.md连续变量:
- 交叉:SBX(模拟二进制交叉)
- 变异:PM(多项式变异)
二进制变量:
- 交叉:TwoPointCrossover、UniformCrossover
- 变异:BitflipMutation
排列问题(TSP、调度):
- 交叉:OrderCrossover(OX)
- 变异:InversionMutation
参考: 完整算子参考见
references/operators.mdPerformance and Troubleshooting
性能与故障排除
Common issues and solutions:
常见问题及解决方案:
Problem: Algorithm not converging
- Increase population size
- Increase number of generations
- Check if problem is multimodal (try different algorithms)
- Verify constraints are correctly formulated
Problem: Poor Pareto front distribution
- For NSGA-III: Adjust reference directions
- Increase population size
- Check for duplicate elimination
- Verify problem scaling
Problem: Few feasible solutions
- Use constraint-as-objective approach
- Apply repair operators
- Try SRES/ISRES for constrained problems
- Check constraint formulation (should be g <= 0)
Problem: High computational cost
- Reduce population size
- Decrease number of generations
- Use simpler operators
- Enable parallelization (if problem supports)
问题:算法未收敛
- 增大种群规模
- 增加进化代数
- 检查问题是否为多峰(尝试不同算法)
- 验证约束是否正确构建
问题:帕累托前沿分布不佳
- 对于NSGA-III:调整参考方向
- 增大种群规模
- 检查是否开启重复解消除
- 验证问题缩放是否合理
问题:可行解数量少
- 使用约束转目标的方法
- 应用修复算子
- 尝试SRES/ISRES等约束专用算法
- 检查约束构建是否正确(应满足g <=0)
问题:计算成本高
- 减小种群规模
- 减少进化代数
- 使用更简单的算子
- 启用并行计算(如果问题支持)
Best practices:
最佳实践:
- Normalize objectives when scales differ significantly
- Set random seed for reproducibility
- Save history to analyze convergence:
save_history=True - Visualize results to understand solution quality
- Compare with true Pareto front when available
- Use appropriate termination criteria (generations, evaluations, tolerance)
- Tune operator parameters for problem characteristics
- 当目标函数尺度差异较大时,归一化目标函数
- 设置随机种子以保证结果可复现
- 保存历史记录以分析收敛过程:
save_history=True - 可视化结果以理解解的质量
- 当真实帕累托前沿可用时,与其进行对比
- 使用合适的终止条件(进化代数、评估次数、容差)
- 根据问题特性调优算子参数
Resources
资源
This skill includes comprehensive reference documentation and executable examples:
本技能包含全面的参考文档和可执行示例:
references/
references/
Detailed documentation for in-depth understanding:
- algorithms.md: Complete algorithm reference with parameters, usage, and selection guidelines
- problems.md: Benchmark test problems (ZDT, DTLZ, WFG) with characteristics
- operators.md: Genetic operators (sampling, selection, crossover, mutation) with configuration
- visualization.md: All visualization types with examples and selection guide
- constraints_mcdm.md: Constraint handling techniques and multi-criteria decision making methods
Search patterns for references:
- Algorithm details:
grep -r "NSGA-II\|NSGA-III\|MOEA/D" references/ - Constraint methods:
grep -r "Feasibility First\|Penalty\|Repair" references/ - Visualization types:
grep -r "Scatter\|PCP\|Petal" references/
用于深入理解的详细文档:
- algorithms.md:完整算法参考,包含参数、用法和选择指南
- problems.md:基准测试问题(ZDT、DTLZ、WFG)及其特性
- operators.md:遗传算子(采样、选择、交叉、变异)及配置
- visualization.md:所有可视化类型及示例、选择指南
- constraints_mcdm.md:约束处理技术与多准则决策方法
参考文档搜索方式:
- 算法细节:
grep -r "NSGA-II\|NSGA-III\|MOEA/D" references/ - 约束方法:
grep -r "Feasibility First\|Penalty\|Repair" references/ - 可视化类型:
grep -r "Scatter\|PCP\|Petal" references/
scripts/
scripts/
Executable examples demonstrating common workflows:
- single_objective_example.py: Basic single-objective optimization with GA
- multi_objective_example.py: Multi-objective optimization with NSGA-II, visualization
- many_objective_example.py: Many-objective optimization with NSGA-III, reference directions
- custom_problem_example.py: Defining custom problems (constrained and unconstrained)
- decision_making_example.py: Multi-criteria decision making with different preferences
Run examples:
bash
python3 scripts/single_objective_example.py
python3 scripts/multi_objective_example.py
python3 scripts/many_objective_example.py
python3 scripts/custom_problem_example.py
python3 scripts/decision_making_example.py演示常见流程的可执行示例:
- single_objective_example.py:基于GA的基础单目标优化
- multi_objective_example.py:基于NSGA-II的多目标优化及可视化
- many_objective_example.py:基于NSGA-III的多维多目标优化及参考方向
- custom_problem_example.py:自定义问题(带约束和无约束)
- decision_making_example.py:基于不同偏好的多准则决策
运行示例:
bash
python3 scripts/single_objective_example.py
python3 scripts/multi_objective_example.py
python3 scripts/many_objective_example.py
python3 scripts/custom_problem_example.py
python3 scripts/decision_making_example.pyAdditional Notes
补充说明
Installation:
bash
uv pip install pymooDependencies: NumPy, SciPy, matplotlib, autograd (optional for gradient-based)
Documentation: https://pymoo.org/
Version: This skill is based on pymoo 0.6.x
Common patterns:
- Always use for custom problems
ElementwiseProblem - Constraints formulated as and
g(x) <= 0h(x) = 0 - Reference directions required for NSGA-III
- Normalize objectives before MCDM
- Use appropriate termination: or
('n_gen', N)get_termination("f_tol", tol=0.001)
安装:
bash
uv pip install pymoo依赖: NumPy、SciPy、matplotlib、autograd(可选,用于基于梯度的优化)
官方文档: https://pymoo.org/
版本: 本技能基于pymoo 0.6.x版本
常见模式:
- 自定义问题请始终使用
ElementwiseProblem - 约束需构建为和
g(x) <= 0的形式h(x) = 0 - NSGA-III必须提供参考方向
- 多准则决策前需归一化目标函数
- 使用合适的终止条件:或
('n_gen', N)get_termination("f_tol", tol=0.001)