def test_with_and_with_out_my_algorithm(self):
        s = Simulation(nodes=20, simulate_times=1000, use_my_algorithm=False)
        s.run()
        print("With out my algorithm: "+str(s.all_nodes_received_the_packet_freq))

        s = Simulation(nodes=20, simulate_times=1000, use_my_algorithm=True)
        s.run()
        print("With my algorithm: " + str(s.all_nodes_received_the_packet_freq))
Esempio n. 2
0
 def run(self):
     for i in range(self.roundNumber):
         result = []
         print('Generation ' + str(i + 1) + ':')
         for g in self.genes:
             print('\tGene String ' + g.geneStr)
             self.carmap.updateGeneInfo(GeneInfo(g))
             simulation = Simulation(self.cars, self.carmap)
             (total, average) = simulation.run(False, 10000)
             print('\tTotal: ' + str(total) + ' Average: ' + str(average) + '\n')
             if average == -1:
                 self.carmap.clearAllCars()
                 continue
             result.append((average, g))
         result.sort(key = lambda x:x[0])
         self.addResults(result[0:int(self.geneNumber / 2 )+ 1])
         self.evolve(result[0:int(self.geneNumber / 2 )+ 1])
     return self.results