Localsolver
6.0
|
LocalSolver environment.
Main class of LocalSolver library. Here are described the basic steps for using LocalSolver:
Note that this API is not thread safe. If multiple threads access and modify a same LocalSolver environment, it must be synchronized. The only methods that can be used without synchronization are GetState() and Stop(). Please consult LSVersion for copyright and version info.
Public Member Functions | |
LocalSolver () | |
Constructs a complete LocalSolver environment and take a token license. | |
void | Dispose () |
Delete the LocalSolver objects and release the licence token. | |
LSState | GetState () |
Gets the state of this LocalSolver environment. | |
LSModel | GetModel () |
Gets the model associated to this LocalSolver environment. | |
LSParam | GetParam () |
Gets the parameters of this LocalSolver environment. | |
void | Solve () |
Solves the model. | |
LSInconsistency | ComputeInconsistency () |
Compute an inconsistency core for this model. | |
void | Stop () |
Aborts the resolution previously launched using Solve(). | |
LSPhase | CreatePhase () |
Adds a new phase to this LocalSolver environment. | |
LSPhase | GetPhase (int phaseIndex) |
Gets the phase with the given index. | |
int | GetNbPhases () |
Gets the number of phases. | |
LSSolution | GetSolution () |
Gets the best solution found by the solver. | |
LSStatistics | GetStatistics () |
Gets the statistics of this LocalSolver environment. | |
string | GetInfo () |
Returns useful info about the search while running. | |
override string | ToString () |
Returns a string representation of this LocalSolver environment. | |
void | SaveEnvironment (string filename) |
Exports the complete environment (model, parameters, solution, ..) in a file. | |
void | LoadEnvironment (string filename) |
Import a complete environment or a model from a file. | |
void | AddCallback (LSCallbackType type, LSCallback callback) |
Add a new callback for a specific event type. | |
bool | RemoveCallback (LSCallbackType type, LSCallback callback) |
Remove the callback for the given event type. |
localsolver.LocalSolver.LocalSolver | ( | ) |
Constructs a complete LocalSolver environment and take a token license.
If no token is available or if the token server is not accessible, an exception is thrown. The token license is released when the destructor of this LocalSolver environment is called.
void localsolver.LocalSolver.Dispose | ( | ) |
Delete the LocalSolver objects and release the licence token.
This method is automatically called when the LocalSolver object was created in a using statement (see IDisposable interface). Otherwise it must be called explicitly. It deletes the native memory used by LocalSolver and makes the LocalSolver licence available for another LocalSolver model.
LSState localsolver.LocalSolver.GetState | ( | ) |
Gets the state of this LocalSolver environment.
This method can be called in any state. In particular, this method can be called in state LSState::Running.
LSModel localsolver.LocalSolver.GetModel | ( | ) |
Gets the model associated to this LocalSolver environment.
Once the model is created and closed, the solver can be launched with LocalSolver::Solve().
LSParam localsolver.LocalSolver.GetParam | ( | ) |
Gets the parameters of this LocalSolver environment.
void localsolver.LocalSolver.Solve | ( | ) |
Solves the model.
This method returns only when the time limit, the iteration limit or the objective bounds are reached. The model must be closed to launch the resolution.
LSInconsistency localsolver.LocalSolver.ComputeInconsistency | ( | ) |
Compute an inconsistency core for this model.
Only allowed in state LSState::Stopped.
void localsolver.LocalSolver.Stop | ( | ) |
Aborts the resolution previously launched using Solve().
If no resolution was launched, this method does nothing. Called from another thread, this method enables users to stop the resolution properly. Solution and statistics remain valid. This method can be called in any state, notably in state LSState::Running.
LSPhase localsolver.LocalSolver.CreatePhase | ( | ) |
Adds a new phase to this LocalSolver environment.
Only allowed in state LSState::Stopped.
LSPhase localsolver.LocalSolver.GetPhase | ( | int | phaseIndex | ) |
Gets the phase with the given index.
Only allowed in states LSState::Paused or LSState::Stopped.
phaseIndex | Index of the phase. |
int localsolver.LocalSolver.GetNbPhases | ( | ) |
Gets the number of phases.
Only allowed in states LSState::Paused or LSState::Stopped.
LSSolution localsolver.LocalSolver.GetSolution | ( | ) |
Gets the best solution found by the solver.
If the solver has not been started at least once, all the decision variables of the solution are set to 0 (such a solution may be infeasible). Only allowed in states LSState::Paused or LSState::Stopped.
LSStatistics localsolver.LocalSolver.GetStatistics | ( | ) |
Gets the statistics of this LocalSolver environment.
Statistics are reset to zero before each resolution. Only allowed in states LSState::Paused or LSState::Stopped. Note that for performance reasons, this function always returns the same object.
string localsolver.LocalSolver.GetInfo | ( | ) |
Returns useful info about the search while running.
Only allowed if the solver has been started at least once. Only allowed in states LSState::Paused or LSState::Stopped. Useful for debugging or logging purposes. Here are some explanations about the output string:
override string localsolver.LocalSolver.ToString | ( | ) |
Returns a string representation of this LocalSolver environment.
This representation provides useful info related to the model, the parameters, and the phases (if any). Useful for debugging or logging purposes.
void localsolver.LocalSolver.SaveEnvironment | ( | string | filename | ) |
Exports the complete environment (model, parameters, solution, ..) in a file.
This method is useful to debug or replay a model in the same conditions. Currently, this function supports 2 file formats : LSM and LSB. These two formats reproduce all the parameters and the features of this API. The main difference between LSM and LSB files is the way the fields are organized : LSB files are binary files. They are less readable but offer better performance and are more space-efficient than LSM files. The chosen file format is determined by the file suffix. An exception is thrown if the provided file suffix is not supported. The suffix may optionally be followed by .gz. In that case, this function produces a compressed result (using deflate algorithm).
filename | Name of the file. |
Since version 3.0
void localsolver.LocalSolver.LoadEnvironment | ( | string | filename | ) |
Import a complete environment or a model from a file.
Only allowed in state LSState::Modeling. The current model must be empty. Currently, this function supports 4 main file formats : LSM, LSB, LP and MPS. The first two are preferable since they are the native format of LocalSolver. The other ones are classically used by linear programming solvers. LocalSolver supports only a subset of features exposed by these last formats. Please refer to the documentation for more details on this subject. The chosen file format is determined by the file suffix. An exception is thrown if the provided file suffix is not supported. The suffix may optionally be followed by .gz. In that case, this function uncompress the stream before reading.
filename | Name of the file. |
Since version 3.0
void localsolver.LocalSolver.AddCallback | ( | LSCallbackType | type, |
LSCallback | callback | ||
) |
Add a new callback for a specific event type.
The callback will be called each time the given event occurs.
The same callback can be used for different events. Only allowed in states LSState::Stopped or LSState::Modeling.
Note: When a callback is called, the solver is paused. In that state, you can call all the methods marked as "allowed in state <see cref="LSState::Paused" />". Calling any other method will throw an error. For example, you can stop the resolution from a callback, retrieve the current solution or retrieve the statistics of the solver but you can't remove a constraint.
type | Event to watch. |
callback | Callback. Cannot be null. |
Since version 4.0
bool localsolver.LocalSolver.RemoveCallback | ( | LSCallbackType | type, |
LSCallback | callback | ||
) |
Remove the callback for the given event type.
type | Event. |
callback | User callback to delete. |
Since version 4.0