diff --git a/IncrementalMinimization/generate_graph.py b/IncrementalMinimization/generate_graph.py index 80f72c1d..03aa9e00 100644 --- a/IncrementalMinimization/generate_graph.py +++ b/IncrementalMinimization/generate_graph.py @@ -23,7 +23,7 @@ def mergeData(data, index): for row in data: if new_data and new_data[-1][index] == row[index]: old_row = new_data[-1] - count += 1 + count += 1 for i in range(0, len(old_row)): if i != index: old_row[i] += (row[i] - old_row[i])/float(count) #running average diff --git a/IncrementalMinimization/record_graph.py b/IncrementalMinimization/record_graph.py new file mode 100644 index 00000000..f128f10a --- /dev/null +++ b/IncrementalMinimization/record_graph.py @@ -0,0 +1,68 @@ +import numpy +import matplotlib.pyplot as pyplot +import plotly.plotly as plotly +import plotly.tools as plottls + +import sys + +xAxis = "Percentage of Time Passed" +yAxis = "Number of States" +title = "Progress of Symbolic Incremental Minimization" + +testsfile = sys.argv[1] + +def toNum(s): + if s.isdigit(): + return int(s) + else: + return float(s) + +with open(testsfile, "r") as f: + fStrings = f.read().split("\n") + +title_row = fStrings[0].split(',') +x = [toNum(s) for s in title_row[1:-1] if s] + +y = [] +z = [] +for row in fStrings[1:]: + if row: + row = row.split(",") + print(row) + states = toNum(row[0]) + for percent in row[1:-1]: + z.append(toNum(percent)) + y.append(states) + + +x = numpy.unique(x) +y = numpy.unique(y) +X,Y = numpy.meshgrid(x,y) +z = numpy.array(z) +Z = z.reshape(len(y),len(x)) +print(y) +print(x) +print(Z) +pyplot.pcolormesh(X,Y,Z) +bar = pyplot.colorbar() +bar.set_label("Percentage of Minimization Completed") + +""" + +fig = pyplot.figure() +ax = fig.add_subplot(111) +ax.set_title(title) +plotly_fig = plottls.mpl_to_plotly(fig) +""" + +""" +hexbins = pyplot.hexbin(x,y, gridsize=100, cmap = 'inferno') +pyplot.axis([xmin, xmax, ymin, ymax]) +colorbar = pyplot.colorbar(hexbins) +""" + +pyplot.title(title) +pyplot.ylabel(yAxis) +pyplot.xlabel(xAxis) +pyplot.xticks(range(0,110,10),["{}%".format(p) for p in title_row[1:-1]]) +pyplot.savefig("heatmap.png", dpi=600) diff --git a/IncrementalMinimization/results/heatmap.png b/IncrementalMinimization/results/heatmap.png new file mode 100644 index 00000000..3d56bca0 Binary files /dev/null and b/IncrementalMinimization/results/heatmap.png differ diff --git a/IncrementalMinimization/results/record_test.txt b/IncrementalMinimization/results/record_test.txt new file mode 100644 index 00000000..42be3507 --- /dev/null +++ b/IncrementalMinimization/results/record_test.txt @@ -0,0 +1,165 @@ +initial states, 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, +2, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 100.000000, +3, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 2.380952, 2.380952, 2.380952, 2.380952, 100.000000, +4, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.587302, 1.587302, 1.587302, 1.587302, 100.000000, +5, 0.000000, 0.000000, 0.000000, 0.000000, 2.857143, 8.571429, 12.857143, 12.857143, 13.571429, 15.000000, 100.000000, +6, 0.000000, 0.000000, 1.041667, 4.166667, 10.416667, 18.055556, 21.180556, 23.263889, 23.263889, 25.000000, 100.000000, +7, 0.000000, 0.000000, 0.769231, 6.410256, 16.153846, 19.102564, 22.564103, 29.487179, 36.794872, 38.461538, 100.000000, +8, 0.000000, 0.000000, 2.298851, 9.482759, 16.235632, 18.534483, 29.597701, 34.051724, 36.522989, 38.505747, 100.000000, +9, 0.000000, 0.000000, 2.595628, 4.071038, 9.594067, 14.839969, 20.117096, 21.893052, 26.444184, 28.805621, 100.000000, +10, 0.000000, 0.416667, 3.305556, 11.277778, 15.857143, 20.968254, 26.206349, 33.420635, 34.865079, 43.686508, 100.000000, +11, 0.000000, 0.520833, 5.451389, 9.444444, 14.270833, 20.892857, 26.934524, 31.622024, 39.052579, 41.577381, 100.000000, +12, 0.000000, 0.978261, 6.257764, 10.062112, 16.909938, 23.043478, 26.366460, 32.598344, 41.915114, 45.429607, 100.000000, +13, 0.000000, 0.425532, 6.347518, 7.836879, 11.187943, 14.468085, 22.011145, 29.480750, 39.037487, 44.143870, 100.000000, +14, 0.000000, 1.666667, 9.137159, 16.701262, 26.766382, 32.157102, 36.992267, 42.944648, 49.511600, 56.208791, 100.000000, +15, 0.000000, 1.046099, 7.417258, 11.388889, 19.146403, 23.844985, 32.710233, 36.475008, 40.092030, 46.670044, 100.000000, +16, 0.000000, 2.447090, 7.713294, 10.606812, 15.815146, 21.567460, 28.511905, 51.240588, 59.686101, 63.586564, 100.000000, +17, 0.000000, 2.192982, 9.173977, 14.668964, 22.901003, 29.252297, 35.205723, 42.778822, 53.446115, 60.276734, 100.000000, +18, 0.000000, 1.041667, 9.207459, 13.554154, 26.276571, 33.989066, 41.552753, 45.941836, 49.787990, 53.516553, 100.000000, +19, 0.000000, 2.380952, 5.714286, 12.291937, 20.641504, 30.802219, 37.471861, 46.308171, 47.725920, 53.555465, 100.000000, +20, 0.000000, 4.580639, 12.367887, 21.965650, 28.168452, 31.713425, 38.265554, 46.327087, 51.919782, 58.039160, 100.000000, +21, 0.000000, 5.201662, 14.394933, 19.010712, 27.446872, 36.378120, 44.380727, 52.912195, 67.642250, 75.035806, 100.000000, +22, 0.000000, 8.168978, 18.649754, 24.829495, 33.993982, 43.323246, 51.823611, 56.715663, 66.437392, 73.033237, 100.000000, +23, 0.000000, 2.328193, 6.994348, 14.495325, 20.933141, 35.004885, 39.490816, 50.574796, 56.177624, 67.138423, 100.000000, +24, 0.000000, 5.994916, 15.079679, 24.747828, 29.889056, 42.920160, 58.581371, 69.228316, 74.477101, 78.542757, 100.000000, +25, 0.000000, 10.208793, 22.377715, 38.387728, 43.129135, 52.731289, 56.232616, 61.439710, 72.073390, 76.871734, 100.000000, +26, 0.000000, 10.028860, 21.358225, 28.841991, 33.181818, 42.135799, 53.618483, 65.753576, 73.154370, 80.706130, 100.000000, +27, 0.000000, 6.109582, 14.556132, 20.579872, 25.048354, 28.675125, 38.364991, 48.358841, 52.708275, 56.222408, 100.000000, +28, 0.000000, 10.533304, 18.177448, 25.831668, 35.727120, 47.658852, 56.056287, 60.207692, 65.916254, 75.288011, 100.000000, +29, 0.000000, 5.026455, 7.665344, 12.923280, 23.181217, 27.804233, 30.383598, 40.502646, 45.899471, 61.316138, 100.000000, +30, 0.000000, 17.090039, 24.176816, 34.186937, 39.001071, 42.089370, 46.909944, 55.260314, 59.991802, 76.056730, 100.000000, +31, 0.000000, 7.327160, 12.823888, 24.336141, 37.641418, 42.509491, 57.986726, 64.744825, 72.345076, 82.746658, 100.000000, +32, 0.000000, 7.201518, 17.445282, 30.054409, 44.509945, 55.404405, 66.610655, 70.820024, 76.328811, 84.862159, 100.000000, +33, 0.000000, 5.024630, 11.647267, 22.220521, 33.205693, 44.452513, 49.570520, 53.808897, 63.856219, 70.401695, 100.000000, +34, 0.000000, 11.252346, 20.445020, 32.197117, 38.193968, 47.717359, 52.670284, 62.174484, 71.684195, 78.871674, 100.000000, +35, 0.000000, 10.223759, 20.125576, 32.699737, 38.417236, 52.570834, 54.206012, 56.587303, 61.499717, 72.866614, 100.000000, +36, 0.000000, 11.428360, 19.585671, 38.653670, 42.040251, 52.718499, 59.370187, 65.086992, 67.660521, 72.694915, 100.000000, +37, 0.000000, 11.004464, 18.260169, 37.870558, 44.354933, 53.369070, 59.965052, 63.380344, 74.156633, 82.028657, 100.000000, +38, 0.000000, 13.794972, 20.557583, 32.742979, 43.075196, 50.034822, 59.572540, 67.682203, 79.305491, 86.948141, 100.000000, +39, 0.000000, 12.846132, 17.502216, 26.494096, 37.525983, 41.782272, 48.912302, 58.679819, 65.791812, 80.712447, 100.000000, +40, 0.000000, 21.244154, 39.658781, 46.492783, 54.031875, 57.745499, 66.429472, 72.184121, 77.561541, 85.569141, 100.000000, +41, 0.000000, 18.763730, 31.857689, 40.428073, 46.710887, 52.269824, 58.790134, 62.854231, 67.171870, 73.394482, 100.000000, +42, 0.000000, 9.761905, 19.571429, 36.960317, 49.277778, 54.611111, 62.476190, 66.571429, 71.793651, 75.182540, 100.000000, +43, 0.000000, 15.100724, 27.622987, 41.664091, 47.463077, 57.508704, 63.957574, 71.934562, 79.232697, 85.817553, 100.000000, +44, 0.000000, 15.286404, 26.764531, 35.280845, 46.110900, 54.018480, 58.299689, 65.031248, 77.631019, 84.032992, 100.000000, +45, 0.000000, 9.488842, 20.415020, 28.046017, 43.870704, 48.100502, 56.787170, 69.617153, 76.029035, 81.725058, 100.000000, +46, 0.000000, 0.000000, 25.384615, 29.230769, 43.076923, 50.769231, 68.461538, 68.461538, 82.307692, 82.307692, 100.000000, +47, 0.000000, 18.876919, 34.233323, 48.947757, 52.618556, 54.846517, 59.426407, 70.874410, 77.136462, 82.549685, 100.000000, +48, 0.000000, 26.339865, 38.659741, 48.455328, 57.331656, 60.442767, 67.111216, 70.896573, 75.129398, 78.907298, 100.000000, +49, 0.000000, 24.095238, 35.095238, 38.428571, 43.523810, 47.523810, 52.619048, 57.880952, 60.880952, 66.880952, 100.000000, +50, 0.000000, 23.107664, 35.983314, 43.733668, 47.005352, 51.749096, 59.642392, 61.802886, 66.667083, 75.148393, 100.000000, +51, 0.000000, 14.547023, 32.967064, 41.817567, 49.625292, 58.850786, 65.633479, 71.245796, 73.199819, 84.714387, 100.000000, +52, 0.000000, 21.786971, 38.003214, 44.032716, 49.821788, 53.997612, 62.424047, 66.622046, 72.208935, 83.746050, 100.000000, +53, 0.000000, 5.294118, 40.962795, 48.554550, 55.417295, 70.487682, 75.389643, 83.722976, 84.703369, 85.558069, 100.000000, +54, 0.000000, 33.333333, 41.666667, 41.666667, 41.666667, 41.666667, 41.666667, 58.333333, 66.666667, 83.333333, 100.000000, +55, 0.000000, 14.727273, 22.333916, 31.508741, 42.562937, 48.199301, 57.430070, 70.152098, 79.215035, 85.739510, 100.000000, +56, 0.000000, 23.794565, 35.299706, 45.590071, 49.390481, 56.238054, 60.209916, 63.896063, 69.525933, 73.718574, 100.000000, +57, 0.000000, 27.070762, 41.054819, 52.192169, 62.349435, 72.544212, 77.643666, 83.482494, 87.782860, 91.188573, 100.000000, +58, 0.000000, 8.988044, 25.936872, 29.351506, 38.962219, 56.531325, 64.637016, 70.318508, 81.494978, 86.492587, 100.000000, +59, 0.000000, 30.000000, 43.333333, 50.000000, 50.000000, 56.666667, 66.666667, 76.666667, 76.666667, 86.666667, 100.000000, +60, 0.000000, 22.523041, 27.361751, 37.730415, 49.366359, 52.764977, 64.746544, 80.299539, 86.751152, 91.589862, 100.000000, +61, 0.000000, 6.666667, 22.357143, 40.380952, 46.380952, 53.547619, 62.714286, 69.571429, 70.904762, 86.642857, 100.000000, +62, 0.000000, 11.458333, 17.708333, 29.166667, 37.500000, 58.333333, 58.333333, 72.916667, 79.166667, 79.166667, 100.000000, +63, 0.000000, 10.146104, 31.922244, 44.915501, 48.649267, 58.970196, 64.046370, 71.108059, 78.321678, 85.085748, 100.000000, +64, 0.000000, 22.865222, 39.580884, 46.788587, 49.812741, 55.919137, 69.020390, 74.775975, 78.826531, 84.607150, 100.000000, +65, 0.000000, 24.315476, 33.489583, 41.391369, 47.224702, 58.005952, 60.505952, 72.135417, 77.046131, 85.989583, 100.000000, +66, 0.000000, 11.242884, 33.368121, 53.140417, 62.177419, 64.596774, 67.016129, 69.435484, 80.678368, 88.097723, 100.000000, +67, 0.000000, 6.876457, 41.915102, 61.994438, 65.024741, 74.706580, 82.865088, 89.974645, 92.771848, 95.335951, 100.000000, +68, 0.000000, 36.635101, 49.989398, 53.164630, 59.310059, 63.765956, 69.253906, 75.736401, 79.413467, 87.520011, 100.000000, +69, 0.000000, 50.000000, 50.000000, 50.000000, 50.000000, 50.000000, 50.000000, 50.000000, 50.000000, 50.000000, 100.000000, +70, 0.000000, 20.261438, 38.017429, 63.888889, 63.888889, 71.241830, 75.653595, 77.124183, 89.651416, 89.651416, 100.000000, +71, 0.000000, 21.428571, 42.857143, 42.857143, 57.142857, 57.142857, 92.857143, 92.857143, 92.857143, 92.857143, 100.000000, +72, 0.000000, 30.555556, 33.333333, 47.222222, 47.222222, 55.555556, 63.888889, 72.222222, 83.333333, 94.444444, 100.000000, +73, 0.000000, 34.615385, 50.000000, 63.461538, 75.000000, 84.615385, 92.307692, 92.307692, 98.076923, 98.076923, 100.000000, +74, 0.000000, 12.500000, 25.000000, 37.500000, 37.500000, 50.000000, 62.500000, 62.500000, 62.500000, 75.000000, 100.000000, +75, 0.000000, 27.192982, 36.842105, 50.000000, 54.385965, 63.157895, 76.315789, 76.315789, 85.087719, 94.736842, 100.000000, +76, 0.000000, 0.000000, 0.000000, 0.000000, 5.000000, 5.000000, 15.000000, 15.000000, 50.000000, 90.000000, 100.000000, +77, 0.000000, 22.500000, 45.000000, 45.000000, 55.000000, 62.500000, 70.000000, 70.000000, 72.500000, 95.000000, 100.000000, +78, 0.000000, 27.197680, 43.797828, 51.883564, 59.450793, 66.892944, 70.270055, 78.525215, 87.511513, 90.075615, 100.000000, +79, 0.000000, 17.501848, 35.407922, 47.734022, 50.593965, 57.646313, 61.787242, 68.484531, 77.203611, 83.330034, 100.000000, +80, 0.000000, 18.557309, 26.743724, 43.859372, 50.210340, 55.218337, 60.280340, 65.735773, 69.362308, 70.780620, 100.000000, +82, 0.000000, 38.095238, 64.285714, 69.047619, 69.047619, 69.047619, 69.047619, 69.047619, 78.571429, 80.952381, 100.000000, +83, 0.000000, 23.255814, 39.534884, 62.790698, 69.767442, 79.069767, 79.069767, 88.372093, 88.372093, 95.348837, 100.000000, +84, 0.000000, 0.000000, 0.000000, 4.545455, 13.636364, 13.636364, 13.636364, 22.727273, 59.090909, 86.363636, 100.000000, +85, 0.000000, 49.050179, 52.753883, 56.346476, 56.346476, 56.346476, 61.679809, 65.272401, 67.939068, 73.272401, 100.000000, +86, 0.000000, 22.328932, 44.267707, 58.043217, 60.984394, 61.964786, 70.868347, 75.170068, 83.773509, 92.456983, 100.000000, +87, 0.000000, 5.384615, 5.384615, 40.769231, 40.769231, 43.076923, 43.846154, 43.846154, 46.153846, 46.923077, 100.000000, +88, 0.000000, 13.709677, 24.157706, 36.792115, 47.544803, 51.953405, 55.286738, 55.842294, 56.397849, 64.480287, 100.000000, +89, 0.000000, 32.614608, 48.001998, 56.793207, 59.138084, 62.459762, 65.587191, 69.738595, 79.409479, 85.905761, 100.000000, +90, 0.000000, 73.333333, 80.000000, 82.222222, 84.444444, 86.666667, 88.888889, 91.111111, 93.333333, 95.555556, 100.000000, +91, 0.000000, 12.820513, 20.512821, 38.461538, 43.589744, 53.846154, 56.410256, 61.538462, 82.051282, 84.615385, 100.000000, +92, 0.000000, 75.555556, 77.777778, 82.222222, 84.444444, 88.888889, 88.888889, 93.333333, 97.777778, 97.777778, 100.000000, +93, 0.000000, 23.076923, 23.076923, 23.076923, 36.923077, 40.000000, 49.230769, 50.769231, 60.000000, 81.538462, 100.000000, +94, 0.000000, 16.216216, 32.432432, 47.297297, 60.810811, 78.378378, 78.378378, 87.837838, 90.540541, 95.945946, 100.000000, +95, 0.000000, 85.074627, 86.567164, 86.567164, 88.059701, 92.537313, 92.537313, 92.537313, 92.537313, 92.537313, 100.000000, +96, 0.000000, 17.721519, 29.113924, 43.037975, 56.962025, 69.620253, 84.810127, 89.873418, 89.873418, 96.202532, 100.000000, +97, 0.000000, 39.622642, 60.377358, 62.264151, 64.150943, 64.150943, 66.037736, 66.037736, 90.566038, 94.339623, 100.000000, +98, 0.000000, 2.857143, 17.857143, 19.285714, 19.285714, 64.656085, 81.798942, 81.798942, 83.227513, 93.227513, 100.000000, +100, 0.000000, 24.358974, 35.897436, 37.179487, 46.153846, 46.153846, 92.307692, 96.153846, 96.153846, 96.153846, 100.000000, +102, 0.000000, 0.000000, 0.000000, 77.419355, 93.548387, 95.161290, 95.161290, 95.161290, 95.161290, 98.387097, 100.000000, +103, 0.000000, 53.333333, 60.000000, 62.222222, 62.222222, 62.222222, 64.444444, 73.333333, 77.777778, 80.000000, 100.000000, +105, 0.000000, 80.000000, 91.578947, 93.684211, 93.684211, 98.947368, 98.947368, 98.947368, 98.947368, 98.947368, 100.000000, +108, 0.000000, 29.411765, 41.176471, 48.235294, 52.941176, 61.176471, 75.294118, 84.705882, 95.294118, 95.294118, 100.000000, +109, 0.000000, 29.556919, 54.129406, 65.484064, 66.401573, 71.426825, 75.517734, 77.815714, 79.187768, 86.496010, 100.000000, +110, 0.000000, 16.666667, 28.888889, 44.444444, 60.000000, 75.555556, 87.777778, 94.444444, 97.777778, 97.777778, 100.000000, +111, 0.000000, 1.111111, 36.666667, 36.666667, 36.666667, 60.000000, 60.000000, 64.444444, 68.888889, 83.333333, 100.000000, +112, 0.000000, 15.686275, 19.607843, 21.568627, 23.529412, 58.823529, 60.784314, 70.588235, 80.392157, 84.313725, 100.000000, +113, 0.000000, 58.974359, 58.974359, 61.538462, 61.538462, 61.538462, 61.538462, 61.538462, 61.538462, 61.538462, 100.000000, +115, 0.000000, 83.516484, 91.208791, 91.208791, 91.208791, 91.208791, 91.208791, 91.208791, 98.901099, 98.901099, 100.000000, +118, 0.000000, 26.666667, 30.666667, 40.000000, 46.666667, 52.000000, 65.333333, 74.666667, 88.000000, 92.000000, 100.000000, +119, 0.000000, 14.285714, 19.642857, 30.357143, 42.857143, 58.928571, 75.000000, 78.571429, 85.714286, 92.857143, 100.000000, +120, 0.000000, 59.073359, 85.859073, 94.184363, 95.077220, 95.077220, 95.970077, 95.970077, 95.970077, 95.970077, 100.000000, +121, 0.000000, 0.000000, 0.000000, 38.461538, 38.461538, 38.461538, 43.076923, 69.230769, 83.076923, 90.769231, 100.000000, +122, 0.000000, 72.222222, 80.555556, 80.555556, 80.555556, 83.333333, 83.333333, 94.444444, 94.444444, 94.444444, 100.000000, +123, 0.000000, 22.891566, 22.891566, 22.891566, 22.891566, 28.915663, 40.963855, 56.626506, 71.084337, 89.156627, 100.000000, +126, 0.000000, 0.000000, 57.777778, 60.000000, 61.111111, 61.111111, 61.111111, 65.555556, 84.444444, 90.000000, 100.000000, +127, 0.000000, 59.210526, 75.000000, 75.000000, 75.000000, 76.315789, 76.315789, 76.315789, 82.894737, 93.421053, 100.000000, +129, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 42.857143, 57.142857, 85.714286, 85.714286, 100.000000, +130, 0.000000, 39.506173, 71.604938, 72.839506, 72.839506, 72.839506, 74.074074, 74.074074, 82.716049, 92.592593, 100.000000, +134, 0.000000, 43.333333, 43.333333, 45.555556, 61.111111, 68.888889, 68.888889, 68.888889, 77.777778, 94.444444, 100.000000, +137, 0.000000, 59.090909, 64.772727, 64.772727, 64.772727, 68.181818, 68.181818, 70.454545, 71.590909, 84.090909, 100.000000, +140, 0.000000, 8.045977, 12.643678, 20.689655, 45.977011, 57.471264, 74.712644, 77.011494, 79.310345, 85.057471, 100.000000, +141, 0.000000, 83.950617, 86.419753, 87.654321, 93.827160, 93.827160, 93.827160, 93.827160, 93.827160, 93.827160, 100.000000, +143, 0.000000, 23.664122, 24.427481, 25.190840, 25.190840, 25.190840, 25.190840, 78.625954, 99.236641, 99.236641, 100.000000, +144, 0.000000, 35.294118, 45.098039, 56.862745, 64.705882, 90.196078, 92.156863, 92.156863, 92.156863, 94.117647, 100.000000, +147, 0.000000, 19.230769, 26.923077, 40.384615, 50.000000, 61.538462, 71.153846, 75.000000, 84.615385, 84.615385, 100.000000, +149, 0.000000, 49.152542, 74.576271, 74.576271, 76.271186, 83.050847, 84.745763, 84.745763, 86.440678, 89.830508, 100.000000, +150, 0.000000, 74.647887, 78.873239, 85.915493, 85.915493, 85.915493, 85.915493, 85.915493, 85.915493, 88.732394, 100.000000, +154, 0.000000, 34.876543, 47.222222, 47.685185, 58.333333, 65.277778, 70.061728, 72.376543, 77.006173, 77.469136, 100.000000, +157, 0.000000, 93.965517, 93.965517, 93.965517, 93.965517, 93.965517, 93.965517, 93.965517, 93.965517, 93.965517, 100.000000, +158, 0.000000, 24.576271, 27.966102, 33.898305, 38.983051, 50.000000, 63.559322, 75.423729, 85.593220, 90.677966, 100.000000, +159, 0.000000, 77.419355, 84.946237, 91.397849, 92.473118, 92.473118, 92.473118, 92.473118, 96.774194, 97.849462, 100.000000, +161, 0.000000, 5.154639, 59.793814, 60.824742, 68.041237, 69.072165, 72.164948, 72.164948, 72.164948, 72.164948, 100.000000, +164, 0.000000, 26.804124, 42.268041, 61.855670, 65.979381, 72.164948, 78.350515, 81.443299, 89.690722, 92.783505, 100.000000, +165, 0.000000, 14.569536, 27.152318, 40.397351, 55.629139, 69.536424, 84.768212, 98.675497, 98.675497, 99.337748, 100.000000, +167, 0.000000, 33.333333, 63.768116, 63.768116, 63.768116, 66.666667, 66.666667, 66.666667, 66.666667, 79.710145, 100.000000, +169, 0.000000, 30.303030, 31.818182, 48.484848, 60.606061, 69.696970, 74.242424, 74.242424, 74.242424, 74.242424, 100.000000, +172, 0.000000, 16.091954, 21.839080, 33.333333, 37.931034, 42.528736, 43.678161, 44.827586, 50.574713, 54.022989, 100.000000, +173, 0.000000, 52.941176, 52.941176, 71.568627, 85.294118, 85.294118, 94.117647, 94.117647, 98.039216, 99.019608, 100.000000, +179, 0.000000, 22.352941, 36.470588, 40.000000, 56.470588, 70.588235, 84.705882, 84.705882, 88.235294, 92.941176, 100.000000, +184, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 55.828221, 56.441718, 56.441718, 56.441718, 85.276074, 100.000000, +187, 0.000000, 38.805970, 58.955224, 70.895522, 73.880597, 75.373134, 75.373134, 77.611940, 83.582090, 97.761194, 100.000000, +194, 0.000000, 20.000000, 31.034483, 42.758621, 53.793103, 53.793103, 66.896552, 79.310345, 82.758621, 93.103448, 100.000000, +197, 0.000000, 25.675676, 31.756757, 31.756757, 35.135135, 55.405405, 56.081081, 67.567568, 76.351351, 91.216216, 100.000000, +199, 0.000000, 29.710145, 33.333333, 33.333333, 34.782609, 60.869565, 67.391304, 73.913043, 83.333333, 86.231884, 100.000000, +224, 0.000000, 77.941176, 77.941176, 77.941176, 77.941176, 77.941176, 88.725490, 88.725490, 88.725490, 91.176471, 100.000000, +236, 0.000000, 69.142857, 76.571429, 81.142857, 87.428571, 88.571429, 91.428571, 93.714286, 97.142857, 98.285714, 100.000000, +261, 0.000000, 98.744770, 98.744770, 98.744770, 98.744770, 98.744770, 98.744770, 98.744770, 98.744770, 98.744770, 100.000000, +264, 0.000000, 2.272727, 2.272727, 38.636364, 43.181818, 54.545455, 56.818182, 61.363636, 61.363636, 72.727273, 100.000000, +269, 0.000000, 87.214612, 93.607306, 94.520548, 94.977169, 94.977169, 95.433790, 95.433790, 96.347032, 97.260274, 100.000000, +273, 0.000000, 10.612245, 20.408163, 28.979592, 38.775510, 48.979592, 59.591837, 69.795918, 79.183673, 89.387755, 100.000000, +275, 0.000000, 83.522727, 85.795455, 88.068182, 88.636364, 91.477273, 92.613636, 96.022727, 96.022727, 96.022727, 100.000000, +278, 0.000000, 11.203320, 22.821577, 30.290456, 36.099585, 45.228216, 56.016598, 67.219917, 78.838174, 89.626556, 100.000000, +282, 0.000000, 34.210526, 43.684211, 51.578947, 61.052632, 67.894737, 72.631579, 82.105263, 87.368421, 91.578947, 100.000000, +289, 0.000000, 53.521127, 54.225352, 57.746479, 62.676056, 76.760563, 82.394366, 86.619718, 91.549296, 96.478873, 100.000000, +290, 0.000000, 35.025381, 41.116751, 50.253807, 52.284264, 55.837563, 58.375635, 58.883249, 81.725888, 89.340102, 100.000000, +296, 0.000000, 45.833333, 76.893939, 78.787879, 78.787879, 78.787879, 81.818182, 81.818182, 93.181818, 98.106061, 100.000000, +308, 0.000000, 70.000000, 88.636364, 88.636364, 90.909091, 90.909091, 93.181818, 93.181818, 95.454545, 95.454545, 100.000000, +309, 0.000000, 90.877193, 90.877193, 90.877193, 90.877193, 90.877193, 90.877193, 90.877193, 95.087719, 96.491228, 100.000000, +315, 0.000000, 12.935323, 22.388060, 32.338308, 48.756219, 58.706468, 75.621891, 85.572139, 88.557214, 94.029851, 100.000000, +323, 0.000000, 0.390625, 97.656250, 97.656250, 97.656250, 97.656250, 97.656250, 97.656250, 98.828125, 99.218750, 100.000000, +342, 0.000000, 91.724138, 96.551724, 96.896552, 97.241379, 97.586207, 98.275862, 98.620690, 98.965517, 98.965517, 100.000000, +354, 0.000000, 32.534247, 33.904110, 53.424658, 54.109589, 71.917808, 72.945205, 97.945205, 97.945205, 97.945205, 100.000000, +355, 0.000000, 77.165354, 77.165354, 98.818898, 99.212598, 99.212598, 99.212598, 99.212598, 99.212598, 99.212598, 100.000000, +364, 0.000000, 60.606061, 67.424242, 76.515152, 81.060606, 87.121212, 88.636364, 92.424242, 92.424242, 94.696970, 100.000000, +365, 0.000000, 21.111111, 66.666667, 66.666667, 66.666667, 68.333333, 72.777778, 78.333333, 80.555556, 81.111111, 100.000000, diff --git a/IncrementalMinimization/src/DisjointSets.java b/IncrementalMinimization/src/DisjointSets.java index dac28fd2..827e7a39 100644 --- a/IncrementalMinimization/src/DisjointSets.java +++ b/IncrementalMinimization/src/DisjointSets.java @@ -14,20 +14,45 @@ public class DisjointSets private HashMap parentMap; private HashMap rankMap; + private int size; public DisjointSets() { parentMap = new HashMap(); rankMap = new HashMap(); + size = 0; } public DisjointSets(Collection identifiers) { parentMap = new HashMap(); rankMap = new HashMap(); + size=0; for(E identifier : identifiers) { make(identifier); + size++; + } + } + + public DisjointSets(DisjointSets disjointSets) + { + parentMap = new HashMap(); + rankMap = new HashMap(); + size=0; + HashMap> sets = disjointSets.getSets(); + for (E iden : sets.keySet()) + { + make(iden); + HashSet set = sets.get(iden); + for (E elem : set) + { + if (elem != iden) + { + make(elem); + } + union(elem, iden); + } } } @@ -37,6 +62,7 @@ public void make(E identifier) throws IllegalArgumentException { parentMap.put(identifier, null); rankMap.put(identifier, 1); + size++; } else { @@ -97,6 +123,7 @@ else if (rank1 > rank2) union_iden = iden2; } } + size--; return union_iden; } @@ -120,6 +147,11 @@ public HashMap> getSets() return sets; } + public int size() + { + return size; + } + public String toString() { return getSets().toString(); diff --git a/IncrementalMinimization/src/IncrementalMinimization.java b/IncrementalMinimization/src/IncrementalMinimization.java index b9380072..8ba3b895 100644 --- a/IncrementalMinimization/src/IncrementalMinimization.java +++ b/IncrementalMinimization/src/IncrementalMinimization.java @@ -234,7 +234,7 @@ public static SFA incrementalMinimize(SFA aut, BooleanAlgebra min = new IncrementalMinimization(aut, ba); - return min.minimize(budget, upfront); + return min.minimize(budget, upfront, false); } catch(TimeBudgetExceeded e) { @@ -259,6 +259,9 @@ public static SFA incrementalMinimize(SFA aut, BooleanAlgebra> neq; private LinkedHashMap distanceToFinalMap; private StateComparator stateComp; + private Long startTime; + private LinkedHashMap record; //maps time stamps to number of states + private Long singularRecord = null; public IncrementalMinimization(SFA aut, BooleanAlgebra ba) throws TimeoutException { @@ -272,6 +275,8 @@ public IncrementalMinimization(SFA aut, BooleanAlgebra ba) throws Time this.neq = new HashSet>(num_pairs, 0.9f); //won't exceed initial capacity this.distanceToFinalMap = generateDistanceToFinalMap(); this.stateComp = new StateComparator(); + this.startTime = null; + this.record = new LinkedHashMap(); } private LinkedHashMap generateDistanceToFinalMap() @@ -351,13 +356,14 @@ private boolean isSinkState(Integer p) private boolean isKnownNotEqual(Integer p, Integer q) { - if (neq.contains(normalize(p,q))) + List normalizedPair = normalize(p,q); + if (neq.contains(normalizedPair)) { return true; } else if (!distanceToFinalMap.get(p).equals(distanceToFinalMap.get(q))) { - neq.add(normalize(p,q)); + neq.add(normalizedPair); return true; } else @@ -389,6 +395,12 @@ private SFA mergeSFAStates(DisjointSets equivClasses) throws Timeo return minAut; } + private void updateRecord(DisjointSets equivClasses) + { + Long time = System.nanoTime(); + record.put(time, equivClasses.getSets().size()); + } + private void timeCheck(long endTime, DisjointSets equivClasses) throws TimeoutException { if(System.nanoTime() > endTime) @@ -406,16 +418,21 @@ private void timeCheck(long endTime, DisjointSets equivClasses) throws } } - public SFA minimize(long budget, boolean upfront) + public SFA minimize(long budget, boolean upfront, boolean recordMinimization) throws TimeoutException { - long endTime = System.nanoTime() + budget; + this.startTime = System.nanoTime(); + long endTime = startTime + budget; if (endTime < 0) //indicates overflow { endTime = Long.MAX_VALUE; } if(aut.isEmpty()) { + if(recordMinimization) + { + this.singularRecord = System.nanoTime() - startTime; + } return SFA.getEmptySFA(ba); } ArrayList

upfront_minterms = null; @@ -477,8 +494,11 @@ else if(equivClasses.find(p) == equivClasses.find(q)) equivClasses.union(equivPair.get(0), equivPair.get(1)); //equivClasses.union(equivPair.get(0), equivPair.get(1)); } + if(recordMinimization) + { + updateRecord(equivClasses); + } timeCheck(endTime, equivClasses); - //after equiv merging for soft time budget? } else { @@ -495,6 +515,20 @@ else if(equivClasses.find(p) == equivClasses.find(q)) return mergeSFAStates(equivClasses); } - + public LinkedHashMap getRecord() throws TimeoutException + { + LinkedHashMap actualRecord = new LinkedHashMap(); + actualRecord.put(this.startTime, aut.stateCount()); + if (singularRecord != null) + { + actualRecord.put(singularRecord, 1); + return actualRecord; + } + for(Long time : record.keySet()) + { + actualRecord.put(time, record.get(time)); + } + return actualRecord; + } } diff --git a/IncrementalMinimization/src/TestDisjointSets.java b/IncrementalMinimization/src/TestDisjointSets.java index 4a01b073..7ae1f9e4 100644 --- a/IncrementalMinimization/src/TestDisjointSets.java +++ b/IncrementalMinimization/src/TestDisjointSets.java @@ -35,10 +35,40 @@ public void testUnion() Assert.assertEquals(sets.find(1), sets.find(2)); Assert.assertEquals(new Integer(1),sets.find(1)); Assert.assertEquals(new Integer(1),sets.find(2)); + sets.union(4, 5); + sets.union(2, 4); + Assert.assertEquals(sets.find(1), sets.find(5)); + Assert.assertFalse(sets.find(1).equals(sets.find(7))); + } + + @Test + public void testSize() + { + initialize(); + Assert.assertEquals(10, sets.size()); + sets.union(1, 2); + Assert.assertEquals(9, sets.size()); + sets.union(4, 5); + sets.union(2, 4); + Assert.assertEquals(7, sets.size()); + } + + @Test + public void testCopy() + { + initialize(); + sets.union(1, 2); sets.union(3, 4); - sets.union(2, 3); - Assert.assertEquals(sets.find(1), sets.find(4)); - Assert.assertFalse(sets.find(1).equals(sets.find(5))); + sets.union(5, 4); + DisjointSets newSets = new DisjointSets(sets); + Integer oneIden = newSets.find(1); + Assert.assertTrue(oneIden == 2 || oneIden == 1); + Integer fiveIden = newSets.find(5); + Assert.assertTrue(fiveIden == 3 || fiveIden == 4 || fiveIden == 5); + for (Integer i = 6; i < 10; i++) + { + Assert.assertEquals(sets.find(i), newSets.find(i)); + } } } diff --git a/IncrementalMinimization/src/TestIncrementalMinimization.java b/IncrementalMinimization/src/TestIncrementalMinimization.java index 093e990c..3788cba9 100644 --- a/IncrementalMinimization/src/TestIncrementalMinimization.java +++ b/IncrementalMinimization/src/TestIncrementalMinimization.java @@ -11,8 +11,14 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.LinkedList; +import java.util.Map; +import java.util.Map.Entry; +import java.util.TreeMap; import org.junit.Assert; import org.junit.Before; @@ -130,7 +136,7 @@ public void testCharPred() throws TimeoutException Assert.assertTrue(incrMinAut.stateCount() <= stdMinAut.stateCount()); } - @Test + //@Test public void testCompare() throws TimeoutException, IOException { System.out.println("========================"); @@ -138,7 +144,7 @@ public void testCompare() throws TimeoutException, IOException System.out.println("========================"); //import list of regex. Heavily borrowed code from symbolic automata library - FileReader regexFile = new FileReader("src/pattern@75.txt"); + FileReader regexFile = new FileReader("src/regexlib-SFA.txt"); BufferedReader read = new BufferedReader(regexFile); ArrayList regexList = new ArrayList(); String line; @@ -280,7 +286,7 @@ public void testCompare() throws TimeoutException, IOException writer.close(); } - @Test + //@Test public void testBudget() throws TimeoutException, IOException { //Similar to Regex test, but incremental minimization only given as long as @@ -290,7 +296,7 @@ public void testBudget() throws TimeoutException, IOException System.out.println("========================="); //import list of regex - FileReader regexFile = new FileReader("src/pattern@75.txt"); + FileReader regexFile = new FileReader("src/regexlib-SFA.txt"); BufferedReader read = new BufferedReader(regexFile); ArrayList regexList = new ArrayList(); String line; @@ -305,7 +311,6 @@ public void testBudget() throws TimeoutException, IOException } //regex converted to SFAs and minimized UnaryCharIntervalSolver ba = new UnaryCharIntervalSolver(); - //System.out.println(regexList.size()); ArrayList messageList = new ArrayList(); long timeout = 3600000; //determinization timeout = 1 hour for(String regex : regexList) @@ -380,7 +385,7 @@ public void testBudget() throws TimeoutException, IOException } else { - incrPercentMinimized = ((double) initialCount - incrCount)/(initialCount - finalCount); + incrPercentMinimized = ((double) initialCount - incrCount)/((double) initialCount - finalCount); } String incrPercent = Double.toString(incrPercentMinimized); double upfPercentMinimized; @@ -390,7 +395,7 @@ public void testBudget() throws TimeoutException, IOException } else { - upfPercentMinimized = ((double) initialCount - upfrontCount)/(initialCount - finalCount); + upfPercentMinimized = ((double) initialCount - upfrontCount)/((double)initialCount - finalCount); } String upfPercent = Double.toString(upfPercentMinimized); @@ -404,12 +409,202 @@ public void testBudget() throws TimeoutException, IOException FileOutputStream file = new FileOutputStream("budget_test.txt"); Writer writer = new BufferedWriter(new OutputStreamWriter(file)); writer.write("initial states, final states, incremental states, upfront states" + - "incremental percent, upfront percent"); + "incremental percent, upfront percent" + "\n"); for (String msg : messageList) { writer.write(msg + "\n"); } writer.close(); } + + private Double getTimePercentage(Double currentTime, Double startTime, Double finishTime) + { + Assert.assertTrue(finishTime >= currentTime); + Double relativeTime = ((currentTime - startTime)/(finishTime - startTime))*100.0; + Assert.assertTrue(relativeTime >= 0); + Assert.assertTrue(relativeTime <= 100); + return relativeTime; + } + + private Double getMinimizedPercentage(Double curCount, Double initialCount, Double finalCount) + { + Assert.assertTrue(curCount <= initialCount); + Assert.assertTrue(finalCount <= curCount); + Double percentage = ((initialCount - curCount)/(initialCount - finalCount))*100.0; + Assert.assertTrue(percentage >= 0); + Assert.assertTrue(percentage <= 100); + return percentage; + } + + @Test + public void testRecord() throws IOException + { + //TODO: cleanup + document + System.out.println("===================="); + System.out.println("STARTING RECORD TEST"); + System.out.println("===================="); + + //import list of regex + FileReader regexFile = new FileReader("src/regexlib-SFA.txt"); + BufferedReader read = new BufferedReader(regexFile); + ArrayList regexList = new ArrayList(); + String line; + while(true) + { + line = read.readLine(); + if (line == null) + { + break; + } + regexList.add(line); + } + //regex converted to SFAs and minimized + UnaryCharIntervalSolver ba = new UnaryCharIntervalSolver(); + ArrayList messageList = new ArrayList(); + long timeout = 3600000; //determinization timeout = 1 hour + + Integer[] timeMilestones = {0,10,20,30,40,50,60,70,80,90,100}; + TreeMap> fullMinimizationMap = new TreeMap>(); + HashMap repeatCount = new HashMap(); + for(String regex : regexList) + { + System.out.println("Start"); + SFA aut = (new SFAprovider(regex, ba)).getSFA(); + try + { + aut = aut.determinize(ba, timeout); + aut = aut.mkTotal(ba); + } + catch(TimeoutException e) + { + continue; + } + catch(OutOfMemoryError e) + { + System.gc(); + continue; + } + if(aut.stateCount() > 400 || aut.stateCount() <= 1) + { + continue; + } + System.out.println("Determinized."); + + SFA incrMinAut; + LinkedHashMap record; + try + { + IncrementalMinimization recordMin = + new IncrementalMinimization(aut, ba); + incrMinAut = recordMin.minimize(Long.MAX_VALUE, false, true); + record = recordMin.getRecord(); + } + catch(TimeoutException e) + { + continue; + } + catch(OutOfMemoryError e) + { + continue; + } + System.out.println("Minimized."); + if(record.size()<=1) + { + continue; + } + Iterator timeIter = record.keySet().iterator(); + Long startTime = timeIter.next(); + Long finalTime = startTime; + while (timeIter.hasNext()) + { + finalTime = timeIter.next(); + } + Integer finalStateCount = record.get(finalTime); + Assert.assertEquals(incrMinAut.stateCount(), finalStateCount); + Integer initialStateCount = aut.stateCount(); + if(finalStateCount == initialStateCount) + { + continue; + } + HashMap minimizationTimes = new LinkedHashMap(); + minimizationTimes.put(0, 0.0); + int milestoneIndex = 0; + System.out.println(record); + for (Long time : record.keySet()) + { + Double timePercent = getTimePercentage((double)time, (double)startTime, (double)finalTime); + Integer stateCount = record.get(time); + Double percentMinimized = getMinimizedPercentage((double)stateCount, (double) initialStateCount, (double) finalStateCount); + System.out.println(timePercent); + System.out.println(percentMinimized); + Integer currentMilestone = timeMilestones[milestoneIndex]; + if (timePercent <= currentMilestone) + { + if (minimizationTimes.containsKey(currentMilestone)) + { + Assert.assertTrue(percentMinimized >= minimizationTimes.get(currentMilestone)); + } + minimizationTimes.put(currentMilestone, percentMinimized); + } + else + { + while(timePercent > currentMilestone) + { + Double prevMilestonePercent = minimizationTimes.get(currentMilestone); + milestoneIndex++; + currentMilestone = timeMilestones[milestoneIndex]; + minimizationTimes.put(currentMilestone, prevMilestonePercent); + Assert.assertTrue(prevMilestonePercent <= percentMinimized); + } + minimizationTimes.put(currentMilestone, percentMinimized); + } + } + System.out.println(minimizationTimes); + if (!fullMinimizationMap.containsKey(initialStateCount)) + { + repeatCount.put(initialStateCount, 1.0); + fullMinimizationMap.put(initialStateCount, minimizationTimes); + } + else + { + Double count = repeatCount.get(initialStateCount); + HashMap avgMinTimes = fullMinimizationMap.get(initialStateCount); + System.out.println(minimizationTimes); + for(Integer milestone : avgMinTimes.keySet()) + { + Double curMilestonePercent = minimizationTimes.get(milestone); + Double avgMilestonePercent = avgMinTimes.get(milestone); + Double newAvg = avgMilestonePercent + (curMilestonePercent - avgMilestonePercent)/count; + avgMinTimes.put(milestone, newAvg); + } + repeatCount.put(initialStateCount, count+1); + } + } + FileOutputStream file = new FileOutputStream("record_test.txt"); + Writer writer = new BufferedWriter(new OutputStreamWriter(file)); + String titleRow = "initial states, "; + for (Integer milestone : timeMilestones) + { + titleRow += String.format("%d, ", milestone); + } + titleRow += "\n"; + writer.write(titleRow); + System.out.println(fullMinimizationMap.keySet()); + System.out.println(fullMinimizationMap.entrySet()); + for(Integer stateCount : fullMinimizationMap.keySet()) + { + HashMap minTimes = fullMinimizationMap.get(stateCount); + String row = String.format("%d, ", stateCount); + for (Integer milestone : timeMilestones) + { + Double percentMin = minTimes.get(milestone); + row += String.format("%f, ", percentMin); + } + row += "\n"; + System.out.print(row); + writer.write(row); + } + writer.close(); + } }