class gamble: def __init__(self,name,consequence,probability): self.name = name self.consequence = consequence self.probability = probability def showName(self,NameAlt): NameAlt = NameAlt + [self.name] return NameAlt def showPayoff(self,Pay): Pay = Pay + [self.consequence] return Pay def showProb(self,Prob): Prob = Prob + [self.probability] return Prob class automaton: def __init__(self,alternatives,probabilities,expectations,chosen): self.alternatives = alternatives self.probabilities = probabilities self.expectations = expectations self.chosen = chosen def lookAt(self,Pay,Prob): for i in range(0,len(Pay)): self.alternatives = self.alternatives + [Pay[i]] for j in range(0,len(Prob)): self.probabilities = self.probabilities + [Prob[j]] def formExpect(self): for i in range(0,len(self.alternatives)): A = self.alternatives[i] Prob = self.probabilities[i] Weigh = [] for j in range(0,len(A)): Weigh = Weigh + [A[j] * Prob[j]] self.expectations = self.expectations + [sum(Weigh)] def choose(self,NameAlt): for i in range(0,len(NameAlt)): print "Alternative:", NameAlt[i], "| Expected Payoff:", self.expectations[i] M = max(self.expectations) for j in range(0,len(self.expectations)): if self.expectations[j] == M: self.choice = NameAlt[j] self.chosen = self.chosen + [NameAlt[j]] print("\nThe chosen alternatives are:") for k in range(0,len(self.chosen)): print self.chosen[k] print "\nWith associated expected payoff: "+str(M) ######################################################################################################################## Continua = gamble('Continua',(10,-9),(0.3,0.4)) ParaNegocia = gamble('ParaNegocia',(8,-10),(0.2,0.6)) ParaNaoNegocia = gamble('ParaNaoNegocia',(10,-10),(0.5,0.6)) Alternativas = [Continua, ParaNegocia, ParaNaoNegocia] Pay = [] Prob = [] NameAlt = [] for i in range(0,len(Alternativas)): NameAlt = Alternativas[i].showName(NameAlt) Pay = Alternativas[i].showPayoff(Pay) Prob = Alternativas[i].showProb(Prob) ISIS = automaton([],[],[],[]) ISIS.lookAt(Pay,Prob) ISIS.formExpect() ISIS.choose(NameAlt) # Adaptado de: ####Gonçalves, Carlos Pedro (2015), “Lectures on Artificial Intelligence for Decision Making: Decision Support Automaton”, http://pythonfiddle.com/decision-making-automaton/, ISCSP, Universidade de Lisboa. ####Gonçalves, Carlos Pedro (2015), "Autómato de Suporte à Tomada de Decisão Estratégica" - material pedagógico de suporte à matéria de inteligência artificial para a decisão estratégica”, http://pythonfiddle.com/automato-de-suporte-a-tomada-de-decisao/, ISCSP, Universidade de Lisboa. ####Gonçalves, Carlos Pedro (2015), “"Autómato de Suporte à Tomada de Decisão Estratégica" – material pedagógico de suporte à matéria de inteligência artificial para a decisão estratégica (Parte II)” http://pythonfiddle.com/parte-ii-automato-de-suporte-a-tomada-de-decisao/, ISCSP, Universidade de Lisboa.
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question