Example #1
0
    def get_placement(self):
        """
        Generates uniform placement coordinates for the given number
        of nodes and returns the result as a dictionary.

        *Returns*:
            A list of tuples of horizontal and vertical coordinates for each
            host.
        """
        if self.__area is None or self.__nodes_number is None:
            return None
        while True:
            horizontal_coordinates = \
                [self.random_generator.uniform(0, self.__area.width)
                    for coordinate in range(0, self.__nodes_number)]
            vertical_coordinates = \
                [self.random_generator.uniform(0, self.__area.height)
                    for coordinate in range(0, self.__nodes_number)]
            if Placement.position_conflict(horizontal_coordinates,
                                           vertical_coordinates) == -1:
                break
        self.logger.debug('Initial placement coordinates has been'
                          ' generated: %d nodes within %dx%d %s simulation'
                          ' area' %
                          (self.__nodes_number, self.__area.width,
                           self.__area.height,
                           self.__area.__class__.__name__.lower()))
        return zip(horizontal_coordinates, vertical_coordinates)
Example #2
0
    def get_placement(self):
        """
        Generates uniform placement coordinates for the given number
        of nodes and returns the result as a dictionary.

        *Returns*:
            A list of tuples of horizontal and vertical coordinates for each
            host.
        """
        if self.__area is None or self.__nodes_number is None:
            return None
        while True:
            horizontal_coordinates = \
                [self.random_generator.uniform(0, self.__area.width)
                    for coordinate in range(0, self.__nodes_number)]
            vertical_coordinates = \
                [self.random_generator.uniform(0, self.__area.height)
                    for coordinate in range(0, self.__nodes_number)]
            if Placement.position_conflict(horizontal_coordinates,
                                           vertical_coordinates) == -1:
                break
        self.logger.debug(
            'Initial placement coordinates has been'
            ' generated: %d nodes within %dx%d %s simulation'
            ' area' %
            (self.__nodes_number, self.__area.width, self.__area.height,
             self.__area.__class__.__name__.lower()))
        return zip(horizontal_coordinates, vertical_coordinates)
Example #3
0
    def get_placement(self):
        """
        Generates normal (Gaussian) placement coordinates for the given number
        of nodes and returns the result as a dictionary.

        The means used here are computed as follows: :math:`\\frac{1}{2}\\times
        area~width` and :math:`\\frac{1}{2}\\times area~height`.

        *Returns*:
            A list of tuples of horizontal and vertical coordinates for each
            host.
        """
        if self.__area is None or self.__nodes_number is None \
                or self.__standard_deviation is None:
            return None
        while True:
            horizontal_coordinates = []
            while True:
                coordinate = self.random_generator.normal(
                    float(self.__area.width) / 2.0, self.__standard_deviation)
                if 0 <= coordinate <= self.__area.width:
                    horizontal_coordinates.append(coordinate)
                if len(horizontal_coordinates) == self.__nodes_number:
                    break
            vertical_coordinates = []
            while True:
                coordinate = self.random_generator.normal(
                    float(self.__area.height) / 2.0, self.__standard_deviation)
                if 0 <= coordinate <= self.__area.height:
                    vertical_coordinates.append(coordinate)
                if len(vertical_coordinates) == self.__nodes_number:
                    break
            if Placement.position_conflict(horizontal_coordinates,
                                           vertical_coordinates) == -1:
                break
        self.logger.debug(
            'Initial placement coordinates has been'
            ' generated: %d nodes within %dx%d %s simulation'
            ' area' %
            (self.__nodes_number, self.__area.width, self.__area.height,
             self.__area.__class__.__name__.lower()))
        return zip(horizontal_coordinates, vertical_coordinates)
Example #4
0
    def get_placement(self):
        """
        Generates normal (Gaussian) placement coordinates for the given number
        of nodes and returns the result as a dictionary.

        The means used here are computed as follows: :math:`\\frac{1}{2}\\times
        area~width` and :math:`\\frac{1}{2}\\times area~height`.

        *Returns*:
            A list of tuples of horizontal and vertical coordinates for each
            host.
        """
        if self.__area is None or self.__nodes_number is None or self.__standard_deviation is None:
            return None
        while True:
            horizontal_coordinates = []
            while True:
                coordinate = self.random_generator.normal(float(self.__area.width) / 2.0, self.__standard_deviation)
                if 0 <= coordinate <= self.__area.width:
                    horizontal_coordinates.append(coordinate)
                if len(horizontal_coordinates) == self.__nodes_number:
                    break
            vertical_coordinates = []
            while True:
                coordinate = self.random_generator.normal(float(self.__area.height) / 2.0, self.__standard_deviation)
                if 0 <= coordinate <= self.__area.height:
                    vertical_coordinates.append(coordinate)
                if len(vertical_coordinates) == self.__nodes_number:
                    break
            if Placement.position_conflict(horizontal_coordinates, vertical_coordinates) == -1:
                break
        self.logger.debug(
            "Initial placement coordinates has been"
            " generated: %d nodes within %dx%d %s simulation"
            " area"
            % (self.__nodes_number, self.__area.width, self.__area.height, self.__area.__class__.__name__.lower())
        )
        return zip(horizontal_coordinates, vertical_coordinates)