<s> from nose . tools import * <EOL> from nose import SkipTest <EOL> import networkx <EOL> from nose . plugins . attrib import attr <EOL> from networkx import edge_current_flow_betweenness_centrality as edge_current_flow <EOL> from networkx import edge_current_flow_betweenness_centrality_subset as edge_current_flow_subset <EOL> class TestFlowBetweennessCentrality ( object ) : <EOL> numpy = <NUM_LIT:1> <EOL> @ classmethod <EOL> def setupClass ( cls ) : <EOL> global np <EOL> try : <EOL> import numpy as np <EOL> import scipy <EOL> except ImportError : <EOL> raise SkipTest ( '<STR_LIT>' ) <EOL> def test_K4_normalized ( self ) : <EOL> """<STR_LIT>""" <EOL> G = networkx . complete_graph ( <NUM_LIT:4> ) <EOL> b = networkx . current_flow_betweenness_centrality_subset ( G , <EOL> G . nodes ( ) , <EOL> G . nodes ( ) , <EOL> normalized = True ) <EOL> b_answer = networkx . current_flow_betweenness_centrality ( G , normalized = True ) <EOL> for n in sorted ( G ) : <EOL> assert_almost_equal ( b [ n ] , b_answer [ n ] ) <EOL> def test_K4 ( self ) : <EOL> """<STR_LIT>""" <EOL> G = networkx . complete_graph ( <NUM_LIT:4> ) <EOL> b = networkx . current_flow_betweenness_centrality_subset ( G , <EOL> G . nodes ( ) , <EOL> G . nodes ( ) , <EOL> normalized = True ) <EOL> b_answer = networkx . current_flow_betweenness_centrality ( G , normalized = True ) <EOL> for n in sorted ( G ) : <EOL> assert_almost_equal ( b [ n ] , b_answer [ n ] ) <EOL> G . add_edge ( <NUM_LIT:0> , <NUM_LIT:1> , { '<STR_LIT>' : <NUM_LIT:0.5> , '<STR_LIT>' : <NUM_LIT> } ) <EOL> b = networkx . current_flow_betweenness_centrality_subset ( G , <EOL> G . nodes ( ) , <EOL> G . nodes ( ) , <EOL> normalized = True , <EOL> weight = None ) <EOL> for n in sorted ( G ) : <EOL> assert_almost_equal ( b [ n ] , b_answer [ n ] ) <EOL> b = networkx . current_flow_betweenness_centrality_subset ( G , <EOL> G . nodes ( ) , <EOL> G . nodes ( ) , <EOL> normalized = True ) <EOL> b_answer = networkx . current_flow_betweenness_centrality ( G , normalized = True ) <EOL> for n in sorted ( G ) : <EOL> assert_almost_equal ( b [ n ] , b_answer [ n ] ) <EOL> b = networkx . current_flow_betweenness_centrality_subset ( G , <EOL> G . nodes ( ) , <EOL> G . nodes ( ) , <EOL> normalized = True , <EOL> weight = '<STR_LIT>' ) <EOL> b_answer = networkx . current_flow_betweenness_centrality ( G , normalized = True , weight = '<STR_LIT>' ) <EOL> for n in sorted ( G ) : <EOL> assert_almost_equal ( b [ n ] , b_answer [ n ] ) <EOL> def test_P4_normalized ( self ) : <EOL> """<STR_LIT>""" <EOL> G = networkx . path_graph ( <NUM_LIT:4> ) <EOL> b = networkx . current_flow_betweenness_centrality_subset ( G , <EOL> G . nodes ( ) , <EOL> G . nodes ( ) , <EOL> normalized = True ) <EOL> b_answer = networkx . current_flow_betweenness_centrality ( G , normalized = True ) <EOL> for n in sorted ( G ) : <EOL> assert_almost_equal ( b [ n ] , b_answer [ n ] ) <EOL> def test_P4 ( self ) : <EOL> """<STR_LIT>""" <EOL> G = networkx . path_graph ( <NUM_LIT:4> ) <EOL> b = networkx . current_flow_betweenness_centrality_subset ( G , <EOL> G . nodes ( ) , <EOL> G . nodes ( ) , <EOL> normalized = True ) <EOL> b_answer = networkx . current_flow_betweenness_centrality ( G , normalized = True ) <EOL> for n in sorted ( G ) : <EOL> assert_almost_equal ( b [ n ] , b_answer [ n ] ) <EOL> def test_star ( self ) : <EOL> """<STR_LIT>""" <EOL> G = networkx . Graph ( ) <EOL> G . add_star ( [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' , '<STR_LIT:d>' ] ) <EOL> b = networkx . current_flow_betweenness_centrality_subset ( G , <EOL> G . nodes ( ) , <EOL> G . nodes ( ) , <EOL> normalized = True ) <EOL> b_answer = networkx . current_flow_betweenness_centrality ( G , normalized = True ) <EOL> for n in sorted ( G ) : <EOL> assert_almost_equal ( b [ n ] , b_answer [ n ] ) <EOL> class TestEdgeFlowBetweennessCentrality ( object ) : <EOL> numpy = <NUM_LIT:1> <EOL> @ classmethod <EOL> def setupClass ( cls ) : <EOL> global np <EOL> try : <EOL> import numpy as np <EOL> import scipy <EOL> except ImportError : <EOL> raise SkipTest ( '<STR_LIT>' ) <EOL> def test_K4_normalized ( self ) : <EOL> """<STR_LIT>""" <EOL> G = networkx . complete_graph ( <NUM_LIT:4> ) <EOL> b = edge_current_flow_subset ( G , G . nodes ( ) , G . nodes ( ) , normalized = True ) <EOL> b_answer = edge_current_flow ( G , normalized = True ) <EOL> for ( s , t ) , v1 in b_answer . items ( ) : <EOL> v2 = b . get ( ( s , t ) , b . get ( ( t , s ) ) ) <EOL> assert_almost_equal ( v1 , v2 ) <EOL> def test_K4 ( self ) : <EOL> """<STR_LIT>""" <EOL> G = networkx . complete_graph ( <NUM_LIT:4> ) <EOL> b = edge_current_flow_subset ( G , G . nodes ( ) , G . nodes ( ) , normalized = False ) <EOL> b_answer = edge_current_flow ( G , normalized = False ) <EOL> for ( s , t ) , v1 in b_answer . items ( ) : <EOL> v2 = b . get ( ( s , t ) , b . get ( ( t , s ) ) ) <EOL> assert_almost_equal ( v1 , v2 ) <EOL> G . add_edge ( <NUM_LIT:0> , <NUM_LIT:1> , { '<STR_LIT>' : <NUM_LIT:0.5> , '<STR_LIT>' : <NUM_LIT> } ) <EOL> b = edge_current_flow_subset ( G , G . nodes ( ) , G . nodes ( ) , normalized = False , weight = None ) <EOL> for ( s , t ) , v1 in b_answer . items ( ) : <EOL> v2 = b . get ( ( s , t ) , b . get ( ( t , s ) ) ) <EOL> assert_almost_equal ( v1 , v2 ) <EOL> b = edge_current_flow_subset ( G , G . nodes ( ) , G . nodes ( ) , normalized = False ) <EOL> b_answer = edge_current_flow ( G , normalized = False ) <EOL> for ( s , t ) , v1 in b_answer . items ( ) : <EOL> v2 = b . get ( ( s , t ) , b . get ( ( t , s ) ) ) <EOL> assert_almost_equal ( v1 , v2 ) <EOL> b = edge_current_flow_subset ( G , G . nodes ( ) , G . nodes ( ) , normalized = False , weight = '<STR_LIT>' ) <EOL> b_answer = edge_current_flow ( G , normalized = False , weight = '<STR_LIT>' ) <EOL> for ( s , t ) , v1 in b_answer . items ( ) : <EOL> v2 = b . get ( ( s , t ) , b . get ( ( t , s ) ) ) <EOL> assert_almost_equal ( v1 , v2 ) <EOL> def test_C4 ( self ) : <EOL> """<STR_LIT>""" <EOL> G = networkx . cycle_graph ( <NUM_LIT:4> ) <EOL> b = edge_current_flow_subset ( G , G . nodes ( ) , G . nodes ( ) , normalized = True ) <EOL> b_answer = edge_current_flow ( G , normalized = True ) <EOL> for ( s , t ) , v1 in b_answer . items ( ) : <EOL> v2 = b . get ( ( s , t ) , b . get ( ( t , s ) ) ) <EOL> assert_almost_equal ( v1 , v2 ) <EOL> def test_P4 ( self ) : <EOL> """<STR_LIT>""" <EOL> G = networkx . path_graph ( <NUM_LIT:4> ) <EOL> b = edge_current_flow_subset ( G , G . nodes ( ) , G . nodes ( ) , normalized = True ) <EOL> b_answer = edge_current_flow ( G , normalized = True ) <EOL> for ( s , t ) , v1 in b_answer . items ( ) : <EOL> v2 = b . get ( ( s , t ) , b . get ( ( t , s ) ) ) <EOL> assert_almost_equal ( v1 , v2 ) </s>
