Ejemplo n.º 1
0
def visualize_solutions_overview_second_batch():
    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.db")
    from utils.visualization import visualize_solution_scatter, VisTypes
    min_sum_tasks = session.query(Task).filter(Task.parent_id == 45).all()
    local_min_sum_tasks = session.query(Task).filter(
        Task.parent_id == 40).all()
    makespan_tasks = session.query(Task).filter(
        Task.parent_id == 30, ~Task.name.like("%Reduced%")).all()
    min_sum_jobs = session.query(TaskJobs).filter(
        TaskJobs.task_id.in_([t.id for t in min_sum_tasks])).all()
    local_min_sum_jobs = session.query(TaskJobs).filter(
        TaskJobs.task_id.in_([t.id for t in local_min_sum_tasks])).all()
    makespan_jobs = session.query(TaskJobs).filter(
        TaskJobs.task_id.in_([t.id for t in makespan_tasks])).all()
    #visualize_solution_scatter(min_sum_jobs, "Bla", vis_type=VisTypes.All, logscale=True, loc=9)
    #visualize_solution_scatter(local_min_sum_jobs, "Bla", vis_type=VisTypes.All, logscale=True, loc=9)
    visualize_solution_scatter(makespan_jobs,
                               "Bla",
                               vis_type=VisTypes.All,
                               logscale=True,
                               loc=9)
    print("finished")
Ejemplo n.º 2
0
def general_instances_test():
    from solver.x_split_solver import SplitXSolver
    from solver import MscColoringSolver
    from create_gen_instances_script import create_random_instance
    from database import TaskJobs

    solver_x = SplitXSolver()
    solver_c = MscColoringSolver()
    jobs = []
    for i in tqdm.trange(7, 20, desc="Vertices"):
        for j in tqdm.trange(3,10, desc="Edge probability"):
            for k in tqdm.trange(3, desc="Repetition"):
                g = create_random_instance(i, edge_chance=0.1*j)
                g.id = i*100+j*10+k
                sol_x = solver_x.solve(g)
                sol_c = solver_c.solve(g)
                try:
                    assert sol_x.makespan < max(get_lower_bounds(g)) * 5.5 * math.ceil(math.log2(g.vert_amount))
                    assert sol_c.makespan < max(get_lower_bounds(g)) * 5.5 * math.ceil(math.log2(g.vert_amount))
                except AssertionError as e:
                    print("Solution x-split:", sol_x.makespan, max(get_lower_bounds(g)) * 5.5 * math.ceil(math.log2(g.vert_amount)), "time:", sol_x.runtime)
                    print("Solution color:", sol_c.makespan, max(get_lower_bounds(g)) * 5.5 * math.ceil(math.log2(g.vert_amount)), "time:", sol_x.runtime)
                    raise e
                jobs.append(TaskJobs(task=None, solution=sol_x, graph=g))
                jobs.append(TaskJobs(task=None, solution=sol_c, graph=g))
    from utils.visualization import visualize_solution_scatter, VisTypes
    visualize_solution_scatter(jobs, "Bla", vis_type=VisTypes.LB_Runtime, logscale=True, loc=9)
Ejemplo n.º 3
0
def visualize_geo_solutions_overview():
    from database import Task, TaskJobs, Config, Graph, get_session, CelestialGraph, AngularGraphSolution
    from utils.visualization import visualize_solution_scatter, VisTypes
    session = get_session("angular.db")
    min_sum_tasks = session.query(Task).filter(Task.parent_id.in_([80,107])).all()
    local_min_sum_tasks = session.query(Task).filter(Task.parent_id.in_([89,109])).all() + session.query(Task).filter(Task.id == 82).all()
    makespan_tasks = session.query(Task).filter(Task.parent_id.in_([97,111])).all()
    min_sum_jobs = session.query(TaskJobs).filter(TaskJobs.task_id.in_([t.id for t in min_sum_tasks])).all()
    local_min_sum_jobs = session.query(TaskJobs).filter(TaskJobs.task_id.in_([t.id for t in local_min_sum_tasks])).all()
    makespan_jobs = session.query(TaskJobs).filter(TaskJobs.task_id.in_([t.id for t in makespan_tasks])).all()
    #visualize_solution_scatter(min_sum_jobs, "Bla", vis_type=VisTypes.All, logscale=True, loc=9)
    visualize_solution_scatter(local_min_sum_jobs, "Bla", vis_type=VisTypes.All, logscale=True, loc=9)
Ejemplo n.º 4
0
def bnb_sols():
    from database import Task, TaskJobs, Config, Graph, get_session, CelestialGraph, AngularGraphSolution
    from solver.bnb import MinSumAbstractGraphSolver, MinSumOrderSolver
    from create_gen_instances_script import create_random_instance
    import tqdm
    import pickle
    sols = None
    try:
        with open("bnb_sols.pk", "rb") as f:
            bnb1sols, bnb2sols = pickle.load(f)
    except (EOFError, FileNotFoundError):
        pass
    bnb1 = MinSumAbstractGraphSolver(time_limit=900)
    bnb2 = MinSumOrderSolver(time_limit=900)
    if not bnb1sols or not bnb2sols:
        graphs = [
            create_random_instance(n, edge_chance=e)
            for e in np.arange(0.5, 1, 0.1) for n in range(5, 8)
            for i in range(2)
        ]
        bnb1 = MinSumAbstractGraphSolver(time_limit=900)
        bnb2 = MinSumOrderSolver(time_limit=900)
        bnb1sols = []
        bnb2sols = []
        for g in tqdm.tqdm(graphs):
            bnb1sols.append(bnb1.solve(g))
            bnb2sols.append(bnb2.solve(g))
        sols = bnb1sols + bnb2sols

    for i, (s1, s2) in enumerate(zip(bnb1sols, bnb2sols)):
        s1.graph.id = i
        s1.graph_id = 1
        s2.graph.id = i
        s2.graph_id = 1

    with open("bnb_sols.pk", "wb") as f:
        pickle.dump((bnb1sols, bnb2sols), f)
    from utils.visualization import visualize_solution_scatter, VisTypes

    visualize_solution_scatter(bnb1sols + bnb2sols,
                               "Branch and Bound runtimes",
                               solution_type="runtime",
                               vis_type=VisTypes.Absolute)
    visualize_solution_scatter(bnb1sols + bnb2sols,
                               "Branch and Bound Vs Lower Bound",
                               solution_type="min_sum",
                               vis_type=VisTypes.VsLB)
Ejemplo n.º 5
0
def visualize_solutions_overview():
    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.db")
    from utils.visualization import visualize_solution_scatter, VisTypes
    min_sum_tasks = session.query(Task).filter(Task.parent_id == 2).all()
    local_min_sum_tasks = session.query(Task).filter(Task.parent_id == 11).all() 
    makespan_tasks = session.query(Task).filter(Task.parent_id == 19).all()
    min_sum_jobs = session.query(TaskJobs).filter(TaskJobs.task_id.in_([t.id for t in min_sum_tasks])).all()
    local_min_sum_jobs = session.query(TaskJobs).filter(TaskJobs.task_id.in_([t.id for t in local_min_sum_tasks])).all()
    makespan_jobs = session.query(TaskJobs).filter(TaskJobs.task_id.in_([t.id for t in makespan_tasks])).all()
    visualize_solution_scatter(min_sum_jobs, "Bla", vis_type=VisTypes.LB_Runtime, logscale=True, loc=9)
    visualize_solution_scatter(local_min_sum_jobs, "Bla", vis_type=VisTypes.LB_Runtime, logscale=True, loc=9)
    visualize_solution_scatter(makespan_jobs, "Bla", vis_type=VisTypes.LB_Runtime, logscale=True, loc=9)