Skip to content

Commit

Permalink
version: 0.6.1, PSO with nonlinear constraint is available.
Browse files Browse the repository at this point in the history
  • Loading branch information
guofei9987 committed Nov 20, 2020
1 parent d38edec commit 97937b3
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ plt.show()

## 3. PSO(Particle swarm optimization)

### 3.1 PSO with constraint
### 3.1 PSO
**Step1**: define your problem:
-> Demo code: [examples/demo_pso.py#s1](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_pso.py#L1)
```python
Expand Down Expand Up @@ -328,6 +328,21 @@ plt.show()

![PSO_TPS](https://img1.github.io/heuristic_algorithm/pso.png)

### 3.2 PSO with nonlinear constraint

If you need nolinear constraint like `(x[0] - 1) ** 2 + (x[1] - 0) ** 2 - 0.5 ** 2<=0`
Codes are like this:
```python
constraint_ueq = (
lambda x: (x[0] - 1) ** 2 + (x[1] - 0) ** 2 - 0.5 ** 2
,
)
pso = PSO(func=demo_func, n_dim=2, pop=40, max_iter=max_iter, lb=[-2, -2], ub=[2, 2]
, constraint_ueq=constraint_ueq)
```

Note that, you can add more then one nonlinear constraint. Just add it to `constraint_ueq`


![pso_ani](https://img1.github.io/heuristic_algorithm/pso.gif)
**see [examples/demo_pso_ani.py](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_pso_ani.py)**
Expand Down
2 changes: 1 addition & 1 deletion docs/en/args.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ help(sko.AFSA.AFSA)
| w | 0\.8 | inertia weight |
| c1 | 0\.5 | cognitive parameter |
| c2 | 0\.5 | social parameter |

| constraint\_ueq | tuple() | unequal constraint |

### DE

Expand Down
17 changes: 16 additions & 1 deletion docs/zh/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ plt.show()
## 3. 粒子群算法
(PSO, Particle swarm optimization)

### 3.1 带约束的粒子群算法
### 3.1 粒子群算法
**第一步**,定义问题
-> Demo code: [examples/demo_pso.py#s1](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_pso.py#L1)
```python
Expand Down Expand Up @@ -296,6 +296,21 @@ plt.show()
![pso_ani](https://img1.github.io/heuristic_algorithm/pso.gif)
**see [examples/demo_pso.py](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_pso_ani.py)**

### 3.2 带非线性约束的粒子群算法

### 3.2 PSO with nonlinear constraint

加入你的非线性约束是个圆内的面积 `(x[0] - 1) ** 2 + (x[1] - 0) ** 2 - 0.5 ** 2<=0`
这样写代码:
```python
constraint_ueq = (
lambda x: (x[0] - 1) ** 2 + (x[1] - 0) ** 2 - 0.5 ** 2
,
)
pso = PSO(func=demo_func, n_dim=2, pop=40, max_iter=max_iter, lb=[-2, -2], ub=[2, 2]
, constraint_ueq=constraint_ueq)
```
可以有多个非线性约束,向 `constraint_ueq` 加就行了。

## 4. 模拟退火算法
(SA, Simulated Annealing)
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/args.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ help(sko.AFSA.AFSA)
| w | 0\.8 | 惯性权重 |
| c1 | 0\.5 | 个体记忆 |
| c2 | 0\.5 | 集体记忆 |

| constraint\_ueq | 空元组 | 非线性约束 |

### DE

Expand Down
2 changes: 1 addition & 1 deletion sko/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '0.5.9'
__version__ = '0.6.1'

from . import DE, GA, PSO, SA, ACA, AFSA, IA

Expand Down

0 comments on commit 97937b3

Please sign in to comment.