示例#1
0
    def compute_model(self):
        self.reset_model_assumptions(True)
        self.__model_builder.build_model()

        if len(self.__model_builder.valuation) == 0:
            defaults_to_retract = []

            for default_assumption in self.__defaults:
                self.reset_model_assumptions()

                self.__model_builder.add_assumptions([default_assumption])
                self.__model_builder.build_model()

                if len(self.__model_builder.valuation) == 0:
                    defaults_to_retract.append(default_assumption)

            if len(defaults_to_retract) == 0:
                raise Exception('this should not happen')
            if len(defaults_to_retract) >= 1:
                self.reset_model_assumptions(True)
                self.__model_builder.retract_assumptions(defaults_to_retract)
                self.__model_builder.build_model()

        valuation = list(self.__model_builder.valuation.items())

        return {read_expr(key) for (key, value) in valuation if value}
示例#2
0
    def test_argumentation_action_world(self):
        world = ActionWorld()
        create_actions(world)

        world.model.add(read_expr('StateLowConsumption'))
        world.model.add(read_expr('StateHot'))
        world.model.add(read_expr('StateHotOutside'))

        world.wanted_necessities[read_expr('StateWarm')] = 1
        world.wanted_necessities[read_expr('StateLowConsumption')] = 2

        procedure.start(world)

        plan_actions = [
            str(conflict.predicate) for conflict in argumentationcan.plan
        ]

        assert len(argumentationcan.plan) == 3
        assert 'SwitchCoolerOn' == plan_actions[0]
        assert 'SwitchCoolerOff' == plan_actions[1]
        assert 'CloseBlinds' == plan_actions[2]
def create_actions(world):
    effects_plus = [read_expr('Repaint')]
    action = Action('Repaint', [], effects_plus, [])
    world.actions.append(action)

    effects_plus = [read_expr('BurnOff')]
    action = Action('BurnOff', [], effects_plus, [])
    world.actions.append(action)

    effects_plus = [read_expr('WireBrush')]
    action = Action('WireBrush', [], effects_plus, [])
    world.actions.append(action)

    effects_plus = [read_expr('Sanding')]
    action = Action('Sanding', [], effects_plus, [])
    world.actions.append(action)

    effects_plus = [read_expr('FillerCompound')]
    action = Action('FillerCompound', [], effects_plus, [])
    world.actions.append(action)

    create_negative_actions(world)
示例#4
0
    def abduction(self, predicate) -> []:
        possible_causes = []

        for expression in self.__logic_program:
            if type(expression) is nltk.sem.logic.ImpExpression:
                if str(predicate) in [
                        str(element)
                        for element in self.get_atoms(expression.second)
                ]:
                    for cause in self.get_atoms(expression.first):
                        cause_predicate = read_expr(cause)
                        if cause_predicate not in possible_causes:
                            possible_causes.append(cause_predicate)

        return possible_causes
示例#5
0
 def __init__(self, name, preconditions, effects_plus, effects_minus):
     self.__name = name
     self.__predicate = read_expr(self.__name)
     self.__preconditions = preconditions
     self.__effects_minus = effects_minus
     self.__effects_plus = effects_plus
示例#6
0
    def abduction(self, predicate) -> []:
        possible_causes = [read_expr(action.name) for action in self.actions if
                           {predicate}.issubset(set(action.effects_plus))]

        return possible_causes
示例#7
0
def create_actions(world):
    preconditions = [
        read_expr('StateWarm'),
        read_expr('StateHotOutside'),
        read_expr('-StateWindowOpened')
    ]
    effects_plus = [read_expr('StateHot'), read_expr('StateWindowOpened')]
    effects_minus = [read_expr('StateWarm')]
    action = Action('OpenWindow', preconditions, effects_plus, effects_minus)
    world.actions.append(action)

    preconditions = [read_expr('StateHot'), read_expr('-StateCoolerOn')]
    effects_plus = [read_expr('StateWarm'), read_expr('StateCoolerOn')]
    effects_minus = [read_expr('StateHot')]
    action = Action('SwitchCoolerOn', preconditions, effects_plus,
                    effects_minus)
    world.actions.append(action)

    preconditions = []
    effects_plus = [
        read_expr('StateHighConsumption'),
        read_expr('StateCoolerOn')
    ]
    effects_minus = [read_expr('StateLowConsumption')]
    action = Action('SwitchCoolerOn', preconditions, effects_plus,
                    effects_minus)
    world.actions.append(action)

    preconditions = [read_expr('StateHot'), read_expr('-StateBlindsClosed')]
    effects_plus = [read_expr('StateWarm'), read_expr('StateBlindsClosed')]
    effects_minus = [read_expr('StateHot')]
    action = Action('CloseBlinds', preconditions, effects_plus, effects_minus)
    world.actions.append(action)

    preconditions = [read_expr('StateWarm'), read_expr('StateCoolerOn')]
    effects_plus = [read_expr('StateHot')]
    effects_minus = [read_expr('StateWarm')]
    action = Action('SwitchCoolerOff', preconditions, effects_plus,
                    effects_minus)
    world.actions.append(action)

    preconditions = []
    effects_plus = [read_expr('StateLowConsumption')]
    effects_minus = [
        read_expr('StateCoolerOn'),
        read_expr('StateHighConsumption')
    ]
    action = Action('SwitchCoolerOff', preconditions, effects_plus,
                    effects_minus)
    world.actions.append(action)

    preconditions = [
        read_expr('StateCold'),
        read_expr('StateColdOutside'),
        read_expr('-StateHeaterOn')
    ]
    effects_plus = [read_expr('StateWarm'), read_expr('StateHeaterOn')]
    effects_minus = [read_expr('StateCold')]
    action = Action('SwitchHeaterOn', preconditions, effects_plus,
                    effects_minus)
    world.actions.append(action)

    preconditions = [
        read_expr('StateCold'),
        read_expr('StateWarmOutside'),
        read_expr('-StateWindowOpened')
    ]
    effects_plus = [read_expr('StateWarm'), read_expr('StateWindowOpened')]
    effects_minus = [read_expr('StateCold')]
    action = Action('OpenWindow', preconditions, effects_plus, effects_minus)
    world.actions.append(action)
    def test_argumentation_logic_world(self, input):
        world = LogicWorld()
        create_actions(world)

        world.initial_model.add(read_expr('Mouldings'))
        world.initial_model.add(read_expr('SoftWood'))
        world.initial_model.add(read_expr('SeveralLayers'))

        world.defaults.append(read_expr('-WireBrush'))
        world.defaults.append(read_expr('-SoftWood'))
        world.defaults.append(read_expr('-WoodWrecked'))
        world.defaults.append(read_expr('-SeveralLayers'))

        world.logic_program.append(
            read_expr('BurnOff & -WoodWrecked -> NiceSurface'))
        world.logic_program.append(
            read_expr(
                'Sanding & -SeveralLayers & -WoodWrecked -> NiceSurface'))
        world.logic_program.append(
            read_expr('FillerCompound & -WoodWrecked -> NiceSurface'))
        world.logic_program.append(
            read_expr('Repaint & NiceSurface -> NiceDoors'))
        world.logic_program.append(read_expr('WoodWrecked -> -NiceSurface'))
        world.logic_program.append(
            read_expr('BurnOff & Mouldings & -WireBrush -> ToughWork'))
        world.logic_program.append(
            read_expr('WireBrush & SoftWood -> WoodWrecked'))

        world.wanted_necessities[read_expr('ToughWork')] = -10
        world.wanted_necessities[read_expr('NiceDoors')] = 20

        procedure.start(world)

        plan_actions = [
            str(conflict.predicate) for conflict in argumentationcan.plan
        ]

        assert len(argumentationcan.plan) == 7
        assert 'Repaint' == plan_actions[0]
        assert 'BurnOff' == plan_actions[1]
        assert 'WireBrush' == plan_actions[2]
        assert '-WireBrush' == plan_actions[3]
        assert '-BurnOff' == plan_actions[4]
        assert 'Sanding' == plan_actions[5]
        assert 'FillerCompound' == plan_actions[6]