Beispiel #1
0
def run(args):

    param, clone_id = args[0],  args[1]

    param["transportation_cost"] = np.random.choice(param["range_transportation_cost"])

    param["customer_alpha"] = np.random.uniform(*param["range_customer_alpha"])
    param["customer_temp"] = np.random.uniform(*param["range_customer_temp"])

    param["firm_alpha"] = np.random.uniform(*param["range_firm_alpha"])
    param["firm_temp"] = np.random.uniform(*param["range_firm_temp"])

    # param["utility_consumption"] = np.random.uniform(*param["range_utility_consumption"])

    param["firm_positions"] = np.random.randint(1, param["n_positions"] + 1, size=param["n_firms"])
    param["firm_prices"] = np.random.randint(1, param["n_prices"] + 1, size=param["n_firms"])

    param["seed"] = np.random.randint(2 ** 32)

    job_id = param["job_id"]

    label = "J{}C{}".format(job_id, clone_id)

    env = Environment(**param)
    results = env.run()

    Backup(data=results, name="results", root_folder=cl_parameters["working_folder"], label=label)
    Backup(data=param, name="parameters", root_folder=cl_parameters["working_folder"], label=label)
Beispiel #2
0
def main():

    seed = np.random.randint(1000)

    n_positions = 11
    n_prices = 11

    n_firms = 2

    firms_positions = np.random.randint(1, n_positions + 1, size=n_firms)
    firms_prices = np.random.randint(1, n_prices + 1, size=n_firms)

    transportation_cost = 0.2

    firm_alpha = 0.01
    firm_temp = 0.02
    firm_momentum = 0.0  # Only NN
    firm_neural_network = "MLP"  # Only NN

    customer_alpha = 0.01
    customer_temp = 0.02
    customer_momentum = 0.0  # Only NN

    customer_neural_network = "MLP"  # Only NN

    t_max = 10**3

    firm = "StrategicNeuralNetwork"
    customer = "Customer"

    parameters = {
        "seed": seed,
        "firm": firm,
        "customer": customer,
        "n_positions": n_positions,
        "n_prices": n_prices,
        "firms_positions": firms_positions,  # Initial positions
        "firms_prices": firms_prices,  # Initial prices
        "transportation_cost": transportation_cost,
        "firm_temp": firm_temp,
        "firm_alpha": firm_alpha,
        "firm_momentum": firm_momentum,
        "firm_neural_network": firm_neural_network,  # Useful for NN
        "customer_alpha": customer_alpha,
        "customer_temp": customer_temp,
        "customer_momentum": customer_momentum,
        "customer_neural_network": customer_neural_network,
        "t_max": t_max
    }

    env = Environment(**parameters)
    results = env.run()

    fig_producer = FigureProducer(
        results=results,
        parameters=parameters,
        root_folder=path.expanduser("~/Desktop/HotellingExample"))
    fig_producer.run(customers_choices_plot_period=50,
                     other_plots_period=10000)
Beispiel #3
0
def environment(bdw_paths: mp.Array, stop_env: mp.Event, end_of_run: mp.Event):
    rhostname = 'mininet' + '@' + SSH_HOST

    config = {
        'server': 'ipc:///tmp/zmq',
        'client': 'tcp://*:5555',
        'publisher': 'tcp://*:5556',
        'subscriber': 'ipc:///tmp/pubsub'
    }
    logger = config_logger('environment', filepath='./logs/environment.log')
    env = Environment(bdw_paths,
                      logger=logger,
                      mconfig=config,
                      remoteHostname=rhostname)

    # Lets measure env runs in time
    while not stop_env.is_set():

        # Only the agent can unblock this loop, after a training-batch has been completed
        while not end_of_run.is_set():
            try:
                # update environment config from session
                if env.updateEnvironment() == -1:
                    stop_env.set()
                    end_of_run.set()
                    break

                # run a single session & measure
                #-------------------
                now = time.time()
                env.run()
                end = time.time()
                #-------------------

                diff = int(end - now)
                logger.debug("Time to execute one run: {}s".format(diff))

                end_of_run.set()  # set the end of run so our agent knows
                # env.spawn_middleware() # restart middleware
            except Exception as ex:
                logger.error(ex)
                break
        time.sleep(0.1)

    env.close()