Turnovers=A.Input_data(worksheet_RapidMiner,workbook)#Dictionary with the data from the Excel file
#Create lists with the MAs' names and the Turnovers for the first twelve weeks of 2010 retrieving this data from the dictionary
PPOS=Turnovers.get('Ppos',[])
SP=Turnovers.get('SP',[])
MA=Turnovers.get('FP Material No PGS+',[])
GlobalDemand=Turnovers.get('Global demand',[])
#Call the Distributions object and fit the data from the list in Normal distribution, so as to have info on Global demand (mean and standard deviation)
D=Distributions()
E=HandleMissingValues()
MA=E.DeleteMissingValue(MA)
t=D.Normal_distrfit(GlobalDemand)
avg=t.get('mean')
stdev=t.get('stdev')
defconstrained_sum_sample_pos(n,total):
"""Return a randomly chosen list of n positive integers summing to total.
week=[]# list that defines the planning horizon, i.e. 10 weeks
foriinrange(int(planningHorizon)):
week.append(i+1)
foriinweek:
Demand=int(abs(random.normalvariate(avg,stdev)))# Generate a random, non-negative, integer number from the Normal distribution
AllocatedPercent=0.8-(0.05*i)# Defines a number starts with 0.8 or 80% and reduced with every iteration at 0.05 or 5%
Remaining_Demand=int((1-AllocatedPercent)*Demand)# Defines the Remaining demand
a=constrained_sum_sample_nonneg(len(MA),100)
myInt=100
a=robjects.FloatVector(a)
lista=[x/myIntforxina]# Define a list with the same length as the MA list and elements float numbers with total sum equal to 1
b=constrained_sum_sample_nonneg(len(MA),Remaining_Demand)# Define a list with the same length as the MA list and elements with total sum the Remaining demand
dicta.update({MA[index]:[TotalUnits,MinUnits]})# it updates a dictionary with key the different MAs and values the remaining demand and (b[index]*lista[index])
DemandProfile.update({i:dicta})#It updates a dictionary with key the number of each iteration (week) and value the dictionary dicta