Ejemplo n.º 1
0
def visualize_sols_inst_gen():
    from database import Task, TaskJobs, Config, Graph, get_session, CelestialGraph, AngularGraphSolution
    from utils import visualize_graph_2d, visualize_min_sum_sol_2d, visualize_solution_2d
    session = get_session("angular_copy.db")
    with session.no_autoflush:
        task = session.query(Task).filter(Task.task_type == "CelestialGraphInstances").one()
        task_jobs = session.query(TaskJobs).filter(TaskJobs.task == task).all()
        cel_graphs_old = session.query(CelestialGraph)\
            .filter(CelestialGraph.id.in_([job.graph_id for job in task_jobs]), CelestialGraph.vert_amount <= 8)\
            .all()
        cel_graphs = [i for i in cel_graphs_old if i.id in [44,68,81,82,96,1, 21, 12, 3]]

        min_sum_sols = [session.query(AngularGraphSolution).filter(AngularGraphSolution.graph_id == cel.id, AngularGraphSolution.is_optimal == True, AngularGraphSolution.solution_type == "min_sum").all() for cel in cel_graphs]
        local_min_sum_sols = [session.query(AngularGraphSolution).filter(AngularGraphSolution.graph_id == cel.id, AngularGraphSolution.is_optimal == True, AngularGraphSolution.solution_type == "local_min_sum").all() for cel in cel_graphs]
        makespan_sols = [session.query(AngularGraphSolution).filter(AngularGraphSolution.graph_id == cel.id, AngularGraphSolution.is_optimal == True, AngularGraphSolution.solution_type == "makespan").all() for cel in cel_graphs]
        for g, min_s, l_s, m_s in zip(cel_graphs, min_sum_sols, local_min_sum_sols, makespan_sols):
            print("Graph-id", g.id)
            visualize_graph_2d(g)

            if min_s:
                print("Minsum:")
                visualize_min_sum_sol_2d(min_s[0])
            if l_s:
                print("LocalMinSum")
                visualize_min_sum_sol_2d(l_s[0])
            if m_s:
                print("Makespan")
                visualize_solution_2d(m_s[0])
    return
Ejemplo n.º 2
0
def create_graph():
    d1 = get_distance(9, 3)
    d2 = get_distance(9, 2)
    d = d1 + np.random.default_rng().random() * (d2 - d1)
    body = CelestialBody((0, 0), d, None)
    g = create_circle_n_k(9, 4)
    graph = CelestialGraph([body], g.vertices, g.edges)
    visualize_graph_2d(graph)
    for i in range(10):
        rand_g = create_random_celest_graph(9, celest_bounds=(0.4, 0.6))
        visualize_graph_2d(rand_g)
Ejemplo n.º 3
0
def visualize_makespan_evolve_data():
    from database import Task, TaskJobs, Config, Graph, get_session, CelestialGraph, AngularGraphSolution
    from instance_evolver import GraphGenome
    from utils import visualize_graph_2d, visualize_min_sum_sol_2d, visualize_solution_2d
    from matplotlib import pyplot as plt
    session = get_session("angular_old.db")
    with session.no_autoflush:
        genomes = [session.query(GraphGenome)\
            .filter(GraphGenome.task_id == 5, GraphGenome.generation == i).all()
            for i in range(89)]

        import pandas as pa
        df = pa.DataFrame([
            {
                "Generation": gen.generation,
                #"GraphId": gen.graph_id,
                "Runtime": float(gen.solution.runtime)
            } for genome_generation in genomes for gen in genome_generation
        ])
        mean_df = df.groupby(["Generation"]).mean()
        max_df = df.groupby(["Generation"]).max()

        fig, (ax1, ax2) = plt.subplots(1, 2, sharex=True, sharey=True)
        plt.suptitle(
            "Absolute turn cost IP solver instance generation results")
        fig.set_size_inches(10, 3.8)
        ax1.set_title("Mean runtime")
        ax2.set_title("Max runtime")
        ax1.set_ylabel("Runtime (s)")
        mean_df.plot(ax=ax1)
        max_df.plot(ax=ax2)
        ax1.get_legend().set_visible(False)
        ax2.get_legend().set_visible(False)
        plt.show()

        visualize_graph_2d(genomes[15][0].graph)
        visualize_graph_2d(genomes[25][0].graph)
        visualize_graph_2d(genomes[45][0].graph)
        visualize_graph_2d(genomes[60][0].graph)
        visualize_graph_2d(genomes[80][0].graph)
        visualize_solution_2d(genomes[15][0].solution)
        visualize_solution_2d(genomes[25][0].solution)
        visualize_solution_2d(genomes[45][0].solution)
        visualize_solution_2d(genomes[60][0].solution)
        visualize_solution_2d(genomes[80][0].solution)
Ejemplo n.º 4
0
def solution_example_intro():
    solver1 = ALL_SOLVER["ConstraintAbsSolver"]()
    solver2 = ALL_SOLVER["ConstraintDependencySolver"]()
    solver3 = ALL_SOLVER["ConstraintDependencyLocalMinSumSolver"]()
    s52 = create_circle_n_k(5, 2)
    visualize_graph_2d(s52)
    sol1 = solver1.solve(s52)
    sol2 = solver2.solve(s52)
    sol3 = solver3.solve(s52)
    visualize_solution_2d(sol1)
    visualize_min_sum_sol_2d(sol1)
    print("makespan", sol1.makespan)
    visualize_solution_2d(sol2)
    visualize_min_sum_sol_2d(sol2)
    print("MinSum", sol2.min_sum)
    visualize_solution_2d(sol3)
    visualize_min_sum_sol_2d(sol3)
    print("LocalMinSum", sol2.local_min_sum)
    return
Ejemplo n.º 5
0
def create_graph():
    d1 = get_distance(9,3)
    d2 = get_distance(9,2)
    d = d1 + np.random.default_rng().random() * (d2-d1)
    body = CelestialBody((0,0), d, None)
    g = create_circle_n_k(9,4)
    graph = CelestialGraph([body], g.vertices, g.edges)
    visualize_graph_2d(graph)
    for i in range(10):
        for j in range(3):
            rand_c = create_random_celest_graph(9+i,celest_bounds=(0.4,0.6))
            rand_g = create_random_instance(9+i, edge_chance=random.uniform(0.3, 1))
            visualize_graph_2d(rand_g, savePath=f"instance_vis/rand_e{9+i}_{j}.pdf")
            visualize_graph_2d(rand_c, savePath=f"instance_vis/cel_e{9+i}_{j}.pdf")