public abstract static class IloCplex.Callback
extends java.lang.Object
implements java.lang.Cloneable
This class defines the common interface available to all callback
classes. A callback is an object with a method main
implemented by the user. This method is called by the
IloCplex algorithm at
specific points during the optimization. For each of these points,
CPLEX provides a context or an
extension of IloCplex.Callback. To implement and use
a particular callback, the user must observe the following steps:
main for this extension.
When doing
so, you can use all of the methods defined in the callback class and
its base classes.clone is not
adequate, and if the callback is to be used for
parallel optimization,
this method also needs to be implemented by the user.
Recall that the
default clone method performs a shallow copy, so
typically a user implementation needs to perform a deep copy for
objects that should be local to threads or the user implementation
must use the
synchronize keyword where synchronization is required.
IloCplex with the method IloCplex.use.The next time a solution method is executed
on the IloCplex
object for which the callback has been set, the method
main of the callback will be called each time
the corresponding point in the optimization algorithm is reached,
for example at each iteration.
The methods of this class are protected to make sure they are
used only to derive a user-written callback class or to
implement the main method in it.
This class serves two different purposes:
main method.
IloCplex.Callback.Function interface
(more specifically the IloCplex.Callback.Function.invoke(IloCplex.Callback.Context)
method) and then using the IloCplex.Callback.Context passed into that function
to performs queries and actions.
IloCplex.use(IloCplex.Callback)| Modifier and Type | Class and Description |
|---|---|
static class |
IloCplex.Callback.Context
Context for the CPLEX callback.
|
static interface |
IloCplex.Callback.Function
Interface for CPLEX callbacks.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
abort()
Instructs CPLEX to stop the current optimization after the
user-written callback finishes.
|
double |
getCplexTime()
Returns a time stamp.
|
double |
getDetTime()
This method returns a deterministic time stamp in ticks.
|
protected double |
getEndDetTime()
This method returns a deterministic time stamp specifying
when the solving process terminates.
|
protected double |
getEndTime()
This method returns a time stamp specifying when
solving process terminates.
|
protected double |
getStartDetTime()
This method returns a deterministic time stamp specifying when
the solving process started.
|
protected double |
getStartTime()
This method returns a time stamp specifying when
the solving process started.
|
protected abstract void |
main()
The method to be implemented by user callback classes.
|
protected abstract void main()
throws IloException
IloExceptionprotected void abort()
This method can be called from a user-written implementation of a
main method to instruct the invoking CPLEX
optimizer to stop the current optimization.
After an invocation of this method, it is possible to resume
optimization by another invocation of the method solve.
In such a case, optimization continues at the node of the search tree
where the abort method was called. In fact, any time
that solve stops for a reason other than an error, you
can resume optimization by re-invoking solve.
In contrast, executing additional callback methods in the callback can
lead to unpredictable behavior. For example, callback methods such
as IloCplex.SolveCallback.solve or
IloCplex.BranchCallback.makeBranch
can overwrite the callback status and thus enable the optimization
to continue. Therefore, to abort an optimization effectively,
a user should exit the callback by one of
the following ways:
return immediately after the call
of abort. IloCplex.Callback and its subclasses after
abort.public double getCplexTime()
throws IloException
To measure time spent between a starting point and ending point of an operation, take the time stamp at the starting point; take the time stamp at the ending point; subtract the starting time stamp from the ending time stamp to get elapsed time in seconds.
This computation measures either wall clock time (also
known as real time) or CPU time, depending on the setting
of the clock type parameter ClockType.
The absolute value of the time stamp is not meaningful.
IloExceptionpublic double getDetTime()
throws IloException
To measure deterministic time spent between a starting point and ending point of an operation, take the time stamp at the starting point; take the time stamp at the ending point; subtract the starting time stamp from the ending time stamp to get elapsed time in deterministic ticks.
The absolute value of a deterministic time stamp is not meaningful.
IloExceptionprotected double getStartTime()
throws IloException
To compute elapsed time in seconds,
subtract the result of
getCplexTime
from the result of this method.
The absolute value of the time stamp is not meaningful.
IloExceptionprotected double getStartDetTime()
throws IloException
To compute elapsed time in deterministic ticks,
subtract the result of
getDetTime from the result of this method.
The absolute value of a deterministic time stamp is not meaningful.
IloExceptionprotected double getEndTime()
throws IloException
To compute remaining time in seconds, subtract the result of
IloCplex.getCplexTime
from the result of this method. This computation yields either
wall clock time (also known as real time) or CPU time, depending
on the clock type set by the parameter ClockType.
The absolute value of the time stamp is not meaningful.
IloExceptionprotected double getEndDetTime()
throws IloException
To compute remaining time in deterministic ticks,
subtract the result of
IloCplex.getDetTime
from the result of this method.
The absolute value of the time stamp is not meaningful.
IloException