public class KOpt
extends java.lang.Object
implements java.io.Closeable
Implements the 2-Opt and 3-Opt algorithms
| Constructor and Description |
|---|
KOpt(Session session)
Creates a new instance.
|
KOpt(Session session,
OIDList tour)
Creates a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addAllEdgeTypes(EdgesDirection dir)
Allows for traversing all edge types of the graph.
|
void |
addAllNodeTypes()
Allows for traversing all node types of the graph.
|
void |
addEdgeType(int type,
EdgesDirection dir)
Allows for traversing edges of the given type.
|
void |
addNodeType(int type)
Allows for traversing nodes of the given type.
|
void |
close()
Closes the KOpt instance.
|
double |
getCurrentCost()
Returns tour cost.
|
OIDList |
getCurrentTour()
Returns tour as a list of nodes.
|
boolean |
isClosed()
Gets if KOpt instance has been closed or not.
|
void |
runThreeOpt()
Runs 3-Opt local search.
|
void |
runTwoOpt()
Runs 2-Opt local search.
|
void |
setCurrentTour(OIDList tour)
Sets current tour as a list of nodes.
|
void |
setEdgeWeightAttributeType(int attr)
Sets the attribute to use as edge weight.
|
void |
setMaxIterations(long maxIterations)
Sets maximum number of iterations.
|
void |
setTimeLimit(long maxTime)
Limits execution time.
|
public KOpt(Session session, OIDList tour)
session - [in] Session to get the graph from and perform algorithm.tour - [in] Initial tour that needs to be improved.public KOpt(Session session)
session - [in] Session to get the graph from and perform algorithm.public void setCurrentTour(OIDList tour)
tour - [in] Initial tour that needs to be improved.public double getCurrentCost()
public void addAllEdgeTypes(EdgesDirection dir)
dir - [in] Edge direction.public OIDList getCurrentTour()
public void setEdgeWeightAttributeType(int attr)
throws java.lang.RuntimeException
If the multiple edge are set for traversal, this attribute must be of type GLOBAL_TYPE or EDGES_TYPE. Additionally, the attribute must be of type Double.
sparksee::gdb::Error
attr - [in] The attribute type to use as a weight. Default: InvalidAttributejava.lang.RuntimeException - nullpublic void runTwoOpt()
public void addEdgeType(int type,
EdgesDirection dir)
throws java.lang.RuntimeException
If the edge type was already added, the existing direction is overwritten
type - [in] Edge type.dir - [in] Edge direction.java.lang.RuntimeException - nullpublic void runThreeOpt()
public boolean isClosed()
close()public void setMaxIterations(long maxIterations)
By default the algorithm will run until no improvement can be made in the current tour.
maxIterations - [in] Maximum number of iterationspublic void setTimeLimit(long maxTime)
maxTime - [in] Time limit in milisecondspublic void addNodeType(int type)
throws java.lang.RuntimeException
sparksee::gdb::Error
type - [in] Node type.java.lang.RuntimeException - nullpublic void close()
It must be called to ensure the integrity of all data.
close in interface java.io.Closeableclose in interface java.lang.AutoCloseablepublic void addAllNodeTypes()