Overview | Group | Tree | Graph | Index | Concepts |
Solver lets you define the transit function in a path constraint (the cost for linking two nodes together).
This class is the handle class of the object that defines this transit function.
An object of this handle class uses the virtual member function
IlcPathTransitI::transit
from its
implementation class to define the transit function to apply in the path
constraint in which it is used.
See Also:
IlcPathLength, IlcPathTransitEvalI, IlcPathTransitFunction, IlcPathTransitI
Constructor Summary | |
---|---|
public | IlcPathTransit(const IlcPathTransit & trans) |
public | IlcPathTransit(IlcPathTransitI * trans) |
public | IlcPathTransit(IloSolver s, IlcPathTransitFunction func) |
Method Summary | |
---|---|
public IlcPathTransitI * | getImpl() const |
Constructor Detail |
---|
This copy constructor accepts a reference to an implementation object and creates the corresponding handle object.
This constructor creates a handle that corresponds to the same implementation object that trans
indicates.
This constructor creates a new transit function from an evaluation function. The implementation object of the newly created handle is an instance of the class IlcPathTransitEvalI
constructed with the evaluation function indicated by the argument func
.
Method Detail |
---|
This member function returns a pointer to the implementation object corresponding to the invoking handle.
Example
The simplest way to define a new transit function is to define an evaluation function. For example, the following code defines a transit function that returns the distance from node i
to node j
.
IlcFloat** Distance; IlcFloat GetDistance(IlcInt i, IlcInt j){ return Distance[i][j]; }
Then you create a transition object like this:
IlcPathTransit transition(GetDistance);
However, this approach is not very efficient if the transit function depends on more than the indexes of two nodes. In that example, you saw that we needed to have a global distance array, a situation that we generally want to avoid. Another approach is to define a new transit function like this: define the virtual function transit
for this subclass, as well as a function that returns a handle.
#include <ilsolver/ilcpath.h> class IlcGetDistanceI: public IlcPathTransitI { IlcFloat** distance; public: IlcGetDistanceI(); //Allocates and fills distance virtual IlcFloat transit(IlcInt i, IlcInt j); }; IlcFloat transit(IlcInt i, IlcInt j) { return distance[i][j]; } IlcPathTransit GetDistance(IloSolver s) { return new (s.getHeap()) IlcGetDistanceI(); }
Then with the newly defined class, you create a transition object like this:
IlcPathTransit distance = GetDistance(s);