示例#1
0
文件: misc.py 项目: ghackebeil/pybnb
def _run_command_line_solver(problem, args):
    import pybnb

    if args.nested_solver:
        problem = pybnb.futures.NestedSolver(
            problem,
            node_limit=args.nested_node_limit,
            time_limit=args.nested_time_limit,
            queue_limit=args.nested_queue_limit,
            track_bound=args.nested_track_bound,
            queue_strategy=args.nested_queue_strategy,
        )
    else:
        nested_solver_defaults = get_default_args(
            pybnb.futures.NestedSolver.__init__)
        if (args.nested_node_limit !=
                nested_solver_defaults["node_limit"]):  # pragma:nocover
            logging.getLogger("pybnb").warning(
                "The user-specified --nested-node-limit "
                "setting will be ignored. Did you forget the "
                "--nested-solver flag?")
        if (args.nested_time_limit !=
                nested_solver_defaults["time_limit"]):  # pragma:nocover
            logging.getLogger("pybnb").warning(
                "The user-specified --nested-time-limit "
                "setting will be ignored. Did you forget the "
                "--nested-solver flag?")
        if (args.nested_queue_limit !=
                nested_solver_defaults["queue_limit"]):  # pragma:nocover
            logging.getLogger("pybnb").warning(
                "The user-specified --nested-queue-limit "
                "setting will be ignored. Did you forget the "
                "--nested-solver flag?")
        if (args.nested_track_bound !=
                nested_solver_defaults["track_bound"]):  # pragma:nocover
            logging.getLogger("pybnb").warning(
                "The user-specified --nested-disable-track-bound "
                "setting will be ignored. Did you forget the "
                "--nested-solver flag?")
        if (args.nested_queue_strategy !=
                nested_solver_defaults["queue_strategy"]):  # pragma:nocover
            logging.getLogger("pybnb").warning(
                "The user-specified --nested-queue-strategy "
                "setting will be ignored. Did you forget the "
                "--nested-solver flag?")
    solve_kwds = dict(vars(args))
    del solve_kwds["disable_mpi"]
    del solve_kwds["profile"]
    del solve_kwds["nested_solver"]
    del solve_kwds["nested_node_limit"]
    del solve_kwds["nested_time_limit"]
    del solve_kwds["nested_queue_limit"]
    del solve_kwds["nested_track_bound"]
    del solve_kwds["nested_queue_strategy"]
    if args.disable_mpi:
        results = pybnb.solve(problem, comm=None, **solve_kwds)
    else:
        results = pybnb.solve(problem, **solve_kwds)
    return results
示例#2
0
def _run_command_line_solver(problem, args):
    import pybnb
    solve_kwds = dict(vars(args))
    del solve_kwds["disable_mpi"]
    del solve_kwds["profile"]
    if args.disable_mpi:
        results = pybnb.solve(problem, comm=None, **solve_kwds)
    else:
        results = pybnb.solve(problem, **solve_kwds)
    return results
示例#3
0
                        help=("When set, saves the solver results into a "
                              "YAML-formated file with the given name."))
    args = parser.parse_args()

    problem = Rosenbrock2D(xL=-25, xU=25, yL=-25, yU=25)

    # do parallel bounds tightening on the
    # first 7 nodes that are processed
    obrr = Rosenbrock2D_RangeReduction(problem, comm=comm)

    queue = None
    best_node = None
    if (comm is None) or (comm.rank == 0):
        opt_obrr = pybnb.Solver(comm=None)
        results = opt_obrr.solve(obrr, node_limit=7, log_interval_seconds=0)
        queue = opt_obrr.save_dispatcher_queue()
        best_node = results.best_node
    else:
        obrr.listen(root=0)
    del obrr

    # continue the solve in parallel, without bounds
    # tightening on the remaining nodes
    results = pybnb.solve(problem,
                          comm=comm,
                          relative_gap=1e-4,
                          dispatcher_rank=0,
                          best_node=best_node,
                          initialize_queue=queue,
                          results_filename=args.results_filename)
示例#4
0
    def objective(self):
        if self.node == self.last_node:
            self.solution = solve_formula(self.instances, self.partition,
                                          self.weights)
        return self.solution

    def bound(self):
        self._bound = get_bound(self.instances, self.partition, self.weights)
        return self._bound

    def save_state(self, node):
        node.state = self.partition

    def load_state(self, node):
        self.partition = node.state

    def branch(self):
        if (self._bound > self.solution) and (self.last_node > self.node + 1):
            self.stash.append([self.node + 1, False])
            self.stash.append([self.node + 1, True])
        self.node, self.value = self.stash.pop()
        self.partition[str(self.node)] = self.value
        node = pybnb.Node()
        node.state = self.partition
        yield node


problem = Experiment(problem_set)
results = pybnb.solve(problem, relative_gap=1e-4)
print(results)
示例#5
0
        best_objective = problem.objective()
    if (comm is not None) and (comm.size > 1):
        best_objective = comm.bcast(best_objective, root=0)
    assert best_objective != problem.unbounded_objective

    # do parallel bounds tightening on the
    # first 7 nodes that are processed
    obrr = Rosenbrock2D_RangeReduction(problem, best_objective, comm=comm)

    dispatcher_queue = None
    if (comm is None) or (comm.rank == 0):
        opt_obrr = pybnb.Solver(comm=None)
        results = opt_obrr.solve(obrr,
                                 node_limit=7,
                                 best_objective=best_objective,
                                 log_interval_seconds=0)
        dispatcher_queue = opt_obrr.save_dispatcher_queue()
        best_objective = results.objective
    else:
        obrr.listen(root=0)
    del obrr

    # continue the solve in parallel, without bounds
    # tightening on the remaining nodes
    results = pybnb.solve(problem,
                          comm=comm,
                          dispatcher_rank=0,
                          best_objective=best_objective,
                          initialize_queue=dispatcher_queue,
                          results_filename=args.results_filename)