diff --git a/src/specmicp_common/micpsolver/micpsolver_base.inl b/src/specmicp_common/micpsolver/micpsolver_base.inl index 4d20b88..d64bb25 100644 --- a/src/specmicp_common/micpsolver/micpsolver_base.inl +++ b/src/specmicp_common/micpsolver/micpsolver_base.inl @@ -1,190 +1,195 @@ /* ============================================================================= Copyright (c) 2014 - 2016 F. Georget Princeton University All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ============================================================================= */ #include "micpsolver_base.hpp" // syntaxic coloration namespace specmicp { namespace micpsolver { // ref : Munson et al. (2001) template void MiCPSolverBaseProgram::scaling_jacobian( const Matrix& jacobian, const Vector& residuals, Vector& rscaler, Vector& cscaler) { for (int i=0; i MiCPSolverReturnCode MiCPSolverBaseProgram::check_convergence( int nb_iterations, const Vector& update, const Vector& solution, const Vector& residuals, bool may_have_converged ) { MiCPSolverReturnCode termcode = MiCPSolverReturnCode::NotConvergedYet; const scalar_t norm_residuals = residuals.lpNorm(); if (norm_residuals < get_options().fvectol) { if (may_have_converged == true) termcode = MiCPSolverReturnCode::ResidualMinimized; } else if (nb_iterations >0 and norm_update(update, solution) < get_options().steptol) { if (norm_residuals > get_options().threshold_stationary_point) { ERROR << "Stationary point detected !"; termcode = MiCPSolverReturnCode::StationaryPoint; } if (may_have_converged == true) { WARNING << "MiCP solver : Error is minimized - may indicate a stationnary point"; termcode = MiCPSolverReturnCode::ErrorMinimized; } } else if (nb_iterations > get_options().max_iter) { - ERROR << "Maximum number of iteration reached (" << get_options().max_iter << ")"; + ERROR << "Maximum number of iteration reached (" + << get_options().max_iter << ")\n" + << "Current solution vector \n ---- \n" + << solution + << "\n ---- \n"; + termcode = MiCPSolverReturnCode::MaxIterations; } else if (get_perfs().max_taken) { ++get_perfs().nb_consecutive_max_taken; ++get_perfs().nb_max_taken; if (get_perfs().nb_consecutive_max_taken == get_options().maxiter_maxstep) { ERROR << "Divergence detected - Maximum step length taken two many times"; termcode = MiCPSolverReturnCode::MaxStepTakenTooManyTimes; } } else { get_perfs().nb_consecutive_max_taken = 0; } return termcode; } template void MiCPSolverBaseProgram::reformulate_jacobian_cck( const Vector& x, const Vector& r, Matrix& jacobian ) { // set the z vector : contains 1 for degenerate points Eigen::VectorXd z(Eigen::VectorXd::Zero(get_neq())); for (index_t i=get_neq_free(); i 0) and (x(i) >0)) { c -= (1-lambda)*r(i); d -= (1-lambda)*x(i); } jacobian.row(i) *= d; jacobian(i, i) += c; } } } // Projection of the variables onto the feasible set template void MiCPSolverBaseProgram::projection(Vector& x) { for (index_t i=0; inb_complementarity_variables(); ++i) { if (x(i+get_program()->nb_free_variables()) < get_options().projection_min_variable) { x(i+get_program()->nb_free_variables()) = 0; } } } template scalar_t MiCPSolverBaseProgram::is_step_too_long(Vector& update) { scalar_t steplength = update.norm(); if (steplength > get_options().maxstep) { get_perfs().max_taken = true; update = get_options().maxstep / steplength * update; steplength = get_options().maxstep; } return steplength; } } // end namespace micpsolver } // end namespace specmicp