# Path: retired/discrete/subplanners.py
# class DiscreteSubplanner(Subplanner):
#   def __init__(self, operators):
#     self.operators = operators
#   def generator(self, start_vertex, goal_connector, rg):
#     #yield # NOTE - include if don't want initial generation
#     vertex = rg.vertex(goal_connector.condition.substate)
#     vertex.connect(goal_connector)
#     variable, value = list(vertex.substate)[0]
# 
#     for operator in self.operators:
#       if variable in operator.effects:
#         effect = operator.effects[variable]
#         if is_discrete_effect(effect) and effect.value == value:
#           rg.edge(operator).connect(vertex)
#     yield
# 
# Path: retired/discrete/operators.py
# def is_discrete_condition(condition):
#   return isinstance(condition, SubstateCondition) and len(condition.substate) == 1
# 
# def is_discrete_effect(effect):
#   return isinstance(effect, ValueEffect)
# 
# def is_discrete_operator(operator):
#   for condition in operator.conditions:
#     if not is_discrete_condition(condition):
#       return False
#   for _, effect in operator.effects.items():
#     if not is_discrete_effect(effect):
#       return False
#   return True
# 
# def connect_discrete_conditions(rg, edge):
#   for connector in edge.connectors:
#     if is_discrete_condition(connector.condition):
#       vertex = rg.vertex(connector.condition.substate)
#       vertex.connect(connector)
#       if rg.start.substate in connector.condition:
#         rg.start.connect(connector)
# 
# def connect_discrete_operator(rg, edge):
#   connect_discrete_conditions(rg, edge)
#   connect_discrete_effects(rg, edge)


from .subplanners import DiscreteSubplanner
from .operators import is_discrete_condition, is_discrete_effect, is_discrete_operator, \
  connect_discrete_conditions, connect_discrete_operator


class Scheduler(object):
  def __init__(self, rg):
    self.rg = rg
  def __call__(self, start_vertex, connector):
    raise NotImplementedError('Scheduler must implement __call__(self, start_vertex, connector)')

class GeneratingScheduler(Scheduler):
  def __init__(self, rg, subplanners):
    super(self.__class__, self).__init__(rg)
    self.subplanners = subplanners
  def __call__ (self, start_vertex, connector):
    return [subplanner(start_vertex, connector, self.rg) for subplanner in self.subplanners
            if subplanner.applicable(start_vertex, connector, self.rg)]

###########################################################################

class InitDiscreteScheduler(Scheduler):
  def __init__(self, rg, operators):
    super(self.__class__, self).__init__(rg)
    self.rg.goal.intermediates.update(self.rg.goal.connectors) # NOTE - marks as intermediates to prevent growing

# Path: retired/discrete/subplanners.py
# class DiscreteSubplanner(Subplanner):
#   def __init__(self, operators):
#     self.operators = operators
#   def generator(self, start_vertex, goal_connector, rg):
#     #yield # NOTE - include if don't want initial generation
#     vertex = rg.vertex(goal_connector.condition.substate)
#     vertex.connect(goal_connector)
#     variable, value = list(vertex.substate)[0]
# 
#     for operator in self.operators:
#       if variable in operator.effects:
#         effect = operator.effects[variable]
#         if is_discrete_effect(effect) and effect.value == value:
#           rg.edge(operator).connect(vertex)
#     yield
# 
# Path: retired/discrete/operators.py
# def is_discrete_condition(condition):
#   return isinstance(condition, SubstateCondition) and len(condition.substate) == 1
# 
# def is_discrete_effect(effect):
#   return isinstance(effect, ValueEffect)
# 
# def is_discrete_operator(operator):
#   for condition in operator.conditions:
#     if not is_discrete_condition(condition):
#       return False
#   for _, effect in operator.effects.items():
#     if not is_discrete_effect(effect):
#       return False
#   return True
# 
# def connect_discrete_conditions(rg, edge):
#   for connector in edge.connectors:
#     if is_discrete_condition(connector.condition):
#       vertex = rg.vertex(connector.condition.substate)
#       vertex.connect(connector)
#       if rg.start.substate in connector.condition:
#         rg.start.connect(connector)
# 
# def connect_discrete_operator(rg, edge):
#   connect_discrete_conditions(rg, edge)
#   connect_discrete_effects(rg, edge)


# Path: retired/discrete/schedulers.py
from .subplanners import DiscreteSubplanner
from .operators import is_discrete_condition, is_discrete_effect, is_discrete_operator, \
  connect_discrete_conditions, connect_discrete_operator



class Scheduler(object):
  def __init__(self, rg):
    self.rg = rg
  def __call__(self, start_vertex, connector):
    raise NotImplementedError('Scheduler must implement __call__(self, start_vertex, connector)')

class GeneratingScheduler(Scheduler):
  def __init__(self, rg, subplanners):
    super(self.__class__, self).__init__(rg)
    self.subplanners = subplanners
  def __call__ (self, start_vertex, connector):
    return [subplanner(start_vertex, connector, self.rg) for subplanner in self.subplanners
            if subplanner.applicable(start_vertex, connector, self.rg)]

###########################################################################

class InitDiscreteScheduler(Scheduler):
  def __init__(self, rg, operators):
    super(self.__class__, self).__init__(rg)
    self.rg.goal.intermediates.update(self.rg.goal.connectors) # NOTE - marks as intermediates to prevent growing

    connect_discrete_conditions(self.rg, self.rg.goal)