espitau 8 éve
szülő
commit
a49b6117c2
5 módosított fájl, 275 hozzáadás és 7 törlés
  1. 15 7
      src/main.cpp
  2. 100 0
      src/random_search
  3. 54 0
      src/wrapper_iter.py
  4. 54 0
      src/wrapper_points.py
  5. 52 0
      src/wrapper_temp.py

+ 15 - 7
src/main.cpp

@@ -10,7 +10,7 @@ int main(int argc, char **argv) {
   fprintf(stderr, "seed: %d\n", seed);
   srand(seed);
 
-  int npoints = 100, dim = 2, iterations = atoi(argv[1]);
+  int npoints = atoi(argv[2]), dim = 2, iterations = atoi(argv[3]);
   int p[] = {7,13, 29,3, 19};
   assert(sizeof(p)/sizeof(int) >= (unsigned int)dim);
 
@@ -19,12 +19,20 @@ int main(int argc, char **argv) {
     fprintf(stderr, "%d%s", p[i], (i==dim-1) ? "\n" : ", ");
   fprintf(stderr, "iterations = %d\n\n", iterations);
 
-  // random_search rs(dim, npoints, p);
-  // rs.run(iterations);
-  // sa_local_search s(dim, npoints, p, 0.992, 0.01/dim);
-  // s.run(iterations);
-  genetic_search s(dim, npoints, p, 10, 10, 0.5);
-  s.run(iterations);
+  
+  random_search rs(dim, npoints, p);
+  sa_local_search ls(dim, npoints, p, 0.992, 0.01/dim);
+  genetic_search gs(dim, npoints, p, 10, 10, 0.5);
+  switch (atoi(argv[1])){
+    case 1:
+      rs.run(iterations); break;
+    case 2:
+      ls.run(iterations); break;
+    case 3:
+      gs.run(iterations); break;
+    default:
+      break;
+  }
 
   return EXIT_SUCCESS;
 }

+ 100 - 0
src/random_search

@@ -0,0 +1,100 @@
+0.857143	0.384615
+0.571429	0.769231
+0.142857	0.615385
+0.285714	0.846154
+0.714286	0.153846
+0.428571	0.307692
+0.122449	0.230769
+0.979592	0.923077
+0.693878	0.076923
+0.265306	0.538462
+0.408163	0.461538
+0.836735	0.692308
+0.551020	0.029586
+0.081633	0.414201
+0.938776	0.798817
+0.653061	0.644970
+0.224490	0.875740
+0.367347	0.183432
+0.795918	0.337278
+0.510204	0.260355
+0.020408	0.952663
+0.877551	0.106509
+0.591837	0.568047
+0.163265	0.491124
+0.306122	0.721893
+0.734694	0.059172
+0.448980	0.443787
+0.040816	0.828402
+0.897959	0.674556
+0.612245	0.905325
+0.183673	0.213018
+0.326531	0.366864
+0.755102	0.289941
+0.469388	0.982249
+0.102041	0.136095
+0.959184	0.597633
+0.673469	0.520710
+0.244898	0.751479
+0.387755	0.047337
+0.816327	0.431953
+0.530612	0.816568
+0.061224	0.662722
+0.918367	0.893491
+0.632653	0.201183
+0.204082	0.355030
+0.346939	0.278107
+0.775510	0.970414
+0.489796	0.124260
+0.017493	0.585799
+0.874636	0.508876
+0.588921	0.739645
+0.160350	0.065089
+0.303207	0.449704
+0.731778	0.834320
+0.446064	0.680473
+0.139942	0.911243
+0.997085	0.218935
+0.711370	0.372781
+0.282799	0.295858
+0.425656	0.988166
+0.854227	0.142012
+0.568513	0.603550
+0.099125	0.526627
+0.956268	0.757396
+0.670554	0.011834
+0.241983	0.396450
+0.384840	0.781065
+0.813411	0.627219
+0.527697	0.857988
+0.037901	0.165680
+0.895044	0.319527
+0.609329	0.242604
+0.180758	0.934911
+0.323615	0.088757
+0.752187	0.550296
+0.466472	0.473373
+0.058309	0.704142
+0.915452	0.023669
+0.629738	0.408284
+0.201166	0.792899
+0.344023	0.639053
+0.772595	0.869822
+0.486880	0.177515
+0.119534	0.331361
+0.976676	0.254438
+0.690962	0.946746
+0.262391	0.100592
+0.405248	0.562130
+0.833819	0.485207
+0.548105	0.715976
+0.078717	0.017751
+0.935860	0.402367
+0.650146	0.786982
+0.221574	0.633136
+0.364431	0.863905
+0.793003	0.171598
+0.507289	0.325444
+0.011662	0.248521
+0.868805	0.940828
+0.583090	0.094675

+ 54 - 0
src/wrapper_iter.py

@@ -0,0 +1,54 @@
+import os 
+import matplotlib.pyplot as plt
+results = {}
+
+def errorfill(x, y, yerr, color=None, alpha_fill=0.3, ax=None):
+    ax = ax if ax is not None else plt.gca()
+    if color is None:
+        color = ax._get_lines.color_cycle.next()
+    ymin, ymax = yerr
+    ax.plot(x, y, color=color)
+    ax.fill_between(x, ymax, ymin, color=color, alpha=alpha_fill)
+
+
+def generate(l, la = 0.992, init = 0.01, it = 1000):
+    axis = []
+    resu = []
+    resu_bars_mini = []
+    resu_bars_maxi = []
+    NB_IT = 15 
+    for i in range(10, 1000, 25):
+        results[i] = []
+        axis.append(i)
+        mini  =10
+        maxi = 0
+        for j in range(NB_IT):
+            os.system('./main '+str(l)+" "+str(i)+ " "+str(it)+ " "+ str(la)+ " "+ str(init)+ " > res")
+            r = open("res", "r")
+            res = float(r.readline())
+            mini = min(res, mini)
+            maxi = max(res, maxi)
+            results[i].append(res)
+        resu.append(sum(results[i])/NB_IT)
+        resu_bars_mini.append(mini)
+        resu_bars_maxi.append(maxi)
+
+    resu_bars = [resu_bars_mini, resu_bars_maxi]
+    print results
+    print axis
+    print resu
+    print resu_bars
+
+    #plt.errorbar(axis, resu, resu_bars, fmt='o')
+
+    errorfill(axis, resu, resu_bars)
+
+
+generate(1, 0.99, 0.1, 100)
+generate(1, 0.99, 0.1, 300)
+generate(1, 0.99, 0.1, 600)
+generate(1, 0.99, 0.1, 1000)
+generate(1, 0.99, 0.1, 1300)
+generate(1, 0.99, 0.1, 1600)
+generate(1, 0.99, 0.1, 2000)
+plt.show()

+ 54 - 0
src/wrapper_points.py

@@ -0,0 +1,54 @@
+import os 
+import matplotlib.pyplot as plt
+results = {}
+
+def errorfill(x, y, yerr, color=None, alpha_fill=0.3, ax=None):
+    ax = ax if ax is not None else plt.gca()
+    if color is None:
+        color = ax._get_lines.color_cycle.next()
+    ymin, ymax = yerr
+    ax.plot(x, y, color=color)
+    ax.fill_between(x, ymax, ymin, color=color, alpha=alpha_fill)
+
+
+def generate(l, la = 0.992, init = 0.01, it = 1000):
+    axis = []
+    resu = []
+    resu_bars_mini = []
+    resu_bars_maxi = []
+    NB_IT = 15 
+    for i in range(10, 1000, 25):
+        results[i] = []
+        axis.append(i)
+        mini  =10
+        maxi = 0
+        for j in range(NB_IT):
+            os.system('./main '+str(l)+" "+str(i)+ " "+str(it)+ " "+ str(la)+ " "+ str(init)+ " > res")
+            r = open("res", "r")
+            res = float(r.readline())
+            mini = min(res, mini)
+            maxi = max(res, maxi)
+            results[i].append(res)
+        resu.append(sum(results[i])/NB_IT)
+        resu_bars_mini.append(mini)
+        resu_bars_maxi.append(maxi)
+
+    resu_bars = [resu_bars_mini, resu_bars_maxi]
+    print results
+    print axis
+    print resu
+    print resu_bars
+
+    #plt.errorbar(axis, resu, resu_bars, fmt='o')
+
+    errorfill(axis, resu, resu_bars)
+
+
+generate(1, 0.99, 0.1, 100)
+generate(1, 0.99, 0.1, 300)
+generate(1, 0.99, 0.1, 600)
+generate(1, 0.99, 0.1, 1000)
+generate(1, 0.99, 0.1, 1300)
+generate(1, 0.99, 0.1, 1600)
+generate(1, 0.99, 0.1, 2000)
+plt.show()

+ 52 - 0
src/wrapper_temp.py

@@ -0,0 +1,52 @@
+import os 
+import matplotlib.pyplot as plt
+results = {}
+
+def errorfill(x, y, yerr, color=None, alpha_fill=0.3, ax=None):
+    ax = ax if ax is not None else plt.gca()
+    if color is None:
+        color = ax._get_lines.color_cycle.next()
+    ymin, ymax = yerr
+    ax.plot(x, y, color=color)
+    ax.fill_between(x, ymax, ymin, color=color, alpha=alpha_fill)
+
+
+def generate(l, la = 0.992, init = 0.01):
+    axis = []
+    resu = []
+    resu_bars_mini = []
+    resu_bars_maxi = []
+    NB_IT = 15 
+    for i in range(10, 1000, 25):
+        results[i] = []
+        axis.append(i)
+        mini  =10
+        maxi = 0
+        for j in range(NB_IT):
+            os.system('./main '+str(l)+" "+str(i)+ " 1000 "+ str(la)+ " "+ str(init)+ " > res")
+            r = open("res", "r")
+            res = float(r.readline())
+            mini = min(res, mini)
+            maxi = max(res, maxi)
+            results[i].append(res)
+        resu.append(sum(results[i])/NB_IT)
+        resu_bars_mini.append(mini)
+        resu_bars_maxi.append(maxi)
+
+    resu_bars = [resu_bars_mini, resu_bars_maxi]
+    print results
+    print axis
+    print resu
+    print resu_bars
+
+    #plt.errorbar(axis, resu, resu_bars, fmt='o')
+
+    errorfill(axis, resu, resu_bars)
+
+
+generate(2, 0.99, 0.1)
+generate(2, 0.99, 0.01)
+generate(2, 0.99, 0.001)
+generate(2, 0.99, 0.0001)
+generate(2, 0.99, 0.00001)
+plt.show()