Ejemplo n.º 1
0
    def disjunction(goals: Set[Goal],
                    name: str = None,
                    description: str = None) -> Goal:
        if name is None:
            names = []
            for goal in goals:
                names.append(goal.name)
            names.sort()
            conj_name = ""
            for name in names:
                conj_name += name + "vv"
            name = conj_name[:-2]

        set_of_contracts = set()

        new_goal_world = None
        for g in goals:
            set_of_contracts.add(g.specification)
            if g.world is not None:
                if new_goal_world is None:
                    new_goal_world = g.world
                else:
                    if new_goal_world is not g.world:
                        raise GoalException(
                            "disjoining goals that have different 'variables'")

        try:
            new_contract = Contract.disjunction(set_of_contracts)

        except InconsistentContracts as e:

            raise GoalAlgebraOperationFail(
                goals=goals,
                operation=GoalFailOperations.conjunction,
                contr_ex=e)

        new_goal = Goal(name=name,
                        description=description,
                        specification=new_contract,
                        world=new_goal_world)

        return new_goal
Ejemplo n.º 2
0
patrol_b = b1 & OrderedPatrolling([b1, b2])

"""Inputs and Outputs"""
i_set, o_set = (patrol_a.typeset | patrol_b.typeset | z.typeset).extract_inputs_outputs()
i_typeset = Typeset(i_set)
o_typeset = Typeset(o_set)

"""Mutex"""
mutex_context = Atom.extract_mutex_rules(i_typeset)
mutex_locs = Atom.extract_mutex_rules(o_typeset)

"""Liveness"""
live_day = Atom.extract_liveness_rules(day.typeset)
live_night = Atom.extract_liveness_rules(night.typeset)

"""Topology"""
topology = Atom.extract_adjacency_rules(o_typeset)

c1 = Contract(assumptions=live_day, guarantees=patrol_a & mutex_locs & topology)
c2 = Contract(assumptions=live_night, guarantees=patrol_b & mutex_locs & topology)

print(c1)
print(c2)

# c = Contract(assumptions=c1.assumptions & c2.assumptions, guarantees=c1.guarantees | c2.guarantees)
c = Contract.disjunction({c1, c2})

print(c)
print(c1 <= c)
print(c2 <= c)