Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/instance.py b/instance.py
- index 0d165f8..97d35b6 100644
- --- a/instance.py
- +++ b/instance.py
- @@ -320,10 +320,10 @@ class Instance():
- q.append(task[2])
- return q
- - def schrage(self):
- + def schrage(self, unsorted_tasks): #tu dalem zmiane
- order = []
- sorted_tasks = []
- - unsorted_tasks = self.tasks[:]
- + #unsorted_tasks = self.tasks[:]
- t = min(self.handle_schrage_r(unsorted_tasks))
- j = None
- @@ -341,13 +341,13 @@ class Instance():
- t += order[-1][1]
- return order
- - def schrage_ptmn(self):
- + def schrage_ptmn(self, unsorted_tasks):
- sorted_tasks = []
- - unsorted_tasks = self.tasks[:]
- + #unsorted_tasks = self.tasks[:]
- cmax = 0
- t = 0
- j = None
- - l= [0, 0, 0]
- + l = [0, 0, 0]
- while sorted_tasks or unsorted_tasks:
- while unsorted_tasks and (min(self.handle_schrage_r(unsorted_tasks)) <= t):
- tmp_list = self.handle_schrage_r(unsorted_tasks)
- @@ -369,6 +369,72 @@ class Instance():
- cmax = max(cmax, t + task[2])
- return cmax
- + @staticmethod
- + def handle_c(tasks):
- + C = 0
- + for task in tasks:
- + C = max(C, task[0]) + task[1]
- :...skipping...
- diff --git a/instance.py b/instance.py
- index 0d165f8..97d35b6 100644
- --- a/instance.py
- +++ b/instance.py
- @@ -320,10 +320,10 @@ class Instance():
- q.append(task[2])
- diff --git a/instance.py b/instance.py
- diff --git a/instance.py b/instance.py
- index 0d165f8..97d35b6 100644
- --- a/instance.py
- +++ b/instance.py
- @@ -320,10 +320,10 @@ class Instance():
- q.append(task[2])
- return q
- - def schrage(self):
- + def schrage(self, unsorted_tasks): #tu dalem zmiane
- order = []
- sorted_tasks = []
- - unsorted_tasks = self.tasks[:]
- + #unsorted_tasks = self.tasks[:]
- t = min(self.handle_schrage_r(unsorted_tasks))
- j = None
- @@ -341,13 +341,13 @@ class Instance():
- t += order[-1][1]
- return order
- - def schrage_ptmn(self):
- + def schrage_ptmn(self, unsorted_tasks):
- sorted_tasks = []
- - unsorted_tasks = self.tasks[:]
- + #unsorted_tasks = self.tasks[:]
- cmax = 0
- t = 0
- j = None
- - l= [0, 0, 0]
- + l = [0, 0, 0]
- while sorted_tasks or unsorted_tasks:
- while unsorted_tasks and (min(self.handle_schrage_r(unsorted_tasks)) <= t):
- tmp_list = self.handle_schrage_r(unsorted_tasks)
- @@ -369,6 +369,72 @@ class Instance():
- cmax = max(cmax, t + task[2])
- return cmax
- + @staticmethod
- + def handle_c(tasks):
- + C = 0
- + for task in tasks:
- + C = max(C, task[0]) + task[1]
- + return C
- +
- + @staticmethod
- + def find_b(tasks):
- + b = 0
- + reverse_tasks = tasks[::-1]
- + cmax = self.schrage_makespan(self.schrage(tasks))
- + for task in reverse_tasks:
- + index_of_task = tasks.index(task)
- + if cmax == self.handle_c(tasks[:index_of_task+1]) + task[2]:
- + b = index_of_task
- + break
- + return b
- +
- + @staticmethod
- + def find_a(tasks):
- + cmax = self.schrage_makespan(self.schrage(tasks))
- + a = 0
- + b = self.find_b(tasks)
- + for index in range(b+1):
- + sum = 0
- + for task in tasks[index:b+1]:
- + sum += task[1]
- + if cmax == tasks[index][0] + sum + tasks[b][2]:
- + a = index
- + break
- + return a
- +
- + @staticmethod
- + def find_c(tasks):
- + b = self.find_b(tasks)
- + a = self.find_a(tasks)
- + c = -1
- + for task in tasks[a:b+1]:
- + if task[2] < tasks[b][2]:
- + c = tasks.index(task)
- + break
- + return c
- +
- + def carlier(self, ub, tasks, opt_order):
- + a = 0
- + b = 0
- + c = -1
- + lb = 0
- + p_sum = 0
- + u = self.schrage_makespan(self.schrage(tasks))
- + if u < ub:
- + ub = u
- + opt_order = tasks[:]
- + b = self.find_b(tasks)
- + a = self.find_a(tasks)
- + c = self.find_c(tasks)
- + if c == -1:
- + return opt_order
- + K = tasks[c+1:b+1]
- + r_min = min(self.handle_schrage_r(K))
- + for task in K:
- + p_sum += task[1]
- + q_min = min(self.handle_schrage_q(K))
- +
- +
- def save_results(self, filename, algorithm, json_to_write):
- data = {}
- data['filename'] = filename
- diff --git a/schrage.py b/schrage.py
- index 8a0edf0..fc40682 100644
- --- a/schrage.py
- +++ b/schrage.py
- @@ -9,8 +9,8 @@ for file in files:
- data_parser = DataParser('data/schrage/{}'.format(file))
- jobs, columns, tasks = data_parser.parse_schrage()
- instance = Instance('Schrage', columns, jobs, tasks, [])
- - order = instance.schrage()
- + order = instance.schrage(tasks[:]) # tu zmiana dla dodatkowego argumentu unsorted_tasks
- makespan = instance.schrage_makespan(order)
- - cmax = instance.schrage_ptmn()
- + cmax = instance.schrage_ptmn(tasks[:])
- print("INFO: Makespan for {}: {}".format(file, makespan))
- print("INFO: CMAX for {} using SchragePtmn: {}".format(file,cmax))
- \ No newline at end of file
- (END)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement