import random


# 고객 class
class Customer:
    def __init__(self, cus_num, start_x, start_y, dest_x, dest_y, share, people_num, hour, minute, second, state):
        self.cus_num = cus_num
        self.start_x = start_x
        self.start_y = start_y
        self.dest_x = dest_x
        self.dest_y = dest_y
        self.share = share
        self.people_num = people_num
        self.hour = hour
        self.minute = minute
        self.second = second
        self.state = state

    def get_cus_num(self):
        return self.cus_num

    def get_start_position(self):
        return self.start_x, self.start_y

    def get_dest_position(self):
        return self.dest_x, self.dest_y

    def get_share(self):
        return self.share

    def get_people_num(self):
        return self.people_num

    def get_time(self):
        return self.hour, self.minute, self.second

    def get_state(self):
        return self.state


# 고객 발생 시나리오
def call_scenario(Customer):
    customers = []
    cus_num = 0
    hour = 9
    minute = 0
    second = 0
    state = 0

    # 9시 ~ 5시 랜덤 고객 발생
    for i in range(28800):  # 8시간 = 28800초

        if second == 60:
            minute += 1
            second = 0

        if minute == 60:
            hour += 1
            minute = 0

        if hour == 13:
            hour = 1

        # 9am, 2pm 랜덤 고객 발생
        if (hour == 9 or hour == 2) and (random.randrange(1, 1001) <= 30):
            cus_num += 1
            start_x, start_y, dest_x, dest_y, share, people_num = random_customer()
            customers.append(
                Customer(cus_num, start_x, start_y, dest_x, dest_y, share, people_num, hour, minute, second, state))

        # 10am ~ 1pm, 3pm ~ 5pm 랜덤 고객 발생
        if (hour != 9 and hour != 2) and (random.randrange(1, 1001) <= 10):
            cus_num += 1
            start_x, start_y, dest_x, dest_y, share, people_num = random_customer()
            customers.append(
                Customer(cus_num, start_x, start_y, dest_x, dest_y, share, people_num, hour, minute, second, state))

        second += 1

    # end for

    # 결과 출력
    result_out(customers)

    # 총 8시간 평균 432건
    # 1시간당 평균 36건 / 9시, 2시 시간당 평균 108건
    return customers


# 랜덤한 고객 정보 생성
def random_customer():
    start_x = random.randrange(1, 13)
    start_y = random.randrange(1, 11)
    dest_x = random.randrange(1, 13)
    dest_y = random.randrange(1, 11)
    share = random.randrange(2)

    # 탑승인원 1명 70% / 2명 20% / 3명 10% 확률로 발생
    temp_people_num = random.randrange(1, 11)
    if temp_people_num <= 7:
        people_num = 1
    elif 8 <= temp_people_num <= 9:
        people_num = 2
    else:
        people_num = 3

    return start_x, start_y, dest_x, dest_y, share, people_num


# 결과 출력
def result_out(customers):
    if __name__ == "__main__":
        i = 0
        print("고객번호    출발지점    도착지점    합승여부    탑승인원    호출시각      현재상태")
        while i < len(customers):
            print(
                '%-12s%-12s%-12s%-12s%-12s%-14s%-12s' % (customers[i].get_cus_num(), customers[i].get_start_position(),
                                                         customers[i].get_dest_position(), customers[i].get_share(),
                                                         customers[i].get_people_num(), customers[i].get_time(),
                                                         customers[i].get_state()))
            i += 1


# customer_list에 모든 고객 정보 저장(고객번호, 출발지점, 도착지점, 합승여부, 탑승인원, 호출시각, 현재상태(ex) 0 대기 / 1 탑승 중 / 2 완료))
customer_list = call_scenario(Customer)

# ex) 3번 고객의 호출시각
# print(customer_list[2].get_time())

결과값 출력

 

+ Recent posts