-
Notifications
You must be signed in to change notification settings - Fork 2
/
Main.py
46 lines (34 loc) · 898 Bytes
/
Main.py
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
37
38
39
40
41
42
43
44
45
46
from Objective import Objective
from Swarm import Swarm
def X2(data):
return data[0] ** 2
def X2_reverse(data):
return 1 / (data[0] ** 2)
def X4(data):
return data[0] ** 4
if __name__ == "__main__":
name = "Power2"
numberOfSwarm = 50
firstObjective = Objective("X2", [0], X2)
secondObjective = Objective("X2_reverse", [1], X2_reverse)
objectiveFunction = [firstObjective, secondObjective]
numOfFeature = 2
featureRange = (
(-100, 100),
(-100, 100),
)
numberOfIter = 150
q = 2
swarm = Swarm(
name=name,
numberOfSwarm=numberOfSwarm,
objectiveFunction=objectiveFunction,
numOfFeature=numOfFeature,
featureRange=featureRange,
numberOfIter=numberOfIter,
q=q
)
swarm.initialize()
swarm.optimize()
swarm.chartHistories()
print(swarm.archive[0])