Ejemplo n.º 1
0
    def __init__(self, settings):
        if type(settings) == str:
            self.settings = load(settings)
        elif settings:
            self.settings = settings
        else:  # otherwise
            raise Exception("""Wrong argments.
                            Either filename or settings is indispensable.""")

        GA.__init__(self,
                    self.settings['GA']['population_size'],
                    self.settings['GA']['archive_size'],
                    self.settings['GA']['max_generation'],
                    self.settings['GA']['crossover_rate'],
                    self.settings['GA']['mutation_rate'],
                    self.settings['GA']['crossover_parameter'],
                    self.settings['GA']['mutation_parameter'],
                    self.settings['GA']['tournament_size'])
        # First day of roster.
        self.sdate = datetime(self.settings['date']['year'],
                              self.settings['date']['month'],
                              self.settings['date']['day'])
        if self.settings['length']:
            self.length = self.settings['length']
        else:
            (_, self.length) = calendar.monthrange(self.sdate.year,
                                                   self.sdate.month)
        self.initialize_employees()
        self.initialize_settings()
        self.initialize_population()
Ejemplo n.º 2
0
def get_settings(file_name, date):
    """
    change settings by command line options.
    Arguments:
    - `file_name`: file name of settings.
    - `options`: options.
    """
    settings = load(file_name)
    (settings['date']['year'],
     settings['date']['month'],
     settings['date']['day']) = (date[0],
                                 date[1],
                                 date[2])
    save(settings, file_name)
    return settings