Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
ortools.math_opt.python.message_callback Namespace Reference

Functions

SolveMessageCallback printer_message_callback (*, TextIO file=sys.stdout, str prefix="")
 
None log_messages (Sequence[str] messages, *, int level=logging.INFO, str prefix="")
 
None vlog_messages (Sequence[str] messages, int level, *, str prefix="")
 
SolveMessageCallback list_message_callback (List[str] sink)
 

Variables

 SolveMessageCallback = Callable[[Sequence[str]], None]
 

Detailed Description

Definition and tools for message callbacks.

Message callbacks are used to get the text messages emitted by solvers during
the solve.

  Typical usage example:

  # Print messages to stdout.
  result = solve.solve(
      model, parameters.SolverType.GSCIP,
      msg_cb=message_callback.printer_message_callback(prefix='[solver] '))

  # Log messages with absl.logging.
  result = solve.solve(
      model, parameters.SolverType.GSCIP,
      msg_cb=lambda msgs: message_callback.log_messages(
          msgs, prefix='[solver] '))

Function Documentation

◆ list_message_callback()

SolveMessageCallback ortools.math_opt.python.message_callback.list_message_callback ( List[str] sink)
Returns a message callback that logs messages to a list.

Args:
  sink: The list to append messages to.

Returns:
  A function matching the expected signature for message callbacks.

Definition at line 126 of file message_callback.py.

◆ log_messages()

None ortools.math_opt.python.message_callback.log_messages ( Sequence[str] messages,
* ,
int level = logging.INFO,
str prefix = "" )
Logs the input messages from a message callback using absl.logging.log().

It logs each line with the given prefix. It setups absl.logging so that the
logs use the file name and line of the caller of this function.

  Typical usage example:

  result = solve.solve(
      model, parameters.SolverType.GSCIP,
      msg_cb=lambda msgs: message_callback.log_messages(
          msgs, prefix='[solver] '))

Args:
  messages: The messages received in the message callback (typically a lambda
    function in the caller code).
  level: One of absl.logging.(DEBUG|INFO|WARNING|ERROR|FATAL).
  prefix: The prefix to print in front of each line.

Definition at line 72 of file message_callback.py.

◆ printer_message_callback()

SolveMessageCallback ortools.math_opt.python.message_callback.printer_message_callback ( * ,
TextIO file = sys.stdout,
str prefix = "" )
Returns a message callback that prints to a file.

It prints its output to the given text file, prefixing each line with the
given prefix.

For each call to the returned message callback, the output_stream is flushed.

Args:
  file: The file to print to. It prints to stdout by default.
  prefix: The prefix to print in front of each line.

Returns:
  A function matching the expected signature for message callbacks.

Definition at line 42 of file message_callback.py.

◆ vlog_messages()

None ortools.math_opt.python.message_callback.vlog_messages ( Sequence[str] messages,
int level,
* ,
str prefix = "" )
Logs the input messages from a message callback using absl.logging.vlog().

It logs each line with the given prefix. It setups absl.logging so that the
logs use the file name and line of the caller of this function.

  Typical usage example:

  result = solve.solve(
      model, parameters.SolverType.GSCIP,
      msg_cb=lambda msgs: message_callback.vlog_messages(
          msgs, 1, prefix='[solver] '))

Args:
  messages: The messages received in the message callback (typically a lambda
    function in the caller code).
  level: The verbose log level, e.g. 1, 2...
  prefix: The prefix to print in front of each line.

Definition at line 100 of file message_callback.py.

Variable Documentation

◆ SolveMessageCallback

ortools.math_opt.python.message_callback.SolveMessageCallback = Callable[[Sequence[str]], None]

Definition at line 39 of file message_callback.py.