public double[] RunSUT(string sut, params double[] num) { // Given an input, give SUT's output // Main purpose: Testing int[] outputs = null; readBranch rb = new readBranch(); int[] inputs = Array.ConvertAll(num, n => (int)n); if (sut == "tri") { rb.ReadBranchCLIFunc(inputs, ref outputs, 0); } if (sut == "gcd") { rb.ReadBranchCLIFunc(inputs, ref outputs, 1); } if (sut == "calday") { rb.ReadBranchCLIFunc(inputs, ref outputs, 2); } if (sut == "bestmove") { rb.ReadBranchCLIFunc(inputs, ref outputs, 3); } if (sut == "neichneu") { rb.ReadBranchCLIFunc(inputs, ref outputs, 4); } return(Array.ConvertAll(outputs, n => (double)n)); }
static void GenCalDay(int selectSUT) { int var1L = 0; int var1H = 12; int var2L = 0; int var2H = 365; int var3L = 0; int var3H = 100; readBranch tmp = new readBranch(); int[] inputs = new int[3] { 1, 2, 3 }; int[] ces = null; LocalFileAccess lfa = new LocalFileAccess(); List <string> dataToFile = new List <string>(); for (int i = var1L; i <= var1H; i++) { for (int j = var2L; j <= var2H; j++) { for (int k = var3L; k <= var3H; k++) { Console.WriteLine("{0},{1},{2}", var1H - i, var2H - j, var3H - k); inputs[0] = i; inputs[1] = j; inputs[2] = k; tmp.ReadBranchCLIFunc(inputs, ref ces, selectSUT); string strData = null; for (int l = 0; l < ces.Length; l++) { if (ces[l] == 1) { strData = i.ToString() + " " + j.ToString() + " " + k.ToString() + " " + l.ToString(); dataToFile.Add(strData); lfa.StoreListToLines(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\calday", dataToFile); dataToFile.Clear(); } } } } } }
static void Main(string[] args) { readBranch rb = new readBranch(); int[] outputs = null; List <string> strPaths = new List <string>(); for (int i = 0; i < 512; i++) { for (int j = 0; j < 512; j++) { int[] input = new int[] { i, j }; rb.ReadBranchCLIFunc(input, ref outputs, 3); string tmp = null; for (int m = 0; m < outputs.Length; m++) { tmp = tmp + outputs[m].ToString() + " "; } if (!strPaths.Contains(tmp)) { strPaths.Add(tmp); } } } Console.WriteLine("# of Paths: {0}", strPaths.Count); List <int> lastCEList = new List <int>(); for (int i = 0; i < strPaths.Count; i++) { int index = strPaths[i].LastIndexOf('1'); if (!lastCEList.Contains(index)) { lastCEList.Add(index); } } Console.ReadKey(); }
static void GenGCDData(int selectSUT) { int var1L = 0; int var1H = 100; int var2L = 0; int var2H = 100; readBranch tmp = new readBranch(); int[] inputs = new int[2] { 1, 2 }; int[] ces = null; LocalFileAccess lfa = new LocalFileAccess(); List <string> dataToFile = new List <string>(); for (int i = var1L; i <= var1H; i++) { for (int j = var2L; j <= var2H; j++) { inputs[0] = i; inputs[1] = j; tmp.ReadBranchCLIFunc(inputs, ref ces, selectSUT); string strData = null; for (int l = 0; l < ces.Length; l++) { if (ces[l] == 1) { strData = i.ToString() + " " + j.ToString() + " " + " " + l.ToString(); dataToFile.Add(strData); } } } } lfa.StoreListToLines(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\gcd", dataToFile); }
public static void sutBestMove( Pair <int, int, double[]>[] bins, int numOfLabels ) { Dictionary <string, int> pathStorage = new Dictionary <string, int>(); int numOfMinIntervalX = 32; int numOfMinIntervalY = 32; int minIntervalX = 512 / numOfMinIntervalX; int minIntervalY = 512 / numOfMinIntervalY; double sampleProbability = 0.3; int totalNumberOfBins = numOfMinIntervalX * numOfMinIntervalY; bins = new Pair <int, int, double[]> [totalNumberOfBins]; for (int i = 0; i < totalNumberOfBins; i++) { bins[i] = new Pair <int, int, double[]>(); bins[i].Item0 = i; bins[i].Item1 = -1; int xlowBoundIndex = (i % numOfMinIntervalX) * minIntervalX; int ylowBoundIndex = (i / numOfMinIntervalY) * minIntervalY; int sampleSize = (int)(minIntervalX * minIntervalY * sampleProbability); readBranch rbce = new readBranch(); List <string> paths = new List <string>(); int count = 0; List <int[]> generatedList = new List <int[]>(); while (count < sampleSize) { int x = GlobalVar.rnd.Next(xlowBoundIndex, xlowBoundIndex + minIntervalX); int y = GlobalVar.rnd.Next(ylowBoundIndex, ylowBoundIndex + minIntervalY); if (generatedList.Where(t => (t[0] == x && t[1] == y) == true).Count() == 0) { count += 1; generatedList.Add(new int[] { x, y }); int[] inputs = new int[2] { x, y }; int[] outputs = null; rbce.ReadBranchCLIFunc(inputs, ref outputs, 3); string path = null; foreach (int e in outputs) { path = path + e.ToString(); } paths.Add(path); if (!pathStorage.ContainsKey(path)) { int newValue = pathStorage.Values.Max() + 1; pathStorage.Add(path, newValue); } } } double[] triggeringProbilities = new double[numOfLabels]; var distinctPaths = paths.Distinct().ToList(); for (int o = 0; o < distinctPaths.Count; o++) { double triProb = paths.Count(x => x == distinctPaths[o]) / sampleSize; int value = pathStorage.ContainsKey(distinctPaths[o]) ? pathStorage[distinctPaths[o]] : -1; if (value == -1) { Console.WriteLine("pathStorage WRONG"); } triggeringProbilities[value] = triProb; } bins[i].Item2 = triggeringProbilities; } }