Skip to content
Snippets Groups Projects
Commit 73f65332 authored by Lukas Kettenbach's avatar Lukas Kettenbach
Browse files

NetworkX is now dep! install it first

parent ee11637f
No related branches found
No related tags found
No related merge requests found
import sys
sys.path.append("lib/networkx-1.7-py2.7.egg")
import networkx as nx
from core.Node import Node
......@@ -117,7 +116,7 @@ class BayesNet(object):
def clear(self):
'''Remove all nodes and edges from the graph.
This also removes the name, and all graph, node, and edge attributes.'''
This also removes the name, and all graph, node and edge attributes.'''
self.graph.clear()
self.node_lookup.clear()
......
......@@ -8,3 +8,15 @@ class DynamicBayesNet(BayesNet):
def __init__(self):
super(DynamicBayesNet, self).__init__()
def add_edge(self, node_from, node_to, arc=False):
'''Add an directed edge to the graph.
Keyword arguments:
node_from -- from node
node_to -- to node
arc -- is this edge a temporal conditional dependency (default: False)
'''
super().add_edge(node_from, node_to)
# Adding an edge that already exists updates the edge data.
self.graph.add_edge(node_from, node_to, arc=arc)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from core.BayesNet import *
from reasoning.DiscreteNode import DiscreteNode
bn = BayesNet()
burglary = DiscreteNode("Burglary", ["Intruder", "Safe"])
alarm = DiscreteNode("Alarm", ["Ringing", "Silent", "Kaputt"])
earthquake = DiscreteNode("Earthquake", ["Shaking", "Calm"])
john_calls = DiscreteNode("John calls", ["Calling", "Not Calling"])
mary_calls = DiscreteNode("Mary calls", ["Calling", "Not Calling"])
bn.add_node(burglary)
bn.add_node(alarm)
bn.add_node(earthquake)
bn.add_node(john_calls)
bn.add_node(mary_calls)
bn.add_edge(burglary, alarm)
bn.add_edge(earthquake, alarm)
bn.add_edge(alarm, john_calls)
bn.add_edge(alarm, mary_calls)
bn.draw()
# -*- coding: utf-8 -*-
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment