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)
def _create_task(arg_config, session): solvers = arg_config.solvers solvers_args = arg_config.solvers_args assert len(solvers) == len(solvers_args),\ "The amount of solver arguments must match the amount of solvers" for solver in solvers: assert solver in ALL_SOLVER,\ f"Solver {solver} not found! Please make sure that all solver are properly named." task = Task(task_type="instance_test", status=Task.STATUS_OPTIONS.CREATED, name=arg_config.name) config = ConfigHolder.fromNamespace(arg_config, task=task, ignored_attributes=["url_path", "solvers", "solvers_args", "create_only", "config", "name"]) jobs = _get_instances(task, config, session) for solver, solver_args in zip(solvers, solvers_args): subtask = Task(parent=task, name=f"{solver}_test", task_type="instance_test", status=Task.STATUS_OPTIONS.CREATED) task.children.append(subtask) subconfig_namespace = configargparse.Namespace(solver=solver, solver_args=solver_args) subconfig = ConfigHolder.fromNamespace(subconfig_namespace, task=subtask) add_prev_job = (subconfig.with_start_sol is not None and subconfig.with_start_sol) if isinstance(jobs[0], TaskJobs): for task_job in jobs: prev_job = task_job if add_prev_job else None for i in range(config.repetitions): subtask.jobs.append(TaskJobs(task=subtask, graph=task_job.graph, prev_job=prev_job)) else: for graph in jobs: for i in range(config.repetitions): subtask.jobs.append(TaskJobs(task=subtask, graph=graph)) session.add(task) session.commit() return task, config
def main(): config = _load_config() session = get_session(config.url_path) graphs = [] if config.seed is None: seed = int(np.random.default_rng(None).integers(np.array([2**63]))[0]) config.seed = seed else: seed = int(config.seed) gen = np.random.default_rng(seed) counter = 0 assert len(config.vertex_shape) % 2 == 0 shapes = np.array(config.vertex_shape).reshape(round(len(config.vertex_shape)/2), 2) l_shapes = len(shapes) for n in range(config.min_n, config.max_n): size = config.cel_min while size <= config.cel_max: for i in range(config.repetitions): graphs.append(create_random_celest_graph(n,vertex_shape=shapes[counter % l_shapes], celest_bounds=(size,size+config.cel_range), seed=gen)) counter += 1 size += config.cel_step task = Task(name=config.name, task_type="CelestialGraphInstances", status=Task.STATUS_OPTIONS.FINISHED) # Convert the namespace config into database config task_config_holder = ConfigHolder.fromNamespace(config, task=task, ignored_attributes=["url_path", "name", "config"]) task.jobs = [TaskJobs(graph=graph, task=task) for graph in graphs] session.add(task) session.commit() print(counter, "instances were created. Corresponding task is", task.id)
def main(): config = _load_config() session = get_session(config.url_path) if config.seed is None: seed = int(np.random.default_rng(None).integers(np.array([2**63]))[0]) config.seed = seed else: seed = int(config.seed) gen = np.random.default_rng(seed) if config.fixed_edges: graphs = _fixed_generation(config, gen) else: graphs = _probability_generation(config, gen) task = Task(name=config.name, task_type="GeometricGraphInstances", status=Task.STATUS_OPTIONS.FINISHED) # Convert the namespace config into database config task_config_holder = ConfigHolder.fromNamespace( config, task=task, ignored_attributes=["url_path", "name", "config"]) task.jobs = [TaskJobs(graph=graph, task=task) for graph in graphs] session.add(task) session.commit() print(len(task.jobs), "instances were created. Corresponding task is", task.id)
def _greedy_evolver_test(arg_config): session = get_session(arg_config.url_path) if arg_config.url_path else None task, config = _get_task_and_config(session, arg_config) from angular_evolver.edge_order_evolver import create_circle_n_k for n in range(config.min_n, config.max_n): for k in range(config.min_k, min(config.max_k, math.floor(n / 2) + 1)): graph = create_circle_n_k(n, k) job = TaskJobs(task=task, graph=graph) task.jobs.append(job) session.commit() if not arg_config.create_only: process_task(config, task, session)