Skip to main content

Function: problem2txt()

problem2txt(model: Model, params?: Parameters, warmStart?: Solution, log?: null | WritableStream): Promise<string | undefined>

Converts a problem into a text format similar to the IBM CP Optimizer file format. The result is human-readable and can be stored in a file.

Parameters

ParameterTypeDescription
modelModelThe model to be exported.
params?ParametersThe parameters to pass to the solver (they are mostly unused).
warmStart?SolutionAn initial solution to start the solver with.
log?null | WritableStreamThe stream to which the solver output should be redirected. When undefined, the output is printed to the standard output. When null, the output is suppressed.

Returns

Promise<string | undefined>

A string containing the model in text format.

Remarks

Unlike JSON format, there is no way to convert the text format back into an instance of Model.

The result is so similar to the file format used by IBM CP Optimizer that, under some circumstances, the result can be used as an input file for CP Optimizer. However, some differences between OptalCP and CP Optimizer make it impossible to make sure the result is always valid for CP Optimizer. Known issues are:

  • OptalCP supports optional integer expressions, while CP Optimizer does not. If the model contains optional integer expressions, the result will not be valid for CP Optimizer or badly interpreted. For example, in order to get a valid CP Optimizer file, don't use function IntervalVar.start, use IntervalVar.startOr instead.
  • For the same reason, prefer precedence constraints such as Model.endBeforeStart over constraint(x.end().le(y.start())).
  • Negative heights in cumulative expressions (e.g., in Model.stepAtStart) are not supported by CP Optimizer.

The function uses OptalCP solver for the conversion. Therefore, it is asynchronous. To wait for the result, use the await keyword.

In case of an error, this function returns a rejected promise.