1+ #include < HConst.h>
2+ #include < io/HighsIO.h>
3+
14#include < algorithm>
25#include < cassert>
36#include < climits>
@@ -424,7 +427,6 @@ class JumpMove {
424427};
425428
426429class FeasibilityJumpSolver {
427- int verbosity;
428430 Problem problem;
429431 JumpMove jumpMove;
430432
@@ -465,14 +467,16 @@ class FeasibilityJumpSolver {
465467 const size_t kMinEffortToLogging = 500 * kLoggingFrequency ;
466468 const double kMinRelativeObjectiveImprovement = 1e-4 ;
467469
470+ const HighsLogOptions& logOptions;
471+
468472 public:
469- FeasibilityJumpSolver (int seed = 0 , int _verbosity = 0 ,
473+ FeasibilityJumpSolver (const HighsLogOptions& _logOptions , int seed = 0 ,
470474 double equalityTolerance = 1e-5 ,
471475 double violationTolerance = 1e-5 ,
472476 double _weightUpdateDecay = 1.0 )
473- : problem(equalityTolerance, violationTolerance),
477+ : logOptions(_logOptions),
478+ problem(equalityTolerance, violationTolerance),
474479 jumpMove(equalityTolerance) {
475- verbosity = _verbosity;
476480 weightUpdateDecay = _weightUpdateDecay;
477481 rng = std::mt19937 (seed);
478482 }
@@ -491,10 +495,10 @@ class FeasibilityJumpSolver {
491495 int solve (double * initialValues,
492496 std::function<CallbackControlFlow(FJStatus)> callback) {
493497 assert (callback);
494- if (verbosity >= 1 )
495- printf ( FJ_LOG_PREFIX
496- " starting solve. weightUpdateDecay=%g, relaxContinuous=%d \n " ,
497- weightUpdateDecay, problem.usedRelaxContinuous );
498+ highsLogUser (logOptions, HighsLogType:: kInfo ,
499+ FJ_LOG_PREFIX
500+ " starting solve. weightUpdateDecay=%g, relaxContinuous=%d \n " ,
501+ weightUpdateDecay, problem.usedRelaxContinuous );
498502
499503 init (initialValues);
500504
@@ -504,8 +508,7 @@ class FeasibilityJumpSolver {
504508 if (user_terminate (callback, nullptr )) break ;
505509
506510 if (step % kLoggingFrequency == 0 &&
507- totalEffort > effortAtLastLogging + kMinEffortToLogging &&
508- verbosity >= 1 ) {
511+ totalEffort > effortAtLastLogging + kMinEffortToLogging ) {
509512 if (need_logging_header) {
510513 logging (0 , true );
511514 num_logging_lines_since_header = 0 ;
@@ -532,7 +535,7 @@ class FeasibilityJumpSolver {
532535 if (user_terminate (callback, problem.incumbentAssignment .data ()))
533536 break ;
534537 // Repeat the header in case user callback logs new solution
535- if (verbosity >= 1 ) need_logging_header = true ;
538+ need_logging_header = true ;
536539 }
537540 }
538541
@@ -547,16 +550,19 @@ class FeasibilityJumpSolver {
547550
548551 private:
549552 void logging (const int step, const bool header = false ) {
553+ const HighsLogType logType = HighsLogType::kInfo ;
550554 if (header) {
551- printf (FJ_LOG_PREFIX
552- " step violations good bumps effort (per "
553- " step) Objective\n " );
555+ highsLogUser (
556+ logOptions, logType,
557+ FJ_LOG_PREFIX
558+ " step violations good bumps effort (per "
559+ " step) Objective\n " );
554560 } else {
555- printf (FJ_LOG_PREFIX
556- " %10d %8zd %6zd %8zd %12zd %6zd %10.4g\n " ,
557- step, problem.violatedConstraints .size (), goodVarsSet.size (),
558- nBumps, totalEffort, step > 0 ? totalEffort / step : 0 ,
559- problem.incumbentObjective );
561+ highsLogUser (logOptions, logType,
562+ " %10d %8zd %6zd %8zd %12zd %6zd %10.4g\n " ,
563+ step, problem.violatedConstraints .size (), goodVarsSet.size (),
564+ nBumps, totalEffort, step > 0 ? totalEffort / step : 0 ,
565+ problem.incumbentObjective );
560566 effortAtLastLogging = totalEffort;
561567 }
562568 }
@@ -626,7 +632,8 @@ class FeasibilityJumpSolver {
626632 }
627633
628634 void updateWeights () {
629- if (verbosity >= 2 ) printf (FJ_LOG_PREFIX " Reached a local minimum.\n " );
635+ highsLogDev (logOptions, HighsLogType::kVerbose ,
636+ FJ_LOG_PREFIX " Reached a local minimum.\n " );
630637 nBumps += 1 ;
631638 bool rescaleAllWeights = false ;
632639 size_t dt = 0 ;
@@ -761,7 +768,8 @@ class FeasibilityJumpSolver {
761768 const int CALLBACK_EFFORT = 500000 ; // Originally 500000
762769 if (solution != nullptr ||
763770 totalEffort - effortAtLastCallback > CALLBACK_EFFORT) {
764- if (verbosity >= 2 ) printf (FJ_LOG_PREFIX " calling user termination.\n " );
771+ highsLogDev (logOptions, HighsLogType::kVerbose ,
772+ FJ_LOG_PREFIX " calling user termination.\n " );
765773 effortAtLastCallback = totalEffort;
766774
767775 FJStatus status;
@@ -774,7 +782,8 @@ class FeasibilityJumpSolver {
774782
775783 auto result = callback (status);
776784 if (result == CallbackControlFlow::Terminate) {
777- if (verbosity >= 2 ) printf (FJ_LOG_PREFIX " quitting.\n " );
785+ highsLogDev (logOptions, HighsLogType::kVerbose ,
786+ FJ_LOG_PREFIX " quitting.\n " );
778787 return true ;
779788 }
780789 }
0 commit comments