Advertisement
Guest User

Untitled

a guest
May 19th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.43 KB | None | 0 0
  1. diff --git a/instance.py b/instance.py
  2. index 0d165f8..97d35b6 100644
  3. --- a/instance.py
  4. +++ b/instance.py
  5. @@ -320,10 +320,10 @@ class Instance():
  6. q.append(task[2])
  7. return q
  8.  
  9. - def schrage(self):
  10. + def schrage(self, unsorted_tasks): #tu dalem zmiane
  11. order = []
  12. sorted_tasks = []
  13. - unsorted_tasks = self.tasks[:]
  14. + #unsorted_tasks = self.tasks[:]
  15. t = min(self.handle_schrage_r(unsorted_tasks))
  16. j = None
  17.  
  18. @@ -341,13 +341,13 @@ class Instance():
  19. t += order[-1][1]
  20. return order
  21.  
  22. - def schrage_ptmn(self):
  23. + def schrage_ptmn(self, unsorted_tasks):
  24. sorted_tasks = []
  25. - unsorted_tasks = self.tasks[:]
  26. + #unsorted_tasks = self.tasks[:]
  27. cmax = 0
  28. t = 0
  29. j = None
  30. - l= [0, 0, 0]
  31. + l = [0, 0, 0]
  32. while sorted_tasks or unsorted_tasks:
  33. while unsorted_tasks and (min(self.handle_schrage_r(unsorted_tasks)) <= t):
  34. tmp_list = self.handle_schrage_r(unsorted_tasks)
  35. @@ -369,6 +369,72 @@ class Instance():
  36. cmax = max(cmax, t + task[2])
  37. return cmax
  38.  
  39. + @staticmethod
  40. + def handle_c(tasks):
  41. + C = 0
  42. + for task in tasks:
  43. + C = max(C, task[0]) + task[1]
  44. :...skipping...
  45. diff --git a/instance.py b/instance.py
  46. index 0d165f8..97d35b6 100644
  47. --- a/instance.py
  48. +++ b/instance.py
  49. @@ -320,10 +320,10 @@ class Instance():
  50. q.append(task[2])
  51. diff --git a/instance.py b/instance.py
  52. diff --git a/instance.py b/instance.py
  53. index 0d165f8..97d35b6 100644
  54. --- a/instance.py
  55. +++ b/instance.py
  56. @@ -320,10 +320,10 @@ class Instance():
  57. q.append(task[2])
  58. return q
  59.  
  60. - def schrage(self):
  61. + def schrage(self, unsorted_tasks): #tu dalem zmiane
  62. order = []
  63. sorted_tasks = []
  64. - unsorted_tasks = self.tasks[:]
  65. + #unsorted_tasks = self.tasks[:]
  66. t = min(self.handle_schrage_r(unsorted_tasks))
  67. j = None
  68.  
  69. @@ -341,13 +341,13 @@ class Instance():
  70. t += order[-1][1]
  71. return order
  72.  
  73. - def schrage_ptmn(self):
  74. + def schrage_ptmn(self, unsorted_tasks):
  75. sorted_tasks = []
  76. - unsorted_tasks = self.tasks[:]
  77. + #unsorted_tasks = self.tasks[:]
  78. cmax = 0
  79. t = 0
  80. j = None
  81. - l= [0, 0, 0]
  82. + l = [0, 0, 0]
  83. while sorted_tasks or unsorted_tasks:
  84. while unsorted_tasks and (min(self.handle_schrage_r(unsorted_tasks)) <= t):
  85. tmp_list = self.handle_schrage_r(unsorted_tasks)
  86. @@ -369,6 +369,72 @@ class Instance():
  87. cmax = max(cmax, t + task[2])
  88. return cmax
  89.  
  90. + @staticmethod
  91. + def handle_c(tasks):
  92. + C = 0
  93. + for task in tasks:
  94. + C = max(C, task[0]) + task[1]
  95. + return C
  96. +
  97. + @staticmethod
  98. + def find_b(tasks):
  99. + b = 0
  100. + reverse_tasks = tasks[::-1]
  101. + cmax = self.schrage_makespan(self.schrage(tasks))
  102. + for task in reverse_tasks:
  103. + index_of_task = tasks.index(task)
  104. + if cmax == self.handle_c(tasks[:index_of_task+1]) + task[2]:
  105. + b = index_of_task
  106. + break
  107. + return b
  108. +
  109. + @staticmethod
  110. + def find_a(tasks):
  111. + cmax = self.schrage_makespan(self.schrage(tasks))
  112. + a = 0
  113. + b = self.find_b(tasks)
  114. + for index in range(b+1):
  115. + sum = 0
  116. + for task in tasks[index:b+1]:
  117. + sum += task[1]
  118. + if cmax == tasks[index][0] + sum + tasks[b][2]:
  119. + a = index
  120. + break
  121. + return a
  122. +
  123. + @staticmethod
  124. + def find_c(tasks):
  125. + b = self.find_b(tasks)
  126. + a = self.find_a(tasks)
  127. + c = -1
  128. + for task in tasks[a:b+1]:
  129. + if task[2] < tasks[b][2]:
  130. + c = tasks.index(task)
  131. + break
  132. + return c
  133. +
  134. + def carlier(self, ub, tasks, opt_order):
  135. + a = 0
  136. + b = 0
  137. + c = -1
  138. + lb = 0
  139. + p_sum = 0
  140. + u = self.schrage_makespan(self.schrage(tasks))
  141. + if u < ub:
  142. + ub = u
  143. + opt_order = tasks[:]
  144. + b = self.find_b(tasks)
  145. + a = self.find_a(tasks)
  146. + c = self.find_c(tasks)
  147. + if c == -1:
  148. + return opt_order
  149. + K = tasks[c+1:b+1]
  150. + r_min = min(self.handle_schrage_r(K))
  151. + for task in K:
  152. + p_sum += task[1]
  153. + q_min = min(self.handle_schrage_q(K))
  154. +
  155. +
  156. def save_results(self, filename, algorithm, json_to_write):
  157. data = {}
  158. data['filename'] = filename
  159. diff --git a/schrage.py b/schrage.py
  160. index 8a0edf0..fc40682 100644
  161. --- a/schrage.py
  162. +++ b/schrage.py
  163. @@ -9,8 +9,8 @@ for file in files:
  164. data_parser = DataParser('data/schrage/{}'.format(file))
  165. jobs, columns, tasks = data_parser.parse_schrage()
  166. instance = Instance('Schrage', columns, jobs, tasks, [])
  167. - order = instance.schrage()
  168. + order = instance.schrage(tasks[:]) # tu zmiana dla dodatkowego argumentu unsorted_tasks
  169. makespan = instance.schrage_makespan(order)
  170. - cmax = instance.schrage_ptmn()
  171. + cmax = instance.schrage_ptmn(tasks[:])
  172. print("INFO: Makespan for {}: {}".format(file, makespan))
  173. print("INFO: CMAX for {} using SchragePtmn: {}".format(file,cmax))
  174. \ No newline at end of file
  175. (END)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement