Satsuma
a delicious .NET graph library
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Pages
Public Member Functions | Properties | List of all members
Satsuma.Opt2Tsp< TNode > Class Template Reference

Improves a solution for the traveling salesman problem by using the 2-OPT method. More...

Inheritance diagram for Satsuma.Opt2Tsp< TNode >:
Satsuma.ITsp< TNode >

Public Member Functions

 Opt2Tsp (Func< TNode, TNode, double > cost, IEnumerable< TNode > tour, double?tourCost)
 Initializes the 2-OPT optimizer with the supplied tour. More...
 
void Run ()
 Performs 2-OPT improvement steps until the tour cannot be improved this way. More...
 
bool Step ()
 Performs an improvement step. More...
 

Properties

Func< TNode, TNode, double > Cost [get, set]
 A finite cost function on the node pairs. More...
 
IEnumerable< TNode > Tour [get]
 
double TourCost [get, set]
 

Detailed Description

Improves a solution for the traveling salesman problem by using the 2-OPT method.

It starts from a precomputed tour (e.g. one returned by InsertionTsp<TNode>) and gradually improves it by repeatedly swapping two edges. It is advised to use this class for symmetric cost functions only.

Template Parameters
TNodeThe node type.

Definition at line 276 of file Tsp.cs.

Constructor & Destructor Documentation

Satsuma.Opt2Tsp< TNode >.Opt2Tsp ( Func< TNode, TNode, double >  cost,
IEnumerable< TNode >  tour,
double?  tourCost 
)

Initializes the 2-OPT optimizer with the supplied tour.

Parameters
costThe cost function (should be symmetrical).
tourThe tour to improve with 2-OPT. The starting node must be repeated at the end.
tourCostThe known cost of tour. Use this parameter to speed up initialization. If null is supplied, then the tour cost is recalculated.

Definition at line 291 of file Tsp.cs.

Member Function Documentation

void Satsuma.Opt2Tsp< TNode >.Run ( )

Performs 2-OPT improvement steps until the tour cannot be improved this way.

Definition at line 321 of file Tsp.cs.

bool Satsuma.Opt2Tsp< TNode >.Step ( )

Performs an improvement step.

Returns
true if the objective could be improved.

Definition at line 300 of file Tsp.cs.

Property Documentation

Func<TNode, TNode, double> Satsuma.Opt2Tsp< TNode >.Cost
getset

A finite cost function on the node pairs.

Definition at line 279 of file Tsp.cs.

IEnumerable<TNode> Satsuma.Opt2Tsp< TNode >.Tour
get

Definition at line 283 of file Tsp.cs.

double Satsuma.Opt2Tsp< TNode >.TourCost
getset

Definition at line 284 of file Tsp.cs.


The documentation for this class was generated from the following file: