Skip to content

Commit

Permalink
New App, Simulink Models, Runge-Kutta simulation method for TSP and G…
Browse files Browse the repository at this point in the history
…QKP, 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
  • Loading branch information
mathinking committed Sep 21, 2017
1 parent b383641 commit 1dbabd4
Show file tree
Hide file tree
Showing 142 changed files with 2,745 additions and 1,166 deletions.
382 changes: 85 additions & 297 deletions Hopfield Net TSP solver.prj

Large diffs are not rendered by default.

52 changes: 42 additions & 10 deletions Hopfield Network Toolbox.prj
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,23 @@
<param.email>[email protected]</param.email>
<param.company>mathinking.github.com</param.company>
<param.summary>A Hopfield Network Toolbox for MATLAB</param.summary>
<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>
<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>
<param.screenshot>${PROJECT_ROOT}\help\html\hopfieldnet.png</param.screenshot>
<param.version>1.1.2</param.version>
<param.version>2.0</param.version>
<param.output>${PROJECT_ROOT}\Hopfield Network Toolbox.mltbx</param.output>
<param.products.name>
<item>MATLAB</item>
<item>Simulink</item>
<item>Statistics and Machine Learning Toolbox</item>
</param.products.name>
<param.products.id>
<item>1</item>
<item>2</item>
<item>19</item>
</param.products.id>
<param.products.version>
<item>9.2</item>
<item>8.9</item>
<item>11.1</item>
</param.products.version>
<param.platforms />
Expand Down Expand Up @@ -48,10 +51,16 @@ help_source/
Hopfield Net TSP solver_resources/
README.md
setup_hopfieldNetwork.m
BuildInstructions.m</param.exclude.filters>
BuildInstructions.m
automateTests.m
slprj
tau
Simulations
runMultipleTSPLIBproblems.m
script_runMultipleTSPLIBproblems.m</param.exclude.filters>
<param.examples>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;examples&gt;
&lt;exampleCategory name="Solving the Traveling Salesman Problem using Hopfield Networks"&gt;
&lt;exampleCategory name="Solving the Optimization problems using Hopfield Networks"&gt;
&lt;example name="Solving the TSP with cities in Polygon Vertices" type="html"&gt;
&lt;file type="source"&gt;/help/html/Example_tspUsingRegularPolygons.html&lt;/file&gt;
&lt;file type="main"&gt;/help/Example_tspUsingRegularPolygons.m&lt;/file&gt;
Expand All @@ -78,6 +87,27 @@ BuildInstructions.m</param.exclude.filters>
&lt;file type="main"&gt;/help/Example_tspUsingDistance.m&lt;/file&gt;
&lt;file type="thumbnail"/&gt;
&lt;/example&gt;
&lt;example name="Solving a GQKP problem using a Hopfield Network" type="html"&gt;
&lt;file type="source"&gt;/help/html/Example_GQKPusingCHN.html&lt;/file&gt;
&lt;file type="main"&gt;/help/Example_GQKPusingCHN.m&lt;/file&gt;
&lt;file type="thumbnail"&gt;/help/html/Example_GQKPusingCHN.png&lt;/file&gt;
&lt;file type="image"&gt;/help/html/Example_GQKPusingCHN_01.png&lt;/file&gt;
&lt;/example&gt;
&lt;/exampleCategory&gt;
&lt;exampleCategory name="Solving Hopfield Networks using Simulink"&gt;
&lt;example name="Solving Discrete Hopfield Networks using Simulink" type="html"&gt;
&lt;file type="source"&gt;/help/html/Example_SimulinkDiscrete.html&lt;/file&gt;
&lt;file type="main"&gt;/help/Example_SimulinkDiscrete.m&lt;/file&gt;
&lt;file type="thumbnail"&gt;/help/html/Example_SimulinkDiscrete.png&lt;/file&gt;
&lt;file type="image"&gt;/help/html/Example_SimulinkDiscrete_01.png&lt;/file&gt;
&lt;file type="image"&gt;/help/html/Example_SimulinkDiscrete_02.png&lt;/file&gt;
&lt;/example&gt;
&lt;example name="Solving Continuous Hopfield Networks using Simulink" type="html"&gt;
&lt;file type="source"&gt;/help/html/Example_SimulinkContinuous.html&lt;/file&gt;
&lt;file type="main"&gt;/help/Example_SimulinkContinuous.m&lt;/file&gt;
&lt;file type="thumbnail"&gt;/help/html/Example_SimulinkContinuous.png&lt;/file&gt;
&lt;file type="image"&gt;/help/html/Example_SimulinkContinuous_01.png&lt;/file&gt;
&lt;/example&gt;
&lt;/exampleCategory&gt;
&lt;exampleCategory name="Improving Hopfield Network performance when applied to the TSP"&gt;
&lt;example name="Reduce the free parameter C" type="html"&gt;
Expand All @@ -99,6 +129,12 @@ BuildInstructions.m</param.exclude.filters>
&lt;file type="thumbnail"&gt;/help/html/Example_tspDivideConquer.png&lt;/file&gt;
&lt;file type="image"&gt;/help/html/Example_tspDivideConquer_01.png&lt;/file&gt;
&lt;/example&gt;
&lt;example name="CHN as a 2-opt Algorithm" type="html"&gt;
&lt;file type="source"&gt;/help/html/Example_tsp2opt.html&lt;/file&gt;
&lt;file type="main"&gt;/help/Example_tsp2opt.m&lt;/file&gt;
&lt;file type="thumbnail"&gt;/help/html/Example_tsp2opt.png&lt;/file&gt;
&lt;file type="image"&gt;/help/html/Example_tsp2opt_01.png&lt;/file&gt;
&lt;/example&gt;
&lt;/exampleCategory&gt;
&lt;/examples&gt;</param.examples>
<param.demosxml />
Expand All @@ -119,16 +155,12 @@ BuildInstructions.m</param.exclude.filters>
<file>E:\Users\Lucas\Documents\GitHub\HopfieldNetworkToolbox</file>
</fileset.rootdir>
<fileset.rootfiles>
<file>${PROJECT_ROOT}\@hopfieldnet</file>
<file>${PROJECT_ROOT}\@hopfieldnetwork</file>
<file>${PROJECT_ROOT}\@tsphopfieldnet</file>
<file>${PROJECT_ROOT}\@tsphopfieldnetApp</file>
<file>${PROJECT_ROOT}\@tsplib</file>
<file>${PROJECT_ROOT}\chn</file>
<file>${PROJECT_ROOT}\data</file>
<file>${PROJECT_ROOT}\help</file>
<file>${PROJECT_ROOT}\Hopfield Net TSP solver.mlappinstall</file>
<file>${PROJECT_ROOT}\LICENSE</file>
<file>${PROJECT_ROOT}\setup_TSPLIB.m</file>
<file>${PROJECT_ROOT}\TSPFiles</file>
</fileset.rootfiles>
<fileset.depfun.included />
<fileset.depfun.excluded />
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ The Continuous Hopfield Network (CHN) is a **recurrent neural network** with an
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.
The dynamics of the CHN is described by a **differential equation**:

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

and the output function is a hyperbolic tangent:

![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)

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.
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.

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

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

## References
## Major References
- [“Neural” computation of decisions in optimization problems](http://www.ams.org/mathscinet-getitem?mr=824597)
- [A continuous Hopfield network equilibrium points algorithm](http://www.sciencedirect.com/science/article/pii/S0305054804000243)
- [Parameter setting of the Hopfield network applied to TSP](http://www.sciencedirect.com/science/article/pii/S0893608002000217)
- [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)
- [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)

## Contact us
Send us an [Email](mailto:[email protected]) with your comments/suggestions.
Expand Down
9 changes: 7 additions & 2 deletions chn/+apps/@HopfieldNetworkTSPApp/HopfieldNetworkTSPApp.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
tabOtherCoordinates;
tabOtherDistance;

simulation;
simulation;
schemeMenu;
simFcnMenu;

ExecutionEnvironment;
Expand Down Expand Up @@ -83,7 +84,7 @@
function app = HopfieldNetworkTSPApp()
createFigure(app);
defaultSettings(app);
drawnow nocallbacks;
% drawnow;
app.figure.Visible = 'on';
end
end
Expand All @@ -100,9 +101,13 @@
cb_parameterCEdit(app);
cb_findTour(app);
cb_simFcn(app);
cb_scheme(app);
timeElapsed(app,obj,event);
cleanState(app);
createTspHopfieldNet(app,varargin);
updateTspHopfieldNet(app,C);
problemIsSelected = verifyProblemIsSelected(app);
cb_closeApp(app);
end

end
14 changes: 14 additions & 0 deletions chn/+apps/@HopfieldNetworkTSPApp/cb_closeApp.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function cb_closeApp(app,~)

selection = questdlg('Close Hopfield Net TSP solver App?',...
'Close App?',...
'Yes','No','Yes');
switch selection
case 'Yes'
warning('on','tsphopfieldnet:NotSimulated');
warning('on','MATLAB:MKDIR:DirectoryExists');
delete(app.figure);
case 'No'
return;
end
end
12 changes: 4 additions & 8 deletions chn/+apps/@HopfieldNetworkTSPApp/cb_findTour.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,9 @@ function cb_findTour(app,~)
end
end

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

u0 = str2double(app.settings_u0Edit.String);
Expand All @@ -35,6 +29,7 @@ function cb_findTour(app,~)
dt = str2double(app.settings_dtEdit.String);
e = str2double(app.settings_eEdit.String);
q = str2double(app.settings_qEdit.String);
tau = str2double(app.cities_tauEdit.String);

try
setSetting(app.net,'U0',u0)
Expand All @@ -43,6 +38,7 @@ function cb_findTour(app,~)
setSetting(app.net,'Dt',dt)
setSetting(app.net,'E',e)
setSetting(app.net,'Q',q)
setCities(app.net,'Tau',tau)
catch me
msgbox(me.message)
return;
Expand Down
37 changes: 37 additions & 0 deletions chn/+apps/@HopfieldNetworkTSPApp/cb_scheme.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
function cb_scheme(app,~)

problemIsSelected = verifyProblemIsSelected(app);
if ~problemIsSelected
msgbox('Please select first the problem to solve', 'Error', 'error');
app.schemeMenu.Value = 1;
return;
end
schemes = app.schemeMenu.String;

chosenScheme = schemes{app.schemeMenu.Value};

if strncmp(chosenScheme,'divide-conquer',14)
app.cities_tauEdit.Enable = 'on';
tau = max(3,round(getTrainParam(app.net,'N')/10));
setCities(app.net,'Tau',tau);
app.cities_tauEdit.String = num2str(tau);

train(app.net);
trainParams = getTrainParam(app.net);

app.parameterAEdit.String = num2str(trainParams.A);
app.parameterBEdit.String = num2str(trainParams.B);
app.parameterDEdit.String = num2str(1/trainParams.dUaux);

app.parameterNEdit.String = num2str(trainParams.N);
app.parameterNpEdit.String = num2str(trainParams.Np);
app.cities_tauEdit.String = num2str(getCities(app.net,'Tau'));
else
app.cities_tauEdit.Enable = 'off';
end

if ~isempty(app.net) && ~strcmp(chosenScheme,'Scheme')
setScheme(app.net, chosenScheme)
end

end
40 changes: 18 additions & 22 deletions chn/+apps/@HopfieldNetworkTSPApp/cb_simFcn.m
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
function cb_simFcn(app,~)

problemIsSelected = verifyProblemIsSelected(app);
if ~problemIsSelected
msgbox('Please select first the problem to solve', 'Error', 'error');
app.simFcnMenu.Value = 1;
return;
end
if app.schemeMenu.Value == 1
msgbox('Please select first the Hopfield Network scheme to solve the problem', 'Error', 'error');
app.simFcnMenu.Value = 1;
return;
end

algorithms = app.simFcnMenu.String;

chosenAlgorithm = algorithms(app.simFcnMenu.Value);
chosenAlgorithm = algorithms{app.simFcnMenu.Value};

app.elapsedTime.String = '';

if strcmp(chosenAlgorithm,'euler')
if strcmp(chosenAlgorithm,'euler') || strcmp(chosenAlgorithm,'runge-kutta')
app.settings_u0Edit.Enable = 'on';
app.settings_dtEdit.Enable = 'on';
app.settings_maxIterEdit.Enable = 'on';
app.settings_eEdit.Enable = 'on';
app.settings_R_ITEREdit.Enable = 'on';
app.settings_qEdit.Enable = 'on';
app.cities_tauEdit.Enable = 'off';
if ~isempty(app.net)
setSimFcn(app.net,'euler')
setSimFcn(app.net,chosenAlgorithm)
end

elseif strcmp(chosenAlgorithm,'talavan-yanez')
Expand All @@ -25,31 +36,16 @@ function cb_simFcn(app,~)
app.settings_eEdit.Enable = 'on';
app.settings_R_ITEREdit.Enable = 'on';
app.settings_qEdit.Enable = 'on';
app.cities_tauEdit.Enable = 'off';
if ~isempty(app.net)
setSimFcn(app.net,'talavan-yanez')
end

elseif strcmp(chosenAlgorithm,'divide-conquer')
app.settings_u0Edit.Enable = 'on';
app.settings_dtEdit.Enable = 'off';
app.settings_maxIterEdit.Enable = 'on';
app.settings_eEdit.Enable = 'on';
app.settings_R_ITEREdit.Enable = 'on';
app.settings_qEdit.Enable = 'on';
app.cities_tauEdit.Enable = 'on';
if ~isempty(app.net)
setSimFcn(app.net,'divide-conquer')
end

end
else
app.settings_u0Edit.Enable = 'off';
app.settings_dtEdit.Enable = 'off';
app.settings_maxIterEdit.Enable = 'off';
app.settings_eEdit.Enable = 'off';
app.settings_R_ITEREdit.Enable = 'off';
app.settings_qEdit.Enable = 'off';
app.cities_tauEdit.Enable = 'off';
end

end
2 changes: 1 addition & 1 deletion chn/+apps/@HopfieldNetworkTSPApp/cb_tabPolygonNcities.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function cb_tabPolygonNcities(app)

N = str2double(app.tabPolygonnCitiesEdit.String);
if isnan(N) || N < 2
msgbox('You must provide a value for number of cities greater than 2', 'Error', 'error');
Expand Down
4 changes: 4 additions & 0 deletions chn/+apps/@HopfieldNetworkTSPApp/cb_tabTSPLIBmenu.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ function cb_tabTSPLIBmenu(app)
problems = app.tabTSPLIBmenu.String;
problemSelected = app.tabTSPLIBmenu.Value;

app.schemeMenu.Value = 1;
app.simFcnMenu.Value = 1;
app.cities_tauEdit.Enable = 'off';

% Useful for problems that take longer to compute tsplib
% and training
app.tabTSPLIBnCitiesEdit.String = '- - - ';
Expand Down
3 changes: 3 additions & 0 deletions chn/+apps/@HopfieldNetworkTSPApp/cleanState.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ function cleanState(app)

defaultSettings(app);

app.simFcnMenu.Value = 1;
app.schemeMenu.Value = 1;

app.settings_u0Edit.Enable = 'off';
app.settings_dtEdit.Enable = 'off';
app.settings_maxIterEdit.Enable = 'off';
Expand Down
Loading

0 comments on commit 1dbabd4

Please sign in to comment.