# Path: stripstream/pddl/cond_streams.py
# class ExternalGenCondStream(CondStream):
# 
#     def __init__(self, generator, name=None, *args, **kwargs):
#         self.generator = generator
#         super(ExternalGenCondStream, self).__init__(*args, **kwargs)
#         if name is not None:
#             self.name = name
# 
#     class StreamFn(GeneratorStream):
# 
#         def __init__(self, cs, inputs, **kwargs):
#             self.get_generator = cs.generator
#             GeneratorStream.__init__(self, cs, inputs, **kwargs)
# 
# Path: stripstream/fts/variable.py
# class FreeParameter(SSParameter):
#     num = 0
#     prefix = '_param%s'
# 
#     def __init__(self, name, type=None):
#         if type is None:
#             type = name
#             assert isinstance(type, VarType)
#             name = self.prefix % FreeParameter.num
#             FreeParameter.num += 1
#         super(FreeParameter, self).__init__(name, type)
# 
# Path: stripstream/fts/constraint.py
# class Constraint(object):
# 
#     def __init__(self, constraint, values):
#         self.constraint = constraint
#         self.values = values
# 
#     def __eq__(self, other):
#         return type(self) == type(other) and self.constraint == other.constraint and self.values == other.values
# 
#     def __ne__(self, other):
#         return not(self == other)
# 
#     def __hash__(self):
#         return hash((self.__class__, self.constraint, self.values))
# 
#     def __repr__(self):
#         return '%s(%s)' % (self.constraint.name, ','.join(repr(value) for value in self.values))
# 
# def convert_constraint(constraint):
# 
#     assert all(isinstance(item, FreeParameter) for item in constraint.values)
#     return constraint.constraint.predicate(*constraint.values)


from stripstream.pddl.cond_streams import ExternalGenCondStream
from stripstream.fts.variable import FreeParameter
from stripstream.fts.constraint import Constraint, convert_constraint
                if val not in self.inputs and val not in outputs:
                    outputs.append(val)
            else:
                raise ValueError('Unexpected value %s' % val)
        self.outputs = tuple(outputs)

    def __repr__(self):
        return self.name


def convert_sampler(sampler):
    def generator(inputs):
        input_values = tuple(const.type.get_value(const) for const in inputs)
        for output_list in sampler.gen(*input_values):
            assert type(output_list) == list
            new_output_list = []
            for outputs in output_list:
                if type(outputs) not in [list, tuple]:
                    outputs = [outputs]
                assert len(outputs) == len(sampler.outputs)
                new_output_list.append(tuple(par.type(out)
                                             for par, out in zip(sampler.outputs, outputs)))
            yield new_output_list

    return ExternalGenCondStream(
        generator=generator,
        name=sampler.name,
        inputs=sampler.inputs,
        outputs=sampler.outputs,
        conditions=map(convert_constraint, sampler.domain),

# Path: stripstream/pddl/cond_streams.py
# class ExternalGenCondStream(CondStream):
# 
#     def __init__(self, generator, name=None, *args, **kwargs):
#         self.generator = generator
#         super(ExternalGenCondStream, self).__init__(*args, **kwargs)
#         if name is not None:
#             self.name = name
# 
#     class StreamFn(GeneratorStream):
# 
#         def __init__(self, cs, inputs, **kwargs):
#             self.get_generator = cs.generator
#             GeneratorStream.__init__(self, cs, inputs, **kwargs)
# 
# Path: stripstream/fts/variable.py
# class FreeParameter(SSParameter):
#     num = 0
#     prefix = '_param%s'
# 
#     def __init__(self, name, type=None):
#         if type is None:
#             type = name
#             assert isinstance(type, VarType)
#             name = self.prefix % FreeParameter.num
#             FreeParameter.num += 1
#         super(FreeParameter, self).__init__(name, type)
# 
# Path: stripstream/fts/constraint.py
# class Constraint(object):
# 
#     def __init__(self, constraint, values):
#         self.constraint = constraint
#         self.values = values
# 
#     def __eq__(self, other):
#         return type(self) == type(other) and self.constraint == other.constraint and self.values == other.values
# 
#     def __ne__(self, other):
#         return not(self == other)
# 
#     def __hash__(self):
#         return hash((self.__class__, self.constraint, self.values))
# 
#     def __repr__(self):
#         return '%s(%s)' % (self.constraint.name, ','.join(repr(value) for value in self.values))
# 
# def convert_constraint(constraint):
# 
#     assert all(isinstance(item, FreeParameter) for item in constraint.values)
#     return constraint.constraint.predicate(*constraint.values)


# Path: stripstream/fts/sampler.py
from stripstream.pddl.cond_streams import ExternalGenCondStream
from stripstream.fts.variable import FreeParameter
from stripstream.fts.constraint import Constraint, convert_constraint

                if val not in self.inputs and val not in outputs:
                    outputs.append(val)
            else:
                raise ValueError('Unexpected value %s' % val)
        self.outputs = tuple(outputs)

    def __repr__(self):
        return self.name


def convert_sampler(sampler):
    def generator(inputs):
        input_values = tuple(const.type.get_value(const) for const in inputs)
        for output_list in sampler.gen(*input_values):
            assert type(output_list) == list
            new_output_list = []
            for outputs in output_list:
                if type(outputs) not in [list, tuple]:
                    outputs = [outputs]
                assert len(outputs) == len(sampler.outputs)
                new_output_list.append(tuple(par.type(out)
                                             for par, out in zip(sampler.outputs, outputs)))
            yield new_output_list

    return ExternalGenCondStream(
        generator=generator,
        name=sampler.name,
        inputs=sampler.inputs,
        outputs=sampler.outputs,
        conditions=map(convert_constraint, sampler.domain),

        effects=map(convert_constraint, sampler.cons),