Skip to content

Commit

Permalink
Replaced fprintf(file in HighsModelUtils.cpp by stringstreams and cal…
Browse files Browse the repository at this point in the history
…ls to highsFprintfString(file, log_options
  • Loading branch information
jajhall committed Jul 10, 2024
1 parent 2d078b0 commit 0c6b253
Show file tree
Hide file tree
Showing 6 changed files with 323 additions and 240 deletions.
10 changes: 5 additions & 5 deletions check/TestCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ HighsCallbackFunctionType userInterruptCallback =
REQUIRE(local_callback_data == kUserCallbackNoData);
}
if (callback_type == kCallbackLogging) {
if (dev_run)
printf("Callback: %s", message.c_str());
// printf("userInterruptCallback(type %2d; data %2d): %s",
// callback_type, local_callback_data, message.c_str());
if (dev_run) printf("Callback: %s", message.c_str());
// printf("userInterruptCallback(type %2d; data %2d): %s",
// callback_type, local_callback_data,
// message.c_str());
} else if (callback_type == kCallbackSimplexInterrupt) {
if (dev_run)
printf(
Expand Down Expand Up @@ -267,7 +267,7 @@ TEST_CASE("highs-callback-logging", "[highs-callback]") {
}

TEST_CASE("highs-callback-solution-basis-logging", "[highs-callback]") {
std::string filename = std::string(HIGHS_DIR) + "/check/instances/avgas.mps";
std::string filename = std::string(HIGHS_DIR) + "/check/instances/avgas.mps";
int user_callback_data = kUserCallbackData;
void* p_user_callback_data =
reinterpret_cast<void*>(static_cast<intptr_t>(user_callback_data));
Expand Down
6 changes: 3 additions & 3 deletions src/io/HighsIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,14 @@ void highsLogDev(const HighsLogOptions& log_options_, const HighsLogType type,
va_end(argptr);
}

void highsFprintfString(FILE* file, const HighsLogOptions& log_options_,
const std::string& s) {
void highsFprintfString(FILE* file, const HighsLogOptions& log_options_,
const std::string& s) {
if (file == nullptr) return;
if (file == stdout) {
highsLogUser(log_options_, HighsLogType::kInfo, "%s", s.c_str());
} else {
fprintf(file, "%s", s.c_str());
}
}
}

void highsReportDevInfo(const HighsLogOptions* log_options,
Expand Down
7 changes: 4 additions & 3 deletions src/io/HighsIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,12 @@ void highsLogDev(const HighsLogOptions& log_options_, const HighsLogType type,
const char* format, ...);

/**
* @brief Replaces fprintf(file,... so that when file=stdout highsLogUser is used
* @brief Replaces fprintf(file,... so that when file=stdout highsLogUser is
* used
*/
// Printing format: must contain exactly one "\n" at end of format
void highsFprintfString(FILE* file, const HighsLogOptions& log_options_,
const std::string& s);
void highsFprintfString(FILE* file, const HighsLogOptions& log_options_,
const std::string& s);

/**
* @brief For development logging when true log_options may not be available -
Expand Down
Loading

0 comments on commit 0c6b253

Please sign in to comment.