Ejemplo n.º 1
0
 def __init__(self, algorithm_type: AlgorithmType, colours: ColoursList,
              subset_size: int, iterations: int):
     super().__init__()
     self.algorithm = Algorithm.factory(
         algorithm_type)  # the algorithm to run
     self.subset_size = subset_size
     self.colours = colours.random_permutation(
         subset_size)  # the colours to use to run the benchmark
     self.test_results = []  # the results for each run
     self.iterations = iterations  # number of times to run
Ejemplo n.º 2
0
    def __get_random_indexes(colours: ColoursList) -> (int, int):
        """
        Get two random indexes from self.temp_solution ensuring that index1 < index2.
        :return: int index1, int index2
        """
        colour1 = colours.get_random_element()
        colour2 = colours.get_random_element()

        # Ensure that the elements are different
        while colour1 == colour2:
            colour2 = colours.get_random_element()

        index1 = colours.get_index(colour1)
        index2 = colours.get_index(colour2)

        # Swap indexes if index1 > index2
        if index1 > index2:
            index1, index2 = index2, index1

        return index1, index2
Ejemplo n.º 3
0
    def __init__(self, *args):
        self.colours = ColoursList()
        self.solutions = []
        self.iterations = 0

        # Debug
        self.debug = False

        # Performance
        self.__start_time = 0
        self.__end_time = 0
        self.run_time = 0
        self.total_distance = 0
Ejemplo n.º 4
0
    def find_solution(self):
        colours = copy.deepcopy(self.colours)
        solution = ColoursList()
        # Get a random colour
        current_colour = colours.pop_random()
        solution.append(current_colour)
        while len(colours) > 0:
            # Get the nearest colour to the current one
            current_colour, _ = colours.get_nearest_colour_euclidean(current_colour) \
                if self.distance_method == GreedyConstructive.DistanceMethod.EUCLIDEAN \
                else colours.get_nearest_colour_delta_e(current_colour)
            solution.append(current_colour)
            del colours[current_colour]

        self.solutions.append(
            AlgorithmSolution(solution, solution.get_total_distance()))
Ejemplo n.º 5
0
 def __init__(self, colours: ColoursList, total_distance: float = None):
     self.colours = colours
     self.total_distance = colours.get_total_distance(
     ) if total_distance is None else total_distance
Ejemplo n.º 6
0
 def __invert_range(colours_list: ColoursList, start, end):
     colours_list.colours[start:end] = colours_list[start:end][::-1]
Ejemplo n.º 7
0
 def load_colours_list(self, colours_list: ColoursList):
     self.colours = colours_list.clone()