def generate_population(self, n):
     """
     Generates population with size of N
     :param n:
     :return:
     """
     self.specimenTemplate = self.getSpecimenTemplate(-3, 3)
     self.actualPopulation = PopulationUtils.generate_population(
             self.specimenTemplate,
             n,
             self.fitnessFunction)
     # Show population
     self.plotHandler.updatePopulation(self.actualPopulation)
예제 #2
0
 def generate_population(self):
     """
     Generate Population and set it
     :return:
     """
     template = self.get_specimen_template()
     n = self.numOfSpecimenSpinBox.value()
     self.actualPopulation = PopulationUtils.generate_population(
             template,
             n,
             self.fitness_function)
     # Add reference to algorithm
     if self.algorithm is not None:
         self.algorithm.set_specimen_template(template)
         self.algorithm.set_population(self.actualPopulation)
     # Show population
     self.plotHandler.updatePopulation(self.actualPopulation)
예제 #3
0
    def update_plot(self):
        """
        Updates fitness function surface graph
        If there is some population - generates new one
        """
        x1 = self.mindoubleSpinBox.value()
        x2 = self.maxdoubleSpinBox.value()
        x3 = self.pointsdoubleSpinBox.value()
        self.fitness_function = self.test_functions[self.chooseFunctionComboBox.currentIndex()]

        # regenerate population
        if self.actualPopulation is not None:
            template = self.get_specimen_template()
            n = self.numOfSpecimenSpinBox.value()
            # generate new population
            self.actualPopulation = PopulationUtils.generate_population(
                    self.get_specimen_template(),
                    n,
                    self.fitness_function
            )

            # Add reference to algorithm and update
            if self.algorithm is not None:
                self.algorithm.set_specimen_template(template)
                self.algorithm.set_population(self.actualPopulation)

        # surface plot data
        x = np.arange(x1, x2, x3)

        y = x
        z = None
        if self.fitness_function.__name__ is tF.MultiPurposeFnc.__name__:
            print 'gooo'
            z = tF.MultiPurposeFnc.graph_z(x, y)
        else:
            z = self.fitness_function(np.meshgrid(x, x))
        # Draw all at once
        self.plotHandler.updatePlot(x, y, z, population=self.actualPopulation)