Пример #1
0
 def __init__(self, crossover_rate=1.0, mutation_rate=0.01):
     #print("cross_over: ", crossover_rate, " , mutation_rate :", mutation_rate)
     self.crossover_rate = crossover_rate
     self.mutation_rate = mutation_rate
     self.genotype = None
     #TODO: parameterize
     self.k = Configuration.get()["translator"]["parameter"]["parameters"]["k"]
Пример #2
0
    def __init__(self):
        print("Mongo object init...")
        self.__config = Configuration.get()
        self.__mongo_config = self.__config["MONGO"]

        self.__host = self.__mongo_config["HOST"]
        self.__user = self.__mongo_config["USER"]
        self.__password = self.__mongo_config["PASSWORD"]
        self.__port = self.__mongo_config["PORT"]
        # self.__auth_db = self.__mongo_config["AUTH_DB"]
        # self.__timeout = self.__mongo_config["TIMEOUT"]
        Mongo.connection = MongoClient(self.__host,
                                       self.__port,
                                       username=self.__user,
                                       password=self.__password,
                                       authMechanism='SCRAM-SHA-256')
        # Mongo.connection = MongoClient(f"mongodb+srv://{self.__user}:{self.__password}@{self.__host}/test?retryWrites=true&w=majority")
        if self.__config["DEBUG"]:
            self.__set_database(self.__mongo_config["DEBUG_DATABASE"])
        else:
            self.__set_database(self.__mongo_config["DATABASE"])

        try:
            self.__check_connection()
            Mongo.__mqttc = mqtt.Client()
            Mongo.__mqttc.connect(self.__mongo_config["MQTT_SERVER"], 1883, 60)

            Mongo.__mbus_server_ip = self.__mongo_config["MBUS_SERVER"]
        except Exception as e:
            raise e
Пример #3
0
    def __init__(self, parent, individual, ann=None):
        self.individual = individual
        self.ann = ann
        config = Configuration.get()
        wrap=config["fitness"]["tracker"]["parameters"]["wrap"]
        pull=config["fitness"]["tracker"]["parameters"]["pull"]
        self.scenario = Simulator(wrap = wrap, pull = pull)

        top = self.top = Toplevel(parent)
        top.title("Tracker game - results wrap=" + str(wrap) + " pull=" + str(pull))
        top.grid()

        w = 30
        h = 15

        self.canvas = TrackerAgentDisplay(top, w, h, wrap=wrap)
        self.canvas.set_model(self.scenario)
        self.canvas.grid(row=0, column=0, columnspan=5, sticky=(N,W,S,E) ,padx=4, pady=4)

        self.v = StringVar()
        speed_adjuster = Scale(top, from_=10, to=1000, command=self.set_speed,orient=HORIZONTAL, variable=self.v)
        speed_adjuster.set(400)
        speed_adjuster.grid(row=1, column=0,padx=4, pady=4)

        restart_button = Button(top, text="Restart", command=self.reset)
        restart_button.grid(row=1, column=4,padx=4, pady=4)

        new_button = Button(top, text="New recording", command=self.restart)
        new_button.grid(row=1, column=3,padx=4, pady=4)


        finish_button = Button(top, text="OK", command=self.ok)
        finish_button.grid(row=2, column=4,padx=4, pady=10)

        self.record_agent()
Пример #4
0
def weatherstack():
    config = Configuration.get()
    url = "http://api.weatherstack.com/current"
    params = {}
    params["query"] = config["OPEN_DATA"]["TOWN"]
    params["access_key"] = config["OPEN_DATA"]["WEATHER_STACK"]["KEY"]
    r = requests.get(url, params)
    return r
Пример #5
0
def weatherapi():
    config = Configuration.get()
    url = "http://api.weatherapi.com/v1/current.json"
    params = {}
    params["q"] = config["OPEN_DATA"]["TOWN"]
    params["key"] = config["OPEN_DATA"]["WEATHER_API"]["KEY"]
    r = requests.get(url, params)
    return r
Пример #6
0
def openweathermap():
    config = Configuration.get()
    url = "http://api.openweathermap.org/data/2.5/weather"
    params = {}
    params["q"] = config["OPEN_DATA"]["TOWN"]
    params["appid"] = config["OPEN_DATA"]["OPEN_WEATHER_MAP"]["KEY"]
    r = requests.get(url, params)
    return r
Пример #7
0
 def make_adult_selector(selector=FULL, config=None):
     '''
     Factory method create object by the supplied string argument, selector.
     Configurations are also retrieved and supplied as a kwarg argument for the object.
     '''
     if not config:
         selections = Configuration.get()["adult_selection"]
     else:
         selections = config["adult_selection"]
     return  getattr(sys.modules[__name__], selections[selector]["class_name"])()
Пример #8
0
 def make_parent_selector(selector=PROPORTIONATE, config=None):
     '''
     Factory method create object by the supplied string argument, selector.
     Configurations are also retrieved and supplied as a kwarg argument for the object.
     '''
     if not config:
         selected = Configuration.get()["parent_selection"][selector]
     else:
         selected = config["parent_selection"][selector]
     config = selected['parameters']
     return getattr(sys.modules[__name__], selected["class_name"])(**config)
Пример #9
0
 def make_adult_selector(selector=FULL, config=None):
     '''
     Factory method create object by the supplied string argument, selector.
     Configurations are also retrieved and supplied as a kwarg argument for the object.
     '''
     if not config:
         selections = Configuration.get()["adult_selection"]
     else:
         selections = config["adult_selection"]
     return getattr(sys.modules[__name__],
                    selections[selector]["class_name"])()
Пример #10
0
 def make_genotype(genotype=DEFAULT, config=None):
     '''
     Factory method create object by the supplied string argument, genotype.
     Configurations are also retrieved and supplied as a kwarg argument for the object.
     '''
     if not config:
         selected = Configuration.get()["genotype"][genotype]
     else:
         selected = config["genotype"][genotype]
     config = selected["parameters"]
     return getattr(sys.modules[__name__], selected["class_name"])(**config)
Пример #11
0
 def make_parent_selector(selector=PROPORTIONATE, config=None):
     '''
     Factory method create object by the supplied string argument, selector.
     Configurations are also retrieved and supplied as a kwarg argument for the object.
     '''
     if not config:
         selected = Configuration.get()["parent_selection"][selector]
     else:
         selected = config["parent_selection"][selector]
     config = selected['parameters']
     return getattr(sys.modules[__name__], selected["class_name"])(**config)
Пример #12
0
 def make_fitness_evaluator(genome_length, evaluator=DEFAULT, config=None):
     '''
     Factory method create object by the supplied string argument, evaluator.
     Configurations are also retrieved and supplied as a kwarg argument for the object.
     '''
     if not config:
         selected = Configuration.get()["fitness"][evaluator]
     else:
         selected = config["fitness"][evaluator]
     config = selected["parameters"]
     return getattr(sys.modules[__name__], selected["class_name"])(genome_length, **config)
Пример #13
0
 def make_fitness_evaluator(genome_length, evaluator=DEFAULT, config=None):
     '''
     Factory method create object by the supplied string argument, evaluator.
     Configurations are also retrieved and supplied as a kwarg argument for the object.
     '''
     if not config:
         selected = Configuration.get()["fitness"][evaluator]
     else:
         selected = config["fitness"][evaluator]
     config = selected["parameters"]
     return getattr(sys.modules[__name__],
                    selected["class_name"])(genome_length, **config)
Пример #14
0
 def make_translator(translator=DEFAULT, config=None):
     '''
     Factory method create object by the supplied string argument, translator.
     Configurations are also retrieved and supplied as a kwarg argument for the object.
     '''
     if not config:
         selected = Configuration.get()["translator"][translator]
     else:
         selected = config["translator"][translator]
     config = selected["parameters"]
     print(config)
     return getattr(sys.modules[__name__], selected["class_name"])(**config)
Пример #15
0
def setting_communications():
    try:
        print("before first request")
        cwd = os.path.dirname(os.path.abspath(__file__))
        Configuration(os.path.join(cwd, 'config/config.json'))
        config = Configuration.get()
        db = Mongo()
        pub = Publisher(config["AMQP"])
        mqttc = Mongo.get_mqttc()
        threading.Thread(target=mqttc_keep_alive, args=(mqttc, )).start()
    except Exception as e:
        print("log", str(e))
Пример #16
0
 def make_translator(translator=DEFAULT, config=None):
     '''
     Factory method create object by the supplied string argument, translator.
     Configurations are also retrieved and supplied as a kwarg argument for the object.
     '''
     if not config:
         selected = Configuration.get()["translator"][translator]
     else:
         selected = config["translator"][translator]
     config = selected["parameters"]
     print(config)
     return getattr(sys.modules[__name__], selected["class_name"])(**config)
Пример #17
0
    def __init__(self, parent, individual, ann=None):
        self.individual = individual
        self.ann = ann
        config = Configuration.get()
        wrap = config["fitness"]["tracker"]["parameters"]["wrap"]
        pull = config["fitness"]["tracker"]["parameters"]["pull"]
        self.scenario = Simulator(wrap=wrap, pull=pull)

        top = self.top = Toplevel(parent)
        top.title("Tracker game - results wrap=" + str(wrap) + " pull=" +
                  str(pull))
        top.grid()

        w = 30
        h = 15

        self.canvas = TrackerAgentDisplay(top, w, h, wrap=wrap)
        self.canvas.set_model(self.scenario)
        self.canvas.grid(row=0,
                         column=0,
                         columnspan=5,
                         sticky=(N, W, S, E),
                         padx=4,
                         pady=4)

        self.v = StringVar()
        speed_adjuster = Scale(top,
                               from_=10,
                               to=1000,
                               command=self.set_speed,
                               orient=HORIZONTAL,
                               variable=self.v)
        speed_adjuster.set(400)
        speed_adjuster.grid(row=1, column=0, padx=4, pady=4)

        restart_button = Button(top, text="Restart", command=self.reset)
        restart_button.grid(row=1, column=4, padx=4, pady=4)

        new_button = Button(top, text="New recording", command=self.restart)
        new_button.grid(row=1, column=3, padx=4, pady=4)

        finish_button = Button(top, text="OK", command=self.ok)
        finish_button.grid(row=2, column=4, padx=4, pady=10)

        self.record_agent()
Пример #18
0
def openData():
    config = Configuration.get()
    if request.method == "GET":
        data = request.values
        if not data.has_key('source'):
            return jsonify({"msg": "Source API not provided"}), 400
        source = data.get('source')
        if source not in config["OPEN_DATA"]["SOURCES"]:
            return jsonify({"msg": "Unknown open data source"}), 400
        apiresponse = None
        if(config["DEBUG"]):
            apiresponse = debugResponse(source)
        else:
            if source == 'openweathermap':
                apiresponse = openweathermap()
            if source == 'weatherapi':
                apiresponse = weatherapi()
            if source == "weatherstack":
                apiresponse = weatherstack()
        if apiresponse.status_code != 200:
            print("log the error")
            abort(500)
        return jsonify(json.loads(apiresponse.text)), 200
Пример #19
0
def show_result(best, ann):
    root = Tk()
    f = Frame(master=root)
    config = Configuration.get()
    result_dialog = ResultDialog(f, best)
    root.mainloop()
Пример #20
0
             print(dir,"4")


genome_length = 306
#272 (no pull and wrap)
#352 (pull and wrap)
#296 (no pull and no wrap)

#306 (no pull and wrap) 9 bit
#396 (pull and wrap) 9 bit
#342 (no pull and no wrap) 9 bit
#486 (no wrap no pull) 3 hidden
pop_size = 50
gen = 10
threshold = 30
config = Configuration.get()
ea_system = EA(config)
listner = Listner()
ea_system.add_listener(listner)
translator = "parameter"
fitness = "tracker"
genotype = "default"
adult = "mixing"
parent = "sigma"
ea_system.setup(translator,fitness,genotype,adult,parent,genome_length)

best = ea_system.run(pop_size, gen, threshold)
ann = RecurrentNeuralNet([5,2,2])
p = best.phenotype_container
p = ann.restructure_parameters(p)
ann.set_weights(p)
Пример #21
0
def show_result(best, ann):
    root = Tk()
    f = Frame(master=root)
    config = Configuration.get()
    result_dialog = ResultDialog(f, best)
    root.mainloop()
Пример #22
0
        show_result(best)

    t = threading.Thread(target=callback)
    t.daemon = True
    t.start()


def show_result(individual):
    result_dialog = ResultDialog(app, individual)


def on_exit(*args):
    '''
    Exits application
    '''
    if app.dirty_config:
        Configuration.store(config)
    root.quit()


config = Configuration.get()
root = Tk()
root.wm_protocol("WM_DELETE_WINDOW", on_exit)
root.geometry("500x300")
app = AppUI(config, master=root)
root.bind('<Return>', run_ea)
ea_system = EA(config)
ani = animation.FuncAnimation(app.graph.f, app.graph.animate, interval=3000)
ea_system.add_listener(app)
root.mainloop()