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
def load_results(self): """ Load Sat Solver execution results :return: """ fh = FileHandler() results = fh.read_from_file("./../assets/systems_run/run") return results
def plot_generate_systems_results(self, filename, **kwargs): """ Plot time taken to generate instances :param filename: :param kwargs: :return: """ ph = PlotHandler() fh = FileHandler() data = fh.read_from_file(filename, **kwargs) ph.plot_sat_results(data)
def load_results(self): """ Load results from tests :return: """ ph = ProcessHandler() fh = FileHandler() results = {} run = ph.run_command("ls -v ./../assets/graphs_run/") for graph_run in run: results[graph_run[:-4]] = fh.read_from_file( "./../assets/graphs_run/" + graph_run) return results
def test_17(self): fh = FileHandler() data = fh.read_from_file( "../assets/results/sat/0-n-10000_0-m-10000_step-100/results") for d in data: print "{0} {1} a".format(d[1], d[2]) i = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120] gi = Gi() for j in i: a = gi.run_graph_instance("ga_vs_gb", "{0}_{1}_A.dre".format(j, j)) b = gi.run_graph_instance("ga_vs_gb", "{0}_{1}_B.dre".format(j, j)) print "{0} {1} a".format(j, a["time"], 1) print "{0} {1} b".format(j, b["time"], 1)
def run_solver(self, **kwargs): """ Run Traces through systems and record times Looking for systems that are faster with gauss off => K-local consistent :param kwargs: :return: Null """ fh = FileHandler() ph = ProcessHandler() results = [] skip = kwargs.get("outstanding", False) completed = [] if fh.read_from_file("./../assets/systems_run/run"): for result in fh.read_from_file("./../assets/systems_run/run"): completed.append(result[0]) for filename in ph.run_command('ls -v ./../assets/systems/'): # Init path = './../assets/systems/' + filename system = fh.read_from_file(path) split = filename.split("_") n = split[0] m = split[1] # Skip completed systems key = "{0}:{1}".format(n, m) if skip and key in completed: continue print key # Create cryptominisat system time_off, time_on = self.get_gauss_times(n, m, system) # Save results.append([key, n, m, time_off, time_on, time_off - time_on]) fh.update_file("./../assets/systems_run/run", results)
def run_graph(self, graphs, graph, program, **kwargs): """ Run instances in a graph :param graph: :param kwargs: :return: """ fh = FileHandler() ph = ProcessHandler() run = ph.run_command("ls -v ./../assets/graphs_run/") save = kwargs.get("save", False) outstanding = kwargs.get("outstanding", False) graph_name = self.get_filename(graph, program) # Load previous results if outstanding and graph_name in run: graph_results = fh.read_from_file( "./../assets/graphs_run/{0}".format(graph_name)) else: graph_results = [] # Gather results for graph_instance in graphs: print "{0} {1}".format(graph_instance, datetime.datetime.now()) # Skip existing graph if outstanding and graph_name in run: if any(d['name'] == graph_instance for d in graph_results): continue kwargs["program"] = program result = self.run_graph_instance(graph, graph_instance, **kwargs) graph_results.append(result) # Save if save: print "Saving..." fh.write_to_file("./../assets/graphs_run/" + graph_name, graph_results) return graph_results
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/")