From f3c2191ae7aaa27e1d612943defbeacc50e7b17b Mon Sep 17 00:00:00 2001 From: Charlie Vanaret Date: Wed, 20 Nov 2024 12:35:27 +0100 Subject: [PATCH] Overloaded Uno::solve() with no user callbacks (this passes a NoUserCallbacks object that does nothing) --- uno/Uno.cpp | 8 ++++++++ uno/Uno.hpp | 2 ++ uno/tools/UserCallbacks.hpp | 9 +++++++++ 3 files changed, 19 insertions(+) diff --git a/uno/Uno.cpp b/uno/Uno.cpp index d08f9201..0f0a2897 100644 --- a/uno/Uno.cpp +++ b/uno/Uno.cpp @@ -31,6 +31,14 @@ namespace uno { Level Logger::level = INFO; + // solve without user callbacks + void Uno::solve(const Model& model, Iterate& current_iterate, const Options& options) { + // pass user callbacks that do nothing + NoUserCallbacks user_callbacks{}; + this->solve(model, current_iterate, options, user_callbacks); + } + + // solve with user callbacks void Uno::solve(const Model& model, Iterate& current_iterate, const Options& options, UserCallbacks& user_callbacks) { Timer timer{}; Statistics statistics = Uno::create_statistics(model, options); diff --git a/uno/Uno.hpp b/uno/Uno.hpp index 08534f67..716c0c43 100644 --- a/uno/Uno.hpp +++ b/uno/Uno.hpp @@ -20,6 +20,8 @@ namespace uno { public: Uno(GlobalizationMechanism& globalization_mechanism, const Options& options); + // solve with or without user callbacks + void solve(const Model& model, Iterate& initial_iterate, const Options& options); void solve(const Model& model, Iterate& initial_iterate, const Options& options, UserCallbacks& user_callbacks); static std::string current_version(); diff --git a/uno/tools/UserCallbacks.hpp b/uno/tools/UserCallbacks.hpp index 0939c73c..d1285fec 100644 --- a/uno/tools/UserCallbacks.hpp +++ b/uno/tools/UserCallbacks.hpp @@ -19,6 +19,15 @@ namespace uno { virtual void notify_new_primals(const Vector& primals) = 0; virtual void notify_new_multipliers(const Multipliers& multipliers) = 0; }; + + class NoUserCallbacks: public UserCallbacks { + public: + NoUserCallbacks(): UserCallbacks() { } + + void notify_acceptable_iterate(const Vector& /*primals*/, const Multipliers& /*multipliers*/, double /*objective_multiplier*/) override { } + void notify_new_primals(const Vector& /*primals*/) override { } + void notify_new_multipliers(const Multipliers& /*multipliers*/) override { } + }; } // namespace #endif //UNO_USERCALLBACKS_H \ No newline at end of file