本文整理汇总了Python中networkx.freeze函数的典型用法代码示例。如果您正苦于以下问题:Python freeze函数的具体用法?Python freeze怎么用?Python freeze使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了freeze函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
self.G_basic = tg.node_generate(
[[10, 11], [20], [30, 31], [40, 41], [50]],
itertools.count(step=100))
self.G_basic.add_path([10, 20, 30, 40, 50])
self.G_basic.add_path([11, 20, 31])
self.G_basic.add_path([30, 41, 50])
nx.freeze(self.G_basic)
示例2: MakeAdjacencyGraph
def MakeAdjacencyGraph(n, type, freq=0.5, wexc=0.1):
'''Temporary implementation that only generates complete graph.'''
G = nx.complete_graph(n, nx.DiGraph())
# Should profile this.
for edge in G.edges_iter():
nx.set_edge_attributes(G, 'weight', {edge: wexc})
nx.freeze(G) # To prevent unintended modification of G's structure
return G
示例3: build_meetups_graph
def build_meetups_graph(groups, topics, members, events):
graph = nx.Graph()
for group in groups:
key = group['id']
graph.add_node(key, name=group['name'], type=Type.Groups, members=group['members'])
link_members(graph, group,members)
link_topics(graph, group, topics)
link_members_to_topics(graph, members, topics)
link_members_to_events(graph, members, events)
nx.freeze(graph)
logging.info('graph built')
return graph
示例4: setUp
def setUp(self):
G=nx.Graph(name="test")
e=[('a','b'),('b','c'),('c','d'),('d','e'),('e','f'),('a','f')]
G.add_edges_from(e,width=10)
G.add_node('g',color='green')
G.graph['number']=1
DG=nx.DiGraph(G)
MG=nx.MultiGraph(G)
MG.add_edge('a', 'a')
MDG=nx.MultiDiGraph(G)
MDG.add_edge('a', 'a')
fG = G.copy()
fDG = DG.copy()
fMG = MG.copy()
fMDG = MDG.copy()
nx.freeze(fG)
nx.freeze(fDG)
nx.freeze(fMG)
nx.freeze(fMDG)
self.G=G
self.DG=DG
self.MG=MG
self.MDG=MDG
self.fG=fG
self.fDG=fDG
self.fMG=fMG
self.fMDG=fMDG
示例5: main
def main():
seed(0) #set seed
#get graph info
G = nx.read_gpickle("input/graphMTC_CentroidsLength6.gpickle") #noCentroidsLength15.gpickle") #does not have centroidal links. There is also the choice of a proper multidigraph: nx.read_gpickle("input/graphMTC_CentroidsLength5.gpickle")
G = nx.freeze(G) #prevents edges or nodes to be added or deleted
#get od info. This is in format of a dict keyed by od, like demand[sd1][sd2] = 200000.
demand = bd.build_demand('input/BATS2000_34SuperD_TripTableData.csv', 'input/superdistricts_centroids.csv')
#get earthquake info
q = QuakeMaps('input/20130210_mtc_total_lnsas3.pkl', 'input/20130210_mtc_magnitudes3.pkl', 'input/20130210_mtc_faults3.pkl', 'input/20130210_mtc_weights3.pkl', 'input/20130210_mtc_scenarios3.pkl') #input/20130107_mtc_total_lnsas1.pkl', 'input/20130107_mtc_magnitudes1.pkl','input/20130107_mtc_faults1.pkl', 'input/20130107_mtc_weights1.pkl', 'input/20130107_mtc_scenarios1.pkl') #'input/20130210_mtc_total_lnsas3.pkl', 'input/20130210_mtc_magnitudes3.pkl', 'input/20130210_mtc_faults3.pkl', 'input/20130210_mtc_weights3.pkl', 'input/20130210_mtc_scenarios3.pkl') #('input/20130107_mtc_total_lnsas1.pkl', 'input/20130107_mtc_magnitudes1.pkl', #totalfilename=None, magfilename=None, faultfilename=None, weightsfilename=None, scenariofilename=None):
print 'weights: ', q.weights
q.num_sites = len(q.lnsas[0])
#determine which scenarios you want to run
good_indices = pick_scenarios(q.lnsas, q.weights)
travel_index_times = []
index = 0
#loop over scenarios
print 'size of lnsas: ', len(q.lnsas)
for scenario in q.lnsas: #each 'scenario' has 1557 values of lnsa, i.e. one per site
if index in good_indices:
print 'index: ', index
(bridges, flow, path, path2) = run_simple_iteration(G, scenario, demand, False)
travel_index_times.append((index, bridges, flow, path, path2))
# print 'new travel times: ', travel_index_times
if index%1000 ==0:
util.write_2dlist(time.strftime("%Y%m%d")+'_bridges_flow_paths4.txt',travel_index_times)
index += 1 #IMPORTANT
util.write_2dlist(time.strftime("%Y%m%d")+'_bridges_flow_paths4.txt',travel_index_times)
print 'the number of scenarios I considered doing: ', index
print 'the number of scenarios I actually did: ', len(travel_index_times)
示例6: generic_graph_view
def generic_graph_view(G, create_using=None):
if create_using is None:
newG = G.__class__()
else:
newG = nx.empty_graph(0, create_using)
if G.is_multigraph() != newG.is_multigraph():
raise NetworkXError("Multigraph for G must agree with create_using")
newG = nx.freeze(newG)
# create view by assigning attributes from G
newG._graph = G
newG.graph = G.graph
newG._node = G._node
if newG.is_directed():
if G.is_directed():
newG._succ = G._succ
newG._pred = G._pred
newG._adj = G._succ
else:
newG._succ = G._adj
newG._pred = G._adj
newG._adj = G._adj
elif G.is_directed():
if G.is_multigraph():
newG._adj = UnionMultiAdjacency(G._succ, G._pred)
else:
newG._adj = UnionAdjacency(G._succ, G._pred)
else:
newG._adj = G._adj
return newG
示例7: main
def main():
seed(0) #set seed
#get graph info
G = nx.read_gpickle("input/graphMTC_CentroidsLength5.gpickle") #noCentroidsLength15.gpickle") #does not have centroidal links
print '|V| = ', len(G.nodes())
print '|E| = ', len(G.edges())
G = nx.freeze(G) #prevents edges or nodes to be added or deleted
#get od info. This is in format of a dict keyed by od, like demand[sd1][sd2] = 200000.
demand = bd.build_demand('input/BATS2000_34SuperD_TripTableData.csv', 'input/superdistricts_centroids.csv') #bd.build_demand('input/BATS2000_34SuperD_TripTableData.csv', 'input/superdistricts_centroids.csv')
#get earthquake info
q = QuakeMaps('input/20130210_mtc_total_lnsas3.pkl', 'input/20130210_mtc_magnitudes3.pkl', 'input/20130210_mtc_faults3.pkl', 'input/20130210_mtc_weights3.pkl', 'input/20130210_mtc_scenarios3.pkl') #(input/20130107_mtc_total_lnsas1.pkl', 'input/20130107_mtc_magnitudes1.pkl', 'input/20130107_mtc_faults1.pkl', 'input/20130107_mtc_weights1.pkl', 'input/20130107_mtc_scenarios1.pkl') #totalfilename=None, magfilename=None, faultfilename=None, weightsfilename=None, scenariofilename=None): 'input/20130210_mtc_total_lnsas3.pkl', 'input/20130210_mtc_magnitudes3.pkl', 'input/20130210_mtc_faults3.pkl', 'input/20130210_mtc_weights3.pkl', 'input/20130210_mtc_scenarios3.pkl') #(
q.num_sites = len(q.lnsas[0])
#determine which scenarios you want to run
good_indices = pick_scenarios(q.lnsas, q.weights)
travel_index_times = []
index = 0
#loop over scenarios
for scenario in q.lnsas: #each 'scenario' has 1557 values of lnsa, i.e. one per site
if index in good_indices:
print 'index: ', index
(travel_time, vmt) = run_iteration(G, scenario, demand)
travel_index_times.append((index, travel_time, vmt))
# print 'new travel times: ', travel_index_times
if index%100 ==0:
util.write_2dlist(time.strftime("%Y%m%d")+'_travel_time.txt',travel_index_times)
index += 1 #IMPORTANT
util.write_2dlist(time.strftime("%Y%m%d")+'_travel_time.txt',travel_index_times)
示例8: subgraph_view
def subgraph_view(G, filter_node=no_filter, filter_edge=no_filter):
newG = nx.freeze(G.__class__())
newG._NODE_OK = filter_node
newG._EDGE_OK = filter_edge
# create view by assigning attributes from G
newG._graph = G
newG.graph = G.graph
newG._node = FilterAtlas(G._node, filter_node)
if G.is_multigraph():
Adj = FilterMultiAdjacency
def reverse_edge(u, v, k): return filter_edge(v, u, k)
else:
Adj = FilterAdjacency
def reverse_edge(u, v): return filter_edge(v, u)
if G.is_directed():
newG._succ = Adj(G._succ, filter_node, filter_edge)
newG._pred = Adj(G._pred, filter_node, reverse_edge)
newG._adj = newG._succ
else:
newG._adj = Adj(G._adj, filter_node, filter_edge)
return newG
示例9: _swap
def _swap(self, replacement_graph):
"""Validates the replacement graph and then swaps the underlying graph
with a frozen version of the replacement graph (this maintains the
invariant that the underlying graph is immutable).
"""
self._validate(replacement_graph)
self._graph = nx.freeze(replacement_graph)
示例10: __init__
def __init__(self, graph:str or networkx.Graph):
if isinstance(graph, networkx.Graph):
nxgraph = networkx.Graph(graph)
elif isinstance(graph, str):
nxgraph = phasme.build_graph.graph_from_file(graph)
else:
raise ValueError("Unexpected {}".format(graph))
# internal graph representation
self.__edges = map(frozenset, nxgraph.edges)
if const.TEST_INTEGRITY:
self.__edges = tuple(self.__edges)
for args in self.__edges:
if len(args) > 2:
print('WARNING: Weird edge: {}. It will be filtered.'.format(args))
else:
assert len(args) == 2, args
self.__edges = set(edge for edge in self.__edges if len(edge) == 2)
# data
self.__nodes = set(nxgraph.nodes)
self.__uid = str(min(self.__nodes, key=str))
self.__nb_node = len(self.__nodes)
self.__nb_cc = networkx.number_connected_components(nxgraph)
self._nxgraph = nxgraph if constants.KEEP_NX_GRAPH else networkx.freeze(nxgraph)
self.__initial_number_of_edge = len(self.__edges)
self.__active_recipe = None
self.__hierarchy = set() # inclusions between powernodes
self.__powernodes = defaultdict(set) # (step, set) -> {node in powernode}
self.__poweredges = defaultdict(set) # (step, set) -> (step, set)
示例11: flatten
def flatten(item, freeze=True):
"""Flattens a item (a task or flow) into a single execution graph."""
graph = _post_flatten(_flatten(item, set()))
if freeze:
# Frozen graph can't be modified...
return nx.freeze(graph)
return graph
示例12: get_graph
def get_graph():
import networkx
'''loads full mtc highway graph with dummy links and then adds a few fake centroidal nodes for max flow and traffic assignment'''
G = networkx.read_gpickle("input/graphMTC_CentroidsLength3int.gpickle")
G = add_superdistrict_centroids(G)
# Directed! only one edge between nodes
G = nx.freeze(G) #prevents edges or nodes to be added or deleted
return G
示例13: graph
def graph(self):
if self._subgraph is not None:
return self._subgraph
if self._target is None:
return self._graph
nodes = [self._target]
nodes.extend(dst for _src, dst in
traversal.dfs_edges(self._graph.reverse(), self._target))
self._subgraph = nx.freeze(self._graph.subgraph(nodes))
return self._subgraph
示例14: flatten
def flatten(self):
"""Flattens a item (a task or flow) into a single execution graph."""
if self._graph is not None:
return self._graph
self._pre_flatten()
graph = self._flatten(self._root)
self._post_flatten(graph)
if self._freeze:
self._graph = nx.freeze(graph)
else:
self._graph = graph
return self._graph
示例15: test_freeze
def test_freeze(self):
G=networkx.freeze(self.G)
assert_equal(G.frozen,True)
assert_raises(networkx.NetworkXError, G.add_node, 1)
assert_raises(networkx.NetworkXError, G.add_nodes_from, [1])
assert_raises(networkx.NetworkXError, G.remove_node, 1)
assert_raises(networkx.NetworkXError, G.remove_nodes_from, [1])
assert_raises(networkx.NetworkXError, G.add_edge, 1,2)
assert_raises(networkx.NetworkXError, G.add_edges_from, [(1,2)])
assert_raises(networkx.NetworkXError, G.remove_edge, 1,2)
assert_raises(networkx.NetworkXError, G.remove_edges_from, [(1,2)])
assert_raises(networkx.NetworkXError, G.clear)