04 TpLab V2.07
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
WHAT IS IT?
TpLab - This is the third of a series of three planned models in a study of the maximum power principle (MPP) - the other two models being OamLab and MppLab. In TpLab energy arrives in a steady stream from the Sun and is captured in plants that produce fruit, which appears randomly in dales in the forest. Blind nomadic seekers roaming the forest, each according to their own heuristic search strategy, seek the dales currently having food, and harvest it. The strategies start as ineffective bland heuristics, and evolve to be much more sophisticated. In the most simple scenario, all actions are purely instinctive. But an ability to have beliefs influence behaviour is built into the genes, and belief systems evolve within the societies of seekers. These teleological belief systems can over-rule instinctual behaviours. What happens to seekers of fruit that hold beliefs too tightly? What happens to belief systems that are inconsistent with reality? Under what circumstances can such erroneous belief systems persist? What happens in societies that share a dialectic across multiple belief systems? Can the seekers of fruit become seekers of truth and wisdom?
TpLab, short for Teleological Pruning Laboratory, demonstrates evolutionary processes that shape the belief systems of a society to align with the effects of the Lotka/Odum Maximum Power Principle (MPP). That is, the belief systems are shaped to produce an overall system that functions at the highest rate of consumption of matter and energy that is consistent with the available resources.
MAXIMUM POWER PRINCIPLE (MPP) - It is clear that, when isolated and left alone, all systems die, run down, erode, decay and/or dissipate their matter and energy. This process is closely associated with the phenomenon of entropy production, and the 2nd law of thermodynamics (sometimes referred to as the maximum entropy principle, or MEP) easily describes how this happens. Any such energetically isolated system automatically alters and reconfigures itself, moving through a series of ever more probable states a trajectory of ever increasing entropy, until a most probable configuration or state of maximal entropy is achieved. This state of maximal entropy is usually characterized by an excess of sameness, a lack of structures, shapes or spatial variations, and by characteristic distributions of energies among the parts. Once having achieved such a configuration, the isolated system then remains in a state of maximal entropy (a most probable state) forever after. However, when we look around ourselves, virtually everything we see is characterized by remarkable improbable variety, a plethora of structures and shapes, and turbulent distributions of energy. Clearly, when a system is not isolated and left alone, there is another dynamic able to overpower the 2nd law and undo its nasty work. Such is the nature of the proposed 4th law of thermodynamics. A.J. Lotka, H.T. Odum and R.C. Pinkerton called this the Maximum Power Principle (MPP). H.T. Odum (1924-2002) went on, over four decades, to argue that the MPP is the best candidate for the fourth law of thermodynamics, having explanatory value for such things as ecosystems, economies, and other self-organizing systems. However, in spite of the fact that there is plenty of anecdotal evidence in support of the concept, it remains little understood, and little studied it seems. The MPP says (my words) that any self-organizing system that is open with respect to a flow of energy will configure itself to store/consume/use energy at the maximum rate possible. This model is a "laboratory" in which I can study the nature of the MPP.
This model is the third "laboratory" produced in my personal study of the existence and nature of the MPP. In that study, it has become apparent to me that, through the processes of natural selection, the MPP not only shapes our genes to enhance global consumption, but it also aligns our belief systems to the same end. Those beliefs and practices that stand in the way of increased consumptive power of our emerging global society are pruned away, and those that enhance the consumptive power of global society spread and come to dominate society. So, in like manner to the way our genes are pruned, like the branches of a wild apple tree, our belief systems are also pruned. I refer to this process as Teleological Pruning (or just TP). TP, being a sub-dynamic of the MPP, is sometimes herein referred to as the MPP/TP.
TELEOLOGICAL PRUNING (MPP/TP) - The purpose of this model is to take the study of the MPP into the realm of social effects. It is a desktop laboratory for the study of the MPP/TP. In its broadest interpretation, the MPP says (my words) that any self-organizing system that is open with respect to a flow of matter and energy will continuously reconfigure itself to store/consume/use energy at the maximum rate possible, consistent with available sources of matter and energy. In a variety of diary notes that I have written in an attempt to understand the MPP, I have developed an opinion about just how this affects socially. Not only are our genes shaped to effect this end, but our national political and social structures, our technologies, and our belief systems, plans and practices are also shaped to enhance the overall flow and consumption of matter and energy by the global economy. This even shapes the political and economic organs of global governance, and the political and economic theories that inspire them. It is highly recommended that interested people read my diary notes (referenced below) prior to studying this model.
Conceptual Development - TpLab is being written as part of a personal study of the dynamics of sustainable economics. To understand where and how TpLab fits in, I need to recount some past history. My earliest model economy was a purely biophysical ecosystem model called PSoup (short for Primordial Soup) in which the dynamics of evolution could be demonstrated (Ref D). That was based on a model called Simulated Evolution (SE) by Dr Michael Palmiter (Ref E). In that PSoup model, blind agents compete for limited amounts of energy, and they evolve a nuanced 8-parameter heuristic search pattern that is ever more effective in locating unseen resources. The 8-parameter search pattern can be drawn on the eight points of the compass in a diagram I call a clock face. In a PSoup arena, the MPP, via natural selection, shapes the population to function at remarkably high rates of consumption. I have been using that ecological model as the foundational basis of several agent-based models over the past 15 years, and know it well. SE is the basis of PSoup, ModEco, MppLab (Refs D, F & I below) - and now TpLab.
For TpLab I decided to take the compound genes which encode the agent's heuristic search pattern, and incorporate within them a parallel belief system which modifies the phenotype of each agent in way that the belief system directly enhances or reduces the effects of each gene. The belief system has the same 8-parameter structure as the genetic material, and is super-imposed over the genetic material, but identifiable as a distinct component within the compound gene. It can be manipulated independently of the genetic material, but, at the same time is subject to natural selection through the shared phenotype. But, there is a difference: the belief systems can be modified by learning experiences over the lifetime of the agent, or by social sharing, whereas the genomes are cast at birth and unchanging throughout life. By this means, the basic ecological model of PSoup is converted into a social model in TpLab.
The BIG Question - Why consider the phenomenon of teleological pruning? This is driven by the question that many scientists have considered in recent years. In this modern world, why is economic theory so clearly unscientific, and how does it manage to remain resistant to all attempts to make it science-based? For example, in a world that is clearly depleted of most of its great treasures and on the brink of ecological collapse, to cure these global ills political and economic theory still recommends - indeed demands - an endless pattern of consumptive growth. This appears to be sheer madness, but there are few asking why this emperor has no clothes.
My FINAL answer - All those who believe that something must be done to avert the coming catastrophe are participating in a belief system that is not aligned with the effects of the MPP. That is to say, their belief system does not support the ever increasing rate of consumption of matter and energy until the resources are totally depleted. That belief system, itself, is subject to evolutionary pressures, and is non-adaptive in an evolutionary sense, and is extirpated by natural selection. Any economic or political theory that incorporates such obstructive beliefs is also extirpated by natural selection. Modern political and economic theory is then impervious to all attempts to put science into it. That is MY theory that I call "Teleological Pruning" (i.e. pruning of our theories, purposes and plans by natural selection).
TpLab is a hybrid system, having two intimately linked sub-systems - a biophysical sub-system encoded in a genome, and a teleological sub-system encoded in a set of beliefs:
- In the biophysical sub-system, genes have fixed structure at birth, behavior is encoded as heuristic patterns in genes, and learning happens as the genes and the populations that hold them evolve, generation after generation. Agents are born, struggle for survival, die of hunger or old age, and reproduce only when old enough and healthy enough.
- In the teleological sub-system, agents hold beliefs which alter their genome-derived behaviour. These alterations in behaviour make them more or less efficient at finding food than might be expected from the heuristic encoded in their genome.
- Success is determined by behaviour derived from both the biophysical genome and from the parallel belief system.
Research Questions - Here are my research questions for TpLab:
- Can I effectively model a society which is a hybrid between a biophysical ecosystem and a teleological system?
- Can I demonstrate teleological pruning convincingly? Do the belief systems always align with the heuristic search patterns that evolution produces in the genomes?
- Can desired and potent belief systems that are contrary to the effects of the MPP (e.g. we should not do it that way) nevertheless continue to persist?
Unfortunately, I believe that the answers that come out of this version of TpLab are: "Yes!", "Yes!" and "It seems not!".
HOW IT WORKS
There are several scenarios which all work in a similar fashion, except for key minor design differences. So, I will cover the common design details first, then outline the differences by scenario. Variables and features are enclosed in square [brackets]. Those that are under direct user control, via sliders, are also in [bold].
Nrg - energy, referred to in the model as nrg, exists only in the form of fruit in the arena and nrg in the bodies of the agents. A flux of nrg comes from the Sun at the start of each tick, is deposited into fruit, is eaten by agents, and is expended by agents. There are two mechanisms that throttle the rate of inflow of nrg. There is a hard maximum amount of [Sun-nrg-per-tick] of inflow. However, the maximum amount of nrg that comes from the Sun may also be limited by the size and state of the arena. The amount that arrives per tick can be estimated using the formula [Nrg Flux] = [Number of empty cells] X [Prob-of-deposit] X [nrg-per-deposit]. The actual nrg flux per tick is the lesser of those two amounts, and that determines the carrying capacity of the arena. That flux of nrg is available to be expended by the agents in an amount of [c2-epm-parm] units of nrg per agent per move.
Seekers - the only breed of agents in this model is called Seekers. They are seekers of energy-rich green fruit that appears in the brown arena at random times and random places. But, the seekers are blind and cannot sense the nearby existence of fruit unless it occupies the same cell in which they stand. Their efficiency in finding fruit depends on the heuristic search pattern they undertake, in competition with their contemporaries. Those with a more effective search pattern will have a survival advantage over the others. Seekers are born, move, feed, and live or die. Few live more than 800 ticks, and a typical run of 100,000 ticks spans the lives of over 100 generations of seekers. All of the characteristics of the lives of these agents are encoded in two sets of genes called chromosomes #1 and #2.
Chromosome #1 - c1 - This chromosome contains eight compound genes built in a fashion first used by Dr Michael Palmiter, the author of Simulated Evolution (Ref E). In Dr Palmiter's design, a compound gene had two fundamental components that I label [B] and [G], and store in each seeker in lists called c1-bases and c1-genes. Interpretation of each of these compound genes requires two calculations. The [S]trength of the gene is calculated as the base [B] raised to the power [G]. This can be written as [Si]=[Bi]^[Gi], where 0 <= i <= 7. Then the [P]henotypic character is the relative strength, calculated as the strength [S] of the gene divided by the sum of all eight strengths of all eight genes, written as [Pi]=100x[Si]/SUM([Sj]). Seekers reproduce via fission, so each mother has two daughters, and perishes in the act, splitting her heritage of nrg between the two. The values of [B] and [G] might possibly mutate (change randomly) by a small amount during reproduction. The probability of mutation is set by the slider [prob-of-mutation].
In TpLab there is one additional fundamental component that has been added to each of the eight compound genes - and that is the [L]earned belief. [L] is added to [G] before calculating the [S]trength, so [Si]=[Bi]^([Gi]+[Li]). [Pi] is calculated the same way as before.
The use and interpretation of these genes is described below.
Chromosome #2 - c2 - This chromosome contains the six genes that control biological functions. In this model, these genes are static and do not change, but to maintain similarity with Palmiter's SE model, I encode them into each agent. The six genes are:
- [c2-dat-parm] - Death Age Threshold - Seekers that reach this age (in ticks) die of old age. Either DAT or DET cause death.
- [c2-det-parm] - Death Energy Threshold - Seekers whose energy level falls below this number (in nrg units) die of hunger. Either DAT or DET cause death.
- [c2-rat-parm] - Reproductive Age Threshold - Seekers that reach this age are eligible to reproduce. RAT and RET but both be appropriate for reproduction.
- [c2-ret-parm] - Reproductive Energy Threshold - Seekers that reach this nrg level are eligible to reproduce. RAT and RET but both be appropriate for reproduction.
- [c2-epm-parm] - Energy Per Move - Every agent expends this many nrg units per move.
- [c2-epa-parm] - Energy Per Agent - Seekers cannot harvest fruit that will cause the nrg level to exceed this amount.
C1 Phenotype - The search pattern of the agents is controlled by the C1 genes. If you number the eight genes from 0 to 7 then they can be arranged in a pattern that I call the clock face. With each tick of the model, each agent randomly activates one of its genes, turns to the right an amount equal to that gene number times 45 degrees, then steps forward to feed. So, it always enters one of the eight cells that surround it. When a seeker moves, it first determines which of the eight genes is expressed, it turns to the right by the appropriate angle designated by the expressed gene, and then steps forward and attempts to feed. As shown in the following diagram, the ultimate effect of each of the genes is:
- 0 - 0 degree turn - F - (step forward),
- 1 - 45 degree turn - FR - (step forward to the right),
- 2 - 90 degree turn - R - (step to the right),
- 3 - 135 degree turn - BR - (step back to the right),
- 4 - 180 degree turn - B - (step backward),
- 5 - 225 degree turn - BL - (step back to the left),
- 6 - 270 degree turn - L - (step to the left), or
7 - 315 degree turn - FL - (step forward to the left).
Gene #s Gene Interpretations ------------ --------------- | 7 0 1 | | FL F FR | | | | | | 6 2 | | L R | | | | | | 5 4 3 | | BL B BR | ------------ ---------------
The mechanism used to decide which gene is expressed is the product of Dr Palmiter's genius. The [probability of expression of each gene 'i'] is calculated using the phenotypic values [Pi] with this formula: [Pi]=[Si]/SUM([Sj]) for 0 <= i <= 7. As an example, suppose the eight [S]trengths are 1, 1, 1, 1, 2, 1, 1 and 1. The 1s are calculated as 2^0, and the 2 is 2^1. Then gene 4 is twice as strong as the others, and has a probability of expression [Pi]=100x(2/9), while the others have a probability of expression of [Pi]=100x(1/9). Both are expressed as percentage probabilities.
An almost bland C1 chromosome.
Gene # (i=) 0 1 2 3 4 5 6 7
------ -------------------------------
[Bi] 2 2 2 2 2 2 2 2
[Gi] 0 0 0 0 1 0 0 0
------ -------------------------------
[Si]=[Bi]^[Gi] 1 1 1 1 2 1 1 1
[Pi]=100x[Si]/SUM([Sj]) 1/9 1/9 1/9 1/9 2/9 1/9 1/9 1/9 (all x100)
All scenarios start with a bland set of C1 genes - i.e. [Bi] = 2; [Gi] = 0; and [Si] = 1 for all i. All genes in a bland C1 chromosome have an equal probability of expression in each turn. This results in a search pattern that amounts to a random walk. Such a walk tends to deplete the local resources for each seeker and leads to death, unless all seekers are equally bland and there is lots of nrg flowing in to replenish locally depleted nrg sources.
Not long after a run starts, the [Bi]s and [Gi]s mutate slightly, minor alterations in search patterns appear, and competitive advantages emerge. Different values of [Bi] and [Gi] across a genome represent different heuristic search patterns. Drawn from my experience with PSoup (Ref D), here are a few phenotypic search patterns that may appear:
Notable Phenotypic Search Patterns
Arrow Jitterbug Bent Arrow Dodger
----------- ----------- ----------- -----------
| ^ | | | | \\ | | \ / |
| | | | | | \\ | | \ / |
| | | | | | | || | | | | |
| | | | | | | | |
| | | V | | | | |
----------- ----------- ----------- -----------
Those compound genes not shown are very small, having a negative value for [Gi], and are expressed very rarely. Natural selection chooses the most effective search patterns.
- The Arrow has a strong gene 0, and charges almost straight forward relentlessly. It dominates a wrapped arena (i.e. wrapped at the edges) but is gradually reduced in numbers in a unwrapped or boxed in arena.
- The Jitterbug, has a strong gene 4, jumps back and forth between two cells, and is quickly extirpated as soon as resources become scarce. It persists only when there is energy to spare.
- The Bent Arrow has a strong gene 1 or gene 7, and tends to be an unstable transitional form on the evolutionary path to an arrow or a dodger. It travels in wide sweeping circles that perform a random walk in slow time, as lesser genes are occasionally expressed.
- The Dodger has two strong genes, genes 1 and 7. It dodges forwards in a jagged path that wanders in a far-ranging brownian-like motion. It eventually dominates in arenas in which there are a lot of impediments to movement, such as an unwrapped (boxed in) arena.
Environments can be created in which other patterns emerge as the dominant form in a steady-state environment. In Scenario 0 of TpLab (discussed below) I expect we will see arrows and dodgers as the arena may be either wrapped or unwrapped. The belief systems inject a bias towards a different search pattern. The research questions revolve around this: What heuristic search patterns, if any, will emerge and become dominant in scenarios 1 through 3?
Belief Systems - I have injected a belief system into Palmiter's genes as follows. There are eight learned belief values [Li] superimposed upon and stored along with the gene values [Gi]. The strength of each compound gene 'i' is then calculated as [Si] = [Bi]^([Gi]+[Li]), and the [Pi]s are calculated as usual. The [Pi] values are used in the same way to determine which gene is expressed for any given turn.
The [Bi]s, [Gi]s and [Li]s mutate on reproduction, but the [Li]s also can change through social interaction. In two scenarios the [L]earned belief values are inherited from the mother and established for life for that agent. In two scenarios they are shared within the society, and can spring to dominance or wane to insignificance.
An almost bland C1 chromosome.
Gene # (i=) 0 1 2 3 4 5 6 7
------ -------------------------------
[Bi] 2 2 2 2 2 2 2 2
[Gi] 0 0 0 0 1 1 0 0
[Li] 0 0 0 0 1 -1 0 0
------ -------------------------------
[Si]=[Bi]^([Gi]+[Li]) 1 1 1 1 4 1 1 1
The belief system works as follows. The [L]earned belief values are interpreted as moral convictions, or beliefs, or preferences, purposes, plans or intentions. The emulate free-will decisions of the seekers. There is one ultimately dominant search pattern that can be encoded in the [Bi]s and [Gi]s. Each learned belief [Li] encodes what the seeker believes should be done to improve the outcome of a search, and the contribution to the [S]trength modifies the seeker's behaviour - modifies the actual search pattern. The learned belief might enhance the effects of a [G]ene, as shown for [G4] in the above diagram, or it might cancel its effects, as shown for [G5]. It can be read as "I, the seeker, have learned to believe that I will find more fruit if I turn 180 degrees more often, and turn 135 degrees less often.
Those learned beliefs that align with the ultimately dominant search pattern are TRUE BELIEFS, while those that disagree with the dominant search pattern are FALSE BELIEFS. So, while the seekers are seeking fruit, they are also collectively seeking for the TRUTH - seeking wisdom. According to the MPP, truth is defined by evolution and natural selection as that pattern that leads to the highest rate of consumption of nrg by the system. All learned belief systems that are not aligned with that dominant consumptive pattern must evolve and conform to it, or be rendered impotent.
User Interface - The user interface is organized into several panels, as follows:
- PANEL 01 - The Model - Contains the arena where the seekers live, and the basic tools to select a scenario, with setup and go buttons.
- PANEL 02 - Advanced System Setup Parameters - Contains the sliders that can be used to manage or modify the scenarios. Most key parameters are available for user experimentation, but default parameters can be retrieved.
- PANEL 03 - Debug and Data Collection Tools - Contains a variety of tools used during development that may not be of interest to users. For those experienced with NetLogo, and who wish to study or modify this model, they remain there for your use.
- PANEL 04 - Clock Face - Averages, 8 Compound Genes - Contains a simulation of the clock face showing the averages for each of the five components of each of the eight compound genes.
- PANEL 05 - Population Graphics - Contains graphs that display population counts broken out by learned belief affiliations and by tribal affiliations (see discussion of scenarios below).
- PANEL 06 - Energy Graphics - Contains graphs that display various aspects of the the nrg stocks and flows, with break out by learned belief affiliations and by tribal affiliations (see discussion of scenarios below).
- PANEL 07 - Average Values - C1 Genes - By Component, By Gene # - Contains five graphs, one for each type of component.
- PANEL 08 - Time Lines - Power and EROI (Moving Averages) - These graphs provide a peek into the response of EROI and power to the evolution of the society.
- PANEL 09 - Nrg & Age Histograms, and Causes of Death - The nrg histogram displays the usual Maxwell-Boltzmann distribution of wealth (in this case - nrg), and other graphs are of mild interest.
SCENARIOS - There are four scenarios available:
- SCENARIO 0 - Society With 0 Beliefs - In this society all [Li]s are set to zero, and stay at zero throughout a run. This replicates the pure biophysical demonstration of evolution as first demonstrated by Dr Palmiter in Simulated Evolution, and as replicated in PSoup. There are no learned belief affiliations, and no tribal affiliations. It is every seeker for herself. Arrows and bent arrows dominate.
- SCENARIO 1 - Society with 8 Beliefs - This is the same as Scenario 0 except each seeker is initially endowed with a single learned belief (i.e. one Li != 0) which is unchanging throughout life, and is passed on to offspring. These represent an unchanging belief that one gene should have more weight that all of the rest. This scenario poses the question "If an affiliation of seekers holds fast to a learned belief that is irreducible in effect, and poorly aligned with the effects of evolution, can it survive?"
- SCENARIO 2 - Society With Wisdom Sharing - In this scenario, which starts out similar to Scenario 1, the seekers are able to learn - to adjust their learned beliefs as life proceeds. Each seeker is a member of an affiliation of seekers having the same learned belief - that we can call a belief affiliation. A belief affiliation might be considered to be like a professional association. When seekers of the same belief affiliation meet, the eldest (the guru) can pass wisdom to the others. Essentially, the [Li] of the younger seekers is adjusted to be more like the [Li] of the guru.
- SCENARIO 3 - Society With Tribal Bonds - This is like Scenario 2, but each seeker belongs to two social affiliations. All seekers belong to a belief affiliation - of which there are a maximum of eight. In addition, each seeker belongs to a tribal affiliation. Each tribe originally includes seekers from all eight belief affiliations, and so is collectively agnostic in outlook. You might consider them to be communities of seekers having a common interest in survival, such as might exist in a village, or tribe, or group of lifelong friends. Seekers can seek professional wisdom from gurus having a common learned belief, as in Scenario 2. However, they can also seek wisdom from tribal elders of their own tribe, in connection with the elder's own belief affiliation. So, in this scenario a seeker may eventually hold beliefs of various strengths outside of their own inherent belief affiliation, and pass that very varied belief system on to its offspring.
HOW TO USE IT
You have heard, I suppose, of one-player games. One of my tutored students calls programs like this a zero-player game. You set the parameters, you start it, and you get yourself a glass of port, and sit and watch it develop.
There are four different scenarios, as described above, and each of those can be run with different random number seeds.
To perform a run of the model:
- In PANEL 1 select a scenario options;
- Select a random seed;
- Enter a 'tick' at which you want the run to stop;
- Optionally, go to PANEL 2 and adjust any of the advanced controls;
- Back on PANEL 1, click on the Setup button to configure the system according to the scenario chosen;
- At the top of PANEL 1, adjust the speed to maximum; and
- Click on the Go button.
More adventurous users might scroll to the right and find the panel of "advanced" sliders which can be used to alter a number of parameters of the model. This is not recommended until you understand the standard operation of the model, but there is a lot to learn there. Many combinations of these sliders will be immediately fatal to the population. I have not built in fail-safe code. But if you adjust them a little, you will see things happen. Their effect is explained in some detail in the user documentation (Ref K). The 'reset defaults' button found there will bring you back to ground zero if need be.
The following process will show the progressive effects of belief systems, and the social spread of wisdom:
- Run scenario 0 (Society With 0 Beliefs) two or three times, to 15,000 ticks each, and watch the difference between the evolution of the forward-motion genes (green) and the backward-motion genes (red). This can be seen best in the graph "Average [P]henotypic Values" in PANEL 6. In this scenario belief systems have absolutely no effect. This is the baseline scenario against which all others should be compared.
- Predict what you think will happen when every seeker has a strong unalterable preference for turning a given distance. Run scenario 1 (Society With 8 Beliefs) once, to 15,000 ticks. Compare the results with those noted in scenario 0.
- Predict what you think will happen when younger seekers can strengthen or reduce their learned belief by contact with older 'wiser' seekers holding the same views. Run scenario 2 (Society With Wisdom Sharing) once, to 15,000 ticks. Again, compare the results with those noted in previous scenarios.
- Now, predict what you think will happen when seekers seek wisdom not only from those with the same belief affiliation, but also from other elders in their own tribe having very varied learned beliefs. Then, run scenario 3 (Society With Tribal Bonds) to 15,000 ticks, two or three times. Take particular note of the graph showing ten tribes. Note that the colour scheme for 'tribal affiliations' is different from the colour scheme for 'belief affiliations'.
THINGS TO NOTICE
- Note the effects of learned beliefs that align with and enhance the evolution of an effective search pattern, and those that are misaligned, and detract from such patterns.
THINGS TO TRY
SEEDS - Note the behaviour of the system for the same scenario that differ only by different random seeds.
EXPERIMENTATION - For any scenario, use the special tools in PANEL 2 to impose a learned belief upon half of the population.
A VIEW INSIDE - [ NOTE: Do not let this run for a long time. It generates very large debug log files in a short time.] This is a four step process: (Step 1) Open the command centre by clicking on the teeny tiny upwards-pointing arrow at the bottom left of the screen. (Step 2) Then when the command centre appears at the bottom of the screen, click on the 'upsize' and 'clear' buttons at the top right of the command centre. (Step 3 ) Then use the debug button and the associated 'chooser' (scroll the view screen to the right to find these in PANEL 3) to turn on debug reporting for one or all of the steps. (Step 4 ) Click on 'one tick'. Then scroll through the debug info that has been written into the command centre log.
DATA EXPORT - Right click on any of the graphs, and choose export. Or, open the command centre as described above, and in the observer command line input box at the very bottom of the screen, enter the command EXPORT-WORLD "filename.CSV", where filename is a name of your choosing. I suggest, that e.g. if the model is at tick 35, the filename might be "world35.CSV". The quotes are needed. Then, use MS Excel, or a similar spreadsheet to load that file. Every piece of data in the model will be found there somewhere in the output. These 'whole world' files can be loaded with MS Excel. They can also be re-loaded back into TpLab. Or, you could use the tools I have built to augment those native NetLogo abilities. Click on the "Record Selected Plots" button to create CSV files for seven key plots.
ALL OF THE WAY INSIDE - There are key routines in the code that provide insight into how the model operates. Go to the code tab and search for each of these strings, including the associated hyphens: -own, do-, -initialize-, -mutate-, or -find.
EXTENDING THE MODEL
Should I find the time and inspiration, TpLab will be modified to more clearly present the effects of the Maximum Power Principle (MPP), the study of which lead directly to its development. However, my goal here, to-date, has been to explore the nature of 'Teleological Pruning' in an evolving society. I.e. it has been to explore how our belief systems are subject to the same evolutionary pressures as our genes, but operating at a much higher speed. Our genes are resilient, and take generations to change, but our belief systems are relatively malleable.
A first step would be to import some of the logic around nrg transformations from MppLab into this model. Then the herbivorous seekers would become heterotrophs, eating either fruit or animals. However, I am unsure how I would impose a belief system on them, and how it could be monitored in an insightful way.
RELATED MODELS
This model is one of a series of models that have been developed as part of a personal exploration of the dynamics of sustainable economies. They include:
PSoup - Written in C++, this model explores the nature of evolutionary forces in a purely biophysical economy (Ref D). Based on a previous model called Simulated Evolution by Dr Michael Palmiter, PSoup places a number of bugs into a primordial soup and tracks their development. Offering scenarios at many levels, it demonstrates a variety of effects of evolution from simple development of effective food search patterns in the lowest levels, to development of the five main senses, genetic cross-over and sexual reproduction. The amazing observation, for me, coming out of this model was the speed and certainty of the development of complexity. Whenever a complex option was made available in the potential genetic space of the bugs, it was explored and very complex interactions between a cohort of highly varied genotypes would emerge. I also learned, from this model, that a constant flow of energy was a necessary condition for a sustainable biophysical economy, and a necessary pre-cursor for the emergence of complexity.
ModEco - There are two versions of ModEco. Written in C++, the first-written version of ModEco is a hybrid economy consisting of a PSoup-like biophysical economy joined to a financial economy (Ref F1). In ModEco every transfer of matter and/or energy from agent to agent is facilitated by a reciprocal transfer of money. Again, as long as there is a consistent flow of energy, the economy evolves towards a steady-state biophysical condition. However, sustainability of the financial economy has proven to be a very elusive property. It was discovered that economic sustainability was only possible if profit and loss was eliminated from the financial sector, and in its place an extremely precise regime of recognition and preservation of biophysical value was instituted. The scenario that exhibited sustainability under this harsh condition was called, somewhat jokingly, the "Perpetual Motion Machine", or "The PMM". In more technical terms, the equilibrium achieved in the PMM is an unstable equilibrium that must be maintained by continuous external intervention.
ModEco and the PMM - Written in NetLogo, this model is a replication of the C++ model, but only of the single scenario called The PMM (Ref F2). Again, three observations are clear from this model, and from the two previous models, when looking back over the common characteristics. First, the steady-state condition of any of these models demonstrates clear evidence of entropy rising to a maximal value, and then staying there. The distributions of alleles (in PSoup), or of wealth (in ModEco and The PMM) develop and then hold shapes characteristic of maximal entropy. Second, the emergence of complex economic organizations and inter-agent interactions seems to be an inevitable part of the evolution towards such a sustainable configuration. Third, and perhaps most important, the steady state can only be maintained by programming techniques that address the inherent instability of the equilibria associated with those steady states.
EiLab - Written in C++, this model enables a rather detailed investigation of the phenomenon of rising entropy in economic models (Ref G). Inspired by the work of Dragulescu and Yakovenko (2000), it implements a capital exchange model in which I could study the origins and impact of entropy production in such models. EiLab stands for "Entropic Index Laboratory". I like this "laboratory" approach, because I can study many scenarios, generate lots of data, and then study the data. There were a few key observations coming out of this model. First, the study of entropy in such models is highly analogous to the study of entropy by Gibbs in his development of the concepts of "Gibbs' Free Energy". Second, in spite of the similarity to entropy, as Gibbs understood it, the entropy being investigated is not thermodynamic entropy, but a purely mathematical abstraction of it which is produced by a logical system executing logical processes distinct from chemical or heat-related effects. Third, the emergence of maximum entropy distributions was inevitable in these models, but the emergence of complexity was not, implying that there may be two distinct sets of conditions causing (a) the production of entropy, and (b) the production of complexity.
OamLab - Written in NetLogo, this model is one of two developed to explore more fully the phenomenon of production of complexity in economic systems (Ref H). This is a continuation of my study of sustainability of economic systems. It is the more simple senior member of a set of three models in which I explore the "Maximum Power Principle" as first proposed by A. J. Lotka and as developed by H. T. Odum. Both men argued that there is a need for a "fourth" law of thermodynamics, required to explain the persistent emergence of complexity. However, I found that Odum's ideas on this topic are difficult to decipher for a number of reasons. Ultimately, I found it necessary to restate his MPP as a set of three closely-related falsifiable hypotheses, and only then could I design models to test those hypotheses. OamLab is the first of three such models designed to test the validity of my restatement of the MPP. The prediction was that this model would evolve to a steady state in which the average efficiency was 0.5. Strangely, the steady-state average efficiency was 0.62, and not 0.5. This lead to the discovery of a dispute between Odum and Silvert in the early 1980s over which of the two numbers was the correct prediction. On further investigation, it turns out that there are, in fact, two valid answers, and both results are easily validated as consistent with the MPP. So, I consider that model, simple though it be, as supporting the hypotheses of the MPP.
MppLab - Written in NetLogo, this is the middle member of the trio of models exploring the validity of the MPP (Ref I). This had an exciting result, as it is able to model a trophic web, in action, with from 6 to 10 trophic levels all operational at once. I have made a YouTube video using this model.
CmLab - Written in NetLogo, this is another in the series of models designed to understand sustainable economics (Ref J). The name is short for "Conservation of Money" Laboratory. It's another model derived from PSoup and ModEco, but also derived from EiLab. PSoup is a purely biophysical economy. CmLab is a purely financial economy. ModEco is a hybrid biophysical/financial economy. CmLab is a capital exchange model in which bank loans are used to create money, and double-entry book-keeping is used to track it. It can provide, I think, some interesting insights into the nature of flows on money, which forms one half of a sustainable economy.
TpLab - Written in NetLogo, this model is intended to explore the hypothesized phenomenon that I am calling "Teleological Pruning". I argue that the beliefs and practices of any society are "pruned" and shaped by the same evolutionary pressures that shape our genes. Our societies are therefore shaped to conform to and agree with the effects of the Maximum Power Principle. This would explain why consumerism has emerged as the most destructive and persistent form of economic activity in our highly complex modern global economy. Our global economy has become the most powerful economy ever to have existed (in terms of energy consumed per year, and possibly in terms of energy consumed per person per year). Our beliefs (e.g. the necessity of endless economic growth) and our practices (materialism and consumerism) are now aligned with this destructive social trend. In TpLab, social beliefs are pitted against the effects of evolutionary pressures, with interesting effects.
CREDITS AND REFERENCES
Here's a list of formal references that were helpful to me:
Ref A - A.J. Lotka (1922a) 'Contribution to the Energetics of Evolution', Proceedings of the National Academy of Sciences of the United States of America, Vol. 8, No. 6 (Jun. 15, 1922), pp. 147-151.
Ref B - A.J. Lotka (1922) 'Natural Selection as a Physical Principle', Proceedings of the National Academy of Sciences of the United States of America, Vol. 8, No. 6 (Jun. 15, 1922), pp. 151-154.
Ref C - H.T. Odum and R.C. Pinkerton (1955) 'Time's speed regulator: The optimum efficiency for maximum output in physical and biological systems ', Am. Sci., 43 pp. 331–343.
Here are some less formal references:
Ref D – Boyle, Garvin H (2002), Primordial Soup (PSoup), Application written in C++. Downloadable from http://orrery-software.webs.com/psoup.
Ref E - M. Palmiter (1989), Simulated Evolution, Application. Downloadable from http://lifesciassoc.home.pipeline.com/instruct/evolution/.
Ref F1 – Boyle, Garvin H (2013, March 28). ‘ModEco and the PMM - A simple physically conservative complete sustainable economy.’ (Version 2). CoMSES Computational Model Library. Retrieved from: https://www.openabm.org/model/3613/version/2
Ref F2 – Boyle, Garvin H (2014, June 18). ‘Sustainable Economies ModEco.’ NetLogo Modeling Commons. Retrieved from: http://modelingcommons.org/browse/one_model/4746#model_tabs_browse_info
Ref G – Boyle, Garvin H (2015, May 27). ‘Capital Exchange Models – With Investigations of Entropic Index.’ (Version 3). CoMSES Computational Model Library. Retrieved from: https://www.openabm.org/model/3860/version/3
Ref H – Boyle, Garvin H (2016). ‘Maximum Power Principle OamLab.’ NetLogo Modeling Commons. Retrieved from: http://modelingcommons.org/browse/one_model/4745#model_tabs_browse_info
Ref I1 – Boyle, Garvin H (2016, May 9). ‘Maximum Power Principle MppLab.’ Not yet released.
Ref I2 – Boyle, Garvin H (2016, May 9). ‘150907 MPP and Trophic Levels R1.’ Retrieved from: https://www.youtube.com/watch?v=1NsRF4Bi0Zc
Ref J – Boyle, Garvin H (2016. ‘Conservation of Money Laboratory.’ Not yet released.
Ongoing conversations with Sholto Maud of Australia have been extremely helpful and very encouraging.
CONTACT ME: Garvin H. Boyle Email: orrery@rogers.com Web: http://orrery-software.webs.com/ Snail-mail: PO Box 1149, Richmond, Ontario, Canada, K0A 2Z0
Comments and Questions
;;-----------------------------------------------------------------------------| ;; SECTION A – AUTHOR IDENTIFICATION AND CODE ABSTRACT ;;-----------------------------------------------------------------------------| ;; ;; File Name: TpLab_V2.07.nlogo ;; By Orrery Software ;; Dated: 2017-03-13 ;; Author contact: ;; Garvin H Boyle ;; orrery@rogers.com ;; http://orrery-software.webs.com ;; As the author, I welcome questions, discussion of issues and suggestions ;; for improvements. ;;-----------------------------------------------------------------------------| ;; This TpLab app is a laboratory in which students can study aspects ;; of the phenomenon of Teleological Pruning (TP) as described in my ;; associated diary notes. ;; In this model, nrg arrives in a steady stream from the Sun and is captured ;; in plants that produce fruit, which appears randomly in dales in the ;; forest. Nomadic seekers roaming the forest according to their own ;; heuristic strategy seek the dales currently having food, and harvest it. ;; The strategies start as ineffective bland heuristics, and evolve to be ;; much more sophisticated. In the most simple scenario, all actions are ;; instinctive. ;; But an ability to have beliefs influence behaviour is built into the genes, ;; and belief systems evolve within the society. These teleological belief ;; systems can over-rule instinctual behaviour and stubbornly resist the ;; need to change. What happens to seekers that hold beliefs too tightly? ;; Can the seekers of fruit become seekers of wisdom? What happens to ;; societies that share a dilectic across multiple belief systems? ;;-----------------------------------------------------------------------------| ;; SECTION B – INITIAL DECLARATIONS OF GLOBALS AND BREEDS ;;-----------------------------------------------------------------------------| ;; ;;-----------------------------------------------------------------------------| ;; This program was developed on NetLogo Version 5.0.5 ;; ;;-----------------------------------------------------------------------------| ;; code-determined global variables globals [ ;; The version should be coded in this global variable to be included in ;; output files. gs-Version ;; Note: Some global variables are declared inside of switches, sliders and ;; choosers when the interface is constructed and are not declared here. ;; For the sake of clarity and completeness, they are noted here. ;; There are several uses of global variables: ;; - Toggles (switches), and choosers which enable or disable features; ;; - Numbers (in variables or sliders) which act as parameters; ;; - Numbers (in variables) which collect data. ;; ;; Those marked as 'native Boolean' have values of true or false. ;; Those marked as 'numeric Boolean' have values of 1 or 0. ;;--------------------- ;; MODELING ENVIRONMENT ;;--------------------- ;; Assumed “Model Settings” on startup ;; horizontal wrap: on ;; vertical wrap: on ;; location of origin: centre ;; patch size: 5 pixels ;;-------------------------------------------------------------------------| ;; Implicit global variables due to model settings – patch locations ;; min-pxcor -40 ;; max-pxcor 40 ;; min-pycor -40 ;; max-pycor 40 ;;---------------------------- ;; SCENARIO SELECTION CONTROLS ;;---------------------------- ;; gs-scenario ;; Chooser, string converts to a scenario number g-scenario-number ;; scenario no., 0, 1 or 2; interp. of gs-scenario ;; Glogal enumeration variables - There are 3 scenarios possible. ge-scenario-0-beliefs ;; scenario 0 ge-scenario-8-beliefs ;; scenario 1 ge-scenario-8-shares ;; scenario 2 ge-scenario-n-tribes ;; scenario 3 ;; To halt a scenario at a pre-determined tick. ;; g-halt-at-tick ;; Has it's own input box ;; Initialize the Pseudo Random Number Generator (PRNG). ;; g-use-this-seed ;; Slider [1,1,100,7] ;;----------------------------------------------- ;; BIOPHYSICAL SUB-SYSTEM CONTROLS AND PARAMETERS ;;----------------------------------------------- ;; Biophyscial life function parameters, seekers. ;; g-c2-dat-parm ;; The death age threshold ;; g-c2-det-parm ;; The death nrg threshold ;; g-c2-rat-parm ;; The reproductive age threshold ;; g-c2-ret-parm ;; The reproductive nrg threshold ;; g-c2-epm-parm ;; The nrg per move ;; g-c2-epa-parm ;; The maximum nrg an agent may hold ;; The global list of possible heading deltas for moves. gl-heading-list ;; List of heading deltas. gl-index-list ;; List of numbers 0-7 in order gl-base-factors ;; List of factors, used to mutate bases gl-colour-list ;; List of colours, for agents and graphs ;; Nrg control variables ;; g-sun-nrg-per-tick ;; Nrg arriving per tick [1000,40,12000,6000] ;; g-nrg-per-block ;; Nrg deposited per Dale [1,1,100,40] ;; g-prob-of-deposit ;; Prob nrg will be deposited [0,.001,1,.1] ;; g-heuristic-delta ;; Amount added to heuristic on success [0,.001,2,1] ;; g-prob-of-genetic-mutation ;; As it says [0,.001,1,.1] ;; g-dt-for-eroi ;; Delta time, used for EROI [40,40,400,40] ;; Nrg accounting variables g-nrg-in-sunshine ;; Nrg held in the sunshine, to be placed as fruit. g-nrg-in-fruit ;; Nrg held in the fruit. gl-nrg-by-belief ;; Nrg held, seekers, by belief (a list of 8 numbers). g-total-nrg-in-system ;; Total nrg in the system. gl-nrg-by-tribe ;; Nrg held, seekers, by tribe (a list of 10 numbers) ;; Nrg in Sunshine takeup accounting variables g-sun-takeup-maximum ;; Maximum possible, = [empty-cells]x[size-of-deposit] g-sun-takeup-expected ;; Expected, = [Max]x[prob-of-deposit] g-sun-takeup-actual ;; As measured ;; Biophyscial life function parameters, seekers. ;; g-no-of-tribes ;; seekers, per belief type, at startup [1,1,100,5] ;; g-c1-belief-value ;; Default value [0,.1,3,2] ;; Global enumeration (ge-) codes for cause of death. ge-cod-none ge-cod-hunger ge-cod-fission ge-cod-oldage ;; List to hold counts of cause of death. gl-causes-of-death-per-tick gl-causes-of-death-cumulative ;;------------------------------------- ;; END OF MODEL PARAMETERS AND CONTROLS ;;------------------------------------- ;;------------------------------------- ;; DATA COLLECTION AND DISPLAY CONTROLS ;;------------------------------------- ;; The following global variables are not model controls or paramaters, ;; but, rather, are variables used to collect data about the model ;; for display in the user interface, in some fashion (monitors or plots), ;; or used to manage all of the debug routines and output. ;; Global enumeration (ge-) codes. ge-sinktype-discard ;; Discarded sunlight ge-sinktype-move-EPM ;; Seekers EPM ge-sinktype-die-DET ;; Remaining nrg of seeker on death. ge-sinktype-die-DAT ;; Remaining nrg of seeker on death. ;; SYSTEM-WIDE AGGREGATES ;; System of nrg sinks. gl-sinks-per-tick gl-sinks-cumulative ;;---------------------------------------------------------------------------| ;; The following agent sets, counts and averages are for data collection ;; and display in monitors and plots. ;; Global counts g-no-of-patches ;; count of all patches g-no-of-dales ;; count of all dales with fruit gl-no-of-seekers ;; count of all seekers; list g-no-of-seekers ;; count of all seekers g-no-with-this-belief ;; count of those with this belief. ;; Global EROI/ETA system-wide calculations. g-sys-nrg-returned ;; Total nrg returned within delta T. g-sys-nrg-invested ;; Total nrg invested within delta T. g-sys-nrg-income ;; Total nrg income (flowing) within delta T. gl-sys-nrg-returned ;; List of changes. gl-sys-nrg-invested ;; List of changes. g-sys-eroi ;; System-wide EROI, per tick (=B/C). g-sys-eta ;; System-wide ETA, per tick =(B/I). ;; Averages for seekers g-ave-age ;; age of seekers g-ave-nrg ;; nrg of seekers g-ind-min-eroi ;; min eroi of individual seekers = (B/C) g-ind-ave-eroi ;; ave eroi of individual seekers = (B/C) g-ind-max-eroi ;; max eroi of individual seekers = (B/C) g-ind-min-eta ;; min eta of individual seekers = (B/I) g-ind-ave-eta ;; ave eta of individual seekers = (B/I) g-ind-max-eta ;; max eta of individual seekers = (B/I) g-ave-C1-b0 ;; c1, base character, gene-0 g-ave-C1-b1 ;; c1, base character, gene-1 g-ave-C1-b2 ;; c1, base character, gene-2 g-ave-C1-b3 ;; c1, base character, gene-3 g-ave-C1-b4 ;; c1, base character, gene-4 g-ave-C1-b5 ;; c1, base character, gene-5 g-ave-C1-b6 ;; c1, base character, gene-6 g-ave-C1-b7 ;; c1, base character, gene-7 g-ave-C1-g0 ;; c1, genotypic character, gene-0 g-ave-C1-g1 ;; c1, genotypic character, gene-1 g-ave-C1-g2 ;; c1, genotypic character, gene-2 g-ave-C1-g3 ;; c1, genotypic character, gene-3 g-ave-C1-g4 ;; c1, genotypic character, gene-4 g-ave-C1-g5 ;; c1, genotypic character, gene-5 g-ave-C1-g6 ;; c1, genotypic character, gene-6 g-ave-C1-g7 ;; c1, genotypic character, gene-7 g-ave-C1-l0 ;; c1, learned character, gene-0 g-ave-C1-l1 ;; c1, learned character, gene-1 g-ave-C1-l2 ;; c1, learned character, gene-2 g-ave-C1-l3 ;; c1, learned character, gene-3 g-ave-C1-l4 ;; c1, learned character, gene-4 g-ave-C1-l5 ;; c1, learnedores character, gene-5 g-ave-C1-l6 ;; c1, learned character, gene-6 g-ave-C1-l7 ;; c1, learned character, gene-7 g-ave-C1-s0 ;; c1, strength character, gene-0 g-ave-C1-s1 ;; c1, strength character, gene-1 g-ave-C1-s2 ;; c1, strength character, gene-2 g-ave-C1-s3 ;; c1, strength character, gene-3 g-ave-C1-s4 ;; c1, strength character, gene-4 g-ave-C1-s5 ;; c1, strength character, gene-5 g-ave-C1-s6 ;; c1, strength character, gene-6 g-ave-C1-s7 ;; c1, strength character, gene-7 g-ave-C1-p0 ;; c1, phenotypic character, gene-0 g-ave-C1-p1 ;; c1, phenotypic character, gene-1 g-ave-C1-p2 ;; c1, phenotypic character, gene-2 g-ave-C1-p3 ;; c1, phenotypic character, gene-3 g-ave-C1-p4 ;; c1, phenotypic character, gene-4 g-ave-C1-p5 ;; c1, phenotypic character, gene-5 g-ave-C1-p6 ;; c1, phenotypic character, gene-6 g-ave-C1-p7 ;; c1, phenotypic character, gene-7 ;; SWITCHES - These are declared in the switch itself, and so are ;; commented out here. They are all native Booleans, having values of ;; true or false. ;; gb-plot-data ;; Enables plotting ;; Other - built-in or declared implicitly in plot interface items ;; See each plot design dialogue. ;;--------------- ;; DEBUG CONTROLS ;;--------------- gb-debug-on ;; Numeric Boolean, opens debug log file, 0 or 1. gs-debug-status ;; for monitor, '1 (On)' or '0 (Off)', ;; gs-debug-step-chooser ;; Chooser, used with gb-debug-flow-on gb-debug-flow-on ;; Numeric Boolean, in association with chooser, gs-log-file-name ;; name of the debug log file ;; opens flow to log file ] ;;------------------------------------- ;; DEFINING PATCHES AND BREEDS ;;------------------------------------- ;;-----------------------------------------------------------------------------| ;; Attributes of patches patches-own [ ;; BUILT-IN ATTRIBUTES ;; pxcor ;; min-pxcor <= pxcor < max-pxcor ;; pycor ;; min-pxcor <= pxcor < max-pxcor ;; pcolor ;; color of this patch ( 0 <= color < 140 ) ;; plabel ;; label of this patch ;; plabel-color ;; color of this patch's label ( 0 <= label-color < 140 ) ;; TpLab-DETERMINED ATTRIBUTES fruit ] ;;-----------------------------------------------------------------------------| ;; Attributes of links ;; nil ;; I don't understand links and did not use any. ;;-----------------------------------------------------------------------------| ;; Turtles and breeds breed [ seekers seeker ] ;;-----------------------------------------------------------------------------| ;; Attributes of seekers seekers-own [ ;; BUILT-IN ATTRIBUTES ;; who ;; fixed id number ;; breed ;; to which breed this turtle belongs [seeker] ;; heading ;; 0 <= heading < 360, 0 = north ;; xcor ;; min-pxcor <= xcor < max-pxcor ;; ycor ;; min-pxcor <= xcor < max-pxcor ;; size ;; size relative to a patch, default is 1 ;; shape ;; a shape chosen from the shape library ;; color ;; color of this turtle ( 0 <= color < 140 ) ;; pen-mode ;; "up" or "down" ;; pen-size ;; in pixels ;; hidden? ;; true or false ;; label ;; label of this turtle ;; label-color ;; color of this turtle's label ( 0 <= label-color < 140 ) ;; USER-DETERMINED ATTRIBUTES ;; The chromosome 1 (c1) genes are used to distinguish behaviours. c1-bases ;; c1 - list of 8 [B]ases for genes (P=B^(G+L)) c1-genes ;; c1 - list of 8 heading delta [G]enes c1-learn ;; c1 - list of 8 [L]earned beliefs c1-stren ;; c1 - list of 8 [S]trengths c1-pheno ;; c1 - list of 8 [P]henotypic characters belief-affiliation ;; The belief (0-7) held by this agent. tribal-affiliation ;; the social affiliation of the seeker. ;; The chromosome 2 (C2) genes are static in this model. DAT ;; Death Age Threshold. DET ;; Death Energy Threshold. RAT ;; Reproductive Age Threshold. RET ;; Reproductive Energy Threshold. EPM ;; Energy Per Move. EPA ;; Maximum Energy Per Agent. ;; Other variable characteritics. mas-who ;; serial number of parent agent. age ;; age of the agent in ticks nrg ;; nrg in this agent cause-of-death ;; for statistical purposes b-is-ready-to-move ;; 0 = no; 1 = ready to move b-is-ready-to-reproduce ;; mature (in age) and healthy (in nrg) b-is-ready-to-die ;; old (in age) or starved (in nrg) ;; Variables for calculating personal EROI and ETA. nrg-returned ;; Numerator of EROI - an aggregate = Benefits of (B/C) nrg-invested ;; Denominator of EROI - an aggregate = Costs of (B/C) nrg-income ;; Denominator of ETA - an aggregate = Income of (B/I) eroi ;; Nrg returned on nrg invested = (B/C) eta ;; Nrg efficiency = (B/I) where Income = (B+C) l-er ;; A list of delta ERs l-ei ;; A list of delta EIs counter-eroi ;; For tracking time up to delta T. ] ;;-----------------------------------------------------------------------------| ;; SECTION C – INITIALIZATION OR SETUP PROCEDURE( S ) ;;-----------------------------------------------------------------------------| ;;-----------------------------------------------------------------------------| ;; The 'autostart' startup routine to startup ;; This routine is to be executed by the observer. ;; The manual describes this routine as follows: ;; This procedure, if it exists, will be called when a model is first loaded ;; in the NetLogo application. Startup does not run when a model is run ;; headless from the command line, or by parallel BehaviorSpace. ;; On loading the model, the debug feature is always off. set gb-debug-on 0 set gs-debug-status "0 (Off)" ;; On loading the model, the model, the choosers, switches and sliders are ;; always reset to the values that are known to work by here invoking ;; the f-reset-default-parameters routine. Only the chooser ;; for the scenario is not reset. The last saved ;; selection of scenario will therefore be persistant. This allows the ;; 'Reset Defaults' button to NOT reset the scenario number, but to reset ;; correct parameters for the scenario. f-reset-default-parameters ;; Run the setup routine to initialize other globals. setup end ;;-----------------------------------------------------------------------------| ;; Reset the default values for the interface-declared items. to f-reset-default-parameters ;; The observer executes this routine. ;; Switches, sliders and choosers implicitly declare global variables. The ;; values in these variables are parameters for the model, and many ;; combinations of those parameters are not sustainable. However, the ;; values in those user interface devices are stored with the model and ;; are persistant across a save/load action. The default values must ;; be reset on load, or available to a user as a parameter set. The ;; purpose of this routine is to store at least one viable set of ;; parameter values. ;; DO NOT re-initialize the gs-scenario chooser. The selected scenario ;; is intended to be persistent, and not subject to a default setting. ;; Initialize the Pseudo Random Number Generator (PRNG). set g-use-this-seed 7 ;; [1,1,100,7] set gb-plot-data true ;; Turn plotting on. ;;----------------------------------------------- ;; BIOPHYSICAL SUB-SYSTEM CONTROLS AND PARAMETERS ;;----------------------------------------------- ;; Slider range settings are shown as (Min,Inc,Max,Default) set g-no-of-tribes 10 ;; [1,1,100,5] set g-c1-belief-value 2 ;; [0,.1,3,2] set g-sun-nrg-per-tick 6000 ;; [1000,40,12000,6000] set g-nrg-per-deposit 40 ;; [1,1,100,40] set g-prob-of-deposit 0.1 ;; [0,.001,1,.1] set g-prob-of-mutation 0.5 ;; [0,.001,1,.5] set g-dt-for-eroi 40 ;; [40,40,400,40] set g-gene-to-adjust 0 ;; [0,1,7,0] ;; Static chromosome 2 (C2) biophysical controls - borrowed from PSoup model. set g-c2-dat-parm 1600 ;; [100,10,3200,1600] set g-c2-det-parm 4 ;; [4,4,40,4] set g-c2-rat-parm 800 ;; [50,10,3200,800] set g-c2-ret-parm 1000 ;; [200,1,1600,1000] set g-c2-epm-parm 4 ;; [1,1,40,4] set g-c2-epa-parm 1600 ;; [1600,100,3000,1600] ;; End of f-reset-default-parameters end ;;-----------------------------------------------------------------------------| ;; The setup button(s) to setup ;; This routine is to be executed by the observer. ;; NOTE: The contents of switches, sliders, and choosers seem to be ;; immune to these 'clear' commands. clear-ticks clear-turtles clear-patches clear-drawing clear-all-plots clear-output ;; clear-globals ;; Suppressed to make gb-debug-on value persistent. ;; NOTE: Instead of 'clear-globals', you must ensure all globals are ;; initialized properly in 'setup'. ;; import-drawing "01-B OrrSW.jpg" ;; Set the nrg (encoded in the variable fruit) in all of the patches to zero. ask patches [ set fruit 0 set pcolor brown ] ;; The version should be coded in this global variable to be included in ;; output files. set gs-Version "TpLab_V2.07" ;; Debug features may be off or on depending on history. ;; - Perhaps 'setup' was called by 'to startup'. ;; - Perhaps 'setup' was called during a 'BehaviorSpace' run. ;; - Perhaps 'setup' was called by a user-pushed 'setup' button. ;; Setup needs to handle some quasi-persistant values correctly regardless of ;; the history. For gb-debug-on, in particular, I want it to be ;; persistant so I can have debug output from the 'setup' routine routed ;; to the debug log file, or to the command centre. ;; 'startup' automatically sets gb-debug-on to 0 when the application is first ;; loaded. I want to be able to (A) toggle debug on, then, (B) press ;; 'setup' and watch the debug output of the 'setup' command. The ;; gb-debug-on must be persistant through the above 'clear' commands. The ;; debug log file name and status, however, should not be persistent and ;; must be reset when setup runs, if appropriate. ifelse ( gb-debug-on = 1 ) [ ;; Debug is on due to user setting, so file name and status should be ;; reset. I do this by turning the feature off then on. ;; First toggle it off, closing any remnant log file, if needed. f-toggle-debug ;; Then toggle it back on, opening a new time-stamped log file. f-toggle-debug ] ;; else [ ;; Debug is off, possibly due to startup execution, possibly due to user ;; choice. ;; Ensure associated variables have compatible settings. set gb-debug-on 0 ;; Redundant but ensures consistency. set gs-debug-status "0 (Off)" ;; Redundant but ensures consistency. set gb-debug-flow-on 0 ;; Step-specific flow is off. file-close-all ;; Close the debug log file. set gs-log-file-name "dummyname" ] ;; Now, do the standard check that is done at the start of each debuggable ;; routine. This must follow the clear commands, which reset everything ;; except globals, switches, sliders and choosers. if( gb-debug-on = 1 ) [ ifelse( ( gs-debug-step-chooser = "all" ) or ( gs-debug-step-chooser = "setup" ) ) [ set gb-debug-flow-on 1 LOG-TO-FILE "" LOG-TO-FILE word "Do-setup: Debug on; tick = " 0 ] [ set gb-debug-flow-on 0 ] ] ;; g-use-this-seed comes from a slider, and is persistant during setup. ;; However it is NOT persistent in a 'reset-defaults' call. random-seed g-use-this-seed ;; Tells the PRNG to use this seed. ;; Establish the list of allowed headings, each 45 degrees from the last. ;; These are the possible deltas that will be added to the current heading ;; based on which of the 8 genes is expressed during a move. set gl-heading-list [ 0 45 90 135 180 225 270 315 ] set gl-index-list [ 0 1 2 3 4 5 6 7 ] ;; The factors used to mutate the base values of the genes need to be ;; calculated. let prime-list [ 7 11 13 17 ] let factor-list ( map [ 1 + ( 1 / ? ) ] prime-list ) let inverse-list ( map [ 1 - ( 1 / ? ) ] prime-list ) set gl-base-factors ( sentence factor-list inverse-list ) ;; Identify one colour for each possible value of preferred index. set gl-colour-list [ 65 56 96 26 15 24 84 54 ] ;; Glogal enumeration variables - There are 4 scenarios possible. set ge-scenario-0-beliefs 0 ;; society not affected by beliefs set ge-scenario-8-beliefs 1 ;; society with 8 belief systems set ge-scenario-8-shares 2 ;; wisdom shared within belief system set ge-scenario-n-tribes 3 ;; wisdom also shared within familial group ;; Use the input from the chooser gs-scenario to invoke the selected scenario. f-set-scenario-number ;; For debugging the setup procedure, log the values of the globals. LOG-TO-FILE ( word " Do-set: Scenario number - " g-scenario-number ) LOG-TO-FILE ( word " Do-set: Scenario name - " gs-scenario ) LOG-TO-FILE ( word " Do-set: Random seed - " g-use-this-seed ) ;; Declare values of hidden declarations from sliders. LOG-TO-FILE ( word " Do-set: g-no-of-tribes - " g-no-of-tribes ) LOG-TO-FILE ( word " Do-set: g-c1-belief-value - " g-c1-belief-value ) LOG-TO-FILE ( word " Do-set: g-sun-nrg-per-tick - " g-sun-nrg-per-tick ) LOG-TO-FILE ( word " Do-set: g-nrg-per-deposit - " g-nrg-per-deposit ) LOG-TO-FILE ( word " Do-set: g-prob-of-deposit - " g-prob-of-deposit ) LOG-TO-FILE ( word " Do-set: g-prob-of-mutation - " g-prob-of-mutation ) LOG-TO-FILE ( word " Do-set: g-dt-for-eroi - " g-dt-for-eroi ) ;; Nrg accounting variables set g-nrg-in-sunshine 0 ;; Nrg held in the sunshine, to be placed as fruit. set g-nrg-in-fruit 0 ;; Nrg held in the fruit. set gl-nrg-by-belief ( n-values 8 [0] ) ;; Nrg held, by belief affiliation. set g-total-nrg-in-system 0 ;; Nrg in the system. set gl-nrg-by-tribe ( n-values 10 [0] ) ;; Nrg held, by tribal affiliation. ;; Nrg in Sunshine takeup accounting variables set g-sun-takeup-maximum 0 ;; = [empty-cells]x[size-of-deposit] set g-sun-takeup-expected 0 ;; = [Max]x[prob-of-deposit] set g-sun-takeup-actual 0 ;; As measured ;; Global enumeration (ge-) codes for cause of death. set ge-cod-none 0 set ge-cod-hunger 1 set ge-cod-fission 2 set ge-cod-oldage 3 ;; List to hold counts of cause of death. set gl-causes-of-death-per-tick ( n-values 4 [0] ) set gl-causes-of-death-cumulative ( n-values 4 [0] ) ;; Global enumeration (ge-) codes for sinktype. set ge-sinktype-discard 0 ;; Discarded sunlight set ge-sinktype-move-EPM 1 ;; Seeker EPM set ge-sinktype-die-DET 2 ;; Remaining nrg of seeker on death. set ge-sinktype-die-DAT 3 ;; Remaining nrg of seeker on death. ;; System of nrg sinks. set gl-sinks-per-tick ( n-values 4 [0] ) set gl-sinks-cumulative ( n-values 4 [0] ) ;; Global EROI system-wide calculations. set g-sys-nrg-returned 0 ;; Total nrg returned within delta T. set g-sys-nrg-invested 0 ;; Total nrg invested within delta T. set g-sys-nrg-income 0 ;; Total nrg income within delta T. set gl-sys-nrg-returned [] ;; List of changes. set gl-sys-nrg-invested [] ;; List of changes. set g-sys-eroi 1.0 ;; System-wide EROI, per tick = (B/C). set g-sys-eta 0.5 ;; System-wide ETA, per tick = (B/I). ;;---------------------------------------------------------------------------| ;; The following agent sets, counts and averages are for data collection ;; and display in monitors and plots. ;; Counts set g-no-of-patches 0 ;; count of all patches set g-no-of-dales 0 ;; count of all dales with fruit ;; Counts of all seekers, by belief-affiliation. set gl-no-of-seekers [ 0 0 0 0 0 0 0 0 ] set g-no-of-seekers 0 ;; counts of all seekers set g-no-with-this-belief 0 ;; count of those with this belief. ;; Averages for seekers set g-ave-age 0 ;; age of seekers set g-ave-nrg 0 ;; nrg of seekers set g-ind-min-eroi 1.0 ;; min individual eroi of seekers = (B/C) set g-ind-ave-eroi 1.0 ;; ave individual eroi of seekers = (B/C) set g-ind-max-eroi 1.0 ;; max individual eroi of seekers = (B/C) set g-ind-min-eta 0.5 ;; min individual eta of seekers = (B/I) set g-ind-ave-eta 0.5 ;; ave individual eta of seekers = (B/I) set g-ind-max-eta 0.5 ;; max individual eta of seekers = (B/I) set g-ave-C1-b0 0 ;; c1, base character, gene-0 set g-ave-C1-b1 0 ;; c1, base character, gene-1 set g-ave-C1-b2 0 ;; c1, base character, gene-2 set g-ave-C1-b3 0 ;; c1, base character, gene-3 set g-ave-C1-b4 0 ;; c1, base character, gene-4 set g-ave-C1-b5 0 ;; c1, base character, gene-5 set g-ave-C1-b6 0 ;; c1, base character, gene-6 set g-ave-C1-b7 0 ;; c1, base character, gene-7 set g-ave-C1-g0 0 ;; c1, genotypic character, gene-0 set g-ave-C1-g1 0 ;; c1, genotypic character, gene-1 set g-ave-C1-g2 0 ;; c1, genotypic character, gene-2 set g-ave-C1-g3 0 ;; c1, genotypic character, gene-3 set g-ave-C1-g4 0 ;; c1, genotypic character, gene-4 set g-ave-C1-g5 0 ;; c1, genotypic character, gene-5 set g-ave-C1-g6 0 ;; c1, genotypic character, gene-6 set g-ave-C1-g7 0 ;; c1, genotypic character, gene-7 set g-ave-C1-l0 0 ;; c1, learned character, gene-0 set g-ave-C1-l1 0 ;; c1, learned character, gene-1 set g-ave-C1-l2 0 ;; c1, learned character, gene-2 set g-ave-C1-l3 0 ;; c1, learned character, gene-3 set g-ave-C1-l4 0 ;; c1, learned character, gene-4 set g-ave-C1-l5 0 ;; c1, learned character, gene-5 set g-ave-C1-l6 0 ;; c1, learned character, gene-6 set g-ave-C1-l7 0 ;; c1, learned character, gene-7 set g-ave-C1-s0 0 ;; c1, strength character, gene-0 set g-ave-C1-s1 0 ;; c1, strength character, gene-1 set g-ave-C1-s2 0 ;; c1, strength character, gene-2 set g-ave-C1-s3 0 ;; c1, strength character, gene-3 set g-ave-C1-s4 0 ;; c1, strength character, gene-4 set g-ave-C1-s5 0 ;; c1, strength character, gene-5 set g-ave-C1-s6 0 ;; c1, strength character, gene-6 set g-ave-C1-s7 0 ;; c1, strength character, gene-7 set g-ave-C1-p0 0 ;; c1, phenotypic character, gene-0 set g-ave-C1-p1 0 ;; c1, phenotypic character, gene-1 set g-ave-C1-p2 0 ;; c1, phenotypic character, gene-2 set g-ave-C1-p3 0 ;; c1, phenotypic character, gene-3 set g-ave-C1-p4 0 ;; c1, phenotypic character, gene-4 set g-ave-C1-p5 0 ;; c1, phenotypic character, gene-5 set g-ave-C1-p6 0 ;; c1, phenotypic character, gene-6 set g-ave-C1-p7 0 ;; c1, phenotypic character, gene-7 ;; For debugging the debug feature!!! Suppressed now. ;; show ( word "SETUP: Debug Is " gb-debug-on ) ;; show ( word "SETUP: Debug Status Is " gs-debug-status ) ;; show ( word "SETUP: Step Chooser Is " gs-debug-step-chooser ) ;; show ( word "SETUP: Flow Control Is " gb-debug-flow-on ) set-default-shape seekers "arrow" ;; pulled from shapes library ask patches [ set pcolor brown ] reset-ticks ;; restarts tick counter, runs setup commands within plots set gb-plot-data true ;; Enables all plotting calls. ;; Initialize the seekers. ;; This differs for each scenario. ;; Injects nrg, and establishes belief systems. f-initialize-seekers ;; This call must follow 'reset-ticks' and initialization of seekers. f-update-aggregates ;; Totals and averages. ;; Clears unwanted zeros in plots. clear-all-plots setup-plots ;; Debug controls ;; Boolean, in association with chooser, turns debug LOG-TO-FILE on/off set gb-debug-flow-on 0 ;; Input variable to set a tick for stopping. set g-halt-at-tick -1 Set g-nrg-in-fruit ( sum [fruit] of patches ) ;; ASSERT ( frb-nrg-accounts-are-all-valid ) ;; ( "Do-set: Nrg accounts invalid." ) -1 LOG-TO-FILE " Do-set: procedure completed" ;; end of to-setup end ;;-----------------------------------------------------------------------------| ;; Set the scenario number using the input from the chooser. to f-set-scenario-number ;; This routine is to be executed by the observer. set g-scenario-number ge-scenario-0-beliefs ;; default if( gs-scenario = "Society With 0 Beliefs" ) [ set g-scenario-number ge-scenario-0-beliefs ] if( gs-scenario = "Society With 8 Beliefs" ) [ set g-scenario-number ge-scenario-8-beliefs ] if( gs-scenario = "Society With Wisdom Sharing" ) [ set g-scenario-number ge-scenario-8-shares ] if( gs-scenario = "Society With Tribal Bonds" ) [ set g-scenario-number ge-scenario-n-tribes ] ;; End f-set-scenario-number end ;;-----------------------------------------------------------------------------| ;; Initialize a population of seekers. to f-initialize-seekers ;; This routine is to be executed by the observer. ;; Load nrg into the sunshine, for setup. set g-nrg-in-sunshine g-sun-nrg-per-tick set g-total-nrg-in-system ( g-total-nrg-in-system + g-nrg-in-sunshine ) ;; Record maximum possible Sunshine takeup rate data. let empty-cells ( count patches with [fruit = 0] ) set g-sun-takeup-maximum ( empty-cells * g-nrg-per-deposit ) ;; Record expected Sunshine takeup rate data. set g-sun-takeup-expected ( g-sun-takeup-maximum * g-prob-of-deposit ) ;; I want a population of each type of preferred gene. ;; Although I have allocated an amount of energy for this, I do not stop ;; initializing new agents if/when it runs out. I simply record the ;; over-draw as a negative in the appropriate sink if( g-scenario-number = ge-scenario-0-beliefs ) [ f-initialize-0-beliefs-society ] if( g-scenario-number = ge-scenario-8-beliefs ) [ f-initialize-8-beliefs-society ] if( g-scenario-number = ge-scenario-8-shares ) [ f-initialize-wisdom-sharing ] if( g-scenario-number = ge-scenario-n-tribes ) [ f-initialize-tribal-sharing ] ;; Place more energy into patches. ask patches [ set fruit g-nrg-per-deposit set g-total-nrg-in-system ( g-total-nrg-in-system + g-nrg-per-deposit ) set pcolor green ] ;; Record the actual Sunshine takeup rate data. set g-sun-takeup-actual 0 ;; Put the rest of the Sunshine into the sink. set g-total-nrg-in-system ( g-total-nrg-in-system - g-sun-nrg-per-tick ) f-store-data-in-sink ge-sinktype-discard g-nrg-in-sunshine ;; End of f-initialize-seekers end ;;-----------------------------------------------------------------------------| ;; Initialize a society characterized by 0 belief systems. to f-initialize-0-beliefs-society ;; This routine is to be executed by the observer. ;; In this scenario, we create 8 populations of seekers which are all ;; identical except for location and heading. None are affected ;; by any belief affiliation. This is identical to the 8-beliefs society ;; initialization, except the slider g-c1-belief-value is ignored. foreach gl-index-list ;; 8 genes. [ create-seekers g-no-of-tribes [ f-initialize-new-seeker ;; In this scenario, seekers have a belief affiliation but it ;; is de-activated due to the value of the belief being set ;; to zero. ;; Identify the belief affiliation. set belief-affiliation 0 ;; This is set to zero, but it not used. All seekers have a ;; preferred gene of zero, but the associated belief value is ;; also zero so it has no effect. ;; Set the heading as one of the 8 allowed headings. set heading ( item ( random 8 ) gl-heading-list ) set color ( item belief-affiliation gl-colour-list ) set age ( RAT / 2 ) ;; Age is halfway to mature. set nrg ( EPA ) ;; Nrg is at max. ;; All start with same age and nrg level to avoid bias. ;; Update the energy statistics. let nrg-was ( item belief-affiliation gl-nrg-by-belief ) let nrg-is-now ( nrg-was + nrg ) set gl-nrg-by-belief ( replace-item belief-affiliation gl-nrg-by-belief nrg-is-now ) LOG-TO-FILE ( word " Do-set: gl-nrg-by-belief - " gl-nrg-by-belief ) set g-nrg-in-sunshine ( g-nrg-in-sunshine - nrg ) ;; Genetic and belief characters. set c1-bases [ 2 2 2 2 2 2 2 2 ] ;; 8 unbiased genes set c1-genes [ 0 0 0 0 0 0 0 0 ] ;; 8 unbiased genes set c1-learn [ 0 0 0 0 0 0 0 0 ] ;; 8 unbiased beliefs ;; IGNORE THE g-c1-belief-value SLIDER. Leave the beliefs unbiased. ;; Agent has an enhanced preference to exercise gene ?. ;; set c1-learn ;; ( replace-item ? c1-learn g-c1-belief-value ) ;; Biased beliefs ;; Calculate the strengths and phenotypic characters. f-find-strens-n-phenos LOG-TO-FILE ( word " Do-set: C1-bases - " c1-bases ) LOG-TO-FILE ( word " Do-set: C1-genes - " c1-genes ) LOG-TO-FILE ( word " Do-set: c1-learn - " c1-learn ) LOG-TO-FILE ( word " Do-set: c1-stren - " c1-stren ) LOG-TO-FILE ( word " Do-set: c1-pheno - " c1-pheno ) ;; Move each agent to a random point. setxy random-xcor random-ycor ] ;; End of create. ] ;; End of foreach ;; End of f-initialize-0-beliefs-society end ;;-----------------------------------------------------------------------------| ;; Calculate the strengths and phenotypic values. to f-find-strens-n-phenos ;; This routine is to be executed by a seeker. ;; It uses the second example of the map feature. ;; Examples of the map feature. ;; show (map + [1 2 3] [2 4 6]) ;; => [3 6 9] ;; show (map [?1 + ?2 = ?3] ;; [1 2 3] ;; [2 4 6] ;; [3 5 9]) ;; => [true false true] ;; Compute the strength as S=B^(G+L). set c1-stren ( map [?1 ^ ( ?2 + ?3 )] c1-bases c1-genes c1-learn ) ;; Compute the phenotypic character as Pi=100*(Si/sum(Si)). set c1-pheno ( map [?1 * ?2 / ?3] ( n-values 8 [100] ) c1-stren ( n-values 8 [sum c1-stren] ) ) ;; End of f-find-strens-n-phenos end ;;-----------------------------------------------------------------------------| ;; Initialize a society characterized by 8 beliefs. to f-initialize-8-beliefs-society ;; This routine is to be executed by the observer. ;; In this scenario, we create 8 populations of seekers which are all ;; identical except for (a) location and heading; and (b) belief ;; affiliation. There are 8 different belief affiliations, one for each ;; compound gene in chromosome #1 (C1). Each has their belief value ;; set as per the slider g-c1-belief-value. foreach gl-index-list ;; 8 genes. [ create-seekers g-no-of-tribes [ f-initialize-new-seeker ;; Identify the preferred heading-delta. set belief-affiliation ? ;; Set the heading as one of the 8 allowed headings. set heading ( item ( random 8 ) gl-heading-list ) set color ( item ? gl-colour-list ) set age ( RAT / 2 ) ;; Age is halfway to mature. set nrg ( EPA ) ;; Nrg is at max. ;; All start with same age and nrg level to avoid bias. ;; Update the energy statistics. let nrg-was ( item ? gl-nrg-by-belief ) let nrg-is-now ( nrg-was + nrg ) set gl-nrg-by-belief ( replace-item ? gl-nrg-by-belief nrg-is-now ) LOG-TO-FILE ( word " Do-set: gl-nrg-by-belief - " gl-nrg-by-belief ) set g-nrg-in-sunshine ( g-nrg-in-sunshine - nrg ) ;; Genetic and belief characters. set c1-bases [ 2 2 2 2 2 2 2 2 ] ;; 8 unbiased genes set c1-genes [ 0 0 0 0 0 0 0 0 ] ;; 8 unbiased genes set c1-learn [ 0 0 0 0 0 0 0 0 ] ;; 8 unbiased beliefs ;; Agent has an enhanced preference to exercise gene ?. set c1-learn ( replace-item ? c1-learn g-c1-belief-value ) ;; Biased beliefs ;; Calculate the strengths and phenotypic characters. f-find-strens-n-phenos LOG-TO-FILE ( word " Do-set: C1-bases - " c1-bases ) LOG-TO-FILE ( word " Do-set: C1-genes - " c1-genes ) LOG-TO-FILE ( word " Do-set: c1-learn - " c1-learn ) LOG-TO-FILE ( word " Do-set: c1-stren - " c1-stren ) LOG-TO-FILE ( word " Do-set: c1-pheno - " c1-pheno ) ;; Move each agent to a random point. setxy random-xcor random-ycor ] ;; End of create. ] ;; End of foreach ;; End of f-initialize-8-beliefs-society end ;;-----------------------------------------------------------------------------| ;; Initialize a society characterized by 8 beliefs with wisdom sharing. to f-initialize-wisdom-sharing ;; This routine is to be executed by the observer. ;; This will be an 8-beliefs society, similar to the previous scenario, ;; but with the ability of junior seekers to get wisdom from their ;; elders who share the same belief system. ;; When two seekers having the same belief affiliation ;; occupy the same cell, a seeker may have wisdom about ;; that belief transferred from the eldest such seeker, called ;; the local guru. ;; Wisdom is transferred during the 'do-feed' step. ;; The seekers are no different from those in an 8-beliefs society. f-initialize-8-beliefs-society ;; End of f-initialize-wisdom-sharing end ;;-----------------------------------------------------------------------------| ;; Initialize a society characterized by 8 belief systems. to f-initialize-tribal-sharing ;; This routine is to be executed by the observer. ;; In this scenario, we create a number of tribes of seekers. Each ;; tribe consists of eight seekers having the full range of belief ;; affiliations. let no-of-belieftypes 8 let tribe-no 0 let belief-no 0 while [ tribe-no < g-no-of-tribes ] [ LOG-TO-FILE ( WORD " Do-set: Tribal affiliation - " tribe-no ) set belief-no 0 while [ belief-no < no-of-belieftypes ] [ LOG-TO-FILE ( WORD " Do-set: (Tribe, Belief) - (" tribe-no ", " belief-no ")" ) create-seekers 1 [ f-initialize-new-seeker ;; Identify the belief affiliation. set belief-affiliation belief-no ;; Set the heading as one of the 8 allowed headings. set heading ( item ( random 8 ) gl-heading-list ) ;; Set the tribe number. set tribal-affiliation tribe-no set color ( item belief-no gl-colour-list ) set age ( RAT / 2 ) ;; Age is halfway to mature. set nrg ( EPA ) ;; Nrg is at max. ;; All start with same age and nrg level to avoid bias. ;; Update the energy statistics. let nrg-was ( item belief-no gl-nrg-by-belief ) let nrg-is-now ( nrg-was + nrg ) set gl-nrg-by-belief ( replace-item belief-no gl-nrg-by-belief nrg-is-now ) LOG-TO-FILE ( word " Do-set: gl-nrg-by-belief - " gl-nrg-by-belief ) set g-nrg-in-sunshine ( g-nrg-in-sunshine - nrg ) ;; Genetic and belief characters. set c1-bases [ 2 2 2 2 2 2 2 2 ] ;; 8 unbiased genes set c1-genes [ 0 0 0 0 0 0 0 0 ] ;; 8 unbiased genes set c1-learn [ 0 0 0 0 0 0 0 0 ] ;; 8 unbiased beliefs ;; Agent has an enhanced preference to exercise gene belief-no. set c1-learn ( replace-item belief-no c1-learn g-c1-belief-value ) ;; Biased beliefs ;; Calculate the strengths and phenotypic characters. f-find-strens-n-phenos LOG-TO-FILE ( word " Do-set: C1-bases - " c1-bases ) LOG-TO-FILE ( word " Do-set: C1-genes - " c1-genes ) LOG-TO-FILE ( word " Do-set: c1-learn - " c1-learn ) LOG-TO-FILE ( word " Do-set: c1-stren - " c1-stren ) LOG-TO-FILE ( word " Do-set: c1-pheno - " c1-pheno ) ;; Move each agent to a random point. setxy random-xcor random-ycor ] set belief-no ( belief-no + 1 ) ] set tribe-no ( tribe-no + 1 ) ] ;; End of f-initialize-tribal-sharing end ;;-----------------------------------------------------------------------------| ;; Initialize a society characterized by 8 belief systems. to f-impose-belief-affiliation ;; This routine is to be executed by the observer. ;; This routine will impose a belief affiliation on roughly 1/2 of the ;; current population of seekers. The gene affected by this imposition ;; is determined by the slider g-belief-to-adjust. The magnitude of the ;; belief is determined by the slider g-c1-belief-value. ;; It can be called by the "Impose This Belief Affiliation" button at ;; any time during any scenario. let selector 0 ask seekers [ ifelse ( selector = 0 ) [ ;; This seeker has been selected to have its belief affiliation adjusted. ;; The gene adjusted is determined by g-gene-to-adjust let adjustment g-c1-belief-value let target g-gene-to-adjust set c1-learn ( replace-item target c1-learn adjustment ) set belief-affiliation g-gene-to-adjust set selector 1 ] ;; End if selector = 0 ;; Else selector = 1 [ ;; This seeker will not have its belief affiliation adjusted. ;; No action required, other than resetting the selector. set selector 0 ] ;; End else if selector = 1 ] f-update-aggregates ;; End of f-impose-belief-affiliation end ;;-----------------------------------------------------------------------------| ;; Initialize a single seeker. to f-initialize-new-seeker ;; This routine is to be executed by a seeker. ;; BUILT-IN ATTRIBUTES ;; who ;; set automatically ;; heading ;; direction of motion ;; xcor ;; min-pxcor <= xcor < max-pxcor ;; ycor ;; min-pxcor <= xcor < max-pxcor ;; pen-mode ;; "up" or "down" ;; pen-size ;; in pixels ;; size ;; size relative to a patch, default is 1 ;; USER-DETERMINED ATTRIBUTES ;; These two are re-initialized specifically for some scenarios. set belief-affiliation 0 set tribal-affiliation 0 ;; The biophysical body function genes are static in this model. ;; Load chromosome 2 with the parameters from sliders. set DAT g-c2-dat-parm set DET g-c2-det-parm set RAT g-c2-rat-parm set RET g-c2-ret-parm set EPM g-c2-epm-parm set EPA g-c2-epa-parm ;; Associated with seeker dynamics. set mas-who -1 ;; serial number of parent seeker. ;; age and nrg are set in group initialization routine. set cause-of-death ge-cod-none ;; for statistical purposes. ;; Set the logic trigger flags. set b-is-ready-to-move 1 ;; i.e. true set b-is-ready-to-reproduce 0 ;; i.e. false set b-is-ready-to-die 0 ;; i.e. false ;; Variables for calculating individual EROI and ETA. set nrg-returned g-dt-for-eroi ;; Numerator of EROI - an aggregate set nrg-invested g-dt-for-eroi ;; Denominator of EROI - an aggregate set nrg-income ( nrg-returned + nrg-invested ) set eroi 1.0 ;; Nrg returned on nrg invested = (B/C) set eta 0.5 ;; individual efficiency = (B/I) set l-er ( n-values g-dt-for-eroi [1] ) ;; Delta ERs = B of B/C set l-ei ( n-values g-dt-for-eroi [1] ) ;; Delta EIs = C of B/C set counter-eroi g-dt-for-eroi ;; For tracking time up to delta T. ;; end f-initialize-new-seeker end ;;-----------------------------------------------------------------------------| ;; SECTION D – GO OR MAIN-LOOP PROCEDURE( S ) ;;-----------------------------------------------------------------------------| ;;-----------------------------------------------------------------------------| ;; The go button to go ;; This routine is to be executed by the observer. ;; Stop codes: ;; All stop decisions must be here in the 'go' procedure, as it causes an ;; exit from the current procdure only. if( g-halt-at-tick = ticks ) [ set g-halt-at-tick -1 stop ] let b-should-stop-now false if( count turtles <= 0 ) [ set b-should-stop-now true ] if( b-should-stop-now = true ) [ stop ] ;; MANUAL CHANGE FOR DEBUG ;; If needed, each check for validity can be enabled between steps. ;; They have been suppressed (turned into comments) for the sake ;; of speed of execution, but can be re-enabled if a bug has ;; somehow been re-introduced. ;; A single call to the validity check has been left active inside of the ;; Do-Post-Tick step. If it flags a problem, re-activate these to ;; narrow down where the problem starts. ;; Major steps or functions, done once per tick, in order of execution. do-pre-tick ;; if( frb-agents-are-all-valid = false ) ;; [ LOG-TO-FILE ( word "Agents failed validity test: Do-pre-tick." ) ] do-energize ;; if( frb-agents-are-all-valid = false ) ;; [ LOG-TO-FILE ( word "Agents failed validity test: Do-energize." ) ] do-move ;; if( frb-agents-are-all-valid = false ) ;; [ LOG-TO-FILE ( word "Agents failed validity test: Do-move." ) ] do-feed ;; if( frb-agents-are-all-valid = false ) ;; [ LOG-TO-FILE ( word "Agents failed validity test: do-feed." ) ] do-reproduce ;; if( frb-agents-are-all-valid = false ) ;; [ LOG-TO-FILE ( word "Agents failed validity test: Do-reproduce." ) ] do-die ;; if( frb-agents-are-all-valid = false ) ;; [ LOG-TO-FILE ( word "Agents failed validity test: Do-die." ) ] do-post-tick ;; if( frb-agents-are-all-valid = false ) ;; [ LOG-TO-FILE ( word "Agents failed validity test: Do-post-tick." ) ] end ;;-----------------------------------------------------------------------------| ;; D1 - do-pre-tick procedure( s ) ;;-----------------------------------------------------------------------------| to do-pre-tick ;; This routine is to be executed by the observer. if( gb-debug-on = 1 ) [ ifelse( ( gs-debug-step-chooser = "all" ) or ( gs-debug-step-chooser = "pre-tick" ) ) [ set gb-debug-flow-on 1 LOG-TO-FILE "" LOG-TO-FILE word "Do-pre-tick: Debug on.; tick = " ticks ] [ set gb-debug-flow-on 0 ] ] ;; Enter all commands that need to be done before a tick begins. ;; Supressed. f-update-aggregates ;; Advance the tick counter by 1 tick. ifelse( gb-plot-data = true ) [ ;; Advance the ticks by one and update the plots. tick ;; 'tick' is exactly the same as 'update-plots' except that the tick counter ;; is incremented before the plot commands are executed. ] ;; else [ ;; Advance ticks by one but do not update the plots. tick-advance 1 ] ;; End else ;; Once the data is plotted, the per-tick counts can be cleared. ;; List to hold counts of cause of death. set gl-causes-of-death-per-tick ( n-values 6 [0] ) ;; Global EROI system-wide calculations. ifelse( length gl-sys-nrg-returned <= g-dt-for-eroi ) [ ;; Append a zero for new data. set gl-sys-nrg-returned ( lput 0 gl-sys-nrg-returned ) ;; List of changes. set gl-sys-nrg-invested ( lput 0 gl-sys-nrg-invested ) ;; List of changes. ] ;; Else [ ;; Remove old data set gl-sys-nrg-returned ( butfirst gl-sys-nrg-returned ) ;; List of changes. set gl-sys-nrg-invested ( butfirst gl-sys-nrg-invested ) ;; List of changes. ;; Append a zero for new data. set gl-sys-nrg-returned ( lput 0 gl-sys-nrg-returned ) ;; List of changes. set gl-sys-nrg-invested ( lput 0 gl-sys-nrg-invested ) ;; List of changes. ] ;; Reset the scenario number, in case the chooser has been changed. f-set-scenario-number ;; Clear the per-tick data for energy sinks. ;; This call must happen before the seeker population is stabilized. set gl-sinks-per-tick ( n-values 4 [0] ) ask seekers [ set age ( age + 1 ) ] LOG-TO-FILE ( word " Do-pre-tick: Seekers aged." ) LOG-TO-FILE ( word " Do-pre-tick: Halt at tick - " g-halt-at-tick ) LOG-TO-FILE ( word " Do-pre-tick: Current tick - " ticks ) LOG-TO-FILE " Do-pre-tick: Routine completed." end ;;-----------------------------------------------------------------------------| ;; D2 – do-energize procedure(s) ;;-----------------------------------------------------------------------------| to do-energize ;; This routine is to be executed by the observer. if( gb-debug-on = 1 ) [ ifelse( ( gs-debug-step-chooser = "all" ) or ( gs-debug-step-chooser = "energize" ) ) [ set gb-debug-flow-on 1 LOG-TO-FILE "" LOG-TO-FILE word "Do-energize: Debug on; tick = " ticks ] [ set gb-debug-flow-on 0 ] ] ;; The Sun radiates a fixed amount of energy per tick into the system. set g-nrg-in-sunshine ( g-nrg-in-sunshine + g-sun-nrg-per-tick ) set g-total-nrg-in-system ( g-total-nrg-in-system + g-sun-nrg-per-tick ) ;; Record maximum possible Sunshine takeup rate data. let empty-cells ( count patches with [fruit = 0] ) set g-sun-takeup-maximum ( empty-cells * g-nrg-per-deposit ) ;; Record expected Sunshine takeup rate data. set g-sun-takeup-expected ( g-sun-takeup-maximum * g-prob-of-deposit ) ;; Make a list of the patches that are without fruit (without nrg) let empty-patch-list ( patches with [fruit = 0] ) ;; Use the probability of deposit to determine if fruit is added. ask empty-patch-list [ let random-number ( random 100000 ) let threshold ( 100000 * g-prob-of-deposit ) if ( ( random-number <= threshold ) and ( g-nrg-in-sunshine > g-nrg-per-deposit ) ) [ set fruit ( fruit + g-nrg-per-deposit ) set pcolor green ;; Record in system nrg accounts set g-nrg-in-fruit ( g-nrg-in-fruit + g-nrg-per-deposit ) set g-nrg-in-sunshine ( g-nrg-in-sunshine - g-nrg-per-deposit ) ] ] ;; Record actual Sunshine takeup rate data. set g-sun-takeup-actual ( g-sun-nrg-per-tick - g-nrg-in-sunshine ) ;; Discard any remaining energy that has not been absorbed by plants. f-store-data-in-sink ge-sinktype-discard g-nrg-in-sunshine set g-total-nrg-in-system ( g-total-nrg-in-system - g-nrg-in-sunshine ) set g-nrg-in-sunshine 0 ;; Supressed. f-update-aggregates LOG-TO-FILE " Do-energize: procedure completed" end ;;-----------------------------------------------------------------------------| ;; D3 – do-move procedure(s) ;;-----------------------------------------------------------------------------| to do-move ;; This routine is to be executed by the observer. if( gb-debug-on = 1 ) [ ifelse( ( gs-debug-step-chooser = "all" ) or ( gs-debug-step-chooser = "move" ) ) [ set gb-debug-flow-on 1 LOG-TO-FILE "" LOG-TO-FILE word "Do-move: Debug on; tick = " ticks ] [ set gb-debug-flow-on 0 ] ] ;; The seekers move. ask seekers [ if( b-is-ready-to-move = 1 ) [ f-seeker-moves ] ;; End if( b-is-ready-to-move = 1 ) ] ;; End ask seekers ;; Supressed. f-update-aggregates LOG-TO-FILE " Do-move: procedure completed" end ;;-----------------------------------------------------------------------------| ;; A seeker moves according to genes and heuristics. to f-seeker-moves ;; This routine is to be executed by a seeker. ;; When a seeker moves it expends energy out of its pool of nrg. ;; Determine if this seeker has sufficient nrg to move. ifelse ( nrg >= EPM ) [ ;; Establish a heading. f-seeker-sets-heading ;; Step forward forward 1 ;; Expend the nrg to the sink. f-store-data-in-sink ge-sinktype-move-EPM EPM set nrg ( nrg - EPM ) ;; Record the expenditure in the stats. let sum-was ( item belief-affiliation gl-nrg-by-belief ) let sum-is-now ( sum-was - EPM ) set gl-nrg-by-belief ( replace-item belief-affiliation gl-nrg-by-belief sum-is-now ) set g-total-nrg-in-system ( g-total-nrg-in-system - EPM ) ;; Record the expenditure in the EROI variables f-record-ei-for-eroi EPM set b-is-ready-to-move 1 ;; set b-is-ready-to-die 0 ] ;; Else [ ;; The seeker is marked for death, and nrg is removed. ;; It will die and be removed when do-die is executed. f-store-data-in-sink ge-sinktype-move-EPM nrg let sum-was ( item belief-affiliation gl-nrg-by-belief ) let sum-is-now ( sum-was - nrg ) set gl-nrg-by-belief ( replace-item belief-affiliation gl-nrg-by-belief sum-is-now ) set g-total-nrg-in-system ( g-total-nrg-in-system - nrg ) ;; Record the expenditure in the EROI variables f-record-ei-for-eroi nrg set nrg 0 set cause-of-death ge-cod-hunger set b-is-ready-to-move 0 set b-is-ready-to-die 1 ] ;; End else LOG-TO-FILE ( word " Do-move: S(heading,nrg,move-flag,die-flag) - (" heading "," floor nrg "," b-is-ready-to-move"," b-is-ready-to-die ")" ) ;; End of f-seeker-moves end ;;-----------------------------------------------------------------------------| ;; A seeker sets a heading using c1-pheno. to f-seeker-sets-heading ;; This routine is to be executed by a seeker. ;; The agent will consult its phenotypic characters, to determine the ;; best direction for the next heading. It is blind, and cannot sense ;; other agents, or patches of fruit. So the only guidance it has is ;; the genetic information received from its mother, or from the social ;; wisdom learned via its belief and tribal affiliations. ;; Take note of the current heading. let old-heading heading ;; DECIDE HOW MUCH TO TURN AS DELTA-HEADING. ;; Add up the indicators. let sum-of-phenos ( round ( sum c1-pheno ) ) LOG-TO-FILE ( word " Do-move: Phenos - " c1-pheno ) LOG-TO-FILE ( word " Do-move: Summed Phenos - " sum-of-phenos ) ;; Each pheno is derived from genes plus learnings. The size of ;; the pheno creates a proportional target interval in the sum. ;; Choose an interval (i.e. choose a pheno) by getting a random number. let random-number ( random-float sum-of-phenos ) LOG-TO-FILE ( word " Do-move: Random Number - " random-number ) ;; The random-number must fall between two sequential pheno aggregates. ;; E.g if the random-number is 50%, and the first two pheno numbers ;; are 13% and 25% (+=38%) then that sum is less than 50%. If the ;; next pheno is 20%, then the aggregate is 58%, which is bigger ;; than 50%. So it falls between the 2nd and 3rd aggregate of the ;; phenos. The third interval then is selected "randomly" with ;; probability determined by its relative size, among all phenos. ;; Due to zero-based indexing, the correct index is 3-1 = 2. let counter 0 let good-index -1 let this-pheno 0 let this-sum 0 let next-sum 0 while [ counter < 8 ] ;; Do not overshoot [ LOG-TO-FILE ( word " Do-move: Counter - " counter ) set this-pheno ( item counter c1-pheno ) LOG-TO-FILE ( word " Do-move: This sum - " this-sum ) LOG-TO-FILE ( word " Do-move: Pheno - " this-pheno ) set next-sum ( this-pheno + this-sum ) LOG-TO-FILE ( word " Do-move: Next sum - " next-sum ) if ( ( random-number >= this-sum ) and ( random-number < next-sum ) ) [ set good-index counter LOG-TO-FILE ( word " Do-move: Selected gene - " good-index ) ] set this-sum next-sum set counter ( counter + 1 ) ] let heading-delta ( item good-index gl-heading-list ) LOG-TO-FILE ( word " Do-move: Old heading - " heading ) ;; Set the new heading set heading ( heading + heading-delta ) LOG-TO-FILE ( word " Do-move: New heading - " heading ) ;; End of f-seeker-sets-heading end ;;-----------------------------------------------------------------------------| ;; Store data in the lists of sinks. to f-store-data-in-sink [ sinktype value ] ;; This routine is to be executed by anyone. ;; Record it in the per-tick list. let old-value ( item sinktype gl-sinks-per-tick ) let new-value ( old-value + value ) set gl-sinks-per-tick ( replace-item sinktype gl-sinks-per-tick new-value ) ;; Record it in the cumulative list. set old-value ( item sinktype gl-sinks-cumulative ) set new-value ( old-value + value ) set gl-sinks-cumulative ( replace-item sinktype gl-sinks-cumulative new-value ) ;; end of f-store-data-in-sink end ;;-----------------------------------------------------------------------------| ;; Increment the count in the lists of causes of death. to f-increment-cod-list [ breedtype codtype ] ;; This routine is to be executed by anyone. ;; Record it in the per-tick list. let old-count ( item codtype gl-causes-of-death-per-tick ) let new-count ( old-count + 1 ) set gl-causes-of-death-per-tick ( replace-item codtype gl-causes-of-death-per-tick new-count ) ;; Record it in the cumulative list. set old-count ( item codtype gl-causes-of-death-cumulative ) set new-count ( old-count + 1 ) set gl-causes-of-death-cumulative ( replace-item codtype gl-causes-of-death-cumulative new-count ) ;; End of f-increment-cod-list end ;;-----------------------------------------------------------------------------| ;; Record the 'energy invested' component of EROI calculation. to f-record-ei-for-eroi [eroi-ei] ;; This routine is to be executed by a seeker. ;; NOTE: EROI is ER/EI, that is Benefits over Costs, or (B/C). ;; ETA is ER/(ER+EI), that is Benefits over Income, or (B/I). ;; LOG-TO-FILE ( word " Do-move: Counter-eroi - " counter-eroi ) ;; LOG-TO-FILE ( word " Do-move: Nrg-returned - " nrg-returned ) ;; LOG-TO-FILE ( word " Do-move: Nrg-invested - " nrg-invested ) ;; LOG-TO-FILE ( word " Do-move: Nrg-income - " nrg-income ) ;; LOG-TO-FILE ( word " Do-move: L-er - " l-er ) ;; LOG-TO-FILE ( word " Do-move: L-ei - " l-ei ) LOG-TO-FILE ( word " Do-move: g-sys-ei was - " gl-sys-nrg-invested ) ;; First, record it in the system-wide data. let last-index ( ( length gl-sys-nrg-invested ) - 1 ) let old-value ( last gl-sys-nrg-invested ) let new-value ( old-value + eroi-ei ) set gl-sys-nrg-invested ( replace-item last-index gl-sys-nrg-invested new-value ) LOG-TO-FILE ( word " Do-move: g-sys-ei is now - " gl-sys-nrg-invested ) ;; Check to determine whether we are only appending data to the list, ;; or we are dropping old data and appending new data. ifelse ( counter-eroi < g-dt-for-eroi ) [ ;; Case of appending new data only. ;; Increment the counter - done only in move-related function. set counter-eroi ( counter-eroi + 1 ) ;; Append new entry to last of l-ei. set l-ei ( lput eroi-ei l-ei ) ;; Append a place-holder zero to l-er. set l-er ( lput 0 l-er ) ] ;; Else [ ;; Case of dropping/appending data ;; Remove oldest entry. set l-ei ( butfirst l-ei ) ;; Append new entry to last of l-ei set l-ei ( lput eroi-ei l-ei ) ;; Adjust l-er, removing oldest and appending a place-holder zero. ;; Remove oldest entry. set l-er ( butfirst l-er ) ;; Append zero to last of l-er set l-er ( lput 0 l-er ) ] ;; End else dropping/appending ;; Re-calculate the seekers stats. set nrg-invested ( sum l-ei ) set nrg-income ( nrg-returned + nrg-invested ) set eroi 0 if (nrg-invested > 0) [ set eroi ( nrg-returned / nrg-invested ) ] set eta 0 if (nrg-income > 0) [ set eta ( nrg-returned / nrg-income ) ] ;; LOG-TO-FILE ( word " Do-move: Counter-eroi - " counter-eroi ) ;; LOG-TO-FILE ( word " Do-move: Nrg-returned - " nrg-returned ) ;; LOG-TO-FILE ( word " Do-move: Nrg-invested - " nrg-invested ) ;; LOG-TO-FILE ( word " Do-move: Nrg-income - " nrg-income ) ;; LOG-TO-FILE ( word " Do-move: L-er - " l-er ) ;; LOG-TO-FILE ( word " Do-move: L-ei - " l-ei ) ;; End of f-record-ei-for-eroi end ;;-----------------------------------------------------------------------------| ;; D4 – do-feed procedure(s) ;;-----------------------------------------------------------------------------| to do-feed ;; This routine is to be executed by the observer. if( gb-debug-on = 1 ) [ ifelse( ( gs-debug-step-chooser = "all" ) or ( gs-debug-step-chooser = "feed" ) ) [ set gb-debug-flow-on 1 LOG-TO-FILE "" LOG-TO-FILE word "Do-feed: Debug on; tick = " ticks ] [ set gb-debug-flow-on 0 ] ] ;; Agents feed on fruit found in patches. ask seekers [ let this-patch patch-here ;; handle to the patch under the seeker. let nrg-available ( [fruit] of this-patch ) if ( ( nrg < ( EPA - g-nrg-per-deposit ) ) and ( nrg-available > 0 ) ) [ ;; Case of there is food to eat. ;; Seeker eats. set nrg ( nrg + nrg-available ) let sum-was ( item belief-affiliation gl-nrg-by-belief ) let sum-is-now ( sum-was + nrg-available ) set gl-nrg-by-belief ( replace-item belief-affiliation gl-nrg-by-belief sum-is-now ) f-record-er-for-eroi nrg-available ask this-patch [ set fruit 0 set g-nrg-in-fruit ( g-nrg-in-fruit - nrg-available ) set pcolor brown ] ] ;; A seeker checks for a local guru with similar belief affiliation. f-seek-guru-wisdom ;; A seeker checks for a local tribal elder of the same tribal affiliation. f-seek-tribal-wisdom ] ;; End of ask seekers. ;; Supressed. f-update-aggregates LOG-TO-FILE " Do-feed: procedure completed" ;; End Do-feed procedure. end ;;-----------------------------------------------------------------------------| ;; Check if a guru exists locally, and seek a wisdom transfer. to f-seek-guru-wisdom ;; This routine is to be executed by a seeker. ;; Do this routine for scenarios 2 and 3 only. if( g-scenario-number > 1 ) [ ;; Case of scenarios 2 and 3. ;; Unpack and rename needed characters let mywho who let mypatch patch-here let myage age let mybelief belief-affiliation ;; Select a local guru. let belief-elders ( seekers with [ ( who != mywho ) and ( patch-here = mypatch ) and ( belief-affiliation = mybelief ) and ( age >= myage ) ] ) if( ( count belief-elders ) > 0 ) [ ;; Case of guru exists. LOG-TO-FILE ( word " Do-feed: wXFer - SEEKING GURU'S WISDOM" ) LOG-TO-FILE ( word " Do-feed: wXFer - Elders - " ( [who] of belief-elders ) ) let maxage ( max [age] of belief-elders ) let guru ( one-of ( belief-elders with [age = maxage] ) ) LOG-TO-FILE ( word " Do-feed: wXFer - Guru found - " guru ) LOG-TO-FILE ( word " Do-feed: wXFer - Belief affiliation - " mybelief ) ;; I estimate that, at steady state, only 1 in ten seekers will ;; ever experience enlightenment by this routine. ;; Perform the transfer of wisdom. ;; It is assumed that, since the guru has lived longer, his belief ;; has been tested more. Since the guru is still alive ;; that level of belief is to be emulated. let mylevel ( item mybelief c1-learn ) let gurulevel 0 ask guru [ set gurulevel ( item mybelief c1-learn ) ] let level-delta ( ( gurulevel - mylevel ) / 2 ) let mynewlevel ( mylevel + level-delta ) set c1-learn ( replace-item mybelief c1-learn mynewlevel ) LOG-TO-FILE ( word " Do-feed: wXFer - MyOldLevel - " mylevel ", GuruLevel - " gurulevel ", LevelDelta - " level-delta ", MyNewLevel - " mynewlevel ) ] ;; End if guru exists ] ;; End if scenario > 1 ;; End of f-seek-guru-wisdom end ;;-----------------------------------------------------------------------------| ;; Check if a tribal elder exists locally, and seek a wisdom transfer. to f-seek-tribal-wisdom ;; This routine is to be executed by a seeker. ;; Do this routine for scenario 3 only. if( g-scenario-number > 2 ) [ ;; Case of scenario 3. ;; Unpack and rename needed characters let mywho who let mypatch patch-here let myage age let mytribe tribal-affiliation ;; Select a local tribal elder. let tribal-elders ( seekers with [ ( who != mywho ) and ( patch-here = mypatch ) and ( tribal-affiliation = mytribe ) and ( age >= myage ) ] ) if( ( count tribal-elders ) > 0 ) [ ;; Case of tribal elder exists. LOG-TO-FILE ( word " Do-feed: wXFer - SEEKING TRIBAL WISDOM" ) LOG-TO-FILE ( word " Do-feed: wXFer - Tribal elders - " ( [who] of tribal-elders ) ) let maxage ( max [age] of tribal-elders ) let tribal-elder ( one-of ( tribal-elders with [age = maxage] ) ) LOG-TO-FILE ( word " Do-feed: wXFer - Teacher found - " tribal-elder ) ;; Transfer from the tribal elder to the seeker. let target-gene ( [belief-affiliation] of tribal-elder ) LOG-TO-FILE ( word " Do-feed: wXFer - Belief affiliation - " target-gene ) let mylevel ( item target-gene c1-learn ) let elderlevel 0 ask tribal-elder [ set elderlevel ( item target-gene c1-learn ) ] let level-delta ( ( elderlevel - mylevel ) / 2 ) let mynewlevel ( mylevel + level-delta ) set c1-learn ( replace-item target-gene c1-learn mynewlevel ) LOG-TO-FILE ( word " Do-feed: wXFer - MyOldLevel - " mylevel ", ElderLevel - " elderlevel ", LevelDelta - " level-delta ", MyNewLevel - " mynewlevel ) ] ;; End case of elder exists ] ;; End Scenario 3 special processing for tribal connections. ;; End of f-seek-Tribal-wisdom end ;;-----------------------------------------------------------------------------| ;; Record the 'energy returned' component of EROI calculation. to f-record-er-for-eroi [eroi-er] ;; This routine is to be executed by a seeker. ;; NOTE: EROI is ER/EI, that is Benefits over Costs, or (B/C). ;; ETA is ER/(ER+EI), that is Benefits over Income, or (B/I). ;; LOG-TO-FILE ( word " Do-feed: Counter-eroi - " counter-eroi ) ;; LOG-TO-FILE ( word " Do-feed: Nrg-returned - " nrg-returned ) ;; LOG-TO-FILE ( word " Do-feed: Nrg-invested - " nrg-invested ) ;; LOG-TO-FILE ( word " Do-feed: Nrg-income - " nrg-income ) ;; LOG-TO-FILE ( word " Do-feed: L-er - " l-er ) ;; LOG-TO-FILE ( word " Do-feed: L-ei - " l-ei ) ;; LOG-TO-FILE ( word " Do-move: g-sys-er was - " gl-sys-nrg-returned ) ;; First, record it in the system-wide data. let last-index ( ( length gl-sys-nrg-returned ) - 1 ) let old-value ( last gl-sys-nrg-returned ) let new-value ( old-value + eroi-er ) set gl-sys-nrg-returned ( replace-item last-index gl-sys-nrg-returned new-value ) ;; LOG-TO-FILE ( word " Do-move: g-sys-er is now - " gl-sys-nrg-returned ) ;; This routine is called by Do-feed. ;; The associated routine f-record-er-for-eroi is called by Do-move. ;; The two routines work together to calculate EROI. ;; DO NOT increment the counter here - done only in move-related function. ;; set counter-eroi ( counter-eroi + 1 ) ;; Remove the place-holder zero, put there in the move-related routine. set l-er ( butlast l-er ) ;; Append new entry to last of l-er. set l-er ( lput eroi-er l-er ) ;; Re-calculate the seekers stats. set nrg-returned ( sum l-er ) set nrg-income ( nrg-returned + nrg-invested ) set eroi 0 if (nrg-invested > 0) [ set eroi ( nrg-returned / nrg-invested ) ] set eta 0 if (nrg-income > 0) [ set eta ( nrg-returned / nrg-income ) ] ;; LOG-TO-FILE ( word " Do-feed: Counter-eroi - " counter-eroi ) ;; LOG-TO-FILE ( word " Do-feed: Nrg-returned - " nrg-returned ) ;; LOG-TO-FILE ( word " Do-feed: Nrg-invested - " nrg-invested ) ;; LOG-TO-FILE ( word " Do-feed: Nrg-income - " nrg-income ) ;; LOG-TO-FILE ( word " Do-feed: L-er - " l-er ) ;; LOG-TO-FILE ( word " Do-feed: L-ei - " l-ei ) ;; End of f-record-er-for-eroi end ;;-----------------------------------------------------------------------------| ;; D5 – do-reproduce procedure(s) ;;-----------------------------------------------------------------------------| to do-reproduce ;; This routine is to be executed by the observer. if( gb-debug-on = 1 ) [ ifelse( ( gs-debug-step-chooser = "all" ) or ( gs-debug-step-chooser = "reproduce" ) ) [ set gb-debug-flow-on 1 LOG-TO-FILE "" LOG-TO-FILE word "Do-rep: Debug on; tick = " ticks ] [ set gb-debug-flow-on 0 ] ] ask seekers [ f-set-seeker-repro-flag f-reproduce-seeker-by-fission ] ;; Supressed. f-update-aggregates LOG-TO-FILE " Do-rep: procedure completed" end ;;-----------------------------------------------------------------------------| ;; f-set-seeker-repro-flag to f-set-seeker-repro-flag ;; This routine is to be executed by a seeker. set b-is-ready-to-reproduce 1 ;; i.e. true is the default. if( nrg < RET ) [ set b-is-ready-to-reproduce 0 ] ;; i.e. false due to lack of health. if( age < RAT ) [ set b-is-ready-to-reproduce 0 ] ;; i.e. false due to lack of maturity. if( b-is-ready-to-reproduce = 1 ) [ LOG-TO-FILE ( word " Do-rep: S(age,nrg,rep-flag) - (" age "," floor nrg "," b-is-ready-to-reproduce ")" ) ] ;; End f-set-seeker-repro-flag end ;;-----------------------------------------------------------------------------| ;; A seeker reproduces via fission, one mother having two daughters. to f-reproduce-seeker-by-fission ;; This routine is to be executed by a seeker. if( b-is-ready-to-reproduce = 1 ) ;; 1 = true [ LOG-TO-FILE ( word " Do-rep: seeker Ma - " who ) let mother self let mothers-who who let mothers-patch patch-here let first-share-of-nrg floor( nrg / 2 ) let second-share-of-nrg ( nrg - first-share-of-nrg ) let daughter-count 0 ask mothers-patch [ sprout-seekers 2 [ set daughter-count ( daughter-count + 1 ) LOG-TO-FILE ( word " Do-rep: seeker D" daughter-count " - " who ) f-initialize-new-seeker set color ( [color] of mother ) ;; Copy the C1 genetic/learned material. set c1-bases ( [c1-bases] of mother ) set c1-genes ( [c1-genes] of mother ) set c1-learn ( [c1-learn] of mother ) set c1-stren ( [c1-stren] of mother ) set c1-pheno ( [c1-pheno] of mother ) set belief-affiliation ( [belief-affiliation] of mother ) set tribal-affiliation ( [tribal-affiliation] of mother ) ;; C2 genes are static. set DAT ( [DAT] of mother ) set DET ( [DET] of mother ) set RAT ( [RAT] of mother ) set RET ( [RET] of mother ) set EPM ( [EPM] of mother ) set EPA ( [EPA] of mother ) ;; Note the mother of this daughter. set mas-who ( [who] of mother ) set age 0 ifelse ( daughter-count = 1 ) [ set nrg first-share-of-nrg ] [ set nrg second-share-of-nrg ] set cause-of-death 0 set b-is-ready-to-move 1 set b-is-ready-to-reproduce 0 set b-is-ready-to-die 0 ;; Variables for calculating individual EROI and ETA. ;; All inherited from mother. set nrg-returned ( [nrg-returned] of mother ) set nrg-invested ( [nrg-invested] of mother ) set nrg-income ( [nrg-income] of mother ) set eroi ( [eroi] of mother ) set eta ( [eta] of mother ) set l-er ( [l-er] of mother ) set l-ei ( [l-ei] of mother ) set counter-eroi ( [counter-eroi] of mother ) f-mutate-new-seeker ] ] ;; Set the cause of death for the mother. set cause-of-death ge-cod-fission ;; The mother disappears after fission, leaving two daughters. ;; Death actually occurs in the Do-die step. ] ;; End f-reproduce-seeker-by-fission end ;;-----------------------------------------------------------------------------| ;; A new seeker mutates, changing the genetic basis of strategies. to f-mutate-new-seeker ;; This routine is to be executed by a seeker. ;; Decide if a genetic mutation is to happen. let random-number ( random-float 1 ) let threshold ( g-prob-of-mutation ) LOG-TO-FILE ( word " Do-rep: PreMut (RN, TH) - (" random-number ", " threshold ")" ) if ( random-number <= threshold ) [ ;; Case of mutation to be done. LOG-TO-FILE ( word " Do-rep: PreMut c1-bases - " c1-bases ) LOG-TO-FILE ( word " Do-rep: PreMut c1-genes - " c1-genes ) LOG-TO-FILE ( word " Do-rep: PreMut c1-learn - " c1-learn ) LOG-TO-FILE ( word " Do-rep: PreMut c1-stren - " c1-stren ) LOG-TO-FILE ( word " Do-rep: PreMut c1-pheno - " c1-pheno ) ;; Select the gene to be mutated. These genes control ;; the search strategy. let gene-to-be-mutated ( random 8 ) LOG-TO-FILE ( word " Do-rep: Target gene # - " gene-to-be-mutated ) ;; Mutate the gene base. let oldbase ( item gene-to-be-mutated c1-bases ) LOG-TO-FILE ( word " Do-rep: Old base value - " oldbase ) ;; Choose a factor for the base. let base-factor ( item (random 8) gl-base-factors ) ;; Mutate it let newbase ( oldbase * base-factor ) LOG-TO-FILE ( word " Do-rep: Factor - " base-factor ) set c1-bases ( replace-item gene-to-be-mutated c1-bases newbase ) LOG-TO-FILE ( word " Do-rep: New base value - " newbase ) ;; Mutate the gene. The gene value is an integer of either sign. let oldgene ( item gene-to-be-mutated c1-genes ) LOG-TO-FILE ( word " Do-rep: Old gene value - " oldgene ) ;; Decide whether it will increase or decrease in value. let delta ( -1 + ( 2 * ( random 2 ) ) ) ;; Either a -1 or a 1. LOG-TO-FILE ( word " Do-rep: Delta - " delta ) let newgene ( oldgene + delta ) set c1-genes ( replace-item gene-to-be-mutated c1-genes newgene ) LOG-TO-FILE ( word " Do-rep: New gene value - " newgene ) ;; The belief values do not mutate here. ;; Calculate the strengths and phenotypic characters. f-find-strens-n-phenos LOG-TO-FILE ( word " Do-rep: AftMut c1-bases - " c1-bases ) LOG-TO-FILE ( word " Do-rep: AftMut c1-genes - " c1-genes ) LOG-TO-FILE ( word " Do-rep: AftMut c1-learn - " c1-learn ) LOG-TO-FILE ( word " Do-rep: AftMut c1-stren - " c1-stren ) LOG-TO-FILE ( word " Do-rep: AftMut c1-pheno - " c1-pheno ) ] ;; Belief values do not alter in scenarios 0 and 1. if( g-scenario-number > 1 ) [ ;; Decide if a shift of belief value is to happen. set random-number ( random-float 1 ) set threshold ( g-prob-of-belief-drift ) LOG-TO-FILE ( word " Do-rep: PreAlt (RN, TH) - (" random-number ", " threshold ")" ) if ( random-number <= threshold ) [ ;; Case of belief drift to be done. LOG-TO-FILE ( word " Do-rep: PreAlt c1-bases - " c1-bases ) LOG-TO-FILE ( word " Do-rep: PreAlt c1-genes - " c1-genes ) LOG-TO-FILE ( word " Do-rep: PreAlt c1-learn - " c1-learn ) LOG-TO-FILE ( word " Do-rep: PreAlt c1-stren - " c1-stren ) LOG-TO-FILE ( word " Do-rep: PreAlt c1-pheno - " c1-pheno ) ;; Alter the belief. The belief value is an integer ;; of either sign. let myoldbelief ( item belief-affiliation c1-learn ) LOG-TO-FILE ( word " Do-rep: Belief Affiliation - " belief-affiliation ) LOG-TO-FILE ( word " Do-rep: Old belief value - " myoldbelief ) ;; Decide whether it will increase or decrease in value. let delta ( -1 + ( 2 * ( random 2 ) ) ) ;; Either -1 or 1. LOG-TO-FILE ( word " Do-rep: Delta - " delta ) let mynewbelief ( myoldbelief + delta ) LOG-TO-FILE ( word " Do-rep: New belief value - " mynewbelief ) set c1-learn ( replace-item belief-affiliation c1-learn mynewbelief ) ;; Calculate the strengths and phenotypic characters. f-find-strens-n-phenos LOG-TO-FILE ( word " Do-rep: AftAlt c1-bases - " c1-bases ) LOG-TO-FILE ( word " Do-rep: AftAlt c1-genes - " c1-genes ) LOG-TO-FILE ( word " Do-rep: AftAlt c1-learn - " c1-learn ) LOG-TO-FILE ( word " Do-rep: AftAlt c1-stren - " c1-stren ) LOG-TO-FILE ( word " Do-rep: AftAlt c1-pheno - " c1-pheno ) ] ] ;; End of f-mutate-new-seeker end ;;-----------------------------------------------------------------------------| ;; D6 – do-die procedure(s) ;;-----------------------------------------------------------------------------| to do-die ;; This routine is to be executed by the observer. if( gb-debug-on = 1 ) [ ifelse( ( gs-debug-step-chooser = "all" ) or ( gs-debug-step-chooser = "die" ) ) [ set gb-debug-flow-on 1 LOG-TO-FILE "" LOG-TO-FILE word "Do-die: Debug on; tick = " ticks ] [ set gb-debug-flow-on 0 ] ] if( ( count seekers ) > 0 ) [ ask seekers [ f-set-seeker-death-flag f-seeker-dies ] ] ;; Supressed. f-update-aggregates LOG-TO-FILE " Do-die: procedure completed" end ;;-----------------------------------------------------------------------------| ;; f-set-seeker-death-flag to f-set-seeker-death-flag ;; This routine is to be executed by a seeker. set b-is-ready-to-die 0 ;; i.e. false, default. ;; If a cause of death has already been noted, it dies. ifelse( cause-of-death > ge-cod-none ) [ ;; A cause of death has been previously flagged. ;; This is either due to hunger (in do-move) or fission (in do-repro). ;; In both cases nrg has been stripped out already. ;; In the cases of DET and DAT, the flag is not yet set, ;; and the nrg remains. set b-is-ready-to-die 1 ] ;; Else [ ;; No cause of death has been set yet. Check basic vital signs. if( nrg <= DET ) ;; Death Energy Threshold. [ set b-is-ready-to-die 1 set cause-of-death ge-cod-hunger f-store-data-in-sink ge-sinktype-die-det nrg let sum-was ( item belief-affiliation gl-nrg-by-belief ) let sum-is-now ( sum-was - nrg ) set gl-nrg-by-belief ( replace-item belief-affiliation gl-nrg-by-belief sum-is-now ) set g-total-nrg-in-system ( g-total-nrg-in-system - nrg ) set nrg 0 ] if( age > DAT ) ;; Death Age Threshold. [ set b-is-ready-to-die 1 set cause-of-death ge-cod-oldage f-store-data-in-sink ge-sinktype-die-dat nrg let sum-was ( item belief-affiliation gl-nrg-by-belief ) let sum-is-now ( sum-was - nrg ) set gl-nrg-by-belief ( replace-item belief-affiliation gl-nrg-by-belief sum-is-now ) set g-total-nrg-in-system ( g-total-nrg-in-system - nrg ) set nrg 0 ] ] if( b-is-ready-to-die = 1 ) [ LOG-TO-FILE ( WORD " Do-die: S(age,nrg,cod) - (" age "," nrg "," cause-of-death ")" ) ] ;; End f-set-seeker-death-flag end ;;-----------------------------------------------------------------------------| ;; f-seeker-dies to f-seeker-dies ;; This routine is to be executed by a seeker. if( b-is-ready-to-die = 1 ) [ ;; Nrg was stripped out in do-move step. ;; However, nrg may exist for those who die of old age. f-increment-cod-list breed cause-of-death die ;; The seeker disappears from the system. ] ;; End f-seeker-dies end ;;-----------------------------------------------------------------------------| ;; D7 - do-post-tick procedure(s) ;;-----------------------------------------------------------------------------| to do-post-tick ;; This routine is to be executed by the observer. if( gb-debug-on = 1 ) [ ifelse( ( gs-debug-step-chooser = "all" ) or ( gs-debug-step-chooser = "post-tick" ) ) [ set gb-debug-flow-on 1 LOG-TO-FILE "" LOG-TO-FILE word "Do-Post-tick: Debug on; tick = " ticks ] [ set gb-debug-flow-on 0 ] ] ;; MANUAL CHANGE FOR DEBUG. ;; This is a call to a debug routine which could be suppressed if all is okay. ;; This is one of a group of such calls, most of which are between steps in ;; the 'Go' routine. They are suppressed there, but can be enabled again. ;; I have decided to leave this one active, for now. ;; It checks all agents, every tick, to ensure that all values are greater than ;; or equal to zero. if( frb-agents-are-all-valid = false ) [ LOG-TO-FILE ( word " Do-post-tick: Agents failed validity test." ) ] ;; Global EROI system-wide calculations. set g-sys-nrg-returned ( sum gl-sys-nrg-returned ) ;; Total nrg returned within delta T. set g-sys-nrg-invested ( sum gl-sys-nrg-invested ) ;; Total nrg invested within delta T. set g-sys-nrg-income ( g-sys-nrg-returned + g-sys-nrg-invested ) set g-sys-eroi 0 ;; System-wide EROI, per tick. if( g-sys-nrg-invested != 0 ) [ set g-sys-eroi ( g-sys-nrg-returned / g-sys-nrg-invested ) ] set g-sys-eta 0 ;; System-wide ETA, per tick. if( g-sys-nrg-income != 0 ) [ set g-sys-eta ( g-sys-nrg-returned / g-sys-nrg-income ) ] ;; Update the aggregates for display in the monitors. f-update-aggregates display LOG-TO-FILE " Do-post-tick: procedure completed." end ;;-----------------------------------------------------------------------------| ;; SECTION E – DRAWING AND MAINTENANCE PROCEDURE(S) ;;-----------------------------------------------------------------------------| ;;-----------------------------------------------------------------------------| ;; Update the values of global aggregate numbers. to f-update-aggregates ;; This routine is to be executed by the observer. ;; Although this is a display-only routine, it may implicitly call the ;; PRNG and so may have an effect on the trajectory of the model. In a ;; standard 'go' run it is called only once per tick, before graphs are ;; updated. If you use the one-step debug buttons, it is called once ;; after each step, so debug runs that use those buttons will not ;; replicate a real run. ;;---------------------------------------------------------------------------| ;; The following agent sets, counts and averages are for data collection ;; and display in monitors and plots. ;; Counts set g-no-of-patches ( count patches ) foreach gl-index-list [ set gl-no-of-seekers ( replace-item ? gl-no-of-seekers ( count seekers with [belief-affiliation = ?] ) ) ] set g-no-of-seekers ( sum gl-no-of-seekers ) ;; For the 8-beliefs society, track those with targeted belief affiliation. set g-no-with-this-belief ( count seekers with [belief-affiliation = g-gene-to-adjust] ) ;; Averages - seekers ifelse( 0 = ( count seekers ) ) [ set g-ave-age 0 ;; age of seekers set g-ave-nrg 0 ;; nrg of seekers set g-ind-min-eroi 1 ;; eroi of seekers set g-ind-ave-eroi 1 ;; eroi of seekers set g-ind-max-eroi 1 ;; eroi of seekers set g-ind-min-eta 0.5 ;; eta of seekers set g-ind-ave-eta 0.5 ;; eta of seekers set g-ind-max-eta 0.5 ;; eta of seekers set g-ave-C1-b0 0 ;; c1, base character, gene-0 set g-ave-C1-b1 0 ;; c1, base character, gene-1 set g-ave-C1-b2 0 ;; c1, base character, gene-2 set g-ave-C1-b3 0 ;; c1, base character, gene-3 set g-ave-C1-b4 0 ;; c1, base character, gene-4 set g-ave-C1-b5 0 ;; c1, base character, gene-5 set g-ave-C1-b6 0 ;; c1, base character, gene-6 set g-ave-C1-b7 0 ;; c1, base character, gene-7 set g-ave-C1-g0 0 ;; c1, genotypic character, gene-0 set g-ave-C1-g1 0 ;; c1, genotypic character, gene-1 set g-ave-C1-g2 0 ;; c1, genotypic character, gene-2 set g-ave-C1-g3 0 ;; c1, genotypic character, gene-3 set g-ave-C1-g4 0 ;; c1, genotypic character, gene-4 set g-ave-C1-g5 0 ;; c1, genotypic character, gene-5 set g-ave-C1-g6 0 ;; c1, genotypic character, gene-6 set g-ave-C1-g7 0 ;; c1, genotypic character, gene-7 set g-ave-C1-l0 0 ;; c1, learned character, gene-0 set g-ave-C1-l1 0 ;; c1, learned character, gene-1 set g-ave-C1-l2 0 ;; c1, learned character, gene-2 set g-ave-C1-l3 0 ;; c1, learned character, gene-3 set g-ave-C1-l4 0 ;; c1, learned character, gene-4 set g-ave-C1-l5 0 ;; c1, learned character, gene-5 set g-ave-C1-l6 0 ;; c1, learned character, gene-6 set g-ave-C1-l7 0 ;; c1, learned character, gene-7 set g-ave-C1-s0 0 ;; c1, strength character, gene-0 set g-ave-C1-s1 0 ;; c1, strength character, gene-1 set g-ave-C1-s2 0 ;; c1, strength character, gene-2 set g-ave-C1-s3 0 ;; c1, strength character, gene-3 set g-ave-C1-s4 0 ;; c1, strength character, gene-4 set g-ave-C1-s5 0 ;; c1, strength character, gene-5 set g-ave-C1-s6 0 ;; c1, strength character, gene-6 set g-ave-C1-s7 0 ;; c1, strength character, gene-7 set g-ave-C1-p0 0 ;; c1, phenotypic character, gene-0 set g-ave-C1-p1 0 ;; c1, phenotypic character, gene-1 set g-ave-C1-p2 0 ;; c1, phenotypic character, gene-2 set g-ave-C1-p3 0 ;; c1, phenotypic character, gene-3 set g-ave-C1-p4 0 ;; c1, phenotypic character, gene-4 set g-ave-C1-p5 0 ;; c1, phenotypic character, gene-5 set g-ave-C1-p6 0 ;; c1, phenotypic character, gene-6 set g-ave-C1-p7 0 ;; c1, phenotypic character, gene-7 set gl-nrg-by-tribe [ 0 0 0 0 0 0 0 0 0 0 ] ;; Max of 10 tribes ] ;; Else [ set g-ave-age ( sum [age] of seekers ) / g-no-of-seekers set g-ave-nrg ( sum [nrg] of seekers ) / g-no-of-seekers set g-ind-min-eroi ( min [eroi] of seekers ) set g-ind-ave-eroi ( sum [eroi] of seekers ) / g-no-of-seekers set g-ind-max-eroi ( max [eroi] of seekers ) set g-ind-min-eta ( min [eta] of seekers ) set g-ind-ave-eta ( sum [eta] of seekers ) / g-no-of-seekers set g-ind-max-eta ( max [eta] of seekers ) set g-ave-C1-b0 ( f-compute-C1-bases-average 0 ) set g-ave-C1-b1 ( f-compute-C1-bases-average 1 ) set g-ave-C1-b2 ( f-compute-C1-bases-average 2 ) set g-ave-C1-b3 ( f-compute-C1-bases-average 3 ) set g-ave-C1-b4 ( f-compute-C1-bases-average 4 ) set g-ave-C1-b5 ( f-compute-C1-bases-average 5 ) set g-ave-C1-b6 ( f-compute-C1-bases-average 6 ) set g-ave-C1-b7 ( f-compute-C1-bases-average 7 ) set g-ave-C1-g0 ( f-compute-C1-genes-average 0 ) set g-ave-C1-g1 ( f-compute-C1-genes-average 1 ) set g-ave-C1-g2 ( f-compute-C1-genes-average 2 ) set g-ave-C1-g3 ( f-compute-C1-genes-average 3 ) set g-ave-C1-g4 ( f-compute-C1-genes-average 4 ) set g-ave-C1-g5 ( f-compute-C1-genes-average 5 ) set g-ave-C1-g6 ( f-compute-C1-genes-average 6 ) set g-ave-C1-g7 ( f-compute-C1-genes-average 7 ) set g-ave-C1-l0 ( f-compute-c1-learn-average 0 ) set g-ave-C1-l1 ( f-compute-c1-learn-average 1 ) set g-ave-C1-l2 ( f-compute-c1-learn-average 2 ) set g-ave-C1-l3 ( f-compute-c1-learn-average 3 ) set g-ave-C1-l4 ( f-compute-c1-learn-average 4 ) set g-ave-C1-l5 ( f-compute-c1-learn-average 5 ) set g-ave-C1-l6 ( f-compute-c1-learn-average 6 ) set g-ave-C1-l7 ( f-compute-c1-learn-average 7 ) set g-ave-C1-s0 ( f-compute-c1-stren-average 0 ) set g-ave-C1-s1 ( f-compute-c1-stren-average 1 ) set g-ave-C1-s2 ( f-compute-c1-stren-average 2 ) set g-ave-C1-s3 ( f-compute-c1-stren-average 3 ) set g-ave-C1-s4 ( f-compute-c1-stren-average 4 ) set g-ave-C1-s5 ( f-compute-c1-stren-average 5 ) set g-ave-C1-s6 ( f-compute-c1-stren-average 6 ) set g-ave-C1-s7 ( f-compute-c1-stren-average 7 ) set g-ave-C1-p0 ( f-compute-c1-pheno-average 0 ) set g-ave-C1-p1 ( f-compute-c1-pheno-average 1 ) set g-ave-C1-p2 ( f-compute-c1-pheno-average 2 ) set g-ave-C1-p3 ( f-compute-c1-pheno-average 3 ) set g-ave-C1-p4 ( f-compute-c1-pheno-average 4 ) set g-ave-C1-p5 ( f-compute-c1-pheno-average 5 ) set g-ave-C1-p6 ( f-compute-c1-pheno-average 6 ) set g-ave-C1-p7 ( f-compute-c1-pheno-average 7 ) ;; Make a list of existing tribal-affiliation numbers., let tribe-list ( sort remove-duplicates ( [tribal-affiliation] of seekers ) ) set gl-nrg-by-tribe [ 0 0 0 0 0 0 0 0 0 0 ] ;; Max of 10 tribes foreach tribe-list [ let total-nrg ( sum [nrg] of seekers with [tribal-affiliation = ?] ) set gl-nrg-by-tribe ( replace-item ? gl-nrg-by-tribe total-nrg ) ] ] ;; End else ;;-----------------------------------------------------------------------------| ;; To ensure that the PRNG is called whether or not plots are displayed, the ;; calculations needed for any histogram plots which invoke the PRNG ;; implicitly should be carried out here where they will happen every tick. ;;-----------------------------------------------------------------------------| ;; Setup for Plot "AAAAAA" ;; This log entry may come from any step during debug operations. LOG-TO-FILE " Do-update: All aggregates updated." ;; End of f-update-aggregates end ;;-----------------------------------------------------------------------------| ;; Compute an average for C1-bases, by preferred gene type. to-report f-compute-C1-bases-average [ gene-to-check ] ;; This routine is to be executed by the observer. let count-of-seekers ( count seekers ) let appropriate-sum ( sum ( [item gene-to-check c1-bases] of seekers ) ) let answer 0 if ( count-of-seekers > 0 ) [ set answer ( appropriate-sum / count-of-seekers ) ] ;; LOG-TO-FILE ( word " Do-update: g# - " gene-to-check ", ave [B] - " answer ) report answer ;; End of f-compute-C1-bases-average end ;;-----------------------------------------------------------------------------| ;; Compute an average for C1-genes, by preferred gene type. to-report f-compute-C1-genes-average [ gene-to-check ] ;; This routine is to be executed by the observer. let count-of-seekers ( count seekers ) let appropriate-sum ( sum ( [item gene-to-check c1-genes] of seekers ) ) let answer 0 if ( count-of-seekers > 0 ) [ set answer ( appropriate-sum / count-of-seekers ) ] ;; LOG-TO-FILE ( word " Do-update: g# - " gene-to-check ", ave [G] - " answer ) report answer ;; End of f-compute-C1-genes-average end ;;-----------------------------------------------------------------------------| ;; Compute an average for c1-learn, by preferred gene type. to-report f-compute-c1-learn-average [ gene-to-check ] ;; This routine is to be executed by the observer. let count-of-seekers ( count seekers ) let appropriate-sum ( sum ( [item gene-to-check c1-learn] of seekers ) ) let answer 0 if ( count-of-seekers > 0 ) [ set answer ( appropriate-sum / count-of-seekers ) ] ;; LOG-TO-FILE ( word " Do-update: g# - " gene-to-check ", ave [M] - " answer ) report answer ;; End of f-compute-c1-learn-average end ;;-----------------------------------------------------------------------------| ;; Compute an average for c1-stren, by preferred gene type. to-report f-compute-c1-stren-average [ gene-to-check ] ;; This routine is to be executed by the observer. let count-of-seekers ( count seekers ) let appropriate-sum ( sum ( [item gene-to-check c1-stren] of seekers ) ) let answer 0 if ( count-of-seekers > 0 ) [ set answer ( appropriate-sum / count-of-seekers ) ] ;; LOG-TO-FILE ( word " Do-update: g# - " gene-to-check ", ave [S] - " answer ) report answer ;; End of f-compute-c1-stren-average end ;;-----------------------------------------------------------------------------| ;; Compute an average for c1-pheno, by preferred gene type. to-report f-compute-c1-pheno-average [ gene-to-check ] ;; This routine is to be executed by the observer. let count-of-seekers ( count seekers ) let appropriate-sum ( sum ( [item gene-to-check c1-pheno] of seekers ) ) let answer 0 if ( count-of-seekers > 0 ) [ set answer ( appropriate-sum / count-of-seekers ) ] ;; LOG-TO-FILE ( word " Do-update: g# - " gene-to-check ", ave [P] - " answer ) report answer ;; End of f-compute-c1-pheno-average end ;;-------------------------- ;; DATA CAPTURE TO CSV FILES ;;-------------------------- ;;-----------------------------------------------------------------------------| ;; Record the data is several selected plots to CSV files to f-record-selected-plots ;; This routine is to be executed by the observer. ;; The template for the export command is: ;; export-plot plotname filename ;; Get a common timestamp for all plots. let timestamp fr-get-time-stamp ;; Plot 01 let plotname "Nrg - By Belief Affiliation" let plot-filename ( word timestamp "_Sc" g-scenario-number "_Se" g-use-this-seed "_Pl01_NBBA.CSV" ) export-plot plotname plot-filename ;; Plot 02 set plotname "Nrg - By Tribal Affiliation" set plot-filename ( word timestamp "_Sc" g-scenario-number "_Se" g-use-this-seed "_Pl02_NBTA.CSV" ) export-plot plotname plot-filename ;; Plot 03 set plotname "[B]ase Values By Gene #" set plot-filename ( word timestamp "_Sc" g-scenario-number "_Se" g-use-this-seed "_Pl03_BVBG.CSV" ) export-plot plotname plot-filename ;; Plot 04 set plotname "[G]ene Values By Gene #" set plot-filename ( word timestamp "_Sc" g-scenario-number "_Se" g-use-this-seed "_Pl04_GVBG.CSV" ) export-plot plotname plot-filename ;; Plot 05 set plotname "[L]earned Beliefs By Gene #" set plot-filename ( word timestamp "_Sc" g-scenario-number "_Se" g-use-this-seed "_Pl05_LVBG.CSV" ) export-plot plotname plot-filename ;; Plot 06 set plotname "[S]trengths By Gene #" set plot-filename ( word timestamp "_Sc" g-scenario-number "_Se" g-use-this-seed "_Pl06_SVBG.CSV" ) export-plot plotname plot-filename ;; Plot 06 set plotname "[P]henotype Values By Gene #" set plot-filename ( word timestamp "_Sc" g-scenario-number "_Se" g-use-this-seed "_Pl07_PVBG.CSV" ) export-plot plotname plot-filename ;; End f-record-selected-plots end ;;-----------------------------------------------------------------------------| ;; Construct a time stamp for a file name for data in CSV format. to-report fr-get-time-stamp ;; This routine is to be executed by the observer. ;; ;; Date-string format "01:19:36.685 PM 19-Sep-2002" let date-string date-and-time let time-stamp "" ;; Append the year as yy. set time-stamp word time-stamp ( substring date-string 25 27 ) ;; Append the month as Mmm. set time-stamp word time-stamp fr-convert-mmm-mm ( substring date-string 19 22 ) ;; Append the day as dd. set time-stamp word time-stamp ( substring date-string 16 18 ) ;; Append a dash. set time-stamp word time-stamp "_" ;; Append the hour as hh. set time-stamp word time-stamp fr-convert1224 ( substring date-string 0 2 ) ( substring date-string 13 15 ) ;; Append the minute as mm. set time-stamp word time-stamp ( substring date-string 3 5 ) ;; Append the second as ss. set time-stamp word time-stamp ( substring date-string 6 8 ) report time-stamp ;; End fr-get-time-stamp end ;;-----------------------------------------------------------------------------| ;; DEBUG AND DEBUG LOG FILE MANAGEMENT FUNCTIONS ;;-----------------------------------------------------------------------------| ;;-----------------------------------------------------------------------------| ;; Open a log file for debug output. to f-open-log-file ;; This routine is to be executed by the observer. ;; Ensure previous log file is closed. if ( is-string? gs-log-file-name ) [ if ( file-exists? gs-log-file-name ) [ file-close-all ] ] ;; Date-string format "01:19:36.685 PM 19-Sep-2002" let date-string date-and-time set gs-log-file-name "TpLab_Log_" ;; Append the year as yy. set gs-log-file-name word gs-log-file-name ( substring date-string 25 27 ) ;; Append the month as Mmm. set gs-log-file-name word gs-log-file-name fr-convert-mmm-mm ( substring date-string 19 22 ) ;; Append the day as dd. set gs-log-file-name word gs-log-file-name ( substring date-string 16 18 ) ;; Append a dash. set gs-log-file-name word gs-log-file-name "_" ;; Append the hour as hh. set gs-log-file-name word gs-log-file-name fr-convert1224 ( substring date-string 0 2 ) ( substring date-string 13 15 ) ;; Append the minute as mm. set gs-log-file-name word gs-log-file-name ( substring date-string 3 5 ) ;; Append the second as ss. set gs-log-file-name word gs-log-file-name ( substring date-string 6 8 ) ;; Append the .txt extension. set gs-log-file-name word gs-log-file-name ".txt" file-open gs-log-file-name file-show "Log File for a TpLab (NetLogo) Model." file-show word "File Name: " gs-log-file-name file-show word "File opened at:" date-and-time file-show "" ;; Send a message directly to the command centre. ifelse ( file-exists? gs-log-file-name ) [ show word gs-log-file-name " opened." ] [ show word gs-log-file-name " not opened." ] end ;;-----------------------------------------------------------------------------| ;; Convert month in text form to digital form. to-report fr-convert-mmm-mm [ mmm ] ;; This routine is to be executed by the observer. ;; It converts a string in the form mmm ( alpha text ) to the form mm ( digit-text ). let mm "00" if( mmm = "Jan" ) [ set mm "01" ] if( mmm = "Feb" ) [ set mm "02" ] if( mmm = "Mar" ) [ set mm "03" ] if( mmm = "Apr" ) [ set mm "04" ] if( mmm = "May" ) [ set mm "05" ] if( mmm = "Jun" ) [ set mm "06" ] if( mmm = "Jul" ) [ set mm "07" ] if( mmm = "Aug" ) [ set mm "08" ] if( mmm = "SeP" ) [ set mm "09" ] if( mmm = "Oct" ) [ set mm "10" ] if( mmm = "Nov" ) [ set mm "11" ] if( mmm = "Dec" ) [ set mm "12" ] report mm end ;;-----------------------------------------------------------------------------| ;; Convert hour in 12 format to 24 hour format. to-report fr-convert1224 [ hh ampm ] ;; This routine is to be executed by the observer. ;; It converts a string in 12 hour format to 24 hour format. let hour read-from-string hh if( ampm = "PM" ) [ set hour ( hour + 12 ) ] let dd ( word "00" hour ) let d2 last dd set dd but-last dd let d1 last dd set dd ( word d1 d2 ) report dd end ;;-----------------------------------------------------------------------------| ;; Close a log file for debug output. to f-close-log-file ;; This routine is to be executed by the observer. let b-filename-exists 0 if ( is-string? gs-log-file-name ) [ if ( file-exists? gs-log-file-name ) [ set b-filename-exists 1 ] ] ifelse( b-filename-exists = 1 ) [ ;; Ensure the file is selected. file-open gs-log-file-name ;; Stanp it. LOG-TO-FILE word "File closed at: " date-and-time ;; Flush the buffers. file-flush ;; Close it. file-close-all ;; Note sent to command centre. show word gs-log-file-name " closed." ;; Revert to dummy name. set gs-log-file-name "dummyname" ] [ if( gs-log-file-name = "dummyname" ) [ show "No log file is open. Cannot close it." ] ] end ;;-----------------------------------------------------------------------------| ;; Select an already opened log file. to f-select-log-file ;; This routine is to be executed by the observer. ifelse ( file-exists? gs-log-file-name ) [ ;; Ensure the file is selected. file-open gs-log-file-name ;; Ensure it is open for writing. LOG-TO-FILE "" LOG-TO-FILE "SELECTED" ] [ show word gs-log-file-name " is not open. Cannot select it." ] end ;;-----------------------------------------------------------------------------| ;; Change the debug mode from on to off, or vice versa. to f-toggle-debug ;; This routine is to be executed by the observer, and is activated by a ;; button. ifelse( gb-debug-on = 1 ) [ ;; Debug is On, turn it Off. ;; Close the file before turning debug logging off. f-close-log-file set gs-debug-status "0 (Off)" ;; This appears in the monitor. set gb-debug-on 0 ;; But this controls the debug feature. ] [ ;; Debug is Off, turn it On. set gs-debug-status "1 (On)" ;; This appears in the monitor. set gb-debug-on 1 ;; But this controls the debug feature. ;; The switches, if needed, are reset manually by the user. ;; Open the log file after turning debug logging on. f-open-log-file ] end ;;-----------------------------------------------------------------------------| ;; 'Show' a string in a debug log. to LOG-TO-FILE [ log-this-string ] ;; This routine may be executed by observer or seeker. ;; It should be invoked as a debug routine only, and would not be used for ;; normal output. It sends output to the debug log file, or, optionally, ;; also to the command centre. ;; gb-debug-on is a global Boolean and has value 1 (true) or 0 (false). if( gb-debug-on = 1 ) [ ;; gb-debug-flow-on is declared as a global Boolean variable, and its value ;; is 0 ( false ) or 1 ( true ) and is set on or off at the beginning of each ;; function ( each do-step ). It is controlled by the chooser that selects 'all' ;; or a specific do-function. ;; ;; When it is 'on' you can assume the debug log file exists and is open for ;; write. if( gb-debug-flow-on = 1 ) [ file-show log-this-string show log-this-string ] ] end ;;-----------------------------------------------------------------------------| ;; This replicates the effect of an 'ASSERTION' in C++ to ASSERT [ error-test error-string error-who ] ;; This routine can be run by observer or seeker. if( error-test = false ) [ show ( word error-test " " error-string " " error-who ) ;; Cause a run-time error and display a message. error ( word "Agent: " error-who " - " error-string ) ] end ;;-----------------------------------------------------------------------------| ;; Check whether the nrg accounts are all valid. to-report frb-nrg-accounts-are-all-valid ;; This routine can be run by the observer. let b-accounts-are-all-valid 1 if( gb-debug-on = 1 ) [ ;; Do the check only if debug is on. let temp-nrg-in-seekers ( sum [nrg] of seekers ) let temp-nrg-in-fruit ( sum [fruit] of patches ) let temp-nrg-in-sunshine g-nrg-in-sunshine let temp-total-nrg ( temp-nrg-in-seekers + temp-nrg-in-fruit + temp-nrg-in-sunshine ) if (temp-nrg-in-seekers != ( sum gl-nrg-by-belief ) ) [ set b-accounts-are-all-valid 0 LOG-TO-FILE ( word "S-nrg-check: SB:" temp-nrg-in-seekers ", IS:" ( sum gl-nrg-by-belief ) ) ] if (temp-nrg-in-fruit != g-nrg-in-fruit ) [ set b-accounts-are-all-valid 0 LOG-TO-FILE ( word "F-nrg-check: SB:" temp-nrg-in-fruit ", IS:" g-nrg-in-fruit ) ] if (temp-total-nrg != g-total-nrg-in-system ) [ set b-accounts-are-all-valid 0 LOG-TO-FILE ( word "T-nrg-check: SB:" temp-total-nrg ", IS:" g-total-nrg-in-system ) ] ] report b-accounts-are-all-valid ;; End of frb-nrg-accounts-are-all-valid end ;;-----------------------------------------------------------------------------| ;; Check whether the agents are all valid. to-report frb-agents-are-all-valid ;; This routine can be run by the observer. let b-agents-are-all-valid true if( gb-debug-on = 1 ) [ ;; Do the check only if debug is on. ;; Check the seekers. ask seekers [ if( frb-seeker-is-valid = false ) [ set b-agents-are-all-valid false ] ] ] report b-agents-are-all-valid ;; End of frb-agents-are-all-valid end ;;-----------------------------------------------------------------------------| ;; Check whether a seeker is valid. to-report frb-seeker-is-valid ;; This routine can be run by a seeker. let b-seeker-is-valid true report b-seeker-is-valid ;; End of frb-seeker-is-valid end
There is only one version of this model, created over 8 years ago by Garvin Boyle.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
04 TpLab V2.07.png | preview | Preview for '04 TpLab V2.07' | over 8 years ago, by Garvin Boyle | Download |
141129 NTF - NetLogo Stds for OrrerySW R2.pdf | Prepared standards for Orrery Software for NetLogo projects. | over 8 years ago, by Garvin Boyle | Download | |
160702 03 PPT MPP in Sustainable Society R8.pptx | A presentation at ISEE 2017 on the nature of the MPP and its role in economics. | over 8 years ago, by Garvin Boyle | Download | |
170219 NTF Reconciling Eco n Sci R5.pdf | A proposal on how to reconcile science and economics (draft). | over 8 years ago, by Garvin Boyle | Download | |
170322 NTF TpLab Change Log R2.07.pdf | The most recent change diary. | over 8 years ago, by Garvin Boyle | Download |
This model does not have any ancestors.
This model does not have any descendants.