def test_add_three_workout_schedule_3_at_same_time() -> None: """ Add three different workouts to the schedule at the same time""" ac = Gym('Athletic Centre') diane = Instructor(1, 'Diane') timmy = Instructor(2, 'Timmy') greg = Instructor(3, 'Greg') assert ac.add_instructor(diane) assert ac.add_instructor(timmy) assert ac.add_instructor(greg) assert diane.add_certificate('Cardio 1') assert timmy.add_certificate('Cardio 1') assert greg.add_certificate('Cardio 1') assert ac.add_room('Dance Studio', 50) assert ac.add_room('Bike Studio', 50) assert ac.add_room('Lift Studio', 50) boot_camp = WorkoutClass('Boot Camp', ['Cardio 1']) assert ac.add_workout_class(boot_camp) sep_9_2019_12_00 = datetime(2019, 9, 9, 12, 0) assert ac.schedule_workout_class(sep_9_2019_12_00, 'Dance Studio', boot_camp.get_name(), diane.get_id()) assert ac.schedule_workout_class(sep_9_2019_12_00, 'Lift Studio', boot_camp.get_name(), greg.get_id()) assert ac.schedule_workout_class(sep_9_2019_12_00, 'Bike Studio', boot_camp.get_name(), diane.get_id()) is False
def test_add_3_rooms() -> None: """add 3 room to a gym""" ac = Gym('Athletic Centre') assert ac.add_room('Dance Studio', 50) assert ac.add_room('Dance a', 50) assert ac.add_room('Dance b', 50) assert len(ac._rooms) == 3
def test_gym_add_two_instructor() -> None: """Add 2 different instructors to the gym""" ac = Gym('Athletic Centre') diane = Instructor(1, 'Diane') timmy = Instructor(2, 'Timmy') assert ac.add_instructor(diane) assert ac.add_instructor(timmy)
def test_add_3_one_repeat_room() -> None: """add 3 room to a gym and one replicate""" ac = Gym('Athletic Centre') assert ac.add_room('Dance Studio', 50) assert ac.add_room('Dance a', 50) assert ac.add_room('Dance b', 50) assert ac.add_room('Dance b', 50) is False assert len(ac._rooms) == 3
def test_gym_add_same_instructor() -> None: """Add the same instructor to the gym twice and another new one""" ac = Gym('Athletic Centre') diane = Instructor(1, 'Diane') timmy = Instructor(2, 'Timy') assert ac.add_instructor(diane) assert ac.add_instructor(diane) is False assert ac.add_instructor(timmy)
def test_add_three_workouts() -> None: """Add three workouts to the Gym""" ac = Gym('Athletic Centre') kickboxing = WorkoutClass('Kickboxing', ['Strength Training']) a = WorkoutClass('b', ['Strength Training']) b = WorkoutClass('c', ['Strength Training']) assert ac.add_workout_class(kickboxing) assert ac.add_workout_class(a) assert ac.add_workout_class(b)
def test_add_three_workout_schedule_1_dup_time() -> None: """ Add three workout to the schedule, 2 with different rooms at the same time, and one with a room at a different time""" ac = Gym('Athletic Centre') diane = Instructor(1, 'Diane') timmy = Instructor(2, 'Timmy') assert ac.add_instructor(diane) assert ac.add_instructor(timmy) assert diane.add_certificate('Cardio 1') assert timmy.add_certificate('Cardio 1') assert ac.add_room('Dance Studio', 50) assert ac.add_room('Bike Studio', 50) boot_camp = WorkoutClass('Boot Camp', ['Cardio 1']) assert ac.add_workout_class(boot_camp) sep_9_2019_12_00 = datetime(2019, 9, 9, 12, 0) sep_9_2020_1_00 = datetime(2020, 9, 9, 1, 0) assert ac.schedule_workout_class(sep_9_2019_12_00, 'Dance Studio', boot_camp.get_name(), diane.get_id()) assert ac.schedule_workout_class(sep_9_2020_1_00, 'Dance Studio', boot_camp.get_name(), timmy.get_id()) assert ac.schedule_workout_class(sep_9_2019_12_00, 'Bike Studio', boot_camp.get_name(), diane.get_id()) is False
def main(): # Instantiate objects agent_name = 'ddpg' config = Config(agent_name) fields = build_data() gym = Gym(fields,config) math_gym = Gym(fields,config) agent = Agent(gym.total_fields,gym.total_fields,gym.field_indexes,config) # Fill replay buffer seed_replay_buffer(gym,agent,config.min_buffer_size) # train on data train_network(agent,gym,math_gym,config)
def verify_network(agent, utils, config): """ For plotting - plot the math mean error versions along with the agent mean """ experience = namedtuple('experience', field_names=[ 'state', 'value', 'log_prob', 'action', 'reward', 'next_state' ]) # Create two instances of gyms gym_network = Gym(config.total_routes, config.num_reset_routes, utils) gym_math = Gym(config.total_routes, config.num_reset_routes, utils) # tic = time.time() # Load weights of trained model agent.load_weights(config.checkpoint_path) # Collections math_means = [] math_stds = [] means = [] stds = [] scores_window = deque(maxlen=100) math_window = deque(maxlen=100) for e in range(1, 11): trajectory = [] rewards = [] math_rewards = [] state = gym_network.reset() math_state = gym_math.reset() math_loss = [gym_math.loss] network_loss = [gym_network.loss] for t in range(config.tmax): suggestion, log_prob, value = agent.act(state) route = utils.route_from_suggestion(suggestion) next_state, reward = gym_network.step(route) # Compare with math math_route = utils.deterministic_route(math_state) math_next_state, math_reward = gym_math.step(math_route) math_rewards.append(math_reward) math_loss.append(gym_math.loss) # Record (s,a,r,s) exp = experience(state, value, log_prob, suggestion, reward, next_state) trajectory.append(exp) rewards.append(reward) network_loss.append(gym_network.loss) state = next_state scores_window.append(np.sum(rewards)) means.append(np.mean(scores_window)) stds.append(np.std(scores_window)) math_window.append(np.sum(math_rewards)) math_means.append(np.mean(math_window)) math_stds.append(np.std(math_window)) # Compare network vs math if e == 1: plot_episode(math_loss, name="Math single episode") plot_episode(network_loss, name="Network single episode") if e % 5 == 0: plot(means, stds, name=config.name, game='RouteMuse') plot(math_means, math_stds, name='Math', game='RouteMuse')
def main(): # Instantiate objects config = Config('math') fields = build_data() gym_math = Gym(fields,config) # train on data test_math(gym_math,config)
def test_register_no_room_left_move_to_other_room_JEN() -> None: ac = Gym('Athletic Centre') instructor = Instructor(5, 'Matthew') instructor2 = Instructor(15, 'Jennifer') swimming = WorkoutClass('Swimming', ['Lifeguard']) jan_28_2020_11_00 = datetime(2020, 1, 29, 11, 0) assert instructor.add_certificate('Lifeguard') assert instructor2.add_certificate('Lifeguard') assert ac.add_workout_class(swimming) assert ac.add_instructor(instructor) assert ac.add_instructor(instructor2) assert ac.add_room('25-yard Pool', 1) assert ac.add_room('Weight Room', 1) assert ac.schedule_workout_class(jan_28_2020_11_00, '25-yard Pool', swimming.get_name(), instructor.get_id()) assert ac.schedule_workout_class(jan_28_2020_11_00, 'Weight Room', swimming.get_name(), instructor2.get_id()) assert ac.register(jan_28_2020_11_00, 'Benjamin', 'Swimming')
def test_gym_offerings_at_one_class_same_workouts_JEN() -> None: ac = Gym('Athletic Centre') instructor = Instructor(5, 'Matthew') instructor2 = Instructor(12, 'Jennifer') swimming = WorkoutClass('Swimming', ['Lifeguard']) jan_28_2020_11_00 = datetime(2020, 1, 29, 11, 0) assert instructor.add_certificate('Lifeguard') assert instructor2.add_certificate('Lifeguard') assert ac.add_workout_class(swimming) assert ac.add_instructor(instructor) assert ac.add_instructor(instructor2) assert ac.add_room('25-yard Pool', 100) assert ac.add_room('Kiddie Pool', 100) assert ac.schedule_workout_class(jan_28_2020_11_00, '25-yard Pool', swimming.get_name(), instructor.get_id()) assert ac.schedule_workout_class(jan_28_2020_11_00, 'Kiddie Pool', swimming.get_name(), instructor2.get_id()) assert ac.offerings_at(jan_28_2020_11_00) == \ [('Matthew', 'Swimming', '25-yard Pool'), ('Jennifer', 'Swimming', 'Kiddie Pool')]
def setup(env, stream, NUMBER_OF_CUSTOMERS, n, session): gym = Gym(env, stream, session) for i in range(5): env.process(athlete(env, i, gym, wait_times[n], stream)) NUMBER_OF_CUSTOMERS[n] += 1 while True: yield env.timeout(stream.exponential(INTERARRAVAL_TIME)) i += 1 NUMBER_OF_CUSTOMERS[n] += 1 env.process(athlete(env, i, gym, wait_times[n], stream))
def test_register_two_diff_person_diff_room() -> None: """Register 2 diff people to same workout class, diff room, same time""" ac = Gym('Athletic Centre') diane = Instructor(1, 'Diane') assert diane.add_certificate('Cardio 1') assert ac.add_instructor(diane) assert ac.add_room('Dance Studio', 50) assert ac.add_room('Bike Studio', 5) boot_camp = WorkoutClass('Boot Camp', ['Cardio 1']) assert ac.add_workout_class(boot_camp) sep_9_2019_12_00 = datetime(2019, 9, 9, 12, 0) assert ac.schedule_workout_class(sep_9_2019_12_00, 'Dance Studio', \ boot_camp.get_name(), diane.get_id()) assert ac.schedule_workout_class(sep_9_2019_12_00, 'Bike Studio', \ boot_camp.get_name(), diane.get_id())\ is False assert ac.register(sep_9_2019_12_00, 'Greg', 'Boot Camp') assert ac.register(sep_9_2019_12_00, 'Greg', 'Boot Camp') is False assert ac.register(sep_9_2019_12_00, 'Tim', 'Boot Camp') assert ac.register(sep_9_2019_12_00, 'Tim', 'Boot Camp') is False
def test_gym_add_room() -> None: """Test add room.""" ac = Gym('Athletic Centre') assert ac.add_room('Dance Studio', 50) assert ac._rooms == {'Dance Studio': 50} assert ac.add_room('Dance Studio', 50) is False assert ac.add_room('Dance Studi', 50) assert ac.add_room('', 50) assert ac._rooms == {'Dance Studio': 50, 'Dance Studi': 50, '': 50} assert ac.add_room('', 50) is False
def test_register_one_person() -> None: """Register one person to one workout class""" ac = Gym('Athletic Centre') diane = Instructor(1, 'Diane') assert diane.add_certificate('Cardio 1') assert ac.add_instructor(diane) assert ac.add_room('Dance Studio', 50) boot_camp = WorkoutClass('Boot Camp', ['Cardio 1']) assert ac.add_workout_class(boot_camp) sep_9_2019_12_00 = datetime(2019, 9, 9, 12, 0) assert ac.schedule_workout_class(sep_9_2019_12_00, 'Dance Studio', \ boot_camp.get_name(), diane.get_id()) assert ac.register(sep_9_2019_12_00, 'Philip', 'Boot Camp') assert ac.register(sep_9_2019_12_00, 'Tim', 'Boot Camp') is True
def test_register_over_capacity() -> None: """Add too many people to a room""" ac = Gym('Athletic Centre') diane = Instructor(1, 'Diane') assert diane.add_certificate('Cardio 1') assert ac.add_instructor(diane) assert ac.add_room('Dance Studio', 1) boot_camp = WorkoutClass('Boot Camp', ['Cardio 1']) assert ac.add_workout_class(boot_camp) sep_9_2019_12_00 = datetime(2019, 9, 9, 12, 0) assert ac.schedule_workout_class(sep_9_2019_12_00, 'Dance Studio', \ boot_camp.get_name(), diane.get_id()) assert ac.register(sep_9_2019_12_00, 'Greg', 'Boot Camp') assert ac.register(sep_9_2019_12_00, 'Tim', 'Boot Camp') is False
def test_instructor_hours_two_people_mixed_hours_JEN() -> None: ac = Gym('Athletic Centre') instructor = Instructor(5, 'Matthew') instructor2 = Instructor(12, 'Jennifer') swimming = WorkoutClass('Swimming', []) jan_28_2020_11_00 = datetime(2020, 1, 29, 11, 0) jan_28_2020_12_00 = datetime(2020, 1, 29, 12, 0) assert ac.add_workout_class(swimming) assert ac.add_instructor(instructor) assert ac.add_instructor(instructor2) assert ac.add_room('25-yard Pool', 100) assert ac.schedule_workout_class(jan_28_2020_11_00, '25-yard Pool', swimming.get_name(), instructor.get_id()) assert ac.schedule_workout_class(jan_28_2020_12_00, '25-yard Pool', swimming.get_name(), instructor.get_id()) t1 = datetime(2020, 1, 29, 11, 0) t2 = datetime(2020, 1, 29, 12, 0) assert ac.instructor_hours(t1, t2) == {5: 2, 12: 0}
def test_gym_register_one_class() -> None: """Test Gym.register with a single user and class.""" ac = Gym('Athletic Centre') instructor = Instructor(5, 'Matthew') swimming = WorkoutClass('Swimming', ['Lifeguard']) jan_28_2020_11_00 = datetime(2020, 1, 29, 11, 0) assert instructor.add_certificate('Lifeguard') assert ac.add_workout_class(swimming) assert ac.add_instructor(instructor) assert ac.add_room('25-yard Pool', 100) assert ac.schedule_workout_class(jan_28_2020_11_00, '25-yard Pool', swimming.get_name(), instructor.get_id()) assert ac.register(jan_28_2020_11_00, 'Benjamin', 'Swimming')
def test_gym_no_offerings_JEN() -> None: ac = Gym('Athletic Centre') instructor = Instructor(5, 'Matthew') swimming = WorkoutClass('Swimming', ['Lifeguard']) feb_28_2020_11_00 = datetime(2020, 2, 28, 11, 0) t1 = datetime(2020, 1, 29, 11, 0) assert instructor.add_certificate('Lifeguard') assert ac.add_workout_class(swimming) assert ac.add_instructor(instructor) assert ac.add_room('25-yard Pool', 100) assert ac.schedule_workout_class(t1, '25-yard Pool', swimming.get_name(), instructor.get_id()) assert ac.offerings_at(feb_28_2020_11_00) == []
def test_gym_one_instructor_one_hour_pay_no_certificates() -> None: ac = Gym('Athletic Centre') instructor = Instructor(5, 'Matthew') swimming = WorkoutClass('Swimming', []) jan_28_2020_11_00 = datetime(2020, 1, 29, 11, 0) assert ac.add_workout_class(swimming) assert ac.add_instructor(instructor) assert ac.add_room('25-yard Pool', 100) assert ac.schedule_workout_class(jan_28_2020_11_00, '25-yard Pool', swimming.get_name(), instructor.get_id()) t1 = datetime(2020, 1, 17, 11, 0) t2 = datetime(2020, 1, 29, 13, 0) assert ac.payroll(t1, t2, 22.0) == [(5, 'Matthew', 1, 22)]
def test_schedule_in_unavailable_room_JEN() -> None: ac = Gym('Athletic Centre') instructor = Instructor(5, 'Matthew') assert ac.add_instructor(instructor) instructor2 = Instructor(6, 'Jennifer') assert ac.add_instructor(instructor2) assert ac.add_room('25-yard Pool', 100) swimming = WorkoutClass('Swimming', ['Lifeguard']) assert ac.add_workout_class(swimming) assert instructor.add_certificate('Lifeguard') assert instructor2.add_certificate('Lifeguard') jan_28_2020_11_00 = datetime(2020, 1, 29, 11, 0) assert ac.schedule_workout_class(jan_28_2020_11_00, '25-yard Pool', swimming.get_name(), instructor.get_id()) assert not ac.schedule_workout_class(jan_28_2020_11_00, '25-yard Pool', swimming.get_name(), instructor2.get_id())
def test_instr_teaching_other_class_JEN() -> None: ac = Gym('Athletic Centre') instructor = Instructor(5, 'Matthew') assert ac.add_instructor(instructor) assert ac.add_room('25-yard Pool', 100) assert ac.add_room('Weight Room', 100) swimming = WorkoutClass('Swimming', ['Lifeguard']) crossfit = WorkoutClass('Cross Fit', []) assert instructor.add_certificate('Lifeguard') assert ac.add_workout_class(swimming) assert ac.add_workout_class(crossfit) jan_28_2020_11_00 = datetime(2020, 1, 29, 11, 0) assert ac.schedule_workout_class(jan_28_2020_11_00, '25-yard Pool', swimming.get_name(), instructor.get_id()) assert not ac.schedule_workout_class(jan_28_2020_11_00, 'Weight Room', crossfit.get_name(), instructor.get_id())
def test_add_three_workout_schedule_diff_time() -> None: """ Add three workout to the schedule at different times""" ac = Gym('Athletic Centre') diane = Instructor(1, 'Diane') assert ac.add_instructor(diane) assert diane.add_certificate('Cardio 1') assert ac.add_room('Dance Studio', 50) boot_camp = WorkoutClass('Boot Camp', ['Cardio 1']) assert ac.add_workout_class(boot_camp) sep_9_2019_12_00 = datetime(2019, 9, 9, 12, 0) sep_9_2020_12_00 = datetime(2020, 9, 9, 12, 0) sep_9_2020_1_00 = datetime(2020, 9, 9, 1, 0) assert ac.schedule_workout_class(sep_9_2019_12_00, 'Dance Studio', boot_camp.get_name(), diane.get_id()) assert ac.schedule_workout_class(sep_9_2020_12_00, 'Dance Studio', boot_camp.get_name(), diane.get_id()) assert ac.schedule_workout_class(sep_9_2020_1_00, 'Dance Studio', boot_camp.get_name(), diane.get_id())
def test_schedule_unqualified_instructor_JEN() -> None: ac = Gym('Athletic Centre') instructor = Instructor(5, 'Matthew') assert ac.add_instructor(instructor) assert ac.add_room('25-yard Pool', 100) swimming = WorkoutClass('Swimming', ['Lifeguard']) assert ac.add_workout_class(swimming) jan_28_2020_11_00 = datetime(2020, 1, 29, 11, 0) assert not ac.schedule_workout_class(jan_28_2020_11_00, '25-yard Pool', swimming.get_name(), instructor.get_id())
def test_gym_add_workout_class() -> None: """Test add workout class.""" ac = Gym('Athletic Centre') kickboxing = WorkoutClass('Kickboxing', ['Strength Training']) assert ac.add_workout_class(kickboxing) assert ac._workouts == {'Kickboxing': kickboxing} assert ac.add_workout_class(kickboxing) is False tes = WorkoutClass('test', ['test1', 'test2', 'test3']) assert ac.add_workout_class(tes) assert ac._workouts == {'Kickboxing': kickboxing, 'test': tes} assert ac.add_workout_class(tes) is False
def test_gym_add_instructor() -> None: """Test add instructor.""" ac = Gym('Athletic Centre') assert ac.name == 'Athletic Centre' diane = Instructor(1, 'Diane') assert ac.add_instructor(diane) assert ac._instructors == {1: diane} assert ac.add_instructor(diane) is False dian1 = Instructor(2, 'Dian') assert ac.add_instructor(dian1) assert ac._instructors == {1: diane, 2: dian1} dia = Instructor(2, 'Dian') assert ac.add_instructor(dia) is False dian = Instructor(3, 'Dian') assert ac.add_instructor(dian) assert ac._instructors == {1: diane, 2: dian1, 3: dian}
def test_schedule_workout_can_teach() -> None: """Test schedule workout can teach.""" ac = Gym('Athletic Centre') diane = Instructor(1, 'Diane') assert ac.add_instructor(diane) # assert diane.add_certificate('Cardio 1') assert ac.add_room('Dance Studio', 50) boot_camp = WorkoutClass('Boot Camp', ['Cardio 1']) assert ac.add_workout_class(boot_camp) sep_9_2019_12_00 = datetime(2019, 9, 9, 12, 0) assert ac.schedule_workout_class(sep_9_2019_12_00, 'Dance Studio', boot_camp.get_name(), diane.get_id()) is False assert ac._schedule == {}
def test_add_5_workouts() -> None: """Add three workouts to the Gym""" ac = Gym('Athletic Centre') kickboxing = WorkoutClass('Kickboxing', ['Strength Training']) a = WorkoutClass('b', ['Strength Training']) b = WorkoutClass('c', ['Strength Training']) d = WorkoutClass('d', ['Strength Training']) e = WorkoutClass('e', ['Strength Training']) assert ac.add_workout_class(kickboxing) assert ac.add_workout_class(a) assert ac.add_workout_class(b) assert ac.add_workout_class(d) a = WorkoutClass('bz', ['Strength Training']) assert ac.add_workout_class(e) assert ac.add_workout_class(a) assert len(ac._workouts) == 6
# iterations: number of data disired def gen_data(func, iterations): data = [] for i in range(0, iterations): x = randint(-50, 50) y = randint(-50, 50) limit = func(x) dato = [x, y] desired_output = 0 if y > limit: desired_output = 1 data.append([dato, desired_output]) return data P = Perceptron() P.random_init(2) data1 = gen_data(lambda x: x + 10, 0) data2 = gen_data(lambda x: x + 10, 2) data3 = [] n = 1000 for i in range(0, n): data3.append(gen_data(lambda x: x + 10, 1000)) Gym_P = Gym(data1) Gym_P.training_(P) j = Gym_P.general_exam(P, data2) av = Gym_P.average_exam(P, data3)