def check_diagram(sparse_diagram, ext_possible_chords, ext_min, ext_max):

    # Skip diagrams with 1, 2 or 3 moves
    compressed_diag = get_compressed_diagram(sparse_diagram)
    if (contains_one_move(compressed_diag) or
        contains_two_move(compressed_diag) or
        contains_three_move(compressed_diag)):
        return (sparse_diagram, [], [])

    # Find the permitted single chord extensions
    invariant_chords = get_invariant_chords_for_diagram(
            sparse_diagram, ext_possible_chords, diagram_filter=diagram_filter,
            doScale=False)
    if len(invariant_chords) == 0:
        # Skip diagrams with no invariant chords
        return (sparse_diagram, invariant_chords, [])

    # Test planarability of sparse_diag plus combinations of min..max chords
    planarable_extension_sets = []
    for n_extensions in range(ext_min, ext_max+1):
        for extensions in combinations(invariant_chords, n_extensions):
            # Skip extension chord pair if they share any nodes
            uniq_nodes = {node for ext in extensions for node in ext}
            if len(uniq_nodes) != n_extensions * 2:
                continue
            diag = Diagram(sparse_diagram + list(extensions))
            if diag.is_planarable():
                planarable_extension_sets.append((timestamp(), extensions))

    return (sparse_diagram, invariant_chords, planarable_extension_sets)
def check_123_planarable(diagram):

    # Skip diagrams with 1, 2 or 3 moves
    if (contains_one_move(diagram) or
        contains_two_move(diagram) or
        contains_three_move(diagram)):
        return (diagram, False)

    # Test planarability of sparse_diag
    diag = Diagram(diagram)
    rv = diag.is_planarable()

    return (diagram, rv)
def check_planarable_2move(diagram):
    # Scale up by 3 to leave 2 open nodes between each existing node
    diagx3 = Diagram(diagram)
    diagx3.scale(3)

    # Find parallel chord to each existing chord
    n_chords = diagx3.size()
    chords = [ get_parallel_extension(chord, n_chords*2*3) for chord in diagx3 ]

    n_extensions = n_chords # Only check with 1 extension per chord
    chord_combos = combinations(chords, n_extensions)
    for chord_combo in chord_combos:
        # Append this chord_combo to new copy of diagx3
        test_diag = Diagram(diagx3)
        for chord in chord_combo:
            test_diag.append(chord)
        if test_diag.is_planarable():
            return (diagram, test_diag, chord_combo)

    return (diagram, None, None)
 def test_Diagram_is_planarable_5_chord_regression2(self):
     "Rotation of test 5_chord_regression1"
     # This is False
     diag = Diagram([[1, 7], [2, 3], [4, 9], [5, 8], [6, 10]])
     self.assertFalse(diag.is_planarable())
 def test_Diagram_is_planarable_5_chord_regression1(self):
     diag = Diagram([(1, 2), (3, 8), (4, 7), (5, 9), (6, 10)])
     self.assertFalse(diag.is_planarable())
 def test_Diagram_is_planarable_4_chord_test1(self):
     diag = Diagram([(1, 4), (2, 3), (5, 8), (6, 7)])
     self.assertTrue(diag.is_planarable())
 def test_Diagram_is_planarable_4_chord_regression3(self):
     diag = Diagram([(1, 8), (2, 6), (3, 5), (4, 7)])
     self.assertFalse(diag.is_planarable())
Example #8
0
def check_planarable(diagram):
    # Test planarability of diagram
    diag = Diagram(diagram)
    rv = diag.is_planarable()

    return (diagram, rv)
 def test_Diagram_is_planarable_6_chord_regression4(self):
     diag = Diagram([[1, 10], [2, 7], [3, 6], [4, 13], [5, 12], [8, 11],
                     [9, 14]])
     self.assertTrue(diag.is_planarable())
 def test_Diagram_is_planarable_6_chord_regression1(self):
     # This is True
     diag = Diagram([[1, 8], [2, 9], [3, 12], [4, 7], [5, 10], [6, 11]])
     self.assertTrue(diag.is_planarable())
 def test_Diagram_is_planarable_3_chord_regression1(self):
     diag = Diagram([(1, 4), (2, 6), (3, 5)])
     self.assertFalse(diag.is_planarable())
 def test_Diagram_is_planarable_3_chord_positive(self):
     diag = Diagram([(1, 2), (3, 6), (4, 5)])
     self.assertTrue(diag.is_planarable())
 def test_Diagram_is_planarable_7_chord(self):
     diag = Diagram([(1, 10), (2, 7), (3, 6), (4, 11), (5, 12), (13, 8),
                     (14, 9)])
     self.assertTrue(diag.is_planarable())
 def test_Diagram_is_planarable_2_move_crossed(self):
     "Verify that the crossed 2-move fails in all rotations"
     for _ in range(0, 4):
         diag = Diagram([(1, 3), (2, 4)])
         self.assertFalse(diag.is_planarable())
 def test_Diagram_is_planarable_maindiag(self):
     diag = Diagram([(1, 4), (2, 5), (3, 8), (6, 7)])
     self.assertTrue(diag.is_planarable())
 def test_Diagram_is_planarable_5_chord_regression3(self):
     # This is True
     diag = Diagram([[1, 8], [2, 5], [3, 10], [4, 9], [6, 7]])
     self.assertTrue(diag.is_planarable())
 def test_Diagram_is_planarable_5_chord_regression4(self):
     # This is True
     diag = Diagram([[1, 3], [2, 10], [4, 7], [5, 8], [6, 9]])
     self.assertFalse(diag.is_planarable())
 def test_Diagram_is_planarable_3_chord_regression4(self):
     'Form region opposite the typical - but works - interesting'
     diag = Diagram([[1, 4], [6, 2], [3, 5]])
     self.assertFalse(diag.is_planarable())
 def test_Diagram_is_planarable_6_chord_regression3(self):
     diag = Diagram([[1, 4], [2, 5], [3, 12], [6, 9], [7, 11], [8, 10]])
     self.assertFalse(diag.is_planarable())
 def test_Diagram_is_planarable_4_chord_regression1(self):
     diag = Diagram([[1, 6], [2, 5], [3, 7], [4, 8]])
     self.assertFalse(diag.is_planarable())
 def test_Diagram_is_planarable_21_chord_1(self):
     diag = Diagram([(1, 42), (2, 37), (3, 36), (4, 31), (5, 30), (6, 25),
                     (7, 24), (8, 23), (9, 26), (10, 29), (11, 32),
                     (12, 35), (13, 38), (14, 41), (15, 40), (16, 39),
                     (17, 34), (18, 33), (19, 28), (20, 27), (21, 22)])
     self.assertTrue(diag.is_planarable())
 def test_Diagram_is_planarable_4_chord_regression2(self):
     diag = Diagram([[1, 6], [2, 3], [4, 7], [5, 8]])
     self.assertTrue(diag.is_planarable())