Menu

Home

pdrozdowski

Project Members:

This page was made to answer most common questions about using the Library and to cover basic how to use it.

How to use the Library?

You need to add reference in you .Net project to TspLibNet.dll
Also you'll need to extract TSPLIB95.zip file, which contains TSP problems and optimal tours.
After referencing TspLibNet.dll you can use class TspLib95 to load chosen or all TSP LIB problem instances.

How to load all instance of TSPLIB?

// set this to point to place where you unzipped TSPLIB95.zip
string dirPath = @"C:\MY_PATH_TO_PROJECTS\TSPLIB95";
TspLib95 library = new TspLib95(dirPath);
int counter = library.LoadAll();
Console.WriteLine("Loaded problems: " + counter);

Now library.Items has all loaded problem instances + their optimal tours if were available.

How to load specific instance of TSPLIB?

// set this to point to place where you unzipped TSPLIB95.zip
string dirPath = @"C:\MY_PATH_TO_PROJECTS\TSPLIB95";
TspLib95 library = new TspLib95(dirPath);
int counter = library.LoadTSP("a280");
Console.WriteLine("Loaded problems: " + counter);

Now library.Items has 1 loaded problem instance + its optimal tour if were available.

How to make custom instance of TSP problem, for example for 6 node problem?

IProblem problem = TravelingSalesmanProblem.FromNodes(NodesFactory.MakeNodes(6));

Note that NodeFactory creates the random node in amount you specified, also you can control the area on which the points will be made. FromNodes TSP method allows to simply create problem having just a list of nodes.

How to make super customized instance of TSP problem?

If you will look into details how graphs are represented for different problems you will note that you can mix multiple different implementations of graph parts providers to create one. So for example when you want to make graph based just on a list of nodes you will use following provider combination:

var nodeProvider = new NodeListBasedNodeProvider(nodes);
var edgeProvider = new NodeBasedEdgeProvider(nodes);
var edgeWeightsProvider = new FunctionBasedWeightProviderWithCaching(new DistanceFunctions.Euclidean());
var fixedEdgesProvider = new EdgeListBasedFixedEdgesProvider(new EdgesCollection());
return new TravelingSalesmanProblem("TSP problem", "Generated", nodeProvider, edgeProvider, edgeWeightsProvider, fixedEdgesProvider);

As you see you can control every aspect of making it, just to briefly list graph can be made as a node list, edges list, weighted edges list... also can be complete or incomplete, you can specify list of edges that must be part of solution, what's more you can control how weights are calculated for providing weights matrices up to choosing different distance functions.


Discussion

  • pdrozdowski

    pdrozdowski - 2014-01-24

    Uploaded 1.0.5137
    - HCP implemented
    - added faster way to load problems directly from files
    - extra comments put to code

     
  • pdrozdowski

    pdrozdowski - 2014-03-11

    Uploaded 1.0.5183
    - Added factoring methods
    - Library usage simplified

     

Log in to post a comment.