示例#1
0
def main(suite_path,
         solver_name,
         instance_path,
         specifics=None,
         budget=1e6,
         max_length=None,
         seed=None,
         *args):
    """Make a single solver run for ParamILS."""

    suite = borg.load_solvers(suite_path)

    if seed is not None:
        borg.statistics.set_prng_seeds(seed)

    suite = borg.load_solvers(suite_path)
    solver = suite.solvers[solver_name].with_args(args)

    with suite.domain.task_from_path(instance_path) as task:
        with borg.accounting() as accountant:
            answer = solver(task)(budget)

        succeeded = suite.domain.is_final(task, answer)

    print \
        "Result for ParamILS: {solved}, {run_time}, {run_length}, {best}, {seed}".format(
            solved = "SAT" if succeeded else "TIMEOUT",
            run_time = accountant.total.cpu_seconds,
            run_length = -1,
            best = -1,
            seed = seed,
            )
示例#2
0
def main(
    suite_path,
    solver_name,
    instance_path,
    specifics = None,
    budget = 1e6,
    max_length = None,
    seed = None,
    *args
    ):
    """Make a single solver run for ParamILS."""

    suite = borg.load_solvers(suite_path)

    if seed is not None:
        borg.statistics.set_prng_seeds(seed)

    suite = borg.load_solvers(suite_path)
    solver = suite.solvers[solver_name].with_args(args)

    with suite.domain.task_from_path(instance_path) as task:
        with borg.accounting() as accountant:
            answer = solver(task)(budget)

        succeeded = suite.domain.is_final(task, answer)

    print \
        "Result for ParamILS: {solved}, {run_time}, {run_length}, {best}, {seed}".format(
            solved = "SAT" if succeeded else "TIMEOUT",
            run_time = accountant.total.cpu_seconds,
            run_length = -1,
            best = -1,
            seed = seed,
            )
示例#3
0
文件: run_solvers.py 项目: smhjn/borg
    def yield_runs():
        suite = borg.load_solvers(suite_path)

        logger.info("scanning paths under %s", tasks_root)

        paths = list(borg.util.files_under(tasks_root, suite.domain.extensions))

        if not paths:
            raise ValueError("no paths found under specified root")

        if only_solver is None:
            solver_names = suite.solvers.keys()
        else:
            solver_names = [only_solver]

        for path in paths:
            run_data = None

            if only_missing and os.path.exists(path + suffix):
                run_data = numpy.recfromcsv(path + suffix, usemask=True)

            for solver_name in solver_names:
                if only_missing and run_data is not None:
                    count = max(0, runs - numpy.sum(run_data.solver == solver_name))
                else:
                    count = runs

                logger.info("scheduling %i run(s) of %s on %s", count, solver_name, os.path.basename(path))

                for _ in xrange(count):
                    seed = numpy.random.randint(sys.maxint)

                    yield (run_solver_on, [suite_path, solver_name, path, budget, store_answers, seed])
示例#4
0
def run_solver_on(suite_path,
                  solver_name,
                  task_path,
                  budget,
                  store_answers,
                  seed=None):
    """Run a solver."""

    if seed is not None:
        borg.statistics.set_prng_seeds(seed)

    suite = borg.load_solvers(suite_path)

    with suite.domain.task_from_path(task_path) as task:
        with borg.accounting() as accountant:
            answer = suite.solvers[solver_name](task)(budget)

        succeeded = suite.domain.is_final(task, answer)

    cost = accountant.total.cpu_seconds

    logger.info(
        "%s %s in %.2f (of %.2f) on %s",
        solver_name,
        "succeeded" if succeeded else "failed",
        cost,
        budget,
        os.path.basename(task_path),
    )

    if store_answers:
        return (task_path, solver_name, budget, cost, succeeded, answer)
    else:
        return (task_path, solver_name, budget, cost, succeeded, None)
示例#5
0
def run_solver_on(suite_path, solver_name, task_path, budget, store_answers, seed = None):
    """Run a solver."""

    if seed is not None:
        borg.statistics.set_prng_seeds(seed)

    suite = borg.load_solvers(suite_path)

    with suite.domain.task_from_path(task_path) as task:
        with borg.accounting() as accountant:
            answer = suite.solvers[solver_name](task)(budget)

        succeeded = suite.domain.is_final(task, answer)

    cost = accountant.total.cpu_seconds

    logger.info(
        "%s %s in %.2f (of %.2f) on %s",
        solver_name,
        "succeeded" if succeeded else "failed",
        cost,
        budget,
        os.path.basename(task_path),
        )

    if store_answers:
        return (task_path, solver_name, budget, cost, succeeded, answer)
    else:
        return (task_path, solver_name, budget, cost, succeeded, None)
示例#6
0
    def yield_runs():
        if os.path.exists(domain_name):
            domain = borg.load_solvers(domain_name).domain
        else:
            domain = borg.get_domain(domain_name)

        paths = list(borg.util.files_under(instances_root, domain.extensions))
        count = 0

        for path in paths:
            if skip_existing and os.path.exists(path + suffix):
                continue

            count += 1

            yield (features_for_path, [domain, path])

        logger.info("collecting features for %i instances", count)
示例#7
0
    def yield_runs():
        if os.path.exists(domain_name):
            domain = borg.load_solvers(domain_name).domain
        else:
            domain = borg.get_domain(domain_name)

        paths = list(borg.util.files_under(instances_root, domain.extensions))
        count = 0

        for path in paths:
            if skip_existing and os.path.exists(path + suffix):
                continue

            count += 1

            yield (features_for_path, [domain, path])

        logger.info("collecting features for %i instances", count)
示例#8
0
文件: train.py 项目: buhman/borg
def main(out_path, portfolio_name, solvers_path, *tasks_roots):
    """Train a solver."""

    cargo.enable_default_logging()

    # load the solvers bundle
    bundle = borg.load_solvers(solvers_path)

    # train the portfolio
    training = borg.storage.TrainingData(tasks_roots, bundle.domain)
    portfolio = borg.portfolios.named[portfolio_name](bundle, training, 50.0, 42) # XXX

    logger.info("portfolio training complete")

    # write it to disk
    with open(out_path, "w") as out_file:
        pickle.dump(portfolio, out_file, protocol = -1)

    logger.info("portfolio written to %s", out_path)
示例#9
0
    def yield_runs():
        bundle = borg.load_solvers(solvers_path)
        paths = list(cargo.files_under(tasks_root, bundle.domain.extensions))

        if not paths:
            raise ValueError("no paths found under specified root")

        if only_solver is None:
            solver_names = bundle.solvers.keys()
        else:
            if only_solver not in bundle.solvers:
                raise ArgumentError("no such solver")

            solver_names = [only_solver]

        for _ in xrange(runs):
            for solver_name in solver_names:
                for path in paths:
                    yield (run_solver_on, [solvers_path, solver_name, path, budget])
示例#10
0
def main(out_path, portfolio_name, solvers_path, suffix = ".runs.csv", *tasks_roots):
    """Train a solver."""

    borg.enable_default_logging()

    # load the solvers bundle
    bundle = borg.load_solvers(solvers_path)

    # train the portfolio
    training = borg.storage.TrainingData.from_roots(tasks_roots, bundle.domain, suffix = suffix)
    portfolio = borg.portfolios.named[portfolio_name](bundle, training, 100.0, 60) # XXX

    logger.info("portfolio training complete")

    # write it to disk
    with open(out_path, "w") as out_file:
        pickle.dump(portfolio, out_file, protocol = -1)

    logger.info("portfolio written to %s", out_path)
示例#11
0
文件: solve.py 项目: buhman/borg
def main(
    model_path,
    solvers_path,
    input_path,
    seed = 42,
    budget = 3600.0,
    cores = 1,
    speed = borg.defaults.machine_speed,
    quiet = False
    ):
    """Solve a problem instance."""

    # XXX hackish
    borg.defaults.machine_speed = speed

    try:
        # general setup
        enable_output()

        if not quiet:
            cargo.get_logger("borg.solvers", level = "DETAIL")

        numpy.random.seed(seed)
        random.seed(numpy.random.randint(2**31))

        # run the solver
        bundle = borg.load_solvers(solvers_path)

        logger.info("loaded portfolio model from %s", model_path)

        with open(model_path) as file:
            portfolio = pickle.load(file)

        logger.info("solving %s", input_path)

        with bundle.domain.task_from_path(input_path) as task:
            remaining = budget - borg.get_accountant().total.cpu_seconds
            answer = portfolio(task, bundle, borg.Cost(cpu_seconds = remaining), cores)

            return bundle.domain.show_answer(task, answer)
    except KeyboardInterrupt:
        print "\nc terminating on SIGINT"
示例#12
0
def main(model_path,
         solvers_path,
         input_path,
         seed=42,
         budget=3600.0,
         cores=1,
         speed=borg.defaults.machine_speed,
         quiet=False):
    """Solve a problem instance."""

    # XXX hackish
    borg.defaults.machine_speed = speed

    try:
        # general setup
        enable_output()

        if not quiet:
            borg.get_logger("borg.solvers", level="DETAIL")

        borg.statistics.set_prng_seeds(seed)

        # run the solver
        bundle = borg.load_solvers(solvers_path)

        logger.info("loaded portfolio model from %s", model_path)

        with open(model_path) as file:
            portfolio = pickle.load(file)

        logger.info("solving %s", input_path)

        with bundle.domain.task_from_path(input_path) as task:
            remaining = budget - borg.get_accountant().total.cpu_seconds
            answer = portfolio(task, bundle, borg.Cost(cpu_seconds=remaining),
                               cores)

            return bundle.domain.show_answer(task, answer)
    except KeyboardInterrupt:
        print "\nc terminating on SIGINT"
示例#13
0
    def yield_runs():
        suite = borg.load_solvers(suite_path)

        logger.info("scanning paths under %s", tasks_root)

        paths = list(borg.util.files_under(tasks_root,
                                           suite.domain.extensions))

        if not paths:
            raise ValueError("no paths found under specified root")

        if only_solver is None:
            solver_names = suite.solvers.keys()
        else:
            solver_names = [only_solver]

        for path in paths:
            run_data = None

            if only_missing and os.path.exists(path + suffix):
                run_data = numpy.recfromcsv(path + suffix, usemask=True)

            for solver_name in solver_names:
                if only_missing and run_data is not None:
                    count = max(
                        0, runs - numpy.sum(run_data.solver == solver_name))
                else:
                    count = runs

                logger.info("scheduling %i run(s) of %s on %s", count,
                            solver_name, os.path.basename(path))

                for _ in xrange(count):
                    seed = numpy.random.randint(sys.maxint)

                    yield (run_solver_on, [
                        suite_path, solver_name, path, budget, store_answers,
                        seed
                    ])
示例#14
0
def run_solver_on(solvers_path, solver_name, task_path, budget):
    """Run a solver."""

    bundle = borg.load_solvers(solvers_path)

    with bundle.domain.task_from_path(task_path) as task:
        with borg.accounting() as accountant:
            answer = bundle.solvers[solver_name](task)(budget)

        succeeded = bundle.domain.is_final(task, answer)

    cost = accountant.total.cpu_seconds

    logger.info(
        "%s %s in %.2f (of %.2f) on %s",
        solver_name,
        "succeeded" if succeeded else "failed",
        cost,
        budget,
        os.path.basename(task_path),
        )

    return (solver_name, budget, cost, succeeded, answer)