Commit dd39e021 authored by VIGNET Pierre's avatar VIGNET Pierre

[lib] CLU: Test variant constraints from text/DIMACS properties

parent fad1c384
......@@ -989,6 +989,117 @@ def init_forward_unfolding_solution_4(mcla):
assert unfolder.final_constraints == [[49]]
def test_init_forward_unfolding_solution_5(feed_mclanalyser):
"""Test variant_prop, dim_variant attributes of a query and their solutions
Query:
variant text: ["_h4 and _h2 and _h3", "_h5", "_h_0"]
variant DIMACS: [[[18], [16], [17]], [[19]], [[22]]]
Solution: D E I (not D E F I)
variant text: ["_h4 and _h2 and _h3", "_h5 and _h7", "_h_0"]
variant DIMACS: [[[18], [16], [17]], [[19], [21]], [[22]]]
Solution: D E G I
Note: 2 events on the second step (test the correct parsing)
.. note: Since we force the event h3 [F] to be activated; the condition F
no longer needs to be satisfied. The solution will be composed of the
following places: D E I instead of D E F I.
It is paradoxical to note that the entry E is still necessary but that
the condition F is no longer necessary...
"""
mcla = feed_mclanalyser
unfolder = mcla.unfolder
## Textual variant properties
query = MCLSimpleQuery(None, None, None)
query.variant_prop = ["_h4 and _h2 and _h3", "_h5", "_h_0"]
unfolder.init_with_query(query)
unfolder.init_forward_unfolding()
expected = [
[[18, -47], [16, -47], [-18, -16, 47], [47, -48], [17, -48], [-47, -17, 48], [48]],
[[19]],
[[22]]
]
assert unfolder._CLUnfolder__precomputed_variant_constraints == expected
# First step = First item of __precomputed_variant_constraints
assert unfolder._CLUnfolder__variant_constraints == expected[0]
# 2 auxiliary variables created
assert unfolder.shift_step == 48
## Search solutions
solutions = set(mcla.mac_search(query, 3))
print("solutions:", solutions)
found = {solution.activated_frontier for solution in solutions}
expected = {frozenset(["D", "E", "I"])}
assert found == expected
# Here, constraints have been shifted 2 times
expected = [
# Step 0: not modified
[18, -47], [16, -47], [-18, -16, 47], [47, -48], [17, -48], [-47, -17, 48], [48],
# Step 1: shited 1 time
[67],
# Step 2: shifted 2 times
[118]
]
assert unfolder._CLUnfolder__variant_constraints == expected
############################################################################
## DIMACS variant properties: D E I
# query = MCLSimpleQuery(None, None, None)
dimacs_variant_expected = [[[18], [16], [17]], [[19]], [[22]]]
# Reset query
query.variant_prop = None
query.dim_start = []
query.dim_variant = dimacs_variant_expected
unfolder.init_with_query(query)
unfolder.init_forward_unfolding()
assert unfolder._CLUnfolder__precomputed_variant_constraints == dimacs_variant_expected
# First step = First item of __precomputed_variant_constraints
assert unfolder._CLUnfolder__variant_constraints == dimacs_variant_expected[0]
# No auxiliary variables created
assert unfolder.shift_step == 46
## Search solutions
solutions = set(mcla.mac_search(query, 3))
print("solutions:", solutions)
found = {solution.activated_frontier for solution in solutions}
expected = {frozenset(["D", "E", "I"])}
assert found == expected
# Here, constraints have been shifted 2 times
assert unfolder._CLUnfolder__variant_constraints == [[18], [16], [17], [65], [114]]
############################################################################
## DIMACS variant properties: D E G I
query = MCLSimpleQuery(None, None, None)
dimacs_variant_expected = [[[18], [16], [17]], [[19], [21]], [[22]]]
query.dim_variant = dimacs_variant_expected
unfolder.init_with_query(query)
unfolder.init_forward_unfolding()
assert unfolder._CLUnfolder__precomputed_variant_constraints == dimacs_variant_expected
# First step = First item of __precomputed_variant_constraints
assert unfolder._CLUnfolder__variant_constraints == dimacs_variant_expected[0]
## Search solutions
solutions = set(mcla.mac_search(query, 3))
print("solutions:", solutions)
found = {solution.activated_frontier for solution in solutions}
expected = {frozenset(["D", "E", "G", "I"])}
assert found == expected
# Here, constraints have been shifted 2 times
assert unfolder._CLUnfolder__variant_constraints == [[18], [16], [17], [65], [67], [114]]
def test_init_forward_unfolding_variant_constraints(feed_mclanalyser):
"""Test variant_prop and dim_variant attributes of a query
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment