Esempio n. 1
0
 def update_strongly_k(self, n, m, system):
     """
     Update the folder of stored systems which are a catalogue of slow systems
     :param n: 
     :param m: 
     :param system: 
     :return: 
     """
     ph = ProcessHandler()
     fh = FileHandler()
     path = "./../assets/systems_strongly_k/{0}_{1}".format(n, m)
     fh.delete_file(path)
     self.save_system(n, m, system, "./../assets/systems_strongly_k/")
Esempio n. 2
0
    def is_system_eligble(self, n, m, system, gi, location):
        """
        Check if graph meets the construction criteria
        - k consistent 
        - No automorphisms
        :param n: 
        :param m: 
        :param gi: 
        :param system: 
        :return: 
        """
        # Init
        ph = ProcessHandler()
        fh = FileHandler()
        graph_path = "{0}/constructions/".format(location)
        system_path = "{0}/constructions/{1}_{2}".format(location, n, m)
        construct_a_location = "{0}{1}_{2}_A.dre".format(graph_path, n, m)

        # Save system temporarily
        self.save_system(n, m, system, graph_path)
        G = self.convert_system_to_graph(n, m, system)
        gi.convert_graph_to_traces(n, m, G, "A",
                                   graph_path)  # First construction

        # Check for k-local consistency
        if not self.is_k_consistent(n, m, system):
            # print "Not K consistent"
            fh.delete_file(system_path)
            return False
        elif not gi.graph_has_automorphisms(construct_a_location):
            # print "No Automorphisms. Construct."
            G = self.convert_system_to_construction(n, m, system)
            gi.convert_graph_to_traces(n, m, G, "B",
                                       graph_path)  # Second construction
            fh.delete_file(system_path)
            return True
        else:
            # print "Automorphisms. Remove."
            fh.delete_file(construct_a_location)  # Remove unwanted graph
            fh.delete_file(system_path)  # Remove unwanted system
            return False
Esempio n. 3
0
    def convert_systems_to_constructions(self, **kwargs):
        """
        Convert found systems into graphs and run them through Traces
        :return: 
        """
        # Init
        gi = Gi()
        sat = Sat()
        ph = ProcessHandler()
        fh = FileHandler()
        paths = ph.run_command("ls -v ./../assets/systems_to_convert/")
        validate = kwargs.get("validate", False)
        delete = kwargs.get("delete", False)

        # Iterate systems
        for path in paths:
            print "Checking " + path

            # Paths
            graph_path = "./../assets/construction/" + path + "_A.dre"
            system_path = "./../assets/systems_to_convert/" + path

            # Extract n and m values
            n, m = path.split("_")
            n = int(n)
            m = int(m)

            # Load system
            system = fh.read_from_file(system_path)

            if validate:
                # Check for k-local consistency
                if not sat.is_k_consistent(n, m, system):
                    print "\t Not K consistent system. Removing and skipping."
                    if delete:
                        fh.delete_file(system_path)
                    continue
                else:
                    print "\t K consistent system. Constructing A."

                # Convert system into graphs and check for automorphisms
                G = sat.convert_system_to_graph(n, m, system)
                gi.convert_graph_to_traces(
                    n, m, G, "A",
                    "./../assets/construction/")  # First construction
                if not gi.graph_has_automorphisms(graph_path):
                    print "\t No Automorphisms. Constructing B."
                    G = sat.convert_system_to_construction(n, m, system)
                    gi.convert_graph_to_traces(
                        n, m, G, "B",
                        "./../assets/construction/")  # Second construction
                    if delete:
                        fh.delete_file(graph_path)
                else:
                    print "\t Automorphisms. Removing and skipping."
                    if delete:
                        fh.delete_file(graph_path)  # Remove unwanted graph
                        fh.delete_file(system_path)  # Remove unwanted system
            else:
                G = sat.convert_system_to_construction(n, m, system)
                gi.convert_graph_to_traces(n, m, G, "B",
                                           "./../assets/construction/")