Exemplo n.º 1
0
    def is_system_slower(self, n, m, system):
        """
        Determine if a given system is slower than the current slowest system stored in "systems_strongly_k"
        :param n: 
        :param m: 
        :param system: 
        :return: 
        """
        fh = FileHandler()
        path = "./../assets/systems_strongly_k/{0}_{1}".format(n, m)
        temp_path_a = "./../assets/temp/temp_a"
        temp_path_b = "./../assets/temp/temp_b"
        system_old = fh.read_from_file(path)

        if not system_old:
            return True

        fh.write_to_file_simple(
            temp_path_a, self.prepare_cryptominisat_system(n, m, system))
        fh.write_to_file_simple(
            temp_path_b, self.prepare_cryptominisat_system(n, m, system_old))
        diff_a = self.get_gauss_off_time(temp_path_a) - self.get_gauss_on_time(
            temp_path_a)
        diff_b = self.get_gauss_off_time(temp_path_b) - self.get_gauss_on_time(
            temp_path_b)

        if diff_a > diff_b:
            print "Slower {0}".format(diff_a - diff_b)
        pass

        return diff_a > diff_b
Exemplo n.º 2
0
    def convert_graph_to_traces(self, n, m, G, type, dir):
        """
        Convert a given networkx graph into dreadnaut format
        :param n: 
        :param m: 
        :param G: 
        :return: 
        """
        if type == "B":
            nodes = (2 * n) + (4 * m)
            variables = (2 * n)
        else:
            nodes = n + m
            variables = n

        # Init
        fh = FileHandler()
        path = dir + "{0}_{1}_{2}.dre".format(n, m, type)
        path_temp = "./../assets/temp/temp.adjlist"

        # Convert to Adjlist and store temporarily
        nx.write_adjlist(G, path_temp)

        # Read data and convert
        data = fh.read_from_file_simple(path_temp)
        output = ["n={0} $=0 g".format(nodes)]
        for i in range(3, variables + 3):
            datum = data[i].split()
            datum[0] = "{0}:".format(datum[0])
            output.append(" ".join(datum))
        output[-1] = "{}.".format(output[-1])
        output.append("$$")

        # Save as .dre
        fh.write_to_file_simple(path, output)

        # Convert to dot if necessary
        # ./nauty26r7/dretodot construction/3.dre construction/3.dot

        return path
Exemplo n.º 3
0
    def get_gauss_times(self, n, m, system):
        """
        Retrieve the validation times (unique satisfiability) on a given system executed on a Sat solver
        :param n: 
        :param m: 
        :param system: 
        :return: 
        """
        path = "./../assets/temp/temp_gauss_check"
        fh = FileHandler()

        # Create cryptominisat system
        input = self.prepare_cryptominisat_system(n, m, system)
        fh.write_to_file_simple(path, input)

        # run gauss off
        time_off = self.get_gauss_off_time(path)

        # run gauss on
        time_on = self.get_gauss_on_time(path)

        return time_off, time_on