Ejemplo n.º 1
0
def compute_sum_weighted_completion(input_file):

   # open the input file in read mode
   f = open(input_file,'r')

   # Create a list of jobs
   jobs_list = []

   try:

      # populate the data into jobs_list data structure
      for line in f.readlines():
         str = line.split(" ") 
         int_list = [int(e) for e in str]
         if len(int_list) == 2 :
            j = Job(int_list[0],int_list[1])
            jobs_list.append(j)

   
      # sort the jobs in the array using insertion sort routine
      jobs_list = selection_sort(jobs_list)


      # print the job details here
      #for j in jobs_list:
         #print_no_new_line(j.getWeight().__str__()+" ")
         #print_no_new_line(j.getLength().__str__()+"\n")
     
      # compute the sum of weighted completion times
      sum_weighted_completion = 0
      completion = 0
      for j in jobs_list:
         completion = completion + j.getLength()
         j.setCompletion(completion)
         sum_weighted_completion = sum_weighted_completion + \
                                   j.getWeight()*j.getCompletion() 
      
      # display the final sum of weighted completion times
      print sum_weighted_completion



   finally:
      f.close()