Ejemplo n.º 1
0
def test_graph_paths():
    dg = DesignGraph(
        [color, text, congruent, repeated_color_factor, repeated_text_factor])

    assert nx.has_path(dg.graph, "congruent?", "color")
    assert nx.has_path(dg.graph, "congruent?", "text")

    assert nx.has_path(dg.graph, "repeated color?", "color")
    assert nx.has_path(dg.graph, "repeated text?", "text")

    assert not nx.has_path(dg.graph, "repeated color?", "text")
    assert not nx.has_path(dg.graph, "repeated text?", "color")
Ejemplo n.º 2
0
def test_basic_graph():
    dg = DesignGraph([color, text, congruent])

    assert len(dg.graph.nodes()) == 3
    assert dg.graph.has_node("color")
    assert dg.graph.has_node("text")
    assert dg.graph.has_node("congruent?")

    assert len(dg.graph.edges()) == 2
    assert dg.graph.has_edge("congruent?", "color")
    assert dg.graph.has_edge("congruent?", "text")

    # Graph is directed, so these should not exist.
    assert not dg.graph.has_edge("color", "congruent?")
    assert not dg.graph.has_edge("text", "congruent?")
Ejemplo n.º 3
0
    def __validate_crossing(self):
        dg = DesignGraph(self.design).graph
        warnings = []
        template = "'{}' depends on '{}'"
        for crossing in self.crossing:
            combos = combinations(crossing, 2)

            for c in combos:
                if has_path(dg, c[0].factor_name, c[1].factor_name):
                    warnings.append(template.format(c[0].factor_name, c[1].factor_name))
                elif has_path(dg, c[1].factor_name, c[0].factor_name):
                    warnings.append(template.format(c[1].factor_name, c[0].factor_name))

        if warnings:
            self.errors.add("WARNING: There are dependencies between factors in the crossing. "
                            "This may lead to unsatisfiable designs.\n"
                            + reduce(lambda accum, s: accum + s + "\n", warnings, ""))
Ejemplo n.º 4
0
 def draw_design_graph(self):
     dg = DesignGraph(self.design)
     dg.draw()