Пример #1
0
 def get_locations_list(self):
     print('Getting locations list...')
     world_x = \
         database_calls.db_reconstruct_simulation_parameters(self.cur,
             self.starting_time)['world_x']
     world_y = \
         database_calls.db_reconstruct_simulation_parameters(self.cur,
             self.starting_time)['world_y']
     world_z = \
         database_calls.db_reconstruct_simulation_parameters(self.cur,
             self.starting_time)['world_z']
     return [(x, y, z) for x in range(world_x) for y in range(world_y)
             for z in range(world_z)]
Пример #2
0
 def get_locations_list(self):
     print('Getting locations list...')
     world_x = \
         database_calls.db_reconstruct_simulation_parameters(self.cur, 
             self.starting_time)['world_x']
     world_y = \
         database_calls.db_reconstruct_simulation_parameters(self.cur, 
             self.starting_time)['world_y']
     world_z = \
         database_calls.db_reconstruct_simulation_parameters(self.cur, 
             self.starting_time)['world_z']
     return [(x,y,z) 
             for x in range(world_x) 
                 for y in range(world_y) 
                     for z in range(world_z)]
Пример #3
0
 def analyze_individual_status_by_generation(self, csv_output, status, status_analysis, aggregate_functions = None, generations = 'all'):
     print('\n[INDIVIDUAL ' + status.upper() + ' STATUS ANALYSIS]')
     print('Opening outputfile: ' + csv_output + '...')
     outputfile = open(csv_output, 'w')
     print('Getting population size...')
     pop_size = database_calls.db_reconstruct_simulation_parameters(self.cur, self.starting_time)['population_size']
     print('Writing outputfile header...')
     header = ['Generation'] + [str(i) for i in range(1, pop_size + 1)]
     if aggregate_functions != None:
         header = header + [key for key in list(aggregate_functions.keys())]
     outputfile.write(','.join(header) + '\n')
     print('Starting main analysis...')
     if generations == 'all':
         generation_list = database_calls.db_list_generations(self.cur, self.starting_time)
     else:
         generation_list = [str(gen) for gen in generations]
     for generation in generation_list:
         print('Analyzing generation ' + str(generation) + '...')
         print()
         status_list = [status_analysis(stat) for stat in self.get_individual_status_list_by_generation(status, generation)]
         status_row = [str(generation)] + [str(stat_result) for stat_result in status_list]
         if aggregate_functions != None:
             for key in list(aggregate_functions.keys()):
                 status_row.append(str(aggregate_functions[key](status_list)))
         outputfile.write(','.join(status_row) + '\n')
     print('\nIndividual [' + status + '] analysis complete!')
Пример #4
0
 def get_fitness_range_by_percentage(self, percentage):
     print('Getting fitness range...')
     fitness_goal = \
         database_calls.db_reconstruct_simulation_parameters(self.cur, 
             self.starting_time)['goal']
     return range(int(fitness_goal * percentage), 
                  int(fitness_goal + 1))
Пример #5
0
def revive_simulation(rev_parameters, sim_functions):
    print('\n[' + rev_parameters["simulation_name"].upper() + ' REVIVAL SIMULATION]')
    Populations = {}
    if "sim_folder" in rev_parameters:
        print('Accessing simulation files directory...') 
        print('Excavating World entity: ' + rev_parameters['eco_file'] + '...')
        World = excavate_world(rev_parameters['sim_folder'] + \
                               rev_parameters['eco_file'])
        print('Updating parameters with World dimensions...')
        rev_parameters["world_z"] = len(World.ecosystem[0][0][0])
        rev_parameters["world_y"] = len(World.ecosystem[0][0])
        rev_parameters["world_x"] = len(World.ecosystem[0])
        for i in range(len(rev_parameters["pop_files"])):
            print('\nReviving population file: ' + \
                rev_parameters["pop_files"][i] + '...')
            pop_file = rev_parameters["sim_folder"] + \
                rev_parameters["pop_files"][i]
            Populations[rev_parameters["population_names"][i]] = \
                revive_population(pop_file)
        print('\nUpdating revival generation start in simulation parameters...')
        rev_parameters["rev_start"] = [Populations[pop_name].generation 
                                       for pop_name in Populations]
    elif "database_source" in rev_parameters:
        print('Constructing database directory...')
        dbpath = os.sep.join([os.getcwd(), 
                              'Simulations', 
                              rev_parameters["database_source"]])
        print('Connecting to database file: ' + \
            rev_parameters["database_source"] + '...')
        (con, cur) = connect_database(dbpath, None)
        if rev_parameters["simulation_time"] == 'default':
            print('Acquiring simulation starting time...')
            rev_parameters["simulation_time"] = db_list_simulations(cur)[0][0]
        print('Reconstructing old simulation parameters...')
        temp_parameters = db_reconstruct_simulation_parameters(cur, 
                                    rev_parameters["simulation_time"])
        print('Assimilating old simulation parameters with new simulation parameters...')
        for key in temp_parameters:
            if key not in rev_parameters:
                rev_parameters[key] = temp_parameters[key]
        print('Reconstructing World entity...')
        World = db_reconstruct_world(cur, rev_parameters["simulation_time"], 
                                     rev_parameters["rev_start"][0])
        print('\nUpdating population names parameter...')
        for pop_name in rev_parameters["population_names"]:
            print('Reconstructing population: ' + pop_name + '...')
            Populations[pop_name] = db_reconstruct_population(cur, 
                              rev_parameters["simulation_time"], pop_name, 
            rev_parameters["rev_start"][rev_parameters["population_names"].index(pop_name)])
        print('Terminating database connection...')
        con.close()
    print('Updating last generation revival and population size simulation parameters...')
    rev_parameters["rev_finish"] = [(Populations[pop_name].generation + \
                                     rev_parameters["extend_gen"]) 
                                    for pop_name in Populations]
    rev_parameters["rev_pop_size"] = [len(Populations[pop_name].agents) 
                                      for pop_name in Populations]
    print('\nStarting simulation core...')
    simulation_core(sim_functions, rev_parameters, Populations, World)
Пример #6
0
    def analyze_individual_status_by_generation(self,
                                                csv_output,
                                                status,
                                                status_analysis,
                                                aggregate_functions=None,
                                                generations='all'):
        print('\n[INDIVIDUAL ' + status.upper() + ' STATUS ANALYSIS]')
        print('Getting population size...')
        pop_size = \
            database_calls.db_reconstruct_simulation_parameters(self.cur,
                self.starting_time)['population_size']
        print('Constructing generations list...')
        if generations == 'all':
            generation_list = database_calls.db_list_generations(
                self.cur, self.starting_time)
        else:
            generation_list = [str(gen) for gen in generations]
        print('Preparing outputfile: ' + csv_output + '...')
        outputfile = open(csv_output, 'w')
        print('Writing outputfile header...')
        header = ['Generation'] + [str(i) for i in range(1, pop_size + 1)]
        if aggregate_functions != None:
            header = header + \
                     [key for key in list(aggregate_functions.keys())]
        outputfile.write(','.join(header) + '\n')
        outputfile.close()
        print('Starting main analysis...')
        for generation in generation_list:
            print('Analyzing generation ' + str(generation) + '...')
            status_list = \
                [status_analysis(stat)
                 for stat in self.get_individual_status_list_by_generation(status, generation)]
            status_row = [str(generation)] + \
                         [str(stat_result) for stat_result in status_list]
            if aggregate_functions != None:
                for key in list(aggregate_functions.keys()):
                    status_row.append(
                        str(aggregate_functions[key](status_list)))
            outputfile = open(csv_output, 'a')
            outputfile.write(','.join(status_row) + '\n')
            outputfile.close()

        print('\nIndividual [' + status + '] analysis complete!')
Пример #7
0
def revive_simulation(rev_parameters, sim_functions, eb = event_broker()):

    eb.log("[" + rev_parameters["simulation_name"].upper() + " REVIVAL SIMULATION]")

    populations = {}
    world = None
    eb.log("Accessing simulation files directory")
    if "sim_folder" in rev_parameters:

        eb.log('Excavating World entity: ' + rev_parameters['eco_file'])
        world = excavate_world(rev_parameters['sim_folder'] + rev_parameters['eco_file'])

        eb.log('Updating parameters with World dimensions')
        rev_parameters["world_z"] = len(world.ecosystem[0][0][0])
        rev_parameters["world_y"] = len(world.ecosystem[0][0])
        rev_parameters["world_x"] = len(world.ecosystem[0])

        for i in range(len(rev_parameters["pop_files"])):
            eb.log('Reviving population file: ' + rev_parameters["pop_files"][i])
            pop_file = rev_parameters["sim_folder"] + rev_parameters["pop_files"][i]
            populations[rev_parameters["population_names"][i]] = revive_population(pop_file)

        eb.log('Updating revival generation start in simulation parameters')
        rev_parameters["rev_start"] = [populations[pop_name].generation for pop_name in populations]

    elif "database_source" in rev_parameters:

        eb.log('Constructing database directory')
        dbpath = os.sep.join([os.getcwd(), 'Simulations', rev_parameters["database_source"]])

        eb.log('Connecting to database file: ' + rev_parameters["database_source"])
        (con, cur) = connect_database(dbpath, None)

        if rev_parameters["simulation_time"] == 'default':
            eb.log('Acquiring simulation starting time')
            rev_parameters["simulation_time"] = db_list_simulations(cur)[0][0]

        eb.log('Reconstructing old simulation parameters')
        temp_parameters = db_reconstruct_simulation_parameters(cur, rev_parameters["simulation_time"])

        eb.log('Assimilating old simulation parameters with new simulation parameters')
        for key in temp_parameters:
            if key not in rev_parameters:
                rev_parameters[key] = temp_parameters[key]

        eb.log('Reconstructing World entity')
        world = db_reconstruct_world(cur, rev_parameters["simulation_time"], rev_parameters["rev_start"][0])

        eb.log('Updating population names parameter')
        for pop_name in rev_parameters["population_names"]:
            eb.log('Reconstructing population: ' + pop_name)
            populations[pop_name] = db_reconstruct_population(cur, rev_parameters["simulation_time"], pop_name,
                                                              rev_parameters["rev_start"][rev_parameters
                                                              ["population_names"].index(pop_name)])
        eb.log('Terminating database connection')
        con.close()

    eb.log('Updating last generation revival and population size simulation parameters')
    rev_parameters["rev_finish"] = [(populations[pop_name].generation + rev_parameters["extend_gen"])
                                    for pop_name in populations]
    rev_parameters["rev_pop_size"] = [len(populations[pop_name].agents) for pop_name in populations]

    eb.log('Starting simulation core')
    simulation_core(sim_functions, rev_parameters, populations, world)
Пример #8
0
 def get_fitness_range_by_percentage(self, percentage):
     print('Getting fitness range...')
     fitness_goal = \
         database_calls.db_reconstruct_simulation_parameters(self.cur,
             self.starting_time)['goal']
     return range(int(fitness_goal * percentage), int(fitness_goal + 1))