def __init__(self):
        communication = CommunicationHandler()
        igaService = IgaService()

        db_instances = communication.selectAllInstances()
        genetic_instances = igaService.fromDatabaseInstances(db_instances)
        communication.uploadPictures(db_instances)
示例#2
0
    def __init__(self):
        communication = CommunicationHandler()
        igaService = IgaService()

        if not communication.reset():
            print("Cannot reset!")
            return
        else:
            print("Reset complete!")

        igaService.reset()
示例#3
0
    def __init__(self, verbose = False):

        # Start the communication
        communication = CommunicationHandler()

        # Resume the IGA service
        self.igaService = IgaService(verbose)

        # Generate the initial population
        population = self.igaService.generateInitialPopulation()
        databaseInstances = self.igaService.createDatabaseInstances(population)

        # Upload the initial population
        if communication.uploadPopulation(databaseInstances):
            print("Upload complete!")
        else:
            print("Cannot upload!")
示例#4
0
    def __init__(self,secondsBetweenUpdates = 60*15, performOnlyOnce = False, verbose=False):
        self.verbose = verbose

        # Start the communication
        self.communication = CommunicationHandler()

        # Resume the IGA service
        self.igaService = IgaService(verbose)

        if performOnlyOnce:
            self.update()
            return

        while True:
            # Sleep until the chosen time arrives
            if self.verbose: print "Waiting " + str(secondsBetweenUpdates) + "s\n"
            time.sleep(secondsBetweenUpdates)
            self.update()
    def __init__(self):
        communication = CommunicationHandler()
        igaService = IgaService()

        igaService.clearAllPictures()  # Local
        communication.clearAllPictures()  # Server
示例#6
0
class SteadyState:
    """
    Steady state interactive genetic algorithm.
    This runs as long as the IGA is needed.
    """

    def __init__(self,secondsBetweenUpdates = 60*15, performOnlyOnce = False, verbose=False):
        self.verbose = verbose

        # Start the communication
        self.communication = CommunicationHandler()

        # Resume the IGA service
        self.igaService = IgaService(verbose)

        if performOnlyOnce:
            self.update()
            return

        while True:
            # Sleep until the chosen time arrives
            if self.verbose: print "Waiting " + str(secondsBetweenUpdates) + "s\n"
            time.sleep(secondsBetweenUpdates)
            self.update()

    def update(self):
        """
        Perform an update step of the IGA steady state.
        """
        if self.verbose: print("START STEADY STATE UPDATE! Time: " + str(time.time()))
        if self.canSteadyStateEvolve():
            if self.verbose: print("Evolving the steady state!")
            self.updateSteadyState()
            self.evolveSteadyState()
        else:
            if self.verbose: print("Cannot evolve the steady state!")
        if self.verbose: print("End steady state update!")

    def updateSteadyState(self):
        """
        Update the steady state if an evolution occoured.
        """
        self.igaService.params.viewCount = self.communication.getViewsCount()
        if self.verbose: print("CURRENT VIEW COUNT: " + str(self.igaService.params.viewCount))
        self.igaService.params.currentGeneration += 1
        self.igaService.params.saveParamsToFile()

    def canSteadyStateEvolve(self):
        """
        Check whether we should evolve the steady state.
        """
        return self.communication.canSteadyStateEvolve(
                                                           self.igaService.params.viewCount,
                                                           self.igaService.params.populationSize,
                                                           self.igaService.params.perc_new_views,
                                                           self.igaService.params.min_individual_views,
                                                           self.igaService.params.min_valid_views
                                                           )

    def evolveSteadyState(self):
        """
        Perform the steady state evolution
        """
        databaseInstances = self.communication.selectInstances(self.igaService.params.selection_size,
                                                           self.igaService.params.min_individual_views,
                                                           self.igaService.params.tournament_size)

        instances = self.igaService.fromDatabaseInstances(databaseInstances)
        offspring = self.igaService.mutateAndRecombine(instances)

        if self.igaService.params.delete_random_instances:
            self.communication.deleteRandomInstances(len(instances), self.igaService.params.min_individual_views)

        databaseInstances = self.igaService.createDatabaseInstances(offspring)
        self.communication.uploadPopulation(databaseInstances)