-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraph.py
54 lines (40 loc) · 1.03 KB
/
Graph.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from abc import ABC, abstractmethod
class Domain:
def __init__(self, values):
self.values = tuple(values)
def __hash__(self):
return hash(self.values)
def __eq__(self, other):
return (
self.__class__ == other.__class__ and
self.values == other.values
)
class Potential(ABC):
def __init__(self):
pass
@abstractmethod
def get(self, parameters):
pass
class RV:
def __init__(self, domain, value=None):
self.domain = domain
self.value = value
self.nb = []
class F:
def __init__(self, potential, nb=None):
self.potential = potential
if nb is None:
self.nb = []
else:
self.nb = nb
class Graph:
def __init__(self, rvs, factors):
self.rvs = rvs
self.factors = factors
self.init_nb()
def init_nb(self):
for rv in self.rvs:
rv.nb = []
for f in self.factors:
for rv in f.nb:
rv.nb.append(f)