Beispiel #1
0
def convert_goal_constraints(goal_constraints, var_map, axiom_map):
    # NOTE - could use quantifiers here
    # NOTE - any parameters here would have to be the same across effects
    goal_literals = []
    for con in goal_constraints:
        for item in con.values:  # TODO - later relax this to handle quantification over goals
            assert not isinstance(item, FreeParameter) and (
                not isinstance(item, VarMember)
                or not any(isinstance(arg, FreeParameter) for arg in item.var))
        if con.constraint == Eq:
            a, b = con.values
            if is_constant(a) and is_constant(b):
                if a != b:
                    return None
            elif isinstance(a, VarMember) and isinstance(b, VarMember):
                raise NotImplementedError()
            elif isinstance(a, VarMember) and is_constant(b):
                goal_literals.append(make_equal_predicate(a, b, var_map))
            elif is_constant(a) and isinstance(b, VarMember):
                goal_literals.append(make_equal_predicate(b, a, var_map))
            else:
                raise ValueError()
        else:
            # TODO - could allow constants if a Parameter is used once
            constants = set()
            for item in con.values:
                if isinstance(item, VarMember):
                    constants.update(var_args(item.var))
                else:
                    constants.add(item)
            goal_literals.append(
                get_derived(con, var_map, axiom_map, constants))
    return goal_literals
def convert_goal_constraints(goal_constraints, var_map, axiom_map):

    goal_literals = []
    for con in goal_constraints:
        for item in con.values:
            assert not isinstance(item, FreeParameter) and (
                not isinstance(item, VarMember)
                or not any(isinstance(arg, FreeParameter) for arg in item.var))
        if con.constraint == Eq:
            a, b = con.values
            if is_constant(a) and is_constant(b):
                if a != b:
                    return None
            elif isinstance(a, VarMember) and isinstance(b, VarMember):
                raise NotImplementedError()
            elif isinstance(a, VarMember) and is_constant(b):
                goal_literals.append(make_equal_predicate(a, b, var_map))
            elif is_constant(a) and isinstance(b, VarMember):
                goal_literals.append(make_equal_predicate(b, a, var_map))
            else:
                raise ValueError()
        else:

            constants = set()
            for item in con.values:
                if isinstance(item, VarMember):
                    constants.update(var_args(item.var))
                else:
                    constants.add(item)
            goal_literals.append(
                get_derived(con, var_map, axiom_map, constants))
    return goal_literals
def get_single_state(constraints):
    state = {}
    for con in constraints:
        if not con.constraint is Eq:
            raise ValueError(
                'Initial state must solely be composed of %s constraints: %s' %
                (Eq, con))
        a, b = con.values
        assert isinstance(a, VarMember) and is_constant(b)
        assert not any(
            isinstance(arg, FreeParameter) for arg in var_args(a.var))
        state[a.var] = b

    return state
Beispiel #4
0
def convert_initial_state(initial_state, var_map, expanded_state_vars):
    initial_atoms = []
    initial_variables = set()
    for con in initial_state:
        assert con.constraint == Eq
        a, b = con.values
        assert isinstance(a, VarMember) and is_constant(b)
        assert not any(
            isinstance(arg, FreeParameter) for arg in var_args(a.var))
        initial_atoms.append(make_equal_predicate(a, b, var_map))
        initial_variables.add(a.var)
    if initial_variables != expanded_state_vars:
        raise ValueError(initial_variables - expanded_state_vars,
                         expanded_state_vars - initial_variables)
    return initial_atoms
def get_assignments(internal_params, var_map, eq_map):
    assign_map = {}
    for param in internal_params:
        if isinstance(param, FreeParameter):
            dtype = param.type
        elif isinstance(param, VarMember):
            dtype = var_map[var_name(param.var)].dtype
        else:
            raise ValueError(param)
        eq_param = eq_map.get(param, param)
        if not is_constant(eq_param):
            if eq_param not in assign_map:
                assign_map[eq_param] = Par('%s' % len(assign_map), dtype)
            assign_map[param] = assign_map[eq_param]
        else:
            assign_map[param] = dtype(eq_param)
    return assign_map
Beispiel #6
0
def make_con_constants(con):
    return [ty(arg) if is_constant(arg) else arg
            for ty, arg in zip(con.constraint.types, con.values)]