Esempio n. 1
0
    def test_non_symmetric_input_wrong(self):
        """Symmetric encoding on non-symmetric graph

        The formula in this test uses the symmetric encoding for a non
        symmetric graph. This causes the formula to be unsatisfiable,
        even if it should be SAT.

        """
        G = readGraph(sio(example1), "simple", file_format="kthlist")
        T = readGraph(sio(example1alt), "simple", file_format="kthlist")
        F = SubgraphFormula(G, [T], symmetric=True)  # This should cause the wrong answer
        self.assertUNSAT(F)
Esempio n. 2
0
    def test_non_symmetric_input_right(self):
        """Symmetric encoding on non-symmetric graph

        The formula in this test uses the NON symmetric encoding for
        a non symmetric graph. This causes the formula to be
        satisfiable, as it should be.

        """
        G = readGraph(sio(example1), "simple", file_format="kthlist")
        T = readGraph(sio(example1alt), "simple", file_format="kthlist")
        F = SubgraphFormula(G, [T])
        self.assertSAT(F)
Esempio n. 3
0
    def test_non_symmetric_input_wrong(self):
        """Symmetric encoding on non-symmetric graph

        The formula in this test uses the symmetric encoding for a non
        symmetric graph. This causes the formula to be unsatisfiable,
        even if it should be SAT.

        """
        G = readGraph(sio(example1),"simple",file_format="kthlist")
        T = readGraph(sio(example1alt),"simple",file_format="kthlist")
        F = SubgraphFormula(G,[T],symmetric=True) # This should cause the wrong answer
        self.assertUNSAT(F)
Esempio n. 4
0
    def test_non_symmetric_input_right(self):
        """Symmetric encoding on non-symmetric graph

        The formula in this test uses the NON symmetric encoding for
        a non symmetric graph. This causes the formula to be
        satisfiable, as it should be.

        """
        G = readGraph(sio(example1),"simple",file_format="kthlist")
        T = readGraph(sio(example1alt),"simple",file_format="kthlist")
        F = SubgraphFormula(G,[T])
        self.assertSAT(F)
Esempio n. 5
0
    def test_readGraph_gml_path2(self):

        self.assertRaises(ValueError, readGraph, sio(
            gml_path2), graph_type='simple')
        G = readGraph(sio(gml_path2), graph_type='simple', file_format='gml')
        self.assertEqual(G.order(), 3)
        self.assertEqual(len(G.edges()), 2)
Esempio n. 6
0
    def test_readGraph_kthlist_bipartite(self):

        G = readGraph(sio(kthlist_bipartite), graph_type="bipartite", file_format="kthlist")
        self.assertEqual(G.order(), 5)
        L, R = bipartite_sets(G)
        self.assertEqual(len(L), 2)
        self.assertEqual(len(R), 3)
Esempio n. 7
0
 def test_small_pyramid(self):
     input = io.StringIO("3\n1 : 0\n2 : 0\n3 : 1 2 0\n")
     F = PebblingFormula(readGraph(input, 'dag', 'kthlist'))
     input.seek(0)
     self.checkFormula(input,
                       F, ["kthlist2pebbling", "-q", "none"],
                       cmdline=kthlist2pebbling)
    def test_unit_graph(self) :

        input = StringIO.StringIO("1\n1 : 0\n")
        F = PebblingFormula(readGraph(input,'dag','kthlist'))

        input.seek(0)
        self.checkFormula(input,F,["kthlist2pebbling","-q","none"],cmdline = kthlist2pebbling)
    def test_small_line(self) :

        input = StringIO.StringIO("3\n1 : 0\n2 : 1 0\n3 : 2 0\n")
        F = PebblingFormula(readGraph(input,'dag','kthlist'))

        input.seek(0)
        self.checkFormula(input,F,["kthlist2pebbling","-q","none"],cmdline = kthlist2pebbling)
Esempio n. 10
0
    def test_readGraph_kthlist_non_dag(self):

        self.assertRaises(ValueError, readGraph, sio(kthlist_non_dag), graph_type="digraph")
        self.assertRaises(ValueError, readGraph, sio(kthlist_non_dag), graph_type="dag", file_format="kthlist")
        G = readGraph(sio(kthlist_non_dag), graph_type="digraph", file_format="kthlist")
        self.assertEqual(G.order(), 3)
        self.assertEqual(len(G.edges()), 3)
Esempio n. 11
0
    def test_readGraph_kthlist_bipartite(self):

        G = readGraph(sio(kthlist_bipartite),
                      graph_type='bipartite', file_format='kthlist')
        self.assertEqual(G.order(), 5)
        L, R = bipartite_sets(G)
        self.assertEqual(len(L), 2)
        self.assertEqual(len(R), 3)
Esempio n. 12
0
 def test_xor_substitution(self):
     input = io.StringIO("3\n1 : 0\n2 : 0\n3 : 1 2 0\n")
     G = PebblingFormula(readGraph(input, 'dag', 'kthlist'))
     F = XorSubstitution(G, 2)
     input.seek(0)
     self.checkFormula(input,
                       F, ["kthlist2pebbling", "-q", "xor", 2],
                       cmdline=kthlist2pebbling)
Esempio n. 13
0
 def test_lift_substitution(self):
     input = io.StringIO("3\n1 : 0\n2 : 0\n3 : 1 2 0\n")
     G = PebblingFormula(readGraph(input, 'dag', 'kthlist'))
     F = FormulaLifting(G, 3)
     input.seek(0)
     self.checkFormula(input,
                       F, ["kthlist2pebbling", "-q", "lift", 3],
                       cmdline=kthlist2pebbling)
Esempio n. 14
0
    def obtain_graph(args):
        """Build a Graph according to command line arguments

        Arguments:
        - `args`: command line options
        """
        if hasattr(args,'gnd') and args.gnd:

            n,d = args.gnd
            if (n*d)%2 == 1:
                raise ValueError("n * d must be even")
            G=networkx.random_regular_graph(d,n)
            return G

        elif hasattr(args,'gnp') and args.gnp:

            n,p = args.gnp
            G=networkx.gnp_random_graph(n,p)

        elif hasattr(args,'gnm') and args.gnm:

            n,m = args.gnm
            G=networkx.gnm_random_graph(n,m)

        elif hasattr(args,'grid') and args.grid:

            G=networkx.grid_graph(args.grid)

        elif hasattr(args,'torus') and args.torus:
            
            G=networkx.grid_graph(args.torus,periodic=True)

        elif hasattr(args,'complete') and args.complete>0:

            G=networkx.complete_graph(args.complete)

        elif args.graphformat:

            G=readGraph(args.input,args.graphformat)
        else:
            raise RuntimeError("Invalid graph specification on command line")

        # Graph modifications
        if hasattr(args,'plantclique') and args.plantclique>1:

            clique=random.sample(G.nodes(),args.plantclique)

            for v,w in combinations(clique,2):
                G.add_edge(v,w)

        # Output the graph is requested
        if hasattr(args,'savegraph') and args.savegraph:
            writeGraph(G,
                       args.savegraph,
                       args.graphformat,
                       graph_type='simple')

        return G
Esempio n. 15
0
    def test_readGraph_dot_path2(self):

        if "dot" not in supported_formats()["simple"]:
            self.skipTest("No support for Dot file I/O.")

        self.assertRaises(ValueError, readGraph, sio(dot_path2), graph_type="simple")
        G = readGraph(sio(dot_path2), graph_type="simple", file_format="dot")
        self.assertEqual(G.order(), 3)
        self.assertEqual(len(G.edges()), 2)
Esempio n. 16
0
    def test_unit_graph(self):

        input = io.StringIO("1\n1 : 0\n")
        F = PebblingFormula(readGraph(input, 'dag', 'kthlist'))

        input.seek(0)
        self.checkFormula(input,
                          F, ["kthlist2pebbling", "-q", "none"],
                          cmdline=kthlist2pebbling)
Esempio n. 17
0
    def test_readGraph_kthlist_non_bipartite(self):

        self.assertRaises(ValueError, readGraph, sio(kthlist_non_bipartite), graph_type="bipartite")
        self.assertRaises(
            ValueError, readGraph, sio(kthlist_non_bipartite), graph_type="bipartite", file_format="kthlist"
        )
        G = readGraph(sio(kthlist_non_bipartite), graph_type="simple", file_format="kthlist")
        self.assertEqual(G.order(), 5)
        self.assertEqual(len(G.edges()), 5)
Esempio n. 18
0
    def test_readGraph_kthlist_non_dag(self):

        self.assertRaises(ValueError, readGraph, sio(
            kthlist_non_dag), graph_type='digraph')
        self.assertRaises(ValueError, readGraph, sio(
            kthlist_non_dag), graph_type='dag', file_format='kthlist')
        G = readGraph(sio(kthlist_non_dag), graph_type='digraph',
                      file_format='kthlist')
        self.assertEqual(G.order(), 3)
        self.assertEqual(len(G.edges()), 3)
Esempio n. 19
0
    def test_readGraph_kthlist_non_bipartite(self):

        self.assertRaises(ValueError, readGraph, sio(
            kthlist_non_bipartite), graph_type='bipartite')
        self.assertRaises(ValueError, readGraph, sio(
            kthlist_non_bipartite), graph_type='bipartite', file_format='kthlist')
        G = readGraph(sio(kthlist_non_bipartite),
                      graph_type='simple', file_format='kthlist')
        self.assertEqual(G.order(), 5)
        self.assertEqual(len(G.edges()), 5)
Esempio n. 20
0
    def test_readGraph_dot_path2(self):

        if 'dot' not in supported_formats()['simple']:
            self.skipTest("No support for Dot file I/O.")

        self.assertRaises(ValueError, readGraph, sio(
            dot_path2), graph_type='simple')
        G = readGraph(sio(dot_path2), graph_type='simple', file_format='dot')
        self.assertEqual(G.order(), 3)
        self.assertEqual(len(G.edges()), 2)
Esempio n. 21
0
 def identity_check_helper(self, input, liftname, liftrank) :
     G = readGraph(input,'dag','kthlist')
     input.seek(0)
     peb = PebblingFormula(G)
     lift = cnfformula.TransformFormula(peb, liftname, liftrank)
     reference_output = lift.dimacs(export_header=False)+"\n"
     
     tool_output=StringIO.StringIO()
     kthlist2pebbling.kthlist2pebbling(input, liftname, liftrank, tool_output, header=True)
     self.assertMultiLineEqual(tool_output.getvalue(), reference_output)
Esempio n. 22
0
def command_line_utility(argv=sys.argv):

    # Parse the command line arguments
    parser=argparse.ArgumentParser(prog=os.path.basename(argv[0]))
    setup_command_line(parser)
    args=parser.parse_args(argv[1:])

    G = graphs.readGraph(args.input,"dag",file_format="kthlist")

    Fstart = cnfformula.PebblingFormula(G)

    Ftransform = args.transformation.transform_cnf(Fstart,args)
    print(Ftransform.dimacs(export_header=args.verbose),file=args.output)
Esempio n. 23
0
def command_line_utility(argv=sys.argv):

    # Parse the command line arguments
    parser = argparse.ArgumentParser(prog=os.path.basename(argv[0]))
    setup_command_line(parser)
    args = parser.parse_args(argv[1:])

    G = graphs.readGraph(args.input, "dag", file_format="kthlist")

    Fstart = cnfformula.PebblingFormula(G)

    Ftransform = args.transformation.transform_cnf(Fstart, args)
    print(Ftransform.dimacs(export_header=args.verbose), file=args.output)
Esempio n. 24
0
    def test_readGraph_dot_path2_file(self):

        if "dot" not in supported_formats()["simple"]:
            self.skipTest("No support for Dot file I/O.")

        with open(example_filename("path2.dot"), "r") as ifile:

            # Parsing should fail here
            self.assertRaises(ValueError, readGraph, ifile, graph_type="simple", file_format="gml")

            ifile.seek(0)

            # Parser should guess that it is a dot file
            G = readGraph(ifile, graph_type="simple")
            self.assertEqual(G.order(), 3)
            self.assertEqual(len(G.edges()), 2)
Esempio n. 25
0
    def test_readGraph_dot_path2_file(self) :

        if 'dot' not in supported_formats()['simple']:
            self.skipTest("No support for Dot file I/O.")
        
        with open(example_filename('path2.dot'),'r') as ifile:

            # Parsing should fail here
            self.assertRaises(ValueError, readGraph, ifile, graph_type='simple', file_format='gml')

            ifile.seek(0)
            
            # Parser should guess that it is a dot file
            G = readGraph(ifile, graph_type='simple')
            self.assertEqual(G.order(), 3)
            self.assertEqual(len(G.edges()), 2)
Esempio n. 26
0
    def test_readGraph_dot_path2_file(self):

        if 'dot' not in supported_formats()['simple']:
            self.skipTest("No support for Dot file I/O.")

        with open(example_filename('path2.dot'), 'r') as ifile:

            # Parsing should fail here
            self.assertRaises(ValueError, readGraph, ifile,
                              graph_type='simple', file_format='gml')

            ifile.seek(0)

            # Parser should guess that it is a dot file
            G = readGraph(ifile, graph_type='simple')
            self.assertEqual(G.order(), 3)
            self.assertEqual(len(G.edges()), 2)
Esempio n. 27
0
    def test_readGraph_gml_path2(self) :

        self.assertRaises(ValueError, readGraph, sio(gml_path2), graph_type='simple')
        G = readGraph(sio(gml_path2), graph_type='simple', file_format = 'gml')
        self.assertEqual(G.order(), 3)
        self.assertEqual(len(G.edges()), 2)
Esempio n. 28
0
    def test_readGraph_dimacs_path2(self):

        self.assertRaises(ValueError, readGraph, sio(dimacs_path2), graph_type="simple")
        G = readGraph(sio(dimacs_path2), graph_type="simple", file_format="dimacs")
        self.assertEqual(G.order(), 3)
        self.assertEqual(len(G.edges()), 2)
 def test_xor_substitution(self) :
     input = StringIO.StringIO("3\n1 : 0\n2 : 0\n3 : 1 2 0\n")
     G = PebblingFormula(readGraph(input,'dag','kthlist'))
     F = XorSubstitution(G,2)
     input.seek(0)
     self.checkFormula(input,F,["kthlist2pebbling","-q","xor",2],cmdline = kthlist2pebbling)
 def test_lift_substitution(self) :
     input = StringIO.StringIO("3\n1 : 0\n2 : 0\n3 : 1 2 0\n")
     G = PebblingFormula(readGraph(input,'dag','kthlist'))
     F = FormulaLifting(G,3)
     input.seek(0)
     self.checkFormula(input,F,["kthlist2pebbling","-q","lift",3],cmdline = kthlist2pebbling)