Skip to content

Commit

Permalink
Bug Fixing, minor enhancements (and packaging projects upgrades to R2…
Browse files Browse the repository at this point in the history
…017a)

Bug Fixing:
#24 Sim fails when using divide-conquer method
#25 tsphopfieldnet fails if coordinates are missing, but distance matrix
is available

Enhancements:
#26 Code cleanup
#27 Change interface from generichopfieldnet to hopfieldnet

Updating release notes.
Upgrading to MATLAB R2017a (App and Toolbox packaging projects).
  • Loading branch information
mathinking committed Apr 9, 2017
1 parent 189bec3 commit 37dedb8
Show file tree
Hide file tree
Showing 50 changed files with 265 additions and 128 deletions.
77 changes: 76 additions & 1 deletion +Test/test_tsphopfieldnet.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'});
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion @tsphopfieldnet/sim.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion @tsphopfieldnet/tsphopfieldnet.m
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 12 additions & 6 deletions Hopfield Net TSP solver.prj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<deployment-project plugin="plugin.apptool" plugin-version="1.0">
<configuration build-checksum="1730626426" file="E:\Users\Lucas\Documents\Math\PhD\sandbox\hopfield_network\trunk\code\Hopfield Net TSP solver.prj" location="E:\Users\Lucas\Documents\Math\PhD\sandbox\hopfield_network\trunk\code" name="Hopfield Net TSP solver" target="target.mlapps" target-name="Package App">
<configuration build-checksum="2665613974" file="E:\Users\Lucas\Documents\GitHub\HopfieldNetworkToolbox\Hopfield Net TSP solver.prj" location="E:\Users\Lucas\Documents\GitHub\HopfieldNetworkToolbox" name="Hopfield Net TSP solver" target="target.mlapps" target-name="Package App">
<param.appname>Hopfield Net TSP solver</param.appname>
<param.authnamewatermark>Lucas García Rodríguez</param.authnamewatermark>
<param.email>[email protected]</param.email>
Expand All @@ -26,11 +26,11 @@ Find more information in the documentation of the toolbox or in the &lt;a href="
<item>19</item>
</param.products.id>
<param.products.version>
<item>9.0</item>
<item>10.2</item>
<item>9.2</item>
<item>11.1</item>
</param.products.version>
<param.platforms />
<param.output>E:\Users\Lucas\Documents\Math\PhD\sandbox\hopfield_network\trunk\code</param.output>
<param.output>E:\Users\Lucas\Documents\GitHub\HopfieldNetworkToolbox</param.output>
<param.guid>d605def3-3010-4890-ac40-cf704be9aed1</param.guid>
<unset>
<param.platforms />
Expand Down Expand Up @@ -338,16 +338,17 @@ Find more information in the documentation of the toolbox or in the &lt;a href="
</fileset.resources>
<fileset.package />
<build-deliverables>
<file location="E:\Users\Lucas\Documents\Math\PhD\sandbox\hopfield_network\trunk" name="code" optional="false">E:\Users\Lucas\Documents\Math\PhD\sandbox\hopfield_network\trunk\code</file>
<file location="E:\Users\Lucas\Documents\GitHub" name="HopfieldNetworkToolbox" optional="false">E:\Users\Lucas\Documents\GitHub\HopfieldNetworkToolbox</file>
</build-deliverables>
<workflow />
<matlab>
<root>C:\Program Files\MATLAB\R2016a</root>
<root>C:\Program Files\MATLAB\R2017a</root>
<toolboxes>
<toolbox name="fixedpoint" />
<toolbox name="matlabcoder" />
<toolbox name="matlabhdlcoder" />
<toolbox name="embeddedcoder" />
<toolbox name="polyspacebugfinder" />
</toolboxes>
<toolbox>
<fixedpoint>
Expand All @@ -369,6 +370,11 @@ Find more information in the documentation of the toolbox or in the &lt;a href="
<enabled>true</enabled>
</embeddedcoder>
</toolbox>
<toolbox>
<polyspacebugfinder>
<enabled>true</enabled>
</polyspacebugfinder>
</toolbox>
</matlab>
<platform>
<unix>false</unix>
Expand Down
51 changes: 32 additions & 19 deletions Hopfield Network Toolbox.prj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<deployment-project plugin="plugin.toolbox" plugin-version="1.0">
<configuration build-checksum="3794982231" file="E:\Users\Lucas\Documents\Math\PhD\sandbox\hopfield_network\trunk\code\Hopfield Network Toolbox.prj" location="E:\Users\Lucas\Documents\Math\PhD\sandbox\hopfield_network\trunk\code" name="Hopfield Network Toolbox" target="target.toolbox" target-name="Package Toolbox">
<configuration build-checksum="3794982231" file="E:\Users\Lucas\Documents\GitHub\HopfieldNetworkToolbox\Hopfield Network Toolbox.prj" location="E:\Users\Lucas\Documents\GitHub\HopfieldNetworkToolbox" name="Hopfield Network Toolbox" target="target.toolbox" target-name="Package Toolbox">
<param.appname>Hopfield Network Toolbox</param.appname>
<param.authnamewatermark>Lucas García Rodríguez</param.authnamewatermark>
<param.email>[email protected]</param.email>
Expand All @@ -9,9 +9,18 @@
<param.screenshot>${PROJECT_ROOT}\help\html\hopfieldnet.png</param.screenshot>
<param.version>1.1.2</param.version>
<param.output>${PROJECT_ROOT}\Hopfield Network Toolbox.mltbx</param.output>
<param.products.name />
<param.products.id />
<param.products.version />
<param.products.name>
<item>MATLAB</item>
<item>Statistics and Machine Learning Toolbox</item>
</param.products.name>
<param.products.id>
<item>1</item>
<item>19</item>
</param.products.id>
<param.products.version>
<item>9.2</item>
<item>11.1</item>
</param.products.version>
<param.platforms />
<param.guid>9468a56e-2dfa-48c1-b681-f168f0815c88</param.guid>
<param.exclude.filters>% List files contained in your toolbox folder that you would like to exclude
Expand Down Expand Up @@ -45,48 +54,48 @@ BuildInstructions.m</param.exclude.filters>
&lt;exampleCategory name="Solving the Traveling Salesman Problem 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;E:/Users/Lucas/Documents/MATLAB/Add-Ons/Toolboxes/Hopfield Network Toolbox/code/help/Example_tspUsingRegularPolygons.m&lt;/file&gt;
&lt;file type="main"&gt;/help/Example_tspUsingRegularPolygons.m&lt;/file&gt;
&lt;file type="thumbnail"&gt;/help/html/Example_tspUsingRegularPolygons.png&lt;/file&gt;
&lt;file type="image"&gt;/help/html/Example_tspUsingRegularPolygons_01.png&lt;/file&gt;
&lt;file type="image"&gt;/help/html/Example_tspUsingRegularPolygons_02.png&lt;/file&gt;
&lt;/example&gt;
&lt;example name="Solving the TSP with TSPLIB cities" type="html"&gt;
&lt;file type="source"&gt;/help/html/Example_tspUsingTSPLIB.html&lt;/file&gt;
&lt;file type="main"&gt;E:/Users/Lucas/Documents/MATLAB/Add-Ons/Toolboxes/Hopfield Network Toolbox/code/help/Example_tspUsingTSPLIB.m&lt;/file&gt;
&lt;file type="main"&gt;/help/Example_tspUsingTSPLIB.m&lt;/file&gt;
&lt;file type="thumbnail"&gt;/help/html/Example_tspUsingTSPLIB.png&lt;/file&gt;
&lt;file type="image"&gt;/help/html/Example_tspUsingTSPLIB_01.png&lt;/file&gt;
&lt;file type="image"&gt;/help/html/Example_tspUsingTSPLIB_02.png&lt;/file&gt;
&lt;/example&gt;
&lt;example name="Solving the TSP provided the problem's coordinates" type="html"&gt;
&lt;file type="source"&gt;/help/html/Example_tspUsingCoords.html&lt;/file&gt;
&lt;file type="main"&gt;E:/Users/Lucas/Documents/MATLAB/Add-Ons/Toolboxes/Hopfield Network Toolbox/code/help/Example_tspUsingCoords.m&lt;/file&gt;
&lt;file type="main"&gt;/help/Example_tspUsingCoords.m&lt;/file&gt;
&lt;file type="thumbnail"&gt;/help/html/Example_tspUsingCoords.png&lt;/file&gt;
&lt;file type="image"&gt;/help/html/Example_tspUsingCoords_01.png&lt;/file&gt;
&lt;file type="image"&gt;/help/html/Example_tspUsingCoords_02.png&lt;/file&gt;
&lt;/example&gt;
&lt;example name="Solving the TSP provided the distance matrix" type="html"&gt;
&lt;file type="source"&gt;/help/html/Example_tspUsingDistance.html&lt;/file&gt;
&lt;file type="main"&gt;E:/Users/Lucas/Documents/MATLAB/Add-Ons/Toolboxes/Hopfield Network Toolbox/code/help/Example_tspUsingDistance.m&lt;/file&gt;
&lt;file type="main"&gt;/help/Example_tspUsingDistance.m&lt;/file&gt;
&lt;file type="thumbnail"/&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;
&lt;file type="source"&gt;/help/html/Example_tspReducingC.html&lt;/file&gt;
&lt;file type="main"&gt;E:/Users/Lucas/Documents/MATLAB/Add-Ons/Toolboxes/Hopfield Network Toolbox/code/help/Example_tspReducingC.m&lt;/file&gt;
&lt;file type="main"&gt;/help/Example_tspReducingC.m&lt;/file&gt;
&lt;file type="thumbnail"&gt;/help/html/Example_tspReducingC.png&lt;/file&gt;
&lt;file type="image"&gt;/help/html/Example_tspReducingC_01.png&lt;/file&gt;
&lt;file type="image"&gt;/help/html/Example_tspReducingC_02.png&lt;/file&gt;
&lt;file type="image"&gt;/help/html/Example_tspReducingC_03.png&lt;/file&gt;
&lt;/example&gt;
&lt;example name="Appropriate starting point" type="html"&gt;
&lt;file type="source"&gt;/help/html/Example_tspSaddlePoint.html&lt;/file&gt;
&lt;file type="main"&gt;E:/Users/Lucas/Documents/MATLAB/Add-Ons/Toolboxes/Hopfield Network Toolbox/code/help/Example_tspSaddlePoint.m&lt;/file&gt;
&lt;file type="main"&gt;/help/Example_tspSaddlePoint.m&lt;/file&gt;
&lt;file type="thumbnail"/&gt;
&lt;/example&gt;
&lt;example name="A Divide-and-Conquer Scheme" type="html"&gt;
&lt;file type="source"&gt;/help/html/Example_tspDivideConquer.html&lt;/file&gt;
&lt;file type="main"&gt;E:/Users/Lucas/Documents/MATLAB/Add-Ons/Toolboxes/Hopfield Network Toolbox/code/help/Example_tspDivideConquer.m&lt;/file&gt;
&lt;file type="main"&gt;/help/Example_tspDivideConquer.m&lt;/file&gt;
&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;
Expand All @@ -98,17 +107,16 @@ BuildInstructions.m</param.exclude.filters>
</param.apps>
<param.docs>${PROJECT_ROOT}\help\info.xml</param.docs>
<param.matlabpath.excludes />
<param.javaclasspath.excludes />
<unset>
<param.output />
<param.products.name />
<param.products.id />
<param.products.version />
<param.platforms />
<param.demosxml />
<param.matlabpath.excludes />
<param.javaclasspath.excludes />
</unset>
<fileset.rootdir>
<file>E:\Users\Lucas\Documents\Math\PhD\sandbox\hopfield_network\trunk\code</file>
<file>E:\Users\Lucas\Documents\GitHub\HopfieldNetworkToolbox</file>
</fileset.rootdir>
<fileset.rootfiles>
<file>${PROJECT_ROOT}\@hopfieldnet</file>
Expand All @@ -118,25 +126,25 @@ BuildInstructions.m</param.exclude.filters>
<file>${PROJECT_ROOT}\@tsplib</file>
<file>${PROJECT_ROOT}\help</file>
<file>${PROJECT_ROOT}\Hopfield Net TSP solver.mlappinstall</file>
<file>${PROJECT_ROOT}\Phase1_PossibleSaddlePoint</file>
<file>${PROJECT_ROOT}\ReleaseNotes.txt</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 />
<fileset.package />
<build-deliverables>
<file location="E:\Users\Lucas\Documents\Math\PhD\sandbox\hopfield_network\trunk\code" name="Hopfield Network Toolbox.mltbx" optional="false">E:\Users\Lucas\Documents\Math\PhD\sandbox\hopfield_network\trunk\code\Hopfield Network Toolbox.mltbx</file>
<file location="E:\Users\Lucas\Documents\GitHub\HopfieldNetworkToolbox" name="Hopfield Network Toolbox.mltbx" optional="false">E:\Users\Lucas\Documents\GitHub\HopfieldNetworkToolbox\Hopfield Network Toolbox.mltbx</file>
</build-deliverables>
<workflow />
<matlab>
<root>C:\Program Files\MATLAB\R2016a</root>
<root>C:\Program Files\MATLAB\R2017a</root>
<toolboxes>
<toolbox name="fixedpoint" />
<toolbox name="matlabcoder" />
<toolbox name="matlabhdlcoder" />
<toolbox name="embeddedcoder" />
<toolbox name="polyspacebugfinder" />
</toolboxes>
<toolbox>
<fixedpoint>
Expand All @@ -158,6 +166,11 @@ BuildInstructions.m</param.exclude.filters>
<enabled>true</enabled>
</embeddedcoder>
</toolbox>
<toolbox>
<polyspacebugfinder>
<enabled>true</enabled>
</polyspacebugfinder>
</toolbox>
</matlab>
<platform>
<unix>false</unix>
Expand Down
Loading

0 comments on commit 37dedb8

Please sign in to comment.