def greedy_color(G, strategy='largest_first', interchange=False):
 if (len(G) == 0):
  return {}
 strategy = STRATEGIES.get(strategy, strategy)
 if (not callable(strategy)):
  raise nx.NetworkXError('strategy must be callable or a valid string. {0} not valid.'.format(strategy))
 if interchange:
  if (strategy is strategy_independent_set):
   msg = 'interchange cannot be used with strategy_independent_set'
   raise nx.NetworkXPointlessConcept(msg)
  if (strategy is strategy_saturation_largest_first):
   msg = 'interchange cannot be used with strategy_saturation_largest_first'
   raise nx.NetworkXPointlessConcept(msg)
 colors = {}
 nodes = strategy(G, colors)
 if interchange:
  return _interchange.greedy_coloring_with_interchange(G, nodes)
 for u in nodes:
  neighbour_colors = {colors[v] for v in G[u] if (v in colors)}
  for color in itertools.count():
   if (color not in neighbour_colors):
    break
  colors[u] = color
 return colors

def greedy_color ( G , strategy = 'largest_first' , interchange = False ) : if ( len ( G ) == 0 ) : return { } strategy = STRATEGIES . get ( strategy , strategy ) if ( not callable ( strategy ) ) : raise nx . NetworkXError ( 'strategy must be callable or a valid string. {0} not valid.' . format ( strategy ) ) if interchange : if ( strategy is strategy_independent_set ) : msg = 'interchange cannot be used with strategy_independent_set' raise nx . NetworkXPointlessConcept ( msg ) if ( strategy is strategy_saturation_largest_first ) : msg = 'interchange cannot be used with strategy_saturation_largest_first' raise nx . NetworkXPointlessConcept ( msg ) colors = { } nodes = strategy ( G , colors ) if interchange : return _interchange . greedy_coloring_with_interchange ( G , nodes ) for u in nodes : neighbour_colors = { colors [ v ] for v in G [ u ] if ( v in colors ) } for color in itertools . count ( ) : if ( color not in neighbour_colors ) : break colors [ u ] = color return colors
color a graph using various strategies of greedy graph coloring .