-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.py
More file actions
36 lines (32 loc) · 654 Bytes
/
main.py
File metadata and controls
36 lines (32 loc) · 654 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from nsga2 import NSGA2
import moo_test_problems as mtp
# Problem Definition
problem = {
'cost_function': mtp.MOP4,
'n_var': 3,
'var_min': -5,
'var_max': 5,
}
# Initialize Algorithm
alg = NSGA2(
max_iter = 50,
pop_size = 100,
p_crossover = 0.7,
alpha = 0.1,
p_mutation = 0.3,
mu = 0.05,
verbose = True,
)
# Solve the Problem
results = alg.run(problem)
pop = results['pop']
F = results['F']
# Plot Results
import numpy as np
import matplotlib.pyplot as plt
pf_costs = np.array([pop[i]['cost'] for i in F[0]])
plt.scatter(pf_costs[:,0], pf_costs[:,1])
plt.grid()
plt.xlabel('f1')
plt.ylabel('f2')
plt.show()