public class LocalSolver
extends java.lang.Object
implements java.lang.AutoCloseable
LSModel
) by creating some expressions (LSExpression
).LSParam
, LSPhase
).LocalSolver
).LSSolution
).LSStatistics
).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.
Constructor and Description |
---|
LocalSolver()
Constructs a complete LocalSolver environment and take a token license.
|
Modifier and Type | Method and Description |
---|---|
void |
addCallback(LSCallbackType type,
LSCallback callback)
Adds a new callback for a specific event type.
|
void |
close()
Deletes the LocalSolver objects and release the license token.
|
LSInconsistency |
computeInconsistency()
Computes an inconsistency core for this model.
|
LSPhase |
createPhase()
Adds a new phase to this LocalSolver environment.
|
void |
delete()
Deletes the LocalSolver objects and release the license token.
|
boolean |
equals(java.lang.Object obj) |
LSModel |
getModel()
Gets the model associated to this LocalSolver environment.
|
int |
getNbPhases()
Gets the number of phases.
|
LSParam |
getParam()
Gets the parameters of this LocalSolver environment.
|
LSPhase |
getPhase(int phaseIndex)
Gets the phase with the given index.
|
LSSolution |
getSolution()
Gets the best solution found by the solver.
|
LSState |
getState()
Gets the state of this LocalSolver environment.
|
LSStatistics |
getStatistics()
Gets the statistics of this LocalSolver environment.
|
int |
hashCode() |
void |
loadEnvironment(java.lang.String filename)
Import a complete environment or a model from a file.
|
boolean |
removeCallback(LSCallbackType type,
LSCallback callback)
Removes the callback for the given event type.
|
void |
saveEnvironment(java.lang.String filename)
Export a complete environment or a model to a file.
|
void |
solve()
Solves the model.
|
void |
stop()
Aborts the resolution previously launched using
solve() . |
java.lang.String |
toString()
Returns a String representation of this LocalSolver environment.
|
public LocalSolver()
public void delete()
public void close()
close
in interface java.lang.AutoCloseable
public LSState getState()
LSState.Running
.public LSModel getModel()
solve()
.public LSParam getParam()
public void solve()
public LSInconsistency computeInconsistency()
LSState.Stopped
.public void stop()
solve()
. If no
resolution was launched, this method does nothing. Called from another
thread or callback, 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
.
Note that the effect of this method is not immediate. In particular when
called within a callback, the resolution will not be stopped before the
end of the callback.public LSPhase createPhase()
LSState.Modeling
or LSState.Stopped
.public LSPhase getPhase(int phaseIndex)
phaseIndex
- Index of the phase.public int getNbPhases()
public LSSolution getSolution()
LSState.Paused
or LSState.Stopped
.public LSStatistics getStatistics()
LSState.Paused
or LSState.Stopped
. Note that for
performance reasons, this function always returns the same object.LSStatistics
public java.lang.String toString()
toString
in class java.lang.Object
public void saveEnvironment(java.lang.String filename)
filename
- Name of the file.loadEnvironment(java.lang.String)
public void loadEnvironment(java.lang.String filename)
LSState.Modeling
. The current model must be empty.
The only format supported is LSB.
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.saveEnvironment(java.lang.String)
public void addCallback(LSCallbackType type, LSCallback callback)
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
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.LSCallback
public boolean removeCallback(LSCallbackType type, LSCallback callback)
type
- Event.callback
- User callback to delete.addCallback(localsolver.LSCallbackType, localsolver.LSCallback)
,
LSCallback
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object