Last active
January 9, 2019 13:50
-
-
Save amineremache/4a0283a31de94557a2427e978d62485d to your computer and use it in GitHub Desktop.
The local search implementation for Bee Swarm Optimization algorithm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def localSearch(self): | |
| best=self.fitness | |
| #done=False | |
| lista=[j for j, n in enumerate(self.solution) if n == 1] | |
| indice =lista[0] | |
| for itr in range(self.locIterations): | |
| while(True): | |
| pos=-1 | |
| oldFitness=self.fitness | |
| for i in range(len(self.solution)): | |
| if ((len(lista)==1) and (indice==i)and (i < self.data.nb_attribs-1)): | |
| i+=1 | |
| self.solution[i]= (self.solution[i] + 1) % 2 | |
| quality = self.data.evaluate(self.solution) | |
| if (quality >best): | |
| pos = i | |
| best=quality | |
| self.solution[i]= (self.solution[i]+1) % 2 | |
| self.fitness = oldFitness | |
| if (pos != -1): | |
| self.solution[pos]= (self.solution[pos]+1)%2 | |
| self.fitness = best | |
| else: | |
| break | |
| for i in range(len(self.solution)): | |
| oldFitness=self.fitness | |
| if ((len(lista)==1) and (indice==i) and (i < self.data.nb_attribs-1)): | |
| i+=1 | |
| self.solution[i]= (self.solution[i] + 1) % 2 | |
| quality = self.data.evaluate(self.solution) | |
| if (quality<best): | |
| self.solution[i]= (self.solution[i] + 1) % 2 | |
| self.fitness = oldFitness |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment