Advertisement
D_Pain

Engine Calculation

Nov 2nd, 2020 (edited)
2,165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.37 KB | None | 0 0
  1. import itertools
  2.  
  3. # Creates an Engine object
  4.  
  5.  
  6. class Engine:
  7.     def __init__(self, time, comp):
  8.         self.time = time
  9.         self.comp = comp
  10.  
  11.     def __repr__(self):
  12.         return f"<Engine Time: {self.time}, Company: {self.comp}>"
  13.  
  14.  
  15. # Defines the available Engines
  16. engines = [Engine([6, 7, 9], 0), Engine([6, 7, 9], 0), Engine([6, 7, 9], 0), Engine(
  17.     [5, 8, 11], 1), Engine([5, 8, 11], 1), Engine([6, 9, 10], 2), Engine([6, 9, 10], 2)]
  18.  
  19. # Cost calculations for each fire
  20.  
  21.  
  22. def fire_0(eng0, eng1):
  23.     return 6*eng0.time[0] + 4*eng1.time[0]
  24.  
  25.  
  26. def fire_1(eng0, eng1):
  27.     return 7*eng0.time[1] + 3*eng1.time[1]
  28.  
  29.  
  30. def fire_2(eng0, eng1, eng2):
  31.     return 9*eng0.time[2] + 8*eng1.time[2] + 5*eng2.time[2]
  32.  
  33.  
  34. # Arbitrary starting values
  35. lowest_cost = 10000
  36. lowest_perm = '999999999'
  37.  
  38. # Functions to calculate sum of a possibility
  39.  
  40.  
  41. def get_sum(a, b, c, d, e, f, g):
  42.     return fire_0(a, b) + fire_1(c, d) + fire_2(e, f, g)
  43.  
  44.  
  45. # Running the simulation
  46. for combi in itertools.permutations(engines, 7):
  47.     new_sum = get_sum(combi[0], combi[1], combi[2],
  48.                       combi[3], combi[4], combi[5], combi[6])
  49.     if lowest_cost > new_sum:
  50.         lowest_cost = new_sum
  51.         lowest_perm = combi
  52.  
  53.  
  54. print(lowest_cost)
  55. print(lowest_perm)
  56. print("Fire 1: comp1 + comp1")
  57. print("Fire 2: comp0 + comp2")
  58. print("Fire 3: comp0 + comp0 + comp2")
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement