# 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/nodes/types.py
# class ntype:
#     DIV = 'div'
#     EXP = 'exp'
#     LOG = 'log'
#     MUL = 'mul'
#     NEG = 'neg'
#     NUM = 'num'
#     POW = 'pow'
#     SQR = 'sqr'
#     SUM = 'sum'
#     VAR = 'var'
# 
# Path: sdopt/representation/dag_util.py
# def add_keep_smaller_value(mapping, key, value):
#     # mapping[key]=value BUT if key is already present, keeps smaller value
#     old_value = mapping.get(key,  value)
#     mapping[key] = min(old_value, value)


from ..nodes.attributes import NodeAttr
from ..nodes.types import ntype
from ..representation.dag_util import add_keep_smaller_value
        edge['weight'] = -edge['weight']
    # Rewrite the node type to ntype.SUM
    d[NodeAttr.operation] = '+'
    d[NodeAttr.type] = ntype.SUM
    sum_setup(node_id, d, problem)

def num_setup(unused1, d, unused2):
    d[NodeAttr.display] = str(d[NodeAttr.number])

def pow_setup(node_id, d, problem):
    d[NodeAttr.display] = d[NodeAttr.operation]

def sqr_setup(node_id, d, problem):
    d[NodeAttr.display] = d[NodeAttr.operation]

def sum_setup(node_id, d, problem):
    # neg_node also calls this
    d[NodeAttr.display] = d[NodeAttr.operation]

def var_setup(node_id, d, problem):
    var_num = d[NodeAttr.var_num]
    # for base vars only: find the node with the smallest node id
    if  var_num < problem.nvars:
        # FIXME We could collect ALL the var aliases (base and defined) here!
        add_keep_smaller_value(problem.var_num_id, var_num, node_id)
    name    = problem.var_num_name.get(var_num, '_v%d' % var_num)
    d[NodeAttr.name]    = name
    d[NodeAttr.display] = '%s(%d)' % (name, node_id)



# 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/nodes/types.py
# class ntype:
#     DIV = 'div'
#     EXP = 'exp'
#     LOG = 'log'
#     MUL = 'mul'
#     NEG = 'neg'
#     NUM = 'num'
#     POW = 'pow'
#     SQR = 'sqr'
#     SUM = 'sum'
#     VAR = 'var'
# 
# Path: sdopt/representation/dag_util.py
# def add_keep_smaller_value(mapping, key, value):
#     # mapping[key]=value BUT if key is already present, keeps smaller value
#     old_value = mapping.get(key,  value)
#     mapping[key] = min(old_value, value)


# Path: sdopt/nodes/setup.py
from ..nodes.attributes import NodeAttr
from ..nodes.types import ntype
from ..representation.dag_util import add_keep_smaller_value

        edge['weight'] = -edge['weight']
    # Rewrite the node type to ntype.SUM
    d[NodeAttr.operation] = '+'
    d[NodeAttr.type] = ntype.SUM
    sum_setup(node_id, d, problem)

def num_setup(unused1, d, unused2):
    d[NodeAttr.display] = str(d[NodeAttr.number])

def pow_setup(node_id, d, problem):
    d[NodeAttr.display] = d[NodeAttr.operation]

def sqr_setup(node_id, d, problem):
    d[NodeAttr.display] = d[NodeAttr.operation]

def sum_setup(node_id, d, problem):
    # neg_node also calls this
    d[NodeAttr.display] = d[NodeAttr.operation]

def var_setup(node_id, d, problem):
    var_num = d[NodeAttr.var_num]
    # for base vars only: find the node with the smallest node id
    if  var_num < problem.nvars:
        # FIXME We could collect ALL the var aliases (base and defined) here!
        add_keep_smaller_value(problem.var_num_id, var_num, node_id)
    name    = problem.var_num_name.get(var_num, '_v%d' % var_num)
    d[NodeAttr.name]    = name
    d[NodeAttr.display] = '%s(%d)' % (name, node_id)



def setup(node_id, d, prob):