Skip to content

Commit 1dbabd4

Browse files
committed
New App, Simulink Models, Runge-Kutta simulation method for TSP and GQKP, improved documentation, new examples, minor bugs and enhancements
Bug fixing: #35 Checkpoint fails when using divide-conquer simulation method Enhancements: #10 Enable phase visualization in Divide-and-Conquer #28 Create Hopfield Network for Simulink #50 Update Hopfield Net TSP solver App #51 Runge-Kutta simulation method #52 energyplot function for HopfieldNetworkGQKP #53 Improve documentation #54 New examples for 2-opt, simulink models and GQKP Tasks: #23 TSPLIB help page not linked in User's Guide
1 parent b383641 commit 1dbabd4

File tree

142 files changed

+2745
-1166
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

142 files changed

+2745
-1166
lines changed

Hopfield Net TSP solver.prj

Lines changed: 85 additions & 297 deletions
Large diffs are not rendered by default.

Hopfield Network Toolbox.prj

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,23 @@
55
<param.email>lucasgarciarodriguez@ucm.es</param.email>
66
<param.company>mathinking.github.com</param.company>
77
<param.summary>A Hopfield Network Toolbox for MATLAB</param.summary>
8-
<param.description>The Hopfield Network Toolbox can solve combinatorial optimization problems by using Hopfield Neural Networks. The Hopfield Network Toolbox is focused in Continuous Hopfield Networks.</param.description>
8+
<param.description>The Hopfield Network Toolbox can solve combinatorial optimization problems by using Hopfield Neural Networks. The Hopfield Network Toolbox is mainly focused in Continuous Hopfield Networks.</param.description>
99
<param.screenshot>${PROJECT_ROOT}\help\html\hopfieldnet.png</param.screenshot>
10-
<param.version>1.1.2</param.version>
10+
<param.version>2.0</param.version>
1111
<param.output>${PROJECT_ROOT}\Hopfield Network Toolbox.mltbx</param.output>
1212
<param.products.name>
1313
<item>MATLAB</item>
14+
<item>Simulink</item>
1415
<item>Statistics and Machine Learning Toolbox</item>
1516
</param.products.name>
1617
<param.products.id>
1718
<item>1</item>
19+
<item>2</item>
1820
<item>19</item>
1921
</param.products.id>
2022
<param.products.version>
2123
<item>9.2</item>
24+
<item>8.9</item>
2225
<item>11.1</item>
2326
</param.products.version>
2427
<param.platforms />
@@ -48,10 +51,16 @@ help_source/
4851
Hopfield Net TSP solver_resources/
4952
README.md
5053
setup_hopfieldNetwork.m
51-
BuildInstructions.m</param.exclude.filters>
54+
BuildInstructions.m
55+
automateTests.m
56+
slprj
57+
tau
58+
Simulations
59+
runMultipleTSPLIBproblems.m
60+
script_runMultipleTSPLIBproblems.m</param.exclude.filters>
5261
<param.examples>&lt;?xml version="1.0" encoding="utf-8"?&gt;
5362
&lt;examples&gt;
54-
&lt;exampleCategory name="Solving the Traveling Salesman Problem using Hopfield Networks"&gt;
63+
&lt;exampleCategory name="Solving the Optimization problems using Hopfield Networks"&gt;
5564
&lt;example name="Solving the TSP with cities in Polygon Vertices" type="html"&gt;
5665
&lt;file type="source"&gt;/help/html/Example_tspUsingRegularPolygons.html&lt;/file&gt;
5766
&lt;file type="main"&gt;/help/Example_tspUsingRegularPolygons.m&lt;/file&gt;
@@ -78,6 +87,27 @@ BuildInstructions.m</param.exclude.filters>
7887
&lt;file type="main"&gt;/help/Example_tspUsingDistance.m&lt;/file&gt;
7988
&lt;file type="thumbnail"/&gt;
8089
&lt;/example&gt;
90+
&lt;example name="Solving a GQKP problem using a Hopfield Network" type="html"&gt;
91+
&lt;file type="source"&gt;/help/html/Example_GQKPusingCHN.html&lt;/file&gt;
92+
&lt;file type="main"&gt;/help/Example_GQKPusingCHN.m&lt;/file&gt;
93+
&lt;file type="thumbnail"&gt;/help/html/Example_GQKPusingCHN.png&lt;/file&gt;
94+
&lt;file type="image"&gt;/help/html/Example_GQKPusingCHN_01.png&lt;/file&gt;
95+
&lt;/example&gt;
96+
&lt;/exampleCategory&gt;
97+
&lt;exampleCategory name="Solving Hopfield Networks using Simulink"&gt;
98+
&lt;example name="Solving Discrete Hopfield Networks using Simulink" type="html"&gt;
99+
&lt;file type="source"&gt;/help/html/Example_SimulinkDiscrete.html&lt;/file&gt;
100+
&lt;file type="main"&gt;/help/Example_SimulinkDiscrete.m&lt;/file&gt;
101+
&lt;file type="thumbnail"&gt;/help/html/Example_SimulinkDiscrete.png&lt;/file&gt;
102+
&lt;file type="image"&gt;/help/html/Example_SimulinkDiscrete_01.png&lt;/file&gt;
103+
&lt;file type="image"&gt;/help/html/Example_SimulinkDiscrete_02.png&lt;/file&gt;
104+
&lt;/example&gt;
105+
&lt;example name="Solving Continuous Hopfield Networks using Simulink" type="html"&gt;
106+
&lt;file type="source"&gt;/help/html/Example_SimulinkContinuous.html&lt;/file&gt;
107+
&lt;file type="main"&gt;/help/Example_SimulinkContinuous.m&lt;/file&gt;
108+
&lt;file type="thumbnail"&gt;/help/html/Example_SimulinkContinuous.png&lt;/file&gt;
109+
&lt;file type="image"&gt;/help/html/Example_SimulinkContinuous_01.png&lt;/file&gt;
110+
&lt;/example&gt;
81111
&lt;/exampleCategory&gt;
82112
&lt;exampleCategory name="Improving Hopfield Network performance when applied to the TSP"&gt;
83113
&lt;example name="Reduce the free parameter C" type="html"&gt;
@@ -99,6 +129,12 @@ BuildInstructions.m</param.exclude.filters>
99129
&lt;file type="thumbnail"&gt;/help/html/Example_tspDivideConquer.png&lt;/file&gt;
100130
&lt;file type="image"&gt;/help/html/Example_tspDivideConquer_01.png&lt;/file&gt;
101131
&lt;/example&gt;
132+
&lt;example name="CHN as a 2-opt Algorithm" type="html"&gt;
133+
&lt;file type="source"&gt;/help/html/Example_tsp2opt.html&lt;/file&gt;
134+
&lt;file type="main"&gt;/help/Example_tsp2opt.m&lt;/file&gt;
135+
&lt;file type="thumbnail"&gt;/help/html/Example_tsp2opt.png&lt;/file&gt;
136+
&lt;file type="image"&gt;/help/html/Example_tsp2opt_01.png&lt;/file&gt;
137+
&lt;/example&gt;
102138
&lt;/exampleCategory&gt;
103139
&lt;/examples&gt;</param.examples>
104140
<param.demosxml />
@@ -119,16 +155,12 @@ BuildInstructions.m</param.exclude.filters>
119155
<file>E:\Users\Lucas\Documents\GitHub\HopfieldNetworkToolbox</file>
120156
</fileset.rootdir>
121157
<fileset.rootfiles>
122-
<file>${PROJECT_ROOT}\@hopfieldnet</file>
123-
<file>${PROJECT_ROOT}\@hopfieldnetwork</file>
124-
<file>${PROJECT_ROOT}\@tsphopfieldnet</file>
125-
<file>${PROJECT_ROOT}\@tsphopfieldnetApp</file>
126-
<file>${PROJECT_ROOT}\@tsplib</file>
158+
<file>${PROJECT_ROOT}\chn</file>
159+
<file>${PROJECT_ROOT}\data</file>
127160
<file>${PROJECT_ROOT}\help</file>
128161
<file>${PROJECT_ROOT}\Hopfield Net TSP solver.mlappinstall</file>
129162
<file>${PROJECT_ROOT}\LICENSE</file>
130163
<file>${PROJECT_ROOT}\setup_TSPLIB.m</file>
131-
<file>${PROJECT_ROOT}\TSPFiles</file>
132164
</fileset.rootfiles>
133165
<fileset.depfun.included />
134166
<fileset.depfun.excluded />

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ The Continuous Hopfield Network (CHN) is a **recurrent neural network** with an
55
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.
66
The dynamics of the CHN is described by a **differential equation**:
77

8-
![\frac{du}{dt} = - \frac{u}{\Lambda} + T v + i^b](http://mathurl.com/hzhnzj5.png)
8+
![\frac{du}{dt} = - \frac{u}{\lambda} + T v + i^b](http://mathurl.com/ycfv6hhd.png)
99

1010
and the output function is a hyperbolic tangent:
1111

1212
![v_i = g(u_i) = \frac{1}{2} \left( 1 + \tanh \left( \frac{u_i}{u_0} \right) \right), \qquad u_0 > 0](http://mathurl.com/zdeg52h.png)
1313

14-
The existence of an equilibrium point is guaranteed if a Lyapunov or energy function exists. The idea is that the network's Lyapunov function, when ![\Lambda \rightarrow{} \infty](http://mathurl.com/hl2t4by.png), is associated with the cost function to be minimized in the combinatorial problem.
14+
The existence of an equilibrium point is guaranteed if a Lyapunov or energy function exists. The idea is that the network's Lyapunov function, when ![\lambda \rightarrow{} \infty](http://mathurl.com/ydye9fha.png), is associated with the cost function to be minimized in the combinatorial problem.
1515

1616
The CHN will solve those combinatorial problems which can be expressed as the constrained minimization of:
1717

@@ -37,11 +37,12 @@ Want to contribute? Great! Feel free to fork the repository and contact us for i
3737
## Questions?
3838
Open a new Issue and label it as a question. We will get back to you.
3939

40-
## References
40+
## Major References
4141
- [“Neural” computation of decisions in optimization problems](http://www.ams.org/mathscinet-getitem?mr=824597)
4242
- [A continuous Hopfield network equilibrium points algorithm](http://www.sciencedirect.com/science/article/pii/S0305054804000243)
4343
- [Parameter setting of the Hopfield network applied to TSP](http://www.sciencedirect.com/science/article/pii/S0893608002000217)
4444
- [Improving the Hopfield model performance when applied to the traveling salesman problem: A divide-and-conquer scheme](http://link.springer.com/article/10.1007/s00500-016-2039-8)
45+
- [Attractor basin analysis of the Hopfield model: The Generalized Quadratic Knapsack Problem. In International Work-Conference on Artificial Neural Networks (2017)](https://link.springer.com/chapter/10.1007%2F978-3-319-59153-7_37)
4546

4647
## Contact us
4748
Send us an [Email](mailto:lucasgarciarodriguez@ucm.es) with your comments/suggestions.

chn/+apps/@HopfieldNetworkTSPApp/HopfieldNetworkTSPApp.m

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
tabOtherCoordinates;
2727
tabOtherDistance;
2828

29-
simulation;
29+
simulation;
30+
schemeMenu;
3031
simFcnMenu;
3132

3233
ExecutionEnvironment;
@@ -83,7 +84,7 @@
8384
function app = HopfieldNetworkTSPApp()
8485
createFigure(app);
8586
defaultSettings(app);
86-
drawnow nocallbacks;
87+
% drawnow;
8788
app.figure.Visible = 'on';
8889
end
8990
end
@@ -100,9 +101,13 @@
100101
cb_parameterCEdit(app);
101102
cb_findTour(app);
102103
cb_simFcn(app);
104+
cb_scheme(app);
103105
timeElapsed(app,obj,event);
104106
cleanState(app);
105107
createTspHopfieldNet(app,varargin);
106108
updateTspHopfieldNet(app,C);
109+
problemIsSelected = verifyProblemIsSelected(app);
110+
cb_closeApp(app);
107111
end
112+
108113
end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function cb_closeApp(app,~)
2+
3+
selection = questdlg('Close Hopfield Net TSP solver App?',...
4+
'Close App?',...
5+
'Yes','No','Yes');
6+
switch selection
7+
case 'Yes'
8+
warning('on','tsphopfieldnet:NotSimulated');
9+
warning('on','MATLAB:MKDIR:DirectoryExists');
10+
delete(app.figure);
11+
case 'No'
12+
return;
13+
end
14+
end

chn/+apps/@HopfieldNetworkTSPApp/cb_findTour.m

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,9 @@ function cb_findTour(app,~)
1818
end
1919
end
2020

21-
if app.simFcnMenu.Value == 1
22-
msgbox('Please choose an algorithm for the Hopfield Network simulation', 'Error', 'error');
21+
if app.schemeMenu.Value == 1
22+
msgbox('Please choose a scheme for the Hopfield Network simulation', 'Error', 'error');
2323
return;
24-
else
25-
algorithms = app.simFcnMenu.String;
26-
setSimFcn(app.net,algorithms{app.simFcnMenu.Value});
27-
if strcmp(algorithms{app.simFcnMenu.Value},'divide-conquer')
28-
setCities(app.net,'Tau',max(3,round(getTrainParam(app.net,'N')/10))); %#TODO Bring to APP
29-
end
3024
end
3125

3226
u0 = str2double(app.settings_u0Edit.String);
@@ -35,6 +29,7 @@ function cb_findTour(app,~)
3529
dt = str2double(app.settings_dtEdit.String);
3630
e = str2double(app.settings_eEdit.String);
3731
q = str2double(app.settings_qEdit.String);
32+
tau = str2double(app.cities_tauEdit.String);
3833

3934
try
4035
setSetting(app.net,'U0',u0)
@@ -43,6 +38,7 @@ function cb_findTour(app,~)
4338
setSetting(app.net,'Dt',dt)
4439
setSetting(app.net,'E',e)
4540
setSetting(app.net,'Q',q)
41+
setCities(app.net,'Tau',tau)
4642
catch me
4743
msgbox(me.message)
4844
return;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
function cb_scheme(app,~)
2+
3+
problemIsSelected = verifyProblemIsSelected(app);
4+
if ~problemIsSelected
5+
msgbox('Please select first the problem to solve', 'Error', 'error');
6+
app.schemeMenu.Value = 1;
7+
return;
8+
end
9+
schemes = app.schemeMenu.String;
10+
11+
chosenScheme = schemes{app.schemeMenu.Value};
12+
13+
if strncmp(chosenScheme,'divide-conquer',14)
14+
app.cities_tauEdit.Enable = 'on';
15+
tau = max(3,round(getTrainParam(app.net,'N')/10));
16+
setCities(app.net,'Tau',tau);
17+
app.cities_tauEdit.String = num2str(tau);
18+
19+
train(app.net);
20+
trainParams = getTrainParam(app.net);
21+
22+
app.parameterAEdit.String = num2str(trainParams.A);
23+
app.parameterBEdit.String = num2str(trainParams.B);
24+
app.parameterDEdit.String = num2str(1/trainParams.dUaux);
25+
26+
app.parameterNEdit.String = num2str(trainParams.N);
27+
app.parameterNpEdit.String = num2str(trainParams.Np);
28+
app.cities_tauEdit.String = num2str(getCities(app.net,'Tau'));
29+
else
30+
app.cities_tauEdit.Enable = 'off';
31+
end
32+
33+
if ~isempty(app.net) && ~strcmp(chosenScheme,'Scheme')
34+
setScheme(app.net, chosenScheme)
35+
end
36+
37+
end
Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,32 @@
11
function cb_simFcn(app,~)
22

3+
problemIsSelected = verifyProblemIsSelected(app);
4+
if ~problemIsSelected
5+
msgbox('Please select first the problem to solve', 'Error', 'error');
6+
app.simFcnMenu.Value = 1;
7+
return;
8+
end
9+
if app.schemeMenu.Value == 1
10+
msgbox('Please select first the Hopfield Network scheme to solve the problem', 'Error', 'error');
11+
app.simFcnMenu.Value = 1;
12+
return;
13+
end
14+
315
algorithms = app.simFcnMenu.String;
416

5-
chosenAlgorithm = algorithms(app.simFcnMenu.Value);
17+
chosenAlgorithm = algorithms{app.simFcnMenu.Value};
618

719
app.elapsedTime.String = '';
8-
9-
if strcmp(chosenAlgorithm,'euler')
20+
21+
if strcmp(chosenAlgorithm,'euler') || strcmp(chosenAlgorithm,'runge-kutta')
1022
app.settings_u0Edit.Enable = 'on';
1123
app.settings_dtEdit.Enable = 'on';
1224
app.settings_maxIterEdit.Enable = 'on';
1325
app.settings_eEdit.Enable = 'on';
1426
app.settings_R_ITEREdit.Enable = 'on';
1527
app.settings_qEdit.Enable = 'on';
16-
app.cities_tauEdit.Enable = 'off';
1728
if ~isempty(app.net)
18-
setSimFcn(app.net,'euler')
29+
setSimFcn(app.net,chosenAlgorithm)
1930
end
2031

2132
elseif strcmp(chosenAlgorithm,'talavan-yanez')
@@ -25,31 +36,16 @@ function cb_simFcn(app,~)
2536
app.settings_eEdit.Enable = 'on';
2637
app.settings_R_ITEREdit.Enable = 'on';
2738
app.settings_qEdit.Enable = 'on';
28-
app.cities_tauEdit.Enable = 'off';
2939
if ~isempty(app.net)
3040
setSimFcn(app.net,'talavan-yanez')
31-
end
32-
33-
elseif strcmp(chosenAlgorithm,'divide-conquer')
34-
app.settings_u0Edit.Enable = 'on';
35-
app.settings_dtEdit.Enable = 'off';
36-
app.settings_maxIterEdit.Enable = 'on';
37-
app.settings_eEdit.Enable = 'on';
38-
app.settings_R_ITEREdit.Enable = 'on';
39-
app.settings_qEdit.Enable = 'on';
40-
app.cities_tauEdit.Enable = 'on';
41-
if ~isempty(app.net)
42-
setSimFcn(app.net,'divide-conquer')
43-
end
44-
41+
end
4542
else
4643
app.settings_u0Edit.Enable = 'off';
4744
app.settings_dtEdit.Enable = 'off';
4845
app.settings_maxIterEdit.Enable = 'off';
4946
app.settings_eEdit.Enable = 'off';
5047
app.settings_R_ITEREdit.Enable = 'off';
5148
app.settings_qEdit.Enable = 'off';
52-
app.cities_tauEdit.Enable = 'off';
5349
end
54-
50+
5551
end

chn/+apps/@HopfieldNetworkTSPApp/cb_tabPolygonNcities.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function cb_tabPolygonNcities(app)
2-
2+
33
N = str2double(app.tabPolygonnCitiesEdit.String);
44
if isnan(N) || N < 2
55
msgbox('You must provide a value for number of cities greater than 2', 'Error', 'error');

chn/+apps/@HopfieldNetworkTSPApp/cb_tabTSPLIBmenu.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ function cb_tabTSPLIBmenu(app)
33
problems = app.tabTSPLIBmenu.String;
44
problemSelected = app.tabTSPLIBmenu.Value;
55

6+
app.schemeMenu.Value = 1;
7+
app.simFcnMenu.Value = 1;
8+
app.cities_tauEdit.Enable = 'off';
9+
610
% Useful for problems that take longer to compute tsplib
711
% and training
812
app.tabTSPLIBnCitiesEdit.String = '- - - ';

0 commit comments

Comments
 (0)