77#include < random>
88#include < vector>
99
10+ #include " io/HighsIO.h"
11+ #include " lp_data/HConst.h"
12+
1013#define FJ_LOG_PREFIX " Feasibility Jump: "
1114
1215// TIP: clang-format the reference feasibilityjump.hh before diffing with this
@@ -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+ highsLogDev (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,18 @@ class FeasibilityJumpSolver {
547550
548551 private:
549552 void logging (const int step, const bool header = false ) {
553+ const HighsLogType logType = HighsLogType::kDetailed ;
550554 if (header) {
551- printf (FJ_LOG_PREFIX
552- " step violations good bumps effort (per "
553- " step) Objective\n " );
555+ highsLogDev (logOptions, logType,
556+ FJ_LOG_PREFIX
557+ " step violations good bumps effort (per "
558+ " step) Objective\n " );
554559 } 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 );
560+ highsLogDev (logOptions, logType,
561+ " %10d %8zd %6zd %8zd %12zd %6zd %10.4g\n " ,
562+ step, problem.violatedConstraints .size (), goodVarsSet.size (),
563+ nBumps, totalEffort, step > 0 ? totalEffort / step : 0 ,
564+ problem.incumbentObjective );
560565 effortAtLastLogging = totalEffort;
561566 }
562567 }
@@ -626,7 +631,8 @@ class FeasibilityJumpSolver {
626631 }
627632
628633 void updateWeights () {
629- if (verbosity >= 2 ) printf (FJ_LOG_PREFIX " Reached a local minimum.\n " );
634+ highsLogDev (logOptions, HighsLogType::kVerbose ,
635+ FJ_LOG_PREFIX " Reached a local minimum.\n " );
630636 nBumps += 1 ;
631637 bool rescaleAllWeights = false ;
632638 size_t dt = 0 ;
@@ -761,7 +767,8 @@ class FeasibilityJumpSolver {
761767 const int CALLBACK_EFFORT = 500000 ; // Originally 500000
762768 if (solution != nullptr ||
763769 totalEffort - effortAtLastCallback > CALLBACK_EFFORT) {
764- if (verbosity >= 2 ) printf (FJ_LOG_PREFIX " calling user termination.\n " );
770+ highsLogDev (logOptions, HighsLogType::kVerbose ,
771+ FJ_LOG_PREFIX " calling user termination.\n " );
765772 effortAtLastCallback = totalEffort;
766773
767774 FJStatus status;
@@ -774,7 +781,8 @@ class FeasibilityJumpSolver {
774781
775782 auto result = callback (status);
776783 if (result == CallbackControlFlow::Terminate) {
777- if (verbosity >= 2 ) printf (FJ_LOG_PREFIX " quitting.\n " );
784+ highsLogDev (logOptions, HighsLogType::kVerbose ,
785+ FJ_LOG_PREFIX " quitting.\n " );
778786 return true ;
779787 }
780788 }
0 commit comments