Пример #1
0
    def test_copy(self):
        original_numbers = self._get_original_numbers()

        simple = Graph(name='simple')
        simple.add_node(x=0.0, y=0.0, name='A')
        simple.add_node(x=0.0, y=1.0, name='B')
        simple.connect('A', 'B', name="I", directional=False)
        simple_copy = simple.copy(0.0, 0.0)

        nodes = [('A', Node(0.0, 0.0)), ('B', Node(0.0, 1.0))]
        edges = [('I', Edge('A', 'B', directional=False))]
        numbers = (
            2,  # anchored_nodes
            1,  # anchored_edges
            2,  # unique_nodes
            1,  # unique_anchored_edges
            0,  # unique_unanchored_edges
            0,  # subgraphs
            0  # anchored_subgraphs
        )
        self._check_graph(simple_copy, 'simple(copy)', 'A', True, nodes, edges,
                          numbers)
        self._check_numbers(original_numbers, 6, 3, 2)

        for node, node_copy in zip(simple.nodes.values(),
                                   simple_copy.nodes.values()):
            self.assertEqual(node, node_copy)
            self.assertIsNot(node, node_copy)
        for edge, edge_copy in zip(simple.edges.values(),
                                   simple_copy.edges.values()):
            self.assertEqual(edge, edge_copy)
            self.assertIsNot(edge, edge_copy)
Пример #2
0
    def test_subgraphing(self):
        original_numbers = self._get_original_numbers()

        simple = Graph(name='simple')
        simple.add_node(x=0.0, y=0.0, name='A')
        simple.add_node(x=0.0, y=1.0, name='B')
        simple.connect('A', 'B', name="I", directional=False)
        simple_copy = simple.copy(1.0, 0.0)
        super_graph = Graph(name='super_graph', graphs=[simple, simple_copy])
        super_graph.connect('simple:A',
                            'simple(copy):B',
                            name='II',
                            directional=True)

        nodes = [('simple:A', Node(0.0, 0.0)), ('simple:B', Node(0.0, 1.0)),
                 ('simple(copy):A', Node(1.0, 0.0)),
                 ('simple(copy):B', Node(1.0, 1.0))]
        edges = [('simple:I', Edge('simple:A', 'simple:B', directional=False)),
                 ('simple(copy):I',
                  Edge('simple(copy):A', 'simple(copy):B', directional=False)),
                 ('II', Edge('simple:A', 'simple(copy):B', directional=True))]
        numbers = (
            4,  # anchored_nodes
            3,  # anchored_edges
            0,  # unique_nodes
            1,  # unique_anchored_edges
            0,  # unique_unanchored_edges
            2,  # subgraphs
            2  # anchored_subgraphs
        )
        self._check_graph(super_graph, 'super_graph', 'simple:A', True, nodes,
                          edges, numbers)
        self._check_numbers(original_numbers, 8, 6, 3)
Пример #3
0
  def test_subgraphing(self):
    original_numbers = self._get_original_numbers()

    simple = Graph(name = 'simple')
    simple.add_node(x=0.0,   y=0.0,   name = 'A')
    simple.add_node(x=0.0,   y=1.0,   name = 'B')
    simple.connect('A', 'B', name = "I", directional = False)
    simple_copy = simple.copy(1.0, 0.0)
    super_graph = Graph(name = 'super_graph', graphs = [simple, simple_copy])
    super_graph.connect('simple:A', 'simple(copy):B', name = 'II', directional = True)

    nodes = [('simple:A', Node(0.0, 0.0)), ('simple:B', Node(0.0, 1.0)),
             ('simple(copy):A', Node(1.0, 0.0)), ('simple(copy):B', Node(1.0, 1.0))]
    edges = [('simple:I', Edge('simple:A', 'simple:B', directional = False)),
             ('simple(copy):I', Edge('simple(copy):A', 'simple(copy):B', directional = False)),
             ('II', Edge('simple:A', 'simple(copy):B', directional = True))]
    numbers = (4, # anchored_nodes
               3, # anchored_edges
               0, # unique_nodes
               1, # unique_anchored_edges
               0, # unique_unanchored_edges
               2, # subgraphs
               2  # anchored_subgraphs
              )
    self._check_graph(super_graph, 'super_graph', 'simple:A', True, nodes, edges, numbers)
    self._check_numbers(original_numbers, 8, 6, 3)
Пример #4
0
  def test_copy(self):
    original_numbers = self._get_original_numbers()

    simple = Graph(name = 'simple')
    simple.add_node(x=0.0,   y=0.0,   name = 'A')
    simple.add_node(x=0.0,   y=1.0,   name = 'B')
    simple.connect('A', 'B', name = "I", directional = False)
    simple_copy = simple.copy(0.0, 0.0)

    nodes = [('A', Node(0.0, 0.0)), ('B', Node(0.0, 1.0))]
    edges = [('I', Edge('A', 'B', directional = False))]
    numbers = (2, # anchored_nodes
               1, # anchored_edges
               2, # unique_nodes
               1, # unique_anchored_edges
               0, # unique_unanchored_edges
               0, # subgraphs
               0  # anchored_subgraphs
              )
    self._check_graph(simple_copy, 'simple(copy)', 'A', True, nodes, edges, numbers)
    self._check_numbers(original_numbers, 6, 3, 2)

    for node, node_copy in zip(simple.nodes.values(), simple_copy.nodes.values()):
      self.assertEqual(node, node_copy)
      self.assertIsNot(node, node_copy)
    for edge, edge_copy in zip(simple.edges.values(), simple_copy.edges.values()):
      self.assertEqual(edge, edge_copy)
      self.assertIsNot(edge, edge_copy)
Пример #5
0
  def test_copying_with_subgraphing(self):
    original_numbers = self._get_original_numbers()

    pipe1 = Graph(name = 'pipe1')
    pipe1.add_node(x=0.0, y=0.0, name = 'inlet')
    pipe1.add_node(1.0, 0.0, name = 'outlet')
    pipe2 = pipe1.copy(x=1.5, y=0.0, name = 'pipe2')
    long_pipe1 = Graph(name = 'long_pipe1', graphs = [pipe1, pipe2])
    long_pipe1.connect('pipe1:outlet', 'pipe2:inlet', name = "junction")
    long_pipe1.connect('pipe1:inlet', 'pipe1:outlet', name = "internal-connection1", directional = False)
    long_pipe1.connect('pipe2:inlet', 'pipe2:outlet', name = "internal-connection2", directional = False)
    long_pipe2 = long_pipe1.copy(x=2.5, y=1.0, name = 'long_pipe2')
    long_pipe2.reflect(axis = 'y')
    circuit = Graph(name = 'circuit', graphs = [long_pipe1, long_pipe2])
    circuit.connect('long_pipe1:pipe2:outlet', 'long_pipe2:pipe1:inlet', name = "junction1")
    circuit.connect('long_pipe2:pipe2:outlet', 'long_pipe1:pipe1:inlet', name = "junction2")

    nodes = [('long_pipe1:pipe1:inlet',  Node(0.0, 0.0)),
             ('long_pipe1:pipe1:outlet', Node(1.0, 0.0)),
             ('long_pipe1:pipe2:inlet',  Node(1.5, 0.0)),
             ('long_pipe1:pipe2:outlet', Node(2.5, 0.0)),
             ('long_pipe2:pipe1:inlet',  Node(2.5, 1.0)),
             ('long_pipe2:pipe1:outlet', Node(1.5, 1.0)),
             ('long_pipe2:pipe2:inlet',  Node(1.0, 1.0)),
             ('long_pipe2:pipe2:outlet', Node(0.0, 1.0))]
    edges = [('long_pipe1:junction', Edge('long_pipe1:pipe1:outlet', 'long_pipe1:pipe2:inlet', directional = True)),
             ('long_pipe1:internal-connection1', Edge('long_pipe1:pipe1:inlet', 'long_pipe1:pipe1:outlet', directional = False)),
             ('long_pipe1:internal-connection2', Edge('long_pipe1:pipe2:inlet', 'long_pipe1:pipe2:outlet', directional = False)),
             ('long_pipe2:junction', Edge('long_pipe2:pipe1:outlet', 'long_pipe2:pipe2:inlet', directional = True)),
             ('long_pipe2:internal-connection1', Edge('long_pipe2:pipe1:inlet', 'long_pipe2:pipe1:outlet', directional = False)),
             ('long_pipe2:internal-connection2', Edge('long_pipe2:pipe2:inlet', 'long_pipe2:pipe2:outlet', directional = False)),
             ('junction1', Edge('long_pipe1:pipe2:outlet', 'long_pipe2:pipe1:inlet', directional = True)),
             ('junction2', Edge('long_pipe2:pipe2:outlet', 'long_pipe1:pipe1:inlet', directional = True))]
    numbers = (8, # anchored_nodes
               8, # anchored_edges
               0, # unique_nodes
               2, # unique_anchored_edges
               0, # unique_unanchored_edges
               2, # subgraphs
               2  # anchored_subgraphs
              )
    self._check_graph(circuit, 'circuit', 'long_pipe1:pipe1:inlet', True, nodes, edges, numbers)
    self._check_numbers(original_numbers, 16, 16, 7)
Пример #6
0
main = Graph(name = 'main')

main.add_node(x=0.0,   y=0.0,   name = 'A',   ll = 'bottom')
main.add_node(x=1.0,   y=0.0,   name = 'B',   ll = 'right')
main.add_node(x=1.0,   y=1.0,   name = 'C',   ll = 'top')
main.add_node(x=0.0,   y=1.0,   name = 'D',   ll = 'left')

main.connect('A', 'B', name = '1', ll = 'top', la = 0.0)
main.connect('B', 'C', name = '2', ll = 'top', la = 0.0)
main.connect('C', 'D', name = '3', ll = 'top', la = 0.0)
main.connect('D', 'A', name = '4', ll = 'top', la = 0.0)

main.anchor_graph()
print 'Nodes are anchored:', main.anchored
print main.general_info(), '\n'
print main

graphs = []
displacement = 3.0

for i in range(2):
  graphs.append( main.copy(i * displacement, 0.0) )
  graphs[-1].rotate(i * 45.0)

CAN = Canvas(border_thickness = 0.05, grid = True)
for graph in graphs:
  CAN.add_graph(graph)

CAN.draw(save_file = 'test.pdf', display = True, print_information = False)
Пример #7
0
main.add_node(x=0.0, y=0.0, name="A", ll="bottom")
main.add_node(x=1.0, y=0.0, name="B", ll="right")
main.add_node(x=1.0, y=1.0, name="C", ll="top")
main.add_node(x=0.0, y=1.0, name="D", ll="left")

main.connect("A", "B", name="1", ll="top", la=45.0, lp=1.0)
main.connect("B", "C", name="2", ll="top", la=45.0, lp=1.0)
main.connect("C", "D", name="3", ll="top", la=45.0, lp=1.0)
main.connect("D", "A", name="4", ll="top", la=45.0, lp=1.0)

main.anchor_graph()
print("Nodes are anchored:", main.anchored)
print(main.general_info(), "\n")
print(main)

graphs = []
graphs.append(main)

graphs.append(main.copy(-1.0, 0.0))
graphs[-1].reflect("y")

graphs.append(main.copy(0.0, -1.0))
graphs[-1].reflect("x")


CAN = Canvas(border_thickness=0.05, grid=True)
for graph in graphs:
    CAN.add_graph(graph)

CAN.draw(save_file="test.pdf", display=True, print_information=False)
Пример #8
0
main.add_node(x=0.0, y=0.0, name='A', ll='bottom')
main.add_node(x=1.0, y=0.0, name='B', ll='right')
main.add_node(x=1.0, y=1.0, name='C', ll='top')
main.add_node(x=0.0, y=1.0, name='D', ll='left')

main.connect('A', 'B', name='1', ll='top', la=45.0, lp=1.0)
main.connect('B', 'C', name='2', ll='top', la=45.0, lp=1.0)
main.connect('C', 'D', name='3', ll='top', la=45.0, lp=1.0)
main.connect('D', 'A', name='4', ll='top', la=45.0, lp=1.0)

main.anchor_graph()
print('Nodes are anchored:', main.anchored)
print(main.general_info(), '\n')
print(main)

graphs = []
graphs.append(main)

graphs.append(main.copy(-1.0, 0.0))
graphs[-1].reflect('y')

graphs.append(main.copy(0.0, -1.0))
graphs[-1].reflect('x')

CAN = Canvas(border_thickness=0.05, grid=True)
for graph in graphs:
    CAN.add_graph(graph)

CAN.draw(save_file='test.pdf', display=True, print_information=False)
Пример #9
0
    def test_copying_with_subgraphing(self):
        original_numbers = self._get_original_numbers()

        pipe1 = Graph(name='pipe1')
        pipe1.add_node(x=0.0, y=0.0, name='inlet')
        pipe1.add_node(1.0, 0.0, name='outlet')
        pipe2 = pipe1.copy(x=1.5, y=0.0, name='pipe2')
        long_pipe1 = Graph(name='long_pipe1', graphs=[pipe1, pipe2])
        long_pipe1.connect('pipe1:outlet', 'pipe2:inlet', name="junction")
        long_pipe1.connect('pipe1:inlet',
                           'pipe1:outlet',
                           name="internal-connection1",
                           directional=False)
        long_pipe1.connect('pipe2:inlet',
                           'pipe2:outlet',
                           name="internal-connection2",
                           directional=False)
        long_pipe2 = long_pipe1.copy(x=2.5, y=1.0, name='long_pipe2')
        long_pipe2.reflect(axis='y')
        circuit = Graph(name='circuit', graphs=[long_pipe1, long_pipe2])
        circuit.connect('long_pipe1:pipe2:outlet',
                        'long_pipe2:pipe1:inlet',
                        name="junction1")
        circuit.connect('long_pipe2:pipe2:outlet',
                        'long_pipe1:pipe1:inlet',
                        name="junction2")

        nodes = [('long_pipe1:pipe1:inlet', Node(0.0, 0.0)),
                 ('long_pipe1:pipe1:outlet', Node(1.0, 0.0)),
                 ('long_pipe1:pipe2:inlet', Node(1.5, 0.0)),
                 ('long_pipe1:pipe2:outlet', Node(2.5, 0.0)),
                 ('long_pipe2:pipe1:inlet', Node(2.5, 1.0)),
                 ('long_pipe2:pipe1:outlet', Node(1.5, 1.0)),
                 ('long_pipe2:pipe2:inlet', Node(1.0, 1.0)),
                 ('long_pipe2:pipe2:outlet', Node(0.0, 1.0))]
        edges = [('long_pipe1:junction',
                  Edge('long_pipe1:pipe1:outlet',
                       'long_pipe1:pipe2:inlet',
                       directional=True)),
                 ('long_pipe1:internal-connection1',
                  Edge('long_pipe1:pipe1:inlet',
                       'long_pipe1:pipe1:outlet',
                       directional=False)),
                 ('long_pipe1:internal-connection2',
                  Edge('long_pipe1:pipe2:inlet',
                       'long_pipe1:pipe2:outlet',
                       directional=False)),
                 ('long_pipe2:junction',
                  Edge('long_pipe2:pipe1:outlet',
                       'long_pipe2:pipe2:inlet',
                       directional=True)),
                 ('long_pipe2:internal-connection1',
                  Edge('long_pipe2:pipe1:inlet',
                       'long_pipe2:pipe1:outlet',
                       directional=False)),
                 ('long_pipe2:internal-connection2',
                  Edge('long_pipe2:pipe2:inlet',
                       'long_pipe2:pipe2:outlet',
                       directional=False)),
                 ('junction1',
                  Edge('long_pipe1:pipe2:outlet',
                       'long_pipe2:pipe1:inlet',
                       directional=True)),
                 ('junction2',
                  Edge('long_pipe2:pipe2:outlet',
                       'long_pipe1:pipe1:inlet',
                       directional=True))]
        numbers = (
            8,  # anchored_nodes
            8,  # anchored_edges
            0,  # unique_nodes
            2,  # unique_anchored_edges
            0,  # unique_unanchored_edges
            2,  # subgraphs
            2  # anchored_subgraphs
        )
        self._check_graph(circuit, 'circuit', 'long_pipe1:pipe1:inlet', True,
                          nodes, edges, numbers)
        self._check_numbers(original_numbers, 16, 16, 7)
Пример #10
0
from math import sqrt

component1 = Graph(name = 'component1')
component1.add_node(x=0.0,   y=0.0,   name = 'outlet',   ll = 'bottom')

component2 = Graph(name = 'component2')
component2.add_node(x=1.0,   y=1.0,   name = 'inlet',   ll = 'right')

junction = Graph(name = 'junction')
junction.add_node(x=1.0,   y=0.0,   name = 'node',   ll = 'bottom', draw = False)

system1 = Graph(name = 'system1', graphs = [component1, component2, junction])
system1.connect('component1:outlet', 'junction:node', dir = False, ll = 'top')
system1.connect('junction:node', 'component2:inlet',  dir = True,  ll = 'top')

system2 = system1.copy(2.0, 0.0, name = 'system2')
system2.rotate(45.0)

# -----

component1 = Graph(name = 'component1')
component1.add_node(x=0.0,   y=2.0,   name = 'outlet',   ll = 'bottom')

component2 = Graph(name = 'component2')
component2.add_node(x=1.5,   y=3.0,   name = 'inlet',   ll = 'right')

junction = Graph(name = 'junction')
junction.add_node(x=1.0,   y=2.0,   name = 'node',   ll = 'bottom', draw = False)

system3 = Graph(name = 'system3', graphs = [component1, component2, junction])
system3.connect('component1:outlet', 'junction:node', dir = False, ll = 'top')
Пример #11
0
from math import sqrt

component1 = Graph(name='component1')
component1.add_node(x=0.0, y=0.0, name='outlet', ll='bottom')

component2 = Graph(name='component2')
component2.add_node(x=1.0, y=1.0, name='inlet', ll='right')

junction = Graph(name='junction')
junction.add_node(x=1.0, y=0.0, name='node', ll='bottom', draw=False)

system1 = Graph(name='system1', graphs=[component1, component2, junction])
system1.connect('component1:outlet', 'junction:node', dir=False, ll='top')
system1.connect('junction:node', 'component2:inlet', dir=True, ll='top')

system2 = system1.copy(2.0, 0.0, name='system2')
system2.rotate(45.0)

# -----

component1 = Graph(name='component1')
component1.add_node(x=0.0, y=2.0, name='outlet', ll='bottom')

component2 = Graph(name='component2')
component2.add_node(x=1.5, y=3.0, name='inlet', ll='right')

junction = Graph(name='junction')
junction.add_node(x=1.0, y=2.0, name='node', ll='bottom', draw=False)

system3 = Graph(name='system3', graphs=[component1, component2, junction])
system3.connect('component1:outlet', 'junction:node', dir=False, ll='top')
Пример #12
0
from schematics import Graph
from schematics import Canvas
import matplotlib.pyplot as plt
from math import sqrt

main = Graph(name='main')

main.add_node(x=0.0, y=0.0, name='A', ll='bottom')
main.add_node(x=1.0, y=0.0, name='B', ll='right')

main.connect('A', 'B', name='1', ll='top', la=0.0, label_shift=0.75)

graphs = []
displacement = 3.0

for i in range(2):
    graphs.append(main.copy(i * displacement, 0.0))
    graphs[-1].rotate(i * 45.0)

main.connect('A', 'B', name='1', ll='bottom', la=0.0, label_shift=-0.75)
for i in range(2):
    graphs.append(main.copy(i * displacement, 2.0))
    graphs[-1].rotate(i * 45.0)

CAN = Canvas(border_thickness=0.05, grid=True)
for graph in graphs:
    CAN.add_graph(graph)

CAN.draw(save_file='test.pdf', display=True, print_information=False)
Пример #13
0
# ------------- pipe1

pipe1 = Graph(name = 'pipe1')

pipe1.add_node(x=0.0, y=0.0, name = 'inlet')
pipe1.add_node(1.0, 0.0, name = 'outlet')

# pipe1.connect('inlet', 'outlet', name = 'internal', directional = False)

pipe1.anchor = 'inlet'


# ------------- pipe2

pipe2 = pipe1.copy(x=1.5, y=0.0, name = 'pipe2')

pipe2.anchor = 'inlet'


# ------------- long_pipe1

long_pipe1 = Graph(name = 'long_pipe1', graphs = [pipe1, pipe2])

long_pipe1.connect('pipe1:outlet', 'pipe2:inlet', name = "junction", la = 0.0)
long_pipe1.connect('pipe1:inlet', 'pipe1:outlet', name = "internal-connection1", directional = False, la = 0.0)
long_pipe1.connect('pipe2:inlet', 'pipe2:outlet', name = "internal-connection2", directional = False, la = 0.0)


# ------------- long_pipe2