Skip to content

Commit

Permalink
bug fix when skip_duplicates = False
Browse files Browse the repository at this point in the history
  • Loading branch information
iacopoff committed Oct 4, 2020
1 parent 0964c36 commit d49d521
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions spotpy/algorithms/nsgaii.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,20 +335,13 @@ def sample(self, generations, n_obj, n_pop = None, skip_duplicates = False,

for igen in range(1,self.generations - 1):

Rt = np.vstack([Pt_parent,Qt])
Rt = np.vstack([Pt_parent,Qt])


if self.skip_duplicates:
# print(f"pop: {len(Qt)}")
# print(f"pop non dup: {len(np.unique(Qt,axis=0))}")


#Qt_nondup = np.unique(Qt,axis=0)
#self.n_pop_nondup = len(Qt_nondup)

# evaluate population
param_generator = ((i,Qt[i,:]) for i in range(self.n_pop))

param_generator = ((i,Qt[i,:]) for i in range(self.n_pop))

ret = list(self.repeat(param_generator))

Expand All @@ -358,39 +351,38 @@ def sample(self, generations, n_obj, n_pop = None, skip_duplicates = False,
Of.append(self.postprocessing(igen, parameters, simulation_results, chains=p))
Of = np.vstack(Of)

Of = np.vstack([Of_parent ,Of])
Of = np.vstack([Of_parent ,Of])

nonDomRank = self.fastSort(Of)

crDist = np.empty(len(Of))
for rk in range(1,np.max(nonDomRank)+1):
crDist[nonDomRank == rk] = self.crowdDist(Of[nonDomRank ==rk,:])
else:

# print(f"pop: {len(Qt)}")
# print(f"pop non dup: {len(np.unique(Qt,axis=0))}")

n_pop_combined = self.n_pop *2
# evaluate population
param_generator = ((i,Rt[i,:]) for i in range(self.n_pop *2))

param_generator = ((i,Rt[i,:]) for i in range( n_pop_combined ))


#import pdb;pdb.set_trace()
ret = list(self.repeat(param_generator))

Of = []
for p in range(self.n_pop*2):
for p in range(n_pop_combined):
index, parameters,simulation_results = ret[p]
Of.append(self.postprocessing(igen, parameters, simulation_results, chains=p))
Of = np.vstack(Of)

nonDomRank = self.fastSort(Of)

crDist = np.empty(self.n_pop*2)
crDist = np.empty(n_pop_combined)
for rk in range(1,np.max(nonDomRank)+1):
crDist[nonDomRank == rk] = self.crowdDist(Of[nonDomRank ==rk,:])


# sorting
rank = np.lexsort((-crDist,nonDomRank))[:self.n_pop]
rank = np.lexsort((-crDist,nonDomRank))[:self.n_pop]
Ptsort = Rt[rank]
Ofsort = Of[rank]

Expand Down

0 comments on commit d49d521

Please sign in to comment.