Example #1
0
    def test_unsat_euc_strengthening(self):
        """ Test case where EUC Strengthening makes model unsat. """
        fname = os.path.join(self.data_dir, "euc_strengthening_unsat.orm")

        model = NormaLoader(fname).model
        self.assertIsNotNone(
            ORMMinusModel(model=model, experimental=False).solution)

        model = NormaLoader(fname).model
        self.assertIsNone(
            ORMMinusModel(model=model, experimental=True).solution)
Example #2
0
    def test_unsat_subset(self):
        """ Test a model that is unsatisfiable due to a subset constraint. """
        fname = TestDataLocator.path("subset_unsat.orm")

        model = NormaLoader(fname).model
        ormminus = ORMMinusModel(model, ubound=100, experimental=True)
        self.assertIsNone(ormminus.solution)

        model = NormaLoader(fname).model
        ormminus = ORMMinusModel(model, ubound=100, experimental=False)
        self.assertIsNotNone(ormminus.solution)
Example #3
0
    def test_unsat_overlapping_iuc(self):
        """ Test case where OverlappingIFCTransform makes model unsat. """
        fname = os.path.join(self.data_dir,
                             "overlapping_iuc_unsat_if_strengthened.orm")

        model = NormaLoader(fname).model
        self.assertIsNotNone(
            ORMMinusModel(model=model, experimental=False).solution)

        model = NormaLoader(fname).model
        self.assertIsNone(
            ORMMinusModel(model=model, experimental=True).solution)
Example #4
0
def check_or_populate(model, args):
    """ Check or populate the model, as requested. """
    try:
        model = ORMMinusModel(model,
                              max(1, args.ubound),
                              experimental=args.experimental)

        if model.solution == None:
            if model.strengthened:
                print "Model satisfiability cannot be determined."
            else:
                print "Model is unsatisfiable."
        elif args.populate:
            pop = Population(model)
            dirname = args.directory.strip()

            if dirname == '':
                pop.write_stdout()
            else:
                try:
                    # Pass the original, untransformed model to the GENERATOR
                    original_model = import_model(args.filename, args)
                    GENERATOR[args.generator](original_model, pop, dirname)
                except:
                    print "Model is satisfiable."
                    print "Cannot write population to " + dirname
                    if args.debug: raise
        else:
            print "Model is satisfiable."
    except Exception as exception:
        text = "populate" if args.populate else "check"
        logging.error("Failed to %s the model: %s", text, exception)
        logging.debug("Stack trace:", exc_info=sys.exc_info())
        sys.exit(2)
Example #5
0
    def test_unsat_join_equality(self):
        """ Test a model that is unsatisfiable due to a join equality constraint. """
        fname = TestDataLocator.path("join_equality_unsat.orm")

        model = NormaLoader(fname).model
        ormminus = ORMMinusModel(model, ubound=100, experimental=True)

        self.assertEquals(ormminus.ignored, [])
        self.assertIsNone(ormminus.solution)

        model = NormaLoader(fname).model
        eq = model.constraints.get("EQ")
        ormminus = ORMMinusModel(model, ubound=100, experimental=False)

        self.assertEquals(ormminus.ignored, [eq])
        self.assertIsNotNone(ormminus.solution)
Example #6
0
    def test_config_file(self):
        """ Test contents of config.py file. """
        model = NormaLoader(TestData.path("empty_model.orm")).model
        pop = Population(ORMMinusModel(model))

        tempdir = os.path.join(self.tempdir, "test_config_file")

        logiql = LogiQL(model, pop, tempdir, make=False)

        config_file = os.path.join(tempdir, "config.py")

        self.assertTrue(os.path.exists(config_file))

        with open(config_file, "r") as infile:
            actual = infile.readlines()

        expected = [
            "from lbconfig.api import *\n",
            "lbconfig_package('test_config_file', version='0.1', default_targets=['lb-libraries'])\n",
            "depends_on(logicblox_dep)\n",
            "lb_library(name='test_config_file', srcdir='.')\n",
            "check_lb_workspace(name='test_config_file', libraries=['test_config_file'])\n"
        ]

        self.assertItemsEqual(actual, expected)
Example #7
0
 def test_unsat_subtype_with_value_constraint(self):
     """ Test a model that is unsatisfiable because the intersection of the
         value constraints for the root type and subtype is empty. """
     fname = TestDataLocator.path("unsat_subtype_with_value_constraint.orm")
     model = NormaLoader(fname).model
     ormminus = ORMMinusModel(model, ubound=30)
     self.assertIsNone(ormminus.solution)
Example #8
0
    def test_unsat_role_and_value_type_value_constraint(self):
        """ Test unsatisfiable combination of role and value type value constraint. """
        fname = os.path.join(
            self.data_dir,
            "role_value_constraint_and_type_value_constraint.orm")
        model = NormaLoader(fname).model
        ormminus = ORMMinusModel(model, ubound=10)

        self.assertItemsEqual(ormminus.ignored, [])

        a_id = model.object_types.get("A_id")
        cc1 = model.constraints.get("CC1")
        rvc1 = model.constraints.get("RVC1")
        vc1 = model.constraints.get("VC1")

        value_cons = model.constraints.of_type(Constraint.ValueConstraint)
        self.assertEquals(len(value_cons), 2)

        self.assertItemsEqual(value_cons, [rvc1, vc1])
        self.assertEquals(rvc1.covers, [a_id])
        self.assertEquals(vc1.covers, [a_id])

        self.assertItemsEqual(a_id.covered_by, [rvc1, vc1, cc1])

        # Key test 1: domain of a_id is intersection of two value constraints
        self.assertItemsEqual(a_id.domain.draw(10), [1, 2])

        # Key test 2: model is unsat due to cardinality constraint
        self.assertIsNone(ormminus.solution)
Example #9
0
    def test_types_without_subtype(self):
        """ Test writing out of types without any subtypes present. """
        model = NormaLoader(TestData.path("objectification.orm")).model
        pop = Population(ORMMinusModel(model))

        tempdir = os.path.join(self.tempdir, "test_types_without_subtype")

        logiql = LogiQL(model, pop, tempdir, make=False)

        types_file = os.path.join(tempdir, "model", "types.logic")

        with open(types_file, 'r') as infile:
            actual = infile.readlines()

        expected = [
            "block(`types) {\n", "  export(`{\n",
            "    A(x), A_constructor(x: v) -> string(v).\n", "\n",
            "    B(x), B_constructor(x: v) -> string(v).\n", "\n",
            "    AHasB(x), AHasB_constructor(x: v) -> string(v).\n", "\n",
            "    ALikesB(x), ALikesB_constructor(x: v) -> string(v).\n", "\n",
            "    AEnjoysB(x), AEnjoysB_constructor(x: v) -> string(v).\n",
            "\n", "  })\n", "} <-- .\n"
        ]

        self.assertItemsEqual(actual, expected)
Example #10
0
    def test_subtypes(self):
        """ Test writing out of subtypes. """
        model = NormaLoader(TestData.path("object_type_tests.orm")).model
        pop = Population(ORMMinusModel(model))

        tempdir = os.path.join(self.tempdir, "test_subtypes")

        logiql = LogiQL(model, pop, tempdir, make=False)

        types_file = os.path.join(tempdir, "model", "types.logic")

        with open(types_file, 'r') as infile:
            actual = [line for line in infile.readlines() if line != "\n"]

        expected = [
            "block(`types) {\n", "  export(`{\n",
            "    A(x), A_constructor(x: v) -> string(v).\n",
            "    A_id(x), A_id_constructor(x: v) -> string(v).\n",
            "    B(x) -> A(x).\n", "    C(x) -> B(x).\n",
            "    CHasV1(x), CHasV1_constructor(x: v) -> string(v).\n",
            "    V1(x), V1_constructor(x: v) -> string(v).\n",
            "    V2(x), V2_constructor(x: v) -> string(v).\n",
            "    V1HasV2(x), V1HasV2_constructor(x: v) -> string(v).\n",
            "    D(x), D_constructor(x: v) -> string(v).\n",
            "    D_id(x), D_id_constructor(x: v) -> string(v).\n", "  }),\n",
            "  clauses(`{\n", "    lang:entity(`B).\n",
            "    lang:entity(`C).\n", "  })\n", "} <-- .\n"
        ]

        self.assertItemsEqual(actual, expected)
Example #11
0
    def test_objectification_inequalities(self):
        """ Test a model with objectifications. """
        fname = os.path.join(self.data_dir, "objectification.orm")
        model = NormaLoader(fname).model
        ormminus = ORMMinusModel(model, ubound=10)

        # Confirm NORMA doesn't copy the cardinality constraint to the fact type
        self.assertEquals(
            len(model.constraints.of_type(Constraint.CardinalityConstraint)),
            1)

        # Check for existence of expected inequalities
        actual = set([ineq.tostring() for ineq in ormminus._ineqsys])
        self.assertIn("ObjectTypes.AHasB <= FactTypes.AHasB", actual)
        self.assertIn("FactTypes.AHasB <= ObjectTypes.AHasB", actual)
        self.assertIn("ObjectTypes.ALikesB <= FactTypes.ALikesB", actual)
        self.assertIn("FactTypes.ALikesB <= ObjectTypes.ALikesB", actual)
        self.assertIn("ObjectTypes.AEnjoysB <= FactTypes.AEnjoysB", actual)
        self.assertIn("FactTypes.AEnjoysB <= ObjectTypes.AEnjoysB", actual)

        # Check that solution has expected relations
        self.assertEquals(ormminus.solution["ObjectTypes.AHasB"],
                          ormminus.solution["FactTypes.AHasB"])
        self.assertEquals(ormminus.solution["ObjectTypes.AHasB"], 10)

        self.assertEquals(ormminus.solution["ObjectTypes.ALikesB"],
                          ormminus.solution["FactTypes.ALikesB"])
        self.assertEquals(ormminus.solution["ObjectTypes.ALikesB"], 5)

        self.assertEquals(ormminus.solution["ObjectTypes.AEnjoysB"],
                          ormminus.solution["FactTypes.AEnjoysB"])
        self.assertEquals(ormminus.solution["ObjectTypes.AEnjoysB"], 3)
Example #12
0
    def test_import_types(self):
        """ Test writing type import logic. """
        model = NormaLoader(TestData.path("object_type_tests_2.orm")).model
        pop = Population(ORMMinusModel(model))

        tempdir = os.path.join(self.tempdir, "test_import_types")
        logiql = LogiQL(model, pop, tempdir, make=False)

        actual = file_lines(os.path.join(tempdir, "import.logic"))

        AFile = os.path.join(tempdir, "import", "ObjectTypes.A.csv")
        BFile = os.path.join(tempdir, "import", "ObjectTypes.B.csv")

        expected = [
            "// Import code for A\n",
            "_import_types_A[offset] = v -> int(offset), string(v).\n",
            'lang:physical:filePath[`_import_types_A] = "{0}".\n'.format(
                AFile),
            'lang:physical:fileMode[`_import_types_A] = "import".\n',
            "+model:types:A(x), +model:types:A_constructor(x: v) <- _import_types_A[_] = v.\n",

            # Note here the constructor is A_constructor because B is a subtype of A
            "// Import code for B\n",
            "_import_types_B[offset] = v -> int(offset), string(v).\n",
            'lang:physical:filePath[`_import_types_B] = "{0}".\n'.format(
                BFile),
            'lang:physical:fileMode[`_import_types_B] = "import".\n',
            "+model:types:B(x), +model:types:A_constructor(x: v) <- _import_types_B[_] = v.\n"
        ]

        self.assertItemsEqual(actual, expected)
Example #13
0
 def test_unsat_subtype_due_to_card_constraint(self):
     """ Test a model that is unsatisfiable because the cardinality of the 
         root type is less than required for one of the subtypes. """
     fname = TestDataLocator.path(
         "unsat_subtype_due_to_card_constraint.orm")
     model = NormaLoader(fname).model
     ormminus = ORMMinusModel(model, ubound=30)
     self.assertIsNone(ormminus.solution)
Example #14
0
    def test_fact_type_parts(self):
        """ Test that fact type parts (e.g. roles vs role sequences) are 
            correctly identified. """
        fname = os.path.join(self.data_dir, "fact_type_parts.orm")
        model = NormaLoader(fname).model
        ormminus = ORMMinusModel(model=model, ubound=5)

        fact_type = model.fact_types.get("V1HasV2HasV3")
        role1, role2, role3 = fact_type.roles
        self.assertItemsEqual(ormminus.get_parts(fact_type),
                              [role1, role2, role3])

        fact_type = model.fact_types.get("V4HasV5")
        role1, role2 = fact_type.roles
        cons = model.constraints.get("IUC4")
        self.assertItemsEqual(ormminus.get_parts(fact_type), [cons, role2])

        fact_type = model.fact_types.get("V6HasV7")
        cons = model.constraints.get("IUC5")
        self.assertItemsEqual(ormminus.get_parts(fact_type), [cons])

        fact_type = model.fact_types.get("V8HasV9")
        cons = model.constraints.get("IFC1")
        self.assertItemsEqual(ormminus.get_parts(fact_type), [cons])

        fact_type = model.fact_types.get("Seven_ary")
        roles = fact_type.roles
        iuc = model.constraints.get("IUC11")
        ifc = model.constraints.get("IFC2")
        self.assertItemsEqual(ormminus.get_parts(fact_type),
                              [iuc, ifc, roles[3], roles[6]])
Example #15
0
    def test_unsat_equality(self):
        """ Test a model that is unsatisfiable due to an equality constraint. """
        fname = TestDataLocator.path("equality_unsat.orm")

        model = NormaLoader(fname).model
        ormminus = ORMMinusModel(model, ubound=100, experimental=True)
        self.assertIsNone(ormminus.solution)

        actual = [ineq.tostring() for ineq in ormminus._ineqsys]

        self.assertIn("FactTypes.ALovesB.Roles.A <= FactTypes.AHasB.Roles.A",
                      actual)
        self.assertIn("FactTypes.AHasB.Roles.A <= FactTypes.ALovesB.Roles.A",
                      actual)

        model = NormaLoader(fname).model
        ormminus = ORMMinusModel(model, ubound=100, experimental=False)
        self.assertIsNotNone(ormminus.solution)
Example #16
0
    def test_disjunctive_mandatory(self):
        """ Test that disjunctive mandatory constraint is ignored. """
        fname = os.path.join(self.data_dir, "disjunctive_mandatory.orm")
        model = NormaLoader(fname).model
        ormminus = ORMMinusModel(model=model)

        actual = [cons.name for cons in ormminus.ignored]
        expected = ["InclusiveOrConstraint1"]

        self.assertItemsEqual(actual, expected)
Example #17
0
    def test_create_directory_exception(self):
        """ Test exception case in _create_directory. """
        model = Model()
        pop = Population(ORMMinusModel(model))

        try:
            handle, filename = tempfile.mkstemp()
            with self.assertRaises(OSError):  # filename is a file, not a dir
                LogiQL(model, pop, filename, make=False)
        finally:
            os.remove(filename)
Example #18
0
    def test_ignored_value_constraint(self):
        """ Test that role value constraints are ignored. """
        fname = os.path.join(self.data_dir,
                             "test_value_type_value_constraint.orm")
        model = NormaLoader(fname).model
        ormminus = ORMMinusModel(model=model)
        solution = ormminus.solution

        actual = [cons.name for cons in ormminus.ignored]
        expect = ["RVC_ET3", "RVC_ET4", "RVC_ET5", "RVC_VT2"]
        self.assertItemsEqual(actual, expect)
Example #19
0
    def test_ignored_subset(self):
        """ Test a model with an ignored subset constraint. """
        fname = TestDataLocator.path("subset_with_incompat_superset.orm")
        model = NormaLoader(fname).model

        subset = model.constraints.get("SUB1")

        ormminus = ORMMinusModel(model, ubound=100, experimental=True)
        solution = ormminus.solution

        self.assertIsNotNone(solution)
        self.assertItemsEqual(ormminus.ignored, [subset])
Example #20
0
    def test_empty_model(self):
        """ Test that empty model produces empty model directory. """
        model = NormaLoader(TestData.path("empty_model.orm")).model
        pop = Population(ORMMinusModel(model))

        tempdir = os.path.join(self.tempdir, "test_empty_model")

        logiql = LogiQL(model, pop, tempdir, make=False)

        model_dir = os.path.join(tempdir, "model")
        self.assertTrue(os.path.isdir(model_dir))
        self.assertEquals(0, len(os.listdir(model_dir)))
Example #21
0
    def setUp(self):
        self.data_dir = TestDataLocator.get_data_dir()
        self.maxDiff = None

        # Log capturing
        self.log = LogCapture()
        self.log.logformat = '%(levelname)s: %(message)s'
        self.log.begin()

        fname = os.path.join(self.data_dir, "paper_has_author.orm")
        model = NormaLoader(fname).model
        self.paper_has_author = ORMMinusModel(model=model)
        self.solution1 = self.paper_has_author.solution
Example #22
0
    def test_unbounded_freq_constraint(self):
        """ Test a model with an unbounded frequency constraint. """
        fname = os.path.join(self.data_dir,
                             "unbounded_frequency_constraint.orm")
        model = NormaLoader(fname).model
        ormminus = ORMMinusModel(model)

        cons = model.constraints.get("IFC1")
        self.assertEquals(cons.max_freq, float('inf'))
        self.assertEquals(cons.min_freq, 5)

        solution = ormminus.solution
        size = ORMMinusModel.DEFAULT_SIZE
        self.assertEquals(solution["Constraints.IFC1"], size / 5)
        self.assertEquals(solution["FactTypes.AHasB"], size)
Example #23
0
    def test_cardinality_inequalities(self):
        """ Test that correct cardinality constraint inequalities are generated. """
        self.log.beforeTest(None)
        fname = os.path.join(self.data_dir, "test_cardinality_constraint.orm")
        model = NormaLoader(fname, deontic=True).model
        ormminus = ORMMinusModel(model)

        actual = set([ineq.tostring() for ineq in ormminus._ineqsys])

        expected = [
            "ObjectTypes.A <= " + str(ORMMinusModel.DEFAULT_SIZE),
            "ObjectTypes.B <= " + str(ORMMinusModel.DEFAULT_SIZE),
            "FactTypes.AExists.Roles.A <= ObjectTypes.A",
            "FactTypes.AExists.Roles.A <= FactTypes.AExists",
            "FactTypes.AExists <= Constraints.IUC1",
            "Constraints.IUC1 <= FactTypes.AExists",
            "Constraints.IUC1 <= FactTypes.AExists.Roles.A",
            "FactTypes.AExists.Roles.A <= Constraints.IUC1",
            "ObjectTypes.A <= FactTypes.AExists.Roles.A",
            "FactTypes.BDances.Roles.B <= ObjectTypes.B",
            "FactTypes.BDances.Roles.B <= FactTypes.BDances",
            "FactTypes.BDances <= Constraints.IUC2",
            "Constraints.IUC2 <= FactTypes.BDances",
            "Constraints.IUC2 <= FactTypes.BDances.Roles.B",
            "FactTypes.BDances.Roles.B <= Constraints.IUC2",
            "FactTypes.BHopes.Roles.B <= ObjectTypes.B",
            "FactTypes.BHopes.Roles.B <= FactTypes.BHopes",
            "FactTypes.BHopes <= Constraints.IUC3",
            "Constraints.IUC3 <= FactTypes.BHopes",
            "Constraints.IUC3 <= FactTypes.BHopes.Roles.B",
            "FactTypes.BHopes.Roles.B <= Constraints.IUC3",
            "ObjectTypes.B <= FactTypes.BDances.Roles.B + FactTypes.BHopes.Roles.B",
            "0 <= ObjectTypes.A", "ObjectTypes.A <= 4",
            "4 <= FactTypes.AExists.Roles.A", "FactTypes.AExists.Roles.A <= 7",
            "2 <= ObjectTypes.B", "4 <= FactTypes.BHopes.Roles.B",
            "FactTypes.BHopes.Roles.B <= 4"
        ]
        self.assertItemsEqual(actual, expected)

        self.assertItemsEqual(ormminus.ignored, [model.constraints.get("CC5")])

        self.assertItemsEqual(self.log.formatLogRecords(), [
            "WARNING: 1 constraint was ignored while checking the model.",
            "INFO: Ignored CardinalityConstraint named CC5."
        ])

        self.log.afterTest(None)
Example #24
0
    def test_create_directories(self):
        """ Test that appropriate directories get created. """
        model = Model()
        pop = Population(ORMMinusModel(model))

        tempdir = os.path.join(self.tempdir, "test_create_directories")

        # Directory doesn't exist before call
        self.assertFalse(os.path.isdir(tempdir))

        logiql = LogiQL(model, pop, tempdir, make=False)

        # Directory and expected sub-directories now exist
        self.assertTrue(os.path.isdir(tempdir))
        self.assertEquals(tempdir, logiql.rootdir)
        self.assertTrue(os.path.isdir(logiql.importdir))
        self.assertTrue(os.path.isdir(logiql.logicdir))
Example #25
0
    def test_sat_subset(self):
        """ Test a model that is satisfiable with subset constraints. """
        fname = TestDataLocator.path("subset_multiple_roots.orm")
        model = NormaLoader(fname).model
        ormminus = ORMMinusModel(model, ubound=100, experimental=True)
        solution = ormminus.solution

        self.assertIsNotNone(solution)
        self.assertItemsEqual(ormminus.ignored, [])

        self.assertEquals(solution["FactTypes.ALikesB.Roles.A"], 7)
        self.assertEquals(solution["FactTypes.CLikesA.Roles.A"], 7)
        self.assertEquals(solution["FactTypes.ASmokes.Roles.A"], 7)
        self.assertEquals(solution["FactTypes.AExists.Roles.A"], 6)
        self.assertEquals(solution["FactTypes.AHasB.Roles.A"], 6)
        self.assertEquals(solution["ObjectTypes.A"], 7)

        self.assertEquals(solution["FactTypes.ALikesB.Roles.B"], 7)
        self.assertEquals(solution["FactTypes.AHasB.Roles.B"], 6)
        self.assertEquals(solution["ObjectTypes.B"], 7)

        self.assertEquals(solution["ObjectTypes.C"], 100)

        # Check inequalities
        actual = [ineq.tostring() for ineq in ormminus._ineqsys]

        # Check IDMC for A
        filt = lambda x: x.startswith("ObjectTypes.A <=")
        self.assertItemsEqual(filter(filt, actual), [
            "ObjectTypes.A <= 100",
            "ObjectTypes.A <= FactTypes.ALikesB.Roles.A"
        ])

        # Check IDMC for B
        filt = lambda x: x.startswith("ObjectTypes.B <=")
        self.assertItemsEqual(filter(filt, actual), [
            "ObjectTypes.B <= 100", "ObjectTypes.B <= 7",
            "ObjectTypes.B <= FactTypes.ALikesB.Roles.B + FactTypes.BExists.Roles.B"
        ])

        # Confirm R < S inequalities present
        self.assertIn("FactTypes.AHasB.Roles.A <= FactTypes.ALikesB.Roles.A",
                      actual)
        self.assertIn("FactTypes.AHasB.Roles.B <= FactTypes.ALikesB.Roles.B",
                      actual)
Example #26
0
    def test_implicit_disjunctive_on_entities(self):
        """ Test implicit disjunctive mandatory constraint inequality on
            entity types. """
        fname = os.path.join(self.data_dir, "implicit_disjunctive_test_2.orm")
        model = NormaLoader(fname).model
        ormminus = ORMMinusModel(model=model)
        solution = ormminus.solution

        actual = set([ineq.tostring() for ineq in ormminus._ineqsys])

        expected = [
            "ObjectTypes.A <= " + str(ORMMinusModel.DEFAULT_SIZE),
            "ObjectTypes.A_id <= " + str(ORMMinusModel.DEFAULT_SIZE),
            "ObjectTypes.Boolean <= 2",
            "FactTypes.AHasBoolean.Roles.R1 <= ObjectTypes.A",
            "FactTypes.AHasBoolean.Roles.R1 <= FactTypes.AHasBoolean",
            "FactTypes.AHasBoolean.Roles.R2 <= ObjectTypes.Boolean",
            "FactTypes.AHasBoolean.Roles.R2 <= FactTypes.AHasBoolean",
            "FactTypes.AHasAId.Roles.R1 <= ObjectTypes.A",
            "FactTypes.AHasAId.Roles.R1 <= FactTypes.AHasAId",
            "FactTypes.AHasAId.Roles.R2 <= ObjectTypes.A_id",
            "FactTypes.AHasAId.Roles.R2 <= FactTypes.AHasAId",
            "FactTypes.AHasAId <= Constraints.IUC1",
            "Constraints.IUC1 <= FactTypes.AHasAId",
            "Constraints.IUC1 <= FactTypes.AHasAId.Roles.R2",
            "FactTypes.AHasAId.Roles.R2 <= Constraints.IUC1",
            "FactTypes.AHasAId <= Constraints.IUC2",
            "Constraints.IUC2 <= FactTypes.AHasAId",
            "Constraints.IUC2 <= FactTypes.AHasAId.Roles.R1",
            "FactTypes.AHasAId.Roles.R1 <= Constraints.IUC2",
            "FactTypes.AHasBoolean <= Constraints.IUC3",
            "Constraints.IUC3 <= FactTypes.AHasBoolean",
            "Constraints.IUC3 <= FactTypes.AHasBoolean.Roles.R2",
            "FactTypes.AHasBoolean.Roles.R2 <= Constraints.IUC3",
            "ObjectTypes.A <= FactTypes.AHasAId.Roles.R1",
            "ObjectTypes.A <= FactTypes.AHasBoolean.Roles.R1",
            "ObjectTypes.A_id <= FactTypes.AHasAId.Roles.R2",
            "ObjectTypes.Boolean <= FactTypes.AHasBoolean.Roles.R2",
            "FactTypes.AHasAId <= Constraints.IUC1 * Constraints.IUC2",
            "FactTypes.AHasBoolean <= Constraints.IUC3 * FactTypes.AHasBoolean.Roles.R1"
        ]

        self.assertItemsEqual(actual, expected)

        self.assertEquals(solution["ObjectTypes.A"], 2)
Example #27
0
    def test_idmc_with_disjunctive_ref_old_approach(self):
        """ Test implicit disjunctive mandatory constraint inequality when
            entity type has disjunctive ref scheme, using the old approach. """
        fname = os.path.join(self.data_dir, "disjunctive_reference_scheme.orm")
        model = NormaLoader(fname).model
        ormminus = ORMMinusModel(model=model, experimental=False)

        # Confirm IDMC inequality includes all roles played by A
        actual = set([ineq.tostring() for ineq in ormminus._ineqsys])
        euc = model.constraints.get("EUC")
        a = model.object_types.get("A")

        self.assertIn(
            "ObjectTypes.A <= FactTypes.AHasB.Roles.A + FactTypes.AHasC.Roles.A",
            actual)
        self.assertIsNone(a.identifying_constraint)
        self.assertIsNone(euc.identifier_for)
        self.assertEquals(a.ref_roles, [])
Example #28
0
    def test_ubound_on_object_types(self):
        """ Test upper bound on object type variables.  """
        fname = os.path.join(self.data_dir, "data_types.orm")
        model = NormaLoader(fname).model
        ormminus = ORMMinusModel(model=model, ubound=sys.maxsize)
        solution = ormminus.solution

        bool_obj = model.object_types.get("B")
        bool_var = ormminus._variables[bool_obj]
        self.assertEquals(bool_var.upper, 2)

        int_obj = model.object_types.get("D")
        int_var = ormminus._variables[int_obj]
        self.assertEquals(int_var.upper, sys.maxsize)

        time_obj = model.object_types.get("J")
        time_var = ormminus._variables[time_obj]
        self.assertEquals(time_var.upper, 60 * 24)
Example #29
0
    def test_remove_ignored_constraints(self):
        """ Test that ignored constraints are removed. """
        model = NormaLoader(TestData.path("omitted_constraints.orm")).model
        model2 = ORMMinusModel(model)
        pop = Population(model2)

        tempdir = os.path.join(self.tempdir, "test_remove_ignored_constraints")
        logiql = LogiQL(model, pop, tempdir, make=False)

        self.assertEquals(len(logiql.constraints), 4)

        actual = [c.name for c in logiql.constraints]
        expected = [
            "InternalUniquenessConstraint1", "InternalUniquenessConstraint2",
            "InternalUniquenessConstraint3", "InternalUniquenessConstraint4"
        ]

        self.assertItemsEqual(actual, expected)
Example #30
0
    def test_subtype_inequalities(self):
        """ Test that expected subtype inequalities are created. """
        fname = TestDataLocator.path("value_constraints_on_subtypes.orm")
        model = NormaLoader(fname).model
        ormminus = ORMMinusModel(model, ubound=30)

        actual = set([ineq.tostring() for ineq in ormminus._ineqsys])

        self.assertIn("ObjectTypes.J <= ObjectTypes.I", actual)
        self.assertIn("ObjectTypes.L <= ObjectTypes.J", actual)
        self.assertIn("ObjectTypes.K <= ObjectTypes.I", actual)
        self.assertIn("ObjectTypes.M <= ObjectTypes.J", actual)
        self.assertIn("ObjectTypes.M <= ObjectTypes.K", actual)

        self.assertEquals(ormminus.solution["ObjectTypes.I"], 21)
        self.assertEquals(ormminus.solution["ObjectTypes.J"], 21)
        self.assertEquals(ormminus.solution["ObjectTypes.K"], 11)
        self.assertEquals(ormminus.solution["ObjectTypes.M"], 11)