/[cvs]/nfo/python/scripts/sixdegrees/sixtest.py
ViewVC logotype

Diff of /nfo/python/scripts/sixdegrees/sixtest.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4 by joko, Wed Feb 6 03:14:58 2008 UTC revision 1.5 by joko, Wed Feb 6 22:59:39 2008 UTC
# Line 18  Line 18 
18  # along with this program.  If not, see <http://www.gnu.org/licenses/>.  # along with this program.  If not, see <http://www.gnu.org/licenses/>.
19    
20    
21    import sys
22  import random  import random
23  from sixdegrees import Graph, Node  from sixdegrees import Graph, Node
24    
25    
26  # maximum search depth (DLS limiter)  # maximum search depth (DLS limiter)
27  MAX_SEARCH_DEPTH = 5  MAX_SEARCH_DEPTH = 4
28    
29  # settings for random graph  # settings for random graph
30  RANDOM_MAX_NODES = 10  #RANDOM_MAX_NODES = 10
31  RANDOM_MAX_CHILDREN_PER_NODE = 5  #RANDOM_MAX_CHILDREN_PER_NODE = 5
32  #RANDOM_MAX_NODES = 1000  RANDOM_MAX_NODES = 10000
33  #RANDOM_MAX_CHILDREN_PER_NODE = 10  RANDOM_MAX_CHILDREN_PER_NODE = 20
34    
35    
36    ENABLE_PROFILING = False
37    ENABLE_JIT = True
38    
39    
40    if ENABLE_PROFILING:
41      import profile
42      from profile import Profile
43    
44    
45  def operateOnFixedGraph():  def operateOnFixedGraph():
# Line 59  def operateOnFixedGraph(): Line 69  def operateOnFixedGraph():
69    
70  def buildRandomGraph(graph):  def buildRandomGraph(graph):
71        
72      count = 0
73    for parent_id in range(1, RANDOM_MAX_NODES + 1):    for parent_id in range(1, RANDOM_MAX_NODES + 1):
74        count += 1
75        if count % 100 == 0:
76          sys.stderr.write('.')
77      for j in range(1, random.randint(1, RANDOM_MAX_CHILDREN_PER_NODE)):      for j in range(1, random.randint(1, RANDOM_MAX_CHILDREN_PER_NODE)):
78        child_id = random.randint(1, RANDOM_MAX_NODES)        child_id = random.randint(1, RANDOM_MAX_NODES)
79        graph.addRelation(parent_id, child_id)        graph.addRelation(parent_id, child_id)
80      sys.stderr.write("\n")
81    
82    """    """
83    RANDOM_MAX_NODES = 10    RANDOM_MAX_NODES = 10
# Line 80  def operateOnRandomGraph(): Line 95  def operateOnRandomGraph():
95    print '-' * 42    print '-' * 42
96    graph = Graph()    graph = Graph()
97    buildRandomGraph(graph)    buildRandomGraph(graph)
98    print graph    #print graph
99    
100    # 2. choose two random distinct nodes    # 2. choose two random distinct nodes
101    node1 = graph.getNode(random.choice(graph.index.keys()))    node1 = graph.getNode(random.choice(graph.index.keys()))
# Line 96  def findAllPaths(graph, source_node, tar Line 111  def findAllPaths(graph, source_node, tar
111    # 1. calculate paths    # 1. calculate paths
112    print '-' * 42    print '-' * 42
113    print "  Finding paths from %s to %s (depth=%s)" % (source_node.id, target_node.id, MAX_SEARCH_DEPTH)    print "  Finding paths from %s to %s (depth=%s)" % (source_node.id, target_node.id, MAX_SEARCH_DEPTH)
114      print "  Using JIT (Psyco):", bool(sys.modules.get('psyco'))
115    print '-' * 42    print '-' * 42
116    paths = graph.computePaths(source_node, target_node, MAX_SEARCH_DEPTH)  
117      """
118      def doCompute():
119        #global paths
120        paths = graph.computePaths(source_node, target_node, MAX_SEARCH_DEPTH)
121        return paths
122      """
123      
124      if ENABLE_PROFILING:
125        global paths
126        paths = []
127        p = Profile()
128        p.runcall(doCompute)
129        p.print_stats()
130      else:
131        paths = graph.computePaths(source_node, target_node, MAX_SEARCH_DEPTH)
132      
133      #p.create_stats()
134      #a = p.dump_stats()
135      #print a
136      #print dir(p)
137      #for key, value in p.timings.iteritems():
138      #  print '%s: %s' % (key, value)
139        
140    # 2. output paths    # 2. output paths
141    #print paths    #print paths
# Line 115  def main(): Line 153  def main():
153        
154    
155  if __name__ == '__main__':  if __name__ == '__main__':
156      if ENABLE_JIT:
157        # Import Psyco if available
158        try:
159          import psyco
160          psyco.log()
161          psyco.full()
162        except ImportError:
163          pass
164    main()    main()

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed