diff --git a/+Test/test_tsphopfieldnet.m b/+Test/test_tsphopfieldnet.m index b09ea24..cbd9435 100644 --- a/+Test/test_tsphopfieldnet.m +++ b/+Test/test_tsphopfieldnet.m @@ -125,6 +125,16 @@ function createOptions_simFcnNotChar_Errors(testCase) function createOptions_simFcnNotValid_Errors(testCase) verifyError(testCase, @()tsphopfieldnet.createOptions('simFcn','yanez-talavan'),'tsphopfieldnet:invalid_value'); end + function createOptions_simFcnTalavanYanez(testCase) + options = tsphopfieldnet.createOptions('simFcn','talavan-yanez'); + net = tsphopfieldnet(4, 1e-5, options); + verifyTrue(testCase, strcmp(getSimFcn(net),options.simFcn)); + end + function createOptions_simFcnDivideConquer(testCase) + options = tsphopfieldnet.createOptions('simFcn','divide-conquer'); + net = tsphopfieldnet(4, 1e-5, options); + verifyTrue(testCase, strcmp(getSimFcn(net),options.simFcn)); + end function train_trainFcnIsTrainty_WorksFine(testCase) import matlab.unittest.constraints.IsEqualTo; @@ -189,6 +199,37 @@ function sim_simTalavanYanezOutputWithPolygon_sumsN(testCase) verifyEqual(testCase, sum(sum(V)), networkSize); end + function sim_simDivideConquerOutputWithPolygon_hasOne1perRow(testCase) + rng(2); + options = tsphopfieldnet.createOptions('simFcn','divide-conquer'); + networkSize = 6; + C = 0.1; + net = tsphopfieldnet(networkSize, C, options); + train(net); + V = sim(net); + verifyTrue(testCase, all(sum(V,2) == 1)); + end + function sim_simDivideConquerOutputWithPolygon_hasOne1perCol(testCase) + rng(2); + options = tsphopfieldnet.createOptions('simFcn','divide-conquer'); + networkSize = 6; + C = 0.1; + net = tsphopfieldnet(networkSize, C, options); + train(net); + V = sim(net); + verifyTrue(testCase, all(sum(V,1) == 1)); + end + function sim_simDivideConquerOutputWithPolygon_sumsN(testCase) + rng(2); + options = tsphopfieldnet.createOptions('simFcn','divide-conquer'); + networkSize = 6; + C = 0.1; + net = tsphopfieldnet(networkSize, C, options); + train(net); + V = sim(net); + verifyEqual(testCase, sum(sum(V)), networkSize); + end + function sim_simTalavanYanezOutputWithBerlin52_hasOne1perRow(testCase) rng(2); problem = tsplib({'berlin52'}); @@ -221,7 +262,41 @@ function sim_simTalavanYanezOutputWithBerlin52_sumsN(testCase) train(net); V = sim(net); verifyEqual(testCase, sum(sum(V)), networkSize); - end + end + + function sim_simDivideConquerOutputWithBerlin52_hasOne1perRow(testCase) + rng(2); + problem = tsplib({'berlin52'}); + options = tsphopfieldnet.createOptions('coords',problem.coords,'type',problem.type,'simFcn','divide-conquer'); + networkSize = problem.nCities; + C = 0.1; + net = tsphopfieldnet(networkSize, C, options); + train(net); + V = sim(net); + verifyTrue(testCase, all(sum(V,2) == 1)); + end + function sim_simDivideConquerOutputWithBerlin52_hasOne1perCol(testCase) + rng(2); + problem = tsplib({'berlin52'}); + options = tsphopfieldnet.createOptions('coords',problem.coords,'type',problem.type,'simFcn','divide-conquer'); + networkSize = problem.nCities; + C = 0.1; + net = tsphopfieldnet(networkSize, C, options); + train(net); + V = sim(net); + verifyTrue(testCase, all(sum(V,1) == 1)); + end + function sim_simDivideConquerOutputWithBerlin52_sumsN(testCase) + rng(2); + problem = tsplib({'berlin52'}); + options = tsphopfieldnet.createOptions('coords',problem.coords,'type',problem.type,'simFcn','divide-conquer'); + networkSize = problem.nCities; + C = 0.1; + net = tsphopfieldnet(networkSize, C, options); + train(net); + V = sim(net); + verifyEqual(testCase, sum(sum(V)), networkSize); + end function reinit_netObjectAlreadySimulated_WorksFine(testCase) import matlab.unittest.constraints.IsEqualTo; diff --git a/@tsphopfieldnet/sim.m b/@tsphopfieldnet/sim.m index 16cf34e..930f43f 100644 --- a/@tsphopfieldnet/sim.m +++ b/@tsphopfieldnet/sim.m @@ -480,7 +480,7 @@ % Backing up distances aux_d = net.cities.d; - [net.cities.d, neighbours] = tsphopfieldnet.neighbourDistance(net, p_or_tau); + [net.cities.d, neighbours] = neighbourDistance(net, p_or_tau); % Starting point close to saddle point if nargin < 2 diff --git a/@tsphopfieldnet/tsphopfieldnet.m b/@tsphopfieldnet/tsphopfieldnet.m index f4cba52..d7b2921 100644 --- a/@tsphopfieldnet/tsphopfieldnet.m +++ b/@tsphopfieldnet/tsphopfieldnet.m @@ -48,7 +48,8 @@ net.trainParam.C = C; - if size(net.cities.coords,1) ~= net.trainParam.N + if (~isempty(net.cities.coords) && size(net.cities.coords,1) ~= net.trainParam.N) || ... + (isempty(net.cities.coords) && size(net.cities.d,1) ~= net.trainParam.N) error('Mismatch between number of coordinates, distance matrix and neurons'); end diff --git a/Hopfield Net TSP solver.prj b/Hopfield Net TSP solver.prj index c02650d..b30b19e 100644 --- a/Hopfield Net TSP solver.prj +++ b/Hopfield Net TSP solver.prj @@ -1,5 +1,5 @@ - + Hopfield Net TSP solver Lucas García Rodríguez lucasgarciarodriguez@ucm.es @@ -26,11 +26,11 @@ Find more information in the documentation of the toolbox or in the <a href=" 19 - 9.0 - 10.2 + 9.2 + 11.1 - E:\Users\Lucas\Documents\Math\PhD\sandbox\hopfield_network\trunk\code + E:\Users\Lucas\Documents\GitHub\HopfieldNetworkToolbox d605def3-3010-4890-ac40-cf704be9aed1 @@ -338,16 +338,17 @@ Find more information in the documentation of the toolbox or in the <a href=" - E:\Users\Lucas\Documents\Math\PhD\sandbox\hopfield_network\trunk\code + E:\Users\Lucas\Documents\GitHub\HopfieldNetworkToolbox - C:\Program Files\MATLAB\R2016a + C:\Program Files\MATLAB\R2017a + @@ -369,6 +370,11 @@ Find more information in the documentation of the toolbox or in the <a href=" true + + + true + + false diff --git a/Hopfield Network Toolbox.prj b/Hopfield Network Toolbox.prj index e89c5cb..6582833 100644 --- a/Hopfield Network Toolbox.prj +++ b/Hopfield Network Toolbox.prj @@ -1,5 +1,5 @@ - + Hopfield Network Toolbox Lucas García Rodríguez lucasgarciarodriguez@ucm.es @@ -9,9 +9,18 @@ ${PROJECT_ROOT}\help\html\hopfieldnet.png 1.1.2 ${PROJECT_ROOT}\Hopfield Network Toolbox.mltbx - - - + + MATLAB + Statistics and Machine Learning Toolbox + + + 1 + 19 + + + 9.2 + 11.1 + 9468a56e-2dfa-48c1-b681-f168f0815c88 % List files contained in your toolbox folder that you would like to exclude @@ -45,35 +54,35 @@ BuildInstructions.m <exampleCategory name="Solving the Traveling Salesman Problem using Hopfield Networks"> <example name="Solving the TSP with cities in Polygon Vertices" type="html"> <file type="source">/help/html/Example_tspUsingRegularPolygons.html</file> - <file type="main">E:/Users/Lucas/Documents/MATLAB/Add-Ons/Toolboxes/Hopfield Network Toolbox/code/help/Example_tspUsingRegularPolygons.m</file> + <file type="main">/help/Example_tspUsingRegularPolygons.m</file> <file type="thumbnail">/help/html/Example_tspUsingRegularPolygons.png</file> <file type="image">/help/html/Example_tspUsingRegularPolygons_01.png</file> <file type="image">/help/html/Example_tspUsingRegularPolygons_02.png</file> </example> <example name="Solving the TSP with TSPLIB cities" type="html"> <file type="source">/help/html/Example_tspUsingTSPLIB.html</file> - <file type="main">E:/Users/Lucas/Documents/MATLAB/Add-Ons/Toolboxes/Hopfield Network Toolbox/code/help/Example_tspUsingTSPLIB.m</file> + <file type="main">/help/Example_tspUsingTSPLIB.m</file> <file type="thumbnail">/help/html/Example_tspUsingTSPLIB.png</file> <file type="image">/help/html/Example_tspUsingTSPLIB_01.png</file> <file type="image">/help/html/Example_tspUsingTSPLIB_02.png</file> </example> <example name="Solving the TSP provided the problem's coordinates" type="html"> <file type="source">/help/html/Example_tspUsingCoords.html</file> - <file type="main">E:/Users/Lucas/Documents/MATLAB/Add-Ons/Toolboxes/Hopfield Network Toolbox/code/help/Example_tspUsingCoords.m</file> + <file type="main">/help/Example_tspUsingCoords.m</file> <file type="thumbnail">/help/html/Example_tspUsingCoords.png</file> <file type="image">/help/html/Example_tspUsingCoords_01.png</file> <file type="image">/help/html/Example_tspUsingCoords_02.png</file> </example> <example name="Solving the TSP provided the distance matrix" type="html"> <file type="source">/help/html/Example_tspUsingDistance.html</file> - <file type="main">E:/Users/Lucas/Documents/MATLAB/Add-Ons/Toolboxes/Hopfield Network Toolbox/code/help/Example_tspUsingDistance.m</file> + <file type="main">/help/Example_tspUsingDistance.m</file> <file type="thumbnail"/> </example> </exampleCategory> <exampleCategory name="Improving Hopfield Network performance when applied to the TSP"> <example name="Reduce the free parameter C" type="html"> <file type="source">/help/html/Example_tspReducingC.html</file> - <file type="main">E:/Users/Lucas/Documents/MATLAB/Add-Ons/Toolboxes/Hopfield Network Toolbox/code/help/Example_tspReducingC.m</file> + <file type="main">/help/Example_tspReducingC.m</file> <file type="thumbnail">/help/html/Example_tspReducingC.png</file> <file type="image">/help/html/Example_tspReducingC_01.png</file> <file type="image">/help/html/Example_tspReducingC_02.png</file> @@ -81,12 +90,12 @@ BuildInstructions.m </example> <example name="Appropriate starting point" type="html"> <file type="source">/help/html/Example_tspSaddlePoint.html</file> - <file type="main">E:/Users/Lucas/Documents/MATLAB/Add-Ons/Toolboxes/Hopfield Network Toolbox/code/help/Example_tspSaddlePoint.m</file> + <file type="main">/help/Example_tspSaddlePoint.m</file> <file type="thumbnail"/> </example> <example name="A Divide-and-Conquer Scheme" type="html"> <file type="source">/help/html/Example_tspDivideConquer.html</file> - <file type="main">E:/Users/Lucas/Documents/MATLAB/Add-Ons/Toolboxes/Hopfield Network Toolbox/code/help/Example_tspDivideConquer.m</file> + <file type="main">/help/Example_tspDivideConquer.m</file> <file type="thumbnail">/help/html/Example_tspDivideConquer.png</file> <file type="image">/help/html/Example_tspDivideConquer_01.png</file> </example> @@ -98,17 +107,16 @@ BuildInstructions.m ${PROJECT_ROOT}\help\info.xml + - - - + - E:\Users\Lucas\Documents\Math\PhD\sandbox\hopfield_network\trunk\code + E:\Users\Lucas\Documents\GitHub\HopfieldNetworkToolbox ${PROJECT_ROOT}\@hopfieldnet @@ -118,8 +126,7 @@ BuildInstructions.m ${PROJECT_ROOT}\@tsplib ${PROJECT_ROOT}\help ${PROJECT_ROOT}\Hopfield Net TSP solver.mlappinstall - ${PROJECT_ROOT}\Phase1_PossibleSaddlePoint - ${PROJECT_ROOT}\ReleaseNotes.txt + ${PROJECT_ROOT}\LICENSE ${PROJECT_ROOT}\setup_TSPLIB.m ${PROJECT_ROOT}\TSPFiles @@ -127,16 +134,17 @@ BuildInstructions.m - E:\Users\Lucas\Documents\Math\PhD\sandbox\hopfield_network\trunk\code\Hopfield Network Toolbox.mltbx + E:\Users\Lucas\Documents\GitHub\HopfieldNetworkToolbox\Hopfield Network Toolbox.mltbx - C:\Program Files\MATLAB\R2016a + C:\Program Files\MATLAB\R2017a + @@ -158,6 +166,11 @@ BuildInstructions.m true + + + true + + false diff --git a/help/html/Example_tspDivideConquer.html b/help/html/Example_tspDivideConquer.html index 5919b8c..972d3ba 100644 --- a/help/html/Example_tspDivideConquer.html +++ b/help/html/Example_tspDivideConquer.html @@ -6,7 +6,7 @@ Improving Hopfield Network performance using a Divide-and-Conquer scheme

Improving Hopfield Network performance using a Divide-and-Conquer scheme

In order to improve the performance of this heuristic technique, a Divide-and-Conquer strategy based on two phases is proposed. The first phase involves linking cities with the most neighbors to define a set of chains of cities and, secondly, to join these with isolated cities to define the final tour. Both problems are solved by mapping the two TSPs onto their respective CHNs.

Contents

TSPLIB problem and network parameters

rng(6); % For reproducibility
+  

Improving Hopfield Network performance using a Divide-and-Conquer scheme

In order to improve the performance of this heuristic technique, a Divide-and-Conquer strategy based on two phases is proposed. The first phase involves linking cities with the most neighbors to define a set of chains of cities and, secondly, to join these with isolated cities to define the final tour. Both problems are solved by mapping the two TSPs onto their respective CHNs.

Contents

TSPLIB problem and network parameters

rng(6); % For reproducibility
 

TSPLIB Problem:

problem = tsplib({'berlin52'});
 

Number of cities:

N = problem.nCities;
 

Free parameter C:

C = 0.00001;
-

Creating the tsphopfieldnetwork object using the Divide-and-Conquer simulation method

Providing problem coordinates cities and distance matrix to the tsphopfieldnet network by creating a structure of options

options = tsphopfieldnet.createOptions('coords',problem.coords,'d',problem.d,'type',...
+

Creating the tsphopfieldnetwork object using the Divide-and-Conquer simulation method

Providing problem coordinates cities and distance matrix to the tsphopfieldnet network by creating a structure of options

options = tsphopfieldnet.createOptions('coords',problem.coords,'d',problem.d,'type',...
     problem.type,'simFcn','divide-conquer','tau',2);
 net = tsphopfieldnet(N,C,options);
-

Training the network

The default training algorithm is trainty

train(net);
-

Simulating the network

The simulation is using the algorithm is divide-conquer

sim(net);
-

Visualizing results

getResults(net)
+

Training the network

The default training algorithm is trainty

train(net);
+

Simulating the network

The simulation is using the algorithm is divide-conquer

sim(net);
+

Visualizing results

getResults(net)
 plot(net);
 
 ans = 
 
-        compTime: 0.4148
-          energy: [1x466 double]
+  struct with fields:
+
+        compTime: 0.4183
+          energy: [1×466 double]
         exitFlag: 1
     itersReached: 466
-            time: [1x466 double]
+            time: [1×466 double]
       tourLength: 9201
        validPath: 1
-      visitOrder: [1x52 double]
+      visitOrder: [1×52 double]
 
-
Improving the convergence of the Hopfield Network applied to the TSP by reducing the parameter C

Improving the convergence of the Hopfield Network applied to the TSP by reducing the parameter C

In this section, you will be able to see how the convergence of the Hopfield Network is improved when reducing the free parameter C. Note that this had been proved experimentaly but there was no analytical proof until [ref].

Contents

TSPLIB problem and network parameters

seed = 10;
+  

Improving the convergence of the Hopfield Network applied to the TSP by reducing the parameter C

In this section, you will be able to see how the convergence of the Hopfield Network is improved when reducing the free parameter C. Note that this had been proved experimentaly but there was no analytical proof until [ref].

Contents

TSPLIB problem and network parameters

seed = 10;
 rng(seed); % For reproducibility
 

TSPLIB Problem:

problem = tsplib({'berlin52'});
 

Number of cities:

N = problem.nCities;
 

Free parameter C:

C = 1e5;
-

Creating the tsphopfieldnetwork object with value of C 'big'

Providing problem coordinates cities and distance matrix to the tsphopfieldnet network by creating a structure of options

options = tsphopfieldnet.createOptions('coords',problem.coords,'d',problem.d,'type',problem.type);
+

Creating the tsphopfieldnetwork object with value of C 'big'

Providing problem coordinates cities and distance matrix to the tsphopfieldnet network by creating a structure of options

options = tsphopfieldnet.createOptions('coords',problem.coords,'d',problem.d,'type',problem.type);
 net1 = tsphopfieldnet(N,C,options);
 

Data coordinates (cities) can be visualized before training takes place:

plot(net1);
 
Warning: Simulation has not taken place yet. Use 'sim(net)' to simulate your
 network. 
-

Training the network

The default training algorithm is trainty

train(net1);
+

Training the network

The default training algorithm is trainty

train(net1);
 

Results of the training phase. Network parameters

getTrainParam(net1)
 
 ans = 
 
+  struct with fields:
+
         A: 1.0000e+05
         B: 100003
         C: 100000
@@ -93,22 +95,24 @@
     dUaux: 1716
       rho: 0.0087
 
-

Simulating the network

The default simulation algorithm is talavan-yanez

sim(net1);
-

Visualizing results

getResults(net1)
+

Simulating the network

The default simulation algorithm is talavan-yanez

sim(net1);
+

Visualizing results

getResults(net1)
 plot(net1);
 
 ans = 
 
-        compTime: 0.8826
-          energy: [1x836 double]
+  struct with fields:
+
+        compTime: 0.5900
+          energy: [1×836 double]
         exitFlag: 1
     itersReached: 836
-            time: [1x836 double]
+            time: [1×836 double]
       tourLength: 29725
        validPath: 1
-      visitOrder: [1x52 double]
+      visitOrder: [1×52 double]
 
-

Repeating the tsphopfieldnet network simulation with a smaller value of C

rng(seed); % For reproducibility
+

Repeating the tsphopfieldnet network simulation with a smaller value of C

rng(seed); % For reproducibility
 C = 1e-5;
 
 net2 = tsphopfieldnet(N,C,options);
@@ -121,16 +125,18 @@
 
 ans = 
 
-        compTime: 0.2266
-          energy: [1x220 double]
+  struct with fields:
+
+        compTime: 0.1724
+          energy: [1×220 double]
         exitFlag: 1
     itersReached: 220
-            time: [1x220 double]
+            time: [1×220 double]
       tourLength: 12889
        validPath: 1
-      visitOrder: [1x52 double]
+      visitOrder: [1×52 double]
 
-

Note that not only the solution was improved, but the number of iterations and time to convergence was considerably improved.

Improving the convergence of the Hopfield Network applied to the TSP by choosing a starting point close to the Saddle point

Improving the convergence of the Hopfield Network applied to the TSP by choosing a starting point close to the Saddle point

In this section, you will be able to see how the convergence of the Hopfield Network is improved by choosing a starting point close to the Saddle point of the Energy Function of the associated problem.

Contents

Simulating the network with default starting point

seed = 5;
+  

Improving the convergence of the Hopfield Network applied to the TSP by choosing a starting point close to the Saddle point

In this section, you will be able to see how the convergence of the Hopfield Network is improved by choosing a starting point close to the Saddle point of the Energy Function of the associated problem.

Contents

Simulating the network with default starting point

seed = 5;
 rng(seed); % For reproducibility
 

TSPLIB Problem:

problem = tsplib({'tsp225'});
 

Number of cities:

N = problem.nCities;
@@ -75,12 +75,12 @@
 net1 = tsphopfieldnet(N,C,options);
 

Training the network

train(net1);
 

Simulating the network

sim(net1);
-

Simulating the network with starting point close to Saddle point

net2 = tsphopfieldnet(N,C,options);
+

Simulating the network with starting point close to Saddle point

net2 = tsphopfieldnet(N,C,options);
 V = saddle(net2) + (rand(N) - 0.5)*1e-10;
 invTransferFcn = getSetting(net2,'invTransferFcn');
 U = invTransferFcn(V);
 sim(net2,V,U);
-

Comparing results

getResults(net1,'tourLength')
+

Comparing results

getResults(net1,'tourLength')
 
 getResults(net2,'tourLength')
 
@@ -93,7 +93,7 @@
 
        10930
 
-
Solving the TSP provided the problem's coordinates using Hopfield Network

Solving the TSP provided the problem's coordinates using Hopfield Network

The following example shows how to solve any TSP problem, provided the problem coordinates

Contents

Network parameters

rng(22); % For reproducibility
+  

Solving the TSP provided the problem's coordinates using Hopfield Network

The following example shows how to solve any TSP problem, provided the problem coordinates

Contents

Network parameters

rng(22); % For reproducibility
 

Free parameter C:

C = 0.00001;
-

Creating the tsphopfieldnetwork object

Providing problem coordinates

coords = [0.4000 0.4439;...
+

Creating the tsphopfieldnetwork object

Providing problem coordinates

coords = [0.4000 0.4439;...
           0.2439 0.1463;...
           0.1707 0.2293;...
           0.2293 0.7610;...
@@ -85,11 +85,13 @@
 

Data coordinates (cities) can be visualized before training takes place:

plot(net);
 
Warning: Simulation has not taken place yet. Use 'sim(net)' to simulate your
 network. 
-

Training the network

The default training algorithm is trainty

train(net);
+

Training the network

The default training algorithm is trainty

train(net);
 

Results of the training phase. Network parameters

getTrainParam(net)
 
 ans = 
 
+  struct with fields:
+
         A: 2.9408
         B: 3.0000
         C: 1.0000e-05
@@ -102,22 +104,24 @@
     dUaux: 0.8407
       rho: 0.0592
 
-

Simulating the network

The default simulation algorithm is talavan-yanez

sim(net);
-

Visualizing results

getResults(net)
+

Simulating the network

The default simulation algorithm is talavan-yanez

sim(net);
+

Visualizing results

getResults(net)
 plot(net);
 
 ans = 
 
-        compTime: 0.0347
-          energy: [1x93 double]
+  struct with fields:
+
+        compTime: 0.0307
+          energy: [1×93 double]
         exitFlag: 1
     itersReached: 93
-            time: [1x93 double]
+            time: [1×93 double]
       tourLength: 2.6907
        validPath: 1
       visitOrder: [2 10 9 8 7 6 5 4 1 3]
 
-
Solving the TSP provided the distance matrix using Hopfield Network

Solving the TSP provided the distance matrix using Hopfield Network

The following example shows how to solve any TSP problem, provided the distance matrix between cities.

Contents

Network parameters

rng(22); % For reproducibility
+  

Solving the TSP provided the distance matrix using Hopfield Network

The following example shows how to solve any TSP problem, provided the distance matrix between cities.

Contents

Network parameters

rng(22); % For reproducibility
 

Free parameter C:

C = 0.00001;
-

Creating the tsphopfieldnetwork object

Providing the distance matrix

d = [.0000 .3361 .3141 .3601 .5111 .5176 .2982 .4564 .3289 .2842;...
+

Creating the tsphopfieldnetwork object

Providing the distance matrix

d = [.0000 .3361 .3141 .3601 .5111 .5176 .2982 .4564 .3289 .2842;...
      .3361 .0000 .1107 .6149 .8407 .8083 .5815 .6418 .4378 .3934;...
      .3141 .1107 .0000 .5349 .7919 .8207 .5941 .6908 .4982 .4501;...
      .3601 .6149 .5349 .0000 .3397 .6528 .5171 .7375 .6710 .6323;...
@@ -82,11 +82,13 @@
 

Number of cities:

N = size(d,1);
 
 net = tsphopfieldnet(N,C,options);
-

Training the network

The default training algorithm is trainty

train(net);
+

Training the network

The default training algorithm is trainty

train(net);
 

Results of the training phase. Network parameters

getTrainParam(net)
 
 ans = 
 
+  struct with fields:
+
         A: 2.9408
         B: 3.0000
         C: 1.0000e-05
@@ -99,14 +101,14 @@
     dUaux: 0.8407
       rho: 0.0592
 
-

Simulating the network

The default simulation algorithm is talavan-yanez

sim(net);
-

Tour Length

getResults(net,'tourLength')
+

Simulating the network

The default simulation algorithm is talavan-yanez

sim(net);
+

Tour Length

getResults(net,'tourLength')
 
 ans =
 
     2.6908
 
-
Solving the TSP with cities in Polygon Vertices using a Hopfield Network

Solving the TSP with cities in Polygon Vertices using a Hopfield Network

There are numerous TSP problems that have been used in the literature. In this section, an additional set of problem examples is proposed, by placing TSP cities in the vertices of regular polygons. This provides a whole new set of TSP problems that can be used to test different method approaches.

As a matter of fact, the coordinates of a regular polygon of size N is used as the default behaviour of tsphopfieldnet if no set of coordinates is provided to the network.

Contents

Network parameters

rng(2); % For reproducibility
+  

Solving the TSP with cities in Polygon Vertices using a Hopfield Network

There are numerous TSP problems that have been used in the literature. In this section, an additional set of problem examples is proposed, by placing TSP cities in the vertices of regular polygons. This provides a whole new set of TSP problems that can be used to test different method approaches.

As a matter of fact, the coordinates of a regular polygon of size N is used as the default behaviour of tsphopfieldnet if no set of coordinates is provided to the network.

Contents

Network parameters

rng(2); % For reproducibility
 

Number of cities:

N = 10;
 

Free parameter C:

C = 0.00001;
-

Creating the tsphopfieldnetwork object

net = tsphopfieldnet(N,C);
+

Creating the tsphopfieldnetwork object

net = tsphopfieldnet(N,C);
 

Data coordinates (cities) can be visualized before training takes place:

plot(net);
 
Warning: Simulation has not taken place yet. Use 'sim(net)' to simulate your
 network. 
-

Training the network

The default training algorithm is trainty

train(net);
+

Training the network

The default training algorithm is trainty

train(net);
 

Results of the training phase. Network parameters

getTrainParam(net)
 
 ans = 
 
+  struct with fields:
+
         A: 2.6910
         B: 3.0000
         C: 1.0000e-05
@@ -90,22 +92,24 @@
     dUaux: 2
       rho: 0.3090
 
-

Simulating the network

The default simulation algorithm is talavan-yanez

sim(net);
-

Visualizing results

getResults(net)
+

Simulating the network

The default simulation algorithm is talavan-yanez

sim(net);
+

Visualizing results

getResults(net)
 plot(net);
 
 ans = 
 
-        compTime: 0.0254
-          energy: [1x64 double]
+  struct with fields:
+
+        compTime: 0.0587
+          energy: [1×64 double]
         exitFlag: 1
     itersReached: 64
-            time: [1x64 double]
+            time: [1×64 double]
       tourLength: 6.1803
        validPath: 1
       visitOrder: [6 7 8 9 10 1 2 3 4 5]
 
-
Solving the TSP with TSPLIB cities using a Hopfield Network

Solving the TSP with TSPLIB cities using a Hopfield Network

TSPLIB is an extensive set of problems frequently used for solving the TSP (and related problems) and used as a powerful reference for benchmarking different algorithms. In this section, tsphopfieldnet is used for solving the TSP when the problem coordinates are given by one of the library problems from TSPLIB.

Contents

TSPLIB problem and network parameters

rng(6); % For reproducibility
+  

Solving the TSP with TSPLIB cities using a Hopfield Network

TSPLIB is an extensive set of problems frequently used for solving the TSP (and related problems) and used as a powerful reference for benchmarking different algorithms. In this section, tsphopfieldnet is used for solving the TSP when the problem coordinates are given by one of the library problems from TSPLIB.

Contents

TSPLIB problem and network parameters

rng(6); % For reproducibility
 

TSPLIB Problem:

problem = tsplib({'berlin52'});
 

Number of cities:

N = problem.nCities;
 

Free parameter C:

C = 0.00001;
-

Creating the tsphopfieldnetwork object

Providing problem coordinates cities and distance matrix to the tsphopfieldnet network by creating a structure of options

options = tsphopfieldnet.createOptions('coords',problem.coords,'d',problem.d,'type',problem.type);
+

Creating the tsphopfieldnetwork object

Providing problem coordinates cities and distance matrix to the tsphopfieldnet network by creating a structure of options

options = tsphopfieldnet.createOptions('coords',problem.coords,'d',problem.d,'type',problem.type);
 net = tsphopfieldnet(N,C,options);
 

Data coordinates (cities) can be visualized before training takes place:

plot(net);
 
Warning: Simulation has not taken place yet. Use 'sim(net)' to simulate your
 network. 
-

Training the network

The default training algorithm is trainty

train(net);
+

Training the network

The default training algorithm is trainty

train(net);
 

Results of the training phase. Network parameters

getTrainParam(net)
 
 ans = 
 
+  struct with fields:
+
         A: 2.9913
         B: 3.0000
         C: 1.0000e-05
@@ -92,22 +94,24 @@
     dUaux: 1716
       rho: 0.0087
 
-

Simulating the network

The default simulation algorithm is talavan-yanez

sim(net);
-

Visualizing results

getResults(net)
+

Simulating the network

The default simulation algorithm is talavan-yanez

sim(net);
+

Visualizing results

getResults(net)
 plot(net);
 
 ans = 
 
-        compTime: 0.3416
-          energy: [1x216 double]
+  struct with fields:
+
+        compTime: 0.1708
+          energy: [1×216 double]
         exitFlag: 1
     itersReached: 216
-            time: [1x216 double]
+            time: [1×216 double]
       tourLength: 12583
        validPath: 1
-      visitOrder: [1x52 double]
+      visitOrder: [1×52 double]
 
-
Hopfield Network TSP Solver App

Hopfield Network TSP Solver App

The Hopfield Network TSP Solver App allows to solve the Traveling Salesman Problem using Continuous Hopfield Networks by using several of the solver algorithms available in Hopfield Network Toolbox (euler, talavan-yanez and divide-conquer.

You will find the Hopfield Network TSP Solver App from the APPS section in your MATLAB Desktop.

The Hopfield Network TSP Solver App can solve TSPLIB problems, TSPs where its cities are located at the vertices of regular polygons, and any TSP problem defined by its coordinates or distance matrix.

About Hopfield Network Toolbox

About Hopfield Network Toolbox

Contents

Acknowledgements

The authors would like to thank:

  • Javier Yáñez of Universidad Complutense de Madrid (Spain)
  • Pedro M. Talaván of Instituto Nacional de Estadística (Spain)

for their sound contributions and recommendations.

What problems can Hopfield Network Toolbox solve?

Hopfield Networks may solve any combinatorial optimization problem, given it is properly mapped to the network. However, at this point, Hopfield Network Toolbox is mainly designed to solve The Traveling Salesman Problem.

The Toolbox has been designed though to be easily expanded to solve any combinatorial optimization problem.

Contents

Acknowledgements

The authors would like to thank:

  • Javier Yáñez of Universidad Complutense de Madrid (Spain)
  • Pedro M. Talaván of Instituto Nacional de Estadística (Spain)

for their sound contributions and recommendations.

What problems can Hopfield Network Toolbox solve?

Hopfield Networks may solve any combinatorial optimization problem, given it is properly mapped to the network. However, at this point, Hopfield Network Toolbox is mainly designed to solve The Traveling Salesman Problem.

The Toolbox has been designed though to be easily expanded to solve any combinatorial optimization problem.

Concepts

Hopfield Network Toolbox

The Hopfield Network Toolbox can solve combinatorial optimization problems by using Hopfield Neural Networks. The Hopfield Network Toolbox is focused in Continuous Hopfield Networks.

If you are interested in using Discrete Hopfield Networks, see the documentation for newhop in Neural Network Toolbox™.

The Continuous Hopfield Network (CHN) is a recurrent neural network with an associated differential equation, whose state evolves from an initial condition to an equilibrium point by minimizing a Lyapunov function. As the Lyapunov function is associated with an objective function of the optimization problem (i.e. the mapping process), the equilibrium, or stable point, helps identify a local optimum for the optimization problem.

You can find more information about Continuous Hopfield Networks in the Concepts Section of the documentation.

Available Documentation

See also the GitHub repository Hopfield Network Toolbox for the latest release of the software.

Hopfield Network Toolbox Release Notes

Hopfield Network Toolbox Release Notes

This toolbox is solves combinatorial optimization problems by using Continuous Hopfield Networks (CHN).

The Hopfield Network Toolbox requires the following products: MATLAB® and Statistics and Machine Learning Toolbox™

Contents

Version 1.1.1, 21-Feb-2015

Bug fixing for Unix platforms

List of Bugs fixed in this release.

Version 1.1.1 on GitHub

Version 1.1, 21-Feb-2015

New App, Toolbox Documentation and Examples.

New Features:

  • Hopfield Net TSP solver App
  • Toolbox documentation
  • Step-by-step examples
  • TSPLIB automatic download

List of Bugs fixed in this release.

Version 1.1 on GitHub

Version 1.0, 02-Nov-2015

Initial release of Hopfield Network Toolbox.

This release is mainly focused in solving the Traveling Salesman Problem using the Continuous Hopfield Network (CHN). However, the release also provides a class structure to solve generic combinatorial optimization problems. Development in this area is undergoing.

The class to solve the TSP problems using CHNs is tsphopfieldnet. This network can solve any TSP problem, provided its coordinates or distance matrix. The Toolbox also includes the library TSPLIB, a de facto library for TSP benchmarks. Instances with up to 13509 cities have been tested using the tsphopfieldnet network. Note that solving such instances might require a large amount of memory.

Two main algorithms can be tested in this release:

  • talavan-yanez: based on the paper Parameter setting of the Hopfield network applied to TSP by Pedro M. Talaván and Javier Yáñez.
  • divide-conquer: based on the paper (pending publishing at the time of this release) Improving the Hopfield model performance when applied to the traveling salesman problem: A divide-and-conquer scheme by Lucas García, Pedro M. Talaván and Javier Yáñez.

Version 1.0 on GitHub

References

The latest version of this toolbox is available on GitHub.

This toolbox is solves combinatorial optimization problems by using Continuous Hopfield Networks (CHN).

The Hopfield Network Toolbox requires the following products: MATLAB® and Statistics and Machine Learning Toolbox™

Contents

Version 1.1.2, 09-Apr-2017

Bug fixing for Unix platforms

List of Bugs fixed and Enhancements in this release.

Version 1.1.2 on GitHub

Version 1.1.1, 21-Feb-2016

Bug fixing for Unix platforms

List of Bugs fixed in this release.

Version 1.1.1 on GitHub

Version 1.1, 21-Feb-2016

New App, Toolbox Documentation and Examples.

New Features:

  • Hopfield Net TSP solver App
  • Toolbox documentation
  • Step-by-step examples
  • TSPLIB automatic download

List of Bugs fixed in this release.

Version 1.1 on GitHub

Version 1.0, 02-Nov-2015

Initial release of Hopfield Network Toolbox.

This release is mainly focused in solving the Traveling Salesman Problem using the Continuous Hopfield Network (CHN). However, the release also provides a class structure to solve generic combinatorial optimization problems. Development in this area is undergoing.

The class to solve the TSP problems using CHNs is tsphopfieldnet. This network can solve any TSP problem, provided its coordinates or distance matrix. The Toolbox also includes the library TSPLIB, a de facto library for TSP benchmarks. Instances with up to 13509 cities have been tested using the tsphopfieldnet network. Note that solving such instances might require a large amount of memory.

Two main algorithms can be tested in this release:

  • talavan-yanez: based on the paper Parameter setting of the Hopfield network applied to TSP by Pedro M. Talaván and Javier Yáñez.
  • divide-conquer: based on the paper (pending publishing at the time of this release) Improving the Hopfield model performance when applied to the traveling salesman problem: A divide-and-conquer scheme by Lucas García, Pedro M. Talaván and Javier Yáñez.

Version 1.0 on GitHub

References

The latest version of this toolbox is available on GitHub.

Hopfield Network Toolbox System Requirements

Hopfield Network Toolbox System Requirements

Hopfield Network Toolbox requires MATLAB® and Statistics and Machine Learning Toolbox™

Hopfield Network Toolbox User's GuideHow to solve the Traveling Salesman Problem using Hopfield Networks

How to solve the Traveling Salesman Problem using Hopfield Networks

The Continuous Hopfield Network has been extensively used to solve the Travelling Salesman Problem. However, only after Talaván and Yáñez's approach with an appropriate problem parametrization, it is reasonable to solve the TSP using a Hopfield Network, as obtaining a feasible solution is guaranteed.

The Hopfield Network tsphopfieldnet can solve the following types of problems:

What is hopfieldnet?

What is hopfieldnet?

hopfieldnet is a MATLAB class that has been developed to solve the Continuous Hopfield Network using MATLAB.

hopfieldnet has been programmed in a similiar way to other Artificial Neural Networks available in Neural Network Toolbox™, using classdef to create and design the class.

hopfielnet is a generic class which can be used to solve any kind of combinatorial optimization problem.

A child class from hopfielnet, tsphopfieldnet, is specially focused in solving the Traveling Salesman Problem using Continuous Hopfield Networks. See the examples using tsphopfieldnet to learn more.

How to use tsphopfieldnet and createOptions

How to solve improve the performance of the Hopfield Network for the TSP

As it probably has already been noted in previous sections, the solutions of the Hopfield Network cannot compete against other popular combinatorial optimization methods. However, there are several ways in which we can considerably improve the solution obtain through Hopfield Networks. The following sections highlight 2 crucial aspects worth considering: the parameter C and the initial point for the simulation.

How to solve improve the performance of the Hopfield Network for the TSP using Hybrid methods

How to solve improve the performance of the Hopfield Network for the TSP using Hybrid methods

TSPLIB - A library for Traveling Salesman Problems

TSPLIB - A library for Traveling Salesman Problems

TSPLIB is a collection of Traveling Salesman Problem instances of varying difficulty published by Gerhard Reinelt in 1991, which has been extensively used by many research groups for comparing results.

The library has already been installed with the Hopfield Network Toolbox. If for some reason you need to download the TSPLIB library again, use the following script to do so (since some TSPLIB instances are not correctly formated and required some additional parsing).

>> setup_TSPLIB;
-