[ Pobierz całość w formacie PDF ]
.It is a square matrix of order n2. An input vector is generated at random in the function main ( ), and is later referred to as ip asgninpt ( ) function presents the input vector ip to the network and determines the initial activations of the neurons. getacts ( ) function updates the activations of the neurons after each iteration. getouts ( ) function computes the outputs after each iteration.la is used as abbreviation for lambda in its argument. iterate ( ) function carries out the number of iterations desired. findtour ( ) function determines the tour orders of cities to be visited using the outputs of the neurons.When used at the end of the iterations, it gives the solution obtained for the traveling salesperson problem. calcdist ( ) function calculates the distance of the tour in the solution.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 11class 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 functionsvoid prdist();void prmtrx(int);void prtour();void practs();void prouts();};PreviousTable of ContentsNext | | Use of this site is subject to certain ,All rights reserved.Reproduction whole or in part in any form or medium without express written permision of EarthWeb is prohibited
[ Pobierz całość w formacie PDF ]