# Path: retired/planners/connectivity_graph/utils.py
# PRUNE_INACTIVE = False
# 
# CYCLE_INACTIVE = PRUNE_INACTIVE
# 
# UPDATE_INACTIVE = False


from .connectivity_graph import *
from misc.utils import *
from .utils import PRUNE_INACTIVE, CYCLE_INACTIVE, UPDATE_INACTIVE
    from pygraphviz import AGraph # NOTE - LIS machines do not have pygraphviz
    for edge in self.edges.values(): edge.reset()
    for vertex in self.vertices.values():
      vertex.reset()
      if self.start.includes(vertex.substate):
        vertex.initial = True

    #print(start, '\n')
    for vertex in self.initial_vertices():
      vertex.set_reachable()
    #print(self.queue)
    #print([c for c in self.connectors.values() if c.active], '\n')

    self.goal.set_active()
    #print(self.queue)
    #print([c for c in self.connectors.values() if c.active], '\n')

    #self.graph('start.pdf', reachable=False)
    while time() - start_time <= max_time and iterations <= max_iterations and cycles <= max_cycles:
      if self.greedy and self.goal.reachable: break

      subplanner = self.queue.popleft()
      if subplanner is None: # Dummy node to count the number of cycles
        cycles += 1
        if len(self.queue) == 0: break
        self.queue.append(None)
        continue
      if not subplanner.queued or subplanner.generation_history[self.state_uses[start]] >= max_generations: continue # NOTE - treating queued as whether it should be in the queue
      subplanner.queued = False

      #print(subplanner.goal_connector.active, self.is_connector_active(subplanner.goal_connector))

# Path: retired/planners/connectivity_graph/utils.py
# PRUNE_INACTIVE = False
# 
# CYCLE_INACTIVE = PRUNE_INACTIVE
# 
# UPDATE_INACTIVE = False


# Path: retired/planners/connectivity_graph/relaxed_connectivity_graph.py
from .connectivity_graph import *
from misc.utils import *
from .utils import PRUNE_INACTIVE, CYCLE_INACTIVE, UPDATE_INACTIVE
    from pygraphviz import AGraph # NOTE - LIS machines do not have pygraphviz

    for edge in self.edges.values(): edge.reset()
    for vertex in self.vertices.values():
      vertex.reset()
      if self.start.includes(vertex.substate):
        vertex.initial = True

    #print(start, '\n')
    for vertex in self.initial_vertices():
      vertex.set_reachable()
    #print(self.queue)
    #print([c for c in self.connectors.values() if c.active], '\n')

    self.goal.set_active()
    #print(self.queue)
    #print([c for c in self.connectors.values() if c.active], '\n')

    #self.graph('start.pdf', reachable=False)
    while time() - start_time <= max_time and iterations <= max_iterations and cycles <= max_cycles:
      if self.greedy and self.goal.reachable: break

      subplanner = self.queue.popleft()
      if subplanner is None: # Dummy node to count the number of cycles
        cycles += 1
        if len(self.queue) == 0: break
        self.queue.append(None)
        continue
      if not subplanner.queued or subplanner.generation_history[self.state_uses[start]] >= max_generations: continue # NOTE - treating queued as whether it should be in the queue
      subplanner.queued = False

      #print(subplanner.goal_connector.active, self.is_connector_active(subplanner.goal_connector))

      if UPDATE_INACTIVE: self.update_active()