本文整理汇总了Python中networkx.classes.digraph.DiGraph.__init__方法的典型用法代码示例。如果您正苦于以下问题:Python DiGraph.__init__方法的具体用法?Python DiGraph.__init__怎么用?Python DiGraph.__init__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkx.classes.digraph.DiGraph
的用法示例。
在下文中一共展示了DiGraph.__init__方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from networkx.classes.digraph import DiGraph [as 别名]
# 或者: from networkx.classes.digraph.DiGraph import __init__ [as 别名]
def __init__(self, incoming_graph_data=None, **attr):
"""Initialize a graph with edges, name, or graph attributes.
Parameters
----------
incoming_graph_data : input graph
Data to initialize graph. If incoming_graph_data=None (default)
an empty graph is created. The data can be an edge list, or any
NetworkX graph object. If the corresponding optional Python
packages are installed the data can also be a NumPy matrix
or 2d ndarray, a SciPy sparse matrix, or a PyGraphviz graph.
attr : keyword arguments, optional (default= no attributes)
Attributes to add to graph as key=value pairs.
See Also
--------
convert
Examples
--------
>>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc
>>> G = nx.Graph(name='my graph')
>>> e = [(1, 2), (2, 3), (3, 4)] # list of edges
>>> G = nx.Graph(e)
Arbitrary graph attribute pairs (key=value) may be assigned
>>> G = nx.Graph(e, day="Friday")
>>> G.graph
{'day': 'Friday'}
"""
self.edge_key_dict_factory = self.edge_key_dict_factory
DiGraph.__init__(self, incoming_graph_data, **attr)
示例2: __init__
# 需要导入模块: from networkx.classes.digraph import DiGraph [as 别名]
# 或者: from networkx.classes.digraph.DiGraph import __init__ [as 别名]
def __init__(self, algo_id, *args, **kwargs):
DiGraph.__init__(self, args, kwargs)
self.id = algo_id
self.scan_count = 0
self.input_data = []
self.output_data =[]
self.data_id_dict = {} # internal dictionary for lookups of data nodes by id
self.scan_rate = kwargs.pop('scan_rate') # rate at which module should be scanned
示例3: __init__
# 需要导入模块: from networkx.classes.digraph import DiGraph [as 别名]
# 或者: from networkx.classes.digraph.DiGraph import __init__ [as 别名]
def __init__(self, node_dict, edge_dict, U, initial_node, initial_label):
DiGraph.__init__(self, name='motion_mdp', init_state=initial_node, init_label=initial_label)
for (n, prob_label) in node_dict.iteritems():
self.add_node(n, label = prob_label, act = set())
print "-------Motion MDP Initialized-------"
self.add_edges(edge_dict, U)
print "%s states and %s edges" %(str(len(self.nodes())), str(len(self.edges())))
self.unify_mdp()
示例4: __init__
# 需要导入模块: from networkx.classes.digraph import DiGraph [as 别名]
# 或者: from networkx.classes.digraph.DiGraph import __init__ [as 别名]
def __init__(self, formula):
#----call ltl2dra executable----
ltl2dra_output = run_ltl2dra(formula)
#----parse the output----
statenum, init, edges, aps, acc = parse_dra(ltl2dra_output)
#------
DiGraph.__init__(self, type='DRA', initial=set([init,]), accept=acc, symbols=aps)
print "-------DRA Initialized-------"
for state in xrange(0,statenum):
self.add_node(state)
for (ef,et) in edges.keys():
guard_string = edges[(ef,et)]
self.add_edge(ef, et, guard_string=guard_string)
print "-------DRA Constructed-------"
print "%s states, %s edges and %s accepting pairs" %(str(len(self.nodes())), str(len(self.edges())), str(len(acc)))
示例5: __init__
# 需要导入模块: from networkx.classes.digraph import DiGraph [as 别名]
# 或者: from networkx.classes.digraph.DiGraph import __init__ [as 别名]
def __init__(self, data=None, params=None, **attr):
# self.reaction_graph.graph['node'] = {'fontname': 'Courier new'}
# self.reaction_graph.graph['edge'] = {'fontname': 'Arial',
# 'fontsize': 10.0, # labelfontsize
# 'len': 4.0}
DiGraph.__init__(self, data, **attr)
if params is None:
params = {}
self.params = params # or "config" ?
if 'reaction_graph_default_attrs' in params:
self.graph.update(params['reaction_graph_default_attrs'])
# A reaction can have multiple end-state when a complex is being split up:
# (edge_attrs should be the same for edges belonging to the same reaction for intracomplex reactions
self.endstates_by_reaction = {} # [startstate][(reaction_spec_pair, reaction_attr)] = [list of endstates]
self.endstates_by_reaction[0] = defaultdict(list) # Also adding the "null" node
self.reverse_reaction_key = {} # get reaction edge key for the opposite direction.
self.tau_cum_max = 0
# self.reverse_reaction[(rx_spec_pair, rx_attr)] = (rev_rx_spec_pair, rev_rx_attr)
# used to be a dict {edge_key => target} but we can have multiple targets for a single reaction.
self.reaction_graph_complexes_directory = params.get("reaction_graph_complexes_directory")
if self.reaction_graph_complexes_directory is not None:
if not os.path.exists(self.reaction_graph_complexes_directory):
print("Creating directory for complex files:", self.reaction_graph_complexes_directory)
os.makedirs(self.reaction_graph_complexes_directory)
assert os.path.isdir(self.reaction_graph_complexes_directory)
self.dispatchers = []
# File with changes to the reaction graph, e.g. new nodes/edges and node/edge updates:
self.reaction_graph_events_file = params.get('reaction_graph_events_file')
if self.reaction_graph_events_file is None and self.reaction_graph_complexes_directory is not None:
self.reaction_graph_events_file = os.path.join(self.reaction_graph_complexes_directory,
"reaction_graph_eventstream.json")
if self.reaction_graph_events_file:
#self.reaction_graph_delta_file = open(self.reaction_graph_delta_file, 'a')
#self.open_files.append(self.reaction_graph_delta_file)
gs_file_dispatcher = GraphStreamFileDispatcher(self.reaction_graph_events_file)
gs_file_dispatcher.writer.write("# New reaction graph initialized at %s\n" % datetime.now())
print("\n\nWriting reaction_graph event stream to file: %s\n" % self.reaction_graph_events_file)
self.dispatchers.append(gs_file_dispatcher)
else:
# raise ValueError("self.reaction_graph_events_file not given: ", self.reaction_graph_events_file)
print("self.reaction_graph_events_file (%s) not given: Graph events will not be available." %
self.reaction_graph_events_file)
示例6: __init__
# 需要导入模块: from networkx.classes.digraph import DiGraph [as 别名]
# 或者: from networkx.classes.digraph.DiGraph import __init__ [as 别名]
def __init__(self,data=None,**kwds):
DiGraph.__init__(self,**kwds)
if data is not None:
try: # build a rooted tree
D=DiGraph()
for (child,parent) in data.par.iteritems():
D.add_edge(parent,child)
except AttributeError:
D=DiGraph(data)
except: # else nothing we can do
raise NetworkXError, "Data %s is not a rooted tree:"%data
if D.order()==D.size()+1:
self.pred=D.pred.copy()
self.succ=D.succ.copy()
self.adj=self.succ
del D
else: # not a tree
raise NetworkXError, "Data %s is not a rooted tree:"%data
示例7: __init__
# 需要导入模块: from networkx.classes.digraph import DiGraph [as 别名]
# 或者: from networkx.classes.digraph.DiGraph import __init__ [as 别名]
def __init__(self, data=None, **attr):
self.edge_key_dict_factory = self.edge_key_dict_factory
DiGraph.__init__(self, data, **attr)
示例8: __init__
# 需要导入模块: from networkx.classes.digraph import DiGraph [as 别名]
# 或者: from networkx.classes.digraph.DiGraph import __init__ [as 别名]
def __init__(self,*args,**kargs):
DiGraph.__init__(self,*args,**kargs)
示例9: __init__
# 需要导入模块: from networkx.classes.digraph import DiGraph [as 别名]
# 或者: from networkx.classes.digraph.DiGraph import __init__ [as 别名]
def __init__(self, config=None):
"""fill out the link data from the csv file"""
DiGraph.__init__(self)
self.config = config
if config is not None:
infile = open(config["link_file"])
reader = csv.reader(infile)
data = []
names = []
for row in reader:
if row[0] == "A":
names = row
else:
data.append(row)
M = len(data)
N = len(names)
if "perform_transformation" in config:
if config["perform_transformation"]:
# create wrong way links
if config["create_ww_links"]:
names.append(config["ww_exist_alias"][1])
for i in range(M):
if int(data[i][names.index(config["ww_exist_alias"][0])]) == 1:
new_row = data[i] + [1]
if len(new_row) < len(names):
print "A"
raise Exception
for var in config["ww_change"]:
idx = names.index(var)
stmt = (
"new_row[idx]=float(new_row[idx])"
+ config["ww_change"][var][0]
+ "config['ww_change'][var][1]"
)
###print names
###print data[i]
exec (stmt)
if len(new_row) < len(names):
print "B"
raise Exception
data.append(new_row)
data[i].append(0)
M = len(data)
N = len(names)
# transform variables
for var in config["variable_transforms"]:
names.append(var)
for i in range(M):
if type(config["variable_transforms"][var][1]) == type({}):
stmt = (
"data[i].append(config['variable_transforms'][var][1]["
+ config["variable_transforms"][var][2]
+ "(data[i][names.index(config['variable_transforms'][var][0])])])"
)
exec (stmt)
else:
if type(config["variable_transforms"][var][1]) == type((1, 2)):
stmt = (
"data[i].append("
+ config["variable_transforms"][var][1][0]
+ "("
+ config["variable_transforms"][var][2]
+ "(data[i][names.index(config['variable_transforms'][var][0])]),config['variable_transforms'][var][1][1]))"
)
exec (stmt)
else:
print "D"
raise Exception
M = len(data)
N = len(names)
if "relevant_variables" in config:
to_keep = []
for var in config["relevant_variables"]:
to_keep.append(names.index(var))
else:
to_keep = range(2, N)
for i in range(M):
edge_data = {}
for j in to_keep:
try:
edge_data[names[j]] = float(data[i][j])
except IndexError:
print names
print j
#.........这里部分代码省略.........
示例10: __init__
# 需要导入模块: from networkx.classes.digraph import DiGraph [as 别名]
# 或者: from networkx.classes.digraph.DiGraph import __init__ [as 别名]
def __init__(self, node_dict, symbols, ts_type):
DiGraph.__init__(self, symbols=symbols, type=ts_type, initial=set())
for (n, label) in node_dict.iteritems():
self.add_node(n, label=label, status='confirmed')
示例11: __init__
# 需要导入模块: from networkx.classes.digraph import DiGraph [as 别名]
# 或者: from networkx.classes.digraph.DiGraph import __init__ [as 别名]
def __init__(self, algo_id, *args, **kwargs):
self.id = algo_id
self.active_states = []
self.state_id_dict = {} # dictionary of state.id aliases for convenient node/edge lookups
DiGraph.__init__(self, args, kwargs)
示例12: __init__
# 需要导入模块: from networkx.classes.digraph import DiGraph [as 别名]
# 或者: from networkx.classes.digraph.DiGraph import __init__ [as 别名]
def __init__(self, ts, buchi, alpha=100):
DiGraph.__init__(self, ts=ts, buchi=buchi, alpha=alpha, initial=set(), accept=set(), type='ProdAut')