# Path: sas/operators.py
# class Axiom(Operator):
#   cost = 0


from .hsp import *
from .operators import Axiom
  return sum(operator.cost for operator in flatten(relaxed_plan))

def plan_length(goal, operator_costs, relaxed_plan, relaxed_goals):
  return len(flatten(relaxed_plan))

def multi_cost(goal, operator_costs, relaxed_plan, relaxed_goals):
  return plan_cost(goal, operator_costs, relaxed_plan, relaxed_goals), operator_costs[goal].cost, operator_costs[goal].level

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

def filter_axioms(operators):
  return list(filter(lambda o: not isinstance(o, Axiom), operators))

def none(goal, operator_costs, relaxed_plan, relaxed_goals):
  return []

def applicable(goal, operator_costs, relaxed_plan, relaxed_goals):
  return filter_axioms([o for o, (_, level) in operator_costs.items() if level == 0])

def first_goals(goal, operator_costs, relaxed_plan, relaxed_goals):
  if len(relaxed_plan) == 0:
      return [] # TODO - weird bug where the current state is the goal so the relaxed plan is empty...probably relates to costs
  return filter_axioms([o for o, (_, level) in operator_costs.items() if level == 0 and any(value in relaxed_goals[1][var] for var, value in o.effects.items())])

def first_operators(goal, operator_costs, relaxed_plan, relaxed_goals):
  if len(relaxed_plan) == 0:
      return []
  return filter_axioms(list(relaxed_plan[0]))

def first_combine(goal, operator_costs, relaxed_plan, relaxed_goals):

# Path: sas/operators.py
# class Axiom(Operator):
#   cost = 0


# Path: sas/ff.py
from .hsp import *
from .operators import Axiom

  return sum(operator.cost for operator in flatten(relaxed_plan))

def plan_length(goal, operator_costs, relaxed_plan, relaxed_goals):
  return len(flatten(relaxed_plan))

def multi_cost(goal, operator_costs, relaxed_plan, relaxed_goals):
  return plan_cost(goal, operator_costs, relaxed_plan, relaxed_goals), operator_costs[goal].cost, operator_costs[goal].level

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

def filter_axioms(operators):
  return list(filter(lambda o: not isinstance(o, Axiom), operators))

def none(goal, operator_costs, relaxed_plan, relaxed_goals):
  return []

def applicable(goal, operator_costs, relaxed_plan, relaxed_goals):
  return filter_axioms([o for o, (_, level) in operator_costs.items() if level == 0])

def first_goals(goal, operator_costs, relaxed_plan, relaxed_goals):
  if len(relaxed_plan) == 0:
      return [] # TODO - weird bug where the current state is the goal so the relaxed plan is empty...probably relates to costs
  return filter_axioms([o for o, (_, level) in operator_costs.items() if level == 0 and any(value in relaxed_goals[1][var] for var, value in o.effects.items())])

def first_operators(goal, operator_costs, relaxed_plan, relaxed_goals):
  if len(relaxed_plan) == 0:
      return []
  return filter_axioms(list(relaxed_plan[0]))

def first_combine(goal, operator_costs, relaxed_plan, relaxed_goals):

  one = first_operators(goal, operator_costs, relaxed_plan, relaxed_goals)