def get_history(demand_type,TS,lt, agent_pos,AI_choice): Mu = 10 Sigma = 5 periods = 40 ''' Je ne vois pas comment est-ce qu'on peut éviter de faire le if comme tu avais proposé Thierry. Dans un moment ou l'autre il va falloir lire la valeur dans demand_type et créer l'instance de la bonne classe Donc soit on doit faire ce lecture ici dans la création des classes soit dans une fonction dans le fichier des Demandes De toute le façon on aura un if avec tous les cas et ensuite la création de la demande avec les bon paramêtres ''' if demand_type == "Seasonal": demand = Demand.Seasonal_Demand(15, 5, 0, 1.5, 0, Mu - 2, Sigma) elif demand_type == "Growing": demand = Demand.Growing_Demand(0,(2*Mu/periods), 0, Sigma) elif demand_type == "Sporadic": demand = Demand.Sporadic_Demand (Mu,0.2,5) elif demand_type == "Gaussian": demand= Demand.Gaussian_Demand(Mu, Sigma, min_value = 0, max_value = 100) elif demand_type =="Uniform": demand = Demand.Uniform_Demand(Mu,Mu+1,Step = 1) elif demand_type == "Growingseasonal": demand = Demand.Growing_Seasonal_Demand(1,[Mu*0.5,Mu* 0.8,Mu*0.7,Mu*0.9,Mu,Mu,Mu*0.9,Mu*1.2,Mu,Mu*1.1,Mu*1.5,Mu*2], Sigma) elif demand_type == "Mixedseasonal": demand = Demand.Mixed_Saisonnalities_Demand(Mu, [1,2,2,2,3,4,4,2,1,1,4,3,2,3,4,2,1,2,3,2,3,2,3,2,3],[0.6,0.8,0.7,0.9], Sigma) elif demand_type == "Growthstable": demand = Demand.Growth_Stable_Demand(0, 1, Mu + 5, Sigma) game_params = { 'client_demand': demand, 'lead_times':[ld.Constant_LeadTime(lt), ld.Constant_LeadTime(lt), ld.Constant_LeadTime(lt), ld.Constant_LeadTime(lt)], 'AI_possible_actions': np.arange(-10,11), 'm' :1, 'shortage_cost':get_optimal_gaussian_SC(TS, Mu = Mu, Sigma= Sigma, lead_time=lt), 'holding_cost':1, 'initial_inventory': Mu*lt, 'number_periods':periods, 'use_backorders':1, 'state_features':["IL" ,"d", "BO", "RS", "OO","t"], 'AI_DN':[10,10], # Not implemented yet 'TS':TS } list_agents = ['BS20','BS20', 'BS20' , 'BS20'] list_agents[agent_pos-1] = 'BNC' test_agents = generate_agents(list_agents, game_params) bg = BG.BeerGame() env = Env.Environment(test_agents, game_params) env.reset() bg.play(env, test_agents, train = False, display = False , display_all=False) # History #print("History keys : ", env.history.keys()) #print(env.history['IL']) # IMPORTANT NOTE!! # There are 4 agent # They're indices are 1, 2 ,3 ,4 #print("Agent's 1 stock history : ", env.history['IL'][:,1]) #print("Agent's 2 stock history : ", env.history['IL'][:,2]) #print("Agent's 3 stock history : ", env.history['IL'][:,3]) #print("Agent's 4 stock history : ", env.history['IL'][:,4]) return env.history
def __init__(self, index, vision,freq, mu, sigma, label = "BS", lead_time = ld.Uniform_LeadTime(2,2,1), BS_level = 20): Agent.__init__(self, index = index, lead_time = lead_time, label = label+"("+str(BS_level)+")") self.BS_level = BS_level self.vision = vision self.freq = freq self.lastupdate = 0 self.average = mu
def __init__(self, index = 0, lead_time = None, label="agent"): self.i = index self.label = label self.is_AI_agent = False if lead_time: self.lead_time = lead_time else: self.lead_time = ld.Uniform_LeadTime(2,2,1)
def __init__(self, index, sigma, TS, mu, label = "BS_Gauss", lead_time = ld.Constant_LeadTime(1)): """ Args: index : position agent dans la chaine sigma : sigma de la demande gaussienne à lequel l'agent va faire face TS : souhaité par le client mu : mu de la demande gaussienne à lequel l'agent va faire face label : lead_time : """ global dict_z z = dict_z[str(TS)] self.BS_level = int(np.sqrt(lead_time.Mean) * sigma * z + (lead_time.Mean * mu)) + 1 #Base stock = point de commande de stock (lead_time * mu) + stock de securité Agent.__init__(self, index = index, lead_time = lead_time, label = label+"("+str(self.BS_level)+")")
def __init__(self, index, sigma, TS, mu, label = "SS_Gauss", lead_time = ld.Uniform_LeadTime(2,2,1)): """ index : position agent dans la chaine sigma : sigma de la demande gaussienne à lequel l'agent va faire face TS : souhaité par le client mu : mu de la demande gaussienne à lequel l'agent va faire face label : lead_time : """ Agent.__init__(self, index = index, lead_time = lead_time, label = label) self.mu = mu self.leadtime=lead_time global dict_z z = dict_z[str(TS)] #Base stock = point de commande de stock (lead_time * mu) + stock de securité self.BS_level = int(np.sqrt(self.leadtime.Mean) * sigma * z + (self.leadtime.Mean) * self.mu)+1
def __init__ (self, index, sigma, TS, demand , label = "SS_Seas", lead_time = ld.Uniform_LeadTime(2,2,1), BS_level = 20): """ Args: index : agent's index sigma : standard deviation TS : Taux de service demand : end client seasonal demand instance nb_periodes : number of periods that will have the demand. Used to create the list of averages per period label : agent's label lead_time : lead time of the agent """ self.BS_level_list = [] demand_avg = demand.demand_avg self.size = len(demand_avg) global dict_z z = dict_z[str(TS)] for t in range(self.size): self.BS_level_list.append(int(np.sqrt(lead_time.Mean) * sigma * z + demand_avg[t]*lead_time.Mean))
import Demand as Demand import LeadTime as ld import numpy as np DEFAULT_PARAMS = { 'client_demand': Demand.Uniform_Demand(1,10,Step = 1), 'lead_times':[ld.Uniform_LeadTime(2,3), ld.Uniform_LeadTime(2,3), ld.Uniform_LeadTime(2,3), ld.Uniform_LeadTime(2,3)], 'AI_possible_actions': np.arange(-10,11), 'm' :1, 'shortage_cost':4, 'holding_cost':1, 'initial_inventory':20, 'number_periods':52, 'use_backorders':1, 'state_features':["IL" ,"d", "BO", "RS", "OO"], 'AI_DN':[10,10] }
def __init__(self, index, label = "BS", lead_time = ld.Uniform_LeadTime(2,2,1), BS_level = 20): Agent.__init__(self, index = index, lead_time = lead_time, label = label+"("+str(BS_level)+")") self.BS_level = BS_level
def __init__(self, index, lead_time = ld.Uniform_LeadTime(2,2,1), RND_possible_actions = [-5, 0, 5], label = "RND"): Agent.__init__(self, index = index, lead_time = lead_time, label = label) self.RND_possible_actions = RND_possible_actions
def Use_Dicts(global_variables,demand_variables): for i in range(len(global_variables)): for j in range(len(demand_variables)): reload_all() #%matplotlib qt5 # RE DEFINE PATH TO THE RESULTS FOLDER path = 'C:/Users/danie/Dropbox/BeerGame/' TS = global_variables[i]['TS'] Mu = global_variables[i]['mu'] Sigma = global_variables[i]['sigma'] constant_ld = global_variables[i]['ltavg'] periods = 40 ''' old way of using all demand types #il faut choisir le type de demand et les actions possibles #ensuite lancer avec les variations des autres variables avec le dictionnaire crée ''' demand_type = global_variables[i]['demand_type'] if demand_type == "Seasonal": demand = Demand.Seasonal_Demand(15, 5, 0, 1.5, 0, Mu - 2, Sigma) elif demand_type == "Growing": demand = Demand.Growing_Demand(0,(2*Mu/periods), 0, Sigma) elif demand_type == "Sporadic": demand = Demand.Sporadic_Demand(Mu,0.2,5) #demand.generate(periods) #bench_agent = Agent.BS_Agent_Gauss(1, Sigma, TS, Mu) elif demand_type == "Gaussian": demand= Demand.Gaussian_Demand(Mu, Sigma, min_value = 0, max_value = 100) #demand = Demand.Gaussian_Demand(global_variables[i]['Mu'],global_variables[i]['Sigma'],global_variables[i]['Min'],global_variables[i]['Max']) elif demand_type =="Uniform": demand = Demand.Uniform_Demand(Mu ,Mu,Step = 1) elif demand_type == "Growingseasonal": demand = Demand.Growing_Seasonal_Demand(1,[Mu*0.5,Mu* 0.8,Mu*0.7,Mu*0.9,Mu,Mu,Mu * 0.9,Mu*1.2,Mu,Mu*1.1,Mu*1.5,Mu*2], Sigma) elif demand_type == "Mixedseasonal": demand = Demand.Mixed_Saisonnalities_Demand(Mu, [1,1,2,2,2,3,4,4,2,1,1,4],[0.6,0.8,0.7,0.9], Sigma) elif demand_type == "Growthstable": demand = Demand.Growth_Stable_Demand(0, 1, Mu + 5, Sigma) else: print("Did not recognize demand type") break bench_agent = demand.bench_agent(global_variables[i]['pos'],global_variables[i]['TS'],periods) game_params = { 'client_demand':demand, 'lead_times':[ld.Constant_LeadTime(global_variables[i]['lt'][0]), ld.Constant_LeadTime(global_variables[i]['lt'][1]), ld.Constant_LeadTime(global_variables[i]['lt'][2]), ld.Constant_LeadTime(global_variables[i]['lt'][3])], 'AI_possible_actions': np.arange(-10,10), 'm' : global_variables[i]['m'], 'shortage_cost':get_optimal_gaussian_SC(TS, Mu = Mu, Sigma= Sigma, lead_time=constant_ld), 'TS' : TS, 'holding_cost':1, 'initial_inventory':constant_ld * Mu + 2* Sigma, 'number_periods':periods, 'use_backorders':0, 'state_features':["IL" ,"d", "BO", "RS", "OO","t"], 'AI_DN':[10,10], # Not implemented yet 'comparison_agent' : bench_agent } ''' Alternatives to above to be more flexible { 'client_demand': demand, 'lead_times':(global_variables[i]['leadtimes'], global_variables[i]['leadtimes'], global_variables[i]['leadtimes'], global_variables[i]['leadtimes']), 'initial_inventory':global_variables[i]['leadtimes'].Mean*10, } Need to make changes to functions that creates the dictionary list ''' list_agents = ['BS20','BS20', 'BS20' , 'BS20'] list_agents[global_variables[i]['pos']] = 'DQN' agents = generate_agents(list_agents, game_params) trainer = Tr.Trainer(agents, game_params) comparator = trainer.generate_comparator(min_BS_level = 5, max_BS_level = 20) trainer.train2(400) AI_Agent = trainer.best_AI_agent #.get_AI_agent() AI_Agent.label = 'best DQN' comparator.update_AI_Agents([trainer.best_AI_agent, trainer.get_AI_agent()]) comparator.launch_comparison() comparator.histograms() comparator.one_game_results([trainer.get_AI_agent()]) importlib.reload(Saver) saver = Saver.Saver(path) saver.clean_results_folder() saver.save(trainer)