# Path: stripstream/fts/variable.py
# class VariableType(Type):
# class FreeParameter(SSParameter):
# class Variable(object):
# class VariableSet(object):
# class VariableMember(object):
#     def __init__(self, name=None, domain=None):
#     def __call__(self, value):
#     def get_value(self, const):
#     def param(self, name):
# def get_value(const):
#     def __init__(self, name, type=None):
# def var_name(var):
# def var_args(var):
# def split_var(var):
#     def __init__(self, name, dtype, args=[]):
#     def __repr__(self):
#     def __init__(self, name):
#     def __getitem__(self, var):
#     def __call__(self, *args):
#     def __repr__(self):
#     def __init__(self, temp, var):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def __hash__(self):
#     def __repr__(self):
# def is_parameter(v):
# def is_constant(v):
# def expand_variables(vars):
# def make_var_constants(var, var_map):
# X = VariableSet('x')
# U = VariableSet('u')
# 
# Path: stripstream/fts/constraint.py
# class ConstraintType(object):
#     num = 0
# 
#     prefix = 'Con%s'
# 
#     def __init__(self, types=(), test=None, domain=(), satisfying=(), name=None, **kwargs):
#         self.types = tuple(types)
#         self.test = test
#         self.n = ConstraintType.num
#         ConstraintType.num += 1
#         self.name = name if name is not None else self.prefix % self.n
#         self.domain = tuple(domain)
#         self.satisfying = tuple(satisfying)
#         self.predicate = Predicate(self.name, self.types)
#         self.kwargs = kwargs
# 
#     def __call__(self, *args, **kwargs):
#         return Constraint(self, args)
# 
#     def __repr__(self):
#         return self.name
# 
# Path: stripstream/pddl/objects.py
# class Constant(Object):
#     pass
#     """
#   PDDL constant which extends :class:`.Object`.
#   """
# 
# Path: stripstream/pddl/logic/predicates.py
# class Predicate(Head):
#     pass
#     """
#   Predicate P which extends :class:`.NamedHead`.
#   """


from stripstream.fts.variable import VarType, FreeParameter, VariableType
from stripstream.fts.constraint import ConstraintType
from stripstream.pddl.objects import Constant
from stripstream.pddl.logic.predicates import Predicate


def get_value(x):
    if type(x) != Constant or not isinstance(x.type, VariableType):
        return x
    return x.type.get_value(x)


def convert_plan(plan):
    if plan is None:
        return plan
    return [(action, map(get_value, args)) for action, args in plan]


def rename_variables(assignments):
    for name, value in assignments.iteritems():
        if type(value) == VarType:
            value.name = name.lower()
        elif type(value) == ConstraintType:
            value.name = name.lower()
            value.predicate = Predicate(value.name, value.types)
        elif type(value) == FreeParameter:

# Path: stripstream/fts/variable.py
# class VariableType(Type):
# class FreeParameter(SSParameter):
# class Variable(object):
# class VariableSet(object):
# class VariableMember(object):
#     def __init__(self, name=None, domain=None):
#     def __call__(self, value):
#     def get_value(self, const):
#     def param(self, name):
# def get_value(const):
#     def __init__(self, name, type=None):
# def var_name(var):
# def var_args(var):
# def split_var(var):
#     def __init__(self, name, dtype, args=[]):
#     def __repr__(self):
#     def __init__(self, name):
#     def __getitem__(self, var):
#     def __call__(self, *args):
#     def __repr__(self):
#     def __init__(self, temp, var):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def __hash__(self):
#     def __repr__(self):
# def is_parameter(v):
# def is_constant(v):
# def expand_variables(vars):
# def make_var_constants(var, var_map):
# X = VariableSet('x')
# U = VariableSet('u')
# 
# Path: stripstream/fts/constraint.py
# class ConstraintType(object):
#     num = 0
# 
#     prefix = 'Con%s'
# 
#     def __init__(self, types=(), test=None, domain=(), satisfying=(), name=None, **kwargs):
#         self.types = tuple(types)
#         self.test = test
#         self.n = ConstraintType.num
#         ConstraintType.num += 1
#         self.name = name if name is not None else self.prefix % self.n
#         self.domain = tuple(domain)
#         self.satisfying = tuple(satisfying)
#         self.predicate = Predicate(self.name, self.types)
#         self.kwargs = kwargs
# 
#     def __call__(self, *args, **kwargs):
#         return Constraint(self, args)
# 
#     def __repr__(self):
#         return self.name
# 
# Path: stripstream/pddl/objects.py
# class Constant(Object):
#     pass
#     """
#   PDDL constant which extends :class:`.Object`.
#   """
# 
# Path: stripstream/pddl/logic/predicates.py
# class Predicate(Head):
#     pass
#     """
#   Predicate P which extends :class:`.NamedHead`.
#   """


# Path: stripstream/fts/utils.py
from stripstream.fts.variable import VarType, FreeParameter, VariableType
from stripstream.fts.constraint import ConstraintType
from stripstream.pddl.objects import Constant
from stripstream.pddl.logic.predicates import Predicate



def get_value(x):
    if type(x) != Constant or not isinstance(x.type, VariableType):
        return x
    return x.type.get_value(x)


def convert_plan(plan):
    if plan is None:
        return plan
    return [(action, map(get_value, args)) for action, args in plan]


def rename_variables(assignments):
    for name, value in assignments.iteritems():
        if type(value) == VarType:
            value.name = name.lower()
        elif type(value) == ConstraintType:
            value.name = name.lower()
            value.predicate = Predicate(value.name, value.types)
        elif type(value) == FreeParameter:

            FreeParameter.__init__(value, name, value.type)