Skip to content

Commit

Permalink
[solvers] Fix Gurobi console logging config to happen first (RobotLoc…
Browse files Browse the repository at this point in the history
  • Loading branch information
jwnimmer-tri authored and RussTedrake committed Dec 15, 2024
1 parent b03566c commit c04faa6
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion solvers/gurobi_solver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@ void GurobiSolver::DoSolve2(const MathematicalProgram& prog,
const std::optional<std::string> grb_write =
options->template Pop<std::string>("GRBwrite");

// Copy the remaining options into model_env.
// Convert the common options into their Gurobi flavor.
options->Respell([](const auto& common, auto* respelled) {
respelled->emplace("LogToConsole", common.print_to_console ? 1 : 0);
if (!common.print_file_name.empty()) {
Expand Down Expand Up @@ -986,6 +986,11 @@ void GurobiSolver::DoSolve2(const MathematicalProgram& prog,
DRAKE_DEMAND(num_threads.has_value());
respelled->emplace("Threads", *num_threads);
});

// Copy the remaining options into model_env. Set the logging level first, so
// that changes to any of the other options are uniformly logged (or not).
SetOptionOrThrow(model_env, "LogToConsole",
options->Pop<int>("LogToConsole").value_or(0));
options->CopyToCallbacks(
[&model_env](const std::string& key, double value) {
SetOptionOrThrow(model_env, key, value);
Expand Down

0 comments on commit c04faa6

Please sign in to comment.