@@ -22,13 +22,14 @@ def __init__(self):
22
22
"""Our constructor for the Graph class.
23
23
24
24
Each graph should store a container of all the nodes in the graph.
25
- The container should be a dict that maps the specific state of the
26
- Markov chain to the specific instantiation of the Vertex that
25
+ The container should be a dict that maps the specific data of a
26
+ vertex to the specific instantiation of the Vertex that
27
27
encapsulates that state
28
28
29
29
TODO: Make sure to incorporate the empty graph case.
30
30
"""
31
- # Our container of all the vertices in this Graph
31
+ # Our container of all the vertices in this Graph, this dictionary
32
+ # should map data to the vertices that encapsulate the data
32
33
self ._vertices = {}
33
34
34
35
@property
@@ -38,35 +39,38 @@ def vertices(self):
38
39
"""
39
40
return frozenset (self ._vertices .keys ())
40
41
41
- def add_vertex (self , state ):
42
+ def add_vertex (self , data ):
42
43
"""Method to add another Vertex to this Graph. Simply store a newly
43
44
instantiated Vertex in our container
44
45
"""
45
- # TODO: make sure that the state can be any value?
46
- # Create a new Vertex and add the (k, v) pair of mapping state to
47
- # actual Vertex to our Graph
48
- self ._vertices [state ] = Vertex (state )
49
-
50
- def __contains__ (self , state ):
51
- """Method overriding. Make sure that we can quickly check to see if
52
- a given state is contained in the graph
46
+ if data is None :
47
+ raise TypeError ("Error: data must be non-null" )
48
+ else :
49
+ # Create a new Vertex and add the (k, v) pair of mapping data to
50
+ # actual Vertex to our Graph
51
+ self ._vertices [data ] = Vertex (data )
52
+
53
+ def __contains__ (self , data ):
54
+ """Contains method overriding. Make sure that we can quickly check to
55
+ see if a given data piece is contained in the graph
53
56
"""
54
- return state in self ._vertices .keys ()
57
+ return data in self ._vertices .keys ()
55
58
56
- def __getitem__ (self , state ):
57
- """Contains method for our Graph class . Make sure that we can quickly
58
- access any given state in our graph
59
+ def __getitem__ (self , data ):
60
+ """Get method overriding . Make sure that we can quickly
61
+ access any given Vertex in our graph
59
62
"""
60
- # attempt to hash the given state to return its corresponding Vertex
63
+ # attempt to hash the given data to return its corresponding Vertex
61
64
try :
62
- return self ._vertices [state ]
65
+ return self ._vertices [data ]
63
66
except ValueError :
64
- raise KeyError (f"State { repr (state )} is not in the Graph" )
67
+ raise KeyError (f"State { repr (data )} is not in the Graph" )
65
68
66
69
def compute_probabilities (self ):
67
70
"""Method to traverse our graph entirely and compute the
68
71
probabilities of each of the paths
69
72
"""
73
+ # TODO: KEEP GRAPH CONTEXT MAN. SIMPLE AND GENERIC, NO COMPUTATION HERE
70
74
raise NotImplementedError ()
71
75
72
76
@@ -78,27 +82,26 @@ def compute_probabilities(self):
78
82
79
83
80
84
class Vertex :
81
- def __init__ (self , state ):
85
+ def __init__ (self , data ):
82
86
"""Our constructor for our Vertex class.
83
87
84
- Vertices should contain the current state of the Markov chain in which
85
- we are in as well of a storage container of all the outgoing edges that
86
- are directed from this Vertex to another Vertex
88
+ Vertices should contain data as well of a storage container of all the
89
+ outgoing edges that are directed from this Vertex to another Vertex
87
90
"""
88
91
# Our current state of history in regards to
89
- self ._state = state
90
- # Our container for possible next states which is encapsulated by
91
- # dictionary mappings of tokens to Edges
92
+ self ._data = data
93
+ # Our container for edges that leave this vertex which is
94
+ # encapsulated by dictionary mappings of tokens to Edges
92
95
self ._outgoing_edges = {}
93
96
# TODO: may need to add another dict for fast lookups that maps Edge
94
97
# objects to probabilities
95
98
96
99
@property
97
- def state (self ):
100
+ def data (self ):
98
101
"""Getter for Vertex that returns the current state (differentiates
99
102
vertices from one another).
100
103
"""
101
- return self ._state
104
+ return self ._data
102
105
103
106
@property
104
107
def outgoing_edges (self ):
0 commit comments