#NEWLINE# def stateInTheMiddleOfGrid( self , s ) : #NEWLINE# #INDENT# '\n        Accepts a continuous state *s*, bins it into the discretized domain,\n        and returns the state of the nearest gridpoint.\n        Essentially, we snap *s* to the nearest gridpoint and return that\n        gridpoint state.\n        For continuous MDPs this plays a major rule in improving the speed\n        through caching of next samples.\n\n        :param s: The given state\n\n        :return: The nearest state *s* which is captured by the discretization.\n        ' #NEWLINE# s_normalized = s . copy ( ) #NEWLINE# for d in xrange ( self . domain . state_space_dims ) : #NEWLINE# #INDENT# s_normalized [ d ] = closestDiscretization ( s [ d ] , self . bins_per_dim [ d ] , self . domain . statespace_limits [ s , : ] ) #NEWLINE# #UNINDENT# return s_normalized