Skip to main content

Function: problem2txt

problem2txt(model, params?, warmStart?, log?): Promise<string | undefined>

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

Parameters

NameTypeDescription
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 then the output is printed to the standard output. When null then 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 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 there are some differences between OptalCP and CP Optimizer that makes 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 it will be badly interpreted. For example, in order to get valid CP Optimizer file, don't use function start, use startOr instead.
  • For the same reason, prefer precedence constraints such as endBeforeStart over constraint(x.end().le(y.start())).
  • Negative heights in cumulative expressions (e.g. in stepAtStart) are not supported by CP Optimizer.

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

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