Coverage for pybeepop/beepop/adult.py: 86%
66 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-30 13:34 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-30 13:34 +0000
1"""BeePop+ Adult Bee Module.
3This module contains the Adult class that represents mature honey bees (workers,
4drones, and foragers) in the colony simulation. Adult bees are the final life
5stage that can perform colony functions including foraging, nursing, and reproduction.
7The Adult class extends the base Bee class with additional attributes specific
8to adult bee behavior including lifespan tracking, mite infestations, foraging
9capacity, and age-dependent mortality.
11Adult bees in the simulation represent discrete cohorts that age daily and
12eventually die based on their maximum lifespan and environmental factors.
13Workers can transition to foraging roles based on colony needs and population
14dynamics.
15"""
17from pybeepop.beepop.bee import Bee
18from pybeepop.beepop.mite import Mite
21class Adult(Bee):
22 """Adult honey bee class representing mature workers, drones, or foragers.
24 This class models adult honey bees that have completed metamorphosis and
25 are capable of performing colony functions. Adult bees track their age,
26 lifespan, mite load, and foraging contribution within the colony simulation.
28 Adult bees age daily and die when they exceed their maximum lifespan.
29 Workers may transition to foraging roles based on colony needs. All adults
30 can carry varroa mites that affect their longevity and colony health.
32 Attributes:
33 number (int): Population count for this age cohort (inherited from Bee)
34 age (float): Bee age in simulation time units (inherited from Bee)
35 alive (bool): Whether this cohort is alive (inherited from Bee)
36 lifespan (float): Maximum lifespan for this adult cohort
37 current_age (float): Current age of this adult cohort
38 mites (Mite): Varroa mites carried by this adult population
39 prop_virgins (float): Proportion of virgin mites (0.0-1.0)
40 forage_inc (float): Foraging increment/contribution value
41 mites_counted (bool): Whether mites have been counted this period
42 """
44 def __init__(self, number=0):
45 """Initialize a new Adult bee cohort.
47 Creates an adult bee population with specified initial size and
48 default attributes for lifespan, age, mite load, and behavioral
49 characteristics.
51 Args:
52 number (int, optional): Initial population size for this adult
53 cohort. Defaults to 0.
54 """
55 super().__init__(number)
56 self.lifespan = 0.0
57 self.current_age = 0.0
58 self.mites = Mite() # Initialize with empty Mite object
59 self.prop_virgins = 0.0
60 self.forage_inc = 0.0
61 self.mites_counted = False
63 def set_lifespan(self, span):
64 self.lifespan = float(span)
66 def set_current_age(self, age):
67 self.current_age = age
69 def set_prop_virgins(self, prop):
70 if prop < 0.0:
71 self.prop_virgins = 0.0
72 elif prop > 1.0:
73 self.prop_virgins = 1.0
74 else:
75 self.prop_virgins = prop
77 def get_prop_virgins(self):
78 return self.prop_virgins
80 def increment_age(self, increment):
81 self.current_age += increment
83 def get_current_age(self):
84 return self.current_age
86 def get_lifespan(self):
87 return int(self.lifespan)
89 def set_forage_inc(self, inc):
90 self.forage_inc = inc
92 def get_forage_inc(self):
93 return self.forage_inc
95 def set_mites(self, the_mites):
96 self.mites = the_mites
98 def get_mites(self):
99 return self.mites
101 def have_mites_been_counted(self):
102 return self.mites_counted
104 def set_mites_counted(self, value):
105 self.mites_counted = value
107 def reset(self):
108 super().reset()
109 self.lifespan = 0.0
110 self.current_age = 0.0
111 self.mites = Mite() # Initialize with empty Mite object
112 self.prop_virgins = 0.0
113 self.forage_inc = 0.0
114 self.mites_counted = False
116 def copy_from(self, other):
117 """Copy all attributes from another Adult object."""
118 if isinstance(other, Adult):
119 self.number = int(other.number)
120 self.age = other.age
121 self.alive = other.alive
122 # Copy Adult-specific attributes
123 self.lifespan = other.lifespan
124 self.current_age = other.current_age
125 self.mites = other.mites
126 self.prop_virgins = other.prop_virgins
127 self.forage_inc = other.forage_inc
128 self.mites_counted = other.mites_counted
130 def __eq__(self, other):
131 if not isinstance(other, Adult):
132 return False
133 return (
134 self.lifespan == other.lifespan
135 and self.current_age == other.current_age
136 and self.mites == other.mites
137 and self.prop_virgins == other.prop_virgins
138 and self.forage_inc == other.forage_inc
139 and self.number == other.number
140 and self.alive == other.alive
141 and self.mites_counted == other.mites_counted
142 )
144 def __str__(self):
145 return (
146 f"Adult(number={self.number}, lifespan={self.lifespan}, "
147 f"current_age={self.current_age}, mites={self.mites}, "
148 f"prop_virgins={self.prop_virgins}, forage_inc={self.forage_inc}, "
149 f"mites_counted={self.mites_counted}, alive={self.alive})"
150 )