pybnb.solver_results¶
Branch-and-bound solver results object.
Copyright by Gabriel A. Hackebeil (gabe.hackebeil@gmail.com).
- class pybnb.solver_results.SolverResults[source]¶
Stores the results of a branch-and-bound solve.
- solution_status¶
The solution status will be set to one of the strings documented by the
SolutionStatus
enum.- Type
string
- termination_condition¶
The solve termination condition, as determined by the dispatcher, will be set to one of the strings documented by the
TerminationCondition
enum.- Type
string
- objective¶
The best objective found.
- Type
float
- bound¶
The global optimality bound.
- Type
float
- absolute_gap¶
The absolute gap between the objective and bound. This will only be set when the solution status sf “optimal” or “feasible”; otherwise, it will be None.
- Type
float or None
- relative_gap¶
The relative gap between the objective and bound. This will only be set when the solution status sf “optimal” or “feasible”; otherwise, it will be None.
- Type
float or None
- nodes¶
The total number of nodes processes by all workers.
- Type
int
- wall_time¶
The process-local wall time (seconds). This is the only value on the results object that varies between processes.
- Type
float
- best_node¶
The node with the best objective obtained during the solve. Note that if the best_objective solver option was used, the best_node on the results object may have an objective that is worse than the objective stored on the results (or may be None).
- Type
- pprint(stream=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>)[source]¶
Prints a nicely formatted representation of the results.
- Parameters
stream (file-like object or string, optional) – A file-like object or a filename where results should be written to. (default:
sys.stdout
)
- write(stream, prefix='', pretty=False)[source]¶
Writes results in YAML format to a stream or file. Changing the parameter values from their defaults may result in the output becoming non-compatible with the YAML format.
- Parameters
stream (file-like object or string) – A file-like object or a filename where results should be written to.
prefix (string, optional) – A string to use as a prefix for each line that is written. (default: ‘’)
pretty (bool, optional) – Indicates whether or not certain recognized attributes should be formatted for more human-readable output. (default: False)
Example
>>> import six >>> import pybnb >>> results = pybnb.SolverResults() >>> results.best_node = pybnb.Node() >>> results.best_node.objective = 123 >>> out = six.StringIO() >>> # the best_node is serialized >>> results.write(out) >>> del results >>> import yaml >>> results_dict = yaml.safe_load(out.getvalue()) >>> # de-serialize the best_node >>> best_node = pybnb.node.loads(results_dict['best_node']) >>> assert best_node.objective == 123