Skip to content

Resources

Natural resources: harvesting, extracting, and cultivating stocks.

The stocks are renewable and nonrenewable.

BidRentInteraction(label, *, target, yields, prices, costs, rates)

Bases: Interaction

Land use of highest bid rent.

Crop i bids Y_i (p_i - c_i) - Y_i f_i d at the distance d of a market. A cell grows the crop of the highest positive bid, and lies idle as crop 0 when no bid is positive.

Parameters:

Name Type Description Default
label str

The label of the interaction.

required
target Role

The path of the field of cells, whose members hold crop and distance.

required
yields Sequence[float]

The yield Y_i of every crop per cell.

required
prices Sequence[float]

The price p_i of every crop at the market.

required
costs Sequence[float]

The cost c_i of every crop per unit of yield.

required
rates Sequence[float]

The transport rate f_i of every crop per unit of yield and of distance.

required

Raises:

Type Description
ValidationError

The four sequences do not have one value per crop, raised by prepare.

Examples:

>>> from skcomplex.systems.economics.resources import BidRentInteraction
>>> bid = BidRentInteraction('bid', target='plain', yields=(2.0,), prices=(3.0,), costs=(1.0,), rates=(0.1,))
>>> bid.rates
(0.1,)
Source code in src/skcomplex/systems/economics/resources/_land_use.py
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
def __init__(
    self,
    label: str,
    *,
    target: Role,
    yields: Sequence[float],
    prices: Sequence[float],
    costs: Sequence[float],
    rates: Sequence[float],
) -> None:
    super().__init__(label)
    self.target = target
    self.yields = yields
    self.prices = prices
    self.costs = costs
    self.rates = rates

CatchInteraction(label, *, target, resource='land/stock.n', effort='harvest.effort')

Bases: Interaction

Catch of every farmer, who adds the effort times the resource stock to its wealth.

The farmers read the stock from another subsystem at its last synchronisation point.

Parameters:

Name Type Description Default
label str

The label of the interaction.

required
target Role

The path of the group of farmers.

required
resource str

The dotted name of the resource stock.

'land/stock.n'
effort str

The dotted name of the harvest effort per farmer.

'harvest.effort'

Examples:

>>> from skcomplex.systems.economics.resources import CatchInteraction
>>> CatchInteraction('catch', target='farmers').resource
'land/stock.n'
Source code in src/skcomplex/systems/economics/resources/_harvesting.py
172
173
174
175
176
177
178
179
180
181
182
183
def __init__(
    self,
    label: str,
    *,
    target: Role,
    resource: str = 'land/stock.n',
    effort: str = 'harvest.effort',
) -> None:
    super().__init__(label)
    self.target = target
    self.resource = resource
    self.effort = effort

catch(agent, system)

Add the effort times the resource stock to the wealth.

The stock is read at the last synchronisation point.

Parameters:

Name Type Description Default
agent FarmerView

The farmer.

required
system SystemView

The system.

required
Source code in src/skcomplex/systems/economics/resources/_harvesting.py
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
def catch(self, agent: FarmerView, system: SystemView) -> None:
    """Add the effort times the resource stock to the wealth.

    The stock is read at the last synchronisation point.

    Args:
        agent:
            The farmer.

        system:
            The system.
    """
    stock = system.inputs.get(self.resource, 0.0)
    if not isinstance(stock, int | float | np.number):
        error_msg = f'The input {self.resource!r} of the farmers is {stock!r}, not a number.'
        raise ValidationError(error_msg)
    agent.wealth += system.parameters[self.effort] * float(stock)

CocoaSystem(area=10.0, *, price=40.0, cost=100.0, insect_growth=0.6, subsidy=0.0, label='system', solver='auto', backend='auto')

Bases: BaseSystem

A cocoa production system, plantations that boom and bust.

They boom with their profit and bust with the insects they invite. The planted area moves towards a desired area, the current area times a table function of the profit margin, so a profitable crop expands it. Farmers thin the shading trees, which raises the yield through an intensification table but lets the insects multiply. Insect attack lowers the yield through an ecological table, and the area is abandoned at a rate that falls with the yield and the profit through two more tables. Abandoned land is converted to oil palm. A subsidy for shade conservation and pest control slows the thinning and controls the insects. Land is conserved, so the area booms while the yield is high and busts once the insects take over, unless a subsidy keeps the shade. The structure and the five table functions follow the boom and bust of cocoa in Malaysia of Bala, Arshad and Noh (2017, Chapter 8), and the rates, the price, and the costs are illustrative, with the area in thousands of hectares, the yield in hundreds of kilograms per hectare, the money in ringgit per hundred kilograms and per hectare, the shade removal and the insect attack as indices from 0 to 100, and time in years.

The system has the land stocks cocoa.area and cocoa.abandoned, the indices cocoa.shade_removal and cocoa.insects, and the flows cocoa.planting, cocoa.abandonment, and cocoa.conversion per year, over years. The observables of the system are cocoa.cocoa_yield, cocoa.profit_per_area, and cocoa.profitability.

Parameters:

Name Type Description Default
area float

The initial planted area.

10.0
price float

The farm price of cocoa.

40.0
cost float

The operating cost per hectare.

100.0
insect_growth float

The largest relative growth rate of the insect attack, reached with all shade removed.

0.6
subsidy float

The coverage of the subsidy and extension programme, from 0 to 1.

0.0
label str

The label of the system, which names it when it is nested in another one.

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for the one the system chooses.

'auto'
backend BaseBackend | str

The backend that evaluates the compiled functions, or 'auto' for the one the system chooses.

'auto'

Examples:

>>> from skcomplex.systems.economics.resources import CocoaSystem
>>> CocoaSystem(subsidy=1.0).prepare().system_.elements[0].subsidy
1.0
Source code in src/skcomplex/systems/economics/resources/_plantations.py
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
def __init__(
    self,
    area: float = 10.0,
    *,
    price: float = 40.0,
    cost: float = 100.0,
    insect_growth: float = 0.6,
    subsidy: float = 0.0,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.area = area
    self.price = price
    self.cost = cost
    self.insect_growth = insect_growth
    self.subsidy = subsidy

CowElement(label, *, owner=-1.0, energy=4.0, values=None, size=None, space=None)

Bases: Element

Cow of a herder that gains the energy of the grass it eats.

It burns its metabolism, and starves without food.

Parameters:

Name Type Description Default
label str

The label of the agent or group.

required
owner Annotated[object, Member(herders)]

The herder that owns the cow among the herders.

-1.0
energy object

The energy of the cow.

4.0
values Mapping[str, object] | None

Further values by name, such as the cells x and y of the members on the meadow.

None
size int | None

The number of cows, or None for one.

None
space BaseSpace | None

The meadow the cows live on, whose axes x and y place them, or None.

None

Examples:

>>> from skcomplex.systems.economics.resources import CowElement
>>> CowElement('cows', energy=4.0, size=3).size
3
Source code in src/skcomplex/systems/economics/resources/_commons.py
154
155
156
157
158
159
160
161
162
163
164
165
166
def __init__(
    self,
    label: str,
    *,
    owner: Annotated[object, Member('herders')] = -1.0,
    energy: object = 4.0,
    values: Mapping[str, object] | None = None,
    size: int | None = None,
    space: BaseSpace | None = None,
) -> None:
    super().__init__(label, values=values, size=size, space=space)
    self.owner = owner
    self.energy = energy

CropLivestockHouseholdSystem(wealth=10000.0, livestock=4.0, *, crop_area=0.5, yield_normal=3.2, price=50000.0, unit_price=35000.0, purchase_price=15000.0, household_consumption=75000.0, max_livestock=8.0, sale_fraction=0.2, label='system', solver='auto', backend='auto')

Bases: DynamicalSystem

Bala's crop livestock model.

A farming household adds livestock rearing to its crop income. A household with a fixed crop area and a grant or loan to start rearing livestock earns the crop production times the price and the sales of animals, and spends on its consumption and on buying animals. Every year it sells the integer part of a fraction of its herd and buys as many animals as its wealth affords when the herd has room for them, and the animals it buys join the herd after three years. The equations and the defaults are those of the STELLA model of Bala et al. (2017, Section 4.11.6), whose DELAY(purchase_of_livestock, 3) is a pipeline of three years and whose INT truncates, so the model is a yearly map. The effects of the cropping intensity and the regeneration on the yield are zero. Livestock raises the income of the household considerably, but only after the maturation delay.

The system has the stocks household.wealth, household.livestock, and household.yield_multiplier, and the purchases of the previous year household.purchases, over years. The observables of the system are household.crop_production, household.income_from_crop, household.income_from_livestock, household.sale, and household.purchase.

Parameters:

Name Type Description Default
wealth float

The initial wealth of the household.

10000.0
livestock float

The initial herd.

4.0
crop_area float

The crop area, in hectares.

0.5
yield_normal float

The normal crop yield, in tonnes per hectare.

3.2
price float

The price of a tonne of crop.

50000.0
unit_price float

The price an animal sells for.

35000.0
purchase_price float

The price of an animal bought.

15000.0
household_consumption float

The consumption of the household per year.

75000.0
max_livestock float

The largest herd the household can rear.

8.0
sale_fraction float

The fraction of the herd sold every year.

0.2
label str

The label of the system, which names it when it is nested in another one.

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for the one the system chooses.

'auto'
backend BaseBackend | str

The backend that evaluates the compiled functions, or 'auto' for the one the system chooses.

'auto'

Examples:

>>> from skcomplex.systems.economics.resources import CropLivestockHouseholdSystem
>>> CropLivestockHouseholdSystem(wealth=20000.0).prepare().system_.elements[0].values['wealth']
20000.0
Source code in src/skcomplex/systems/economics/resources/_crop_livestock.py
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
def __init__(
    self,
    wealth: float = 10000.0,
    livestock: float = 4.0,
    *,
    crop_area: float = 0.5,
    yield_normal: float = 3.2,
    price: float = 50000.0,
    unit_price: float = 35000.0,
    purchase_price: float = 15000.0,
    household_consumption: float = 75000.0,
    max_livestock: float = 8.0,
    sale_fraction: float = 0.2,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label=label, solver=solver, backend=backend)
    self.wealth = wealth
    self.livestock = livestock
    self.crop_area = crop_area
    self.yield_normal = yield_normal
    self.price = price
    self.unit_price = unit_price
    self.purchase_price = purchase_price
    self.household_consumption = household_consumption
    self.max_livestock = max_livestock
    self.sale_fraction = sale_fraction

FarmerElement(label, *, wealth=0.0, values=None, size=None, space=None)

Bases: Element

Farmer who adds the catch of every step to its wealth, by CatchInteraction.

Parameters:

Name Type Description Default
label str

The label of the agent or group.

required
wealth Annotated[object, closed_open(0, oo)]

The initial wealth.

0.0
values Mapping[str, object] | None

Further values by name, or None for none.

None
size int | None

The number of farmers, or None for one.

None
space BaseSpace | None

The space of the farmers, or None for none.

None

Examples:

>>> from skcomplex.systems.economics.resources import FarmerElement
>>> FarmerElement('farmers', size=10).size
10
Source code in src/skcomplex/systems/economics/resources/_harvesting.py
133
134
135
136
137
138
139
140
141
142
143
def __init__(
    self,
    label: str,
    *,
    wealth: Annotated[object, RealSet.closed_open(0, oo)] = 0.0,
    values: Mapping[str, object] | None = None,
    size: int | None = None,
    space: BaseSpace | None = None,
) -> None:
    super().__init__(label, values=values, size=size, space=space)
    self.wealth = wealth

FisheryCapitalSystem(resource=1000.0, capital=5.0, *, cost=1.0, growth_goal=0.1, lifetime=20.0, yield_table=FISH_YIELD, label='system', solver='auto', backend='auto')

Bases: BaseSystem

Meadows' fishing fleet, capital that grows on a renewable resource.

The capital can overshoot the resource. The capital grows while the harvest pays, and the outcome depends on the yield per unit of capital. With the default yield, which falls with the square of the stock, the fleet and the stock settle at an equilibrium. A technology that keeps the yield high at low stocks lets the fleet overshoot, and the stock and then the fleet collapse. The system has the resource fishery.resource and the capital fishery.capital.

Parameters:

Name Type Description Default
resource float

The initial resource stock.

1000.0
capital float

The initial capital.

5.0
cost float

The operating cost per unit of capital.

1.0
growth_goal float

The largest investment per unit of capital.

0.1
lifetime float

The average lifetime of the capital.

20.0
yield_table Sequence[float]

The yield per unit of capital at the resource levels 0, 100, ..., 1000.

FISH_YIELD
label str

The label of the system, which names it when it is nested in another one.

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for the one the system chooses.

'auto'
backend BaseBackend | str

The backend that evaluates the compiled functions, or 'auto' for the one the system chooses.

'auto'

Examples:

>>> from skcomplex.systems.economics.resources import FisheryCapitalSystem
>>> FisheryCapitalSystem(lifetime=10.0).prepare().system_.elements[0].lifetime
10.0
Source code in src/skcomplex/systems/economics/resources/_extraction.py
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
def __init__(
    self,
    resource: float = 1000.0,
    capital: float = 5.0,
    *,
    cost: float = 1.0,
    growth_goal: float = 0.1,
    lifetime: float = 20.0,
    yield_table: Sequence[float] = FISH_YIELD,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.resource = resource
    self.capital = capital
    self.cost = cost
    self.growth_goal = growth_goal
    self.lifetime = lifetime
    self.yield_table = yield_table

FisheryElement(label, *, resource=1000.0, capital=5.0, cost=1.0, growth_goal=0.1, lifetime=20.0, yield_table=FISH_YIELD, regeneration_table=REGENERATION, price_table=PRICE_BY_YIELD)

Bases: Element

Capital that harvests a regenerating resource.

Its price rises as the yield falls. The resource regenerates at a rate per unit of stock that is a hump-shaped table of the stock, zero when it is empty or full. The harvest is the capital times the yield per unit of capital, a table of the stock. The fishery holds the stocks, the parameters, and the tables, and transfers within it of the system move the resource and the capital.

Parameters:

Name Type Description Default
label str

The label of the fishery.

required
resource Annotated[float, closed_open(0, oo), Quantity(fish)]

The initial resource stock.

1000.0
capital Annotated[float, closed_open(0, oo), Quantity(capital)]

The initial capital.

5.0
cost Annotated[float, closed_open(0, oo)]

The operating cost per unit of capital.

1.0
growth_goal Annotated[float, closed_open(0, oo)]

The largest investment per unit of capital.

0.1
lifetime Annotated[float, open(0, oo)]

The average lifetime of the capital.

20.0
yield_table Sequence[float]

The yield per unit of capital at the resource levels 0, 100, ..., 1000.

FISH_YIELD
regeneration_table Sequence[float]

The regeneration rate at the resource levels 0, 100, ..., 1000.

REGENERATION
price_table Sequence[float]

The price at the yields 0, 0.1, 0.2, 0.4, 0.6, 0.8, and 1.

PRICE_BY_YIELD

Examples:

>>> from skcomplex.systems.economics.resources import FisheryElement
>>> FisheryElement('fishery', lifetime=15.0).lifetime
15.0
Source code in src/skcomplex/systems/economics/resources/_extraction.py
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
def __init__(
    self,
    label: str,
    *,
    resource: Annotated[float, RealSet.closed_open(0, oo), Quantity('fish')] = 1000.0,
    capital: Annotated[float, RealSet.closed_open(0, oo), Quantity('capital')] = 5.0,
    cost: Annotated[float, RealSet.closed_open(0, oo)] = 1.0,
    growth_goal: Annotated[float, RealSet.closed_open(0, oo)] = 0.1,
    lifetime: Annotated[float, RealSet.open(0, oo)] = 20.0,
    yield_table: Sequence[float] = FISH_YIELD,
    regeneration_table: Sequence[float] = REGENERATION,
    price_table: Sequence[float] = PRICE_BY_YIELD,
) -> None:
    super().__init__(label)
    self.resource = resource
    self.capital = capital
    self.cost = cost
    self.growth_goal = growth_goal
    self.lifetime = lifetime
    self.yield_table = yield_table
    self.regeneration_table = regeneration_table
    self.price_table = price_table

FisheryMeasurementErrorsSystem(n_fisheries=200, *, x=0.5, r0=1.0, sigma_r=1.0, K=1.0, error=0.0, step=0.01, restocking=False, label='system', solver='auto', backend='auto')

Bases: BaseSystem

Independent fisheries whose quota is set from a measurement of the stock.

The measurement has a Gaussian error. The fish stock grows logistically with a growth rate R0 + sigma_R W(t) that white noise W makes random, and the fishermen harvest the quota gamma(x~) = x~ - K / 2 from their measurement x~ = x + e(t), Problem 14.8 of Argun et al. (2021). The harvest of the deterministic system peaks at x = K / 2, at R0 K / 4, and the quota rule holds the stock at K / sqrt(2), where the growth R0 x (1 - x / K) equals the quota. The problem asks whether the extinction probability can fall as the measurement error grows, after Argun et al. (2016). A quota is a catch, so it is floored at zero, and restocking lets a negative quota release fish as the formula of the source does. Every member of the group fisheries is an independent replica, so the share of extinct stocks estimates the extinction probability, and a step is an Euler-Maruyama step of length step.

The system has the group fisheries of the stocks fisheries.x and the quotas fisheries.catch. The observables of the system are the share of extinct stocks extinct, the mean stock mean_stock, and the mean quota mean_catch.

Parameters:

Name Type Description Default
n_fisheries int

The number of independent fisheries.

200
x float

The initial stock.

0.5
r0 float

The mean growth rate.

1.0
sigma_r float

The standard deviation of the noise of the growth rate.

1.0
K float

The carrying capacity.

1.0
error float

The standard deviation of the measurement error.

0.0
step float

The length of a step in units of time.

0.01
restocking bool

Whether a negative quota releases fish.

False
label str

The label of the system, which names it when it is nested in another one.

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for the one the system chooses.

'auto'
backend BaseBackend | str

The backend that evaluates the compiled functions, or 'auto' for the one the system chooses.

'auto'

Examples:

>>> from skcomplex.systems.economics.resources import FisheryMeasurementErrorsSystem
>>> FisheryMeasurementErrorsSystem(10).prepare().system_.elements[0].size
10
Source code in src/skcomplex/systems/economics/resources/_measurement_errors.py
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
def __init__(
    self,
    n_fisheries: int = 200,
    *,
    x: float = 0.5,
    r0: float = 1.0,
    sigma_r: float = 1.0,
    K: float = 1.0,
    error: float = 0.0,
    step: float = 0.01,
    restocking: bool = False,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.n_fisheries = n_fisheries
    self.x = x
    self.r0 = r0
    self.sigma_r = sigma_r
    self.K = K
    self.error = error
    self.step = step
    self.restocking = restocking

FoodSecuritySystem(*, subsidy=0.67, bio_target=0.0, research=0.0, training_target=0.0, intensity_target=1.0, label='system', solver='auto', backend='auto')

Bases: BaseSystem

A food security system, the rice self-sufficiency of a country.

The country acts by subsidy, research, and extension. The land suitable for rice is developed into rice area over eight years, and the rice area is discarded for housing, roads, and industry at a small fraction per year. The production is the milled share of the productivity times the area times the cropping intensity. The productivity is the potential yield, which research raises towards a limit, times a table of the input ratio, the soil quality, which chemical fertiliser degrades and fallow regenerates, and the farming practice, which training and extension improve through a learning table. The input ratio is the share of the recommended fertiliser that the farmers apply, which the subsidy raises, and a target share of bio-fertiliser replaces the chemical one without degrading the soil. The requirement is the per capita consumption of a population growing exponentially, and the self-sufficiency level is the production over the requirement. Land is conserved, so the rice area peaks once the suitable land is developed and then declines, and without research and extension the self-sufficiency falls as the population grows. The structure and the initial values follow the food security system of Malaysia of Bala, Arshad and Noh (2017, Chapter 10), and the table functions and the rates are illustrative, with the land in millions of hectares, the population in millions, the productivity in tonnes of paddy per hectare, the rice in millions of tonnes, and time in years.

The system has the land stocks rice.available_land and rice.rice_area, the population rice.population, the factors rice.potential, rice.soil_quality, rice.practice, rice.training, rice.bio_fraction, and rice.cropping_intensity, and the flows rice.development, rice.discard, and rice.population_growth per year, over years. The observables of the system are rice.input_ratio, rice.productivity, rice.production, rice.requirement, and rice.self_sufficiency.

Parameters:

Name Type Description Default
subsidy float

The share of the recommended fertiliser that the subsidy pays for.

0.67
bio_target float

The target share of bio-fertiliser in the inputs.

0.0
research float

The funding of research for high-yielding varieties, relative to its normal level.

0.0
training_target float

The target coverage of the farmers by training and extension, from 0 to 1.

0.0
intensity_target float

The target cropping intensity, the crops per year on the rice area.

1.0
label str

The label of the system, which names it when it is nested in another one.

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for the one the system chooses.

'auto'
backend BaseBackend | str

The backend that evaluates the compiled functions, or 'auto' for the one the system chooses.

'auto'

Examples:

>>> from skcomplex.systems.economics.resources import FoodSecuritySystem
>>> FoodSecuritySystem(subsidy=0.0).prepare().system_.elements[0].subsidy
0.0
Source code in src/skcomplex/systems/economics/resources/_food.py
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
def __init__(
    self,
    *,
    subsidy: float = 0.67,
    bio_target: float = 0.0,
    research: float = 0.0,
    training_target: float = 0.0,
    intensity_target: float = 1.0,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.subsidy = subsidy
    self.bio_target = bio_target
    self.research = research
    self.training_target = training_target
    self.intensity_target = intensity_target

GrazingInteraction(label, *, requesters, providers, rule=RandomSearchSpec(), phase='grazing', herders, appetite=1.0, metabolism=0.5, milk=1.0)

Bases: MatchingInteraction[SystemView]

Grazing of the meadow, a matching of the cows with the pastures.

After the matching every cow eats and burns energy. The rule of the matching pairs the cows with the pastures, such as PartnerMatchingSpec('local', 'score', score=GrazingInteraction.score, value='provider'), which pairs every cow, in random order, with the free pasture of most grass in its cell or the cells around it, ties broken at random. A pasture takes one cow, its default quantity of one unit. Every matched cow moves to its pasture and eats up to its appetite as a transfer of grass to its energy, and its herder earns milk for what it ate. Then every cow burns its metabolism and counts in the herd of its herder, and a cow whose energy runs out dies.

Parameters:

Name Type Description Default
label str

The label of the grazing.

required
requesters Role

The path of the group of cows.

required
providers Role

The path of the group of pastures.

required
rule MatchingRule

The spec of the algorithm that pairs the cows with the pastures.

RandomSearchSpec()
phase str | None

The phase the grazing runs in.

'grazing'
herders Role

The path of the group of herders.

required
appetite Annotated[float, closed_open(0, oo)]

The most grass a cow eats in a step.

1.0
metabolism Annotated[float, closed_open(0, oo)]

The energy a cow burns in a step.

0.5
milk Annotated[float, closed_open(0, oo)]

The income of a herder per unit of grass its cows eat.

1.0

Examples:

>>> from skcomplex.systems.economics.resources import GrazingInteraction
>>> GrazingInteraction('grazing', requesters='cows', providers='meadow', herders='herders').appetite
1.0
Source code in src/skcomplex/systems/economics/resources/_commons.py
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
def __init__(
    self,
    label: str,
    *,
    requesters: Role,
    providers: Role,
    rule: MatchingRule = RandomSearchSpec(),
    phase: str | None = 'grazing',
    herders: Role,
    appetite: Annotated[float, RealSet.closed_open(0, oo)] = 1.0,
    metabolism: Annotated[float, RealSet.closed_open(0, oo)] = 0.5,
    milk: Annotated[float, RealSet.closed_open(0, oo)] = 1.0,
) -> None:
    super().__init__(label, requesters=requesters, providers=providers, rule=rule, phase=phase)
    self.herders = herders
    self.appetite = appetite
    self.metabolism = metabolism
    self.milk = milk

match(system)

Pair and feed the cows, then let every cow burn its metabolism.

Every cow is counted in its herd, and it starves.

Parameters:

Name Type Description Default
system SystemView

The system view of the grazing.

required
Source code in src/skcomplex/systems/economics/resources/_commons.py
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
def match(self, system: SystemView) -> None:
    """Pair and feed the cows, then let every cow burn its metabolism.

    Every cow is counted in its herd, and it starves.

    Args:
        system:
            The system view of the grazing.
    """
    super().match(system)
    for cow in cast(list[CowView], system.get_agents('requesters')):
        cow.energy -= system.get_parameter('metabolism')
        self._get_herder(cow).herd += 1
        if cow.energy < 0:
            cow.remove()

score(cow, pasture) staticmethod

Return the score of a pasture for a cow, the grass on the pasture.

Parameters:

Name Type Description Default
cow object

The agent view of the cow.

required
pasture object

The agent view of the pasture.

required

Returns:

Name Type Description
score float

The grass on the pasture, or minus infinity for an agent that is not a pasture.

Source code in src/skcomplex/systems/economics/resources/_commons.py
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
@staticmethod
def score(cow: object, pasture: object) -> float:
    """Return the score of a pasture for a cow, the grass on the pasture.

    Args:
        cow:
            The agent view of the cow.

        pasture:
            The agent view of the pasture.

    Returns:
        score:
            The grass on the pasture, or minus infinity for an agent that is not a pasture.
    """
    del cow
    return float(pasture.grass) if isinstance(pasture, PastureView) else -np.inf

HarvestInteraction(label, *, target, harvesters, effort=0.05, state='n')

Bases: Interaction

Harvest of a stock proportional to the stock and to the number of harvesters.

The rate is -effort * N * n, a rate on the state n of the target whose coefficient counts the members of the group of harvesters, which may live in another subsystem.

Parameters:

Name Type Description Default
label str

The label of the interaction.

required
target Role

The path of the harvested stock.

required
harvesters Role

The path of the group of harvesters, which the harvest counts.

required
effort Annotated[float, closed_open(0, oo)]

The harvest rate per harvester and unit of stock.

0.05
state str

The name of the state of the target that holds the stock.

'n'

Examples:

>>> from skcomplex.systems.economics.resources import HarvestInteraction
>>> HarvestInteraction('harvest', target='land/stock', harvesters='village/farmers', effort=0.05).effort
0.05
Source code in src/skcomplex/systems/economics/resources/_harvesting.py
244
245
246
247
248
249
250
251
252
253
254
255
256
257
def __init__(
    self,
    label: str,
    *,
    target: Role,
    harvesters: Role,
    effort: Annotated[float, RealSet.closed_open(0, oo)] = 0.05,
    state: str = 'n',
) -> None:
    super().__init__(label)
    self.target = target
    self.harvesters = harvesters
    self.effort = effort
    self.state = state

HarvestingSystem(farmers=10, *, effort=0.05, r=1.0, K=1000.0, label='system', solver='auto', backend='auto')

Bases: BaseSystem

A socio-ecological system of farmer agents harvesting a resource.

The resource regrows logistically. The resource settles at K * (1 - effort * farmers / r) when effort * farmers < r, and collapses otherwise. The system has the ODE subsystem land and the agent subsystem village.

Parameters:

Name Type Description Default
farmers int

The number of farmers.

10
effort float

The harvest rate per farmer and unit of stock.

0.05
r float

The growth rate of the resource.

1.0
K float

The carrying capacity of the resource.

1000.0
label str

The label of the system, which names it when it is nested in another one.

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for the one the system chooses.

'auto'
backend BaseBackend | str

The backend that evaluates the compiled functions, or 'auto' for the one the system chooses.

'auto'

Examples:

>>> from skcomplex.systems.economics.resources import HarvestingSystem
>>> [subsystem.label for subsystem in HarvestingSystem().prepare().system_.systems]
['land', 'village']
Source code in src/skcomplex/systems/economics/resources/_harvesting.py
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
def __init__(
    self,
    farmers: int = 10,
    *,
    effort: float = 0.05,
    r: float = 1.0,
    K: float = 1000.0,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.farmers = farmers
    self.effort = effort
    self.r = r
    self.K = K

HerderElement(label, *, income=0.0, herd=0.0, upkeep=0.3, newborn=4.0, quota=UNLIMITED, values=None, size=None, space=None)

Bases: Element

Herder who adds a cow whenever a cow earned more than its upkeep.

It sells one when the herd exceeds its quota. The life cycle investment of the system buys a cow, at a random cell, or sells the first cow the herder owns, and two maps clear the income and the herd the grazing tallies, all member interactions in the phase of herding.

Parameters:

Name Type Description Default
label str

The label of the agent or group.

required
income Annotated[object, closed_open(0, oo)]

The milk income of the herder in the last step.

0.0
herd Annotated[object, closed_open(0, oo)]

The number of cows of the herder in the last step.

0.0
upkeep Annotated[object, closed_open(0, oo)]

The cost of keeping a cow for a step.

0.3
newborn Annotated[object, open(0, oo)]

The energy of a new cow.

4.0
quota Annotated[object, open(0, oo)]

The largest herd of a herder, which a regulator may change.

UNLIMITED
values Mapping[str, object] | None

Further values by name, such as the cells x and y of the members on the meadow.

None
size int | None

The number of herders, or None for one.

None
space BaseSpace | None

The meadow the herders live on, whose axes x and y place them, or None.

None

Examples:

>>> from skcomplex.systems.economics.resources import HerderElement
>>> HerderElement('herders', size=5).size
5
Source code in src/skcomplex/systems/economics/resources/_commons.py
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
def __init__(
    self,
    label: str,
    *,
    income: Annotated[object, RealSet.closed_open(0, oo)] = 0.0,
    herd: Annotated[object, RealSet.closed_open(0, oo)] = 0.0,
    upkeep: Annotated[object, RealSet.closed_open(0, oo)] = 0.3,
    newborn: Annotated[object, RealSet.open(0, oo)] = 4.0,
    quota: Annotated[object, RealSet.open(0, oo)] = UNLIMITED,
    values: Mapping[str, object] | None = None,
    size: int | None = None,
    space: BaseSpace | None = None,
) -> None:
    super().__init__(label, values=values, size=size, space=space)
    self.income = income
    self.herd = herd
    self.upkeep = upkeep
    self.newborn = newborn
    self.quota = quota

HilsaElement(label, *, eggs=0.0, larvae=0.0, juveniles=0.0, yearlings=0.0, adults=0.0, migrants=0.0, spawners=375.0, female_fraction=FEMALE_FRACTION, eggs_per_nest=200000.0, max_nests=MAX_NESTS, spawning_time=SPAWNING_TIME, hatching_time=1.0, larval_time=2.0, river_time=8.0, ocean_time=12.0, adult_ocean_time=12.0, migration_time=2.0, egg_loss=0.99, larval_loss=0.8, juvenile_loss=0.4, first_year_loss=0.3, second_year_loss=0.5, migration_loss=0.25, juvenile_harvest=0.48, adult_harvest=0.8, weight_per_adult=0.82, weight_per_juvenile=0.09)

Bases: Element

Life cycle of the hilsa, with one stock of fish per stage.

It holds the parameters of the stages and the catch.

Parameters:

Name Type Description Default
label str

The label of the element.

required
eggs Annotated[float, closed_open(0, oo), Quantity(fish)]

The eggs in the nests, in millions of fish.

0.0
larvae Annotated[float, closed_open(0, oo), Quantity(fish)]

The larvae in the rivers, in millions of fish.

0.0
juveniles Annotated[float, closed_open(0, oo), Quantity(fish)]

The juveniles in the rivers, in millions of fish.

0.0
yearlings Annotated[float, closed_open(0, oo), Quantity(fish)]

The fish in their first year in the ocean, in millions of fish.

0.0
adults Annotated[float, closed_open(0, oo), Quantity(fish)]

The fish in their second year in the ocean, in millions of fish.

0.0
migrants Annotated[float, closed_open(0, oo), Quantity(fish)]

The adults migrating back to the rivers, in millions of fish.

0.0
spawners Annotated[float, closed_open(0, oo), Quantity(fish)]

The adults about to spawn, in millions of fish.

375.0
female_fraction Annotated[float, closed_open(0, oo)]

The fraction of the spawners that are female and build a nest.

FEMALE_FRACTION
eggs_per_nest Annotated[float, closed_open(0, oo)]

The number of eggs per nest.

200000.0
max_nests Annotated[float, closed_open(0, oo)]

The most nests the spawning grounds hold.

MAX_NESTS
spawning_time Annotated[float, open(0, oo)]

The duration of the spawning, in months.

SPAWNING_TIME
hatching_time Annotated[float, open(0, oo)]

The time the eggs take to hatch, in months.

1.0
larval_time Annotated[float, open(0, oo)]

The time the larvae take to become juveniles, in months.

2.0
river_time Annotated[float, open(0, oo)]

The time the juveniles stay in the rivers, in months.

8.0
ocean_time Annotated[float, open(0, oo)]

The time the fish spend in their first year in the ocean, in months.

12.0
adult_ocean_time Annotated[float, open(0, oo)]

The time the fish spend in their second year in the ocean, in months.

12.0
migration_time Annotated[float, open(0, oo)]

The time the migration back to the rivers takes, in months.

2.0
egg_loss Annotated[float, closed_open(0, oo)]

The fraction of the eggs lost to natural mortality.

0.99
larval_loss Annotated[float, closed_open(0, oo)]

The fraction of the larvae lost to natural mortality.

0.8
juvenile_loss Annotated[float, closed_open(0, oo)]

The fraction of the juveniles lost to natural mortality.

0.4
first_year_loss Annotated[float, closed_open(0, oo)]

The fraction of the fish lost to natural mortality in their first year in the ocean.

0.3
second_year_loss Annotated[float, closed_open(0, oo)]

The fraction of the fish lost to natural mortality in their second year in the ocean.

0.5
migration_loss Annotated[float, closed_open(0, oo)]

The fraction of the adults lost during their migration to the rivers.

0.25
juvenile_harvest Annotated[float, closed_open(0, oo)]

The fraction of the juveniles leaving the rivers that the fishery catches.

0.48
adult_harvest Annotated[float, closed_open(0, oo)]

The fraction of the adults about to spawn that the fishery catches.

0.8
weight_per_adult Annotated[float, closed_open(0, oo)]

The weight of an adult, in kilograms.

0.82
weight_per_juvenile Annotated[float, closed_open(0, oo)]

The weight of a juvenile, in kilograms.

0.09
Source code in src/skcomplex/systems/economics/resources/_fisheries.py
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
def __init__(
    self,
    label: str,
    *,
    eggs: Annotated[float, RealSet.closed_open(0, oo), Quantity('fish')] = 0.0,
    larvae: Annotated[float, RealSet.closed_open(0, oo), Quantity('fish')] = 0.0,
    juveniles: Annotated[float, RealSet.closed_open(0, oo), Quantity('fish')] = 0.0,
    yearlings: Annotated[float, RealSet.closed_open(0, oo), Quantity('fish')] = 0.0,
    adults: Annotated[float, RealSet.closed_open(0, oo), Quantity('fish')] = 0.0,
    migrants: Annotated[float, RealSet.closed_open(0, oo), Quantity('fish')] = 0.0,
    spawners: Annotated[float, RealSet.closed_open(0, oo), Quantity('fish')] = 375.0,
    female_fraction: Annotated[float, RealSet.closed_open(0, oo)] = FEMALE_FRACTION,
    eggs_per_nest: Annotated[float, RealSet.closed_open(0, oo)] = 2e5,
    max_nests: Annotated[float, RealSet.closed_open(0, oo)] = MAX_NESTS,
    spawning_time: Annotated[float, RealSet.open(0, oo)] = SPAWNING_TIME,
    hatching_time: Annotated[float, RealSet.open(0, oo)] = 1.0,
    larval_time: Annotated[float, RealSet.open(0, oo)] = 2.0,
    river_time: Annotated[float, RealSet.open(0, oo)] = 8.0,
    ocean_time: Annotated[float, RealSet.open(0, oo)] = 12.0,
    adult_ocean_time: Annotated[float, RealSet.open(0, oo)] = 12.0,
    migration_time: Annotated[float, RealSet.open(0, oo)] = 2.0,
    egg_loss: Annotated[float, RealSet.closed_open(0, oo)] = 0.99,
    larval_loss: Annotated[float, RealSet.closed_open(0, oo)] = 0.8,
    juvenile_loss: Annotated[float, RealSet.closed_open(0, oo)] = 0.4,
    first_year_loss: Annotated[float, RealSet.closed_open(0, oo)] = 0.3,
    second_year_loss: Annotated[float, RealSet.closed_open(0, oo)] = 0.5,
    migration_loss: Annotated[float, RealSet.closed_open(0, oo)] = 0.25,
    juvenile_harvest: Annotated[float, RealSet.closed_open(0, oo)] = 0.48,
    adult_harvest: Annotated[float, RealSet.closed_open(0, oo)] = 0.8,
    weight_per_adult: Annotated[float, RealSet.closed_open(0, oo)] = 0.82,
    weight_per_juvenile: Annotated[float, RealSet.closed_open(0, oo)] = 0.09,
) -> None:
    super().__init__(label)
    self.eggs = eggs
    self.larvae = larvae
    self.juveniles = juveniles
    self.yearlings = yearlings
    self.adults = adults
    self.migrants = migrants
    self.spawners = spawners
    self.female_fraction = female_fraction
    self.eggs_per_nest = eggs_per_nest
    self.max_nests = max_nests
    self.spawning_time = spawning_time
    self.hatching_time = hatching_time
    self.larval_time = larval_time
    self.river_time = river_time
    self.ocean_time = ocean_time
    self.adult_ocean_time = adult_ocean_time
    self.migration_time = migration_time
    self.egg_loss = egg_loss
    self.larval_loss = larval_loss
    self.juvenile_loss = juvenile_loss
    self.first_year_loss = first_year_loss
    self.second_year_loss = second_year_loss
    self.migration_loss = migration_loss
    self.juvenile_harvest = juvenile_harvest
    self.adult_harvest = adult_harvest
    self.weight_per_adult = weight_per_adult
    self.weight_per_juvenile = weight_per_juvenile

HilsaFisherySystem(spawners=375.0, *, eggs_per_nest=200000.0, juvenile_harvest=0.48, adult_harvest=0.8, migration_loss=0.25, label='system', solver='auto', backend='auto')

Bases: BaseSystem

A hilsa fishery, the life cycle of a migratory fish.

The catch of juveniles and spawners depletes it. Spawning adults lay eggs in nests in the rivers, and the number of nests is limited by the spawning grounds. The eggs hatch into larvae within a month, the larvae become juveniles within two months, and the juveniles stay in the rivers for eight months before they enter the ocean. The fish mature in the ocean over two years, migrate back to the rivers, and spawn. Every stage drains over its duration, and a fixed fraction of its outflow is lost to natural mortality, to the catch of juveniles, or to the catch of spawning adults, while the rest enters the next stage. Fish are conserved, every change of a stage is a flow, and the population settles where the spawning grounds fill, unless the catch keeps the reproduction below replacement. The stages, the durations, and the loss fractions follow the hilsa system of Bala, Arshad and Noh (2017, Chapter 9), with the stocks in millions of fish and time in months.

The system has the stages hilsa.eggs, hilsa.larvae, hilsa.juveniles, hilsa.yearlings, hilsa.adults, hilsa.migrants, and hilsa.spawners, and the flows between the stages, among them hilsa.egg_deposition, hilsa.young_entering_ocean_catch, and hilsa.adult_catch, per month, over months. The observables of the system are the nests hilsa.nests, and the weights hilsa.adult_weight and hilsa.juvenile_weight in tonnes.

Parameters:

Name Type Description Default
spawners float

The initial number of adults about to spawn.

375.0
eggs_per_nest float

The number of eggs per nest.

200000.0
juvenile_harvest float

The fraction of the juveniles leaving the rivers that the fishery catches.

0.48
adult_harvest float

The fraction of the adults about to spawn that the fishery catches.

0.8
migration_loss float

The fraction of the adults lost during their migration to the rivers.

0.25
label str

The label of the system, which names it when it is nested in another one.

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for the one the system chooses.

'auto'
backend BaseBackend | str

The backend that evaluates the compiled functions, or 'auto' for the one the system chooses.

'auto'

Examples:

>>> from skcomplex.systems.economics.resources import HilsaFisherySystem
>>> HilsaFisherySystem(adult_harvest=0.5).prepare().system_.elements[0].adult_harvest
0.5
Source code in src/skcomplex/systems/economics/resources/_fisheries.py
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
def __init__(
    self,
    spawners: float = 375.0,
    *,
    eggs_per_nest: float = 2e5,
    juvenile_harvest: float = 0.48,
    adult_harvest: float = 0.8,
    migration_loss: float = 0.25,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.spawners = spawners
    self.eggs_per_nest = eggs_per_nest
    self.juvenile_harvest = juvenile_harvest
    self.adult_harvest = adult_harvest
    self.migration_loss = migration_loss

LandCellElement(label, *, crop=0.0, distance=0.0, values=None, size=None, space=None)

Bases: Element

Cell of a plain that grows one crop, numbered from 1, or lies idle as crop 0.

Parameters:

Name Type Description Default
label str

The label of the cell or the field.

required
crop object

The initial guess of the crop, which the equation replaces.

0.0
distance object

The distance from the market.

0.0
values Mapping[str, object] | None

Further values by name, or None for none.

None
size int | None

The number of cells, or None for one.

None
space BaseSpace | None

The plain with one cell per site, or None for none.

None

Examples:

>>> from skcomplex.systems.economics.resources import LandCellElement
>>> LandCellElement('cell', distance=3.0).distance
3.0
Source code in src/skcomplex/systems/economics/resources/_land_use.py
53
54
55
56
57
58
59
60
61
62
63
64
65
def __init__(
    self,
    label: str,
    *,
    crop: object = 0.0,
    distance: object = 0.0,
    values: Mapping[str, object] | None = None,
    size: int | None = None,
    space: BaseSpace | None = None,
) -> None:
    super().__init__(label, values=values, size=size, space=space)
    self.crop = crop
    self.distance = distance

MeasuredFisheryElement(label, *, x=0.5, catch=0.0, r0=1.0, sigma_r=1.0, K=1.0, error=0.0, step=0.01, restocking=0.0, size=None)

Bases: Element

Logistic fish stock with a noisy growth rate, harvested by a quota by QuotaHarvestInteraction.

The quota is set from a measurement with an error. Every step of length step is an Euler-Maruyama step of dx = (R0 + sigma_R W) x (1 - x / K) dt - gamma dt, where W is white noise. The fishermen measure x~ = x + e, with a Gaussian error e of standard deviation error, and set the quota gamma = x~ - K / 2, which is never negative unless restocking lets a negative quota release fish. A stock that reaches zero is extinct and stays at zero.

Parameters:

Name Type Description Default
label str

The label of the fishery.

required
x Annotated[object, closed_open(0, oo)]

The fish stock.

0.5
catch object

The quota of the last step, per unit of time.

0.0
r0 Annotated[object, open(0, oo)]

The mean growth rate R0.

1.0
sigma_r Annotated[object, closed_open(0, oo)]

The standard deviation sigma_R of the noise of the growth rate.

1.0
K Annotated[object, open(0, oo)]

The carrying capacity.

1.0
error Annotated[object, closed_open(0, oo)]

The standard deviation of the measurement error.

0.0
step Annotated[object, open(0, oo)]

The length of a step in units of time.

0.01
restocking Annotated[object, closed(0, 1)]

1 to let a negative quota release fish into the stock, 0 to floor the quota at zero.

0.0
size int | None

The number of fisheries, or None for one.

None

Examples:

>>> from skcomplex.systems.economics.resources import MeasuredFisheryElement
>>> MeasuredFisheryElement('fishery', error=0.1).error
0.1
Source code in src/skcomplex/systems/economics/resources/_measurement_errors.py
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
def __init__(
    self,
    label: str,
    *,
    x: Annotated[object, RealSet.closed_open(0, oo)] = 0.5,
    catch: object = 0.0,
    r0: Annotated[object, RealSet.open(0, oo)] = 1.0,
    sigma_r: Annotated[object, RealSet.closed_open(0, oo)] = 1.0,
    K: Annotated[object, RealSet.open(0, oo)] = 1.0,
    error: Annotated[object, RealSet.closed_open(0, oo)] = 0.0,
    step: Annotated[object, RealSet.open(0, oo)] = 0.01,
    restocking: Annotated[object, RealSet.closed(0, 1)] = 0.0,
    size: int | None = None,
) -> None:
    super().__init__(label, size=size)
    self.x = x
    self.catch = catch
    self.r0 = r0
    self.sigma_r = sigma_r
    self.K = K
    self.error = error
    self.step = step
    self.restocking = restocking

OilEconomySystem(resource=1000.0, capital=5.0, *, price=3.0, cost=0.1, growth_goal=0.1, lifetime=20.0, price_table=None, label='system', solver='auto', backend='auto')

Bases: StockFlowSystem

Meadows' oil economy, capital that grows on a nonrenewable resource.

The capital collapses as the resource runs out. The capital grows exponentially while extraction is cheap, peaks as falling yields cut the profit, and declines with depreciation, leaving part of the resource in the ground. The system has the resource oil.resource and the capital oil.capital.

Parameters:

Name Type Description Default
resource float

The initial resource stock.

1000.0
capital float

The initial capital.

5.0
price float

The price of the resource, used without a price table.

3.0
cost float

The operating cost per unit of capital.

0.1
growth_goal float

The largest investment per unit of capital.

0.1
lifetime float

The average lifetime of the capital.

20.0
price_table Sequence[float] | None

The price at the yields 0, 0.1, 0.2, 0.4, 0.6, 0.8, and 1, or None for a constant price.

None
label str

The label of the system, which names it when it is nested in another one.

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for the one the system chooses.

'auto'
backend BaseBackend | str

The backend that evaluates the compiled functions, or 'auto' for the one the system chooses.

'auto'

Examples:

>>> from skcomplex.systems.economics.resources import OilEconomySystem
>>> OilEconomySystem(resource=2000.0).prepare().system_.elements[0].values['resource']
2000.0
Source code in src/skcomplex/systems/economics/resources/_extraction.py
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
def __init__(
    self,
    resource: float = 1000.0,
    capital: float = 5.0,
    *,
    price: float = 3.0,
    cost: float = 0.1,
    growth_goal: float = 0.1,
    lifetime: float = 20.0,
    price_table: Sequence[float] | None = None,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label=label, solver=solver, backend=backend)
    self.resource = resource
    self.capital = capital
    self.price = price
    self.cost = cost
    self.growth_goal = growth_goal
    self.lifetime = lifetime
    self.price_table = price_table

OptimalHarvestingSystem(x=1.0, *, r=1.0, K=1.0, q=1.0, p=1.0, c=0.2, delta=0.1, label='system', solver='auto', backend='auto')

Bases: DynamicalSystem

A logistic resource harvested with the effort that maximises its profit.

The profit is discounted, and the objective law ObjectiveLaw(-profit, controls=[s.target.effort]) maximises it over the effort, which lies between 0 and 1. Run with an optimal control solver, the effort starts at a bound, drives the stock to the level x* where r (1 - 2 x* / K) + c r (1 - x* / K) / (p q x* - c) = delta, holds it there with the effort r (1 - x* / K) / q, and rises to its largest value at the end of the horizon, when the stock left has no value. The system has the stock resource.x, the effort resource.effort, and the observable catch.

Parameters:

Name Type Description Default
x float

The initial stock.

1.0
r float

The intrinsic growth rate.

1.0
K float

The carrying capacity.

1.0
q float

The catchability.

1.0
p float

The price per unit of catch.

1.0
c float

The cost per unit of effort.

0.2
delta float

The discount rate.

0.1
label str

The label of the system, which names it when it is nested in another one.

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for the one the system chooses.

'auto'
backend BaseBackend | str

The backend that evaluates the compiled functions, or 'auto' for the one the system chooses.

'auto'

Examples:

>>> from skcomplex.systems.economics.resources import OptimalHarvestingSystem
>>> OptimalHarvestingSystem(delta=0.05).prepare().system_.elements[0].get_params()['delta']
0.05
Source code in src/skcomplex/systems/economics/resources/_optimal_harvesting.py
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
def __init__(
    self,
    x: float = 1.0,
    *,
    r: float = 1.0,
    K: float = 1.0,
    q: float = 1.0,
    p: float = 1.0,
    c: float = 0.2,
    delta: float = 0.1,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label=label, solver=solver, backend=backend)
    self.x = x
    self.r = r
    self.K = K
    self.q = q
    self.p = p
    self.c = c
    self.delta = delta

PartialAdjustmentInteraction(label, *, target, state='x', goal=0.0, time=1.0, noise=None)

Bases: Interaction

Partial adjustment of a quantity towards a target over an adjustment time.

Economics names it partial adjustment, as of a policy or an investment that closes a gap to its target at a rate. The rate is (goal(ns) - x) / time(ns) of a state x of a target, with optional noise. With a constant goal and time and an additive noise of amplitude sigma, the state follows the Ornstein-Uhlenbeck process dx = (goal - x) / time dt + sigma dW, whose stationary variance is sigma**2 time / 2. A goal, a time, or a noise function takes the namespace of the interaction, whose target holds the values of the target, and a number stands for a constant. A goal that is a number applies to every component of a vector state.

Parameters:

Name Type Description Default
label str

The label of the interaction, unique among the components of its system.

required
target Role

The path of the element or group whose state relaxes.

required
state str

The name of the state of the target that relaxes.

'x'
goal Callable[[SimpleNamespace], object] | float

A function of the namespace that returns the goal, or a number.

0.0
time Callable[[SimpleNamespace], object] | float

A function of the namespace that returns the relaxation time, or a positive number.

1.0
noise Callable[[SimpleNamespace], object] | float | None

A function of the namespace that returns the amplitude of the noise, a number, or None for no noise.

None

Raises:

Type Description
ValidationError

The state is not a name, or a function is neither callable nor a number.

Examples:

>>> from skcomplex.systems.general.elements import NonnegativeElement
>>> from skcomplex.core.systems import System
>>> from skcomplex.systems.economics.resources import PartialAdjustmentInteraction
>>> relaxation = PartialAdjustmentInteraction('relaxation', target='stock', goal=10.0, time=0.5)
>>> system = System(elements=[NonnegativeElement('stock')], interactions=[relaxation])
>>> trajectory = system.prepare().simulate(until=5.0, dt=0.01)
>>> round(float(trajectory.get_values('stock.x')[-1]), 3)
10.0
Source code in src/skcomplex/systems/economics/resources/_food.py
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
def __init__(
    self,
    label: str,
    *,
    target: Role,
    state: str = 'x',
    goal: Callable[[SimpleNamespace], object] | float = 0.0,
    time: Callable[[SimpleNamespace], object] | float = 1.0,
    noise: Callable[[SimpleNamespace], object] | float | None = None,
) -> None:
    super().__init__(label)
    self.target = target
    self.state = state
    self.goal = goal
    self.time = time
    self.noise = noise

PastureElement(label, *, grass=2.0, capacity=2.0, regrowth=0.2, seed=0.05, values=None, size=None, space=None)

Bases: Element

Cell of the meadow whose grass grows back logistically by RegrassingInteraction.

When it is grazed bare, the grass grows from a seed bank.

Parameters:

Name Type Description Default
label str

The label of the agent or group.

required
grass Annotated[object, closed_open(0, oo)]

The grass on the cell.

2.0
capacity Annotated[object, open(0, oo)]

The most grass the cell holds.

2.0
regrowth Annotated[object, closed_open(0, oo)]

The logistic growth rate of the grass.

0.2
seed Annotated[object, closed_open(0, oo)]

The share of the capacity that grows back as if it stood on a bare cell.

0.05
values Mapping[str, object] | None

Further values by name, such as the cells x and y of the members on the meadow.

None
size int | None

The number of pastures, or None for one.

None
space BaseSpace | None

The meadow the pastures live on, whose axes x and y place them, or None.

None

Examples:

>>> from skcomplex.systems.economics.resources import PastureElement
>>> PastureElement('meadow', capacity=2.0, size=4).size
4
Source code in src/skcomplex/systems/economics/resources/_commons.py
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
def __init__(
    self,
    label: str,
    *,
    grass: Annotated[object, RealSet.closed_open(0, oo)] = 2.0,
    capacity: Annotated[object, RealSet.open(0, oo)] = 2.0,
    regrowth: Annotated[object, RealSet.closed_open(0, oo)] = 0.2,
    seed: Annotated[object, RealSet.closed_open(0, oo)] = 0.05,
    values: Mapping[str, object] | None = None,
    size: int | None = None,
    space: BaseSpace | None = None,
) -> None:
    super().__init__(label, values=values, size=size, space=space)
    self.grass = grass
    self.capacity = capacity
    self.regrowth = regrowth
    self.seed = seed

PlantationElement(label, *, forest=490.0, area=10.0, abandoned=0.0, shade_removal=5.0, insects=1.0, yield_normal=5.0, price=40.0, cost=100.0, thinning_cost=20.0, adjustment_time=3.0, abandon_time=4.0, conversion_time=3.0, palm_margin=0.4, thinning_time=8.0, insect_growth=0.6, insect_control=0.3, subsidy=0.0)

Bases: Element

Cocoa land in forest, planted, and abandoned stocks.

The shade is thinned and lets the insects in. Farmers plant forest towards a desired area that grows with the profitability of cocoa, abandon plantations whose yield and profit fall, and leave abandoned land to the forest or convert it to oil palm when cocoa pays less than palm. Removing shade raises the yield and lets the insects grow logistically, and the subsidy keeps the shade and controls the insects. The land flows are transfers within the plantation of the system.

Parameters:

Name Type Description Default
label str

The label of the plantation.

required
forest Annotated[object, closed_open(0, oo), Quantity(land)]

The initial forest land.

490.0
area Annotated[object, closed_open(0, oo), Quantity(land)]

The initial cocoa area.

10.0
abandoned Annotated[object, closed_open(0, oo), Quantity(land)]

The initial abandoned land.

0.0
shade_removal Annotated[object, closed_open(0, oo)]

The initial index of shade removal, from 0 to 100.

5.0
insects Annotated[object, closed_open(0, oo)]

The initial index of insect attack, from 0 to 100.

1.0
yield_normal Annotated[object, closed_open(0, oo)]

The yield per area without insects or thinning.

5.0
price Annotated[object, closed_open(0, oo)]

The farm price of cocoa.

40.0
cost Annotated[object, closed_open(0, oo)]

The operating cost per area.

100.0
thinning_cost Annotated[object, closed_open(0, oo)]

The cost per area of removing all shade.

20.0
adjustment_time Annotated[object, open(0, oo)]

The time to plant towards the desired area.

3.0
abandon_time Annotated[object, open(0, oo)]

The average time before a plantation is abandoned.

4.0
conversion_time Annotated[object, open(0, oo)]

The time abandoned land stays before it returns to forest or turns to oil palm.

3.0
palm_margin Annotated[object, open(0, oo)]

The profitability of oil palm, against which abandoned land converts.

0.4
thinning_time Annotated[object, open(0, oo)]

The time to remove the shade.

8.0
insect_growth Annotated[object, closed_open(0, oo)]

The largest relative growth rate of the insects, reached with all shade removed.

0.6
insect_control Annotated[object, closed_open(0, oo)]

The rate at which the subsidy controls the insects.

0.3
subsidy Annotated[object, closed_open(0, oo)]

The coverage of the subsidy and extension programme, from 0 to 1.

0.0

Examples:

>>> from skcomplex.systems.economics.resources import PlantationElement
>>> PlantationElement('cocoa', subsidy=0.5).subsidy
0.5
Source code in src/skcomplex/systems/economics/resources/_plantations.py
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
def __init__(
    self,
    label: str,
    *,
    forest: Annotated[object, RealSet.closed_open(0, oo), Quantity('land')] = 490.0,
    area: Annotated[object, RealSet.closed_open(0, oo), Quantity('land')] = 10.0,
    abandoned: Annotated[object, RealSet.closed_open(0, oo), Quantity('land')] = 0.0,
    shade_removal: Annotated[object, RealSet.closed_open(0, oo)] = 5.0,
    insects: Annotated[object, RealSet.closed_open(0, oo)] = 1.0,
    yield_normal: Annotated[object, RealSet.closed_open(0, oo)] = 5.0,
    price: Annotated[object, RealSet.closed_open(0, oo)] = 40.0,
    cost: Annotated[object, RealSet.closed_open(0, oo)] = 100.0,
    thinning_cost: Annotated[object, RealSet.closed_open(0, oo)] = 20.0,
    adjustment_time: Annotated[object, RealSet.open(0, oo)] = 3.0,
    abandon_time: Annotated[object, RealSet.open(0, oo)] = 4.0,
    conversion_time: Annotated[object, RealSet.open(0, oo)] = 3.0,
    palm_margin: Annotated[object, RealSet.open(0, oo)] = 0.4,
    thinning_time: Annotated[object, RealSet.open(0, oo)] = 8.0,
    insect_growth: Annotated[object, RealSet.closed_open(0, oo)] = 0.6,
    insect_control: Annotated[object, RealSet.closed_open(0, oo)] = 0.3,
    subsidy: Annotated[object, RealSet.closed_open(0, oo)] = 0.0,
) -> None:
    super().__init__(label)
    self.forest = forest
    self.area = area
    self.abandoned = abandoned
    self.shade_removal = shade_removal
    self.insects = insects
    self.yield_normal = yield_normal
    self.price = price
    self.cost = cost
    self.thinning_cost = thinning_cost
    self.adjustment_time = adjustment_time
    self.abandon_time = abandon_time
    self.conversion_time = conversion_time
    self.palm_margin = palm_margin
    self.thinning_time = thinning_time
    self.insect_growth = insect_growth
    self.insect_control = insect_control
    self.subsidy = subsidy

QuotaHarvestInteraction(label, *, target)

Bases: Interaction

Noisy logistic growth of a fish stock harvested by a quota set from a noisy measurement.

Every step of length step is an Euler-Maruyama step of dx = (R0 + sigma_R W) x (1 - x / K) dt - gamma dt, with the quota gamma = x~ - K / 2 of the measured stock x~ = x + e. All the values are those of the fishery.

Parameters:

Name Type Description Default
label str

The label of the interaction.

required
target Role

The path of the fishery or of the group of fisheries.

required

Examples:

>>> from skcomplex.systems.economics.resources import QuotaHarvestInteraction
>>> QuotaHarvestInteraction('harvest', target='fisheries').target
'fisheries'
Source code in src/skcomplex/systems/economics/resources/_measurement_errors.py
122
123
124
def __init__(self, label: str, *, target: Role) -> None:
    super().__init__(label)
    self.target = target

QuotaRegulatorInteraction(label, *, rule=None, phase=None, regulated=0.0, low=0.5, high=0.8)

Bases: PolicyRuleInteraction[SystemView]

Regulator of the quota of cows per herder.

It halves the quota when the grass runs short and raises it when it recovers. The quota is the value quota of every herder. It halves, down to one cow, when the grass falls below the share low of the capacity of the meadow, and grows by one cow when the grass is above the share high. Without regulation it stays as it is.

Parameters:

Name Type Description Default
label str

The label of the regulator.

required
rule Callable[[SystemView], None] | None

Unused, since the regulator overrides act.

None
phase str | None

The phase the regulator acts in.

None
regulated Annotated[float, closed_open(0, oo)]

One when the regulator changes the quota, zero otherwise.

0.0
low Annotated[float, closed_open(0, oo)]

The share of the capacity of the meadow below which the quota halves.

0.5
high Annotated[float, closed_open(0, oo)]

The share of the capacity of the meadow above which the quota rises by one cow.

0.8

Examples:

>>> from skcomplex.systems.economics.resources import QuotaRegulatorInteraction
>>> QuotaRegulatorInteraction('regulator', regulated=1.0).regulated
1.0
Source code in src/skcomplex/systems/economics/resources/_commons.py
453
454
455
456
457
458
459
460
461
462
463
464
465
466
def __init__(
    self,
    label: str,
    *,
    rule: Callable[[SystemView], None] | None = None,
    phase: str | None = None,
    regulated: Annotated[float, RealSet.closed_open(0, oo)] = 0.0,
    low: Annotated[float, RealSet.closed_open(0, oo)] = 0.5,
    high: Annotated[float, RealSet.closed_open(0, oo)] = 0.8,
) -> None:
    super().__init__(label, rule=rule, phase=phase)
    self.regulated = regulated
    self.low = low
    self.high = high

act(system)

Change the quota with the share of grass left on the meadow.

Parameters:

Name Type Description Default
system SystemView

The system view of the regulator.

required
Source code in src/skcomplex/systems/economics/resources/_commons.py
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
def act(self, system: SystemView) -> None:
    """Change the quota with the share of grass left on the meadow.

    Args:
        system:
            The system view of the regulator.
    """
    if not system.get_parameter('regulated'):
        return
    pastures = cast(list[PastureView], system.get_agents('meadow'))
    share = sum(pasture.grass for pasture in pastures) / sum(pasture.capacity for pasture in pastures)
    for herder in cast(list[HerderView], system.get_agents('herders')):
        if share < system.get_parameter('low'):
            herder.quota = max(1.0, float(np.floor(herder.quota / 2)))
        elif share > system.get_parameter('high'):
            herder.quota += 1

RegrassingInteraction(label, *, target='meadow', phase=None)

Bases: Interaction

Logistic regrowth of the grass of every pasture, from a seed bank when it is bare.

The grass G of a pasture of capacity K grows by r S (1 - S / K) up to K, with the stand S the larger of G and the seed share of the capacity, so a bare cell grows back. The rates r and the seed share are the values regrowth and seed of each pasture.

Parameters:

Name Type Description Default
label str

The label of the interaction.

required
target Role

The pastures whose grass grows.

'meadow'
phase str | None

The phase the grass grows in, or None for the default phase.

None

Examples:

>>> from skcomplex.systems.economics.resources import RegrassingInteraction
>>> RegrassingInteraction('regrowth', phase='growth').phase
'growth'
Source code in src/skcomplex/systems/economics/resources/_commons.py
264
265
266
267
def __init__(self, label: str, *, target: Role = 'meadow', phase: str | None = None) -> None:
    super().__init__(label)
    self.target = target
    self.phase = phase

grow(agent, system)

Grow the grass logistically up to the capacity.

Parameters:

Name Type Description Default
agent PastureView

The pasture.

required
system SystemView

The system.

required
Source code in src/skcomplex/systems/economics/resources/_commons.py
279
280
281
282
283
284
285
286
287
288
289
290
291
def grow(self, agent: PastureView, system: SystemView) -> None:
    """Grow the grass logistically up to the capacity.

    Args:
        agent:
            The pasture.

        system:
            The system.
    """
    stand = max(agent.grass, agent.seed * agent.capacity)
    growth = agent.regrowth * stand * (1 - stand / agent.capacity)
    agent.grass = min(agent.capacity, agent.grass + growth)

RiceBalanceElement(label, *, area_cultivated=68000.0, population=2800000.0, total_land_available=120000.0, planning_time=15.0, land_fraction_lost=0.00085, crop_yield=3.2, birth_fraction=0.025, life_expectancy=65.0, food_per_capita=0.18)

Bases: Element

Rice land and population of a region.

It holds the land available for rice and the rice each person needs. The area cultivated grows towards the land available over a planning time and loses a fraction to housing, roads, and industry, and the population grows by births and falls by deaths, through labelled flows of the system.

Parameters:

Name Type Description Default
label str

The label of the region.

required
area_cultivated Annotated[float, closed_open(0, oo), Quantity(land)]

The area under rice, in hectares.

68000.0
population Annotated[float, closed_open(0, oo), Quantity(people)]

The population.

2800000.0
total_land_available Annotated[float, open(0, oo)]

The land suitable for rice, in hectares.

120000.0
planning_time Annotated[float, open(0, oo)]

The years over which the land suitable for rice is to be covered.

15.0
land_fraction_lost Annotated[float, closed_open(0, oo)]

The fraction of the area cultivated lost every year.

0.00085
crop_yield Annotated[float, closed_open(0, oo)]

The yield of rice, in tonnes per hectare.

3.2
birth_fraction Annotated[float, closed_open(0, oo)]

The births per person and year.

0.025
life_expectancy Annotated[float, open(0, oo)]

The life expectancy, in years.

65.0
food_per_capita Annotated[float, open(0, oo)]

The rice each person needs, in tonnes per year.

0.18

Examples:

>>> from skcomplex.systems.economics.resources import RiceBalanceElement
>>> RiceBalanceElement('region', crop_yield=4.0).crop_yield
4.0
Source code in src/skcomplex/systems/economics/resources/_food_balance.py
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
def __init__(
    self,
    label: str,
    *,
    area_cultivated: Annotated[float, RealSet.closed_open(0, oo), Quantity('land')] = 68000.0,
    population: Annotated[float, RealSet.closed_open(0, oo), Quantity('people')] = 2800000.0,
    total_land_available: Annotated[float, RealSet.open(0, oo)] = 120000.0,
    planning_time: Annotated[float, RealSet.open(0, oo)] = 15.0,
    land_fraction_lost: Annotated[float, RealSet.closed_open(0, oo)] = 0.00085,
    crop_yield: Annotated[float, RealSet.closed_open(0, oo)] = 3.2,
    birth_fraction: Annotated[float, RealSet.closed_open(0, oo)] = 0.025,
    life_expectancy: Annotated[float, RealSet.open(0, oo)] = 65.0,
    food_per_capita: Annotated[float, RealSet.open(0, oo)] = 0.18,
) -> None:
    super().__init__(label)
    self.area_cultivated = area_cultivated
    self.population = population
    self.total_land_available = total_land_available
    self.planning_time = planning_time
    self.land_fraction_lost = land_fraction_lost
    self.crop_yield = crop_yield
    self.birth_fraction = birth_fraction
    self.life_expectancy = life_expectancy
    self.food_per_capita = food_per_capita

RiceFoodBalanceSystem(area_cultivated=68000.0, population=2800000.0, *, total_land_available=120000.0, planning_time=15.0, land_fraction_lost=0.00085, crop_yield=3.2, birth_fraction=0.025, life_expectancy=65.0, food_per_capita=0.18, label='system', solver='auto', backend='auto')

Bases: BaseSystem

Bala's food security model.

Rice land grows towards the land available against a growing population. The area cultivated grows at MAX((total_land_available - area_cultivated) / planning_time, 0) and loses land_fraction_lost of itself every year to housing, roads, and industry. The population grows by birth_fraction per person and falls by one over the life expectancy. The food security level is the rice available, the area times the yield, over the rice required, the population times the rice per capita, and below 1 the region is short of rice. The structure, the equations, and the defaults are those of the STELLA model of Bala et al. (2017, Section 4.11.3), in hectares, people, tonnes, and years. The area rises for about fifty years towards the land available, and the food security rises for about twenty-five years and then falls as the population grows.

The system has the stocks region.area_cultivated and region.population, and the flows region.area_increase_rate, region.land_lost, region.birth_rate, and region.death_rate per year. The observables of the system are region.food_available, region.food_required, and region.food_security.

Parameters:

Name Type Description Default
area_cultivated float

The initial area under rice, in hectares.

68000.0
population float

The initial population.

2800000.0
total_land_available float

The land suitable for rice, in hectares.

120000.0
planning_time float

The years over which the land suitable for rice is to be covered.

15.0
land_fraction_lost float

The fraction of the area cultivated lost every year.

0.00085
crop_yield float

The yield of rice, in tonnes per hectare.

3.2
birth_fraction float

The births per person and year.

0.025
life_expectancy float

The life expectancy, in years.

65.0
food_per_capita float

The rice each person needs, in tonnes per year.

0.18
label str

The label of the system, which names it when it is nested in another one.

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for the one the system chooses.

'auto'
backend BaseBackend | str

The backend that evaluates the compiled functions, or 'auto' for the one the system chooses.

'auto'

Examples:

>>> from skcomplex.systems.economics.resources import RiceFoodBalanceSystem
>>> RiceFoodBalanceSystem(planning_time=10.0).prepare().system_.elements[0].planning_time
10.0
Source code in src/skcomplex/systems/economics/resources/_food_balance.py
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
def __init__(
    self,
    area_cultivated: float = 68000.0,
    population: float = 2800000.0,
    *,
    total_land_available: float = 120000.0,
    planning_time: float = 15.0,
    land_fraction_lost: float = 0.00085,
    crop_yield: float = 3.2,
    birth_fraction: float = 0.025,
    life_expectancy: float = 65.0,
    food_per_capita: float = 0.18,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.area_cultivated = area_cultivated
    self.population = population
    self.total_land_available = total_land_available
    self.planning_time = planning_time
    self.land_fraction_lost = land_fraction_lost
    self.crop_yield = crop_yield
    self.birth_fraction = birth_fraction
    self.life_expectancy = life_expectancy
    self.food_per_capita = food_per_capita

RiceSectorElement(label, *, available_land=0.088, rice_area=0.680647, population=18.1024, potential=6.0, soil_quality=0.99, practice=0.61, training=0.0, bio_fraction=0.0, cropping_intensity=1.0, conversion_time=8.0, discard_rate=0.0085, growth_rate=0.021, consumption=80.0, milling_rate=0.65, subsidy=0.67, farmer_inputs=0.3, research=0.0, potential_limit=10.0, research_time=20.0, regeneration_time=10.0, degradation=0.002, learning_time=5.0, training_target=0.0, extension_time=5.0, bio_target=0.0, transition_time=10.0, intensity_target=1.0, implementation_time=10.0)

Bases: Element

Rice sector of a country.

It holds its land, population, and the factors of the productivity of its rice land. The suitable land is developed into rice area and the rice area is discarded, and the population grows exponentially, through transfers within the sector of the system. Research raises the potential yield towards a limit, chemical fertiliser degrades the soil and fallow regenerates it, and training improves the farming practice through a learning table. The training, the share of bio-fertiliser, and the cropping intensity relax towards their targets through relaxation interactions of the system, which read the targets and times of the sector.

Parameters:

Name Type Description Default
label str

The label of the sector.

required
available_land Annotated[object, closed_open(0, oo), Quantity(land)]

The initial land suitable for rice and not yet developed.

0.088
rice_area Annotated[object, closed_open(0, oo), Quantity(land)]

The initial rice area.

0.680647
population Annotated[object, closed_open(0, oo), Quantity(people)]

The initial population.

18.1024
potential Annotated[object, closed_open(0, oo)]

The initial potential yield.

6.0
soil_quality Annotated[object, closed_open(0, oo)]

The initial soil quality, from 0 to 1.

0.99
practice Annotated[object, closed_open(0, oo)]

The initial quality of the farming practice, from 0 to 1.

0.61
training Annotated[object, closed_open(0, oo)]

The initial coverage of the farmers by training and extension, from 0 to 1.

0.0
bio_fraction Annotated[object, closed_open(0, oo)]

The initial share of bio-fertiliser in the inputs.

0.0
cropping_intensity Annotated[object, closed_open(0, oo)]

The initial number of crops per year on the rice area.

1.0
conversion_time Annotated[object, open(0, oo)]

The time to develop the suitable land.

8.0
discard_rate Annotated[object, closed_open(0, oo)]

The fraction of the rice area discarded per year.

0.0085
growth_rate object

The growth rate of the population.

0.021
consumption Annotated[object, closed_open(0, oo)]

The rice consumption per capita, in kilograms per year.

80.0
milling_rate Annotated[object, closed_open(0, oo)]

The share of paddy that milling turns into rice.

0.65
subsidy Annotated[object, closed_open(0, oo)]

The share of the recommended fertiliser that the subsidy pays for.

0.67
farmer_inputs Annotated[object, closed_open(0, oo)]

The share of the unsubsidised fertiliser that the farmers buy.

0.3
research Annotated[object, closed_open(0, oo)]

The funding of research for high-yielding varieties, relative to its normal level.

0.0
potential_limit Annotated[object, open(0, oo)]

The potential yield that research approaches.

10.0
research_time Annotated[object, open(0, oo)]

The time research takes to reach the limit at its normal funding.

20.0
regeneration_time Annotated[object, open(0, oo)]

The time fallow takes to regenerate the soil.

10.0
degradation Annotated[object, closed_open(0, oo)]

The rate at which chemical fertiliser degrades the soil.

0.002
learning_time Annotated[object, open(0, oo)]

The time training takes to improve the practice.

5.0
training_target Annotated[object, closed_open(0, oo)]

The target coverage of training and extension.

0.0
extension_time Annotated[object, open(0, oo)]

The time the training takes to reach its target.

5.0
bio_target Annotated[object, closed_open(0, oo)]

The target share of bio-fertiliser.

0.0
transition_time Annotated[object, open(0, oo)]

The time the share of bio-fertiliser takes to reach its target.

10.0
intensity_target Annotated[object, open(0, oo)]

The target cropping intensity.

1.0
implementation_time Annotated[object, open(0, oo)]

The time the cropping intensity takes to reach its target.

10.0

Examples:

>>> from skcomplex.systems.economics.resources import RiceSectorElement
>>> RiceSectorElement('rice', subsidy=0.5).subsidy
0.5
Source code in src/skcomplex/systems/economics/resources/_food.py
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
def __init__(
    self,
    label: str,
    *,
    available_land: Annotated[object, RealSet.closed_open(0, oo), Quantity('land')] = 0.088,
    rice_area: Annotated[object, RealSet.closed_open(0, oo), Quantity('land')] = 0.680647,
    population: Annotated[object, RealSet.closed_open(0, oo), Quantity('people')] = 18.1024,
    potential: Annotated[object, RealSet.closed_open(0, oo)] = 6.0,
    soil_quality: Annotated[object, RealSet.closed_open(0, oo)] = 0.99,
    practice: Annotated[object, RealSet.closed_open(0, oo)] = 0.61,
    training: Annotated[object, RealSet.closed_open(0, oo)] = 0.0,
    bio_fraction: Annotated[object, RealSet.closed_open(0, oo)] = 0.0,
    cropping_intensity: Annotated[object, RealSet.closed_open(0, oo)] = 1.0,
    conversion_time: Annotated[object, RealSet.open(0, oo)] = 8.0,
    discard_rate: Annotated[object, RealSet.closed_open(0, oo)] = 0.0085,
    growth_rate: object = 0.021,
    consumption: Annotated[object, RealSet.closed_open(0, oo)] = 80.0,
    milling_rate: Annotated[object, RealSet.closed_open(0, oo)] = 0.65,
    subsidy: Annotated[object, RealSet.closed_open(0, oo)] = 0.67,
    farmer_inputs: Annotated[object, RealSet.closed_open(0, oo)] = 0.3,
    research: Annotated[object, RealSet.closed_open(0, oo)] = 0.0,
    potential_limit: Annotated[object, RealSet.open(0, oo)] = 10.0,
    research_time: Annotated[object, RealSet.open(0, oo)] = 20.0,
    regeneration_time: Annotated[object, RealSet.open(0, oo)] = 10.0,
    degradation: Annotated[object, RealSet.closed_open(0, oo)] = 0.002,
    learning_time: Annotated[object, RealSet.open(0, oo)] = 5.0,
    training_target: Annotated[object, RealSet.closed_open(0, oo)] = 0.0,
    extension_time: Annotated[object, RealSet.open(0, oo)] = 5.0,
    bio_target: Annotated[object, RealSet.closed_open(0, oo)] = 0.0,
    transition_time: Annotated[object, RealSet.open(0, oo)] = 10.0,
    intensity_target: Annotated[object, RealSet.open(0, oo)] = 1.0,
    implementation_time: Annotated[object, RealSet.open(0, oo)] = 10.0,
) -> None:
    super().__init__(label)
    self.available_land = available_land
    self.rice_area = rice_area
    self.population = population
    self.potential = potential
    self.soil_quality = soil_quality
    self.practice = practice
    self.training = training
    self.bio_fraction = bio_fraction
    self.cropping_intensity = cropping_intensity
    self.conversion_time = conversion_time
    self.discard_rate = discard_rate
    self.growth_rate = growth_rate
    self.consumption = consumption
    self.milling_rate = milling_rate
    self.subsidy = subsidy
    self.farmer_inputs = farmer_inputs
    self.research = research
    self.potential_limit = potential_limit
    self.research_time = research_time
    self.regeneration_time = regeneration_time
    self.degradation = degradation
    self.learning_time = learning_time
    self.training_target = training_target
    self.extension_time = extension_time
    self.bio_target = bio_target
    self.transition_time = transition_time
    self.intensity_target = intensity_target
    self.implementation_time = implementation_time

StockElement(label, *, n=1000.0, r=1.0, K=1000.0)

Bases: Element

Renewable stock n with the growth rate r and the carrying capacity K.

StockGrowthInteraction grows it logistically.

Parameters:

Name Type Description Default
label str

The label of the stock.

required
n Annotated[object, closed_open(0, oo)]

The initial stock.

1000.0
r Annotated[object, closed_open(0, oo)]

The intrinsic growth rate.

1.0
K Annotated[object, open(0, oo)]

The carrying capacity.

1000.0

Examples:

>>> from skcomplex.systems.economics.resources import StockElement
>>> StockElement('stock', n=500.0).n
500.0
Source code in src/skcomplex/systems/economics/resources/_harvesting.py
52
53
54
55
56
57
58
59
60
61
62
63
def __init__(
    self,
    label: str,
    *,
    n: Annotated[object, RealSet.closed_open(0, oo)] = 1000.0,
    r: Annotated[object, RealSet.closed_open(0, oo)] = 1.0,
    K: Annotated[object, RealSet.open(0, oo)] = 1000.0,
) -> None:
    super().__init__(label)
    self.n = n
    self.r = r
    self.K = K

StockGrowthInteraction(label, *, target)

Bases: Interaction

Logistic growth of a renewable stock, n' = r n (1 - n / K).

The rate r and the capacity K are the values of the stock.

Parameters:

Name Type Description Default
label str

The label of the interaction.

required
target Role

The path of the stock.

required

Examples:

>>> from skcomplex.systems.economics.resources import StockGrowthInteraction
>>> StockGrowthInteraction('growth', target='stock').target
'stock'
Source code in src/skcomplex/systems/economics/resources/_harvesting.py
86
87
88
def __init__(self, label: str, *, target: Role) -> None:
    super().__init__(label)
    self.target = target

TragedyOfTheCommonsSystem(n_herders=20, *, width=20, height=20, cows=1, quota=None, regrowth=0.2, capacity=2.0, upkeep=0.3, random_state=0, label='system', solver='auto', backend='auto')

Bases: BaseSystem

Herders whose cows graze a shared meadow, until the grass collapses.

Each herder adds cows while a cow pays. Every step every cow moves to the richest pasture it can reach, eats, and earns its herder milk, and the grass grows back logistically. Every herder adds a cow whenever a cow earned more than its upkeep, since the gain of a cow goes to its herder while the cost of the grass it eats falls on all. With more herders than the meadow carries, the herd grows past what the grass sustains, the grass collapses below a tenth of its capacity, and the cows starve, so the herd shrinks after it. A regulator with an adaptive quota of cows per herder, lowered when the grass runs short and raised when it recovers, keeps the meadow from collapse (Hamill and Gilbert 2016 sec. 10.2).

The system has the groups meadow, cows, and herders, whose adaptive parameter quota the regulator regulator changes, and the grazing grazing.

Parameters:

Name Type Description Default
n_herders int

The number of herders.

20
width int

The number of columns of the meadow.

20
height int

The number of rows of the meadow.

20
cows int

The initial number of cows of every herder.

1
quota float | None

The initial quota of cows per herder of a regulator that adapts it, or None for no regulation.

None
regrowth float

The logistic growth rate of the grass.

0.2
capacity float

The most grass a cell holds.

2.0
upkeep float

The cost of keeping a cow for a step.

0.3
random_state int | Generator | None

The seed or generator of the cells of the cows.

0
label str

The label of the system, which names it when it is nested in another one.

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for the one the system chooses.

'auto'
backend BaseBackend | str

The backend that evaluates the compiled functions, or 'auto' for the one the system chooses.

'auto'

Examples:

>>> from skcomplex.systems.economics.resources import TragedyOfTheCommonsSystem
>>> [group.size for group in TragedyOfTheCommonsSystem(4, width=5, height=5).prepare().system_.elements]
[25, 4, 4]
Source code in src/skcomplex/systems/economics/resources/_commons.py
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
def __init__(
    self,
    n_herders: int = 20,
    *,
    width: int = 20,
    height: int = 20,
    cows: int = 1,
    quota: float | None = None,
    regrowth: float = 0.2,
    capacity: float = 2.0,
    upkeep: float = 0.3,
    random_state: int | np.random.Generator | None = 0,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.n_herders = n_herders
    self.width = width
    self.height = height
    self.cows = cows
    self.quota = quota
    self.regrowth = regrowth
    self.capacity = capacity
    self.upkeep = upkeep
    self.random_state = random_state

VonThunenSystem(size=41, *, yields=(4.0, 2.0, 1.0), prices=(3.0, 3.0, 3.5), costs=(1.0, 0.5, 0.5), rates=(0.2, 0.2, 0.2), label='system', solver='auto', backend='auto')

Bases: BaseSystem

A square plain around one market at its centre.

Every cell grows the crop of highest bid rent. A crop of a high yield per cell bids most near the market, and its bid falls fastest with distance, so the land use forms concentric rings whose boundaries lie where the bids of neighbouring crops are equal (Giordano 2024 §7). The system has the states plain.crop and plain.distance.

Parameters:

Name Type Description Default
size int

The side of the plain in cells, one unit of distance each.

41
yields Sequence[float]

The yield of every crop per cell.

(4.0, 2.0, 1.0)
prices Sequence[float]

The price of every crop at the market.

(3.0, 3.0, 3.5)
costs Sequence[float]

The cost of every crop per unit of yield.

(1.0, 0.5, 0.5)
rates Sequence[float]

The transport rate of every crop per unit of yield and of distance.

(0.2, 0.2, 0.2)
label str

The label of the system, which names it when it is nested in another one.

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for the one the system chooses.

'auto'
backend BaseBackend | str

The backend that evaluates the compiled functions, or 'auto' for the one the system chooses.

'auto'

Examples:

>>> from skcomplex.systems.economics.resources import VonThunenSystem
>>> trajectory = VonThunenSystem().prepare().simulate(until=1.0)
>>> sorted(set(trajectory.get_values('plain.crop')[0].ravel().tolist()))
[0.0, 1.0, 2.0, 3.0]
Source code in src/skcomplex/systems/economics/resources/_land_use.py
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
def __init__(
    self,
    size: int = 41,
    *,
    yields: Sequence[float] = (4.0, 2.0, 1.0),
    prices: Sequence[float] = (3.0, 3.0, 3.5),
    costs: Sequence[float] = (1.0, 0.5, 0.5),
    rates: Sequence[float] = (0.2, 0.2, 0.2),
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.size = size
    self.yields = yields
    self.prices = prices
    self.costs = costs
    self.rates = rates