Exemplo n.º 1
0
def _test_delayed_unbounded_min(comm):
    solver = Solver(comm=comm)
    baseline1 = SolverResults()
    baseline1.solution_status = "unbounded"
    baseline1.termination_condition = "optimality"
    baseline1.objective = -inf
    baseline1.bound = -inf
    baseline1.nodes = _ignore_value_
    baseline1.best_node = None
    baseline1.wall_time = _ignore_value_
    baseline2 = SolverResults()
    baseline2.solution_status = "unbounded"
    baseline2.termination_condition = "optimality"
    baseline2.objective = -inf
    baseline2.bound = -inf
    baseline2.nodes = 0
    baseline2.best_node = None
    baseline2.wall_time = _ignore_value_
    problem = delayed_unbounded_min.DelayedUnboundedMin()
    for queue_strategy in _queue_strategies:
        if queue_strategy == "custom":
            continue
        results = _execute_single_test(problem,
                                       baseline1,
                                       solver=solver,
                                       queue_strategy=queue_strategy)
        queue = solver.save_dispatcher_queue()
        _execute_single_test(problem,
                             baseline2,
                             solver=solver,
                             queue_strategy=queue_strategy,
                             initialize_queue=queue,
                             best_objective=results.objective,
                             best_node=results.best_node)
    # test the NestedSolver
    results = _execute_single_test(NestedSolver(problem,
                                                time_limit=None,
                                                node_limit=None),
                                   baseline1,
                                   solver=solver)
    queue = solver.save_dispatcher_queue()
    _execute_single_test(NestedSolver(problem,
                                      time_limit=None,
                                      node_limit=None),
                         baseline2,
                         solver=solver,
                         initialize_queue=queue,
                         best_objective=results.objective,
                         best_node=results.best_node)
Exemplo n.º 2
0
def _test_root_infeasible_min(comm):
    solver = Solver(comm=comm)
    baseline1 = SolverResults()
    baseline1.solution_status = "infeasible"
    baseline1.termination_condition = "optimality"
    baseline1.objective = inf
    baseline1.bound = inf
    baseline1.nodes = 1
    baseline1.best_node = None
    baseline1.wall_time = _ignore_value_
    baseline2 = SolverResults()
    baseline2.solution_status = "infeasible"
    baseline2.termination_condition = "optimality"
    baseline2.objective = inf
    baseline2.bound = inf
    baseline2.nodes = 0
    baseline2.best_node = None
    baseline2.wall_time = _ignore_value_
    problem = root_infeasible_min.RootInfeasibleMin()
    for queue_strategy in _queue_strategies:
        if queue_strategy == "custom":
            continue
        results = _execute_single_test(problem,
                                       baseline1,
                                       solver=solver,
                                       queue_strategy=queue_strategy)
        queue = solver.save_dispatcher_queue()
        _execute_single_test(problem,
                             baseline2,
                             solver=solver,
                             queue_strategy=queue_strategy,
                             initialize_queue=queue,
                             best_objective=results.objective,
                             best_node=results.best_node)
Exemplo n.º 3
0
def _execute_single_test(problem, baseline, solver=None, comm=None, **kwds):
    if solver is None:
        solver = Solver(comm=comm)
    else:
        assert comm is None
    if solver.comm is not None:
        if solver.comm.rank == 0:
            pass
        elif solver.comm.rank == 1:
            pass
        elif solver.comm.rank == 3:
            pass
    orig = Node()
    problem.save_state(orig)
    results = solver.solve(problem, **kwds)
    assert isinstance(results.solution_status, six.string_types)
    assert isinstance(results.termination_condition, six.string_types)
    current = Node()
    problem.save_state(current)
    assert current.state == orig.state
    assert len(vars(results)) > 0
    assert len(vars(results)) == len(vars(baseline))
    for name in sorted(sorted(list(vars(results).keys()))):
        if getattr(baseline, name) is _ignore_value_:
            continue
        if (name == 'nodes') and \
           (solver.comm is not None) and \
           (solver.comm.size > 2):
            pass
        else:
            assert getattr(results, name) == getattr(baseline, name), \
                ("value for '"+str(name)+"' ("+
                 str(getattr(results, name))+") does "
                 "not match baseline ("+
                 str(getattr(baseline, name))+")")
    if solver.is_dispatcher:
        q = solver.save_dispatcher_queue()
        assert len(q.nodes) == solver._disp.queue.size()
        assert q.sense == solver._disp.converger.sense
        assert q.worst_terminal_bound == solver._disp.worst_terminal_bound
        assert q.bound() == results.bound
    return results
Exemplo n.º 4
0
def _test_infeasible_max(comm):
    solver = None
    if comm is not None:
        solver = Solver(comm=comm)

    baseline = SolverResults()
    baseline.solution_status = "infeasible"
    baseline.termination_condition = "optimality"
    baseline.objective = -inf
    baseline.bound = -inf
    baseline.nodes = 255
    baseline.best_node = None
    baseline.wall_time = _ignore_value_
    problem = infeasible_max.InfeasibleMax()
    if comm is None:
        _execute_tests(comm, problem, baseline)
    else:
        _execute_single_test(problem, baseline, solver=solver)

    baseline = SolverResults()
    baseline.solution_status = "unknown"
    baseline.termination_condition = "queue_empty"
    baseline.objective = -inf
    baseline.bound = -16
    baseline.nodes = 31
    baseline.best_node = None
    baseline.wall_time = _ignore_value_
    problem = infeasible_max.InfeasibleMax(branching_abstol=0.1)
    if comm is None:
        _execute_tests(comm, problem, baseline)
    else:
        _execute_single_test(problem, baseline, solver=solver)

    baseline = SolverResults()
    baseline.solution_status = "unknown"
    baseline.termination_condition = "objective_limit"
    baseline.objective = -inf
    baseline.bound = -16
    baseline.nodes = 31
    baseline.best_node = None
    baseline.wall_time = _ignore_value_
    problem = infeasible_max.InfeasibleMax(branching_abstol=0.1)
    if comm is None:
        _execute_tests(comm, problem, baseline, bound_stop=-15)
    else:
        _execute_single_test(problem, baseline, solver=solver, bound_stop=-15)

    baseline = SolverResults()
    baseline.solution_status = "feasible"
    baseline.termination_condition = "objective_limit"
    baseline.objective = -20
    baseline.bound = -16
    baseline.absolute_gap = 4
    baseline.relative_gap = 0.2
    baseline.nodes = 31
    baseline.best_node = _ignore_value_
    baseline.wall_time = _ignore_value_
    problem = infeasible_max.InfeasibleMax(branching_abstol=0.1,
                                           fixed_objective=-20)
    if comm is None:
        _execute_tests(comm, problem, baseline, bound_stop=-15)
    else:
        _execute_single_test(problem, baseline, solver=solver, bound_stop=-15)

    baseline = SolverResults()
    baseline.solution_status = "unknown"
    baseline.termination_condition = "node_limit"
    baseline.objective = -inf
    baseline.bound = -16
    baseline.nodes = 31
    baseline.best_node = None
    baseline.wall_time = _ignore_value_
    problem = infeasible_max.InfeasibleMax()
    if comm is None:
        _execute_tests(comm, problem, baseline, node_limit=31)
    elif comm.size <= 2:
        # skip for larger comm sizes
        # as the node_limit can lead to
        # a number of different outcomes
        _execute_single_test(problem, baseline, solver=solver, node_limit=31)

    baseline = SolverResults()
    baseline.solution_status = "feasible"
    baseline.termination_condition = "node_limit"
    baseline.objective = -17
    baseline.bound = -16
    baseline.absolute_gap = 1.0
    baseline.relative_gap = 1.0 / 17
    baseline.nodes = 31
    baseline.best_node = _ignore_value_
    baseline.wall_time = _ignore_value_
    problem = infeasible_max.InfeasibleMax(fixed_objective=-17)
    if comm is None:
        _execute_tests(comm, problem, baseline, node_limit=31)
    elif comm.size <= 2:
        # skip for larger comm sizes
        # as the node_limit can lead to
        # a number of different outcomes
        _execute_single_test(problem, baseline, solver=solver, node_limit=31)

    baseline = SolverResults()
    baseline.solution_status = "unknown"
    baseline.termination_condition = "time_limit"
    baseline.objective = -inf
    baseline.bound = inf
    baseline.nodes = 0
    baseline.best_node = None
    baseline.wall_time = _ignore_value_
    problem = infeasible_max.InfeasibleMax()
    if comm is None:
        _execute_tests(comm, problem, baseline, time_limit=0)
    else:
        _execute_single_test(problem, baseline, solver=solver, time_limit=0)

    if solver is None:
        solver = Solver(comm=comm)
    baseline = SolverResults()
    baseline.solution_status = "infeasible"
    baseline.termination_condition = "optimality"
    baseline.objective = -inf
    baseline.bound = -inf
    baseline.nodes = 255
    baseline.best_node = None
    baseline.wall_time = _ignore_value_
    problem = infeasible_max.InfeasibleMax()
    for queue_strategy in _queue_strategies:
        if queue_strategy == "custom":
            continue
        _execute_single_test(problem,
                             baseline,
                             solver=solver,
                             queue_strategy=queue_strategy)

    baseline = SolverResults()
    baseline.solution_status = "invalid"
    baseline.termination_condition = "optimality"
    baseline.objective = -100000000
    baseline.bound = -inf
    baseline.nodes = _ignore_value_
    baseline.best_node = None
    baseline.wall_time = _ignore_value_
    problem = infeasible_max.InfeasibleMax()
    for queue_strategy in _queue_strategies:
        if queue_strategy == "custom":
            continue
        _execute_single_test(problem,
                             baseline,
                             solver=solver,
                             queue_strategy=queue_strategy,
                             best_objective=-100000000)

    baseline1 = SolverResults()
    baseline1.solution_status = "infeasible"
    baseline1.termination_condition = "optimality"
    baseline1.objective = -inf
    baseline1.bound = -inf
    baseline1.nodes = _ignore_value_
    baseline1.best_node = None
    baseline1.wall_time = _ignore_value_
    baseline2 = SolverResults()
    baseline2.solution_status = "infeasible"
    baseline2.termination_condition = "optimality"
    baseline2.objective = -inf
    baseline2.bound = -inf
    baseline2.nodes = _ignore_value_
    baseline2.best_node = None
    baseline2.wall_time = _ignore_value_
    problem = infeasible_max.InfeasibleMax()
    for queue_strategy in _queue_strategies:
        if queue_strategy == "custom":
            continue
        results = _execute_single_test(problem,
                                       baseline1,
                                       solver=solver,
                                       queue_strategy=queue_strategy)
        queue = solver.save_dispatcher_queue()
        _execute_single_test(problem,
                             baseline2,
                             solver=solver,
                             queue_strategy=queue_strategy,
                             initialize_queue=queue,
                             best_objective=results.objective,
                             best_node=results.best_node)