# Path: sdopt/nodes/types.py
# def is_sum_node(node_dict):
#     return node_dict[NodeAttr.type] == ntype.SUM
# 
# def is_var_node(node_dict):
#     return node_dict[NodeAttr.type] == ntype.VAR
# 
# Path: sdopt/nodes/attributes.py
# class NodeAttr:
#     bounds    =  1
#     con_num   =  2
#     d_term    =  3
#     display   =  4
#     input_ord =  5
#     n_term    =  6
#     name      =  7
#     node_id   =  8
#     number    =  9
#     operation = 10
#     type      = 11
#     var_num   = 12


from array import array
from collections import defaultdict
from ..nodes.types import is_sum_node, is_var_node
from ..nodes.attributes import NodeAttr
    from matplotlib import pyplot as plt
import networkx as nx
import six
    dbg_pprint_source_sink_types(dag)
    print('-------------------------------------------------------------------')
    
def dbg_pprint_source_sink_types(dag):
    source_types = group_node_ids_by_kind(itr_sourcetype_nodeid(dag))
    sink_types   = group_node_ids_by_kind(itr_sinktype_nodeid(  dag))
    print('Sources:')
    dbg_pprint_kind_nodeids(source_types)
    print('Sinks:')
    dbg_pprint_kind_nodeids(sink_types)
    
def dbg_pprint_kind_nodeids(kind_nodeids):
    for kind, nodeids in kind_nodeids.items():
        count = len(nodeids)
        print(' ', kind, nodeids if count <= 20 else '', '(count=%d)' % count)

def group_node_ids_by_kind(itr_kind_nodeid_pairs):
    types = defaultdict(list)
    for kind, n in itr_kind_nodeid_pairs:
        types[kind].append(n)
    return types

def itr_sourcetype_nodeid(dag):
    return ((get_pretty_type_str(dag, n), n) for n in dag if is_source(dag, n))

def itr_sinktype_nodeid(dag):
    return ((get_pretty_type_str(dag, n), n) for n in dag if is_sink(dag, n))

def itr_sink_con_num_nodeid(dag):
    '(con_num, node_id) for sinks only; assumes that the problem has been setup'

# Path: sdopt/nodes/types.py
# def is_sum_node(node_dict):
#     return node_dict[NodeAttr.type] == ntype.SUM
# 
# def is_var_node(node_dict):
#     return node_dict[NodeAttr.type] == ntype.VAR
# 
# Path: sdopt/nodes/attributes.py
# class NodeAttr:
#     bounds    =  1
#     con_num   =  2
#     d_term    =  3
#     display   =  4
#     input_ord =  5
#     n_term    =  6
#     name      =  7
#     node_id   =  8
#     number    =  9
#     operation = 10
#     type      = 11
#     var_num   = 12


# Path: sdopt/representation/dag_util.py
from array import array
from collections import defaultdict
from ..nodes.types import is_sum_node, is_var_node
from ..nodes.attributes import NodeAttr
    from matplotlib import pyplot as plt
import networkx as nx
import six

    dbg_pprint_source_sink_types(dag)
    print('-------------------------------------------------------------------')
    
def dbg_pprint_source_sink_types(dag):
    source_types = group_node_ids_by_kind(itr_sourcetype_nodeid(dag))
    sink_types   = group_node_ids_by_kind(itr_sinktype_nodeid(  dag))
    print('Sources:')
    dbg_pprint_kind_nodeids(source_types)
    print('Sinks:')
    dbg_pprint_kind_nodeids(sink_types)
    
def dbg_pprint_kind_nodeids(kind_nodeids):
    for kind, nodeids in kind_nodeids.items():
        count = len(nodeids)
        print(' ', kind, nodeids if count <= 20 else '', '(count=%d)' % count)

def group_node_ids_by_kind(itr_kind_nodeid_pairs):
    types = defaultdict(list)
    for kind, n in itr_kind_nodeid_pairs:
        types[kind].append(n)
    return types

def itr_sourcetype_nodeid(dag):
    return ((get_pretty_type_str(dag, n), n) for n in dag if is_source(dag, n))

def itr_sinktype_nodeid(dag):
    return ((get_pretty_type_str(dag, n), n) for n in dag if is_sink(dag, n))

def itr_sink_con_num_nodeid(dag):
    '(con_num, node_id) for sinks only; assumes that the problem has been setup'

    return ((dag.node[n][NodeAttr.con_num], n) for n in dag if is_sink(dag, n))