コード例 #1
0
def main():
    agent1 = deep_q_learning.DeepQLearning()
    agent1.define_model()
    print(agent1.model.summary())
    print(agent1.model.inputs)
    agent2 = random_agent.RandomAgent()
    wins = collections.defaultdict(int)
    numberOfSetsOfGames = 100
    if os.path.isfile(LEARNING_FILE):
        agent1.loadLearning(LEARNING_FILE)
        print('loaded learning')
    print(agent1.model.get_weights())
    print('running....')
    for i in range(numberOfSetsOfGames):
        agent1.reset()
        gg = g.SuperTicTacToe(verbose=0)
        sim = simulate.Simulate(agent1, agent2, gg, verbose=0)
        result = sim.run(i)
        agent1.update(gg)
        wins[str(result)] += 1
        if i % 1000 == 0:
            print(i)
    print('x won ' + str(wins['x'] / float(numberOfSetsOfGames)) +
          '% of the time')
    print('o won ' + str(wins['o'] / float(numberOfSetsOfGames)) +
          '% of the time')
    print('tie ' + str(wins['False'] / float(numberOfSetsOfGames)) +
          '% of the time')
    agent1.saveLearning(LEARNING_FILE)
コード例 #2
0
    def new_world(self):
        p = []
        p += self.add_humans()
        p += self.add_ai()
        #p+=self.add_sp_ai()

        s = simulate.Simulate(p, 400)

        for i in range(200):
            s.simulate_day()

        return s
コード例 #3
0
ファイル: main.py プロジェクト: inavamsi/Thesis
    def new_world(self):
        p = []
        #p+=self.add_humans()
        #p+=self.add_ai()
        p += self.add_sp_ai()

        s = simulate.Simulate(p, 100)

        for i in range(400):
            s.simulate_day()

        return s.timeseries
コード例 #4
0
def main():
    # g = game.SuperTicTacToe()
    # g.start()
    # g.play()
    wins = collections.defaultdict(int)
    numTrials = 100
    print('out of ' + str(numTrials) + ' games....')
    for i in range(0, numTrials):
        # game = simulate.Simulate(agent1 = mcts.MonteCarloTreeSearch(g.SuperTicTacToe(verbose = 0)), agent2 = random_agent.RandomAgent(), game = g.SuperTicTacToe(verbose = 0), verbose = 0)
        # result = game.run(trial)
        game = simulate.Simulate(\
            # agent1 = deep_q_learning.DeepQLearning(),\
            agent1 = minimax.MiniMax(), \
            agent2 = random_agent.RandomAgent(),\
            game = g.SuperTicTacToe(verbose = 0),\
            verbose = 1\
        )
        result = game.run(i)
        wins[str(result)] += 1
    print('x won ' + str(wins['x'] / float(numTrials)) + '% of the time')
    print('o won ' + str(wins['o'] / float(numTrials)) + '% of the time')
    print('tie ' + str(wins['False'] / float(numTrials)) + '% of the time')
コード例 #5
0
def initSimulate(w):
    w.simulate = simulate.Simulate()
コード例 #6
0
ファイル: main.py プロジェクト: gselgin/RestaurantModel
def main():
    my_restaurant = restaurant.Restaurant()

    my_simulation = simulate.Simulate(my_restaurant)
    my_simulation.run()
コード例 #7
0
ファイル: simulate_relate.py プロジェクト: bambuunet/forex
#coding:utf-8
import pandas as pd
import os
import re  #Regular expression
import copy
import json
import csv
import numpy as np
import func
import simulate

S = simulate.Simulate()
X = func.Func()


def getPipsPerMonth(currency, codeStr, codeArgValStr, year):
    spread = X.getSpread(S.getCurrency())
    try:
        result = X.getResult(currency, codeStr, codeArgValStr, year)
        if len(result.index) > 0:
            month = float(result['month'][len(result.index) - 1]) - 1 + float(
                result['day'][len(result.index) - 1]) / 31
            deltaRate = result.sum()['delta'] / (60 * 24 * 20 * month)
            average = result.mean()['gain']
            if deltaRate > 1:
                countPerMonth = len(result.index) / month / deltaRate
            else:
                countPerMonth = len(result.index) / month
            return (average - spread) * countPerMonth
        else:
            return 0
コード例 #8
0
def main():

    numberOfNodes = 100
    numberOfPacketsPerNode = 300
    contentionWindowMin = 8
    numberOfSims = 1000
    packetSize = 10
    isQoS = True  # type: bool
    # isQoS = False  # type: bool
    isBurstModeEnabled = True
    isBlockACKEnabled = True

    # Initializing random function for the whole simulation
    rand = random.Random()
    rand.seed(time.gmtime())

    timings = []  # type: list[int]
    collisions = []  # type: list[int]
    burstSize = 3
    nodalTransmissionTimes = [[0 for _ in range(numberOfSims)]
                              for _ in range(numberOfNodes)
                              ]  # type: list[int][int]

    if (not isQoS and (isBlockACKEnabled or isBurstModeEnabled)):
        print("The Block/Burst mode cannot be used in a non-QoS environment")
    elif (isQoS and not isBurstModeEnabled and isBlockACKEnabled):
        print(
            "The Block ACK mode requires Burst mode to be active for implementation"
        )
    else:

        for simNum in range(numberOfSims):
            print("{0}".format(simNum), end="")
            sim = simulate.Simulate()  # type: simulate.Simulate
            # Create a new Network object for each simulation run
            network = ntwk.Network(numberOfNodes, numberOfPacketsPerNode,
                                   contentionWindowMin,
                                   packetSize)  # type: ntwk.Network
            network.rand = rand
            network.burstSize = burstSize

            network.isBurstModeEnabled = isBurstModeEnabled
            network.isBlockACKEnabled = isBlockACKEnabled
            # Initiating simulation
            sim.run(network, isQoS)

            # Collects nodal time statistics
            for nodeNum in range(numberOfNodes):
                nodalTransmissionTimes[nodeNum][simNum] = network.nodes[
                    nodeNum].timeToCompleteTransmission
            # Collects simulation's average time and collision count
            timings.append(sim.time)
            collisions.append(sim.collisionCount)

        avgTime = sum(timings) / numberOfSims
        print("\nAverage Time: {0}".format(avgTime))
        nodalTimeAverages = []
        for i in range(numberOfNodes):
            nodalTimeAverages.append(
                sum(nodalTransmissionTimes[i]) / numberOfSims)
        print("Nodal Average Times: ", nodalTimeAverages)
        print("Average Throughput {0}".format(
            (numberOfPacketsPerNode * numberOfNodes) / avgTime))
        print("Average collisions: {0}".format(sum(collisions) / numberOfSims))