コード例 #1
0
def _mk_guarded_vocabulary_object(symbol_table, guarded_vocabulary):
    # Encode the vocabulary
    fosorts, forelations, guard_forelations = guarded_vocabulary
    # Create the set of sort objects
    fo_sorts = set()
    for fosort in fosorts:
        fo_sort = FOSort(fosort)
        _new_entry(symbol_table, fosort, fo_sort)
        fo_sorts = fo_sorts | {fo_sort}
    # Boolean sort for defining predicates
    vdpbool = FOSort('Bool')
    # Create the set of function symbol objects
    fo_relations = set()
    for forelation, fosignature in forelations.items():
        fo_signature = tuple(
            [*[symbol_table[fosort] for fosort in fosignature], vdpbool])
        fo_relation = FOFunction(forelation, fo_signature)
        _new_entry(symbol_table, forelation, fo_relation)
        fo_relations = fo_relations | {fo_relation}
    # Create the set of guard relation objects
    guard_fo_relations = {
        symbol_table[guard_forelation]
        for guard_forelation in guard_forelations
    }
    # Create the GuardedVocabulary object
    guarded_vocabulary_object = GuardedVocabulary(fo_sorts, fo_relations,
                                                  guard_fo_relations)
    return guarded_vocabulary_object
コード例 #2
0
def _filter_relevant_guards(guard_fofunctions, quantified_sort):
    guard_forelations = set()
    for guard_fofunction in guard_fofunctions:
        signature = guard_fofunction.get_function_symbol_signature()
        input_signature = signature[:-1]
        output_signature = signature[-1]
        # Inputs must all be of sort quantified_sort
        input_signature_check = ((quantified_sort,) * len(input_signature) == input_signature)
        # Output must be Bool
        output_signature_check = (output_signature == FOSort('Bool'))
        if input_signature_check and output_signature_check:
            guard_forelations = guard_forelations | {guard_fofunction}
    return guard_forelations
コード例 #3
0
# This file defines a trivial vdp puzzle.
# It is used to test vdp solvers for simple bugs.
# The intended discriminator is 'pen is on table'

from vdp.vocabulary import FOSort, FOFunction, GuardedVocabulary
from vdp.fomodel import FOElement, FOModel
from vdp.vdppuzzle import VDPPuzzle

# defining the common vocabulary
# Create the vocabulary
# Sorts
vdpobject = FOSort('Object')
vdpbool = FOSort('Bool')
# Relations
cube = FOFunction('Cube', (vdpobject, vdpbool))
red = FOFunction('Red', (vdpobject, vdpbool))
green = FOFunction('Green', (vdpobject, vdpbool))
left = FOFunction('Left', (vdpobject, vdpobject, vdpbool))
right = FOFunction('Right', (vdpobject, vdpobject, vdpbool))
# No constants or functions in this signature.
# Make the vocabulary as a pair: ({set of sorts},{set of constants/functions/relations}).
vocabulary = GuardedVocabulary({vdpobject}, {cube, red, green, left, right},
                               {red, green})

# training_model_1
# Create the elements of each sort
o1 = FOElement('t11', vdpobject)
o2 = FOElement('t12', vdpobject)
elements = {vdpobject: {o1, o2}}
# Define the interpretation
cube_interpretation = {cube: {(o1, ): True, (o2, ): True}}
コード例 #4
0
    def setUp(self):
        # Create the vocabulary
        # Sorts
        vdpobject = FOSort('Object')
        vdplabel = FOSort('Label')
        vdpbool = FOSort('Bool')

        # Constants
        cat = FOFunction('cat', tuple([vdplabel]))
        sofa = FOFunction('sofa', tuple([vdplabel]))
        # Relations
        on = FOFunction('On', (vdpobject, vdpobject, vdpbool))
        labelof = FOFunction('LabelOf', (vdpobject, vdplabel, vdpbool))
        # No functions in this signature.
        # Make the vocabulary as a pair: ({set of sorts},{set of constants/functions/relations}).
        vocabulary = Vocabulary({vdpobject, vdplabel},
                                {cat, sofa, on, labelof})

        # Create the elements of each sort
        o1 = FOElement('o1', vdpobject)
        o2 = FOElement('o2', vdpobject)
        o3 = FOElement('o3', vdpobject)

        cat_label = FOElement('cat_label', vdplabel)
        sofa_label = FOElement('sofa_label', vdplabel)

        elements = {vdpobject: {o1, o2, o3}, vdplabel: {cat_label, sofa_label}}

        # Define the interpretation
        labelconst_interpretation = {cat: cat_label, sofa: sofa_label}
        labelof_interpretation = {
            labelof: {
                (o1, cat_label): True,
                (o2, cat_label): True,
                (o3, sofa_label): True,
                (o1, sofa_label): False,
                (o2, sofa_label): False,
                (o3, cat_label): False
            }
        }
        on_interpretation = {
            on: {
                (o1, o3): True,
                (o2, o3): True,
                (o1, o2): False,
                (o3, o1): False,
                (o3, o2): False
            }
        }
        interpretation = {
            **labelconst_interpretation,
            **labelof_interpretation,
            **on_interpretation
        }

        # Create the FO Model
        model = FOModel(vocabulary, elements, interpretation)

        # Set variables to use in tests
        self.vdpobject, self.vdplabel = vdpobject, vdplabel
        self.cat, self.sofa = cat, sofa
        self.on, self.labelof = on, labelof
        self.o1, self.o2, self.o3 = o1, o2, o3
        self.model = model