• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

DIGNEA / DIGNEApy / 27765193716

18 Jun 2026 02:04PM UTC coverage: 0.0% (-89.1%) from 89.085%
27765193716

push

github

amarrerod
Fixes coveralls action

0 of 2254 relevant lines covered (0.0%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/digneapy/operators/selection/binary.py
1
#!/usr/bin/env python
2
# -*-coding:utf-8 -*-
3
"""
4
@File    :   binary.py
5
@Time    :   2026/05/21 15:17:30
6
@Author  :   Alejandro Marrero (amarrerd@ull.edu.es)
7
@Version :   1.0
8
@Contact :   amarrerd@ull.edu.es
9
@License :   (C)Copyright 2026, Alejandro Marrero
10
@Desc    :   None
11
"""
12

13
from collections.abc import Sequence
×
14
from operator import attrgetter
×
15
from typing import Optional
×
16

17
import numpy as np
×
18

19
from digneapy.typing import IndType
×
20

21
from ._base_selection import Selection
×
22

23

24
class BinarySelection(Selection):
×
25
    def __init__(
×
26
        self, attr: str = "fitness", seed: Optional[int | np.random.SeedSequence] = None
27
    ):
28
        super().__init__(seed)
×
29
        self._attr = attr
×
30

31
    def __call__(
×
32
        self,
33
        population: Sequence[IndType] | np.ndarray,
34
    ) -> IndType:
35
        """Binary Tournament Selection Operator
36

37
        Args:
38
            population (Sequence): Population of individuals to select a parent from
39

40
        Raises:
41
            RuntimeError: If the population is empty
42

43
        Returns:
44
            Instance or Solution: New parent
45
        """
46
        if not population:
×
47
            msg = "Trying to selection individuals in an empty population."
×
48
            raise ValueError(msg)
×
49
        elif len(population) == 1:
×
50
            return population[0]
×
51
        else:
52
            idx1, idx2 = self._rng.integers(low=0, high=len(population), size=2)
×
53
            return max(population[idx1], population[idx2], key=attrgetter(self._attr))
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc