Advertisement
Guest User

Untitled

a guest
May 29th, 2016
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.38 KB | None | 0 0
  1. def computeActionFromValues(self, state):
  2.         """
  3.          The policy is the best action in the given state
  4.          according to the values currently stored in self.values.
  5.  
  6.          You may break ties any way you see fit.  Note that if
  7.          there are no legal actions, which is the case at the
  8.          terminal state, you should return None.
  9.        """
  10.  
  11.         if self.mdp.isTerminal(state):
  12.                 return None
  13.  
  14.         # lista tuple-ova (akcija, vrijednost iduceg stanja)
  15.         vrijednostiStanjaZaAkcije = []
  16.         #print "stanje %s" % (state,)
  17.         for action in self.mdp.getPossibleActions(state):
  18.             # buduci da racunam vrijednost stanja za navedenu akciju
  19.             # uzimam najvjerojatniji prijelaz za akciju predanu
  20.             # u mdp.getTransitionStatesAndProbes
  21.             possibleNextStates = self.mdp.getTransitionStatesAndProbs(state,action)
  22.             #print "za akciju %s" % (action,)
  23.             #print "moguca su iduca stanja s vjerojatnostima: %s" % (possibleNextStates,)
  24.             nextStateTuple = max(possibleNextStates,key=lambda x:x[1])
  25.             nextState = nextStateTuple[0]
  26.             vrijednostiStanjaZaAkcije.append((action,self.getValue(nextState)))
  27.  
  28.         trazenaAkcijaTuple = max(vrijednostiStanjaZaAkcije,key=lambda x:x[1])
  29.         # tuple je (akcija, vrijednost)
  30.         return trazenaAkcijaTuple[0]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement