Miscellaneous functions

Provides a reference of miscellaneous functions in IBM ILOG Script.

Table 1. Miscellaneous functions
Syntax Effect
stop() Stops the execution of the program at the current statement and, if the debugger is enabled, enters debug mode.

write (arg1, ..., argn)

writeln (arg1, ..., argn)

Converts the arguments to strings and prints them to the current debug output. The implementation depends on the application in which IBM ILOG Script is embedded. The function writeln prints a newline at the end of the output, while write does not. See the note on writeLine in this topic.
loadFile(string) Loads the script file whose path is string. The path can be either absolute or relative. If this path does not designate an existing file, the file is looked up using a method that depends on the application in which the script is embedded. Typically, a file with the name string is searched for in a list of directories specified in the application setup.
includeScript(string)

For use in OPL.

Loads the script file whose path is string. The path can be either absolute or relative. If this path does not designate an existing file, the file is looked up using a method that depends on the application in which the script is embedded. Typically, a file with the name string is searched for in a list of directories specified in the application setup.

The effect of this function is the same as for loadFile. In OPL, you have to use includeScript, as the function loadFile does not recognize OPL objects, such as thisOplModel.

eval(string)

Executes string as a program, and returns the value of the last evaluated expression. The program in string can use all the features of the language, except that it cannot define functions; in other words, the function statement is not allowed in string.

Examples:

eval("2*3") -> 6

eval("var i=0; for (var j=0; j<100; j++) i=i+j; i") -> 4950 n=25; eval("Math.sqrt(n)") -> 5 eval("function foo(x) { return x+1 }") -> error
fail()

Stops the execution of the scripting block at the current statement, reports an error, and goes on.

Example:

execute b1 { writeln("A"); fail(); writeln("B"); } execute b2 {writeln("C"); }

gives

A C

as the output

and reports an error line 4

Scripting runtime error: fail() called.

Note: IBM ILOG Script is implemented based on JavaScript ECMA-262 2nd edition. JavaScript only knows Numbers; it does not have a real notion of integers and floats. Numbers are 64 bits, whereas integers are 32 bits. All computations are done on Numbers so are 64bits. When calling toString on Numbers, JavaScript will have to handle the case of integers and so will behave on the display as 32bit for them.
Writeln is implemented as follows:
  • If the number is nan, it will return "NaN"
  • If the number is infinity => "Infinity"
  • If the number is 0.0 => "0"
  • If the number has the value of an integer, then the string is the same as if it were printed using sprintf("%d"). If the integer has an absolute value bigger than 2147483647, then it is replaced by +2147483647 or -2147483647 before printing. Note that this also applies to integers that are specified as floating point numbers, like, for example, 1e75.
  • If the number is a fractional number, then the display format depends on the absolute value of the number. If the absolute value is in [1e-6, 1e10], then the number is displayed with 9 decimal digits. Otherwise, it is printed in scientific format.
Any 0 at the end will be erased, so a string representing a floating point number should not end in zero.

The precision setting of OPL can only control printing performed by OPL: writeln of objects, printInternalData, printExternalData. There is no precision control for writeln of primitives.

execute{
writeln(0);
writeln(0.0);
writeln(0.567);
writeln(-0.567);
writeln(-20.0);
writeln(-20);
writeln(-5.123456786742);
writeln(-200000000000);
writeln(-200000000000.5);
writeln(0.000002340);
}

will output

0
0
0.567
-0.567
-20
-20
-5.123456787
-2147483648
-2.000000000e+11
2.340000000e-06
>>