Anonymous avatar Anonymous committed 0cab164

lamg_example -> lamg_example_networkx

Comments (0)

Files changed (2)

src/example/lamg_example.py

-'''
----------------------------------------------------------------------
-
-@author: Christian Staudt (christian.staudt @ ira.uka.de)
-
-Copyright (c) 2012, Christian Staudt
-Karlsruhe Institute of Technology
-
-Original LAMG MATLAB Implementation: Copyright (c) 2011, Oren E. Livne
-
-
-    This file is part of LAMG-Python.
-
-    LAMG-Python is free software: you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation, either version 3 of the License, or
-    (at your option) any later version.
-
-    LAMG-Python is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with LAMG-Python.  If not, see <http://www.gnu.org/licenses/>.
-'''
-
-import networkx
-import pycallgraph
-import os
-import logging
-import datetime
-
-
-from lamg.lin import factory
-from mat import lab
-import mat.util
-from aux import stopwatch
-from graph import api as graphapi
-
-
-if __name__ == '__main__':
-    
-    def main(graphType=None, graphFile=None, saveGraph=True):
-        """
-        LAMG example main function
-        """
-    
-        # Set Log Level here
-        logging.basicConfig(level=logging.DEBUG)
-        
-        # CALL GRAPH
-        os.environ["PATH"] += ":/usr/local/bin"
-        
-        solve = True    # turn on solve phase
-        
-        if graphFile:
-            G_ = networkx.read_gpickle(graphFile)
-        else:
-            # TODO: modularize this
-            # create a graph laplacian
-            print("Setting up Problem")
-            # n must be greater than options.maxDirectSolverSize (= 200)
-            if graphType is "erdos_renyi":
-                G_ = networkx.generators.random_graphs.erdos_renyi_graph(250, 0.005)
-            elif graphType is "barabasi_albert":
-                G_ = networkx.generators.random_graphs.barabasi_albert_graph(250, 2)
-            else:
-                raise Exception("unknown graph type: %s" % graphType)
-
-        if (saveGraph):
-            networkx.write_gpickle(G_, "../../data/input/graph/%s.gpickle" % datetime.datetime.now())
-        
-        G = graphapi.GraphAdapter.newInstanceFromNetworkXGraph(G_)
-    
-        #pycallgraph.start_trace() # CALL GRAPH TRACE
-        
-        solverLamg = factory.Solvers.newSolver("lamg", randomSeed=1)
-        
-        setup = solverLamg.setup("graph", G)
-        
-        if (solve):
-            A = setup.level[0].A
-            b = lab.rand(lab.size(A, 1), 1)
-            b = b - lab.mean(b)
-            logging.getLogger("lamg.lin.api.AcfComputer").setLevel(logging.DEBUG)
-            print("Solving A*x=b\n")
-            timer = stopwatch.Timer()
-            (x, success, errorNormHistory, details) = solverLamg.solve(setup, b, "errorReductionTol", 1e-8)
-            
-            tSolve = timer.stop()
-            logging.getLogger("lamg.lin.api.AcfComputer").setLevel(logging.INFO)
-            print("----------------------------------------------------------\n")
-            
-        # Display statistics
-        print(setup)
-        # TODO: ... display statistics
-        #pycallgraph.make_dot_graph('test.png')
-
-
-    # program starts here
-    graphDataPrefix = "../../data/input/graph/"
-    graphFileName = "BA(250,2)-nonsingular.gpickle"
-    main(graphFile="%s/%s" % (graphDataPrefix, graphFileName))
-    #main(graphType="barabasi_albert")   

src/example/lamg_example_networkx.py

+'''
+---------------------------------------------------------------------
+
+@author: Christian Staudt (christian.staudt @ ira.uka.de)
+
+Copyright (c) 2012, Christian Staudt
+Karlsruhe Institute of Technology
+
+Original LAMG MATLAB Implementation: Copyright (c) 2011, Oren E. Livne
+
+
+    This file is part of LAMG-Python.
+
+    LAMG-Python is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    LAMG-Python is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with LAMG-Python.  If not, see <http://www.gnu.org/licenses/>.
+'''
+
+import networkx
+import pycallgraph
+import os
+import logging
+import datetime
+
+
+from lamg.lin import factory
+from mat import lab
+import mat.util
+from aux import stopwatch
+from graph import api as graphapi
+
+
+if __name__ == '__main__':
+    
+    def main(graphType=None, graphFile=None, saveGraph=True):
+        """
+        LAMG example main function
+        """
+    
+        # Set Log Level here
+        logging.basicConfig(level=logging.DEBUG)
+        
+        # CALL GRAPH
+        os.environ["PATH"] += ":/usr/local/bin"
+        
+        solve = True    # turn on solve phase
+        
+        if graphFile:
+            G_ = networkx.read_gpickle(graphFile)
+        else:
+            # TODO: modularize this
+            # create a graph laplacian
+            print("Setting up Problem")
+            # n must be greater than options.maxDirectSolverSize (= 200)
+            if graphType is "erdos_renyi":
+                G_ = networkx.generators.random_graphs.erdos_renyi_graph(250, 0.005)
+            elif graphType is "barabasi_albert":
+                G_ = networkx.generators.random_graphs.barabasi_albert_graph(250, 2)
+            else:
+                raise Exception("unknown graph type: %s" % graphType)
+
+        if (saveGraph):
+            networkx.write_gpickle(G_, "../../data/input/graph/%s.gpickle" % datetime.datetime.now())
+        
+        G = graphapi.GraphAdapter.newInstanceFromNetworkXGraph(G_)
+    
+        #pycallgraph.start_trace() # CALL GRAPH TRACE
+        
+        solverLamg = factory.Solvers.newSolver("lamg", randomSeed=1)
+        
+        setup = solverLamg.setup("graph", G)
+        
+        if (solve):
+            A = setup.level[0].A
+            b = lab.rand(lab.size(A, 1), 1)
+            b = b - lab.mean(b)
+            logging.getLogger("lamg.lin.api.AcfComputer").setLevel(logging.DEBUG)
+            print("Solving A*x=b\n")
+            timer = stopwatch.Timer()
+            (x, success, errorNormHistory, details) = solverLamg.solve(setup, b, "errorReductionTol", 1e-8)
+            
+            tSolve = timer.stop()
+            logging.getLogger("lamg.lin.api.AcfComputer").setLevel(logging.INFO)
+            print("----------------------------------------------------------\n")
+            
+        # Display statistics
+        print(setup)
+        # TODO: ... display statistics
+        #pycallgraph.make_dot_graph('test.png')
+
+
+    # program starts here
+    graphDataPrefix = "../../data/input/graph/"
+    graphFileName = "BA(250,2)-nonsingular.gpickle"
+    main(graphFile="%s/%s" % (graphDataPrefix, graphFileName))
+    #main(graphType="barabasi_albert")   
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.