/****************************************************************** * * * Nest version 2 - 3D Wasp Nest Simulator * * Copyright (C) 1997 Sylvain GUERIN * * LIASC, ENST Bretagne & Santa Fe Institute * * * ****************************************************************** Name : testN2.c Component : tests Fonctionality : noised simulations ******************************************************************/ #include "algo.h" #include "simu.h" #include "graph.h" #include #define TESTS_NUMBER 19 main (int argc, char* argv[]) { int i; time_t currentTime; char inputFile[256]; char name[256]; char outputFile[256]; char directory[256]; Simulation* aSimulation; double f1, f2, f3, f4, f5, f6, f7; RuleStats ruleStats; FILE *pf; char fname[256]; char noiseInfo[256]; int currentTest; double currentNoiseRate; double noiseRate[TESTS_NUMBER]; char testName[TESTS_NUMBER][10]; FILE *gpf1, *gpf2, *gpf3, *gpf4, *gpf5, *gpf6, *gpf7; FILE *rspf, *rsdf; noiseRate[0] = 0.000; strcpy (testName[0], "_0_000"); noiseRate[1] = 0.005; strcpy (testName[1], "_0_005"); noiseRate[2] = 0.010; strcpy (testName[2], "_0_010"); noiseRate[3] = 0.015; strcpy (testName[3], "_0_015"); noiseRate[4] = 0.020; strcpy (testName[4], "_0_020"); noiseRate[5] = 0.030; strcpy (testName[5], "_0_030"); noiseRate[6] = 0.040; strcpy (testName[6], "_0_040"); noiseRate[7] = 0.050; strcpy (testName[7], "_0_050"); noiseRate[8] = 0.060; strcpy (testName[8], "_0_060"); noiseRate[9] = 0.070; strcpy (testName[9], "_0_070"); noiseRate[10] = 0.080; strcpy (testName[10], "_0_080"); noiseRate[11] = 0.090; strcpy (testName[11], "_0_090"); noiseRate[12] = 0.100; strcpy (testName[12], "_0_100"); noiseRate[13] = 0.110; strcpy (testName[13], "_0_110"); noiseRate[14] = 0.120; strcpy (testName[14], "_0_120"); noiseRate[15] = 0.150; strcpy (testName[15], "_0_150"); noiseRate[16] = 0.200; strcpy (testName[16], "_0_200"); noiseRate[17] = 0.250; strcpy (testName[17], "_0_250"); noiseRate[18] = 0.300; strcpy (testName[18], "_0_300"); if (argc != 4) { printf ("Usage:testN2 directory name outputfile\n"); } else { strcpy (directory, argv[1]); strcpy (name, argv[2]); strcpy (inputFile, name); strcat (inputFile, ".rul"); strcpy (outputFile, argv[3]); printf ("Running testN2 with following parameters:\n"); printf ("Directory: %s\n", directory); printf ("Name: %s\n", name); printf ("Input file: %s\n", inputFile); printf ("Output file: %s\n", outputFile); strcpy (fname, directory); strcat (fname, outputFile); pf = fopen (fname, "w"); if (pf == NULL) { printf ("Unable to open file %s in writing\n", fname); exit (-1); } fprintf (pf, "Resultats obtenus sur la structure %s\n\n", name); fprintf (pf, "Directory: %s\n", directory); fprintf (pf, "Name: %s\n", name); fprintf (pf, "Input file: %s\n", inputFile); fprintf (pf, "Output file: %s\n\n", outputFile); fprintf (pf, "f1: UsedRulesFraction\n"); fprintf (pf, "f2: GlobalUsedRules\n"); fprintf (pf, "f3: Compacity\n"); fprintf (pf, "f4: Complexity\n"); fprintf (pf, "f5: Coherence\n"); fprintf (pf, "f6: HybridMethod\n"); fprintf (pf, "f7: HybridMethod2\n\n"); fprintf (pf, "nr f1 f2 f3 f4 f5 f6 f7 det prob 0.05 0.10 0.20 0.30 0.50 1.00 total\n"); fprintf (pf, "-------------------------------------------------------------------------------------------------------------\n"); strcpy (fname, directory); gpf1 = fopen (strcat (fname, "f1.gp"), "w"); strcpy (fname, directory); gpf2 = fopen (strcat (fname, "f2.gp"), "w"); strcpy (fname, directory); gpf3 = fopen (strcat (fname, "f3.gp"), "w"); strcpy (fname, directory); gpf4 = fopen (strcat (fname, "f4.gp"), "w"); strcpy (fname, directory); gpf5 = fopen (strcat (fname, "f5.gp"), "w"); strcpy (fname, directory); gpf6 = fopen (strcat (fname, "f6.gp"), "w"); strcpy (fname, directory); gpf7 = fopen (strcat (fname, "f7.gp"), "w"); strcpy (fname, directory); rspf = fopen (strcat (fname, "prob_rules.gp"), "w"); strcpy (fname, directory); rsdf = fopen (strcat (fname, "det_rules.gp"), "w"); for (currentTest=0; currentTestload (directory, inputFile, BFalse) == 0) { printf ("ERROR: unable to open %s%s\n", directory, inputFile); delete aSimulation; exit (-1); } else { printf ("Successfully opened %s\n", inputFile); aSimulation->simulate (20, /* architecture size */ 30000, /* iterations number */ 500, /* max cells */ HybridMethod, /* fitness type */ noLearning, /* learning */ 0, /* to build rule number */ 1, /* evaluation enabled */ currentNoiseRate); /* noiseRate */ aSimulation->classifyRules (); f1 = aSimulation->evaluate (UsedRulesFraction); f2 = aSimulation->evaluate (GlobalUsedRules); f3 = aSimulation->evaluate (Compacity); f4 = aSimulation->evaluate (Complexity); f5 = aSimulation->evaluate (Coherence); f6 = aSimulation->evaluate (HybridMethod); f7 = aSimulation->evaluate (HybridMethod2); ruleStats = aSimulation->simulationArchitecture->getRuleStats (); fprintf (pf, "%.3f %.4f %.4f %.4f %.4f %.4f %.4f %.4f %3d %3d %3d %3d %3d %3d %3d %3d %3d\n", currentNoiseRate, f1, f2, f3, f4, f5, f6, f7, ruleStats.detRules, ruleStats.probRules, ruleStats.prob0_05Rules, ruleStats.prob0_1Rules, ruleStats.prob0_2Rules, ruleStats.prob0_3Rules, ruleStats.prob0_5Rules, ruleStats.prob1_0Rules, ruleStats.detRules + ruleStats.probRules); printf ("%.3f %.4f %.4f %.4f %.4f %.4f %.4f %.4f %3d %3d %3d %3d %3d %3d %3d %3d %3d\n", currentNoiseRate, f1, f2, f3, f4, f5, f6, f7, ruleStats.detRules, ruleStats.probRules, ruleStats.prob0_05Rules, ruleStats.prob0_1Rules, ruleStats.prob0_2Rules, ruleStats.prob0_3Rules, ruleStats.prob0_5Rules, ruleStats.prob1_0Rules, ruleStats.detRules + ruleStats.probRules); fprintf (gpf1, "%.3f %.4f\n", currentNoiseRate, f1); fprintf (gpf2, "%.3f %.4f\n", currentNoiseRate, f2); fprintf (gpf3, "%.3f %.4f\n", currentNoiseRate, f3); fprintf (gpf4, "%.3f %.4f\n", currentNoiseRate, f4); fprintf (gpf5, "%.3f %.4f\n", currentNoiseRate, f5); fprintf (gpf6, "%.3f %.4f\n", currentNoiseRate, f6); fprintf (gpf7, "%.3f %.4f\n", currentNoiseRate, f7); fprintf (rspf, "%.3f %.4f\n", currentNoiseRate, (double)100*ruleStats.probRules/(double)(ruleStats.detRules+ruleStats.probRules)); fprintf (rsdf, "%.3f %.4f\n", currentNoiseRate, (double)100*ruleStats.detRules/(double)(ruleStats.detRules+ruleStats.probRules)); sprintf (noiseInfo, " noise=%.3f", currentNoiseRate); strcat (aSimulation->name, noiseInfo); strcpy (aSimulation->fileName, name); strcat (aSimulation->fileName, testName[currentTest]); strcat (aSimulation->fileName, ".rul"); aSimulation->save (rulFile, archMustBeSaved, previewMustNotBeSaved, noCompression); printf ("Successfully simuled and saved %s\n", aSimulation->fileName); delete aSimulation; } }/* boucle for */ fclose (pf); fclose (gpf1); fclose (gpf2); fclose (gpf3); fclose (gpf4); fclose (gpf5); fclose (gpf6); fclose (gpf7); fclose (rspf); fclose (rsdf); } }