using System; using System.Windows.Forms; namespace aiNnFingers { public class BOLTZMAN { public BOLTZMAN() { } public RichTextBox richTextBox; //#include //#include //#include //typedef int BOOL; //typedef int INT; //typedef double REAL; //#define FALSE 0 //#define TRUE 1 //#define NOT ! //#define AND && //#define OR || //#define PI (2*asin(1)) //#define sqr(x) ((x)*(x)) public int BINARY(bool x) { if(x == false) return 0; else return 1; } public struct NET { /* A NET: */ public int Units; /* - number of units in this net */ public bool[] Output; /* - output of ith unit */ public int[] On; /* - counting on states in equilibrium */ public int[] Off; /* - counting off states in equilibrium */ public double[] Threshold; /* - threshold of ith unit */ public double[][] Weight; /* - connection weights to ith unit */ public double Temperature; /* - actual temperature */ } /****************************************************************************** R A N D O M S D R A W N F R O M D I S T R I B U T I O N S ******************************************************************************/ Random r; const int RAND_MAX = Int32.MaxValue; void InitializeRandoms() { //srand(4711); r = new Random(4711); } bool RandomEqualBOOL() { //return rand() % 2; int retVal = r.Next() % 2; if(retVal == 0) return false; else return true; //return Boolean.Parse(retVal.ToString()); } int RandomEqualINT(int Low, int High) { //return rand() % (High-Low+1) + Low; int retVal = r.Next() % (High-Low+1) + Low; return retVal; } double RandomEqualREAL(double Low, double High) { double retVal = ((double) r.Next() / (double) RAND_MAX) * (High-Low) + Low; //268 times return retVal; } /****************************************************************************** A P P L I C A T I O N - S P E C I F I C C O D E ******************************************************************************/ //#define NUM_CITIES 10 const int NUM_CITIES = 10; //#define N (NUM_CITIES * NUM_CITIES) const int N = NUM_CITIES * NUM_CITIES; double Gamma; double [][] Distance = new double[NUM_CITIES][]; //NUM_CITIES //FILE* f; void InitializeApplication(ref NET Net) { int n1,n2; double x1,x2,y1,y2; double Alpha1, Alpha2; Gamma = 7; for (n1=0; n1 1) return false; } if (Net.Output[n2*NUM_CITIES+n1]) { if (++Stops > 1) return false; } } if ((Cities != 1) || (Stops != 1)) return false; } return true; } double LengthOfTour(ref NET Net) { int n1,n2,n3; double Length; Length = 0; for (n1=0; n1 Net.Off[i]; } } void Anneal(ref NET Net) { Net.Temperature = 100; do { BringToThermalEquilibrium(ref Net); WriteTour(ref Net); Net.Temperature *= 0.99; } while (!ValidTour(ref Net)); } /****************************************************************************** M A I N ******************************************************************************/ public void main() { NET Net = new NET(); InitializeRandoms(); GenerateNetwork(ref Net); InitializeApplication(ref Net); CalculateWeights(ref Net); SetRandom(ref Net); Anneal(ref Net); FinalizeApplication(ref Net); } } }