Ajout demonstration final
This commit is contained in:
parent
5002bba5a2
commit
24965b27e7
2 changed files with 90 additions and 51 deletions
35
demo_boucle.py
Normal file
35
demo_boucle.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
#! /bin/python3
|
||||
|
||||
import socket
|
||||
import time
|
||||
import numpy as np
|
||||
|
||||
from coapthon.client.helperclient import HelperClient
|
||||
from coapthon.client.superviseur import (SuperviseurGlobal,
|
||||
SuperviseurLocalFiltre)
|
||||
from coapthon.utils import parse_uri
|
||||
from utils_learning import RequettePeriodique
|
||||
|
||||
|
||||
host, port, path = parse_uri("coap://polaris.kokarde.fr/basic")
|
||||
try:
|
||||
tmp = socket.gethostbyname(host)
|
||||
host = tmp
|
||||
except socket.gaierror:
|
||||
pass
|
||||
|
||||
nombreCapteur = 25
|
||||
periodeRequette = 1
|
||||
periodeControl = 15
|
||||
|
||||
clients = [HelperClient(server=(host, port)) for _ in range(nombreCapteur)]
|
||||
super_g = SuperviseurGlobal(clients, SuperviseurLocalFiltre)
|
||||
|
||||
requests = [RequettePeriodique(client, periodeRequette, path, name="Spamer {}".format(
|
||||
n)) for n, client in enumerate(clients)]
|
||||
[request.start() for request in requests]
|
||||
|
||||
for _ in range(10):
|
||||
super_g.reset()
|
||||
time.sleep(periodeControl)
|
||||
print(super_g.state)
|
|
@ -7,11 +7,7 @@ import time
|
|||
from typing import Any, Callable, Iterable, Mapping, Optional
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from tf_agents.environments import (py_environment, tf_environment,
|
||||
tf_py_environment, utils, wrappers)
|
||||
from tf_agents.specs import array_spec
|
||||
from tf_agents.trajectories import time_step as ts
|
||||
|
||||
|
||||
from coapthon.client.helperclient import HelperClient
|
||||
from coapthon.client.superviseur import (SuperviseurGlobal,
|
||||
|
@ -46,8 +42,13 @@ class RequettePeriodique(threading.Thread):
|
|||
else:
|
||||
raise ValueError
|
||||
|
||||
|
||||
class MaquetteCoapEnv(py_environment.PyEnvironment):
|
||||
try :
|
||||
import tensorflow as tf
|
||||
from tf_agents.environments import (py_environment, tf_environment,
|
||||
tf_py_environment, utils, wrappers)
|
||||
from tf_agents.specs import array_spec
|
||||
from tf_agents.trajectories import time_step as ts
|
||||
class MaquetteCoapEnv(py_environment.PyEnvironment):
|
||||
def __init__(self, clients: Iterable[HelperClient], superviseur_local_type: type, superviseur_global_type: type, request_path: str, args_reward: Iterable[Any] = (),
|
||||
control_period: float = 30, request_period: Iterable[float] = None) -> None:
|
||||
|
||||
|
@ -105,3 +106,6 @@ class MaquetteCoapEnv(py_environment.PyEnvironment):
|
|||
return ts.termination(etat, -10000)
|
||||
else:
|
||||
return ts.transition(etat, reward=recompense)
|
||||
|
||||
except ImportError :
|
||||
print("Pas de fonctionalité d'apprentissage")
|
Loading…
Reference in a new issue