Ejemplo n.º 1
0
def check_sim(sim_id, dbpath=db_path(), dbname='stigmergy.db'):
    db = db_controller(dbpath, dbname)
    q1 = f"SELECT count(ID) as counted FROM sim WHERE sim.id = {sim_id}"
    q2 = f"SELECT IFNULL(steps_recorded,0)steps_recorded FROM sim WHERE sim.id = {sim_id}"
    if extract_settings(*db.return_all(q1))['counted'] == 0:
        return -1  # sim id does not exist in database
    else:
        return int(extract_settings(*db.return_all(q2))['steps_recorded'])
Ejemplo n.º 2
0
def store_map(id, steps, colormap='plasma'):
    " store a copy of the map at specified steps"
    id = id
    path = db_path() + 'maps/'
    name = f'{id}_'
    print(path)
    ani = SubplotAnimation(sim_id=id,
                           path=path,
                           name=name,
                           store_interval=steps,
                           colormap=colormap)
    plt.show()
Ejemplo n.º 3
0
 def __init__(self):
     super(mywindow, self).__init__()
     self.ui = Ui_MainWindow()
     self.ui.setupUi(self)
     self.i = iterator()  # keep track of messages (self.textlines)
     self.textlines = []  # holds messages to display at the gui
     self.connect_buttons()
     self.welcome_message()
     self.db = db_controller(db_path(), 'stigmergy.db')
     self.load_best()
     data = self.get_settings()
     if data:
         self.load_settings(**data)
Ejemplo n.º 4
0
    def simple_plot(self, sim_id, db_name):
        qry = f"SELECT entropy_vec, scorecard, step_vec from results where sim_id = {sim_id}"
        data, headers = db_controller(db_path(), db_name).return_all(qry)
        H, Y, K = [eval(x) for x in data[0]]  #extract results

        fig = plt.figure(figsize=(18, 9))
        ax_entropy = fig.add_subplot(2, 1, 1)
        ax_score = fig.add_subplot(2, 1, 2)
        ax_entropy.plot(K, H)
        ax_score.plot(K, Y)
        ax_entropy.set_xlabel('k')
        ax_entropy.set_ylabel('H')
        ax_entropy.set_ylim(0, max(H) * 1.1)
        ax_score.set_xlabel('k')
        ax_score.set_ylabel('No. Nest returns')
        ax_score.set_ylim(0, max(Y) * 1.1)

        plt.show()
Ejemplo n.º 5
0

def create_connection(db_file, qrys):
    """ create a database connection to a SQLite database """
    try:
        conn = sqlite3.connect(db_file)
        print(sqlite3.version)
        cursor = conn.cursor()
        for q in qrys:
            cursor.execute(q)
            print(q)
    except Error as e:
        print(e)
    finally:
        conn.close()

if __name__ == '__main__':
    qry = ["CREATE TABLE \"sim\" ( `ID` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE, `status` TEXT NOT NULL DEFAULT 'INITIALIZED', `recording` TEXT, `timestamp` DATETIME DEFAULT CURRENT_TIMESTAMP, `initializer` TEXT, `steps_recorded` INTEGER , comment text)"]
    qry.append("CREATE TABLE `sim_settings` ( `sim_id` INTEGER NOT NULL UNIQUE, `n_agents` integer, `dt` numeric, `steps` integer, `deploy_style` text, `deploy_timing` text, `deploy_timing_args` text, `evap_rate` numeric, discrete integer(1) default 1, FOREIGN KEY(`sim_id`) REFERENCES `sim`(`ID`) ON DELETE CASCADE, PRIMARY KEY(`sim_id`) )")
    qry.append("CREATE TABLE \"step\" ( `SIM_ID` INTEGER NOT NULL, `STEP_NR` INTEGER NOT NULL, `ANT_ID` INTEGER NOT NULL, `X` NUMERIC NOT NULL, `Y` NUMERIC NOT NULL, `THETA` NUMERIC NOT NULL, `Q` NUMERIC NOT NULL, FOREIGN KEY(`SIM_ID`) REFERENCES `sim`(`ID`) )")
    qry.append("CREATE TABLE \"ant_settings\" ( `sim_id` INTEGER NOT NULL UNIQUE, `l` NUMERIC, `sens_offset` NUMERIC, `gain` NUMERIC, `noise_gain` NUMERIC, `sens_fun` TEXT, `deposit_fun` TEXT, rotate_fun TEXT, noise_gain2 NUMERIC, steer_regularization NUMERIC DEFAULT 0, d numeric, override_time numeric, override_max numeric, override text, FOREIGN KEY(`sim_id`) REFERENCES `sim`(`ID`) ON DELETE CASCADE, PRIMARY KEY(`sim_id`) )")
    qry.append("CREATE TABLE `deposit_settings` ( `sim_id` INTEGER NOT NULL UNIQUE, `q` numeric, `return_factor` numeric, `beta` numeric, FOREIGN KEY(`sim_id`) REFERENCES `sim`(`ID`) ON DELETE CASCADE, PRIMARY KEY(`sim_id`) )")
    qry.append("CREATE TABLE `domain_settings` ( `sim_id` INTEGER NOT NULL UNIQUE, `size` TEXT, `pitch` NUMERIC, `nest_loc` TEXT, `nest_rad` integer, `food_loc` TEXT, `food_rad` integer, target_pheromone NUMERIC, FOREIGN KEY(`sim_id`) REFERENCES `sim`(`ID`) ON DELETE CASCADE, PRIMARY KEY(`sim_id`) )")
    qry.append("CREATE TABLE `gauss_settings` ( `sim_id` INTEGER NOT NULL UNIQUE, `significancy` NUMERIC, `covariance` NUMERIC, FOREIGN KEY(`sim_id`) REFERENCES `sim`(`ID`) ON DELETE CASCADE, PRIMARY KEY(`sim_id`) )")
    qry.append("CREATE TABLE `queen_settings` ( `sim_id` INTEGER NOT NULL UNIQUE, `default_speed` NUMERIC, `noise_type` TEXT, `noise_parameter` NUMERIC, FOREIGN KEY(`sim_id`) REFERENCES `sim`(`ID`) ON DELETE CASCADE, PRIMARY KEY(`sim_id`) )")
    qry.append("CREATE TABLE \"results\" ( `sim_id` INTEGER NOT NULL UNIQUE, `entropy_vec` text, `start_entropy` numeric, `end_entropy` numeric, `foodcount` integer, `nestcount` integer, `scorecard` TEXT, `step_vec` TEXT, pheromone_max NUMERIC, FOREIGN KEY(`sim_id`) REFERENCES `sim`(`ID`) ON DELETE CASCADE, PRIMARY KEY(`sim_id`) )")
    qry.append("CREATE TABLE `sens_settings` ( `sim_id` INTEGER NOT NULL UNIQUE, `breakpoint` numeric, `exp_lambda` numeric, FOREIGN KEY(`sim_id`) REFERENCES `sim`(`ID`) ON DELETE CASCADE, PRIMARY KEY(`sim_id`) )")
    path = db_path()+"stigmergy.db"
    print(path)
    create_connection(path, qry)
Ejemplo n.º 6
0
from cythonic.plugins.db_path import db_path
path = db_path() + 'maps/'

import numpy as np
import matplotlib.image as mpimg
from matplotlib.lines import Line2D
import matplotlib.pyplot as plt
import matplotlib.markers as markers
from cythonic.plugins.db_controller import db_controller
from math import ceil

# id = 6108
id = 5975

db = db_controller(db_path(), 'stigmergy.db')
qry = f"""select id, scorecard,step_vec,entropy_vec, size, nest_loc,food_loc,food_rad, pheromone_max from
sim
left join domain_settings d on d.sim_id = sim.id
left join results on results.sim_id = sim.id
where sim.id = {id} and sim.status= 'FINISHED'"""
db_result = db.return_all(qry)
db.close()
result = {}
for i in range(len(db_result[1])):
    result[db_result[1][i]] = db_result[0][0][i]

iter = 1000
dt = .3

img_name = f'{id}_i{iter}.npy'