networkx.algorithms.coloring.greedy_color
的用法。用法:
greedy_color(G, strategy='largest_first', interchange=False)
使用各種貪心圖形著色策略為圖形著色。
嘗試使用盡可能少的顏色為圖形著色,其中節點的鄰居不能具有與節點本身相同的顏色。給定的策略決定了節點著色的順序。
這些策略在[1]中說明,smallest-last基於[2]。
- G:NetworkX 圖
- strategy:字符串或函數(G,顏色)
提供著色策略的函數(或表示函數的字符串),通過按應著色的順序返回節點。
G
是圖形,colors
是當前分配顏色的字典,由節點鍵控。該函數必須返回G
中所有節點的可迭代對象。如果策略函數是迭代器生成器(即帶有
yield
語句的函數),請記住colors
字典將在每個yield
之後更新,因為該函數貪心地選擇顏色。如果
strategy
是字符串,則必須是以下之一,每一個代表一個內置策略函數。'largest_first'
'random_sequential'
'smallest_last'
'independent_set'
'connected_sequential_bfs'
'connected_sequential_dfs'
'connected_sequential'
(上一個策略的別名)'saturation_largest_first'
'DSATUR'
(上一個策略的別名)
- interchange: bool:
如果設置為
True
,將使用 [3] 中說明的顏色交換算法。請注意,
saturation_largest_first
和independent_set
不適用於互換。此外,如果您將交換與自己的策略函數一起使用,則不能依賴colors
參數中的值。
- 具有表示節點的鍵和表示的值的字典
- 相應的著色。
- NetworkXPointlessConcept
如果
strategy
是saturation_largest_first
或independent_set
並且interchange
是True
。
參數:
返回:
拋出:
參考:
- 1
Adrian Kosowski, and Krzysztof Manuszewski, Classical Coloring of Graphs, Graph Colorings, 2-19, 2004. ISBN 0-8218-3458-4.
- 2
David W. Matula, and Leland L. Beck, “Smallest-last ordering and clustering and graph coloring algorithms.”
J. ACM
30, 3 (July 1983), 417-427. <https://doi.org/10.1145/2402.322385>- 3
Maciej M. Sysło, Marsingh Deo, Janusz S. Kowalik, Discrete Optimization Algorithms with Pascal Programs, 415-424, 1983. ISBN 0-486-45353-7.
例子:
>>> G = nx.cycle_graph(4) >>> d = nx.coloring.greedy_color(G, strategy="largest_first") >>> d in [{0: 0, 1: 1, 2: 0, 3: 1}, {0: 1, 1: 0, 2: 1, 3: 0}] True
相關用法
- Python NetworkX greedy_modularity_communities用法及代碼示例
- Python NetworkX greedy_tsp用法及代碼示例
- Python NetworkX graphviz_layout用法及代碼示例
- Python NetworkX groups用法及代碼示例
- Python NetworkX graph_edit_distance用法及代碼示例
- Python NetworkX grid_graph用法及代碼示例
- Python NetworkX get_edge_attributes用法及代碼示例
- Python NetworkX generate_multiline_adjlist用法及代碼示例
- Python NetworkX generic_node_match用法及代碼示例
- Python NetworkX gomory_hu_tree用法及代碼示例
- Python NetworkX generate_gml用法及代碼示例
- Python NetworkX generate_adjlist用法及代碼示例
- Python NetworkX gn_graph用法及代碼示例
- Python NetworkX generic_multiedge_match用法及代碼示例
- Python NetworkX generate_graphml用法及代碼示例
- Python NetworkX generic_edge_match用法及代碼示例
- Python NetworkX gnp_random_graph用法及代碼示例
- Python NetworkX generate_edgelist用法及代碼示例
- Python NetworkX generic_weighted_projected_graph用法及代碼示例
- Python NetworkX global_reaching_centrality用法及代碼示例
- Python NetworkX global_parameters用法及代碼示例
- Python NetworkX girvan_newman用法及代碼示例
- Python NetworkX generate_gexf用法及代碼示例
- Python NetworkX gnr_graph用法及代碼示例
- Python NetworkX generalized_degree用法及代碼示例
注:本文由純淨天空篩選整理自networkx.org大神的英文原創作品 networkx.algorithms.coloring.greedy_color。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。