コード例 #1
0
def gym_single_test(trace_path, load_ratio):
    g = gym.Gym("test_gym")
    g.reset(trace_path=trace_path, report_interval_ms=60, duration_time_ms=0)
    packet_record = PacketRecord()
    packet_record.reset()

    while True:
        packet_list, done = g.step(GROUND_TRUTH * load_ratio)
        if not done:
            for pkt in packet_list:
                packet_info = PacketInfo()
                packet_info.payload_type = pkt["payload_type"]
                packet_info.ssrc = pkt["ssrc"]
                packet_info.sequence_number = pkt["sequence_number"]
                packet_info.send_timestamp = pkt["send_time_ms"]
                packet_info.receive_timestamp = pkt["arrival_time_ms"]
                packet_info.padding_length = pkt["padding_length"]
                packet_info.header_length = pkt["header_length"]
                packet_info.payload_size = pkt["payload_size"]
                packet_info.bandwidth_prediction = GROUND_TRUTH * load_ratio
                packet_record.on_receive(packet_info)
        else:
            break

    # Check whole receiving rate at the end
    receiving_rate = packet_record.calculate_receiving_rate()
    check_result(receiving_rate,
                 GROUND_TRUTH * min(1, load_ratio) * (1 - ERROR),
                 GROUND_TRUTH * min(1, load_ratio * (1 + ERROR)),
                 'receiving_rate')
コード例 #2
0
ファイル: test_gym.py プロジェクト: Pterosaur/alphartc-ns3
def test_multiple_instances():
    total_stats = []
    g1 = gym.Gym()
    g2 = gym.Gym()
    g1.reset()
    g2.reset()
    while True:
        stats, done = g1.step(1000)
        if not done:
            total_stats += stats
        else:
            break
    while True:
        stats, done = g2.step(1000)
        if not done:
            total_stats += stats
        else:
            break
    assert (total_stats)
    for stats in total_stats:
        assert (isinstance(stats, dict))
コード例 #3
0
ファイル: test_gym.py プロジェクト: Pterosaur/alphartc-ns3
def test_basic():
    total_stats = []
    g = gym.Gym("test_gym")
    g.reset()
    while True:
        stats, done = g.step(1000)
        if not done:
            total_stats += stats
        else:
            break
    assert (total_stats)
    for stats in total_stats:
        assert (isinstance(stats, dict))
コード例 #4
0
ファイル: test_gym.py プロジェクト: Pterosaur/alphartc-ns3
def test_trace():
    total_stats = []
    trace_path = os.path.join(os.path.dirname(__file__), "data",
                              "trace_example.json")
    g = gym.Gym("test_gym")
    g.reset(trace_path=trace_path, report_interval_ms=60, duration_time_ms=0)
    while True:
        stats, done = g.step(1000)
        if not done:
            total_stats += stats
        else:
            break
    assert (total_stats)
    for stats in total_stats:
        assert (isinstance(stats, dict))
コード例 #5
0
    def setUpClass(cls):
        # called once at beginning 
        print('setUpClass()')

        # create gym instance 
        cls.gym = gym.Gym()

        # initialize gym member instances (member ID's 0-7)
        cls.connor = member.Member('Connor')
        cls.vanessa = member.Member('Vanessa')
        cls.tina = member.Member('Tina')
        cls.joe = member.Member('Joe')
        cls.seth = member.Member('Seth')
        cls.scott = member.Member('Scott')
        cls.mary = member.Member('Mary')
        cls.max = member.Member('Max')

        # initialize gym equipment instances 
        cls.benchPress = equipment.Equipment('Bench Press', 'Weight Training')
        cls.inclineBench = equipment.Equipment('Incline Bench', 'Weight Training')
        cls.declineBench = equipment.Equipment('Decline Bench', 'Weight Training')
        cls.kettleBells = equipment.Equipment('Kettle Bells', 'Weight Training')
        cls.treadmill1 = equipment.Equipment('Treadmill', 'Cardio')
        cls.treadmill2 = equipment.Equipment('Treadmill', 'Cardio')
        cls.rowMachine = equipment.Equipment('Row Machine', 'Cardio')
        cls.resistanceBands = equipment.Equipment('Resistance Bands', 'Stretching')
        cls.wobbleBoard = equipment.Equipment('Wobble Board', 'Balance')

        # add member instances to gym member set 
        cls.gym.add_member(cls.connor)
        cls.gym.add_member(cls.vanessa)
        cls.gym.add_member(cls.tina)
        cls.gym.add_member(cls.joe)
        cls.gym.add_member(cls.seth)
        cls.gym.add_member(cls.scott)
        cls.gym.add_member(cls.mary)
        cls.gym.add_member(cls.max)

        # add equipment instances to gym equipment set 
        cls.gym.add_equipment(cls.benchPress)
        cls.gym.add_equipment(cls.inclineBench)
        cls.gym.add_equipment(cls.declineBench)
        cls.gym.add_equipment(cls.kettleBells)
        cls.gym.add_equipment(cls.treadmill1)
        cls.gym.add_equipment(cls.treadmill2)
        cls.gym.add_equipment(cls.rowMachine)
        cls.gym.add_equipment(cls.resistanceBands)
        cls.gym.add_equipment(cls.wobbleBoard)
コード例 #6
0
def play(mcts, potential=0.99, agent=0, mode=0):
    trained_agent = lambda x: np.argmax(mcts.get_raw_action_prob(x))
    random_player = lambda x: np.random.choice(
        np.where(x.get_valid_moves() == 1)[0])
    optimal_player = get_optimal_move
    mostly_random_player = (lambda x: get_optimal_move(x)
                            if random.random() > 0.75 else random_player(x))
    mostly_optimal_player = (lambda x: get_optimal_move(x)
                             if random.random() > 0.25 else random_player(x))
    agent_map = {
        0: optimal_player,
        1: mostly_random_player,
        2: mostly_optimal_player,
        3: random_player,
    }
    num_games = 100

    a = gym.Gym(trained_agent, agent_map[agent], potential=potential)
    return a.play_games(num_games, mode=mode, verbose=False)
コード例 #7
0
def play(OPTIONS):
    """main method"""
    trained_agent = lambda x: np.argmax(mcts.get_raw_action_prob(x))
    random_player = lambda x: np.random.choice(
        np.where(x.get_valid_moves() == 1)[0])
    num_games = 100

    if OPTIONS.optimal:
        opponent = get_optimal_move
    elif OPTIONS.suboptimal:
        opponent = (
            lambda x: get_optimal_move(x)
            if random.random() > Config.suboptimality else random_player(x))
    elif OPTIONS.suboptimal:
        opponent = trained_agent
    else:
        opponent = random_player

    network = CNN(Config.levels)
    network.load_checkpoint("./temp/", "best.pth.tar")
    mcts = MCTS(network)

    a = gym.Gym(trained_agent, opponent, potential=0.99)
    print(a.play_games(num_games, mode=2, verbose=True))
コード例 #8
0
 def setup_controllers(self):
     self.data_control = data_controller.DataController(self.ticket)
     self.model_control = model_controller.ModelController(
         self.ticket.ml_algorithm)
     self.model_gym = gym.Gym()
コード例 #9
0
def test_gym_stability():
    g = gym.Gym("test_gym")
    trace_path = os.path.join(os.path.dirname(__file__), "data",
                              "trace_300k.json")
    gym_single_test(trace_path, 0.75)
    gym_single_test(trace_path, 1.25)