Skip to content

Commit

Permalink
GWO PSO
Browse files Browse the repository at this point in the history
  • Loading branch information
mariosky committed Mar 18, 2017
1 parent dabc5b8 commit 88bc46e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
7 changes: 4 additions & 3 deletions GWO.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ def GWO(objf,lb,ub,dim,SearchAgents_no,Max_iter, Positions = None, fopt=float("-


# Calculate objective function for each search agent
scores = objf(Positions[i,:])
#score = objf(Positions[i,:])
fitness = objf(Positions[i, :])
#print Positions
#print scores
#score = abs(fitness - fopt)
#print fitness, Positions[i, :]
#print score, fitness

# Update Alpha, Beta, and Delta
if fitness<Alpha_score :
Expand Down
14 changes: 8 additions & 6 deletions PSO.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import random
import numpy
import math
from colorama import Fore, Back, Style
#from colorama import Fore, Back, Style
from solution import solution
import time

Expand All @@ -17,7 +17,7 @@



def PSO(objf,lb,ub,dim,PopSize,iters):
def PSO(objf,lb,ub,dim,PopSize,iters, pos = None, fopt=float("-inf") , **kwargs ):

# PSO parameters

Expand Down Expand Up @@ -48,7 +48,7 @@ def PSO(objf,lb,ub,dim,PopSize,iters):

gBestScore=float("inf")

pos=numpy.random.uniform(0,1,(PopSize,dim)) *(ub-lb)+lb
#pos=numpy.random.uniform(0,1,(PopSize,dim)) *(ub-lb)+lb

convergence_curve=numpy.zeros(iters)

Expand Down Expand Up @@ -92,14 +92,16 @@ def PSO(objf,lb,ub,dim,PopSize,iters):

convergence_curve[l]=gBestScore

if (l%1==0):
if (l%1==0) and 'verbose' in kwargs:
print(['At iteration '+ str(l+1)+ ' the best fitness is '+ str(gBestScore)]);
timerEnd=time.time()
timerEnd=time.time()
s.best=gBestScore
s.endTime=time.strftime("%Y-%m-%d-%H-%M-%S")
s.executionTime=timerEnd-timerStart
s.convergence=convergence_curve
s.convergence=list(convergence_curve)
s.optimizer="PSO"
s.objfname=objf.__name__
s.pop = list(pos)

return s

Expand Down

0 comments on commit 88bc46e

Please sign in to comment.