LocalSolver logo
is now
Hexaly logo

We're excited to share that we are moving forward. We're leaving behind the LocalSolver brand and transitioning to our new identity: Hexaly. This represents a leap forward in our mission to enable every organization to make better decisions faster when faced with operational and strategic challenges.

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.

LSParam Class

class localsolver::LSParam

Solving parameters.

This class contains some methods allowing you to parameterize the resolution of the model. For the sake of simplicity, only a few parameters are actually offered to tune the search.

Summary

Functions
setSeed Sets the seed of the pseudo-random number generator used by the solver.
getSeed Gets the seed of the pseudo-random number generator used by the solver.
setNbThreads Sets the number of threads used to parallelize the search.
getNbThreads Gets the number of threads.
setAnnealingLevel Sets the simulated annealing level.
getAnnealingLevel Gets the simulated annealing level.
setVerbosity Sets the verbosity level of the solver.
getVerbosity Gets the verbosity level of the solver.
setObjectiveBound Sets the bound of the objective with the given index.
setIntObjectiveBound Sets the bound of the objective with the given index.
setDoubleObjectiveBound Sets the bound of the objective with the given index.
getObjectiveBound Gets the bound of the objective with the given index.
getIntObjectiveBound Gets the bound of the objective with the given index.
getDoubleObjectiveBound Gets the bound of the objective with the given index.
setTimeBetweenDisplays Sets the time in seconds between two consecutive displays in console while the solver is running.
getTimeBetweenDisplays Gets the time in seconds between two consecutive displays in console while the solver is running.
setTimeBetweenTicks Sets the time in seconds between two events of type CT_TimeTicked.
getTimeBetweenTicks Gets the time in seconds between two events of type CT_TimeTicked.
setIterationBetweenTicks Sets the number of iterations between two events of type CT_IterationTicked.
getIterationBetweenTicks Gets the number of iterations between two events of type CT_IterationTicked.
setLogFile Sets the path of the LocalSolver log file.
getLogFile Returns the path of the LocalSolver log file.
setAdvancedParam Sets the value of an advanced parameter.
getAdvancedParam Returns the value of an advanced parameter.
toString Returns a string representation of these parameters.

Functions

void setSeed(int seed)

Sets the seed of the pseudo-random number generator used by the solver.

The seed must be a positive integer. The default seed is set to 0. Only allowed in state S_Stopped.

The search for solutions is highly randomized. Fixing the seed and the number of iterations of the solver allows you to reproduce exactly its results over several runs.

Parameters:seed - Seed of the pseudo-random number generator.

int getSeed() const

Gets the seed of the pseudo-random number generator used by the solver.

Only allowed in states S_Paused or S_Stopped.

Return:Seed of the pseudo-random number generator.
See:setSeed(int)

void setNbThreads(int nbThreads)

Sets the number of threads used to parallelize the search.

The number of threads must be a strictly positive integer. The default number of threads is set to 2. Only allowed in state S_Stopped.

By increasing the number of threads, you increase the robustness of the solver (that is, the chance to find better solutions). However, we recommend you to avoid running a number of threads which exceeds the number of cores available on your machine. Since the performance of the solver is sensible to the number of cache misses, the recommended ratio for maximizing its efficiency is to launch at most k/2 searches with k the number of cores of your hardware.

Parameters:nbThreads - Number of threads.

int getNbThreads() const

Gets the number of threads.

Only allowed in states S_Paused or S_Stopped.

Return:Number of threads.
See:setNbThreads(int)

void setAnnealingLevel(int annealingLevel)

Sets the simulated annealing level.

The level must be an integer between 0 and 9. The default simulated annealing level is set to 1. Only allowed in state S_Stopped.

If set to 0, the search heuristic is equivalent to a standard descent: moves deteriorating the current solution are rejected. By increasing this parameter, you increase the number of uphill moves (that is, moves deteriorating the objective value of the current solution): this increases chances to reach better solutions (diversification), but slows the convergence of the search.

Parameters:annealingLevel - Simulated annealing level.

int getAnnealingLevel() const

Gets the simulated annealing level.

Only allowed in states S_Paused or S_Stopped.

Return:Simulated annealing level.
See:setAnnealingLevel(int)

void setVerbosity(int verbosity)

Sets the verbosity level of the solver.

The default verbosity is set to 1. There are 3 defined verbosity levels :

  • 0 : All the traces are disabled.
  • 1 : Normal verbosity. This is the default level.
  • 2 : Detailed verbosity. Displays statistics during the search.

Parameters:verbosity - Verbosity level: 0, 1, 2.

int getVerbosity() const

Gets the verbosity level of the solver.

Return:verbosity Verbosity level: 0, 1 or 2.
See:setVerbosity(int)

void setObjectiveBound(int objectiveIndex, lsint bound)

Sets the bound of the objective with the given index.

If the objective is minimized (resp. maximized), then the optimization of this objective is stopped as soon as this lower (resp. upper) bound is reached. It can be useful for goal programming. Only allowed in states S_Stopped. This method has the same behavior as setIntObjectiveBound.

See:

LSExpression::isObjective()

LSExpression::isInt()

Parameters:
  • objectiveIndex - Index of the objective.
  • bound - Objective bound.

void setObjectiveBound(int objectiveIndex, lsdouble bound)

Sets the bound of the objective with the given index.

If the objective is minimized (resp. maximized), then the optimization of this objective is stopped as soon as this lower (resp. upper) bound is reached. It can be useful for goal programming. Only allowed in states S_Stopped. This method has the same behavior as setDoubleObjectiveBound.

See:

LSExpression::isObjective()

LSExpression::isDouble()

Since:

3.1

Parameters:
  • objectiveIndex - Index of the objective.
  • bound - Objective bound.

void setIntObjectiveBound(int objectiveIndex, lsint bound)

Sets the bound of the objective with the given index.

If the objective is minimized (resp. maximized), then the optimization of this objective is stopped as soon as this lower (resp. upper) bound is reached. It can be useful for goal programming. Only allowed in states S_Stopped.

See:

LSExpression::isObjective()

LSExpression::isInt()

Since:

3.0

Parameters:
  • objectiveIndex - Index of the objective.
  • bound - Objective bound.

void setDoubleObjectiveBound(int objectiveIndex, lsdouble bound)

Sets the bound of the objective with the given index.

If the objective is minimized (resp. maximized), then the optimization of this objective is stopped as soon as this lower (resp. upper) bound is reached. It can be useful for goal programming. Only allowed in states S_Stopped.

See:

LSExpression::isObjective()

LSExpression::isDouble()

Since:

3.0

Parameters:
  • objectiveIndex - Index of the objective.
  • bound - Objective bound.

lsint getObjectiveBound(int objectiveIndex) const

Gets the bound of the objective with the given index.

Only allowed in states S_Paused or S_Stopped.

Return:Objective bound.
See:setObjectiveBound(int, lsint)
Parameters:objectiveIndex - Index of the objective.

lsint getIntObjectiveBound(int objectiveIndex) const

Gets the bound of the objective with the given index.

Only allowed in states S_Paused or S_Stopped.

Return:Objective bound.
See:setObjectiveBound(int, lsint)
Since:3.O
Parameters:objectiveIndex - Index of the objective.

lsdouble getDoubleObjectiveBound(int objectiveIndex) const

Gets the bound of the objective with the given index.

Only allowed in states S_Paused or S_Stopped.

Return:Objective bound.
See:setObjectiveBound(int, lsint)
Since:3.0
Parameters:objectiveIndex - Index of the objective.

void setTimeBetweenDisplays(int timeBetweenDisplays)

Sets the time in seconds between two consecutive displays in console while the solver is running.

The default time between displays is set to 1 second. Only allowed in state S_Stopped.

Parameters:timeBetweenDisplays - Time in seconds between displays.

int getTimeBetweenDisplays() const

Gets the time in seconds between two consecutive displays in console while the solver is running.

Only allowed in states S_Paused or S_Stopped.

Return:Time in seconds between displays.
See:setTimeBetweenDisplays(int)

void setTimeBetweenTicks(int timeBetweenTicks)

Sets the time in seconds between two events of type CT_TimeTicked.

The default time between ticks is set to 1 second. Only allowed in state S_Stopped.

Since:6.0
Parameters:timeBetweenTicks - Time in seconds between ticks.

int getTimeBetweenTicks() const

Gets the time in seconds between two events of type CT_TimeTicked.

Only allowed in states S_Paused or S_Stopped.

Return:Time in seconds between ticks.
See:setTimeBetweenTicks(int)
Since:6.0

void setIterationBetweenTicks(long long iterationBetweenTicks)

Sets the number of iterations between two events of type CT_IterationTicked.

The default number of iterations between ticks is set to 10,000. Only allowed in state S_Stopped.

Since:6.0
Parameters:iterationBetweenTicks - Number of iterations between ticks.

long long getIterationBetweenTicks() const

Gets the number of iterations between two events of type CT_IterationTicked.

Only allowed in states S_Paused or S_Stopped.

Return:Number of iterations between ticks.
See:setIterationBetweenTicks(long long)
Since:6.0

void setLogFile(const std::string &path)

Sets the path of the LocalSolver log file.

If the path is empty, no log will be saved. To tune the logging verbosity, see setVerbosity. Only allowed in states S_Stopped or S_Modeling.

See:

setVerbosity(int)

getLogFile()

Parameters:

path - Path of the log file. Leave empty to disable the logging mechanism.

std::string getLogFile() const

Returns the path of the LocalSolver log file.

If no log file was specified, an empty string is returned.

Return:The path of the log file or an empty string.
See:setLogFile

void setAdvancedParam(const std::string &key, int value)

Sets the value of an advanced parameter.

Advanced parameters are reserved for fine tuning or debugging and should not be used by end-users. Only allowed in states S_Stopped.

Parameters:
  • key - Name of the parameter.
  • value - Value of the parameter.

void setAdvancedParam(const std::string &key, const std::string &value)

Sets the value of an advanced parameter.

Advanced parameters are reserved for fine tuning or debugging and should not be used by end-users. Only allowed in states S_Stopped.

Parameters:
  • key - Name of the parameter.
  • value - Value of the parameter.

int getAdvancedParam(const std::string &key) const

Returns the value of an advanced parameter.

Advanced parameters are reserved for fine tuning or debugging and should not be used by end-users. Throws an exception if the parameter does not exist. Only allowed in states S_Paused or S_Stopped.

Return:Value of the parameter.
See:setAdvancedParam(const std::string&, int)
Parameters:key - Name of the parameter.

int getAdvancedParam(const std::string &key, int defaultValue) const

Returns the value of an advanced parameter.

Advanced parameters are reserved for fine tuning or debugging and should not be used by end-users. A default value is returned if the parameter does not exist or if no value was set for this one.

See:

setAdvancedParam(const std::string&, int)

Parameters:
  • key - Name of the parameter.
  • defaultValue - Default value of the parameter.

std::string getAdvancedParam(const std::string &key, const std::string &defaultValue) const

Returns the value of an advanced parameter.

Advanced parameters are reserved for fine tuning or debugging and should not be used by end-users. A default value is returned if the parameter does not exist or if no value was set for this one.

See:

setAdvancedParam(const std::string&, const std::string&)

Parameters:
  • key - Name of the parameter.
  • defaultValue - Default value of the parameter.

std::string toString() const

Returns a string representation of these parameters.

Useful for debugging or logging purposes.

Return:String representation.