python - User Defined Types as Dictionary Keys -
I've been struggling with the concept of hash tables and dictionaries over the last few days and could not find the right solution for my problem I hope you will forgive me for your initial (and perhaps repetitive) questions and to spend time answering me
The classic GridWorld MDP problem is my "world" as part of the problem but this is not a problem here) I have made various examples of the I have created several states with the following code, failing in many other options, such as dictionaries, sets and sample categories): where class is defined by: In my code later I want to assign each state to an attribute Where Any comments would be greatly appreciated thanks. Note: I know about the elaborate efforts of explanation (for example, but unfortunately I failed to work them and I had to ask more explanation. < p> This is a Planner graph and where each node can be located and indexed with the matrix. Can: You must first empty each state, because you can not reference an object yet not created. In the code: state , each of them A unique and described tuple is
(row, column) . My question is how can I handle these examples and how to reference it.
To be more specific ...
class state: def __init __ (self, Line, color): self.row = line self.col = col def __hash __ ): Return hash ((self.row, self.col)) def __eq__ (self, other): return (Swynko == Anykro) & amp; (Self.col == Other. Col) # __hash__ and __eq__ are here because I know they want it, # yet I do not know how to use them. # I believe that there really is a real question ...
neighbors I'm a list that tells you about the real state on the grid. By "real" I mean that they are not copies of states or represent some of the states, but states themselves. Below you can find your non-white-eye-view-implementation:
def add_neighbbs (self): if self.row == 0: if self.col == 0: self Neibers = [(0, 1), (1, 0)] Elif himself. Col == 1: self Neibersbus = [(0, 0), (0, 2)] Alief himself.col == 2: self Neibbers = [(0, 1), (1, 2), (0, 3)] aliff itself. Col == 3: self. Neibersbus = [[(0, 2), (1, 3)] Alief Self .3 == 1: If self.col == 0: Self. Nehubas = [(0, 0), (2, 0)] Elif himself. Col == 1: self Nehbus = [] # Pitt, N / A Elif himself. Col == 2: Self. Neibbers = [(0, 2), (1, 3), (2, 2)] Elif himself. Col == 3: self. Neibersbus = [(0, 3), (1, 2), (2, 3)] Elif himself.O == 2: If self.col == 0: self Neibers = [(1, 0), (2, 1)] Elif himself == 1: Self. Nehubus = [(2, 0), (2, 2)] Elif himself. Col == 2: self. Neibersbus = [(2, 1), (1, 2), (2, 3)] Elif himself. Col == 3: self Despicable = [(2, 2), (1, 3)]
This definition of neighbors
s To call, but this is not a beautiful sight and I do not see how tasty I'm:
def add_neighbbs (self): if self.row == 0: if self .col == 0: self. Nehubas = [State ((0, 1)), State ((1, 0))] Elif himself. Col == 1: Self. Nehbus = [State ((, 0, 0)), State ((0, 2))] Elif himself == 2: Self. Nehusha = [State ((0, 1)), State ((1, 2)), State ((0, 3) etc ...
state (R.C.C)) is Actual State (or should I say context of the state) is called repeatedly.
# 1. Backing index table = {} # 2. Each state is empty table [(0, 0)] = state (0, 0) Table [(0, 1)] = State (0, 1) Table [(1, 0)] = State (1, 0) Table [(1, 1)] = State (1, 1) # .. .3. Start each state. Table [(0, 0)] Start () table [(0, 1)]. Initialize () # ... class state: def start (self): if ...: # self.neighs is a list of states. ([A, B]], table [(P, Q)]]
Comments
Post a Comment