# Path: planner/states.py
# class State(Substate):
#   def __init__(self, values):
#     super(self.__class__, self).__init__({var: value for var, value in values.items() if value is not False})
#   def __getitem__(self, var):
#     if var not in self.__dict__[HASH_DICT]: return False
#     return self.__dict__[HASH_DICT][var]
#   def substate(self, variables):
#     return Substate({var: self[var] for var in variables})
#   def __call__(self, variables):
#     return self.substate(variables)
# 
# Path: misc/objects.py
# def str_object(obj):
#   if type(obj) in (list, np.ndarray):
#     return '[%s]' % ', '.join(str_object(item) for item in obj)
#   if type(obj) == tuple:
#     return '(%s)' % ', '.join(str_object(item) for item in obj)
#   if type(obj) == dict:
#     return '{%s}' % ', '.join(str_object(item) + ': ' +  str_object(obj[item])
#                               for item in sorted(obj.keys(), key=lambda k: str_object(k)))
#   if type(obj) in (set, frozenset):
#     return '{%s}' % ', '.join(sorted(str_object(item) for item in obj))
#   if type(obj) in (float, np.float64):
#     obj = round(obj, 3)
#     if obj == 0:
#       obj = 0 # NOTE - catches -0.0 bug
#     return '%.3f'%obj
#   if isinstance(obj, types.FunctionType):
#     return obj.__name__
#   return str(obj)


from .utils import *
from planner.states import State
from misc.objects import str_object
  def update_inactive(self): # TODO - this is really slow. Only search if not greedy and reached?
    if not self.active: return

    self.active = False # Temporarily set to inactive
    for connector in self.connectors:
      connector.update_inactive()
      if connector.active:
        self.active = True
        return
    for sink_vertex, _ in self.sinks:
      sink_vertex.update_inactive()
      if sink_vertex.active:
        self.active = True
        return
    # Cannot find active parent node
    self.set_inactive()

  def __str__(self):
    return 'V(' + str(self.substate) + ')'
  __repr__ = __str__
  def node_str(self):
    if isinstance(self.substate, State):
      return self.substate.__class__.__name__
    return '\n'.join([str_object(variable) + '=' + str_object(value) for variable, value in self.substate])
  def node_attr(self):
    return {
      'shape': 'circle',
      'fontcolor': 'black',
      'style': 'filled',
      'colorscheme': 'SVG',

# Path: planner/states.py
# class State(Substate):
#   def __init__(self, values):
#     super(self.__class__, self).__init__({var: value for var, value in values.items() if value is not False})
#   def __getitem__(self, var):
#     if var not in self.__dict__[HASH_DICT]: return False
#     return self.__dict__[HASH_DICT][var]
#   def substate(self, variables):
#     return Substate({var: self[var] for var in variables})
#   def __call__(self, variables):
#     return self.substate(variables)
# 
# Path: misc/objects.py
# def str_object(obj):
#   if type(obj) in (list, np.ndarray):
#     return '[%s]' % ', '.join(str_object(item) for item in obj)
#   if type(obj) == tuple:
#     return '(%s)' % ', '.join(str_object(item) for item in obj)
#   if type(obj) == dict:
#     return '{%s}' % ', '.join(str_object(item) + ': ' +  str_object(obj[item])
#                               for item in sorted(obj.keys(), key=lambda k: str_object(k)))
#   if type(obj) in (set, frozenset):
#     return '{%s}' % ', '.join(sorted(str_object(item) for item in obj))
#   if type(obj) in (float, np.float64):
#     obj = round(obj, 3)
#     if obj == 0:
#       obj = 0 # NOTE - catches -0.0 bug
#     return '%.3f'%obj
#   if isinstance(obj, types.FunctionType):
#     return obj.__name__
#   return str(obj)


# Path: retired/planners/reachability_graph/vertex.py
from .utils import *
from planner.states import State
from misc.objects import str_object

  def update_inactive(self): # TODO - this is really slow. Only search if not greedy and reached?
    if not self.active: return

    self.active = False # Temporarily set to inactive
    for connector in self.connectors:
      connector.update_inactive()
      if connector.active:
        self.active = True
        return
    for sink_vertex, _ in self.sinks:
      sink_vertex.update_inactive()
      if sink_vertex.active:
        self.active = True
        return
    # Cannot find active parent node
    self.set_inactive()

  def __str__(self):
    return 'V(' + str(self.substate) + ')'
  __repr__ = __str__
  def node_str(self):
    if isinstance(self.substate, State):
      return self.substate.__class__.__name__
    return '\n'.join([str_object(variable) + '=' + str_object(value) for variable, value in self.substate])
  def node_attr(self):
    return {
      'shape': 'circle',
      'fontcolor': 'black',
      'style': 'filled',
      'colorscheme': 'SVG',

      'color': 'green' if isinstance(self.substate, State) else 'yellow',