""" instance.py : manage data related to a scheduling instance Copyright Joao Pedro PEDROSO, FCUP/DCC, 09/2004 ********************************************************************** """ from numarray import * import numarray.random_array class Instance: """keep all relavant instance data in a structure, and preprocess it ********************************************************************** required data: -------------- self.JOBS -> list of jobs, e.g. [1,2] self.OPS -> list of all operations, e.g. [1,2,3,4,5,6] NOTE: operation 0 is used to for cleaning self.MACHS -> lists of machines, e.g. [1,2,3] self.O -> list of operations for each job, e.g { 1: [1,2,3,6], 2: [4,5,7,8]} self.COMP -> operation-machine compatibilities, e.g. {1: [1,2], 2: [1,2], ...} self.DEPS -> list of all direct job dependencies (arcs), e.g. [ (1,2), (2,6), ...] self.D -> array with operation durations, e.g. [0, 155, 117, 126, 198, 191, 167, 137, 189] self.C -> array with changeover times, e.g.[[1, 2, 9, 8, 2, 5, 5, 7, 6], [6, 0, 2, 1, 3, 1, 1, 8, 3], ...] self.U -> array with machine transfer times, e.g.[[ 0, 0, 0, 0], [ 0, 0, 11, 19], ...] ********************************************************************** data created on preprocessing: ------------------------------ self.prec -> list of job precedences for each operation self.succ -> list of job successor for each operation ********************************************************************** """ def preprocess(self): """preprocess data: get predecessors and successors for each operation""" self.prec = {} self.succ = {} for i in self.OPS: self.prec[i] = [] self.succ[i] = [] for (i,j) in self.DEPS: self.prec[j].append(i) self.succ[i].append(j) def __str__(self): """ !!! complete with extended output !!! """ self.preprocess() s = "" s += 'prec: ' + str(self.prec) + "\n" s += 'succ: ' + str(self.succ) + "\n" return s # define a small instance gbl_inst = Instance() gbl_inst.JOBS = [1,2] gbl_inst.OPS = [1,2,3,4,5,6,7,8] gbl_inst.MACHS = [1,2,3] gbl_inst.O = { 1: [1,2,3,6], 2: [4,5,7,8], } gbl_inst.COMP = { 1: [1,2], 2: [1,2], 3: [1,2], 4: [1,2], 5: [1,2], 6: [3], 7: [3], 8: [3], } gbl_inst.DEPS = [ (1,2), (2,6), (3,6), (4,5), (5,7), (5,8), ] # # operation's processing duration # D = numarray.random_array.randint(100,200,(8,)) # <-- random initialization gbl_inst.D = array([0, 110, 120, 130, 140, 150, 160, 170, 180]) # # changeover times # C = numarray.random_array.randint(0,10,(9,9)) # <-- random initialization gbl_inst.C = array( [[1, 2, 9, 8, 2, 5, 5, 7, 6], [6, 0, 2, 1, 3, 1, 1, 8, 3], [3, 4, 5, 6, 2, 6, 4, 6, 7], [9, 3, 0, 9, 6, 9, 9, 3, 7], [5, 6, 0, 1, 5, 8, 8, 8, 8], [2, 1, 8, 8, 6, 5, 5, 0, 4], [8, 1, 1, 7, 9, 2, 0, 2, 3], [2, 5, 1, 1, 6, 6, 4, 1, 5], [5, 5, 4, 4, 6, 9, 6, 8, 0]]) # # machine transfer times # U = numarray.random_array.randint(10,20,(4,4)) # <-- random initialization gbl_inst.U = array( [[ 0, 0, 0, 0], [ 0, 0, 11, 19], [ 0, 11, 0, 13], [ 0, 16, 15, 0]]) gbl_inst.preprocess() if __name__ == '__main__': print gbl_inst