示例#1
0
        /// <summary>
        /// Gets the current bound for MIP.
        /// If the current solution is Optimal, then Bound equals objective Value.
        /// If not yet optimal, then Bound is best relaxation bound of all nodes left on the search tree.
        /// This value is not available for all solvers.
        /// </summary>
        /// <param name="solver">The solver. Only available for OsiCbc.</param>
        /// <returns>The current bound</returns>
        internal static double Bound(this COIN.OsiSolverInterface solver)
        {
            Ensure.NotNull(solver, "solver");

            if (solver.isProvenOptimal())
            {
                return(solver.getObjValue());
            }

            // not optimal, so depends per solver
            if (solver is COIN.OsiCbcSolverInterface osiCbc)
            {
                return(osiCbc.Model.getBestPossibleObjValue());
            }

            throw new NotImplementedException($"Bound is not implemented for OsiSolverInterface type {solver.GetType()}");
        }
示例#2
0
 /// <summary>
 /// Pass this message handler to the given solver.
 /// Warning: The solver will use the handler for all components. This likely has unintended consequences.
 /// </summary>
 /// <param name="solver">The solver to pass this message handler to.</param>
 public void PassToSolver(COIN.OsiSolverInterface solver)
 {
     solver.passInMessageHandler(messageHandler);
 }