test_matcher.py :  » Development » Frowns » frowns » extensions » vflib » NetworkGraph » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Development » Frowns 
Frowns » frowns » extensions » vflib » NetworkGraph » test_matcher.py
from topology import *

# Example code
network_nodes = [
    'darkstar.wi.mit.edu',
    'fang.harvard.edu',
    'www.wi.mit.edu'
    ]

network_cables = [ ('t1', 'darkstar.wi.mit.edu', 'fang.harvard.edu'),
                   ('t3', 'fang.harvard.edu', 'www.wi.mit.edu'),
                   ('10base2', 'www.wi.mit.edu', 'darkstar.wi.mit.edu')]

# network is the original graph
# the example will match the network against it self
# and remove the matched nodes from the original network.
network = topology_to_network(network_nodes, network_cables)

#####################################################
# make a couple of clones to play with later
network1 = network.clone()

# This is an independed graph, the nodes and edges are different!
# they are not the same objects!
for node in network.nodes:
    assert network1.has_node(node) == 0

# although they are equivalent to each other
for node1, node2 in zip(network.nodes, network1.nodes):
    assert node1 == node2

#####################################################
# dump the toplogy
network.dump()

print
# make the matching graph
matcher = network.to_matcher()

# generate a graph to be matched against
graph = network.to_graph()

#####################################################
# collect all the results
match =  matcher.match(graph)
print "number of results", len(match)
for nodes, edges in match:
    for edge in edges:
        print '\t', edge, edge.nodes
    print

#####################################################
# now collect the unique results
umatch = matcher.umatch(graph)
nodes, edges = umatch[0]
print "number of unique results", len(umatch)

#####################################################
# remove the matched edges

partialClone = None
for nodes, edges in umatch:
    for edge in edges:
        print '\t', edge, edge.nodes
    print

    # try the partial cloning procedure
    # we'll just do this for the first match
    if partialClone is None:
        partialClone = network.clone(ignoreNodes=nodes,
                                     ignoreEdges=edges)

#####################################################
# let's check the nodes and edges of the graph
# the network topology should be empty
print "Should not be modified"
network.dump()
print

print "partial clone should be empty"
partialClone.dump()
print

print "original clone should be the original network"
network1.dump()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.