C++ Neural Networks and Fuzzy Logic
by Valluru B. Rao M&T Books, IDG Books Worldwide, Inc. ISBN: 1558515526 Pub Date: 06/01/95 |
Previous | Table of Contents | Next |
Let us now look at Hopfield and Tanks approach at solving the TSP.
Hopfield and Tank Example
The Hopfield networks use in solving the traveling salesperson problem is a pioneering effort in the use of the neural network approach for this problem. Hopfield and Tanks example is for a problem with 10 cities. The parameters used were, A1= 500, A2 = 500, A3 = 200, A4 = 500, τ = 1, λ = 50, and m = 15. A good solution corresponding to a local minimum for E is the expected, if not the best, solution (global minimum). An annealing process could be considered to move out of any local minimum. As was mentioned before, the traveling salesperson problem is one of those problems for which a single approach cannot be found that will be successful in all cases. There isnt very much guidance as to how to choose the parameters in general for the use of the Hopfield network to solve the traveling salesperson problem.
We present a C++ program for the Hopfield network operation for the traveling salesperson problem. The header file is in the Listing 15.1, and the source file is in the Listing 15.2. A tsneuron class is declared for a neuron and a network class for the network. The network class is declared a friend in the tsneuron class. The program follows the procedure described for setting inputs, connection weights, and updating.
Program Details
The following is a listing of the characteristics of the C++ program along with definitions and/or functions.
Listing 15.1 Header file for the C++ program for the Hopfield network for the traveling salesperson problem
//trvslsmn.h V. Rao, H. Rao #include <iostream.h> #include <stdlib.h> #include <math.h> #include <stdio.h> #define MXSIZ 11 class tsneuron { protected: int cit,ord; float output; float activation; friend class network; public: tsneuron() { }; void getnrn(int,int); }; class network { public: int citnbr; float pra,prb,prc,prd,totout,distnce; tsneuron (tnrn)[MXSIZ][MXSIZ]; int dist[MXSIZ][MXSIZ]; int tourcity[MXSIZ]; int tourorder[MXSIZ]; float outs[MXSIZ][MXSIZ]; float acts[MXSIZ][MXSIZ]; float mtrx[MXSIZ][MXSIZ]; float citouts[MXSIZ]; float ordouts[MXSIZ]; network() { }; void getnwk(int,float,float,float,float); void getdist(int); void findtour(); void asgninpt(float *); void calcdist(); void iterate(int,int,float,float,float); void getacts(int,float,float); void getouts(float); //print functions void prdist(); void prmtrx(int); void prtour(); void practs(); void prouts(); };
Previous | Table of Contents | Next |