aegis_sim.submodels.resources.resources
1import numpy as np 2 3 4class Resources: 5 """ 6 7 GUI 8 Resources module computes and keeps track of the amount of available resources. 9 Living individuals scavenge resources during each simulation step, with each individual requiring one unit of resources per step to survive. 10 If the number of available resource units falls short of the number of individuals, a starvation response is triggered, as defined by the Starvation module. 11 In that case, resources are fully depleted. 12 13 While scavenging reduces the available resources, regeneration occurs each step as well. 14 Regeneration logic can be customized to operate in an additive or multiplicative manner, or both. 15 Additive regeneration increases the resource pool by a constant amount each step, determined by the [[RESOURCE_ADDITIVE_GROWTH]] parameter. 16 In contrast, multiplicative regeneration increases the currently available resources by a factor of 1 + [[RESOURCE_MULTIPLICATIVE_GROWTH]]. 17 Additionally, there may be a cap on the maximum amount of resources that can be accumulated, which can be controlled using the [[RESOURCE_MAXIMUM_AMOUNT]] parameter. 18 19 By default, resource growth is additive and corresponds to the [[RESOURCE_ADDITIVE_GROWTH]]. 20 Furthermore, there is no maximum limit on resource growth by default. 21 """ 22 23 def init( 24 self, 25 RESOURCE_ADDITIVE_GROWTH, 26 RESOURCE_MULTIPLICATIVE_GROWTH, 27 RESOURCE_MAXIMUM_AMOUNT, 28 RESOURCE_INITIAL_AMOUNT, 29 ): 30 31 self.capacity = RESOURCE_INITIAL_AMOUNT 32 self.RESOURCE_ADDITIVE_GROWTH = RESOURCE_ADDITIVE_GROWTH 33 self.RESOURCE_MULTIPLICATIVE_GROWTH = RESOURCE_MULTIPLICATIVE_GROWTH 34 self.RESOURCE_MAXIMUM_AMOUNT = RESOURCE_MAXIMUM_AMOUNT if RESOURCE_MAXIMUM_AMOUNT is not None else np.inf 35 36 def replenish(self): 37 self.capacity = self.capacity * (1 + self.RESOURCE_MULTIPLICATIVE_GROWTH) + self.RESOURCE_ADDITIVE_GROWTH 38 if self.capacity > self.RESOURCE_MAXIMUM_AMOUNT: 39 self.capacity = self.RESOURCE_MAXIMUM_AMOUNT 40 41 def reduce(self, amount): 42 if amount > self.capacity: 43 self.capacity = 0 44 else: 45 self.capacity -= amount 46 47 def scavenge(self, demands): 48 """Return the available amount of resources and reduce exploited amount""" 49 50 total_demand = demands.sum() 51 52 if total_demand > self.capacity: 53 ration = self.capacity / len(demands) 54 self.reduce(total_demand) 55 return ration * np.ones(shape=demands.shape) 56 else: 57 self.reduce(total_demand) 58 return demands 59 60 61resources = Resources()
5class Resources: 6 """ 7 8 GUI 9 Resources module computes and keeps track of the amount of available resources. 10 Living individuals scavenge resources during each simulation step, with each individual requiring one unit of resources per step to survive. 11 If the number of available resource units falls short of the number of individuals, a starvation response is triggered, as defined by the Starvation module. 12 In that case, resources are fully depleted. 13 14 While scavenging reduces the available resources, regeneration occurs each step as well. 15 Regeneration logic can be customized to operate in an additive or multiplicative manner, or both. 16 Additive regeneration increases the resource pool by a constant amount each step, determined by the [[RESOURCE_ADDITIVE_GROWTH]] parameter. 17 In contrast, multiplicative regeneration increases the currently available resources by a factor of 1 + [[RESOURCE_MULTIPLICATIVE_GROWTH]]. 18 Additionally, there may be a cap on the maximum amount of resources that can be accumulated, which can be controlled using the [[RESOURCE_MAXIMUM_AMOUNT]] parameter. 19 20 By default, resource growth is additive and corresponds to the [[RESOURCE_ADDITIVE_GROWTH]]. 21 Furthermore, there is no maximum limit on resource growth by default. 22 """ 23 24 def init( 25 self, 26 RESOURCE_ADDITIVE_GROWTH, 27 RESOURCE_MULTIPLICATIVE_GROWTH, 28 RESOURCE_MAXIMUM_AMOUNT, 29 RESOURCE_INITIAL_AMOUNT, 30 ): 31 32 self.capacity = RESOURCE_INITIAL_AMOUNT 33 self.RESOURCE_ADDITIVE_GROWTH = RESOURCE_ADDITIVE_GROWTH 34 self.RESOURCE_MULTIPLICATIVE_GROWTH = RESOURCE_MULTIPLICATIVE_GROWTH 35 self.RESOURCE_MAXIMUM_AMOUNT = RESOURCE_MAXIMUM_AMOUNT if RESOURCE_MAXIMUM_AMOUNT is not None else np.inf 36 37 def replenish(self): 38 self.capacity = self.capacity * (1 + self.RESOURCE_MULTIPLICATIVE_GROWTH) + self.RESOURCE_ADDITIVE_GROWTH 39 if self.capacity > self.RESOURCE_MAXIMUM_AMOUNT: 40 self.capacity = self.RESOURCE_MAXIMUM_AMOUNT 41 42 def reduce(self, amount): 43 if amount > self.capacity: 44 self.capacity = 0 45 else: 46 self.capacity -= amount 47 48 def scavenge(self, demands): 49 """Return the available amount of resources and reduce exploited amount""" 50 51 total_demand = demands.sum() 52 53 if total_demand > self.capacity: 54 ration = self.capacity / len(demands) 55 self.reduce(total_demand) 56 return ration * np.ones(shape=demands.shape) 57 else: 58 self.reduce(total_demand) 59 return demands
GUI Resources module computes and keeps track of the amount of available resources. Living individuals scavenge resources during each simulation step, with each individual requiring one unit of resources per step to survive. If the number of available resource units falls short of the number of individuals, a starvation response is triggered, as defined by the Starvation module. In that case, resources are fully depleted.
While scavenging reduces the available resources, regeneration occurs each step as well. Regeneration logic can be customized to operate in an additive or multiplicative manner, or both. Additive regeneration increases the resource pool by a constant amount each step, determined by the [[RESOURCE_ADDITIVE_GROWTH]] parameter. In contrast, multiplicative regeneration increases the currently available resources by a factor of 1 + [[RESOURCE_MULTIPLICATIVE_GROWTH]]. Additionally, there may be a cap on the maximum amount of resources that can be accumulated, which can be controlled using the [[RESOURCE_MAXIMUM_AMOUNT]] parameter.
By default, resource growth is additive and corresponds to the [[RESOURCE_ADDITIVE_GROWTH]]. Furthermore, there is no maximum limit on resource growth by default.
24 def init( 25 self, 26 RESOURCE_ADDITIVE_GROWTH, 27 RESOURCE_MULTIPLICATIVE_GROWTH, 28 RESOURCE_MAXIMUM_AMOUNT, 29 RESOURCE_INITIAL_AMOUNT, 30 ): 31 32 self.capacity = RESOURCE_INITIAL_AMOUNT 33 self.RESOURCE_ADDITIVE_GROWTH = RESOURCE_ADDITIVE_GROWTH 34 self.RESOURCE_MULTIPLICATIVE_GROWTH = RESOURCE_MULTIPLICATIVE_GROWTH 35 self.RESOURCE_MAXIMUM_AMOUNT = RESOURCE_MAXIMUM_AMOUNT if RESOURCE_MAXIMUM_AMOUNT is not None else np.inf
48 def scavenge(self, demands): 49 """Return the available amount of resources and reduce exploited amount""" 50 51 total_demand = demands.sum() 52 53 if total_demand > self.capacity: 54 ration = self.capacity / len(demands) 55 self.reduce(total_demand) 56 return ration * np.ones(shape=demands.shape) 57 else: 58 self.reduce(total_demand) 59 return demands
Return the available amount of resources and reduce exploited amount