Index: framspy/evolalg/examples/niching_novelty.py
===================================================================
--- framspy/evolalg/examples/niching_novelty.py	(revision 1149)
+++ framspy/evolalg/examples/niching_novelty.py	(revision 1182)
@@ -11,4 +11,5 @@
 from evolalg.base.lambda_step import LambdaStep
 from evolalg.base.step import Step
+from evolalg.dissimilarity.archive import ArchiveDissimilarity
 from evolalg.dissimilarity.frams_dissimilarity import FramsDissimilarity
 from evolalg.dissimilarity.levenshtein import LevenshteinDissimilarity
@@ -56,5 +57,6 @@
         description='Run this program with "python -u %s" if you want to disable buffering of its output.' % sys.argv[
             0])
-    parser.add_argument('-path', type=ensureDir, required=True, help='Path to the Framsticks library without trailing slash.')
+    parser.add_argument('-path', type=ensureDir, required=True,
+                        help='Path to the Framsticks library without trailing slash.')
     parser.add_argument('-opt', required=True,
                         help='optimization criteria: vertpos, velocity, distance, vertvel, lifespan, numjoints, numparts, numneurons, numconnections (or other as long as it is provided by the .sim file and its .expdef). For multiple criteria optimization, see multicriteria.py.')
@@ -63,10 +65,12 @@
     parser.add_argument('-genformat', required=False, default="1",
                         help='Genetic format for the demo run, for example 4, 9, or B. If not given, f1 is assumed.')
-    parser.add_argument('-sim', required=False, default="eval-allcriteria.sim", help="Name of the .sim file with all parameter values. If you want to provide more files, separate them with a semicolon ';'.")
+    parser.add_argument('-sim', required=False, default="eval-allcriteria.sim",
+                        help="Name of the .sim file with all parameter values. If you want to provide more files, separate them with a semicolon ';'.")
     parser.add_argument('-fit', required=False, default=Fitness.raw, type=Fitness,
                         help=' Fitness criteria, default: raw', choices=list(Fitness))
     parser.add_argument('-dissim', required=False, type=Dissim, default=Dissim.frams,
                         help='Dissimilarity measure, default: frams', choices=list(Dissim))
-    parser.add_argument('-knn', type=int, help="'k' value for knn-based fitness criteria (knn-niching and knn-novelty).")
+    parser.add_argument('-knn', type=int,
+                        help="'k' value for knn-based fitness criteria (knn-niching and knn-novelty).")
     parser.add_argument('-popsize', type=int, default=50, help="Population size, default: 50.")
     parser.add_argument('-generations', type=int, default=5, help="Number of generations, default: 5.")
@@ -77,10 +81,12 @@
     parser.add_argument('-max_numneurons', type=int, default=None, help="Maximum number of Neurons. Default: no limit")
     parser.add_argument('-max_numconnections', type=int, default=None, help="Maximum number of Neural connections. Default: no limit")
-
+    parser.add_argument('-max_numgenochars', type=int, default=10000, help="Maximum number of characters in genotype, to disable this option set it to -1. Default: 10 000")
     parser.add_argument('-hof_size', type=int, default=10, help="Number of genotypes in Hall of Fame. Default: 10.")
-    parser.add_argument('-hof_evaluations', type=int, default=20, help="Number of final evaluations of each genotype in Hall of Fame to obtain reliable (averaged) fitness. Default: 20.")
+    parser.add_argument('-hof_evaluations', type=int, default=20,
+                        help="Number of final evaluations of each genotype in Hall of Fame to obtain reliable (averaged) fitness. Default: 20.")
     parser.add_argument('-checkpoint_path', required=False, default=None, help="Path to the checkpoint file")
     parser.add_argument('-checkpoint_interval', required=False, type=int, default=100, help="Checkpoint interval")
     parser.add_argument('-debug', dest='debug', action='store_true', help="Prints names of steps as they are executed")
+    parser.add_argument('-archive_size', type=int, default=0, help="Size of the archive size for dissimilarity calculation")
     parser.set_defaults(debug=False)
     return parser.parse_args()
@@ -131,4 +137,11 @@
         return individual.numconnections > self.max_number
 
+class NumCharsHigher(Remove):
+    def __init__(self, max_number):
+        super(NumCharsHigher, self).__init__()
+        self.max_number = max_number
+
+    def remove(self, individual):
+        return len(individual.genotype) > self.max_number
 
 class ReplaceWithHallOfFame(Step):
@@ -136,4 +149,5 @@
         super(ReplaceWithHallOfFame, self).__init__(*args, **kwargs)
         self.hof = hof
+
     def call(self, population, *args, **kwargs):
         super(ReplaceWithHallOfFame, self).call(population)
@@ -166,5 +180,5 @@
     parsed_args = parseArguments()
     frams_lib = FramsticksLib(parsed_args.path, parsed_args.lib,
-                          parsed_args.sim.split(";"))
+                              parsed_args.sim.split(";"))
     # Steps for generating first population
     init_stages = [
@@ -187,13 +201,12 @@
 
     fitness_raw = FitnessStep(frams_lib, fields={parsed_args.opt: "fitness_raw",
-                                             "numparts": "numparts",
-                                             "numjoints": "numjoints",
-                                             "numneurons": "numneurons",
-                                             "numconnections": "numconnections"},
+                                                 "numparts": "numparts",
+                                                 "numjoints": "numjoints",
+                                                 "numneurons": "numneurons",
+                                                 "numconnections": "numconnections"},
                               fields_defaults={parsed_args.opt: None, "numparts": float("inf"),
                                                "numjoints": float("inf"), "numneurons": float("inf"),
                                                "numconnections": float("inf")},
                               evaluation_count=1)
-
 
     fitness_end = FitnessStep(frams_lib, fields={parsed_args.opt: "fitness_raw"},
@@ -213,4 +226,6 @@
     if parsed_args.max_numconnections is not None:
         remove.append(NumConnectionsHigher(parsed_args.max_numconnections))
+    if parsed_args.max_numgenochars is not -1:
+        remove.append(NumCharsHigher(parsed_args.max_numgenochars))
 
     remove_step = UnionStep(remove)
@@ -245,7 +260,8 @@
         generation_modifications.append(raw)
 
-    if parsed_args.fit == Fitness.niching: # TODO reduce redundancy in the four cases below: dictionary?
+    if parsed_args.fit == Fitness.niching:  # TODO reduce redundancy in the four cases below: dictionary?
+
         niching = UnionStep([
-            dissim,
+            ArchiveDissimilarity(parsed_args.archive_size, dissim),
             LambdaStep(func_niching)
         ])
@@ -255,21 +271,21 @@
     if parsed_args.fit == Fitness.novelty:
         novelty = UnionStep([
-            dissim,
+            ArchiveDissimilarity(parsed_args.archive_size, dissim),
             LambdaStep(func_novelty)
         ])
         init_stages.append(novelty)
         generation_modifications.append(novelty)
-    
+
     if parsed_args.fit == Fitness.knn_niching:
         knn_niching = UnionStep([
-            dissim,
+            ArchiveDissimilarity(parsed_args.archive_size, dissim),
             LambdaStep(func_knn_niching)
         ])
         init_stages.append(knn_niching)
         generation_modifications.append(knn_niching)
-    
+
     if parsed_args.fit == Fitness.knn_novelty:
         knn_novelty = UnionStep([
-            dissim,
+            ArchiveDissimilarity(parsed_args.archive_size, dissim),
             LambdaStep(func_knn_novelty)
         ])
@@ -302,13 +318,10 @@
         fitness_end,
         PopulationSave("halloffame.gen", provider=hall_of_fame.halloffame, fields={"genotype": "genotype",
-                                                                                  "fitness": "fitness_raw"})]
+                                                                                   "fitness": "fitness_raw"})]
     # ...but custom fields can be added, e.g. "custom": "recording"
 
     # -------------------------------------------------
 
-
-
     # Experiment creation
-
 
     experiment = Experiment(init_population=init_stages,
@@ -354,6 +367,4 @@
 
 
-
 if __name__ == '__main__':
-
     main()
