I’m trying to generate a random sequence of outages for a set of industrial plants.
An individual plant can be either online, or offline. I need to generate a time-series for each plant showing it’s availability (0 = offline, 1 = online).
Each plant has characteristic data giving its mean outage duration (in days, usually around 3), and the mean fraction of time it is offline in any given duration (in %, around 5%).
I have a solution using native Python, which draws a series of outage lengths and days between outages, both from geometric distributions. However, this is quite slow when generating many series. Is there a way I can use Pandas to speed this up?
mean_outage_length = 3
forced_outage_derating = 0.95
# Forced Outage Derating is percentage of time you would expect a plant to be online allowing for unplanned outages only
outage_length_mu = np.log(1 - 1 / (mean_outage_length + 1))
between_outages_probability = (1 - forced_outage_derating) * (1 / (mean_outage_length + 1)) / (forced_outage_derating)
if between_outages_probability >= 0.9999999999999999:
between_outages_mu = -40
else:
between_outages_mu = np.log(1 - between_outages_probability)
sum_of_days = 0
days_in_between_outages = []
outage_lengths = []
days_in_simulation_window = 1000
while True:
outage_length = math.floor(np.log(1 - random.random()) / outage_length_mu)
days_until_next_outage = math.ceil(np.log(1 - random.random()) / between_outages_mu)
if first_pass:
first_pass = False
if random.random() > forced_outage_derating:
days_until_next_outage = 0
sum_of_days += (days_until_next_outage + outage_length)
if sum_of_days > days_in_simulation_window:
break
outage_lengths.append(outage_length)
days_in_between_outages.append(days_until_next_outage)
if sum_of_days - outage_length <= days_in_simulation_window:
days_in_between_outages.append(days_until_next_outage)
outage_lengths.append((days_in_simulation_window - (sum_of_days - outage_length)) + 1)
Expected Output:
Given a set of N plants, with each plant having a mean outage length, and expected fraction of time online, return a set of outage lengths and durations between outages.
e.g.
Input:
Simulation Duration: 100 days
Plant A: Mean outage length – 5 days, fraction of time online – 80%
Plant B: Mean outage length – 3 days, fraction of time online – 90%
Output:
Plant A: Outage Durations – [3, 7, 6, 4], Duration between outages – [15, 25, 30, 10]
Plant B: Outage Durations – [2, 5, 3], Duration between outages – [35, 15, 40]
6