Index: framspy/evolalg/dissimilarity/archive.py
===================================================================
--- framspy/evolalg/dissimilarity/archive.py	(revision 1182)
+++ framspy/evolalg/dissimilarity/archive.py	(revision 1182)
@@ -0,0 +1,36 @@
+import copy
+from typing import Union
+
+from evolalg.base.step import Step
+from evolalg.dissimilarity.dissimilarity import Dissimilarity
+from evolalg.dissimilarity.frams_dissimilarity import FramsDissimilarity
+from evolalg.statistics.halloffame_custom import HallOfFameCustom
+
+# TODO not fully tested. Verify if works OK, in particular test adding new individuals.
+class ArchiveDissimilarity(Step):
+
+    def __init__(self, archive_size, dissim: Union[Dissimilarity, FramsDissimilarity], order="max", field="dissim"):
+        self.name= "archive"
+        self.archive_size = archive_size
+        self.archive = []
+        self.dissim = dissim
+        self.order = order
+        self.field = field
+        if self.order not in ["min", "max"]:
+            raise ValueError("Order must be min or max")
+
+        if self.archive_size < 0:
+            raise ValueError(f"Archive size must be integer greater than or equal to 0. Got {self.archive_size}")
+
+    def call(self, population):
+        super(ArchiveDissimilarity, self).call(population)
+        population_archive = population + self.archive
+        population_archive = self.dissim(population_archive)
+
+        population = population_archive[:len(population)]
+        order = 1
+        if self.order == "max":
+            order *= -1
+        sorted_archive = sorted(population_archive, key=lambda x: getattr(x, self.field) * order)
+        self.archive = copy.deepcopy(sorted_archive[:self.archive_size])
+        return population
Index: framspy/evolalg/dissimilarity/dissimilarity.py
===================================================================
--- framspy/evolalg/dissimilarity/dissimilarity.py	(revision 1145)
+++ framspy/evolalg/dissimilarity/dissimilarity.py	(revision 1182)
@@ -11,26 +11,39 @@
 
         self.output_field = output_field
-        self.fn_reduce = None
+        self.fn_reduce = Dissimilarity.get_reduction_by_name(reduction)
         self.knn = knn
-        if reduction == "mean": # TODO change this 'elif' sequence to dictionary?
-            self.fn_reduce = np.mean
-        elif reduction == "max":
-            self.fn_reduce = np.max
-        elif reduction == "min":
-            self.fn_reduce = np.min
-        elif reduction == "sum":
-            self.fn_reduce = np.sum
-        elif reduction == "knn_mean":
-            self.fn_reduce = self.knn_mean
-        elif reduction == "none" or reduction is None:
-            self.fn_reduce = None
+
+
+    @staticmethod
+    def reduce(dissim_matrix, fn_reduce, knn):
+        if fn_reduce is None:
+            return dissim_matrix
+        elif fn_reduce is Dissimilarity.knn_mean:
+            return fn_reduce(dissim_matrix, 1, knn)
         else:
-            raise ValueError("Unknown reduction type. Supported: mean, max, min, sum, knn_mean, none")
+            return fn_reduce(dissim_matrix, axis=1)
 
-    def reduce(self, dissim_matrix):
-        if self.fn_reduce is None:
-            return dissim_matrix
-        return self.fn_reduce(dissim_matrix, axis=1)
 
-    def knn_mean(self, dissim_matrix,axis):
-        return np.mean(np.partition(dissim_matrix, self.knn)[:,:self.knn],axis=axis)
+    @staticmethod
+    def knn_mean(dissim_matrix, axis, knn):
+        return np.mean(np.partition(dissim_matrix, knn)[:, :knn], axis=axis)
+
+
+    @staticmethod
+    def get_reduction_by_name(reduction: str):
+
+        if reduction not in REDUCTION_FUNCTION:
+            raise ValueError(f"Unknown reduction type '{reduction}'. Supported: {','.join(REDUCTION_FUNCTION.keys())}")
+
+        return REDUCTION_FUNCTION[reduction]
+
+
+
+REDUCTION_FUNCTION = {
+            "mean": np.mean,
+            "max": np.max,
+            "min": np.min,
+            "sum": np.sum,
+            "knn_mean": Dissimilarity.knn_mean,
+            "none": None
+        }
Index: framspy/evolalg/dissimilarity/frams_dissimilarity.py
===================================================================
--- framspy/evolalg/dissimilarity/frams_dissimilarity.py	(revision 1145)
+++ framspy/evolalg/dissimilarity/frams_dissimilarity.py	(revision 1182)
@@ -6,34 +6,14 @@
 from evolalg.dissimilarity.dissimilarity import Dissimilarity
 
-#TODO eliminate overlap with dissimilarity.py
-
 
 class FramsDissimilarity(FramsStep):
 
-    def __init__(self, frams_lib, reduction="mean", output_field="dissim", knn=None, *args, **kwargs):
+    def __init__(self, frams_lib, reduction="mean", output_field="dissim",knn=None, *args, **kwargs):
         super(FramsDissimilarity, self).__init__(frams_lib, *args, **kwargs)
 
         self.output_field = output_field
-        self.fn_reduce = None
+        self.fn_reduce = Dissimilarity.get_reduction_by_name(reduction)
         self.knn = knn
-        if reduction == "mean":
-            self.fn_reduce = np.mean
-        elif reduction == "max":
-            self.fn_reduce = np.max
-        elif reduction == "min":
-            self.fn_reduce = np.min
-        elif reduction == "sum":
-            self.fn_reduce = np.sum
-        elif reduction == "knn_mean":
-            self.fn_reduce = self.knn_mean
-        elif reduction == "none" or reduction is None:
-            self.fn_reduce = None
-        else:
-            raise ValueError("Unknown reduction type. Supported: mean, max, min, sum, knn_mean, none")
 
-    def reduce(self, dissim_matrix):
-        if self.fn_reduce is None:
-            return dissim_matrix
-        return self.fn_reduce(dissim_matrix, axis=1)
 
     def call(self, population):
@@ -41,10 +21,7 @@
         if len(population) == 0:
             return []
-        dissim_matrix = self.frams.dissimilarity([_.genotype for _ in population])
-        dissim = self.reduce(dissim_matrix)
+        dissim_matrix = self.frams.dissimilarity([_.genotype for _ in population], 1)
+        dissim = Dissimilarity.reduce(dissim_matrix, self.fn_reduce, self.knn)
         for d,ind in zip(dissim, population):
             setattr(ind, self.output_field, d)
         return population
-
-    def knn_mean(self, dissim_matrix,axis):
-        return np.mean(np.partition(dissim_matrix, self.knn)[:,:self.knn],axis=axis)
Index: framspy/evolalg/dissimilarity/levenshtein.py
===================================================================
--- framspy/evolalg/dissimilarity/levenshtein.py	(revision 1145)
+++ framspy/evolalg/dissimilarity/levenshtein.py	(revision 1182)
@@ -18,5 +18,5 @@
                 gen_dis.append(lev.distance(p.genotype, p2.genotype))
             dissim.append(gen_dis)
-        dissim = self.reduce(dissim)
+        dissim = self.reduce(dissim, self.fn_reduce, self.knn)
         for d, ind in zip(dissim, population):
             setattr(ind, self.output_field, d)
