def _neighbor_switch(G, w, unsat, h_node_residual, avoid_node_id=None):
 if ((avoid_node_id is None) or (h_node_residual[avoid_node_id] > 1)):
  w_prime = next(iter(unsat))
 else:
  iter_var = iter(unsat)
  while True:
   w_prime = next(iter_var)
   if (w_prime != avoid_node_id):
    break
 w_prime_neighbs = G[w_prime]
 for v in G[w]:
  if ((v not in w_prime_neighbs) and (v != w_prime)):
   switch_node = v
   break
 G.remove_edge(w, switch_node)
 G.add_edge(w_prime, switch_node)
 h_node_residual[w] += 1
 h_node_residual[w_prime] -= 1
 if (h_node_residual[w_prime] == 0):
  unsat.remove(w_prime)

def _neighbor_switch ( G , w , unsat , h_node_residual , avoid_node_id = None ) : if ( ( avoid_node_id is None ) or ( h_node_residual [ avoid_node_id ] > 1 ) ) : w_prime = next ( iter ( unsat ) ) else : iter_var = iter ( unsat ) while True : w_prime = next ( iter_var ) if ( w_prime != avoid_node_id ) : break w_prime_neighbs = G [ w_prime ] for v in G [ w ] : if ( ( v not in w_prime_neighbs ) and ( v != w_prime ) ) : switch_node = v break G . remove_edge ( w , switch_node ) G . add_edge ( w_prime , switch_node ) h_node_residual [ w ] += 1 h_node_residual [ w_prime ] -= 1 if ( h_node_residual [ w_prime ] == 0 ) : unsat . remove ( w_prime )
releases one free stub for saturated node w .