Example #1
0
 def save_system(self, n, m, system, location):
     """
     Save a system of equations to file
     :param n: 
     :param m: 
     :param system: 
     :param location: 
     :return: 
     """
     fh = FileHandler()
     path = location + "{0}_{1}".format(n, m)
     fh.write_to_file(path, system)
Example #2
0
    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
Example #3
0
    def execute_constructions(self):
        """
        Run new constructions through Traces
        :return: 
        """
        gi = Gi()
        fh = FileHandler()
        graphs = {"con_all": gi.load_graphs()["con_all"]}
        results = gi.run_graphs(graphs, save=True, timeout=7200)

        # Init
        con_4_10 = []
        con_10_100 = []
        con_100_1000 = []
        con_n = []
        con_2n = []
        con_3n = []
        con_sml = []
        found = []

        # Extract packages
        for result in results["con_all"]:
            n = int(result["name"].split("_")[0])
            m = int(result["name"].split("_")[1])
            if n in range(4, 10, 1):
                con_4_10.append(result)
            if n in range(10, 100, 10):
                con_10_100.append(result)
            if n in range(100, 1000, 100):
                con_100_1000.append(result)
            if n == m:
                con_n.append(result)
            if 2 * n == m:
                con_2n.append(result)
            if 3 * n == m:
                con_3n.append(result)

        # Extract smallest n : m ratio
        for i in results["con_all"]:
            n = int(i["name"].split("_")[0])
            m = int(i["name"].split("_")[1])

            if n in found:
                continue

            for j in results["con_all"]:
                n_1 = int(j["name"].split("_")[0])
                m_1 = int(j["name"].split("_")[1])
                if n == n_1 and m_1 <= m:
                    con_sml.append(j)
                    found.append(n)

        # Produce packages
        packages = {
            "con_4_10": con_4_10,
            "con_10_100": con_10_100,
            "con_100_1000": con_100_1000,
            "con_n": con_n,
            "con_2n": con_2n,
            "con_3n": con_3n,
            "con_sml": con_sml
        }

        # Save packages
        for package in packages:
            fh.write_to_file("./../assets/graphs_run/{0}.txt".format(package),
                             packages[package])
            fh.makedir("./../assets/graphs/{0}".format(package))
            for instance in packages[package]:
                name = instance["name"]
                fh.copy_file(
                    "./../assets/graphs/con_all/{0}".format(name),
                    "./../assets/graphs/{0}/{1}".format(package, name))

        return results