This page is for an old version of Hexaly Optimizer. We recommend that you update your version and read the documentation for the latest stable release.

Built-in variables and functions

Parameters

Modeling & Solving

  • lsTimeLimit = {10, 50}; Spends 10 (resp. 50) sec to optimize objective 0 (resp. 1). Note that the braces must be omitted when setting the parameter in the command line.
  • lsTimeLimit = 60; Corresponds to lsTimeLimit = {0,..., 0, 60}.
  • lsIterationLimit = {1000, 5000}; Spends 1000 (resp. 5000) iterations to optimize objective 0 (resp. 1).
  • lsIterationLimit = 6000; Corresponds to lsIterationLimit = {0,..., 0, 6000}.
  • lsTimeBetweenDisplays = 5; Displays info about the search every 5 sec (default: 1).
  • lsSeed = 9; Sets pseudo-random number generator seed to 9 (default: 0).
  • lsNbThreads = 4; Parallelizes the search over 4 threads (default: 2).
  • lsAnnealingLevel = 9; Sets simulated annealing level to 9 (no annealing: 0, default: 1).
  • lsVerbosity = 1; Sets verbosity to 1 (no display: 0, default: 1, wordy : 2). In verbosity 2, each second, LocalSolver displays the elapsed time, the number of iterations and the current best objective value. The ‘’inf’‘, ‘’acc’’ and ‘’imp’’ figures refer to the percentage of moves leading to infeasible solutions, the percentage of accepted moves and the total number of improving moves, respectively.

Programming functions

Input & Output

  • f = io.openRead("data.in"); Opens file “data.in” in reading mode.
  • f = io.openWrite("data.out"); Opens file “data.out” in writing mode.
  • f = io.openAppend("data.out"); Opens file “data.out” in append mode.
  • f.close(); Closes the file.
  • f.eof() Returns true if the end of file is reached.
  • i = f.readInt(); Reads the next int parsed in file.
  • i = f.readDouble(); Reads the next floating-point number parsed in file.
  • s = f.readln(); Reads the next line of file.
  • s = f.readString(); Reads the next string parsed in file.
  • f.flush(); Flush the underlying buffer of the file.
  • print("s = " + s + "\n"); Prints the string in console.
  • f.print("s = " + s + "\n"); Prints the string in file.
  • println("s = " + s); Prints the string followed by a line feed in console.
  • f.println("s = " + s); Prints the string followed by a line feed in file.

Note

To use these functions, you must import the io module. For that, adds the following line at the beginning of your LSP file: use io;.

Map

  • m = {}; Creates an empty map.
  • m = {9, "abc"}; Creates a map containing values 9, “abc” at keys 0, 1 respectively.
  • nbElems = m.count(); Counts the number of values in the map.
  • elems = m.values(); Returns the values of the map as a map.
  • indices = m.keys(); Returns the keys of the map as a map.
  • m.add(123); Adds 123 in the map with key equals to the largest integer key plus one.

String

  • i = "123".toInt(); Converts the string into the corresponding integer.
  • i = "123.45".toDouble(); Converts the string into the corresponding floating-point number.
  • s = "    abcd  ".trim(); Removes white spaces at the beginning and at the end of the string.
  • len = "abcd".length(); Returns the length of a string.
  • m = "a  b  c  d".split(); Splits string “a b c d” into substrings (as a map). Whitespaces are used as delimiter.
  • m = "a::b::c::d".split("::"); Splits string “a::b::c::d” into substrings (as a map) according to the separator ”::”.
  • s = "abcd".substring(1,2); Returns a new string that is a substring of this string. There are two versions of this function: The first one takes one argument: the start index of the substring. The second one takes 2 arguments: the start index and the length of the substring.
  • b = "abcd".startsWith("ab"); Returns true if the string starts with the specified prefix. Returns true if the prefix is the empty string.
  • b = "abcd".endsWith("cd"); Returns true if the string ends with the specified suffix. Returns true if the suffix is the empty string.
  • s = "ABCD".toLowerCase(); Returns a new string converted to lower case.
  • s = "abcd".toUpperCase(); Returns a new string converted to upper case.
  • s = "I was just at home".indexOf("home"); Returns the position of the substring “home” in the string or -1 if the substring was not found.
  • s = "I was just at home".indexOf("home", 10); Returns the position of the substring “home” in the string, starting at the specified position or -1 if the substring was not found.
  • s = "abcd".replace("bc","x"); Replaces each substring of a string that matches the literal target string with the specified literal replacement string. The replacement proceeds from the beginning of the string to the end, for example, replacing “aa” with “b” in the string “aaaaa” will result in “bba” rather than “abb”.This function takes 2 arguments: the searched sequence and the replace sequence.

Modeling & Solving

  • getObjectiveThreshold(0); Gets the threshold of objective (with index) 0.
  • setObjectiveThreshold(0, 42.0); Sets the threshold of objective 0 to 42.0. The optimization of this objective will be stopped as soon as the given threshold is reached.
  • getObjectiveBound(0); Returns the bound computed by the solver for the objective (with index) 0.
  • v = x.value; Retrieves the value of modeling expression x in the best solution found by the solver.
  • x.value = 1; Sets the value of x to 1 in the initial solution (or throws an error if x is not a decision).
  • getSolutionStatus(); Returns the status of the solution. The status can be:
    • 0 for inconsistent model: the solver proved that the model admits no feasible solution
    • 1 for infeasible solution: the computed solution violates some constraints
    • 2 for feasible solution: the computed solution satisfies all constraints
    • 3 for optimal: the solution is feasible and its optimality has been proven.