def __init__(self, replication_id): # BS: class constructor print('Simulation Start') self.running = True # Track current time self.clock = 0 # Instantiate logger EXCEL_DIR = os.path.join(LOG_DIR, 'excel') CSV_DIR = os.path.join(LOG_DIR, 'csv') os.makedirs(LOG_DIR, exist_ok=True) os.makedirs(EXCEL_DIR, exist_ok=True) os.makedirs(CSV_DIR, exist_ok=True) OUT_PATH = os.path.join(CSV_DIR, f'rep{replication_id}.log') self.log = Logger(OUT_PATH) self.log.write_header() # Track number of products output in order to calculate throughput self.num_P1 = 0 self.num_P2 = 0 self.num_P3 = 0 # Track time inspectors (either, or both) spend blocked self.blocked_time = 0 # blocked inspectors list self.blocked_inspectors = list() # Setup FEL self.event_list = PriorityQueue() # Create workstations ws_1 = Workstation(self, 'WS1', WS1_LAM, [ComponentType.C1], ProductType.P1) ws_2 = Workstation(self, 'WS2', WS2_LAM, [ComponentType.C1, ComponentType.C2], ProductType.P2) ws_3 = Workstation(self, 'WS3', WS3_LAM, [ComponentType.C1, ComponentType.C3], ProductType.P3) # LBS: without need to declare workstations as list self.workstations = [ws_1, ws_2, ws_3] # Create inspectors # LBS: ins_1_lambdas is a dict formatted as �� key: value...�� ins_1_lambdas = {ComponentType.C1: IN1_LAM} ins_1 = Inspector(self, 'IN1', ins_1_lambdas, [ComponentType.C1], [ws_1, ws_2, ws_3], OutputPolicy.NAIVE) ins_2_lambdas = { ComponentType.C2: IN2_LAM_C2, ComponentType.C3: IN2_LAM_C3 } ins_2 = Inspector(self, 'IN2', ins_2_lambdas, [ComponentType.C2, ComponentType.C3], [ws_2, ws_3], OutputPolicy.NAIVE) self.inspectors = [ins_1, ins_2] # Generate initial events # These should be the two inspectors' first component selections self.schedule_inspection(ins_1, ins_1.generate_time(0, ins_1.component)) self.schedule_inspection(ins_2, ins_2.generate_time(0, ins_2.component)) # As well as an end-simulation event self.schedule_event(EndSimulationEvent(END_TIME)) # Open Excel log self.TimeColumn = 0 self.CurrentEventColumn = 1 self.EventListColumn = 2 self.Inspector1Column = 3 self.Inspector2Column = 4 self.WS1_C1_Q_Column = 5 self.WS2_C1_Q_Column = 6 self.WS2_C2_Q_Column = 7 self.WS3_C1_Q_Column = 8 self.WS3_C3_Q_Column = 9 self.BLOCKED_IN1 = 10 self.BLOCKED_IN2 = 11 self.NUM_P1 = 12 self.NUM_P2 = 13 self.NUM_P3 = 14 self.BLOCK_INS_LIST = 15 self.WS1_BUSY = 16 self.WS2_BUSY = 17 self.WS3_BUSY = 18 self.now = time.strftime("%H-%M-%S") self.logfile = os.path.join(EXCEL_DIR, "Log" + str(replication_id) + ".xls") print("new file:" + self.logfile) self.workbook = xlwt.Workbook(self.logfile) self.worksheet = self.workbook.add_sheet('log1', cell_overwrite_ok=True) self.rows_old = 0 self.write_excel_xls_append("Time", self.TimeColumn) self.write_excel_xls_append("CurrentEvent", self.CurrentEventColumn) self.write_excel_xls_append("EventList", self.EventListColumn) self.write_excel_xls_append("Inspector1", self.Inspector1Column) self.write_excel_xls_append("Inspector2", self.Inspector2Column) self.write_excel_xls_append("WS1_C1_Q", self.WS1_C1_Q_Column) self.write_excel_xls_append("WS2_C1_Q", self.WS2_C1_Q_Column) self.write_excel_xls_append("WS2_C2_Q", self.WS2_C2_Q_Column) self.write_excel_xls_append("WS3_C1_Q", self.WS3_C1_Q_Column) self.write_excel_xls_append("WS3_C3_Q", self.WS3_C3_Q_Column) self.write_excel_xls_append("blocked_IN1", self.BLOCKED_IN1) self.write_excel_xls_append("blocked_IN2", self.BLOCKED_IN2) self.write_excel_xls_append("num_P1", self.NUM_P1) self.write_excel_xls_append("num_P2", self.NUM_P2) self.write_excel_xls_append("num_P3", self.NUM_P3) self.write_excel_xls_append("blockInsList", self.BLOCK_INS_LIST) self.write_excel_xls_append("ws1Busy", self.WS1_BUSY) self.write_excel_xls_append("ws2Busy", self.WS2_BUSY) self.write_excel_xls_append("ws3Busy", self.WS3_BUSY) # Print initial state to console self.print_current_state_beforeproc(None) self.print_inspectors() self.print_workstations() self.print_event_list() self.print_current_state_afterproc(None) # Print initial state to console self.print_current_state_beforeproc(None) self.print_inspectors() self.print_workstations() self.print_event_list() self.print_current_state_afterproc(None)