This is a minimal usage example of Revolver.
The problem statement is very simple and straightforward:
Given all bit strings of length between 10 and 100 characters, find a string which maximizes the number of ones.
Clearly, the solution is a string of 100 ones. This example shows, how evolutionary algorithms can be used to iteratively arrive at this conclusion.
The example code was created by Petr Mánek, Charles University, 2016.
This example is distributed under the MIT License.
- Revolver
- Xcode 7.3
- Mac OS 10.11 El Capitan (perhaps this example can be ported to Linux?)
- Build and run the project in Xcode. (don't use xcodeproj in this directory, use xcworkspace in the parent directory)
- Hit the Run algorithm button.
- Observe the output generated in the log.
- Play around with
Configuration.swift
to change the weights and values of things and observe how the output changes. - Change parameters of the algorithm in
ViewController.swift
and observe how the output changes.
When running this example, you should see similar output (provided that you don't change the seed or the configuration).
---
Run started.
Generation 1: best: 0.581818181818182, mean: 0.284454545454546
Generation 2: best: 0.6, mean: 0.282909090909091
Generation 3: best: 0.6, mean: 0.290090909090909
Generation 4: best: 0.6, mean: 0.303181818181818
Generation 5: best: 0.6, mean: 0.312618724559023
Generation 6: best: 0.618181818181818, mean: 0.336363636363637
Generation 7: best: 0.618181818181818, mean: 0.360090909090909
Generation 8: best: 0.618181818181818, mean: 0.369363636363637
Generation 9: best: 0.618181818181818, mean: 0.380909090909091
Generation 10: best: 0.618181818181818, mean: 0.383363636363637
Generation 11: best: 0.636363636363636, mean: 0.399004975124378
Generation 12: best: 0.654545454545455, mean: 0.416282225237449
Generation 13: best: 0.672727272727273, mean: 0.439
Generation 14: best: 0.672727272727273, mean: 0.438818181818182
Generation 15: best: 0.672727272727273, mean: 0.435545454545455
Generation 16: best: 0.672727272727273, mean: 0.421709633649932
Generation 17: best: 0.690909090909091, mean: 0.440454545454545
Generation 18: best: 0.690909090909091, mean: 0.452645861601086
Generation 19: best: 0.690909090909091, mean: 0.466181818181818
Generation 20: best: 0.690909090909091, mean: 0.467
Generation 21: best: 0.690909090909091, mean: 0.468909090909091
Generation 22: best: 0.690909090909091, mean: 0.483272727272728
Generation 23: best: 0.690909090909091, mean: 0.494727272727273
Generation 24: best: 0.690909090909091, mean: 0.497818181818182
Generation 25: best: 0.690909090909091, mean: 0.507545454545455
Generation 26: best: 0.709090909090909, mean: 0.509
Generation 27: best: 0.709090909090909, mean: 0.506739032112166
Generation 28: best: 0.709090909090909, mean: 0.522181818181818
Generation 29: best: 0.709090909090909, mean: 0.529895974672094
Generation 30: best: 0.709090909090909, mean: 0.52790592492085
Generation 31: best: 0.709090909090909, mean: 0.535272727272727
Generation 32: best: 0.745454545454545, mean: 0.539909090909091
Generation 33: best: 0.745454545454545, mean: 0.550090909090909
Generation 34: best: 0.745454545454545, mean: 0.549272727272727
Generation 35: best: 0.745454545454545, mean: 0.553545454545454
Generation 36: best: 0.745454545454545, mean: 0.554363636363637
Generation 37: best: 0.745454545454545, mean: 0.555
Generation 38: best: 0.745454545454545, mean: 0.551454545454545
Generation 39: best: 0.745454545454545, mean: 0.553505201266395
Generation 40: best: 0.745454545454545, mean: 0.556218905472637
Generation 41: best: 0.745454545454545, mean: 0.554909090909091
Generation 42: best: 0.763636363636364, mean: 0.565454545454546
Generation 43: best: 0.763636363636364, mean: 0.576454545454545
Generation 44: best: 0.763636363636364, mean: 0.584
Generation 45: best: 0.763636363636364, mean: 0.587878787878788
Generation 46: best: 0.763636363636364, mean: 0.592272727272727
Generation 47: best: 0.763636363636364, mean: 0.596653098145636
Generation 48: best: 0.763636363636364, mean: 0.599728629579376
Generation 49: best: 0.763636363636364, mean: 0.598727272727272
Generation 50: best: 0.763636363636364, mean: 0.599545454545454
Generation 51: best: 0.763636363636364, mean: 0.594482134780642
Generation 52: best: 0.763636363636364, mean: 0.588181818181818
Generation 53: best: 0.763636363636364, mean: 0.597090909090909
Generation 54: best: 0.781818181818182, mean: 0.604090909090909
Generation 55: best: 0.781818181818182, mean: 0.612
Generation 56: best: 0.781818181818182, mean: 0.617818181818181
Generation 57: best: 0.781818181818182, mean: 0.612272727272727
Generation 58: best: 0.781818181818182, mean: 0.616824966078698
Generation 59: best: 0.8, mean: 0.619363636363637
Generation 60: best: 0.8, mean: 0.613454545454545
Generation 61: best: 0.8, mean: 0.611363636363636
Generation 62: best: 0.8, mean: 0.615090909090909
Generation 63: best: 0.8, mean: 0.615363636363636
Generation 64: best: 0.8, mean: 0.619818181818182
Generation 65: best: 0.8, mean: 0.624151967435549
Generation 66: best: 0.8, mean: 0.626413387607417
Generation 67: best: 0.818181818181818, mean: 0.623727272727272
Generation 68: best: 0.818181818181818, mean: 0.633454545454545
Generation 69: best: 0.818181818181818, mean: 0.637454545454546
Generation 70: best: 0.818181818181818, mean: 0.642636363636363
Generation 71: best: 0.818181818181818, mean: 0.638090909090909
Generation 72: best: 0.818181818181818, mean: 0.643690637720488
Generation 73: best: 0.818181818181818, mean: 0.641454545454545
Generation 74: best: 0.818181818181818, mean: 0.646727272727273
Generation 75: best: 0.818181818181818, mean: 0.657818181818182
Generation 76: best: 0.818181818181818, mean: 0.658363636363636
Generation 77: best: 0.818181818181818, mean: 0.654181818181819
Generation 78: best: 0.818181818181818, mean: 0.651650836725464
Generation 79: best: 0.818181818181818, mean: 0.659090909090909
Generation 80: best: 0.818181818181818, mean: 0.666090909090909
Generation 81: best: 0.818181818181818, mean: 0.667818181818182
Generation 82: best: 0.818181818181818, mean: 0.661909090909091
Generation 83: best: 0.836363636363636, mean: 0.665454545454545
Generation 84: best: 0.836363636363636, mean: 0.661090909090909
Generation 85: best: 0.836363636363636, mean: 0.670727272727273
Generation 86: best: 0.836363636363636, mean: 0.672
Generation 87: best: 0.854545454545454, mean: 0.681090909090909
Generation 88: best: 0.854545454545454, mean: 0.688181818181818
Generation 89: best: 0.854545454545454, mean: 0.685181818181818
Generation 90: best: 0.854545454545454, mean: 0.686727272727273
Generation 91: best: 0.854545454545454, mean: 0.689181818181818
Generation 92: best: 0.854545454545454, mean: 0.695818181818182
Generation 93: best: 0.854545454545454, mean: 0.699272727272727
Generation 94: best: 0.872727272727273, mean: 0.692818181818182
Generation 95: best: 0.872727272727273, mean: 0.695909090909091
Generation 96: best: 0.872727272727273, mean: 0.692
Generation 97: best: 0.872727272727273, mean: 0.692454545454546
Generation 98: best: 0.872727272727273, mean: 0.695
Generation 99: best: 0.872727272727273, mean: 0.695909090909091
Generation 100: best: 0.872727272727273, mean: 0.692265943012212
Generation 101: best: 0.872727272727273, mean: 0.693272727272728
Generation 102: best: 0.872727272727273, mean: 0.693636363636364
Generation 103: best: 0.872727272727273, mean: 0.689
Generation 104: best: 0.872727272727273, mean: 0.688454545454546
Generation 105: best: 0.872727272727273, mean: 0.692272727272727
Generation 106: best: 0.872727272727273, mean: 0.698
Generation 107: best: 0.872727272727273, mean: 0.704025327905925
Generation 108: best: 0.872727272727273, mean: 0.699545454545455
Generation 109: best: 0.872727272727273, mean: 0.694545454545455
Generation 110: best: 0.872727272727273, mean: 0.690999547715966
Generation 111: best: 0.872727272727273, mean: 0.699545454545455
Generation 112: best: 0.872727272727273, mean: 0.708090909090909
Generation 113: best: 0.890909090909091, mean: 0.709272727272727
Generation 114: best: 0.890909090909091, mean: 0.701221166892809
Generation 115: best: 0.909090909090909, mean: 0.698507462686567
Generation 116: best: 0.909090909090909, mean: 0.705272727272728
Generation 117: best: 0.909090909090909, mean: 0.705636363636364
Generation 118: best: 0.909090909090909, mean: 0.712090909090909
Generation 119: best: 0.909090909090909, mean: 0.714090909090909
Generation 120: best: 0.909090909090909, mean: 0.720545454545455
Generation 121: best: 0.909090909090909, mean: 0.721909090909091
Generation 122: best: 0.909090909090909, mean: 0.724090909090909
Generation 123: best: 0.909090909090909, mean: 0.731727272727273
Generation 124: best: 0.909090909090909, mean: 0.747090909090908
Generation 125: best: 0.927272727272727, mean: 0.747272727272728
Generation 126: best: 0.927272727272727, mean: 0.751636363636363
Generation 127: best: 0.927272727272727, mean: 0.760000000000001
Generation 128: best: 0.927272727272727, mean: 0.758181818181819
Generation 129: best: 0.927272727272727, mean: 0.752419719583899
Generation 130: best: 0.927272727272727, mean: 0.757756671189507
Generation 131: best: 0.927272727272727, mean: 0.750545454545455
Generation 132: best: 0.927272727272727, mean: 0.753
Generation 133: best: 0.927272727272727, mean: 0.749363636363637
Generation 134: best: 0.927272727272727, mean: 0.752454545454546
Generation 135: best: 0.927272727272727, mean: 0.765181818181819
Generation 136: best: 0.927272727272727, mean: 0.769606512890095
Generation 137: best: 0.927272727272727, mean: 0.769454545454545
Generation 138: best: 0.927272727272727, mean: 0.777272727272727
Generation 139: best: 0.927272727272727, mean: 0.781545454545455
Generation 140: best: 0.927272727272727, mean: 0.791545454545455
Generation 141: best: 0.927272727272727, mean: 0.791909090909091
Generation 142: best: 0.927272727272727, mean: 0.794545454545455
Generation 143: best: 0.927272727272727, mean: 0.796727272727273
Generation 144: best: 0.927272727272727, mean: 0.796636363636364
Generation 145: best: 0.927272727272727, mean: 0.795363636363637
Generation 146: best: 0.927272727272727, mean: 0.797919493441882
Generation 147: best: 0.927272727272727, mean: 0.796454545454546
Generation 148: best: 0.927272727272727, mean: 0.798454545454545
Generation 149: best: 0.927272727272727, mean: 0.787545454545455
Generation 150: best: 0.927272727272727, mean: 0.785545454545455
Generation 151: best: 0.927272727272727, mean: 0.793545454545455
Generation 152: best: 0.945454545454545, mean: 0.795636363636364
Generation 153: best: 0.945454545454545, mean: 0.796909090909091
Generation 154: best: 0.945454545454545, mean: 0.802454545454545
Generation 155: best: 0.945454545454545, mean: 0.800995024875622
Generation 156: best: 0.945454545454545, mean: 0.798727272727274
Generation 157: best: 0.945454545454545, mean: 0.788240615106287
Generation 158: best: 0.945454545454545, mean: 0.786000000000001
Generation 159: best: 0.945454545454545, mean: 0.794
Generation 160: best: 0.945454545454545, mean: 0.797
Generation 161: best: 0.945454545454545, mean: 0.797181818181819
Generation 162: best: 0.945454545454545, mean: 0.798272727272727
Generation 163: best: 0.945454545454545, mean: 0.797454545454545
Generation 164: best: 0.945454545454545, mean: 0.804727272727273
Generation 165: best: 0.945454545454545, mean: 0.801272727272728
Generation 166: best: 0.945454545454545, mean: 0.802727272727273
Generation 167: best: 0.945454545454545, mean: 0.80651289009498
Generation 168: best: 0.945454545454545, mean: 0.812999999999999
Generation 169: best: 0.945454545454545, mean: 0.807909090909091
Generation 170: best: 0.945454545454545, mean: 0.814090909090909
Generation 171: best: 0.945454545454545, mean: 0.813454545454546
Generation 172: best: 0.945454545454545, mean: 0.815363636363637
Generation 173: best: 0.945454545454545, mean: 0.816727272727273
Generation 174: best: 0.945454545454545, mean: 0.819181818181819
Generation 175: best: 0.945454545454545, mean: 0.820909090909091
Generation 176: best: 0.945454545454545, mean: 0.820090909090909
Generation 177: best: 0.945454545454545, mean: 0.821076436001809
Generation 178: best: 0.945454545454545, mean: 0.822
Generation 179: best: 0.945454545454545, mean: 0.820636363636364
Generation 180: best: 0.963636363636364, mean: 0.817096336499322
Generation 181: best: 0.963636363636364, mean: 0.81763907734057
Generation 182: best: 0.963636363636364, mean: 0.824818181818182
Generation 183: best: 0.963636363636364, mean: 0.822727272727273
Generation 184: best: 0.963636363636364, mean: 0.823727272727273
Generation 185: best: 0.963636363636364, mean: 0.818636363636364
Generation 186: best: 0.963636363636364, mean: 0.818727272727273
Generation 187: best: 0.963636363636364, mean: 0.820545454545455
Generation 188: best: 0.963636363636364, mean: 0.821363636363636
Generation 189: best: 0.963636363636364, mean: 0.820454545454547
Generation 190: best: 0.963636363636364, mean: 0.818905472636817
Generation 191: best: 0.963636363636364, mean: 0.817545454545455
Generation 192: best: 0.963636363636364, mean: 0.815468113975577
Generation 193: best: 0.963636363636364, mean: 0.821709633649933
Generation 194: best: 0.963636363636364, mean: 0.82225237449118
Generation 195: best: 0.963636363636364, mean: 0.819181818181818
Generation 196: best: 0.963636363636364, mean: 0.822363636363637
Generation 197: best: 0.963636363636364, mean: 0.820636363636364
Generation 198: best: 0.963636363636364, mean: 0.819818181818182
Generation 199: best: 0.963636363636364, mean: 0.816909090909091
Generation 200: best: 0.963636363636364, mean: 0.823727272727273
Generation 201: best: 0.963636363636364, mean: 0.829363636363637
Generation 202: best: 0.963636363636364, mean: 0.832272727272728
Generation 203: best: 0.963636363636364, mean: 0.833545454545455
Generation 204: best: 0.963636363636364, mean: 0.829636363636364
Generation 205: best: 0.963636363636364, mean: 0.827545454545455
Generation 206: best: 0.963636363636364, mean: 0.828181818181819
Generation 207: best: 0.963636363636364, mean: 0.820909090909091
Generation 208: best: 0.963636363636364, mean: 0.818090909090909
Generation 209: best: 0.963636363636364, mean: 0.812272727272728
Generation 210: best: 0.963636363636364, mean: 0.810818181818182
Generation 211: best: 0.963636363636364, mean: 0.809045680687472
Generation 212: best: 0.963636363636364, mean: 0.808
Generation 213: best: 0.963636363636364, mean: 0.812302125734962
Generation 214: best: 0.963636363636364, mean: 0.816636363636364
Generation 215: best: 0.963636363636364, mean: 0.810636363636364
Generation 216: best: 0.963636363636364, mean: 0.815727272727274
Generation 217: best: 0.963636363636364, mean: 0.813818181818182
Generation 218: best: 0.963636363636364, mean: 0.806818181818182
Generation 219: best: 0.963636363636364, mean: 0.810363636363637
Generation 220: best: 0.963636363636364, mean: 0.815909090909091
Generation 221: best: 0.963636363636364, mean: 0.816181818181818
Generation 222: best: 0.963636363636364, mean: 0.822181818181818
Generation 223: best: 0.963636363636364, mean: 0.820363636363637
Generation 224: best: 0.963636363636364, mean: 0.812935323383085
Generation 225: best: 0.963636363636364, mean: 0.813116236996834
Generation 226: best: 0.963636363636364, mean: 0.817727272727273
Generation 227: best: 0.963636363636364, mean: 0.816
Generation 228: best: 0.963636363636364, mean: 0.811090909090909
Generation 229: best: 0.963636363636364, mean: 0.811818181818182
Generation 230: best: 0.963636363636364, mean: 0.81309090909091
Generation 231: best: 0.963636363636364, mean: 0.817818181818183
Generation 232: best: 0.963636363636364, mean: 0.814818181818182
Generation 233: best: 0.963636363636364, mean: 0.809
Generation 234: best: 0.963636363636364, mean: 0.813636363636364
Generation 235: best: 0.963636363636364, mean: 0.807181818181819
Generation 236: best: 0.963636363636364, mean: 0.806818181818182
Generation 237: best: 0.963636363636364, mean: 0.804909090909091
Generation 238: best: 0.963636363636364, mean: 0.805363636363637
Generation 239: best: 0.963636363636364, mean: 0.812483039348711
Generation 240: best: 0.963636363636364, mean: 0.815920398009951
Generation 241: best: 0.963636363636364, mean: 0.811727272727273
Generation 242: best: 0.963636363636364, mean: 0.818181818181818
Generation 243: best: 0.963636363636364, mean: 0.828493894165536
Generation 244: best: 0.963636363636364, mean: 0.823727272727273
Generation 245: best: 0.963636363636364, mean: 0.825090909090909
Generation 246: best: 0.963636363636364, mean: 0.821636363636363
Generation 247: best: 0.963636363636364, mean: 0.824454545454545
Generation 248: best: 0.963636363636364, mean: 0.82
Generation 249: best: 0.963636363636364, mean: 0.827545454545455
Generation 250: best: 0.963636363636364, mean: 0.824727272727274
Generation 251: best: 0.963636363636364, mean: 0.829272727272728
Generation 252: best: 0.963636363636364, mean: 0.833545454545454
Generation 253: best: 0.963636363636364, mean: 0.833363636363636
Generation 254: best: 0.963636363636364, mean: 0.837363636363637
Generation 255: best: 0.981818181818182, mean: 0.833545454545455
Generation 256: best: 0.981818181818182, mean: 0.827770239710538
Generation 257: best: 0.981818181818182, mean: 0.823545454545455
Generation 258: best: 0.981818181818182, mean: 0.824061510628675
Generation 259: best: 0.981818181818182, mean: 0.828545454545455
Generation 260: best: 0.981818181818182, mean: 0.832545454545455
Generation 261: best: 0.981818181818182, mean: 0.834636363636364
Generation 262: best: 0.981818181818182, mean: 0.837539574853008
Generation 263: best: 0.981818181818182, mean: 0.831818181818182
Generation 264: best: 0.981818181818182, mean: 0.834
Generation 265: best: 0.981818181818182, mean: 0.834102216191769
Generation 266: best: 0.981818181818182, mean: 0.839181818181818
Generation 267: best: 0.981818181818182, mean: 0.834454545454546
Generation 268: best: 0.981818181818182, mean: 0.834727272727273
Generation 269: best: 0.981818181818182, mean: 0.828818181818182
Generation 270: best: 1.0, mean: 0.829
Run finished.
---
BEST FITNESS: 1.0
CHROMOSOME: 1111111111111111111111111111111111111111111111111111111
LENGTH: 55
TIME: 1.46135699748993 seconds