# -*- 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_jobshop(solution,processing_times,machines_routes): current_processing_times = [] current_machines_routes = [] for s in solution: current_processing_times.append(list(processing_times[s])) current_machines_routes.append(list(machines_routes[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,current_machines_routes processing_times = pd.read_csv('processing_times.csv',sep=",",header=None) machines_routes = pd.read_csv('machines.csv',sep=",",header=None) processing_times.transpose() machines_routes.transpose() #m = machines #n = jobs m,n = processing_times.shape[0],processing_times.shape[1] # m=3 # n=4 # sum_processing_times = [] # for p in range(n): # # sum_processing_times.append([p,sum(processing_times[p])]) #SPT / LPT # sum_processing_times.append([p,processing_times[p][0]]) #FSPT # from operator import itemgetter # # sum_processing_times_sorted = sorted(sum_processing_times, key=itemgetter(1)) #SPT # sum_processing_times_sorted = sorted(sum_processing_times, key=itemgetter(1), reverse=True) #LPT # ##https://www.delftstack.com/howto/python/sort-list-of-lists-in-python/ # solution = [] # for s in range(n): # solution.append(sum_processing_times_sorted[s][0]) solution = list(range(n)) # random.shuffle(solution) makespan,start_time,current_processing_times,current_machines_routes = build_schedule_jobshop(solution, processing_times, machines_routes) 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','cyan','grey','maroon','azure','purple','aqua','linen','crimson','olive','skyblue','beige'] 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[current_machines_routes[i][j]]) plt.gca().add_patch(rectangle) plt.text(start_time[-1][-3], 0, "Makespan: " + str(makespan)) plt.axis('auto') plt.show()