Advertisement
EditorRUS

maint_sim.py

Dec 29th, 2015
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.13 KB | None | 0 0
  1. from math import ceil, floor
  2.  
  3. NOT_NEGATIVE = 2**0
  4. POSITIVE     = 2**1
  5. BOUNDARY      = 2**2
  6.  
  7. def persistent_input(question, the_type, rules=0, boundary=[]):
  8.     val = 0
  9.     while True:
  10.         try:
  11.             val = eval('{0}(input(\'{1}\'))'.format(the_type, question))     # Metacode
  12.         except ValueError:
  13.             continue
  14.         else:
  15.             try:
  16.                 if (rules & NOT_NEGATIVE) and val < 0: continue
  17.                 if (rules & POSITIVE) and val <= 0: continue
  18.                 if (rules & BOUNDRY) and val in range(boundary[0], boundary[1]+1): continue
  19.             except:
  20.                 pass # Not appliable
  21.             return val
  22.        
  23. AVG_MONTH   = 30
  24. MONTH       = 24*AVG_MONTH
  25. YEAR        = 24*365
  26. ENG_COST    = persistent_input('Engineer hire cost (1000s): ', 'float', NOT_NEGATIVE)*1000
  27. ENG_SAL     = persistent_input('Engineer salary (1000s): ', 'float', NOT_NEGATIVE)*1000
  28. WORK_COST   = persistent_input('Workshop cost (1000s): ', 'float', NOT_NEGATIVE)*1000
  29. LIVI_COST   = persistent_input('Living quarters cost (1000s): ', 'float', NOT_NEGATIVE)*1000
  30. WORK_MAIN   = persistent_input('Workshop maintenance cost (1000s): ', 'float', NOT_NEGATIVE)*1000
  31. LIVI_MAIN   = persistent_input('Living quarters maintenance cost (1000s): ', 'float', NOT_NEGATIVE)*1000
  32. MAX_WORKSHOPS = floor((6*6-1) / 2)
  33. TFTD = False
  34.  
  35. while True:
  36.     answer = input("TFTD rules? Y/N: ")
  37.     if answer.upper() == "Y":
  38.         TFTD = True
  39.         break
  40.     if answer.upper() == "N":
  41.         TFTD = False
  42.         break
  43.  
  44. print()
  45.  
  46. while True:
  47.     man_hours = persistent_input("Man-hours: ", 'int', POSITIVE)
  48.     man_cost  = persistent_input("Manufacture cost (1000s): ", 'float', POSITIVE)*1000
  49.     man_sell  = persistent_input("Selling cost (1000s): ", 'float', POSITIVE)*1000
  50.     man_space = persistent_input("Workshop space: ", 'int', POSITIVE)
  51.     man_sanity = persistent_input("Max amount of workshops: ", 'int', POSITIVE)
  52.    
  53.     max_workshops_needed = ceil(man_hours+man_space / 50)
  54.     higher_limit_of_engineers = man_hours
  55.  
  56.     best_engineers = 0
  57.     best_workshops = 0
  58.     best_living_space = 0
  59.     best_profit = 0
  60.     best_product = 0
  61.     best_setup = 0
  62.  
  63.     max_workshops_needed = min(MAX_WORKSHOPS, man_sanity)
  64.    
  65.     for workshops in range(1, max_workshops_needed+1):
  66.         max_engineers = workshops*50-man_space
  67.         min_engineers = (workshops-1)*50
  68.         for engineers in range(min_engineers, max_engineers+1):
  69.             reqLS = ceil(engineers / 50)
  70.             hours_to_do = man_hours
  71.             product_made = 0
  72.             for hour in range(MONTH):
  73.                 hours_to_do = hours_to_do - engineers
  74.                 while hours_to_do <= 0:
  75.                     product_made += 1
  76.                     if TFTD:
  77.                         hours_to_do += man_hours
  78.                     else:
  79.                         hours_to_do = man_hours
  80.             income = product_made * man_sell
  81.             maint  = workshops * WORK_MAIN +\
  82.                      reqLS * LIVI_MAIN +\
  83.                      engineers * ENG_SAL
  84.             expend = product_made * man_cost
  85.             expend = expend + maint
  86.             profit = income - expend
  87.             setup = workshops*WORK_COST +\
  88.                     reqLS*LIVI_COST +\
  89.                     engineers*ENG_COST
  90.             if profit > best_profit:
  91.                 best_engineers = engineers
  92.                 best_living_space = reqLS
  93.                 best_workshops = workshops
  94.                 best_profit = profit
  95.                 best_setup = setup
  96.                 best_product = product_made
  97.  
  98.     print()
  99.     print('Best setup')
  100.     print('\tMonthly profit: {0}$'.format(best_profit))
  101.     print('\tEngineers needed: {0}'.format(best_engineers))
  102.     print('\tLiving quartes needed: {0}'.format(best_living_space))
  103.     print('\tWorkshops needed: {0}'.format(best_workshops))
  104.     print('\tSetup cost: {0}$'.format(best_setup))
  105.     if best_profit <= 0:
  106.         print('\tPayoff in: NEVER')
  107.     else:
  108.         print('\tPayoff in: {0} days'.format(ceil(24 * (best_setup / best_profit))))
  109.     print('\tProduct made: {0}'.format(best_product))
  110.     print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement