Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import itertools
- # Creates an Engine object
- class Engine:
- def __init__(self, time, comp):
- self.time = time
- self.comp = comp
- def __repr__(self):
- return f"<Engine Time: {self.time}, Company: {self.comp}>"
- # Defines the available Engines
- engines = [Engine([6, 7, 9], 0), Engine([6, 7, 9], 0), Engine([6, 7, 9], 0), Engine(
- [5, 8, 11], 1), Engine([5, 8, 11], 1), Engine([6, 9, 10], 2), Engine([6, 9, 10], 2)]
- # Cost calculations for each fire
- def fire_0(eng0, eng1):
- return 6*eng0.time[0] + 4*eng1.time[0]
- def fire_1(eng0, eng1):
- return 7*eng0.time[1] + 3*eng1.time[1]
- def fire_2(eng0, eng1, eng2):
- return 9*eng0.time[2] + 8*eng1.time[2] + 5*eng2.time[2]
- # Arbitrary starting values
- lowest_cost = 10000
- lowest_perm = '999999999'
- # Functions to calculate sum of a possibility
- def get_sum(a, b, c, d, e, f, g):
- return fire_0(a, b) + fire_1(c, d) + fire_2(e, f, g)
- # Running the simulation
- for combi in itertools.permutations(engines, 7):
- new_sum = get_sum(combi[0], combi[1], combi[2],
- combi[3], combi[4], combi[5], combi[6])
- if lowest_cost > new_sum:
- lowest_cost = new_sum
- lowest_perm = combi
- print(lowest_cost)
- print(lowest_perm)
- print("Fire 1: comp1 + comp1")
- print("Fire 2: comp0 + comp2")
- print("Fire 3: comp0 + comp0 + comp2")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement