# -*- coding: utf-8 -*- """ Created on Sun Dec 6 11:39:10 2020 @author: danie """ # from PyQt5 import uic, QtWidgets import pandas as pd import random def build_schedule_flowshop(solution,processing_times): current_processing_times = [] for s in solution: current_processing_times.append(list(processing_times[s])) start_time = [] for i in range(len(current_processing_times)): #jobs start_time_temp = [] for j in range(len(current_processing_times[0])): #machines if ((i==0) and (j==0)): start_time_temp.append(0) elif ((i==0) and (j!=0)): start_time_temp.append(start_time_temp[j-1] + current_processing_times[i][j-1]) elif ((i!=0) and (j==0)): start_time_temp.append(start_time[i-1][j] + current_processing_times[i-1][j]) elif ((i!=0) and (j!=0)): start_time_temp.append(max(start_time[i-1][j] + current_processing_times[i-1][j],start_time_temp[j-1] + current_processing_times[i][j-1])) start_time.append(start_time_temp) makespan = start_time[-1][-1] + current_processing_times[-1][-1] # print(current_processing_times) return makespan,start_time,current_processing_times processing_times = pd.read_csv('processing_times.csv',sep=",",header=None) processing_times.transpose() #m = machines #n = jobs m,n = processing_times.shape[0],processing_times.shape[1] # m=3 # n=4 solution = list(range(n)) random.shuffle(solution) makespan,start_time,current_processing_times = build_schedule_flowshop(solution,processing_times) print("Makespan: " + str(makespan)) print("Start Times: ") print(start_time) import matplotlib.pyplot as plt plt.axes() # rectangle = plt.Rectangle((x,y), w, h, fc='blue') lst_color = ['blue','red','black','green','yellow','blue','red','black','green','yellow','blue','red','black','green','yellow','blue','red','black','green','yellow','blue','red','black','green','yellow'] for i in range(len(start_time)): for j in range(len(start_time[0])): rectangle = plt.Rectangle((start_time[i][j],5*i), current_processing_times[i][j], 2, fc=lst_color[j]) plt.gca().add_patch(rectangle) plt.text(start_time[-1][-3], 0, "Makespan: " + str(makespan)) plt.axis('auto') plt.show()