Example #1
0
    def generate_next_generation(self):
        # find models to mutate to next generation
        newAgents_idx = []
        for i in range(self.pop_size):
            newAgents_idx.append(self.pool_selection())

        # temporarily save models and clear session
        configs, weights = [], []
        for model_idx in newAgents_idx:
            configs.append(self.agents[model_idx].model.to_json())
            weights.append(self.agents[model_idx].model.get_weights())

        K.clear_session()

        # reload models
        newAgents = []
        for i in range(self.pop_size):
            print("\rcreating next generation {0:.2f}%...".format(
                (i + 1) / self.pop_size * 100),
                  end="")
            loaded = model_from_json(configs[i])
            loaded.set_weights(weights[i])
            newAgents.append(Agent(self, i, inherited_model=loaded))
        print("")

        self.agents = newAgents
        self.generation_number += 1
Example #2
0
    def __init__(self,
                 pop_size,
                 model_builder,
                 mutation_rate,
                 mutation_scale,
                 starting_cash,
                 starting_price,
                 trading_fee,
                 big_bang=True,
                 remove_sleep=False,
                 one_output=False,
                 dump_trades=False,
                 dump_file=None):

        self.pop_size = pop_size
        self.agents = []

        self.model_builder = model_builder
        self.mutation_rate = mutation_rate
        self.mutation_scale = mutation_scale
        self.starting_cash = starting_cash
        self.starting_price = starting_price
        self.trading_fee = trading_fee

        self.has_sleep_functionality = not remove_sleep
        self.has_one_output = one_output

        self.generation_number = 1
        self.output_width = 5

        self.dump_trades = dump_trades
        self.dump_file = dump_file

        plt.ion()

        if big_bang == True:
            for i in range(self.pop_size):
                print("\rbuilding agents {:.2f}%...".format(
                    (i + 1) / self.pop_size * 100),
                      end="")
                agent = Agent(self, i)
                self.agents.append(agent)
        print("")
    def __init__(self,
                 pop_size,
                 model_builder,
                 mutation_rate,
                 mutation_scale,
                 starting_cash,
                 trading_fee,
                 big_bang=True,
                 remove_sleep=False,
                 one_output=False,
                 dump_trades=False,
                 dump_file=None):
        self.pop_size = pop_size
        self.agents = []

        self.model_builder = model_builder
        self.mutation_rate = mutation_rate
        self.mutation_scale = mutation_scale
        self.starting_cash = starting_cash
        inputs = ccxt.kraken().fetch_tickers(MARKETS.keys())
        self.starting_price = [
            float(inputs[key]['info']['a'][0]) for key in inputs
        ]
        self.trading_fee = trading_fee

        self.has_sleep_functionality = not remove_sleep
        self.has_one_output = one_output

        self.generation_number = 1
        self.output_width = 5

        self.dump_trades = dump_trades
        self.dump_file = dump_file

        plt.ion()

        if big_bang:
            for i in range(self.pop_size):
                # print("\rbuilding agents {:.2f}%...".format((i + 1) / self.pop_size * 100))
                agent = Agent(self, i)
                self.agents.append(agent)
        print("")
Example #4
0
    dhostname = socket.gethostname()
else:
    dhostname = args.dhost

# AGENT ATTRIBUTES ----------------------------------------------------------------------------------------

# Agent Namespace
agn = Namespace("http://www.agentes.org#")

# Message Count
mss_cnt = 0

# Data Agent
# Datos del Agente
CentroLogisticoAgent = Agent('CentroLogistico2Agent',
                    agn.CentroLogistico2Agent,
                    'http://%s:%d/comm' % (hostname, port),
                    'http://%s:%d/Stop' % (hostname, port))

# Directory agent address
DirectoryAgent = Agent('DirectoryAgent',
                       agn.Directory,
                       'http://%s:%d/Register' % (dhostname, dport),
                       'http://%s:%d/Stop' % (dhostname, dport))

CentroLogisticoDirectoryAgent = Agent('CentroLogisticoDirectoryAgent',
                       agn.CentroLogisticoDirectory,
                       'http://%s:9010/Register' % (hostname),
                       'http://%s:9010/Stop' % (hostname))

# Global triplestore graph
dsGraph = Graph()
Example #5
0
# AGENT ATTRIBUTES ----------------------------------------------------------------------------------------

# Configuration stuff
hostname = socket.gethostname()
port = 9015

# Agent Namespace
agn = Namespace("http://www.agentes.org#")

# Message Count
mss_cnt = 0

# Data Agent
FinancialAgent = Agent('FinancialAgent',
                       agn.FinancialAgent,
                       'http://%s:%d/comm' % (hostname, port),
                       'http://%s:%d/Stop' % (hostname, port))

# Directory agent address
DirectoryAgent = Agent('DirectoryAgent',
                       agn.Directory,
                       'http://%s:9000/Register' % hostname,
                       'http://%s:9000/Stop' % hostname)

# Global triplestore graph
dsGraph = Graph()

# Queue
queue = Queue()

# Flask app
Example #6
0
# Configuration stuff
hostname = socket.gethostname()
port = 9010

logger = config_logger(level=1)

# Agent Namespace
agn = Namespace("http://www.agentes.org#")

# Message Count
mss_cnt = 0

# Data Agent
ProductsAgent = Agent('ProductsAgent', agn.ProductsAgent,
                      'http://%s:%d/comm' % (hostname, port),
                      'http://%s:%d/Stop' % (hostname, port))

# Directory agent address
DirectoryAgent = Agent('DirectoryAgent', agn.Directory,
                       'http://%s:9000/Register' % hostname,
                       'http://%s:9000/Stop' % hostname)

# Global triplestore graph
dsGraph = Graph()

# Queue
queue = Queue()

# Flask app
app = Flask(__name__)
Example #7
0
from utils.Agent import Agent
from PesquisaBinaria.binarySearchRecursive import binaryResearch as binarySearchRecursive
from PesquisaBinaria.binarySearchIterative import binaryResearch as binarySearchIterative
from PesquisaSequencial.sequencialSearch import sequencialSearch

ValorantCharacters = []

ValorantCharacters.append(Agent(1, "Raze"))
ValorantCharacters.append(Agent(2, "Breach"))
ValorantCharacters.append(Agent(3, "Phoenix"))
ValorantCharacters.append(Agent(4, "Viper"))
ValorantCharacters.append(Agent(5, "Sova"))
ValorantCharacters.append(Agent(6, "Omen"))
ValorantCharacters.append(Agent(7, "Sage"))
ValorantCharacters.append(Agent(8, "Brimstone"))
ValorantCharacters.append(Agent(9, "Cypher"))
ValorantCharacters.append(Agent(10, "Jett"))
ValorantCharacters.append(Agent(11, "Reyna"))
ValorantCharacters.append(Agent(12, "Killjoy"))

# =====================================================================
#                    ITERATIVE BINARY SEARCH
# =====================================================================
AgentIterativeBinarySearch = binarySearchIterative(ValorantCharacters, 2)
print('--------------------------')
print('Iterative binary search example: ')
print('--------------------------')

if AgentIterativeBinarySearch is not None:
    print('Response: ' + AgentIterativeBinarySearch.name)
else:
    dhostname = socket.gethostname()
else:
    dhostname = args.dhost

# Flask stuff
app = Flask(__name__, template_folder='../templates')

# Configuration constants and variables
agn = Namespace("http://www.agentes.org#")

# Contador de mensajes
mss_cnt = 0

# Datos del Agente
UserPersonalAgent = Agent('UserPersonalAgent', agn.UserPersonalAgent,
                          'http://%s:%d/comm' % (hostname, port),
                          'http://%s:%d/Stop' % (hostname, port))
# Directory agent address
DirectoryAgent = Agent('DirectoryAgent', agn.Directory,
                       'http://%s:%d/Register' % (dhostname, dport),
                       'http://%s:%d/Stop' % (dhostname, dport))

# Global dsgraph triplestore
dsgraph = Graph()

# Productos enconctrados
listaDeProductos = []


# Función que lleva y devuelve la cuenta de mensajes
def getMessageCount():
Example #9
0
# AGENT ATTRIBUTES ----------------------------------------------------------------------------------------

# Configuration stuff
hostname = socket.gethostname()
port = 9020

# Agent Namespace
agn = Namespace("http://www.agentes.org#")

# Message Count
mss_cnt = 0

# Data Agent
QualifierAgent = Agent('QualifierAgent', agn.QualifierAgent,
                       'http://%s:%d/comm' % (hostname, port),
                       'http://%s:%d/Stop' % (hostname, port))

# Directory agent address
DirectoryAgent = Agent('DirectoryAgent', agn.Directory,
                       'http://%s:9000/Register' % hostname,
                       'http://%s:9000/Stop' % hostname)

# Global triplestore graph
dsGraph = Graph()

# Queue
queue = Queue()

# Flask app
app = Flask(__name__)
    dhostname = socket.gethostname()
else:
    dhostname = args.dhost

# AGENT ATTRIBUTES ----------------------------------------------------------------------------------------

# Agent Namespace
agn = Namespace("http://www.agentes.org#")

# Message Count
mss_cnt = 0

# Data Agent
# Datos del Agente
TransportistaDevolucionesAgent = Agent('TransportistaDevolucionesAgent',
                                       agn.TransportistaDevolucionesAgent,
                                       'http://%s:%d/comm' % (hostname, port),
                                       'http://%s:%d/Stop' % (hostname, port))

# Directory agent address
DirectoryAgent = Agent('DirectoryAgent', agn.Directory,
                       'http://%s:%d/Register' % (dhostname, dport),
                       'http://%s:%d/Stop' % (dhostname, dport))

# Global triplestore graph
dsGraph = Graph()

# Queue
queue = Queue()

# Flask app
app = Flask(__name__)
 def __init__(self, name, uri, address, stop, random_seed=1):
     Agent.__init__(self, name, uri, address, stop)
     self.last_price = None
     self.random_seed = abs(random_seed) + 1
Example #12
0
# Configuration stuff
hostname = socket.gethostname()
port = 9035

logger = config_logger(level=1)

# Agent Namespace
agn = Namespace("http://www.agentes.org#")

# Message Count
mss_cnt = 0

# Data Agent
LogisticHubAgent = Agent('LogisticHubAgent', agn.LogisticHubAgent,
                         'http://%s:%d/comm' % (hostname, port),
                         'http://%s:%d/Stop' % (hostname, port))

# Directory agent address
DirectoryAgent = Agent('DirectoryAgent', agn.Directory,
                       'http://%s:9000/Register' % hostname,
                       'http://%s:9000/Stop' % hostname)

# Global triplestore graph
dsGraph = Graph()

# Queue
queue = Queue()

# Flask app
app = Flask(__name__)
# AGENT ATTRIBUTES ----------------------------------------------------------------------------------------

# Configuration stuff
hostname = socket.gethostname()
port = 9030

# Agent Namespace
agn = Namespace("http://www.agentes.org#")

# Message Count
mss_cnt = 0

# Data Agent
TransportDealerAgent = Agent('TransportDealerAgent', agn.TransportDealerAgent,
                             'http://%s:%d/comm' % (hostname, port),
                             'http://%s:%d/Stop' % (hostname, port))

# Directory agent address
DirectoryAgent = Agent('DirectoryAgent', agn.Directory,
                       'http://%s:9000/Register' % hostname,
                       'http://%s:9000/Stop' % hostname)
ExternalTransportDirectory = Agent('ExternalTransportDirectory', agn.Directory,
                                   'http://%s:8000/Register' % hostname,
                                   'http://%s:8000/Stop' % hostname)

# Global triplestore graph
dsGraph = Graph()

# Queue
queue = Queue()
Example #14
0
    dhostname = socket.gethostname()
else:
    dhostname = args.dhost

# AGENT ATTRIBUTES ----------------------------------------------------------------------------------------

# Agent Namespace
agn = Namespace("http://www.agentes.org#")

# Message Count
mss_cnt = 0

# Data Agent
# Datos del Agente
GestorExternoAgent = Agent('GestorExterno', agn.GestorExterno,
                           'http://%s:%d/comm' % (hostname, port),
                           'http://%s:%d/Stop' % (hostname, port))

# Directory agent address
DirectoryAgent = Agent('DirectoryAgent', agn.Directory,
                       'http://%s:%d/Register' % (dhostname, dport),
                       'http://%s:%d/Stop' % (dhostname, dport))

# Global triplestore graph
dsGraph = Graph()

# Queue
queue = Queue()

# Flask app
app = Flask(__name__)
    dhostname = socket.gethostname()
else:
    dhostname = args.dhost

# AGENT ATTRIBUTES ----------------------------------------------------------------------------------------

# Agent Namespace
agn = Namespace("http://www.agentes.org#")

# Message Count
mss_cnt = 0

# Data Agent
# Datos del Agente
GestorDeDevolucionesAgent = Agent('GestorDeDevoluciones',
                                  agn.GestorDeDevoluciones,
                                  'http://%s:%d/comm' % (hostname, port),
                                  'http://%s:%d/Stop' % (hostname, port))

# Directory agent address
DirectoryAgent = Agent('DirectoryAgent', agn.Directory,
                       'http://%s:%d/Register' % (dhostname, dport),
                       'http://%s:%d/Stop' % (dhostname, dport))
# Global triplestore graph
dsGraph = Graph()

# Queue
queue = Queue()

# Flask app
app = Flask(__name__)
else:
    hostname = socket.gethostname()

# Directory Service Graph
dsgraph = Graph()

# Vinculamos todos los espacios de nombre a utilizar
dsgraph.bind('acl', ACL)
dsgraph.bind('rdf', RDF)
dsgraph.bind('rdfs', RDFS)
dsgraph.bind('foaf', FOAF)
dsgraph.bind('dso', DSO)

agn = Namespace("http://www.agentes.org#")
DirectoryAgent = Agent('DirectoryAgent', agn.Directory,
                       'http://%s:%d/Register' % (hostname, port),
                       'http://%s:%d/Stop' % (hostname, port))
app = Flask(__name__)
mss_cnt = 0


@app.route("/Register")
def register():
    """
    Entry point del agente que recibe los mensajes de registro
    La respuesta es enviada al retornar la funcion,
    no hay necesidad de enviar el mensaje explicitamente

    Asumimos una version simplificada del protocolo FIPA-request
    en la que no enviamos el mesaje Agree cuando vamos a responder
    dhostname = socket.gethostname()
else:
    dhostname = args.dhost

# AGENT ATTRIBUTES ----------------------------------------------------------------------------------------

# Agent Namespace
agn = Namespace("http://www.agentes.org#")

# Message Count
mss_cnt = 0

# Data Agent
# Datos del Agente
Transportista2Agent = Agent('Transportista2Agent', agn.Transportista2Agent,
                            'http://%s:%d/comm' % (hostname, port),
                            'http://%s:%d/Stop' % (hostname, port))

# Directory agent address
TransportistaDirectoryAgent = Agent(
    'TransportistaDirectoryAgent', agn.TransportistaDirectory,
    'http://%s:%d/Register' % (dhostname, dport),
    'http://%s:%d/Stop' % (dhostname, dport))

# Global triplestore graph
dsGraph = Graph()

# Queue
queue = Queue()

# Flask app
    dhostname = socket.gethostname()
else:
    dhostname = args.dhost

# AGENT ATTRIBUTES ----------------------------------------------------------------------------------------

# Agent Namespace
agn = Namespace("http://www.agentes.org#")

# Message Count
mss_cnt = 0

# Data Agent
# Datos del Agente
PromotorDeProductosAgent = Agent('PromotorDeProductos',
                                 agn.PromotorDeProductos,
                                 'http://%s:%d/comm' % (hostname, port),
                                 'http://%s:%d/Stop' % (hostname, port))

# Directory agent address
DirectoryAgent = Agent('DirectoryAgent', agn.Directory,
                       'http://%s:%d/Register' % (dhostname, dport),
                       'http://%s:%d/Stop' % (dhostname, dport))
# Global triplestore graph
dsGraph = Graph()

# Queue
queue = Queue()

# Flask app
app = Flask(__name__)
Example #19
0
else:
    hostname = socket.gethostname()

# Directory Service Graph
dsgraph = Graph()

# Vinculamos todos los espacios de nombre a utilizar
dsgraph.bind('acl', ACL)
dsgraph.bind('rdf', RDF)
dsgraph.bind('rdfs', RDFS)
dsgraph.bind('foaf', FOAF)
dsgraph.bind('dso', DSO)

agn = Namespace("http://www.agentes.org#")
CentroLogisticoDirectoryAgent = Agent(
    'CentroLogisticoDirectoryAgent', agn.CentroLogisticoDirectoryAgent,
    'http://%s:%d/Register' % (hostname, port),
    'http://%s:%d/Stop' % (hostname, port))

# Directory agent address
DirectoryAgent = Agent('DirectoryAgent', agn.Directory,
                       'http://%s:9000/Register' % hostname,
                       'http://%s:9000/Stop' % hostname)

app = Flask(__name__)
mss_cnt = 0

queue1 = Queue()


#función incremental de numero de mensajes
def getMessageCount():
Example #20
0
    dhostname = socket.gethostname()
else:
    dhostname = args.dhost

# AGENT ATTRIBUTES ----------------------------------------------------------------------------------------

# Agent Namespace
agn = Namespace("http://www.agentes.org#")

# Message Count
mss_cnt = 0

# Data Agent
# Datos del Agente
SellerAgent = Agent('SellerAgent', agn.SellerAgent,
                    'http://%s:%d/comm' % (hostname, port),
                    'http://%s:%d/Stop' % (hostname, port))

# Directory agent address
DirectoryAgent = Agent('DirectoryAgent', agn.Directory,
                       'http://%s:%d/Register' % (dhostname, dport),
                       'http://%s:%d/Stop' % (dhostname, dport))

# Global triplestore graph
dsGraph = Graph()

# Queue
queue = Queue()

# Flask app
app = Flask(__name__)
Example #21
0
else:
    hostname = socket.gethostname()

# Directory Service Graph
dsgraph = Graph()

# Vinculamos todos los espacios de nombre a utilizar
dsgraph.bind('acl', ACL)
dsgraph.bind('rdf', RDF)
dsgraph.bind('rdfs', RDFS)
dsgraph.bind('foaf', FOAF)
dsgraph.bind('dso', DSO)

agn = Namespace("http://www.agentes.org#")
TransportistaDirectoryAgent = Agent('TransportistaDirectoryAgent',
                       agn.TransportistaDirectoryAgent,
                       'http://%s:%d/Register' % (hostname, port),
                       'http://%s:%d/Stop' % (hostname, port))

# Directory agent address
DirectoryAgent = Agent('DirectoryAgent',
                       agn.Directory,
                       'http://%s:9000/Register' % hostname,
                       'http://%s:9000/Stop' % hostname)

app = Flask(__name__)
mss_cnt = 0

#función incremental de numero de mensajes
def getMessageCount():
    global mss_cnt
    mss_cnt += 1
Example #22
0
 def set_preexisting_agent_base(self, model):
     self.agents = []
     for i in range(self.pop_size):
         self.agents.append(Agent(self, i, inherited_model=model))
Example #23
0
# Configuration constants and variables
agn = Namespace("http://www.agentes.org#")

# Contador de mensajes
mss_cnt = 0

# Datos del Agente
ExternalTransportAgent1 = ExternalTransportAgent(
    'ExternalTransportAgent1', agn.ExternalTransportAgent1,
    'http://%s:%d/comm' % (hostname, port),
    'http://%s:%d/Stop' % (hostname, port), 5)

# Directory agent address
ExternalTransportDirectory = Agent(
    'ExternalTransportDirectory', agn.ExternalTransportDirectory,
    'http://%s:%d/Register' % (dhostname, dport),
    'http://%s:%d/Stop' % (dhostname, dport))

# Global dsgraph triplestore
dsgraph = Graph()


def get_count():
    global mss_cnt
    mss_cnt += 1
    return mss_cnt


def register_message():
    """
    Envia un mensaje de registro al servicio de registro