コード例 #1
0
ファイル: hybrid.py プロジェクト: akhilpm/M.tech-Assignments
	def	update_position(self,seq):
		swap.apply_swap_sequence(np.copy(self.pos),seq)
コード例 #2
0
ファイル: hybrid.py プロジェクト: akhilpm/M.tech-Assignments
 def update_position(self, seq):
     swap.apply_swap_sequence(np.copy(self.pos), seq)
コード例 #3
0
ファイル: hybrid.py プロジェクト: akhilpm/M.tech-Assignments
		#		Particle.gbest=np.copy(child)
		#		gbest_fit=fit_val
		#		flag=0

		#if fitness of child is higher than pbest,update pbest
		#if fit_val<pop[i].pbest_fit:
		#	pop[i].pbest=np.copy(child)
		#	pop[i].pbest_fit=fit_val

		#calculate new velocity,update position	
		seq1=swap.get_swap_sequence(pop[i].pbest,np.copy(pop[i].pos))
		seq2=swap.get_swap_sequence(Particle.gbest,np.copy(pop[i].pos))
		new_vel=pop[i].update_velocity(seq1,seq2,k)
		#new_vel=np.random.permutation(new_vel)
		#new_pos=pop[i].update_position(new_vel)
		new_pos=swap.apply_swap_sequence(np.copy(pop[i].pos),new_vel)
		#print new_vel
		#print pop[i].pos
		#print new_pos
		#pop[i].pos=swap.apply_swap_sequence(new_pos,pop[i].pos)
		pop[i].vel=swap.get_swap_sequence(new_pos,np.copy(pop[i].pos))				
		pop[i].pos=np.copy(new_pos)
		pop[i].fitness=pop[i].get_fitness(cost)



		if(k%5==0):
			randno=random.uniform(0,1)
			if(randno>=0.5):
				idx1=random.randrange(0,cities)
				idx2=random.randrange(0,cities)
コード例 #4
0
ファイル: hybrid.py プロジェクト: akhilpm/M.tech-Assignments
        #		Particle.gbest=np.copy(child)
        #		gbest_fit=fit_val
        #		flag=0

        #if fitness of child is higher than pbest,update pbest
        #if fit_val<pop[i].pbest_fit:
        #	pop[i].pbest=np.copy(child)
        #	pop[i].pbest_fit=fit_val

        #calculate new velocity,update position
        seq1 = swap.get_swap_sequence(pop[i].pbest, np.copy(pop[i].pos))
        seq2 = swap.get_swap_sequence(Particle.gbest, np.copy(pop[i].pos))
        new_vel = pop[i].update_velocity(seq1, seq2, k)
        #new_vel=np.random.permutation(new_vel)
        #new_pos=pop[i].update_position(new_vel)
        new_pos = swap.apply_swap_sequence(np.copy(pop[i].pos), new_vel)
        #print new_vel
        #print pop[i].pos
        #print new_pos
        #pop[i].pos=swap.apply_swap_sequence(new_pos,pop[i].pos)
        pop[i].vel = swap.get_swap_sequence(new_pos, np.copy(pop[i].pos))
        pop[i].pos = np.copy(new_pos)
        pop[i].fitness = pop[i].get_fitness(cost)

        if (k % 5 == 0):
            randno = random.uniform(0, 1)
            if (randno >= 0.5):
                idx1 = random.randrange(0, cities)
                idx2 = random.randrange(0, cities)
                temp_val = pop[i].pos[idx1]
                pop[i].pos[idx1] = pop[i].pos[idx2]