import random
import numpy as np
class Process:
def __init__(self, id, estimated_value, complexity, technology):
self.id = id
self.estimated_value = estimated_value
self.complexity = complexity # 'low', 'medium', 'high'
self.technology = technology
self.real_value = None
self.build_time = None # Number of days to build
self.built = False
self.value_earned = 0
def __repr__(self):
return f"Process(id={self.id}, estimated_value={self.estimated_value}, complexity={self.complexity}, technology={self.technology}, built={self.built})"
def identification_phase(num_processes):
processes = []
complexities = ['low', 'medium', 'high']
technologies = ['TechA', 'TechB', 'TechC', 'TechD', 'TechE', 'TechF', 'TechG']
for i in range(num_processes):
estimated_value = random.randint(1000, 100000)
complexity = random.choice(complexities)
technology = random.choice(technologies)
processes.append(Process(i, estimated_value, complexity, technology))
return processes
def calculate_build_time(process, known_technologies):
base_time = 0
if process.complexity == 'low':
base_time = 30
elif process.complexity == 'medium':
base_time = 200
else: # high
base_time = 600
tech_discount = 0
if process.technology in known_technologies:
tech_discount = 0.9 # Up to 90% discount if technology is known
build_time = base_time * (1 - tech_discount)
return int(build_time)
def build_phase(processes, build_strategy, known_technologies):
buildable_processes = [p for p in processes if not p.built]
if not buildable_processes:
return # No more processes to build
if build_strategy == 'random':
process_to_build = random.choice(buildable_processes)
elif build_strategy == 'highest_value':
process_to_build = max(buildable_processes, key=lambda p: p.estimated_value)
elif build_strategy == 'lowest_build_time':
#Pre-calculate the build time for all processes, then select based on build time
for p in buildable_processes:
p.build_time = calculate_build_time(p, known_technologies)
process_to_build = min(buildable_processes, key=lambda p: p.build_time)
elif build_strategy == 'synergy':
# Filter buildable processes based on technology expertise
synergy_processes = [p for p in buildable_processes if p.technology in known_technologies]
if synergy_processes:
process_to_build = random.choice(synergy_processes) #If more than one tech matches, choose randomly
else:
# If no processes match known technologies, revert to random selection
process_to_build = random.choice(buildable_processes)
else:
raise ValueError(f"Invalid build strategy: {build_strategy}")
process_to_build.build_time = calculate_build_time(process_to_build, known_technologies)
return process_to_build
def earn_phase(process):
# Simulate earning the real value. The real value can deviate quite a lot
# from the estimated value. Could add some logic here to make this depend on
# complexity, technology, etc.
process.real_value = int(process.estimated_value * random.uniform(0.5, 1.5)) # +/- 50% deviation
process.value_earned = process.real_value
process.built = True #Mark the process as built
return process.real_value
def simulate(num_processes=5000, identification_rate=1, build_strategy='random', simulation_days=365, known_technologies=None):
"""
Simulates the IT improvement process.
Args:
num_processes: Total number of processes to identify.
identification_rate: Number of processes identified per day.
build_strategy: Strategy for choosing processes to build ('random', 'highest_value', 'lowest_build_time', 'synergy').
simulation_days: Number of days to run the simulation.
known_technologies: A list of technologies that are already known/familiar.
Returns:
A dictionary where keys are process IDs and values are the value earned.
"""
if known_technologies is None:
known_technologies = []
processes = identification_phase(num_processes)
identified_processes = []
value_earned_per_process = {}
total_value_earned = 0
processes_building = []
processes_building_done = []
for day in range(simulation_days):
# Identification Phase
num_to_identify = int(random.uniform(0, identification_rate+1)) #Identify 0 - identification_rate +1 processes each day
available_processes = [p for p in processes if p not in identified_processes]
processes_to_identify = random.sample(available_processes, min(num_to_identify, len(available_processes)))
identified_processes.extend(processes_to_identify)
# Build Phase
# start building one project a day, if possible
if len([p for p in processes_building if p.build_time > 0]) == 0: #If not projects in the build phase
process_to_build = build_phase(identified_processes, build_strategy, known_technologies)
if process_to_build is not None: #Check we have a process to build
processes_building.append(process_to_build)
#Advance the build time for processes in building
for process in processes_building:
if process.build_time != None:
if process.build_time > 0:
process.build_time -= 1
if process.build_time == 0:
real_value = earn_phase(process)
value_earned_per_process[process.id] = real_value
total_value_earned += real_value
processes_building_done.append(process)
if process.technology not in known_technologies:
known_technologies.append(process.technology) #Learn new technology
#Remove processes once built
for process in processes_building_done:
processes_building.remove(process)
processes_building_done = []
print(f"Simulation over {simulation_days} days.")
print(f"Total value earned: {total_value_earned}")
return value_earned_per_process, total_value_earned
if __name__ == '__main__':
# Example Usage
# Vary parameters to see how they affect the outcome
num_processes = 500 # Reduced for faster demonstration
identification_rate = 2
build_strategy = 'highest_value' #Try different strategies
simulation_days = 365
known_technologies = ['TechA'] # Start with some initial expertise
results, total_value = simulate(num_processes, identification_rate, build_strategy, simulation_days, known_technologies)
print("\nValue earned per process:")
# Print only a subset of the results for brevity
for i, (process_id, value) in enumerate(results.items()):
if i >= 10:
break
print(f"Process ID: {process_id}, Value Earned: {value}")
print(f"\nTotal Value Earned: {total_value}")