Issue
I am currently trying to create a function that does the following.
I want to generate demand patterns that control with the parameters 1) days 2) shifts and 3) demand. Since the demand can of course only occur in discrete values, I would use the Poisson distribution for this. Then the previously defined number of shifts should be added to each day, and then the demand should be distributed to these shifts. The first value (stratum 1) is to be taken from the Poisson distribution, the second then also (whereby this can only receive a maximum of the value of demand - value of stratum 1. And the last shift is then assigned the missing difference.
This example now applies to shift = 3. If there are more shifts, this should be adjusted dynamically. Since this approach means that the last shift can only ever have a lower value, a random new start shift should always be selected every day. And every day, the demand should then always be distributed exactly to all available shifts.
What would such a code look like if I wanted to save the values in a .csv file? This is my code so far.
import csv
import random
from scipy.stats import poisson
def simulate_demand(num_days, num_shifts, demand):
with open(r'...\nachfrage.csv', 'w', newline='') as csvfile:
writer = csv.writer(csvfile)
writer.writerow(['Day', 'Shift', 'Demand'])
for day in range(1, num_days + 1):
Solution
Understanding from question : You want demand data for a certain number of days and shifts using the Poisson distribution. Please check this :
import csv
from scipy.stats import poisson
def simulate_demand(num_days, num_shifts, demand_mean):
with open(r'...\nachfrage.csv', 'w', newline='') as csvfile:
writer = csv.writer(csvfile)
writer.writerow(['Day', 'Shift', 'Demand'])
for day in range(1, num_days + 1):
for shift in range(1, num_shifts + 1):
demand_value = poisson.rvs(demand_mean)
writer.writerow([day, shift, demand_value])
# Adjust below values as per requirement
num_days = 30
num_shifts = 3
demand_mean = 10
simulate_demand(num_days, num_shifts, demand_mean)
Answered By - TheHungryCub
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.