SI_InteligentnyWozekWidlowy/InitialStateFactory.py

88 lines
2.5 KiB
Python
Raw Normal View History

2022-04-16 14:55:25 +02:00
import random
2022-04-16 15:55:43 +02:00
2022-04-16 14:55:25 +02:00
from data.Item import Item
from data.Order import Order
2022-05-22 16:27:36 +02:00
from data.enum.ItemType import ItemType
2022-06-07 01:07:49 +02:00
from data.enum.Priority import Priority
2022-05-22 16:27:36 +02:00
from util.ClientParamsFactory import ClientParamsFactory
2022-06-09 22:36:19 +02:00
from util.PathByEnum import PathByEnum
2022-04-16 14:55:25 +02:00
2022-04-16 15:55:43 +02:00
class InitialStateFactory:
2022-04-16 14:55:25 +02:00
2022-04-16 15:55:43 +02:00
@staticmethod
2022-05-22 16:27:36 +02:00
def generate_item_list(output_list_size: int):
2022-06-09 22:36:19 +02:00
item_list: [Item] = []
2022-05-22 16:27:36 +02:00
for i in range(output_list_size):
item_list.append(InitialStateFactory.__generate_item())
return item_list
@staticmethod
def generate_order_list(output_order_list_size: int):
order_list: [Order] = []
for i in range(output_order_list_size):
order_list.append(InitialStateFactory.__generate_order())
2022-04-16 14:55:25 +02:00
return order_list
2022-06-07 01:07:49 +02:00
@staticmethod
def generate_order_list_XD(output_order_list_size: int):
order_list: [Order] = []
for i in range(output_order_list_size):
order_list.append(InitialStateFactory.__generate_order_XD())
return order_list
@staticmethod
def __generate_order_XD() -> Order:
order_size = random.randint(1, 4)
items: [Item] = []
for i in range(order_size):
items.append(InitialStateFactory.__generate_item())
time_base = random.randint(8, 20)
final_time = time_base * order_size
client_params = ClientParamsFactory.get_client_params()
2022-06-07 23:15:04 +02:00
x = random.randint(0, 3)
2022-06-07 01:07:49 +02:00
type = Priority.LOW
if x == 0:
type = Priority.MEDIUM
2022-06-07 23:15:04 +02:00
elif x == 1:
2022-06-07 01:07:49 +02:00
type = Priority.HIGH
2022-06-07 23:15:04 +02:00
x = random.randint(20, 300)
return Order(final_time, items, type, x, client_params)
2022-06-07 01:07:49 +02:00
2022-04-16 15:55:43 +02:00
@staticmethod
2022-05-22 16:27:36 +02:00
def __generate_order() -> Order:
2022-04-16 14:55:25 +02:00
order_size = random.randint(1, 4)
2022-05-22 16:27:36 +02:00
items: [Item] = []
2022-04-16 14:55:25 +02:00
for i in range(order_size):
2022-05-22 16:27:36 +02:00
items.append(InitialStateFactory.__generate_item())
2022-04-16 14:55:25 +02:00
time_base = random.randint(8, 20)
final_time = time_base * order_size
2022-05-22 16:27:36 +02:00
client_params = ClientParamsFactory.get_client_params()
2022-04-16 14:55:25 +02:00
2022-06-07 23:15:04 +02:00
return Order(final_time, items, Priority.LOW, 0, client_params)
2022-04-16 14:55:25 +02:00
2022-04-16 15:55:43 +02:00
@staticmethod
2022-04-16 14:55:25 +02:00
def generate_input_sequence(self, input_sequence_size):
2022-06-09 22:36:19 +02:00
sequence: [Item] = []
2022-04-16 14:55:25 +02:00
for i in range(0, input_sequence_size):
2022-04-16 15:55:43 +02:00
sequence.append(self.__generate_item())
2022-04-16 14:55:25 +02:00
return sequence
@staticmethod
2022-04-16 15:55:43 +02:00
def __generate_item() -> Item:
2022-04-16 14:55:25 +02:00
randomly_picked_type = random.choice(list(ItemType))
2022-06-09 22:36:19 +02:00
return Item(randomly_picked_type, PathByEnum.get_random_path(randomly_picked_type))