\documentclass[]{book}
\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage[a4paper, total={6in, 6in}]{geometry}
\usepackage[labelfont=bf]{caption}
\usepackage{xcolor}
\usepackage{mdframed}
\usepackage{minitoc}
\usepackage[bottom]{footmisc}
\usepackage{listings}
\usepackage{hyperref}

\lstdefinestyle{CStyle}{
    backgroundcolor=\color{backgroundColour},   
    commentstyle=\color{mGreen},
    keywordstyle=\color{magenta},
    numberstyle=\tiny\color{mGray},
    stringstyle=\color{mPurple},
    basicstyle=\footnotesize,
    breakatwhitespace=false,         
    breaklines=true,                 
    captionpos=b,                    
    keepspaces=true,                 
    numbers=left,                    
    numbersep=5pt,                  
    showspaces=false,                
    showstringspaces=false,
    showtabs=false,                  
    tabsize=2,
    language=C,
    escapechar=\@
}
\definecolor{red}{rgb}{1, 0, 0}
\definecolor{green}{rgb}{0, 1, 0}
\definecolor{blue}{rgb}{0, 0,1}
\definecolor{yellow}{rgb}{1,1, 0}
\definecolor{brown}{rgb}{0.737,0.561,0.561}
\definecolor{grey}{rgb}{0.863,0.863,0.863}
\definecolor{violet}{rgb}{0.58,0,0.827}
\definecolor{cyan}{rgb}{0,1,1}
\definecolor{magenta}{rgb}{1, 0, 1}
\definecolor{orange}{rgb}{1, 0.647, 0}
\definecolor{indigo}{rgb}{0.447,0.129,0.737}
\definecolor{maroon}{rgb}{0.404,0.0275,0.282}
\definecolor{turquoise}{rgb}{0.251,0.878,0.816}
\definecolor{green4}{rgb}{0,0.545, 0}

\definecolor{mGreen}{rgb}{0,0.6,0}
\definecolor{mGray}{rgb}{0.5,0.5,0.5}
\definecolor{mPurple}{rgb}{0.58,0,0.82}
\definecolor{backgroundColour}{rgb}{0.95,0.95,0.92}


\newcommand{\cash}{\mbox{Cash2.1}}

%opening
\begin{document}
\begin{titlepage}
\centering
\hrule
\vspace{5mm}
\LARGE{\textbf{Cash2.1 User Manual}}\\

\Large{Cellular Automata in Simulated Hardware 2.1}\\\vspace{5mm}
\hrule
\vspace{5mm}
\Large{Bram van Dijk}\\
\Large{Nobuto Takeuchi}\\
\Large{Theoretical Biology, Utrecht University\footnote{The distribution of the program and the manual is
allowed but the distribution of modified copies is not
allowed. Suggestions and corrections are welcome. This software uses
CASH (RJ de Boer \& AD Staritsky) and Mersenne Twister (M Matsumoto \& T
Nishimura).}\\
\footnotesize{\today}
\vspace{5mm}
\begin{figure}[h]
	\centering
	\includegraphics[width=0.45\linewidth]{img/cheat.png}
	\label{fig:windowsfeatures}
	\\Cash2.1 Chaotic wave patterns in mutualists and cheaters\\
\end{figure}
\footnotesize{}
}


\end{titlepage}

\dominitoc% Initialization


\tableofcontents

%\minitoc% Creating an actual minitoc
\chapter{Introduction}

\cash{ }is an easy-to-use library to make a program simulating Cellular Automata (CA's), and it was created for the use in the course Bioinformatic Processes given by Paulien Hogeweg at Utrecht University. \bigskip

This document discusses how to setup/install \cash, followed by a basic introduction to the command-line, programming in C, and using \cash. If you need more help with figuring out how to work the command-line, check out  \textbf{\href{http://rik.smith-unna.com/command\_line\_bootcamp/?id=ht0jo2nqxdt}{the command-line bootcamp}}.\bigskip

 If you know what you are doing, and already have \cash{ }running, you can jump right in and make your own CAs by checking out all the advanced functions found in Chapter \ref{advanced}. 


\chapter{Installation}

In principle, \cash{ } is a program made for Linux. Installing
on a Linux system is easiest, but it is also possible to install them on Windows or Mac OS. The general installation process is the same for all systems:
\begin{itemize}
\item Installing dependencies (libraries used by {\cash}) 
\item Installing software for display and graphing
\item Installing and testing {\cash}
\end{itemize}
\newpage

\section{Installing on Linux (own laptop / desktop)}


Installing the required dependencies for \cash{ } can be done manually (see blue box below, only for cool kids) or by using the script provided on our course website: 
\begin{itemize}
	\item \texttt{wget http://theory.bio.uu.nl/BINF/software/Cash2.1/cash\_dependencies.sh}
	\item \texttt{sudo ./cash\_dependencies.sh}
	\item (enter your password)
\end{itemize}
\begin{figure}[h]
	\begin{footnotesize}
		\begin{mdframed}[backgroundcolor=blue!5]
			For geeks that want to do it themselves, here's what the script does:\\
			\begin{itemize}
				\item \texttt{apt-get update}
				\item \texttt{apt-get install unzip	}
				\item \texttt{apt-get install build-essential}
				\item \texttt{apt-get install grace}
				\item \texttt{apt-get install x11-apps (just for testing)}
				\item \texttt{apt-get install libpng-dev}
				\item \texttt{apt-get install zlib1g-dev}
				\item \texttt{apt-get install libx11-dev}
				\item \texttt{echo \nobreak "export DISPLAY=:0.0" $>>$ $\sim$/.bashrc}
				\item \texttt{source $\sim$/.bashrc}
			\end{itemize}
		\end{mdframed}
		\label{depend}
	\end{footnotesize}
\end{figure}

Next, continue to Chapter \ref{using} to start installing and using \cash.

\newpage
\section{Installing on Windows}

Since Windows 10, the Microsoft app store has 'Ubuntu for Windows' freely available, which is a small, yet fully functional, Linux Ubuntu distribution run on windows. By installing this, and installing a program to manage your display (displaying graphs and the CA grid), we can use \cash{ } without any limitations. 


{
\begin{wrapfigure}{r}{0.45\textwidth}
	\centering
	\vspace{-10mm}

	\includegraphics[width=0.7\linewidth]{img/windows_features.png}
	\caption{Enable Windows Subsystem for Linux}
		\label{windowsfeatures}
\end{wrapfigure}
\section*{Step 1/5: Preparing Windows 10 developer mode}
\begin{itemize}
	\item Go to Control Panel $\rightarrow$ Updates and Security $\rightarrow$ For developers, and enable the 'Developer mode'
	\item Go to Control Panel $\rightarrow$ Program's and Features $\rightarrow$ Turn Window features on or off. Enable 'Windows Subsystem for Linux' (see Figure \ref{windowsfeatures})
	\item (Restart Windows)
\end{itemize}
}
\vspace{5mm}
\section*{Step 2/5: Installing Ubuntu for Windows 10}
\begin{itemize}
	\item Install Ubuntu for Windows 10, available in the Microsoft app store.
	\item Start Ubuntu for Windows. Continue through the installation. (setting up a username and password, etc.). 
	\item By default, your Windows documents can be accessed via \textit{\texttt{/mnt/c/Users/<username>}.\\ (note: it is adviced to download and install \cash{ } here, since you can then easily edit the code via your preferred Windows text editor, without getting permission problems)}
\end{itemize}


\newpage
\section*{Step 3/5: Installing an X server for Windows}

In order to run graphical applications such as \cash{ } via your newly installed Ubuntu, you need
an X server. There's a small one called VcXsrv available here \texttt{sourceforge.net/projects/vcxsrv/}\bigskip

NOTE! This program needs to run while using Ubuntu to get a display. It's in your Start Menu, and called XLaunch. If you're lazy like me, you can add it to your windows start-up applications:
\begin{itemize}
	\item Right click on XLaunch in the start-up menu
\item Select More  $\rightarrow$  Open file location
\item Copy the VcXsrv shortcut file
\item Paste the shortcut in \%appdata\%/Microsoft/Windows/Start Menu/Programs/Startup
\item (An X icon should appear in your system tray whenever you start Windows)
\end{itemize}
\section*{Step 4/5: Installing required tools on Ubuntu for Windows}

For \cash{ } to work, some other packages need to be installed (see blue box below). For easily doing this, run the script on our website. Type the following commands into your Ubuntu terminal:\\
{

\begin{itemize}
	\item \texttt{wget http://theory.bio.uu.nl/BINF/software/Cash2.1/cash\_dependencies.sh}
	\item \texttt{sudo ./cash\_dependencies.sh}
	\item (enter your password)
	\item Test your display by typing \texttt{xeyes}. Do you a window with eyes?
\end{itemize}
}
\begin{figure}[h]
	\begin{footnotesize}
		\begin{mdframed}[backgroundcolor=blue!5]
			For geeks that want to do it themselves, here's what the script does:\\
			\begin{itemize}
				\item \texttt{apt-get update}
				\item \texttt{apt-get install unzip	}
				\item \texttt{apt-get install build-essential}
				\item \texttt{apt-get install grace}
				\item \texttt{apt-get install x11-apps (just for testing)}
				\item \texttt{apt-get install libpng-dev}
				\item \texttt{apt-get install zlib1g-dev}
				\item \texttt{apt-get install libx11-dev}
				\item \texttt{echo \nobreak "export DISPLAY=localhost:0.0" $>>$ $\sim$/.bashrc}
				\item \texttt{"source $\sim$/.bashrc}
			\end{itemize}
		\end{mdframed}
		\label{depend}
	\end{footnotesize}
\end{figure}

\section*{Step 5/5: Installing and testing \cash}
This is explained in Chapter \ref{using}.

\clearpage


\section{Installing on Mac OSX}

Since Mac OS is a also a UNIX system, using \cash{ } is possible, but it requires some different steps. We need to install a program to manage your display (displaying graphs and the CA grid), like Xquartz. If you are lazy, see if our setup script gets you through it (we've tested the script, but only on a few systems). If it didnt work, follow the instructions in the blue box below. \\

\begin{figure}[h]
	\begin{footnotesize}
		\begin{mdframed}[backgroundcolor=blue!5]
			Here's what the script is supposed to do on your Mac OS system. It installes xcode and homebrew, and then uses homebrew to install xquartz, libpng and grace:\\
			\begin{itemize}
				\item \texttt{xcode-select --install}
				\item \texttt{ruby -e "\$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"}
				\item \texttt{brew cask install xquartz}
				\item \texttt{brew install libpng}
				\item \texttt{brew install grace}
			\end{itemize}
		\end{mdframed}
		\caption{Dependendies required for \cash}
		\label{depend}
	\end{footnotesize}
\end{figure}

Next, continue to Chapter \ref{using} to start using \cash.
\newpage
\section{Installing on UU campus (COMPbio students)}

Boot the computer in ``Betalinux'' (reboot if it is already in Windows). Open a terminal window (type `term' in the start menu and it should pop up) and type:
\begin{itemize}
	\item \texttt{/clz/bio-binf/setup-binf}
	\item \texttt{source $\sim$/.bashrc}
\end{itemize}

Done. Next, continue to Chapter \ref{using} to start installing and using \cash.
\newpage

\chapter{Downloading and testing \cash}
\label{using}
From here on out, we will start using the command line. I will briefly explain some of the basics for beginners here. If you know how the command line works, you can skip to section \ref{usecash}. 

\section{Using the command line}
Using \cash, you will mostly work in a terminal. You can find the terminal by searching for `terminal' in the start menu of either Linux, Mac OS, or Windows. In the terminal, you can type commands. In this section, some of the most useful commands will be explained.\vspace{3mm}\\
Assume our directories are structured in the following way:\\


Imagine that we start in \verb+root/een/two+. \\
\begin{wrapfigure}{r}{0.4\textwidth}
	\centering
	\vspace{-10mm}
	\includegraphics[width=0.9\linewidth,height=1.1\linewidth]{img/directories.jpg}
	\label{fig:windowsfeatures}
\end{wrapfigure}
\textbf{cd ..}: \\
This command will take us up one step in the directory structure. So, we will end up in \verb+root/een+. \\

\textbf{ls}: \\
This command will show us the content of the directory we are currently in, \verb+root/een+. It will show us at least the three directories: \verb+one+, \verb+two+ and \verb+three+. \\

\textbf{cd three}: \\
This command takes us to the subdirectory \verb+three+. Of course this only works when a directory with the name you type actually exists.\\
We type \textbf{cd ..} again to get back into \verb+root/een+. \\

\textbf{mkdir four}:\\
By using this command, we create a new subdirectory in the directory we are currently in, with the given name. So, we have added a directory \verb+root/een/four+ to our directory structure. \\

\textbf{cp filename four}: \\
This command will copy a certain file (with the name filename) from the place in the directory structure we are now to \verb+root/een/four+. If you want to copy a file from or to a different place, you should specify the path in your command. For instance, if you want to copy a file named file1 from \verb+root/een/two+ to \verb+root/twee/drei+, you should type \textbf{cp two/file1 root/twee/drei}.\\

\textbf{mv A B}:\\
This command enables you to move or rename a file. If A and B are two different file names, the name of A will be changed to B. If A and B are two diffferent path names followed by the same file name, the file will be moved from A to B. If A and B are two different path names followed by different file names, the file will be moved from A to B \textbf{and} it will be renamed. For example, if you type \textbf{mv two/file1 root/drie/file2}, the file named file1 in directory \verb+root/een/two+ will be moved to \verb+root/drie+ and it will be renamed to file2.\\

\textbf{Running, suspending, and cancelling programs}:\\
You can run a program by typing \texttt{./} followed the name of the program. For example, the `game of life' program that comes with \cash{ }available on the course website, can be ran by typing \texttt{./life} in the terminal. (IF you compiled life by typine 'make life'  first!)\bigskip

When starting a program, you will you might notice that you cannot type commands into the terminal anymore (actually you CAN, but they dont do anything). Your \texttt{prompt} is not active any more. You can return to your prompt by pressing \textbf{Ctrl Z}. Although you can now type in commands again, the program is suspended. If you now type \textbf{bg}, the program will start running again `in the background'. This means you can have your cake and eat it too. \bigskip

If you type \textbf{\&} behind a command that starts a program, the program starts in the backgroud. This means that you keep your prompt and can still type commands in your terminal.\\
If you want to (force) quit a certain program, type \textbf{Ctrl C}. This will completely shut down the program you are running. Since most people are used to \textbf{Ctrl C} (and \textbf{Ctrl V}) being the copy-paste commands, these commands are now availble by combining them with SHIFT (Ctrl+Shift+C / Ctrl+Shift+C). On Ubuntu for Windows, you can right-click to paste. \bigskip

\section{Downloading, installing, and first use of \cash}
\label{usecash}
Now that you know a bit about the command-line, lets download and install \cash. Here's the command lines:
\begin{itemize}
	\item \texttt{wget http://theory.bio.uu.nl/BINF/software/Cash2.1/\cash.zip}
	\item \texttt{unzip \cash.zip}
\end{itemize}

Now you should have a directory name \cash. Now it is time to start using the command line. If you already know how this works, you can skip to \S \ref{usecash}.

To install \cash{ }, simply cd into the directory, and type 'make', followed by 'make install':

\begin{itemize}
	\item \texttt{cd \cash}
	\item \texttt{make}
	\item \texttt{make install}
\end{itemize}
If you got through this without serious errors, \cash should now work. But what is this `make' command doing? In the next Chapter, we will briefly introduce programming and compiling code, so you can begin using {\cash}.



\chapter{Programming in C and {\cash}}

\section{What is programming?}
To use {\cash}, we will do some programing. Let me explain what it is
like to make a program. First, one writes down sets of orders that will
be executed by computers in a text file. Such a file is called a
\textbf{source code}. Computers cannot understand the source code as it
is. Thus, one then runs some program to translate the source code into a
\textbf{executable} file. This executable file is what refer to as the \textbf{program}. This translation process is called \textbf{compilation}, and the program to compile source codes is called the \textbf{compiler}. Many modern programming languages like Python and R do not require compilation, but since that this generally means they are also \textit{slower}, we tend to favour programming in C.\bigskip

Let us take an example. Go to the directory called \texttt{examples} by
typing \textbf{cd examples} in the {\cash} directory. Type \textbf{ls} to see the files and the
directories located in this directory. There is a file called \texttt{life.c} and this is our example source code. This will show us the ``Game of Life'', which is explained in the lectures by P. Hogeweg. The file name has an extension ``\texttt{.c}'' which tells us that the file is C
source code. We are going to compile it. Type \textbf{make life} --- this
means to compile the source code called \texttt{life.c} and create a
program called \texttt{life}. Note that one should not type
``\texttt{make life.c}'' but ``\texttt{make life}''. If the compilation
is successful, one obtains a file called \texttt{life}, which is printed
in green color if you type \textbf{ls} (if a program is executable, it
will be in green color on most systems). Now that we have an program to
simulate CA, type \textbf{./life} to see the output of the program. What
do you observe?

Glider gun, it is called. In the next section, we will see how to make
this kind of program by ourselves.
\section{First look at an example source code\label{sec:first-look}}

The following is the source code \texttt{life.c}.  Let's just look
through it:
\begin{lstlisting}[style=CStyle,caption={\texttt life.c}]{}
#include <stdio.h>@\label{life:header}@
#include <string.h>
#include <time.h>
#include <errno.h>
#include <math.h>
#include <grace_np.h>
#include <unistd.h>
#include <float.h>
#include <limits.h>
#include <signal.h>
#include <cash2003.h>
#include <cash2.h>
#include <mersenne.h>
#include <cash2-s.h>

static TYPE2** Life;@\label{life:definition}@

void Initial(void)@\label{life:initial}@
{
  MaxTime = 2147483647; /* default=2147483647 */@\label{life:maxtime}@
  nrow = 200; /* # of row (default=100)*/
  ncol = 200; /* # of column (default=100)*/
  nplane = 1; /* # of planes (default=0)*/
  scale = 2; /* size of the window (default=2)*/
  boundary = WRAP; /* the type of boundary: FIXED, WRAP, ECHO (default=WRAP).
                      Note that Margolus diffusion is not supported for ECHO. */
  ulseedG = 56; /* random seed (default=56)*/

  /* useally, one does not have to change the followings */
  /* the value of boundary (default=(TYPE2){0,0,0,0,0,0.,0.,0.,0.,0.})*/
  boundaryvalue2 = (TYPE2){0,0,0,0,0,0.,0.,0.,0.,0.}; 
}@\label{life:initial-end}@

void InitialPlane(void)@\label{life:initialplane}@
{@\label{life:initialplane0}@
  MakePlane(&Life);@\label{life:initialplane2}@

  /* Usage: InitialSet(1,2,3,4,5);@\label{life:initialplane5-1}@
     1: name of plane
     2: number of the state other than the background state
     3: background state or empty state
     4: state I want to put
     5: fraction of cells that get S1 state (0 to 1) */@\label{life:initialplane5-2}@
  InitialSet(Life,1,0,1,0.3);@\label{life:initialplane6}@

  Boundaries2(Life);@\label{life:initialplane7}@
}@\label{life:initialplane-end}@

void NextState(int row,int col)@\label{life:nextstate}@
{@\label{life:nextstate0}@
  int sum;@\label{life:nextstate1}@

  sum = CountMoore8(Life,1,row,col);@\label{life:nextstate2}@
  
  if(sum==3 || (sum==2 && Life[row][col].val==1)){@\label{life:nextstate3}@
    Life[row][col].val = 1;@\label{life:nextstate6}@
  }
  else{
    Life[row][col].val = 0;@\label{life:nextstate5}@
  }@\label{life:nextstate4}@
}@\label{life:nextstate-end}@

void Update(void)@\label{life:update}@
{
  Display(Life);
  Synchronous(1,Life);
}@\label{life:update-end}@
\end{lstlisting}

Perhaps cryptic in the beginning? I will first explain its outline. The
program simulates the Game of Life. Let us first look at line~\ref{life:nextstate}--\ref{life:nextstate-end}. The \textbf{next-state function} of the
Game of Life is written here. This part is the core of the program, and
a special attention is called for here. Without knowing the details, one
might well understand meaning of
Line~\ref{life:nextstate}--\ref{life:nextstate-end}: it is the rule of
the Game of Life\footnote{For those who forgot the rule of the Game of
Life, let me repeat it: (1) Count the number of the cells with state 1
in the Moore neighborhood---i.e.\ 8 neighbors in east, west, north,
south, north east, north west, south east and south west---of the focal
cell; (2) if the number of neighboring cells with state 1 is three, the
state of the focal cell becomes state 1; if the number of neighboring
cells with state 1 is two and the focal cell's state is 1, the focal
cell's state remains 1; otherwise the focal cell's state becomes 0.}.\bigskip

Let us look at other lines too. Line~\ref{life:update}--\ref{life:update-end} is the thing that runs repeatedly for this program. It is quite verbal: \texttt{Display()} the grid, and then apply a \texttt{Synchronous()} update (this applies the next state function for the entire grid). Rince and repeat. But before all this works, there is a bit of setup. Let's explain that a bit more next.\bigskip

Line~\ref{life:initialplane}--\ref{life:initialplane-end} initializes the CA plane. Line~\ref{life:initial}--\ref{life:initial-end} is a kind of mess. Actually, it sets parameters of CA such as the maximum number of updating (\texttt{MaxTime}), the number of rows and columns (\texttt{nrow}, \texttt{ncol)} and so forth. In summary, the outline is that we (1) initialize the parameters of CA \texttt{Initial()} (Line~\ref{life:initial}) , (2) make a plane and initialize it by \texttt{InitialPlane()} (Line~\ref{life:initialplane}), (3) specify the
rules of CA by NextState() (Line~\ref{life:nextstate}), (4) update the
CA plane by \texttt{Update()} (Line~\ref{life:update}). Next we will see
the meaning of lines in more details.


\section{Details of the source code}
\subsection{Header}
Lines~\ref{life-header:header-start}-\ref{life-header:header-end} (see
below) means that one includes the library called \texttt{cash2-s} and
also the others. In most of the cases during the course, one need not
modify this part of the code, so that one can simply copy and paste it.
This part of the code is called ``header'', and files with \texttt{.h}
are called ``header files''.\bigskip
\begin{lstlisting}[style=CStyle,caption={Header\label{lst:header}}]{}
#include <stdio.h>@\label{life-header:header-start}@
#include <string.h>
#include <time.h>
#include <errno.h>
#include <math.h>
#include <grace_np.h>
#include <unistd.h>
#include <float.h>
#include <limits.h>
#include <signal.h>
#include <cash2003.h>
#include <cash2.h>
#include <mersenne.h>
#include <cash2-s.h>@\label{life-header:header-end}@

static TYPE2** Life;@\label{life-header:definition}@
\end{lstlisting}

Line~\ref{life-header:definition} is a \textbf{variable definition}. A
variable is a storage which can contain a value such as a character
(\texttt{'a'}, \texttt{'b'}), an integer (\texttt{1}) or a floating
number (\texttt{3.1417}). When one uses variables, one has to define
them before using. In this case, we define a variable which will later
contain a plane of CA. I will explain more about the variable definition
by dividing it in parts.

We start from the last word of the variable definition. \texttt{Life} is
the name of the variable. The naming is arbitrary. In naming variables,
we can use alphabets and underscores ``\_''; numbers are also allowed to
use if it does not come to the beginning of the name (e.g.\
\texttt{Plane1}, \texttt{Plane2} are OK, but not \texttt{1Plane}).

Next look at the first two words, \texttt{static TYPE2**}. At this
moment, we ignore the meaning of \texttt{static} but learn by heart to
put it in the beginning. The second one, \texttt{TYPE2 **}, tells the
data {\bf type} of the variable.  Variables have several different
types: integer (\texttt{int}), real number (\texttt{double}), character
(\texttt{char}) and so on. When one defines a variable, one has to
specify its type. Note that once one defines a variable as, say,
\texttt{int} type, one cannot store a real number, such as $1.3$, in
this variable (for example, \texttt{int x; x = 1.3;} stores 1 in
\texttt{x} instead of 1.3). \texttt{TYPE2**} is simply one of those
types. Last but not least, there is a semi-colon, ``\texttt{;}'', at the
end of line. A semi-colon says ``this is the end of an order''. Despite
its littleness, it is a very important to put it.

\subsection{\texttt{Initial()} function}
Let us proceed to Line~\ref{life:initial}--\ref{life:initial-end} (see
below too).  This part has a syntax such that \verb|Initial()|
\verb|{something;}|. This synthax is common to all the other parts of
the program such as \verb|NextState()| \verb|{something;}| and
\verb|Update()| \verb|{something;}|. They are called
\textbf{functions}. A function is a building block of a program.

Taking a closer look, Line~\ref{life:initial} is the begining of the
\textbf{function definition} of the function of which name is
\texttt{Initial()}.
\begin{lstlisting}[style=CStyle,caption={Function definition}]{}
void Initial(void)
\end{lstlisting}
\texttt{void} in the beginning of the line means that the function
returns nothing, i.e.\ it performs some computation, but gives back no
value (cf.\ \texttt{sin(3.14/2.)} which computes $\sin(3.14/2.)$ and
returns $\approx 1$.)

\begin{lstlisting}[style=CStyle,caption={\texttt{Initial()} function}]{}
void Initial(void)
{
  MaxTime = 2147483647; /* default=2147483647 */
  nrow = 200; /* # of row (default=100)*/
  ncol = 200; /* # of column (default=100)*/
  nplane = 1; /* # of planes (default=0)*/
  scale = 2; /* size of the window (default=2)*/
  boundary = WRAP; /* the type of boundary: FIXED, WRAP, ECHO (default=WRAP).
                      Note that Margolus diffusion is not supported for ECHO. */
  ulseedG = 56; /* random seed (default=56)*/

  /* useally, one does not have to change the followings */
  /* the value of boundary (default=(TYPE2){0,0,0,0,0,0.,0.,0.,0.,0.})*/
  boundaryvalue2 = (TYPE2){0,0,0,0,0,0.,0.,0.,0.,0.}; 
}
\end{lstlisting}

Inside of the function \texttt{Initial()}, we sets parameters of
CA. Line~\ref{life:maxtime} sets the maximum number of updating to
2147483647. The simbol ``\texttt{=}'' {\bf assigns} a value on the right
hand side into the variable on the left hand side. Is it allowed to use
variables without defining it? No, but the variable \texttt{MaxTime} has
been already defined in the library. The same is true for the other
parameters. The meaning of the variables is almost clear from the
name. \bigskip

\texttt{nplane} is the number of CA planes. When using multiple CA
planes, one first has to define variables for all planes after the
inclusion of the header files before the \texttt{Initial()} function.
Then, one has to put the correct number of planes in
\texttt{nplane}. \bigskip

\texttt{boundary} is the type of the boundary: \texttt{WRAP} is torus
boundary, \texttt{FIXED} is fixed boundary, \texttt{ECHO} is echoing
boundary; all of those are explained during the lectures. When one wants
to assign some value in the boundaries in \texttt{FIXED} boundary mode,
one sets \texttt{boundaryvalue2} to a state of boundaries. For example,
if one wants to set the value of the boundaries to 2, one writes
\texttt{boundaryvalue2} \texttt{=}
\texttt{\{2,0,0,0,0,0.,0.,0.,0.,0.\}}.  \bigskip

\texttt{ulseedG} is the \textbf{random seed}. When drawing random number from the computer, they are not really random, but just a stack of psuedo-random numbers. When when uses such a ``random'' number, the top one is drawn from the stack. In other words, if you really want 2 simulations to have different results based on random events, one should change this random seed. 

\subsection{\texttt{InitialPlane()} function}
\texttt{InitialPlane()} function
(Line\,\ref{life:initialplane}-\ref{life:initialplane-end}) (1) creates
CA planes, (2) initializes them, and (3) sets the boundaries of CA
(which boundary types and what boundary values have been given in
\texttt{Initial()}).

\begin{lstlisting}[style=CStyle,caption={\texttt{InitialPlane()} function}]{}
void InitialPlane(void)
{
  MakePlane(&Life);

  /* Usage: InitialSet(1,2,3,4,5);
     1: name of plane
     2: number of the state other than the background state
     3: background state or empty state
     4: state I want to put
     5: fraction of cells that get S1 state (0 to 1) */
  InitialSet(Life,1,0,1,0.3);

  Boundaries2(Life);
}
\end{lstlisting}

%Line~\ref{life:initialplane1} defines the variables called
%\texttt{s0} and \texttt{s1}. The type of the variables is
%\texttt{TYPE2}, which is the type used for a variable that will
%contain one cell of CA---\texttt{TYPE2**} is for a plane of
%cells; it's two dimensional and so tow ``*''s. One of the
%differences between the variable definition here and that before
%is the existance of \texttt{static}; we do not need to put
%\texttt{static} because we are the inside of a function---by
%inside, I mean the inside of the curry braces (\verb|{}|) just
%after the name of the function
%(Line~\label{life:initialplane0}--\label{life:initialplane-end}).
%One meaning of roles of the curry braces is to specify the
%begining and the ending of a function. Another difference of the
%variable definition from before is that we \textit{cannot} use
%these variables outside of the \texttt{InitialPlane()} function
%because they are defined in the \texttt{InitialPlane()}
%function. These variables are called \textbf{local variables} and
%the variables like \texttt{Life} and \texttt{MaxTime} are called
%\textbf{groval variables} which we can use any where in
%\texttt{life.c}. One might ask ``What do we define these local
%variables for?'': the reasons comes later. Then, one might
%further ask ``Then, why do we have to talk about their definition
%now!'': the anser is that we have to define all the variables in
%the beginign of the function even if we want to use them later;
%this is a rule. 

Look at Line~\ref{life:initialplane2}. Here one calls the function
called \texttt{MakePlane()}, which makes planes as the name suggests. If
one wants to represent a CA plane in the variable \texttt{Life}, one
gives the variable \texttt{Life} as an argument to the
\texttt{MakePlane()} function. The meaning of an ampersand (\verb|&|) in
the front of the variable will not be explained; it is just a rule. If
one uses multiple CA planes, say \texttt{Plane1} and \texttt{Plane2},
then one writes \texttt{MakePlane(Plane1,Plane2))}.

Line~\ref{life:initialplane6} is the most difficult syntax among all
parts of the source code \verb|life.c|. In this part of the code, we
initialize CA plane. In this particular example, this line sets the
state of 30\% of all the cells in CA to 1, and the rest of the cells
have state 0. The arguments of {InitialSet()} specify the above: The
first argument takes a variable which contains a plane we want to
initialize (\texttt{Life} in our case); the second argument is the
number of cell states we wants to put apart from the background cell
states (we want to put state 1 apart from background cell state 0; thus
the number here should be 1); the third argument is the state of
background (in our case, 0); the forth argument is the state we want to
put in the cells (in our case 1); the fifth argument is the fraction of
the cells which get the cell state of the forth argument (in our case
0.3). For instance, if one wants to set the state of 5\% of the cells to
2, the state of 10\% of the cells to 1 and the rest to 0, then
\texttt{InitialSet(Life,2,0,2,0.05,1,0.1)}.

The last line of the function, Line~\ref{life:initialplane7}, set the
boundaries of the CA plane by calling \texttt{Boundaries2()}. The value
of boundaries are specified in \texttt{Initial()}.
\subsection{\texttt{NextState()} function}
Let us turn to the \texttt{NextState()} function (see below). This
function defines a rule of CA. \texttt{NextState()} function takes two
arguments, \texttt{row} and \texttt{col}. They are the coordinates of a
cell to update. They are used to get an information about the
neighborhood of the cell at position (row,col).

\begin{lstlisting}[style=CStyle,caption={\texttt{NextState()} function}]{}
void NextState(int row,int col)
{
  int sum;

  sum = CountMoore8(Life,1,row,col);
  
  if(sum==3 || (sum==2 && Life[row][col].val==1)){
    Life[row][col].val = 1;
  }
  else{
    Life[row][col].val = 0;
  }
}
\end{lstlisting}

Line~\ref{life:nextstate1} defines a \texttt{int} type variable
\texttt{sum}. The name suggests that it gets the sum of something.  In
Line~\ref{life:nextstate2}, \texttt{CountMoore8()} counts the cells with
state 1 in the Moore neighborhood of the cel at position (row,col). The
number 8 in the name of the function means that the number of the
neighbors is 8 and the counting does not consider the current cell
itself. There are lots of variants of \texttt{CountMoore8()} available
(see \S\,\ref{sec:reference-manual}). The arguments to
\texttt{CountMoore8()} function are as follows: The first argument is
the variable of the plane on which one wants to count (\texttt{Life} in
our case); the second argument is the state we want to count (\texttt{1}
in our case); the third and the forth arguments are the coordinate of
the cell where counting is performed. \texttt{CountMoore8()} function
will return the number of cells with state 1, and the sign \texttt{=}
stores this value in the variable \texttt{sum}.

The last part of the function
(Line~\ref{life:nextstate3}--\ref{life:nextstate4}) contains the CA rule
table. The lines which contain \texttt{if} and \texttt{else} are called
\textbf{if-else statements} (see \S\,\ref{sec:if-else}). In
\texttt{Life[row][col].val} at Line~\ref{life:nextstate3}, the square
brackets ``\texttt{[][]}'' specifies which cell one refers to. The first
clause specifies the row, and the second clause specifies the
column. Thus, \texttt{Life[row][col]} enables one to access the cell at
\texttt{[row][col]} (i.e.\ either to know or to modify its state). the
postfix \texttt{.val} enables one to access the \texttt{val}ue of the
cell called \texttt{val}. Line~\ref{life:nextstate6} assignes 1 to the
variable \verb|Life[row][col].val|---it sets the state of the cell at
\verb|[row][col]| to \verb|1|---if the condition in
Line~\ref{life:nextstate3} is true. The same is true for
Line~\ref{life:nextstate5}.


Actually, there are more than one \texttt{val} in
\texttt{Life[row][col]}. For instance, there is
\texttt{Life[row][col].fval}, which takes a \texttt{double} type value
(a floating number such as 3.14). For example, if one writes
\texttt{Life[row][col].val} \texttt{= 3.14}, \texttt{Life[row][col].val}
actually gets 3, instead of 3.14, because it is \texttt{int}. But, if
one writes \texttt{Life[row][col].fval} \texttt{= 3.14}, then
\texttt{Life[row][col].fval} indeed gets 3.14. There are also
\texttt{val2}, \texttt{val3}, \texttt{val4} and \texttt{val5} for
\texttt{int} type, and \texttt{fval2}, \texttt{fval3}, \texttt{fval4}
and \texttt{fval5} for \texttt{double} type (see \S\,\ref{section:TYPE2}
for details).

\subsection{\texttt{Update()} function}
We are almost at the end. The last function, \texttt{Update()}, (see
below) is a quite easy one. \texttt{Update()} will be called once every
time step. In our case \texttt{Update()} will call \texttt{Display()} to
diplay, and \texttt{Shynchronous()} to update the plane
syhnchronously. The usages of these two function are as
follows. \texttt{Display()} function takes the CA plane as its argument,
thus \texttt{Life} in our case. To call \texttt{Shynchronous()}
function, the first argument is the number of the planes we are
updating, thus 1 in our case, the second argument is the CA plane, thus
\texttt{Life}. If there are two planes, say \texttt{Plane1} and
\texttt{Plane2}, then one writes \texttt{Display(Plane1,Plane2)} and
\texttt{Shynchronous(2,Plane1,Plane2)}.

\begin{lstlisting}[style=CStyle,caption={\texttt{Update()} function}]{}
void Update(void)@@
{
  Display(Life);
  Synchronous(1,Life);
}@@
\end{lstlisting}


\chapter{Advanced useage functions}
\label{advanced}
\section{Reference Manual\label{sec:reference-manual}}
In this section, a summary of almost all the features of {\cash} is
presented. It is recommended to read through it so that one can know
what one can do and supposed to do. In the following, words followed by brackets are functions. The words within the brackets are arguments (parameters and objects used by 
the function). The word in front of the function name is the `return
type' of the function. If this value is \texttt{void}, that means the function returns nothing, but just modifies the objects passed to it (\textit{e.g.} the CA grid), or set global variables like 'MaxTime'. Another common return is \texttt{int} which means that by  calling the function, you get an integer value back. This can then be used to set a variable. Here's some examples: \textit{e.g.}:
\vspace{15mm}
\begin{lstlisting}[style=CStyle,caption={\texttt{Update()} function}]{}
// NOTE This code and the functions are examplary, and not part of CASH2.1
int GlobalVariable = 0;

void SetGlobalVariable(int val)	// A function that modifies something, but returns nothing
{
  GlobalVariable = val;
}

int Square(int val)	// A function that modifies nothing, but returns something
{
  return val*val;
}

SetGlobalVariable(1000);									// Set GlobalVariable
a = 10;																		// a set to 10
asquared = Square(a);											// squared set to 100
printf("%d\n", Square(GlobalVariable)); 	// Prints to the terminal 1.000.000

\end{lstlisting}

\subsection{Functions that must be defined by the user}

What follows here are all the function that have to be defined in the main program. Most of the time, you can simply grab one of the examples, and start modifying the NextState function, the Update function, and the Initial function to get something cool. 
\begin{description}
\item{\texttt{void Initial(void)}}\\ The function is supposed to
set parameters of the CA. The following parameters are available.
 \begin{description}
  \item{\texttt{(int) nplane}}\\ The number of planes. Default is 0.
  \item{\texttt{(int) nrow}}\\ The number of rows of CA
	     planes. Default is 100.
  \item{\texttt{(int) ncol}}\\ The number of columns of CA
	     planes. Default is 100.
  \item{\texttt{(int) scale}}\\ The window size. Default is 2.
  \item{\texttt{(int) margin}}\\ The graphics of the CA planes will be
  shown in a window. \verb|margin| specifies the margin between the edge
  of the window and the drawings of CA planes. If several planes are to
  be displayed, \verb|margin| also specifies the margin between
  planes. Default is 0.
  \item{\texttt{(TYPE2) boundaryvalue2}}\\ The value of the cells at
  boundaries. Boundaries are either at \verb|[0][x]| or at
  \verb|[nrow+1][x]| or at \verb|[x][0]| or at \verb|[x][ncol+1]|. This
  parameter must be set appropriately only in fixed boundary case. In
  the other types of boundary, this parameter is ignored. Default is
  \texttt{\{0,0,0,0,0,0.0,0.0,0.0,0.0,0.0\}}.

  \item{\texttt{(int) boundary}}\\ The type of the boundary. It can
  take either \verb|WRAP| (tourus) or \verb|FIXED| (fixed
  boundary) or \verb|ECHO| (echoing boundary).  \verb|WRAP|,
  \verb|FIXED|, \verb|ECHO| are predefined.


  \item{\texttt{(unsigned long) ulseedG}\\} The random
  seed. Default is 56.
  \item{\texttt{(int) Time}}\\ This variable is not supposed to be
	     modified during whole simulation. Users can know the current
	     time step via this variable.
  \item{\texttt{(int) MaxTime}}\\ The maximum number of
	     iteration. Default is 2147483647 (=\verb|INT_MAX|)
 \end{description} 

\item{\texttt{void InitialPlane(void)}}\\ The function is supposed to
call \verb|MakePlane()| to create CA planes. The function is supposed %% BioMed_Central_Tex_Template_v1.06
%DIF LATEXDIFF DIFFERENCE FILE


%%                                      %
%  bmc_article.tex            ver: 1.06 %
%                                       %

%%IMPORTANT: do not delete the first line of this template
%%It must be present to enable the BMC Submission system to
%%recognise this template!!

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%                                     %%
%%  LaTeX template for BioMed Central  %%
%%     journal article submissions     %%
%%                                     %%
%%          <8 June 2012>              %%
%%                                     %%
%%                                     %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%                                                                 %%
%% For instructions on how to fill out this Tex template           %%
%% document please refer to Readme.html and the instructions for   %%
%% authors page on the biomed central website                      %%
%% http://www.biomedcentral.com/info/authors/                      %%
%%                                                                 %%
%% Please do not use \input{...} to include other tex files.       %%
%% Submit your LaTeX manuscript as one .tex document.              %%
%%                                                                 %%
%% All additional figures and files should be attached             %%
%% separately and not embedded in the \TeX\ document itself.       %%
%%                                                                 %%
%% BioMed Central currently use the MikTex distribution of         %%
%% TeX for Windows) of TeX and LaTeX.  This is available from      %%
%% http://www.miktex.org                                           %%
%%                                                                 %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%% additional documentclass options:
%  [doublespacing]
%  [linenumbers]   - put the line numbers on margins


%%% loading packages, author definitions

%\documentclass[twocolumn]{bmcart}% uncomment this for twocolumn layout and comment line below

\documentclass{bmcart}

%%% Load packages
%\usepackage{amsthm,amsmath}
%DIF 53c53
%DIF < %\RequirePackage{natbib}
%DIF -------
\RequirePackage{natbib} %DIF > 
%DIF -------
%\RequirePackage[authoryear]{natbib}% uncomment this for author-year bibliography
\RequirePackage{hyperref}

\usepackage[utf8]{inputenc} %unicode support
%\usepackage[applemac]{inputenc} %applemac support if unicode package fails
%\usepackage[latin1]{inputenc} %UNIX support if unicode package fails

\usepackage{setspace} 


%\doublespacing
%\usepackage[right]{lineno}
%\linenumbers
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%                                             %%
%%  If you wish to display your graphics for   %%
%%  your own use using includegraphic or       %%
%%  includegraphics, then comment out the      %%
%%  following two lines of code.               %%
%%  NB: These line *must* be included when     %%
%%  submitting to BMC.                         %%
%%  All figure files must be submitted as      %%
%%  separate graphics through the BMC          %%
%%  submission process, not included in the    %%
%%  submitted article.                         %%
%%                                             %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage{graphicx}		% To include figures, useful for draft (REMOVE figures before submission)
\RequirePackage[table]{xcolor}
\definecolor{bmcblue}{rgb}{0,0.2,0.4}
%\usepackage{tikz}		% Necessary for todonotes
% array package and thick rules for tables
%\usepackage{array}

%% ADDED PACKAGES %%
%\usepackage{graphicx}		% To include figures, useful for draft (REMOVE figures before submission)
\usepackage{tabularx}
\usepackage{listings}

%\def\includegraphic{}
%\def\includegraphics{}




%%% Put your definitions there:
\startlocaldefs
\endlocaldefs


%%% Begin ...
%DIF PREAMBLE EXTENSION ADDED BY LATEXDIFF
%DIF UNDERLINE PREAMBLE %DIF PREAMBLE
\RequirePackage[normalem]{ulem} %DIF PREAMBLE
\RequirePackage{color}\definecolor{RED}{rgb}{1,0,0}\definecolor{BLUE}{rgb}{0,0,1} %DIF PREAMBLE
\providecommand{\DIFaddtex}[1]{{\protect\color{blue}\uwave{#1}}} %DIF PREAMBLE
\providecommand{\DIFdeltex}[1]{{\protect\color{red}\sout{#1}}}                      %DIF PREAMBLE
%DIF SAFE PREAMBLE %DIF PREAMBLE
\providecommand{\DIFaddbegin}{} %DIF PREAMBLE
\providecommand{\DIFaddend}{} %DIF PREAMBLE
\providecommand{\DIFdelbegin}{} %DIF PREAMBLE
\providecommand{\DIFdelend}{} %DIF PREAMBLE
%DIF FLOATSAFE PREAMBLE %DIF PREAMBLE
\providecommand{\DIFaddFL}[1]{\DIFadd{#1}} %DIF PREAMBLE
\providecommand{\DIFdelFL}[1]{\DIFdel{#1}} %DIF PREAMBLE
\providecommand{\DIFaddbeginFL}{} %DIF PREAMBLE
\providecommand{\DIFaddendFL}{} %DIF PREAMBLE
\providecommand{\DIFdelbeginFL}{} %DIF PREAMBLE
\providecommand{\DIFdelendFL}{} %DIF PREAMBLE
%DIF HYPERREF PREAMBLE %DIF PREAMBLE
\providecommand{\DIFadd}[1]{\texorpdfstring{\DIFaddtex{#1}}{#1}} %DIF PREAMBLE
\providecommand{\DIFdel}[1]{\texorpdfstring{\DIFdeltex{#1}}{}} %DIF PREAMBLE
\newcommand{\DIFscaledelfig}{0.5}
%DIF HIGHLIGHTGRAPHICS PREAMBLE %DIF PREAMBLE
\RequirePackage{settobox} %DIF PREAMBLE
\RequirePackage{letltxmacro} %DIF PREAMBLE
\newsavebox{\DIFdelgraphicsbox} %DIF PREAMBLE
\newlength{\DIFdelgraphicswidth} %DIF PREAMBLE
\newlength{\DIFdelgraphicsheight} %DIF PREAMBLE
% store original definition of \includegraphics %DIF PREAMBLE
\LetLtxMacro{\DIFOincludegraphics}{\includegraphics} %DIF PREAMBLE
\newcommand{\DIFaddincludegraphics}[2][]{{\color{blue}\fbox{\DIFOincludegraphics[#1]{#2}}}} %DIF PREAMBLE
\newcommand{\DIFdelincludegraphics}[2][]{% %DIF PREAMBLE
	\sbox{\DIFdelgraphicsbox}{\DIFOincludegraphics[#1]{#2}}% %DIF PREAMBLE
	\settoboxwidth{\DIFdelgraphicswidth}{\DIFdelgraphicsbox} %DIF PREAMBLE
	\settoboxtotalheight{\DIFdelgraphicsheight}{\DIFdelgraphicsbox} %DIF PREAMBLE
	\scalebox{\DIFscaledelfig}{% %DIF PREAMBLE
		\parbox[b]{\DIFdelgraphicswidth}{\usebox{\DIFdelgraphicsbox}\\[-\baselineskip] \rule{\DIFdelgraphicswidth}{0em}}\llap{\resizebox{\DIFdelgraphicswidth}{\DIFdelgraphicsheight}{% %DIF PREAMBLE
				\setlength{\unitlength}{\DIFdelgraphicswidth}% %DIF PREAMBLE
				\begin{picture}(1,1)% %DIF PREAMBLE
				\thicklines\linethickness{2pt} %DIF PREAMBLE
				{\color[rgb]{1,0,0}\put(0,0){\framebox(1,1){}}}% %DIF PREAMBLE
				{\color[rgb]{1,0,0}\put(0,0){\line( 1,1){1}}}% %DIF PREAMBLE
				{\color[rgb]{1,0,0}\put(0,1){\line(1,-1){1}}}% %DIF PREAMBLE
				\end{picture}% %DIF PREAMBLE
			}\hspace*{3pt}}} %DIF PREAMBLE
} %DIF PREAMBLE
\LetLtxMacro{\DIFOaddbegin}{\DIFaddbegin} %DIF PREAMBLE
\LetLtxMacro{\DIFOaddend}{\DIFaddend} %DIF PREAMBLE
\LetLtxMacro{\DIFOdelbegin}{\DIFdelbegin} %DIF PREAMBLE
\LetLtxMacro{\DIFOdelend}{\DIFdelend} %DIF PREAMBLE
\DeclareRobustCommand{\DIFaddbegin}{\DIFOaddbegin \let\includegraphics\DIFaddincludegraphics} %DIF PREAMBLE
\DeclareRobustCommand{\DIFaddend}{\DIFOaddend \let\includegraphics\DIFOincludegraphics} %DIF PREAMBLE
\DeclareRobustCommand{\DIFdelbegin}{\DIFOdelbegin \let\includegraphics\DIFdelincludegraphics} %DIF PREAMBLE
\DeclareRobustCommand{\DIFdelend}{\DIFOaddend \let\includegraphics\DIFOincludegraphics} %DIF PREAMBLE
\LetLtxMacro{\DIFOaddbeginFL}{\DIFaddbeginFL} %DIF PREAMBLE
\LetLtxMacro{\DIFOaddendFL}{\DIFaddendFL} %DIF PREAMBLE
\LetLtxMacro{\DIFOdelbeginFL}{\DIFdelbeginFL} %DIF PREAMBLE
\LetLtxMacro{\DIFOdelendFL}{\DIFdelendFL} %DIF PREAMBLE
\DeclareRobustCommand{\DIFaddbeginFL}{\DIFOaddbeginFL \let\includegraphics\DIFaddincludegraphics} %DIF PREAMBLE
\DeclareRobustCommand{\DIFaddendFL}{\DIFOaddendFL \let\includegraphics\DIFOincludegraphics} %DIF PREAMBLE
\DeclareRobustCommand{\DIFdelbeginFL}{\DIFOdelbeginFL \let\includegraphics\DIFdelincludegraphics} %DIF PREAMBLE
\DeclareRobustCommand{\DIFdelendFL}{\DIFOaddendFL \let\includegraphics\DIFOincludegraphics} %DIF PREAMBLE
%DIF LISTINGS PREAMBLE %DIF PREAMBLE
\RequirePackage{listings} %DIF PREAMBLE
\RequirePackage{color} %DIF PREAMBLE
\lstdefinelanguage{DIFcode}{ %DIF PREAMBLE
	%DIF DIFCODE_UNDERLINE %DIF PREAMBLE
	moredelim=[il][\color{red}\sout]{\%DIF\ <\ }, %DIF PREAMBLE
	moredelim=[il][\color{blue}\uwave]{\%DIF\ >\ } %DIF PREAMBLE
} %DIF PREAMBLE
\lstdefinestyle{DIFverbatimstyle}{ %DIF PREAMBLE
	language=DIFcode, %DIF PREAMBLE
	basicstyle=\ttfamily, %DIF PREAMBLE
	columns=fullflexible, %DIF PREAMBLE
	keepspaces=true %DIF PREAMBLE
} %DIF PREAMBLE
\lstnewenvironment{DIFverbatim}{\lstset{style=DIFverbatimstyle}}{} %DIF PREAMBLE
\lstnewenvironment{DIFverbatim*}{\lstset{style=DIFverbatimstyle,showspaces=true}}{} %DIF PREAMBLE
%DIF END PREAMBLE EXTENSION ADDED BY LATEXDIFF

\begin{document}
	
	%%% Start of article front matter
	\begin{frontmatter}
		
		\begin{fmbox}
			\dochead{Research}
			
			%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
			%%                                          %%
			%% Enter the title of your article here     %%
			%%                                          %%
			%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
			
			\title{\DIFdelbegin \DIFdel{Virtual Microbes evolve multiple mechanisms to }\DIFdelend \DIFaddbegin \DIFadd{Trusting }\DIFaddend the \DIFdelbegin \DIFdel{same end}\DIFdelend \DIFaddbegin \DIFadd{hand that feeds}\DIFaddend : \DIFdelbegin \DIFdel{anticipating }\DIFdelend \DIFaddbegin \DIFadd{microbes evolve to anticipate }\DIFaddend a serial transfer protocol \DIFaddbegin \DIFadd{as individuals or collectives}\DIFaddend }
			
			%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
			%%                                          %%
			%% Enter the authors here                   %%
			%%                                          %%
			%% Specify information, if available,       %%
			%% in the form:                             %%
			%%   <key>={<id1>,<id2>}                    %%
			%%   <key>=                                 %%
			%% Comment or delete the keys which are     %%
			%% not used. Repeat \author command as much %%
			%% as required.                             %%
			%%                                          %%
			%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
			
			\author[
			addressref={aff1},                   % id's of addresses, e.g. {aff1,aff2}
			corref={aff1},                       % id of corresponding address, if any
			%noteref={n1},                        % id's of article notes, if any
			email={b.vandijk@uu.nl}   % email address
			]{\inits{B}\fnm{Bram} \snm{van Dijk}}
			\author[
			addressref={aff1},
			email={j.meijer1@uu.nl}
			]
			{\inits{J}\fnm{Jeroen} \snm{Meijer}}
			\author[
			addressref={aff1},
			email={thomas.cuypers@gmail.com}
			]
			{\inits{TD}\fnm{Thomas D} \snm{Cuypers}}
			\author[
			addressref={aff1},
			email={p.hogeweg@uu.nl}
			]
			{\inits{P}\fnm{Paulien} \snm{Hogeweg}}
			\\b.vandijk@uu.nl, j.meijer1@uu.nl, thomas.cuypers@gmail.com, p.hogeweg@uu.nl
			%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
			%%                                          %%
			%% Enter the authors' addresses here        %%
			%%                                          %%
			%% Repeat \address commands as much as      %%
			%% required.                                %%
			%%                                          %%
			%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
			
			\address[id=aff1]{%                           % unique id
				\orgname{Theoretical Biology, Utrecht University}, % university, etc
				\street{Padualaan 8},                     %
				%\postcode{}                                % post or zip code
				\city{Utrecht},                              % city
				\cny{The Netherlands}                                    % country
			}
			
			%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
			%%                                          %%
			%% Enter short notes here                   %%
			%%                                          %%
			%% Short notes will be after addresses      %%
			%% on first page.                           %%
			%%                                          %%
			%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
			
			\begin{artnotes}
				%\note{Sample of title note}     % note to the article
				%\note[id=n1]{Equal contributor} % note, connected to author
			\end{artnotes}
			
		\end{fmbox}% comment this for two column layout
		
		%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
		%%                                          %%
		%% The Abstract begins here                 %%
		%%                                          %%
		%% Please refer to the Instructions for     %%
		%% authors on http://www.biomedcentral.com  %%
		%% and include the section headings         %%
		%% accordingly for your article type.       %%
		%%                                          %%
		%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
		
		\begin{abstractbox}
			\begin{abstract} % abstract
				\footnotesize
				\parttitle{Background} 
				Experimental evolution of microbes often involves a serial transfer protocol, where microbes are repeatedly diluted by transfer to a fresh medium, starting a new growth cycle. This \DIFdelbegin \DIFdel{protocol }\DIFdelend has revealed that evolution can be remarkably reproducible, where microbes show parallel adaptations both on the level of the phenotype as well as the genotype. However, these studies also reveal a strong potential for divergent evolution, leading to diversity both between and within replicate populations.  We here study how \textit{in silico} evolved Virtual Microbe ``wild types'' (WTs) adapt to a serial transfer protocol to investigate \DIFdelbegin \DIFdel{both the generic evolutionary adaptation to such an environment which are independent of prior evolution, and the variety of ways in which the adaptation is implemented at the individual and ecosystem level}\DIFdelend \DIFaddbegin \DIFadd{generic evolutionary adaptations, and how these adaptations can be manifested by a variety of different mechanisms}\DIFaddend .
				\parttitle{Results} 
				We show that all pre-evolved WTs evolve to anticipate the regularity of the serial transfer protocol by adopting a fine-tuned balance of growth and survival. We find that this anticipation \DIFdelbegin \DIFdel{can be done in a variety of ways, either by a single lineage or by several lineages in consort. Interestingly, replicate populations of the same WT initially show similar trajectories, but may subsequently diverge along a growth rate }\DIFdelend \DIFaddbegin \DIFadd{is done by evolving either a high yield mode, or a high growth rate mode. In the high yield mode, the cell volume at the end of the cycle is sufficient to immediately divide the next day. In the high growth rate mode, the medium is maximally exploited but the microbes are very unfit during the stationary phase. Intermediate solutions on this growth }\DIFaddend versus yield trade-off \DIFdelbegin \DIFdel{. 
				}\DIFdelend \DIFaddbegin \DIFadd{rarely evolve. We find that both modes of anticipation can be achieved by individual lineages and by collectives of microbes, and that similar yield can be attained by either outcome. However, populations that cannot regulate gene expression have less degrees of freedom, and perform better as a community.
			}\DIFaddend \parttitle{Conclusions}
			We find that all our \textit{in silico} WTs \DIFdelbegin \DIFdel{show the same anticipation effects --- fitting }\DIFdelend \DIFaddbegin \DIFadd{evolve to trust the hand that feeds by evolving to anticipate }\DIFaddend the periodicity of a serial transfer protocol\DIFdelbegin \DIFdel{--- but }\DIFdelend \DIFaddbegin \DIFadd{, but can }\DIFaddend do so by \DIFdelbegin \DIFdel{a variety of mechanisms. Our results reveal new insights into the dynamics and relevant selection pressures in experimental evolution, but also highlight how, in an eco-evolutionary context, numerous mechanisms can evolve to the same end.
			}%DIFDELCMD < 
			
			%DIFDELCMD < %%%
			\DIFdelend \DIFaddbegin \DIFadd{evolving two distinct growth strategies. Furthermore, both these growth strategies can be accomplished by a gene regulation, a variety of different polymorphisms, and combinations thereof. Our work reveals that, even under controlled conditions like those in the lab, it may not be possible to predict individual evolutionary trajectories, but repeated experiments may well result in only a limited number of possible outcomes.
			}\DIFaddend \end{abstract}
		
		%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
		%%                                          %%
		%% The keywords begin here                  %%
		%%                                          %%
		%% Put each keyword in separate \kwd{}.     %%
		%%                                          %%
		%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
		
		\begin{keyword}
			\kwd{experimental evolution}
			\DIFaddbegin \kwd{predicting evolution}
			\DIFaddend \kwd{serial transfer protocol}
			\DIFaddbegin \kwd{resource cycle}
			\DIFaddend \kwd{eco-evolutionary dynamics}
			\kwd{in silico evolution}
			\DIFdelbegin %DIFDELCMD < \kwd{predicting evolution}
			%DIFDELCMD < %%%
			\DIFdelend \DIFaddbegin \kwd{digital microbes}
			\kwd{virtual microbes}
			\DIFaddend \end{keyword}
		
		% MSC classifications codes, if any
		%\begin{keyword}[class=AMS]
		%\kwd[Primary ]{}
		%\kwd{}
		%\kwd[; secondary ]{}
		%\end{keyword}
		
	\end{abstractbox}
	%
	%\end{fmbox}% uncomment this for twcolumn layout
	
\end{frontmatter}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%                                          %%
%% The Main Body begins here                %%
%%                                          %%
%% Please refer to the instructions for     %%
%% authors on:                              %%
%% http://www.biomedcentral.com/info/authors%%
%% and include the section headings         %%
%% accordingly for your article type.       %%
%%                                          %%
%% See the Results and Discussion section   %%
%% for details on how to create sub-sections%%
%%                                          %%
%% use \cite{...} to cite references        %%
%%  \cite{koon} and                         %%
%%  \cite{oreg,khar,zvai,xjon,schn,pond}    %%
%%  \nocite{smith,marg,hunn,advi,koha,mouse}%%
%%                                          %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%% start of article main body
% <put your article body there>

%%%%%%%%%%%%%%%%
%% Background %%
%%
\def\inserttotalframenumber{10}
\newpage

\section*{Background}
{	
	In order to see microbial evolution in action, we often rely on experimental evolution under controlled laboratory conditions. The Long-term Evolution Experiment (LTEE)\cite{lenski1991long} and similar shorter studies\DIFdelbegin \DIFdel{\mbox{%DIFAUXCMD
			\cite{dettman2007incipient,paterson2010antagonistic,salverda2017adaptive} }\hspace{0pt}%DIFAUXCMD
	}\DIFdelend \DIFaddbegin \DIFadd{\mbox{%DIFAUXCMD
		\cite{dettman2007incipient,paterson2010antagonistic} }\hspace{0pt}%DIFAUXCMD
}\DIFaddend have, for example, evolved many generations of microbes using a serial transfer protocol, where microbes are repeatedly diluted and transferred to a fresh medium to start a new growth cycle. Conceptually, if we learn to understand how microbes adapt to such a \DIFdelbegin \DIFdel{daily }\DIFdelend resource cycle, we might one day be able to predict evolution in the lab and --- ideally --- also in nature. Indeed, a lot of evolution in the lab seems remarkably reproducible, where microbes show parallel adaptations both on the level of the phenotype as well as the genotype  \cite{dunham2002characteristic,cooper2003parallel,pelosi2006parallel,philippe2007evolution,hindre2012new,laan2015evolutionary,salverda2017adaptive,consuegra2017genetic}. However, there also seems to be strong potential for divergent evolution, leading to diversity both between and within replicate populations \cite{rozen2000long,rozen2009death,plucain2014epistasis}. Diversification events within populations often entail cross-feeding interactions \cite{rainey1998adaptive,treves1998repeated,rozen2000long,rozen2005long,rozen2009death,turner2015evolution},
where species emerge that grow on metabolic by-products. These cross-feeding interactions are increasingly well understood with the help of metabolic modeling and digital evolution \cite{grosskopf2016metabolic,rocabert2017beware}. A recent metagenomic study has revealed even more coexisting lineages in the LTEE than were previously reported \cite{good2017dynamics}. It is however not yet clear whether all these polymorphisms are the result of uni-directional cross-feeding interactions, or if other mechanisms could drive coexistence in a simple experiment such as a serial transfer protocol. \DIFaddbegin \DIFadd{Furthermore, whether or not the diversified communities experience fundamentally different selection pressures and growth dynamics as a collective, is still an open question. }\DIFaddend \smallskip

Prior to being subjected to lab conditions, the microbes used in the aforementioned experimental studies have all had a long evolutionary history in natural environments, experiencing harshly fluctuating and --- more
often than not --- \DIFdelbegin \DIFdel{unfavorable }\DIFdelend \DIFaddbegin \DIFadd{unfavourable }\DIFaddend conditions. While a serial transfer protocol \DIFdelbegin \DIFdel{such as that of the LTEE }\DIFdelend at a first glance selects mostly for higher growth rates when resources are abundant (\textit{i.e.} during the log phase), there is also selection to survive when resources are depleted and the population no longer grows (\textit{i.e.} during the stationary phase). In fact, given the unpredictable conditions found in nature, some of the ancestors of \textit{Escherichia coli} might have survived precisely because they diverted resources \textit{away} from growth. Indeed, \textit{E. coli} does exactly this during the stationary phase by means of the stringent response, regulating up to one third of all genes during starvation \cite{sarubbi1989characterization}. This response lowers the growth rate, but promotes efficiency and survival (\textit{i.e.} a higher yield). While most microbes have ways to deal with starvation, the physiology of growth arrest varies a lot across different microbes\DIFaddbegin \DIFadd{, and especially display great variation in how long they can persist in the absence of nutrients }\DIFaddend (for an excellent review, see \cite{bergkessel_physiology_2016}). \DIFdelbegin \DIFdel{Responses to starvation,  as }\DIFdelend \DIFaddbegin \DIFadd{After prolonged starvation,  many species of bacteria go through even more physiological changes, such as the GASP response \mbox{%DIFAUXCMD
		\cite{finkel2006long}}\hspace{0pt}%DIFAUXCMD
	, persistence \mbox{%DIFAUXCMD
		\cite{balaban2004bacterial}}\hspace{0pt}%DIFAUXCMD
	, and sporulation \mbox{%DIFAUXCMD
		\cite{piggot2004sporulation}}\hspace{0pt}%DIFAUXCMD
	. Bacteria have also been shown to employ bet-hedging strategies with respect to these physiological changes \mbox{%DIFAUXCMD
		\cite{veening2008bet,solopova2014bet,veening2008bistability}}\hspace{0pt}%DIFAUXCMD
	, which could help to adapt to unexpected environmental changes. Finally, it has been shown that microorganisms can even adjust to }\textit{\DIFadd{expected}} \DIFadd{environmental changes, anticipating regularity in environmental changes \mbox{%DIFAUXCMD
		\cite{balaban2004bacterial,mitchell2009adaptive,tagkopoulos2008predictive}}\hspace{0pt}%DIFAUXCMD
	, which usually entails using predictive cues from the environment. All these responses, as }\DIFaddend well as other features that organisms have acquired during their evolutionary history (\DIFdelbegin \DIFdel{such as }\DIFdelend gene clustering, gene regulatory network architecture, metabolic regulation\DIFaddbegin \DIFadd{, }\textit{\DIFadd{etc.}}\DIFaddend ), might strongly influence the adaptation and reproducibility we observe in the lab today.  \DIFaddbegin \\	
\DIFaddend 

What do we expect when a complex, ``pre-evolved'' \DIFdelbegin \DIFdel{microbe adapts to a }\DIFdelend \DIFaddbegin \DIFadd{organism adapts to }\DIFaddend serial transfer protocol \DIFdelbegin \DIFdel{like the LTEE}\DIFdelend \DIFaddbegin \DIFadd{in the lab, given how clean and extremely regular these conditions are}\DIFaddend ? We here use Virtual Microbes in order to firstly mimic natural evolution, acquiring Virtual ``wild types'' (WTs), which we then expose to a serial transfer protocol (see methods). We do so in order to obtain a fresh perspective on \emph{\DIFdelbegin \DIFdel{what}\DIFdelend \DIFaddbegin \DIFadd{which}\DIFaddend } \DIFdelbegin \DIFdel{is being selected for, }\DIFdelend \emph{\DIFdelbegin \DIFdel{how}\DIFdelend \DIFaddbegin \DIFadd{generic adaptations}\DIFaddend } \DIFdelbegin \DIFdel{this target can be achieved, and which }\emph{\DIFdel{generic features}} %DIFAUXCMD
\DIFdelend might appear in spite of evolutionary contingencies\DIFaddbegin \DIFadd{, and }\emph{\DIFadd{how}} \DIFadd{these adaptations are achieved}\DIFaddend . We find that \DIFaddbegin \DIFadd{all }\DIFaddend the evolved WTs --- which are both genotypically and \DIFdelbegin \DIFdel{phenotypicall }\DIFdelend \DIFaddbegin \DIFadd{phenotypically }\DIFaddend diverse --- \DIFdelbegin \DIFdel{also lead to a variety of different solutions when subjected to a }\DIFdelend \DIFaddbegin \DIFadd{evolve to anticipate the regularity of the }\DIFaddend serial transfer protocol. \DIFdelbegin \DIFdel{More specifically, we see many alternative paths in terms of a growth dynamic trajectories, speciation and regulation}\DIFdelend \DIFaddbegin \DIFadd{While we find that only two growth strategies evolve, namely a mode of high growth rate and a mode of high yield, 	 many alternative trajectories, regulatory mechanisms, and a diverse set of different microbial communities can realise these two growth strategies}\DIFaddend . Despite this \DIFdelbegin \DIFdel{diversity however}\DIFdelend \DIFaddbegin \DIFadd{assortment of different mechanisms}\DIFaddend , all WTs \DIFdelbegin \DIFdel{evolve the same anticipation towards the serial transfer protocol, timing their growth rate, yield, and survival to accurately }\DIFdelend \DIFaddbegin \DIFadd{accurately time their dynamics to }\DIFaddend fit the daily cycle. \DIFdelbegin \DIFdel{Whereas some WTs do this by means of clever gene regulation, others diverge into specialised growth and survival strains, and other simply time their resource consumption as to not over-exploit the medium. }\DIFdelend In short, our WTs all recognized and exploited the regularity of the serial transfer protocol, \DIFdelbegin \DIFdel{anticipating resources to be available as usual}\DIFdelend \DIFaddbegin \DIFadd{having learned to trust the hand that feeds}\DIFaddend , but they solve this challenge by a variety of different mechanisms.


%%%%%%%%% RESULTS %%%%%%%%%
\section*{Results}

\DIFdelbegin \subsection*{\DIFdel{Using Virtual Microbes to search for generic patterns}}
%DIFAUXCMD
\DIFdelend %DIF > 	\subsection*{Using Virtual Microbes to search for generic patterns}
In this study we use Virtual Microbes, a model of the eco-evolutionary dynamics of microbes (see methods). In short, the Virtual Microbe model is unsupervised, meaning that it aims to combine relevant biological structures (genes, genomes, metabolism, mutations, ecology, etc.)\DIFdelbegin \DIFdel{without a preconceived notion of ``fitness'', which is instead }\DIFdelend \DIFaddbegin \DIFadd{, with ``competitive fitness'' as }\DIFaddend an emergent phenomenon. By not explicitly defining what the model \textit{should} do, it allows for a serendipitous approach to study microbial evolution. Our main objective in this study is to elucidate \emph{generic \DIFdelbegin \DIFdel{patterns}\DIFdelend \DIFaddbegin \DIFadd{adaptations}\DIFaddend } of evolution in a serial transfer protocol, \DIFdelbegin \DIFdel{and to investigate the extend to which these are }\DIFdelend \DIFaddbegin \DIFadd{to investigate how this is achieved, and to what extend it is }\DIFaddend constrained by prior evolution. In order not to lose track of the objective of \emph{finding generic patterns}, we refrain from discussing and analysing every mechanistic detail, and instead focus on major observables and discuss some illustrative cases.\DIFaddbegin \\
\DIFaddend 

\DIFdelbegin \DIFdel{Before we start }\DIFdelend \DIFaddbegin \subsection*{\DIFadd{Evolving Virtual Microbe ``Wild Types''}}
\DIFadd{Before }\DIFaddend evolving Virtual Microbes in a serial transfer protocol, we first evolved a set of Virtual ``\DIFdelbegin \DIFdel{wild types}\DIFdelend \DIFaddbegin \DIFadd{Wild Types}\DIFaddend '' (WTs). Instead of optimizing these WTs solely for high growth rates \DIFaddbegin \DIFadd{or optimal metabolic flux}\DIFaddend , we here mimic natural circumstances by fluctuating resource conditions (Figure \ref{fig:wt_evolution}A). When too little resource is available, the Virtual Microbes cannot grow\DIFaddbegin \DIFadd{, and can only stay alive for as long as their resources last}\DIFaddend . When too much resource is available however, the Virtual Microbes run the risk of accumulating too high concentrations of metabolites, resulting in increased death rates due to toxicity. \DIFaddbegin \DIFadd{Furthermore, a stochastic death process is implemented, allowing even a maximally flourishing Virtual Microbes to only live 100 time steps on average. }\DIFaddend To avoid extinction, we divided the total grid into four sub-grids\DIFdelbegin \DIFdel{. In these sub-grids, }\DIFdelend \DIFaddbegin \DIFadd{, where }\DIFaddend the two resource metabolites A and C (yellow and blue in Figure \ref{fig:overview}A) \DIFaddbegin \DIFadd{independently }\DIFaddend change in their influx rates with probability 0.01 \DIFdelbegin \DIFdel{. Both these resources can be converted into building blocks (purple)required for growth. Maximally flourishing Virtual Microbes live on average 100 time steps. Thus, a healthy Virtual Microbe experiences on average}\DIFdelend \DIFaddbegin \DIFadd{(see Table \ref{tab:force}). Thus, on average, an individual will experience }\DIFaddend one fluctuation in resource conditions \DIFdelbegin \DIFdel{in }\DIFdelend \DIFaddbegin \DIFadd{during }\DIFaddend its lifetime (see full configuration in S1). 
\DIFdelbegin \DIFdel{As }\DIFdelend \DIFaddbegin \DIFadd{While both influxed resources can be converted into building blocks required for growth, }\DIFaddend the rates of influx span four orders of magnitude \DIFdelbegin \DIFdel{, conditions will }\DIFdelend \DIFaddbegin \DIFadd{($10^{-5}$ -- $10^{-1}$, see Table \ref{tab:force})), and conditions will thus }\DIFaddend vary from very favourable to very poor. \DIFdelbegin \DIFdel{This }\DIFdelend \DIFaddbegin \DIFadd{Although poor conditions could cause a local population of microbes to go extinct due to limiting resources, total extinction is highly unlikely due to the 4 independent sub-grids. All this }\DIFaddend in turn depends on which resources the evolved Virtual Microbes like to consume (and at which rate), whether or not there is too much or too little resource, and whether or not space for reproduction is available. \DIFaddbegin \DIFadd{Finally, persisting in an unfavourable environment for a long time can be rewarding if conditions improve. }\DIFaddend All in all, this results in an unsupervised evolutionary process where there is no prior expectation of what metabolic strategy or gene regulatory networks might be best suited to survive. \DIFdelbegin \DIFdel{Because competitive fitness is not a priori defined, we can }\DIFdelend \DIFaddbegin \DIFadd{We }\DIFaddend study what will be the long-term target of the eco-evolutionary dynamics, not in terms of fitness, but in terms of what the Virtual Microbes evolve \textit{to do}. \DIFaddbegin \\	
\DIFaddend 

\DIFdelbegin \DIFdel{Using this protocol, we }\DIFdelend \DIFaddbegin \DIFadd{We }\DIFaddend evolved the same initial clone in the exact same ``random'' resource fluctuations, \emph{only} varying the mutations that happened across $\sim$10.000 generations of evolution. This produced 16 distinct WTs with their own evolutionary history, which we then expose to the serial transfer protocol (Figure \ref{fig:wt_evolution}B). Despite experiencing precisely the same fluctuations, no two WTs evolved to be the same. For example, we observe a great diversity in gene content, kinetic parameters of enzymes, gene regulatory networks and their complexity, and responses to environmental stimuli. The core metabolism is however strikingly similar across WTs, always consisting of a simple metabolic cycle. The rates of building block production and death rates are also very similar across all WTs (Figure \ref{sfig:reg_vs_non}). In other words, it appears that there are many different ways to be fit, and that no solution is evidently better. The similarities and differences between our WTs are summarized in Figure \ref{fig:wt_evolution}C, but we discuss this in more detail in Supplementary Section 1.

\subsection*{Long-term evolution experiment \textit{in silico} }

After evolving a variety of different WTs, we \DIFdelbegin \DIFdel{mimic }\DIFdelend \DIFaddbegin \DIFadd{transfer the WTs to }\DIFaddend a serial transfer protocol\DIFdelbegin \DIFdel{like that of the LTEE}\DIFdelend . With regular intervals, all but 10 percent of the cells are removed, while at the same time refreshing the medium. Although time in Virtual Microbes has arbitrary units, we will refer to this process as the ``daily'' cycle from this point forward. Early in the day, during the log phase, high growth rates are very rewarding as there is a lot of opportunity to reproduce. However, once the population has reached stationary phase (having consumed all resources), it is favourable to survive and to not invest in growth any further. We will focus on how our WTs adapt to these alternating selection pressures. The results discussed here are found for a variety of different medium conditions (\textit{e.g.} also see Table S2). In the main text however, we present the 50 time step serial transfer protocol where the medium contained both resources (A and C), as this was a condition on which all WTs could be cultivated, ensuring equal treatment. We focus on the generic \DIFdelbegin \DIFdel{features of the adaptation }\DIFdelend \DIFaddbegin \DIFadd{adaptations }\DIFaddend towards this protocol \DIFdelbegin \DIFdel{, and }\DIFdelend \DIFaddbegin \DIFadd{first, and then show }\DIFaddend how specific WTs and contingent factors from their evolutionary history shape these outcomes. 

\subsection*{All wild types evolve to anticipate the serial transfer protocol}

After 800 days of evolving in a serial transfer protocol, we compare the ancestral WTs with the evolved populations. We \DIFdelbegin \DIFdel{firstly look at }\DIFdelend \DIFaddbegin \DIFadd{first show }\DIFaddend some of the well-known growth dynamics of microbes: the lag-, log-, and stationary phase (Figure \ref{fig:anticipation}A}). As most experimental \DIFdelbegin \DIFdel{evoultionary }\DIFdelend \DIFaddbegin \DIFadd{evolutionary }\DIFaddend studies in the lab, we too observe a decreased lag phase and an increased growth rate. The increased growth rate in the evolved population results in an earlier onset of the stationary phase, which therefore takes much longer than for their WT ancestors. Eventually, this leads to a phase where the cell count decreases again (death phase), revealing a decrease in survival for the evolved populations. To further study how this decreased survival comes about, we next investigated the dynamics of average cell volumes\DIFdelbegin \DIFdel{, which are indicative of }\DIFdelend \DIFaddbegin \DIFadd{. Cell volume is an indicator for }\DIFaddend the ``health'' of the population\DIFdelbegin \DIFdel{: cell volume determines }\DIFdelend \DIFaddbegin \DIFadd{, determining }\DIFaddend the ability to divide (minimal division volume) and survive (minimal viable volume). A first interesting observation is an increase in average cell volume during the log phase (Figure \ref{fig:anticipation}B-C), which is also one of the first results from the LTEE\cite{lenski1994dynamics}. However, after this increase in cell volumes during the log phase, evolved populations display a clear decrease in cell volumes, either at the end of the day (Figure \ref{fig:anticipation}B), or during the whole stationary phase (Figure \ref{fig:anticipation}C). Indeed, if we expose the populations to prolonged starvation by extending the day, the evolved populations die shortly after the anticipated serial transfer, while their WT ancestors survived for much longer (Figure \ref{fig:anticipation}B-C, right-hand side). \DIFdelbegin \DIFdel{Interestingly}\DIFdelend \DIFaddbegin \DIFadd{Strikingly}\DIFaddend , we observed that the cell volume at the time of \DIFdelbegin \DIFdel{transfering }\DIFdelend \DIFaddbegin \DIFadd{transferring }\DIFaddend the cells to a fresh medium (henceforth `\DIFdelbegin \DIFdel{transfer volume}\DIFdelend \DIFaddbegin \DIFadd{volume-at-transfer}\DIFaddend ') fall into two distinct categories. In the high yield scenario (Figure \ref{fig:anticipation}B), cell volumes are maintained \emph{above the division volume} until the very end of the day, whereas the low yield scenario\DIFaddbegin \DIFadd{, albeit having a higher growth rate, }\DIFaddend leads to a \DIFdelbegin \DIFdel{transfer volume }\DIFdelend \DIFaddbegin \DIFadd{volume-at-transfer }\DIFaddend that is \emph{just above minimal}. \DIFdelbegin \DIFdel{While }\DIFdelend \DIFaddbegin \DIFadd{Indeed, }\DIFaddend the distribution of these observed \DIFdelbegin \DIFdel{transfer volumes }\DIFdelend \DIFaddbegin \DIFadd{volume-at-transfer }\DIFaddend across ancestral WTs are mostly high (Figure \ref{fig:anticipation}D, left-hand side), \DIFaddbegin \DIFadd{while }\DIFaddend the evolved cells \DIFaddbegin \DIFadd{clearly }\DIFaddend show a bimodal distribution (Figure \ref{fig:anticipation}D, right-hand side). \DIFdelbegin \DIFdel{The WTs }\DIFdelend \DIFaddbegin \DIFadd{Thus, all the populations }\DIFaddend evolved to either be ready to immediately divide at transfer (\DIFdelbegin \DIFdel{Figure \ref{fig:anticipation}B}\DIFdelend \DIFaddbegin \DIFadd{high yield mode}\DIFaddend ), or exploit as much resource as possible while remaining above the minimal viable volume (\DIFdelbegin \DIFdel{Figure \ref{fig:anticipation}C}\DIFdelend \DIFaddbegin \DIFadd{high growth rate mode}\DIFaddend ). Despite this difference \DIFdelbegin \DIFdel{, both alternative strategies }\DIFdelend \DIFaddbegin \DIFadd{in growth modes, both populations }\DIFaddend have evolved to \DIFdelbegin \DIFdel{anticipate }\DIFdelend \DIFaddbegin \DIFadd{accurately time }\DIFaddend the regularity of the serial transfer protocol. \DIFdelbegin \DIFdel{Indeed, when the extended yield (the total biomass that was generated after prolonged starvation) is measured, it shows }\DIFdelend \DIFaddbegin \DIFadd{All evolved populations also show }\DIFaddend a consistent decrease \DIFdelbegin \DIFdel{across all evolved populations }\DIFdelend \DIFaddbegin \DIFadd{in extended yield }\DIFaddend (Figure \ref{fig:anticipation}E) relative to the WTs, as \DIFdelbegin \DIFdel{these long term effects are }\DIFdelend \DIFaddbegin \DIFadd{long term yield is }\DIFaddend now masked from natural selection. \DIFdelbegin \DIFdel{We }\DIFdelend \DIFaddbegin \DIFadd{Finally, we }\DIFaddend found that this anticipation effect did not depend on details in the protocol, such as the length of the daily cycle or the number of resources used (Figure \ref{sfig:longshort}, Table S2). This reveals that a key selection pressure in a serial transfer protocol is not only growth as fast as possible, but also remaining viable until the next day, anticipating the next \DIFdelbegin \DIFdel{food supply }\DIFdelend \DIFaddbegin \DIFadd{supply of nutrients}\DIFaddend . 

\subsection*{\DIFdelbegin \DIFdel{WTs have distinct trajectories }\DIFdelend \DIFaddbegin \DIFadd{Evolution }\DIFaddend toward a growth-yield trade-off}

The two extreme categories of cell volume dynamics from Figure \ref{fig:anticipation} \DIFdelbegin \DIFdel{suggest a }\DIFdelend \DIFaddbegin \DIFadd{illustrate a well-studied }\DIFaddend trade-off between growth and yield \DIFaddbegin \DIFadd{in microbial populations \mbox{%DIFAUXCMD
		\cite{wortel2016evolutionary,li2019single,manhart2018trade}}\hspace{0pt}%DIFAUXCMD
}\DIFaddend . We next investigate how our different WTs evolve towards this trade-off, and how reproducible these trajectories are. For this, we repeated the serial transfer protocol 3 times for each WT, and follow the trajectories over time. After $\sim$800 serial transfers, all populations have adapted along a trade-off between growth and yield (Figure \ref{fig:trajectories}A\DIFdelbegin \DIFdel{, p $<<$ 10e-16, R$^2$ = 0.54). This }\DIFdelend \DIFaddbegin \DIFadd{). No }\DIFaddend trade-off was not observed during the first cycle of the protocol, which instead shows a positive correlation between growth and yield (Figure \ref{fig:trajectories}B\DIFdelbegin \DIFdel{, p $<<$ 10e-5, R$^2$ = 0.32). Most WTspredictably evolve }\DIFdelend \DIFaddbegin \DIFadd{), revealing how both growth and yield could initially be improved for most WTs. Evolution }\DIFaddend towards the trade-off\DIFaddbegin \DIFadd{, }\DIFaddend by improving both growth and yield \DIFdelbegin \DIFdel{(}\textit{\DIFdel{e.g.}} %DIFAUXCMD
\DIFdel{by }\DIFdelend \DIFaddbegin \DIFadd{by }\textit{\DIFadd{e.g.}} \DIFaddend importing more resources \DIFdelbegin \DIFdel{, }\DIFdelend or producing more building blocks\DIFdelbegin \DIFdel{), but subsequent evolution is very WT-specific. Many }\DIFdelend \DIFaddbegin \DIFadd{, is similar across all WTs, although not all WTs approach it with the same angle (also see Figure \ref{sfig:trajectories}). Subsequent evolution on the trade-off diverges into two distinct clusters, representing the two aforementioned modes of high yield and high growth rate. While many }\DIFaddend WTs maintain high yield (\textit{e.g.} Figure \ref{fig:trajectories}C), \DIFdelbegin \DIFdel{but }\DIFdelend others consistently trade off yield for a higher growth rate (Figure \ref{fig:trajectories}D). \DIFdelbegin \DIFdel{For instance, importing even more resources can improve growth even further, but leads to prolonged starvation and/or toxicity. Lastly, some WTs are showing }\DIFdelend \DIFaddbegin \DIFadd{Many other WTs however display }\DIFaddend variable trajectories after having arrived at the trade-off (Figure \ref{fig:trajectories}E, Figure \ref{sfig:trajectories}). \DIFdelbegin \DIFdel{Taken together, these results }\DIFdelend \DIFaddbegin \DIFadd{This }\DIFaddend illustrate how prior adaptations \DIFdelbegin \DIFdel{strongly }\DIFdelend \DIFaddbegin \DIFadd{can }\DIFaddend shape the way subsequent evolution plays out\DIFdelbegin \DIFdel{. Evidently}\DIFdelend \DIFaddbegin \DIFadd{, but that these evolutionary contingencies may diminish after prolonged evolution. Finally}\DIFaddend , specific WTs \DIFaddbegin \DIFadd{appear to }\DIFaddend more readily give rise to certain \DIFdelbegin \DIFdel{solutions}\DIFdelend \DIFaddbegin \DIFadd{outcomes}\DIFaddend , having specific adaptations in their ``mutational neighbourhood''. This is \DIFdelbegin \DIFdel{also }\DIFdelend \DIFaddbegin \DIFadd{for example }\DIFaddend illustrated by two WTs \DIFaddbegin \DIFadd{(5 and 11) }\DIFaddend that repeatedly gave rise to mutants with extremely high, but unsustainable growth rates, causing \DIFdelbegin \DIFdel{multiple }\DIFdelend populations to go extinct \DIFaddbegin \DIFadd{repeatedly }\DIFaddend (black crosses in Figure \ref{fig:trajectories}). In summary, some WTs adapt predictably to the serial transfer protocol, while others have diverging evolutionary trajectories and can reach different solutions. The consistency of WTs in combination with the diversity of trajectories illustrates how prior evolution can bias --- but not necessarily constrain --- subsequent evolution.\DIFaddbegin \\
\DIFaddend 

\subsection*{\DIFdelbegin \DIFdel{Polymorphism based anticipation by evolution growth and survival strains}\DIFdelend \DIFaddbegin \DIFadd{Anticipating as a collective}\DIFaddend }
\DIFaddbegin 

\DIFaddend So far we have only looked at population averages. Next, we study the dynamics of lineages and the evolved dynamics within cells. To track lineages we tag each individual in the population with a neutral lineage marker at the start of the experiment (analogous to DNA barcoding \DIFaddbegin \DIFadd{\mbox{%DIFAUXCMD
		\cite{blundell2014beyond}}\hspace{0pt}%DIFAUXCMD
}\DIFaddend ). When a single lineage reaches fixation, we reapply these neutral markers, allowing us to quickly detect long-term coexistence. Moreover, these neutral markers allow us to study which arising mutants are adaptive in the different phases of the growth cycle. In Figure \ref{fig:lineages}A we show dynamics of neutral lineage markers that are frequently redistributed when one lineages fixates in the population, indicating that there is no long-term coexistence of strains. In contrast, figure \ref{fig:lineages}B displays \DIFdelbegin \DIFdel{a repeatedly observed quasi-stable }\DIFdelend \DIFaddbegin \DIFadd{repeatedly observed (quasi-)stable }\DIFaddend coexistence, where two lineages coexist for some time, but coexistence was not stable in the long-term. Lastly, Figure \ref{fig:lineages}C shows stable, long-term coexistence, where \DIFdelbegin \DIFdel{two lineages coexisted }\DIFdelend \DIFaddbegin \DIFadd{the population sustains a balanced polymorphism }\DIFaddend until the end of the experiment. Coexistence (either quasi-stable or stable) was observed in 21 out of 44 extant populations (Figure \ref{fig:lineages}D). \DIFaddbegin \\
\DIFaddend 

By zooming in on the dynamics of coexisting lineage markers over a shorter time span (Figure \ref{fig:lineages}B-C, right-hand side), we can better understand how these lineages stably coexist. Notably, one lineage is dominating during log phase, while the other lineage performs better during stationary phase. In other words, the lineages have specialized on their own temporal niche. We find that these dynamics can be the result of three mechanisms (or combinations thereof): 1) cross-feeding on building \DIFdelbegin \DIFdel{blocks}\DIFdelend \DIFaddbegin \DIFadd{block metabolites}\DIFaddend , 2) specialisation on \DIFdelbegin \DIFdel{resource A or C, }\DIFdelend \DIFaddbegin \DIFadd{either of the two resources, or }\DIFaddend 3) based on the growth vs. yield trade-off. Cross-feeding dynamics always resulted in quasi-stable coexistence (such as depicted in \ref{fig:lineages}B), and never resulted in the balanced polymorphism as depicted in Figure \ref{fig:lineages}C), while the other two mechanisms (resource specialisation and growth vs. yield differentiation) most often resulted in long-term coexistence where \DIFdelbegin \DIFdel{the }\DIFdelend \DIFaddbegin \DIFadd{both }\DIFaddend lineages perform better together than they do alone (Figure \ref{sfig:removelin}). \DIFaddbegin \\
\DIFaddend 

While specialisation on different resources is a well known mechanism for negative frequency dependent selection, it is far less evident how a growth vs. yield trade-off would result in a fully balanced polymorphism. Mutants with higher growth rates but elevated death rates have a very distinct signature of increasing in frequency early in the daily cycle and decreasing to much lower frequencies during the stationary phase (Figure \ref{sfig:sfig_mutantsinvading}A), as apposed to lineages that increase in frequency throughout all phases of the cycle (Figure \ref{sfig:sfig_mutantsinvading}B). While such mutants readily arise across our experiments, they often have difficulty rising to fixation due to an increasing duration of the stationary phase\DIFaddbegin \DIFadd{, where they are unfit}\DIFaddend . In the meantime, a slower growing lineage with lower death rates can be optimized to utilize resources at low concentrations during stationary phase. \DIFdelbegin \DIFdel{Evidently, these }\DIFdelend \DIFaddbegin \DIFadd{These }\DIFaddend dynamics can give rise to a balanced polymorphism that does not depend on resource specialisation \DIFdelbegin \DIFdel{, as it is }\DIFdelend \DIFaddbegin \DIFadd{or cross feeding, and it }\DIFaddend also observed in our experiments with a single resource (Table S2). Indeed, Figure \ref{fig:lineages}\DIFdelbegin \DIFdel{A }\DIFdelend \DIFaddbegin \DIFadd{C }\DIFaddend illustrates how two lineages with more than a three-fold different death rates can stably coexist. \DIFaddbegin \\
\DIFaddend 

\DIFdelbegin \DIFdel{Besides this speciation on the basis of the growth vs. survival trade-off, we also found well-known mechanisms of speciation, such as cross-feeding \mbox{%DIFAUXCMD
		\cite{consuegra2017genetic,treves1998repeated,turner2015evolution}}\hspace{0pt}%DIFAUXCMD
	, canabalism\mbox{%DIFAUXCMD
		\cite{rozen2009death}}\hspace{0pt}%DIFAUXCMD
	, or other resources in the medium \mbox{%DIFAUXCMD
		\cite{rainey1998adaptive,dieckmann1999origin}}\hspace{0pt}%DIFAUXCMD
	. The nature of the coexistence }\DIFdelend %DIF > Besides this speciation on the basis of the growth vs. survival trade-off, we also found well-known mechanisms of speciation, such as cross-feeding \cite{consuegra2017genetic,treves1998repeated}, canabalism\cite{rozen2009death}, or other resources in the medium \cite{rainey1998adaptive,dieckmann1999origin,turner2015evolution}. 
\DIFaddbegin \DIFadd{The different forms of polymorphism discussed above }\DIFaddend can  differ strongly across WTs and replicated experiments. For example, since \emph{de novo} gene discoveries were disabled during this experiment, cross-feeding on building blocks is only possible if the ancestral WT had the necessary importer for \DIFdelbegin \DIFdel{said building block}\DIFdelend \DIFaddbegin \DIFadd{building blocks}\DIFaddend , which was true only for \DIFdelbegin \DIFdel{7}\DIFdelend \DIFaddbegin \DIFadd{6}\DIFaddend /16 WTs. Similarly, even though all WTs have the necessary importers for both the A and C resource, \DIFdelbegin \DIFdel{only }\DIFdelend one WT consistently diverged into an A- and C-specialist (WT10). While other WTs have multiple gene copies for these importers, WT10 had only 1 copy of both genes, making the loss-of-function mutations readily accessible. In conclusion, \DIFaddbegin \DIFadd{although }\DIFaddend all polymorphic population \DIFaddbegin \DIFadd{also }\DIFaddend anticipate the serial transfer protocol, \DIFdelbegin \DIFdel{but do so by a variety of mechanisms. However, they all have in common a }\emph{\DIFdel{generic pattern}} %DIFAUXCMD
\DIFdelend \DIFaddbegin \DIFadd{they do so in a distinct way from populations consisting of a single lineage. They all consist }\DIFaddend of strains which time growth and survival strategies in relation to each other \DIFaddbegin \DIFadd{in order }\DIFaddend to precisely finish the available \DIFdelbegin \DIFdel{food resources }\DIFdelend \DIFaddbegin \DIFadd{nutrients }\DIFaddend by the end of the day. 

\subsection*{\DIFdelbegin \DIFdel{Single lineage }\DIFdelend \DIFaddbegin \DIFadd{Individual }\DIFaddend anticipation by tuning and trimming the gene regulatory network}

The previous section illustrates how multiple lineages can coexist because the predictable serial transfer protocol produces temporal niches. However, many of our WTs do not show any tendency to speciate like this, and instead always adapt to the serial transfer protocol as a single lineage (Figure \ref{fig:anticipation_modes}D). In order to better understand this, we will now look at the intracellular dynamics of WT07, and how it changes when adapting to the protocol. WT07 is one of the more ``clever'' WTs with a relatively complex GRN, and displays strong responses in gene expression when exposed to \DIFdelbegin \DIFdel{``natural'' }\DIFdelend fluctuations. In Figure \ref{fig:anticipation_modes}B we show that WT07 consistently adapts to the protocol by switching between two modes of metabolism, where importer proteins are primed and ready at the beginning of the cycle, and exporter proteins and anabolic enzymes are suppressed during stationary phase. Despite some differences in the \DIFaddbegin \DIFadd{structure of the }\DIFaddend evolved GRNs, the \DIFdelbegin \DIFdel{evolved }\DIFdelend protein allocation patterns are virtually indistinguishable across the three \DIFdelbegin \DIFdel{replicates}\DIFdelend \DIFaddbegin \DIFadd{replicate evolutionary experiments}\DIFaddend . Interestingly, although no parallel changes were observed in the kinetic parameters of proteins, we do observe the parallel loss of a energy-sensing transcription factor as well as increased sensitivity of the TF that senses the external resource C. In other words, \DIFaddbegin \DIFadd{even though all mutations are equally likely, }\DIFaddend evolution apparently happened mostly through loss, and tuning and trimming of the GRN. Modulation between two metabolic modes allows this single lineage to switch between log and stationary phase, occupying both temporal niches. Indeed, a second lineage never appeared for this WT (Figure \ref{fig:anticipation_modes}B and Table S2). 

\DIFaddbegin \subsection*{\DIFadd{Individual and collective solutions can realise the same yield}}

\DIFadd{We have illustrated how all of our evolutionary experiments result in two modes, one with high yield, and another with high growth rates and lower yield. We have also shown how populations could or could not diversify into two strains, and how certain populations used regulated gene expression to adapt to all growth phases by itself. To summarise all these different outcomes, we wondered whether one of the solutions was evidently better than another. In Figure \ref{fig:yield_binned} we show the daily yield of populations with and without gene regulation (left and right panel respectively), with and without the presence of coexisting lineages. For populations with regulated gene expression, the realised yield of both the individual and the collective solutions are identical, and again shows the two previously discussed growth modes. }\DIFaddend Strikingly, \DIFdelbegin \DIFdel{a GRN does not necessarily lead to a single lineage adaptation. For example, another regulating wild type (WT13)repeatedly evolved into multiple coexisting lineages, while maintaining the ability to regulate gene expression. }\textit{\DIFdel{Vice versa}}%DIFAUXCMD
\DIFdel{, }\DIFdelend \DIFaddbegin \DIFadd{although the regulating WTs could fill both temporal niches by themselves, this does not prevent balanced polymorphisms from forming repeatedly. For the }\DIFaddend non-regulating \DIFdelbegin \DIFdel{wild types (WT01 and WT15) also evolved single-lineage anticipation. Hence, even though the GRN of WT07 has a major impact on the repeatability of single-lineage adaptation (as illustrated in Figure \ref{fig:anticipation_modes}B), the presence of a functional GRN is neither sufficient nor necessary for single lineage adaptation}\DIFdelend \DIFaddbegin \DIFadd{populations, we found that the collective solution realises the same levels of daily yield as the regulating populations achieved. However, the individual lineages clearly perform more poorly and rarely achieve the high yield mode, as these populations lack the ability two fill both temporal niches (note that  gene discoveries are disabled during the serial transfer experiment, so gene regulation cannot evolve }\textit{\DIFadd{de novo}}\DIFadd{). This results shows that either a collective solution and/or gene regulation is necessary to be fit in a serial transfer protocol}\DIFaddend . 

\newpage
\section*{Discussion}

In this study we have taken a serendipitous approach to study how  microbes adapt to a serial transfer protocol, and to what extent this is determined by their evolutionary history. The Virtual Microbe modelling framework serves this goal by \DIFdelbegin \DIFdel{not explicitly defining the concept of fitness. Instead, it builds up }\DIFdelend \DIFaddbegin \DIFadd{building }\DIFaddend biology from the bottom up\DIFdelbegin \DIFdel{by }\DIFdelend \DIFaddbegin \DIFadd{, }\textit{\DIFadd{i.e.}} \DIFaddend implementing basic biological features and their interactions. We observe that regardless of their evolutionary history, all WTs learn to anticipate the regularity of the serial transfer protocol by evolving a fine-tuned balance between high growth rate and yield. Long-term survival without food, which is now masked from natural selection, always deteriorates after prolonged exposure to such a protocol. \DIFdelbegin \DIFdel{We next show that, if the same WT is repeatedly evolved in a serial transfer protocol, it has }\DIFdelend \DIFaddbegin \DIFadd{Furthermore, this anticipation is done in two distinct ways. The high yield mode makes sure that the cells are ready to divide as soon as transferred to a fresh medium, whereas the high growth rate mode maximally exploits the medium but results in a poor performance during the stationary phase. We next show that WTs have }\DIFaddend similar trajectories towards a growth versus yield trade-off, but may subsequently diverge along it. Polymorphisms within populations are frequently observed, which can happen by means of cross-feeding interactions, resource specialisation, or \DIFaddbegin \DIFadd{by means of }\DIFaddend growth vs. yield specialisation. We furthermore find \DIFdelbegin \DIFdel{that coexisting lineages }\DIFdelend \DIFaddbegin \DIFadd{these evolved collectives }\DIFaddend are dependent on \DIFdelbegin \DIFdel{each other, as they would }\DIFdelend \DIFaddbegin \DIFadd{one another, as the lineages }\DIFaddend perform better in the presence of the other. \DIFaddbegin \DIFadd{Finally, we show that regulated gene expression allows for an individual lineage to fill both temporal niches by itself, but that populations without regulated gene expression can still be well adapted to the protocol by diverging into two strains. }\DIFaddend In general, our results are robust to details in the serial transfer protocol, such as using only a single resource, or varying the interval between transfers (see Table S2). The anticipation effects therefore appear to be generic features of microbes exposed to prolonged evolution in a serial transfer protocol. \DIFdelbegin \DIFdel{Moreover, the concept of microbial populations anticipating predictable changes has also been observed in previous }\textit{\DIFdel{in silico}}%DIFAUXCMD
\DIFdel{\mbox{%DIFAUXCMD
		\cite{tagkopoulos2008predictive} }\hspace{0pt}%DIFAUXCMD
	and experimental studies\mbox{%DIFAUXCMD
		\cite{wang2015natural}}\hspace{0pt}%DIFAUXCMD
	. Combined with diversification and bet hedging strategies, anticipation might well play an important role in natural populations, the details of which are yet to be elucidated\mbox{%DIFAUXCMD
		\cite{siegal2015shifting}}\hspace{0pt}%DIFAUXCMD
	.}\DIFdelend \\

How do our results map onto experimental evolution in the lab? \textit{E. coli} \DIFdelbegin \DIFdel{Bc251 }\DIFdelend \DIFaddbegin \DIFadd{REL606 }\DIFaddend has been subjected to a daily serial transfer protocol for over 30 years ($\sim$70.000 generations) in the LTEE. Many of our observations are remarkably similar to the LTEE, such as the improved growth rate and cell sizes during the log phase\cite{lenski1994dynamics}, the (quasi-)stable dynamics of coexisting lineages\cite{good2017dynamics}, and ``leapfrogging'' dynamics (\textit{e.g.} Figure \ref{fig:lineages}A-B) where an abundant lineage is overtaken by another lineage before rising to fixation\cite{papadopoulos1999genomic,sniegowskibeneficial}. The comparison with respect to the growth versus yield dynamics and the anticipation effects discussed in this work is however less straightforward. We have observed how all our WTs quickly evolve to be maximally efficient given our artificial chemistry, and only subsequently diverge along the apparent growth versus yield trade-off (see Figure \ref{sfig:trajectories}). For this strain of \textit{E. coli}, growth and yield have continued to improve so far, and although a trade-off has been observed \textit{within} the populations\cite{novak2006experimental}, no growth versus yield trade-off between the replicate populations has been observed yet. \DIFdelbegin \DIFdel{Likewise, our interesting results on the evolution of anticipation could not be corroborated as of yet (T. Hindré and D. Schneider, personal communication, November 2018). }\DIFdelend Nevertheless, we propose that anticipation of periodic environmental change, and a growth versus yield trade-off, provides testable hypotheses for the \DIFdelbegin \DIFdel{future of the LTEE , }\DIFdelend \DIFaddbegin \DIFadd{LTEE }\DIFaddend and similar experimental studies.\\

Cross-feeding interactions are commonly observed in \DIFdelbegin \DIFdel{the LTEE and similar studies \mbox{%DIFAUXCMD
		\cite{turner2015evolution,consuegra2017genetic,consuegra2017genetic,rozen2005long}}\hspace{0pt}%DIFAUXCMD
}\DIFdelend \DIFaddbegin \DIFadd{serial transfer experiments \mbox{%DIFAUXCMD
	\cite{turner2015evolution,consuegra2017genetic,rozen2005long,rozen2009death}}\hspace{0pt}%DIFAUXCMD
}\DIFaddend , and modeling has shown that this adaptive diversification involves character displacement and strong niche construction\cite{grosskopf2016metabolic}, and can furthermore strongly depend on the regularity of a serial transfer protocol \cite{rocabert2017beware}. \DIFdelbegin \DIFdel{While }\DIFdelend \DIFaddbegin \DIFadd{Although }\DIFaddend similar cross-feeding interactions are observed in some of our \textit{in silico} experiments, we also found balanced polymorphisms involving one lineage with high growth rates during log phase and a slower growing lineage which performs better in stationary phase. \DIFdelbegin \DIFdel{This can happen by means of resource specialisation, or purely on the basis of a growth versus yield specialisation which does not require cross-feeding or cannibalism. While the resource specialisation is only relevant to experimental studies that use more than one carbon source, the growth versus yield diversification also happens on a single resource (Table S2). Indeed, other studies have also suggested the importance of these dynamics, such as the }\DIFdelend \DIFaddbegin \DIFadd{Ideed, the }\DIFaddend coexistence of respiratory and fermenting strains in \textit{Saccharomyces cerevisiae} \DIFdelbegin \DIFdel{\mbox{%DIFAUXCMD
	\cite{wortel2016evolutionary} }\hspace{0pt}%DIFAUXCMD
in a }\DIFdelend \DIFaddbegin \DIFadd{has also been observed \mbox{%DIFAUXCMD
	\cite{wortel2016evolutionary} }\hspace{0pt}%DIFAUXCMD
in }\DIFaddend chemostat, and \DIFdelbegin \DIFdel{the presence of multiple selection pressures in a mathematical model of }\DIFdelend \DIFaddbegin \DIFadd{single nucleotide mapping has furthermore revealed the existence of this trade-off \mbox{%DIFAUXCMD
	\cite{li2019single}}\hspace{0pt}%DIFAUXCMD
. These results are directly related to r/K selection theory \mbox{%DIFAUXCMD
	\cite{pianka1970r}}\hspace{0pt}%DIFAUXCMD
, which describes an inherent conflict between the quantity and quality of ones offspring. Indeed, these dynamics have been shown to lead to two species stably coexisting in microbial populations \mbox{%DIFAUXCMD
	\cite{turner1996tests,smith2011bacterial,manhart2018trade}}\hspace{0pt}%DIFAUXCMD
. Manhart }\textit{\DIFadd{et. al,}} \DIFadd{2018 furthermore show that an unlimited number of species can theoretically coexist within }\DIFaddend a serial transfer protocol\DIFdelbegin \DIFdel{\mbox{%DIFAUXCMD
	\cite{manhart2018growth}}\hspace{0pt}%DIFAUXCMD
. Our findings }\DIFdelend \DIFaddbegin \DIFadd{, occupying any niche on a trade-off continuum. Here we }\DIFaddend show that these dynamics can emerge \DIFdelbegin \DIFdel{in }\DIFdelend \DIFaddbegin \DIFadd{from }\DIFaddend a more complex eco-evolutionary setting. \DIFdelbegin \DIFdel{It however remains to be seen if such diversification happens in experiments such as the LTEE. Earlier work on the LTEE has shown that, although no significant negative correlation was found for an evolutionary }\DIFdelend \DIFaddbegin \DIFadd{However, our results suggest that the }\DIFaddend trade-off \DIFdelbegin \DIFdel{of }\DIFdelend \DIFaddbegin \DIFadd{between }\DIFaddend growth and yield \DIFdelbegin \DIFdel{, isolated clones from }\emph{\DIFdel{within}} %DIFAUXCMD
\DIFdel{a population do display a negative correlation \mbox{%DIFAUXCMD
		\cite{novak2006experimental}}\hspace{0pt}%DIFAUXCMD
	, suggestive for the dynamics we observed in Virtual Microbes.With a great deal of polymorphisms in the LTEE left unexplained so far\mbox{%DIFAUXCMD
		\cite{good2017dynamics}}\hspace{0pt}%DIFAUXCMD
	, we thus suggest this as a search image for future evolutionary experiments}\DIFdelend \DIFaddbegin \DIFadd{is not continuous, as intermediate solutions rarely evolve. This is caused by the fact that as soon as the volume-at-transfer for our digital microbes is smaller than the division volume (i.o.w. something else than the main nutrient becomes limiting for division), a cell may as well exploit its resources fully}\DIFaddend . \\

\DIFdelbegin \DIFdel{Much to our surprise, we failed to observe any consistent difference between the WTs that had evolved regulated gene expression before the onset of the serial transfer protocol, and those that did not. Even though we observed that gene regulation was often tuned to anticipate the serial transfer protocol }\DIFdelend %DIF > Furthermore, despite the inherent complexity of the simulations, there are also many features \textit{not} included in our model (gene expression noise, translation machinery, phage predation, \textit{etc.}). Thus, our data  illustrates which mechanisms are \textit{not} required (but might still be important) for the observed phenomena in serial transfer experiments. 
\DIFaddbegin 

%DIF > This can happen by means of resource specialisation, or purely on the basis of a growth versus yield specialisation which does not require cross-feeding or cannibalism\cite{rozen2009death}. While the resource specialisation is only relevant to experimental studies that use more than one carbon source, the growth versus yield diversification also happens on a single resource (Table S2). Earlier work on the LTEE has shown that, although no significant negative correlation was found for an evolutionary trade-off of growth and yield, isolated clones from \emph{within} a population do display a negative correlation \cite{novak2006experimental}, suggestive for the dynamics we observed in Virtual Microbes. With a great deal of polymorphisms in the LTEE left unexplained so far\cite{good2017dynamics}, we thus suggest this as a search image for future evolutionary experiments. \\
\DIFadd{Experimental evolution of microbes has shown that different evolutionary paths can lead to the same phenotypic adaptations in a new environment \mbox{%DIFAUXCMD
		\cite{lind2015experimental}}\hspace{0pt}%DIFAUXCMD
	. On the other hand, many studies have also suggested that adaptation can often entail mutations in the same genes \mbox{%DIFAUXCMD
		\citep{ratcliff2015origins,damkiaer2013evolutionary}}\hspace{0pt}%DIFAUXCMD
	. Indeed, remodelling of the GRN as a means to adapt has been well-studied \mbox{%DIFAUXCMD
		\cite{pelosi2006parallel,wagner2011molecular}}\hspace{0pt}%DIFAUXCMD
	, and can enhance the evolvability of a species \mbox{%DIFAUXCMD
		\citep{crombach2008evolution,raman2011evolvability}}\hspace{0pt}%DIFAUXCMD
	. While WT\#07 }\DIFaddend (Figure \ref{fig:anticipation_modes}\DIFdelbegin \DIFdel{), this solution did not appear to be any more productive than solutions that used no gene regulatory mechanisms}\DIFdelend \DIFaddbegin \DIFadd{B) clearly show similar changes in how the GRN might infer similar changes in phenotypes, other WTs showed much less predictability. For example, another initially strong regulating WT (\#09) had no clear parallel changes on the genotype, losing the ability to regulate in once case, and adapting to the protocol as an individual and a collective in the other two cases. In other words, while the GRN appears to add knobs and buttons for evolution to push \mbox{%DIFAUXCMD
		\cite{hindre2012new}}\hspace{0pt}%DIFAUXCMD
	, other mechanisms are clearly available to adapt and be fit in a serial transfer protocol. }\\ 

\DIFadd{Recent work shown that adding enzyme kinetics to models of metabolic fluxes leads to much more metabolic robustness without leading to a loss in adaptive degrees of freedom \mbox{%DIFAUXCMD
		\cite{millard2017metabolic}}\hspace{0pt}%DIFAUXCMD
}\DIFaddend . Because all the kinetic parameters of enzymes (K$_m$, V$_{max}$, etc.) in the Virtual Microbes are freely evolvable, it is \DIFdelbegin \DIFdel{possible }\DIFdelend \DIFaddbegin \DIFadd{likely }\DIFaddend that metabolic regulation of homeostasis plays a very important role in Virtual Microbes, \DIFdelbegin \DIFdel{and can in many ways be just as ``good'' as a functional gene regulatory network. Furthermore, we noticed that}\DIFdelend \DIFaddbegin \DIFadd{which could explain why the differences in evolvability between regulating and non-regulating populations were smaller than we initially expected. We indeed observed that, }\DIFaddend for certain WTs, a change in metabolism could bypass \DIFaddbegin \DIFadd{regulated }\DIFaddend protein expression by means of kinetic neofunctionalistaion of \DIFdelbegin \DIFdel{paralogous genes}\DIFdelend \DIFaddbegin \DIFadd{importer proteins, that evolved to be sensitive to different concentrations}\DIFaddend . Although such a solution does waste more building blocks on the continuous production of \DIFdelbegin \DIFdel{protein}\DIFdelend \DIFaddbegin \DIFadd{importer proteins}\DIFaddend , it is also much more responsive to environmental changes. \DIFdelbegin \DIFdel{Indeed, recent work has shown that adding enzyme kinetics to models of metabolic fluxes leads to much more robustness without leading to a loss in adaptive degrees of freedom \mbox{%DIFAUXCMD
	\cite{millard2017metabolic}}\hspace{0pt}%DIFAUXCMD
. However, the LTEE has revealed many changes in the GRN \mbox{%DIFAUXCMD
	\cite{pelosi2006parallel} }\hspace{0pt}%DIFAUXCMD
and global transcription profiles. Thus, the GRN appears to add knobs and buttons for evolution to push \mbox{%DIFAUXCMD
	\cite{hindre2012new}}\hspace{0pt}%DIFAUXCMD
, but it does not change what is actually being selected for: anticipating the serial transfer protocol. }\DIFdelend \DIFaddbegin \DIFadd{All in all, it is possible that subtle differences like this explain, for example, why two of our WTs were sensitive to over-exploiting the medium. Furthermore, although the phenotypes that are reachable can be limited by prior evolution \mbox{%DIFAUXCMD
	\cite{blount2012genomic}}\hspace{0pt}%DIFAUXCMD
, the trajectories of evolution may be much less predictable on the long-term \mbox{%DIFAUXCMD
	\cite{bajic2018deformability}}\hspace{0pt}%DIFAUXCMD
. The role of metabolic regulation, and how this interplays with the repeatability and timescales of evolution, is a promising endeavour for future studies. 
}\DIFaddend 

\DIFaddbegin \subsection*{\DIFadd{Who is anticipating what?}}
\DIFadd{The concept of microbial populations anticipating predictable changes is frequently observed in nature \mbox{%DIFAUXCMD
		\cite{mitchell2009adaptive,wang2015natural,mitchell2009adaptive}}\hspace{0pt}%DIFAUXCMD
	, and is supported by theoretical models \mbox{%DIFAUXCMD
		\cite{mitchell2011mathematical,tagkopoulos2008predictive}}\hspace{0pt}%DIFAUXCMD
	. This form of anticipation is typically with respect to environmental cues, where an unrelated signal is used to anticipate environmental changes that frequently follow, and usually entails individuals taking some form of action, such as up- or down-regulation of genes in order to prepare for the changes to come. Although we here show a more passive form of anticipation, where not the individuals, but the populations of microbes have evolved to `trust' in the regularity of environmental changes, this does not necessarily exclude individual-based anticipation. Like WT\#07, most of the evolved regulating populations actually did not evolve to down-regulate their resource importers during the stationary phase, despite having repeatedly evolved to down-regulate other catabolic and anabolic enzymes (illustrated in Figure \ref{fig:anticipation_modes}B)). Since no more resource is available, and building blocks are consumed in order to keep expressing these importer proteins, this might well have a negative impact on the individual cells during the late stationary phase. One can wonder why these populations do not evolve to suppress these importers, but instead seem to keep the engine running. Just like bet-hedging strategies \mbox{%DIFAUXCMD
		\cite{veening2008bet,balaban2004bacterial,solopova2014bet,veening2008bistability,siegal2015shifting,new2014different}}\hspace{0pt}%DIFAUXCMD
	, this passive form of anticipation might play an important role in microbial evolution, and could potentially be the first step towards active anticipation by means of a circadean rhythm, such as the sunflower heliotropism \mbox{%DIFAUXCMD
		\cite{atamian2016circadian} }\hspace{0pt}%DIFAUXCMD
	and the diurnal migration of life in lakes and oceans \mbox{%DIFAUXCMD
		\cite{luellmovements,consalvey2004ups,gaten2008vertical}}\hspace{0pt}%DIFAUXCMD
	. 
}

\DIFaddend \subsection*{Moving towards an eco-evolutionary understanding}
The dynamics of Virtual Microbes expose that even a simple serial transfer protocol entails much more than sequentially evolving faster and faster growth rates. Instead, adaptation is an eco-evolutionary process that strongly depends on prior evolution, timescales, the presence of other competitors and mutants, and transient fitness effects. \DIFdelbegin \DIFdel{In accordance with these dynamics, temporal positive selection for certain alleles can be inferred from a metagenomics study on the LTEE\mbox{%DIFAUXCMD
		\cite{good2017dynamics}}\hspace{0pt}%DIFAUXCMD
	. 
	Strikingly, although competition experiments }\DIFdelend \DIFaddbegin \DIFadd{Although we found that competition experiments generally }\DIFaddend favoured the evolved population over the ancestral WTs\DIFdelbegin \DIFdel{in almost all cases}\DIFdelend , there were exceptions to this rule. It is \DIFdelbegin \DIFdel{therefor }\DIFdelend \DIFaddbegin \DIFadd{therefore }\DIFaddend possible that the ancestral WTs perform better in such an experiment, but that this does not describe \DIFdelbegin \DIFdel{a }\DIFdelend \DIFaddbegin \DIFadd{the }\DIFaddend stable eco-evolutionary attractor. Indeed, survival of the fittest is an eco-evolutionary process where \DIFdelbegin \DIFdel{a lineage interact }\DIFdelend \DIFaddbegin \DIFadd{any emerging lineage interacts }\DIFaddend with other lineages \DIFdelbegin \DIFdel{, or with mutants, }\DIFdelend \DIFaddbegin \DIFadd{(or with other mutants) }\DIFaddend through changes in the environment\DIFdelbegin \DIFdel{. In the LTEE}\DIFdelend \DIFaddbegin \DIFadd{, often resulting in a collective, community-based solution rather than the winner of all pair-wise interactions \mbox{%DIFAUXCMD
		\cite{manhart2018growth}}\hspace{0pt}%DIFAUXCMD
	. Furthermore}\DIFaddend , faster growth \DIFdelbegin \DIFdel{might become }\DIFdelend \DIFaddbegin \DIFadd{becomes }\DIFaddend less and less important as \DIFdelbegin \DIFdel{the years pass}\DIFdelend \DIFaddbegin \DIFadd{populations become better adapted to the serial transfer protocol}\DIFaddend , perhaps making the aforementioned interactions between lineages increasingly relevant. Other recent studies have recently elucidated the importance of eco-evolutionary dynamics\DIFdelbegin \DIFdel{\mbox{%DIFAUXCMD
		\cite{govaert2018eco}}\hspace{0pt}%DIFAUXCMD
}\DIFdelend \DIFaddbegin \DIFadd{\mbox{%DIFAUXCMD
	\cite{govaert2018eco,manhart2018growth}}\hspace{0pt}%DIFAUXCMD
}\DIFaddend , and how this can readily give rise to coexistence of multiple strains which could not have formed from a classical adaptive dynamics perspective\cite{vetsigian2017diverse,kotil2018emergence}. Indeed, metagenomics have revealed much more diversity in the LTEE than previously anticipated\cite{good2017dynamics}. Shifting focus from competition experiments towards the ever-changing selection pressures that emerge from the eco-evolutionary dynamics and interactions, will make the field of experimental evolution harder, but more intriguing, to study. 


\section*{Conclusions}
We have studied how \textit{in silico} WTs of Virtual Microbes adapt to a serial transfer protocol like that of the LTEE. \DIFdelbegin \DIFdel{While the }\DIFdelend \DIFaddbegin \DIFadd{The }\DIFaddend LTEE has shown a sustained increase in competitive fitness, and intensive research displays how the evolved clones are still improving \DIFaddbegin \DIFadd{their growth rates }\DIFaddend with respect to their ancestor \DIFdelbegin \DIFdel{up until today \mbox{%DIFAUXCMD
		\cite{wiser2015comparison,wiser2013long,lenski2015sustained}}\hspace{0pt}%DIFAUXCMD
	. It is however still unclear what the actual selection pressures are which are at stake. }\DIFdelend \DIFaddbegin \DIFadd{as to this day \mbox{%DIFAUXCMD
		\cite{wiser2015comparison,wiser2013long,lenski2015sustained}}\hspace{0pt}%DIFAUXCMD
	. }\DIFaddend Our experiments have generated a novel hypothesis that \DIFdelbegin \DIFdel{what is being selected for is not necessarily high, but balanced growth, which happens with a great variety of underlying mechanisms. A fine-tuned balance between growth and yield causes an accurate anticipation of the }\DIFdelend \DIFaddbegin \DIFadd{microbes in a }\DIFaddend serial transfer protocol \DIFaddbegin \DIFadd{will eventually evolve to anticipate the regular resource interval, and can do so by evolving either a high growth rate mode, or a high yield mode. Both these modes can be achieved by a single individual lineage}\DIFaddend , \DIFdelbegin \DIFdel{which happen by ``clever'' single lineages, }\DIFdelend or by \DIFdelbegin \DIFdel{multiple lineages that arise on the basis of the growth versus yield trade-off}\DIFdelend \DIFaddbegin \DIFadd{a collective of two strains which both have their own temporal niche}\DIFaddend . Taken together, our results reveal important insights into the dynamics and relevant selection pressures in experimental evolution, advancing our understanding of the eco-evolutionary dynamics of microbes. 

\section*{List of abbreviations}
\begin{itemize}
	\item LTEE: Long Term Evolution Experiment (first published by R Lenski, 1991)
	\item WT: wild type (plural: WTs)
	\item TF: Transcription Factor (plural: TFs)
	\item GRN: Gene Regulatory Network (plural: GRNs)
\end{itemize}
\clearpage

%%%%%%%%% METHODS %%%%%%%%%
\section*{Methods}
\vspace{2mm}
\parbox{12.5cm}{
	A full description of the model and underlying equations is available online (\url{bitbucket.org/thocu/virtual-microbes} and \url{https://virtualmicrobes.readthedocs.io}). Here we summarize the sections of these documents that are relevant to this study. 
}

\subsection*{Finding generic patterns of evolution}
Experimental evolution is, of course, done on organisms that have evolved for a long time under a wide variety of conditions. These studied organisms all have their own evolutionary history, and differences in how they deal with starvation, stress, changes in resource etc. With Virtual Microbes we are able to evolve a \textit{de novo} set of ``wild types'' (WTs), adapted to live in such severely fluctuating resource conditions. We can then explore how these WTs adapt to experimental evolution, and find generic patterns of evolution. To find generic patterns without being biased towards specific solutions, the biology of Virtual Microbes build-up from many levels with many degrees of freedom. One downside of this strategy can be that \DIFdelbegin \DIFdel{every simulation (like biological evolution itself) results }\DIFdelend \DIFaddbegin \DIFadd{it can be hard for readers to understand all the underlying assumptions and algorithm and that many simulations result }\DIFaddend in a slightly different anecdote. However, \DIFdelbegin \DIFdel{once we find a result repeatedly across a series of simulated experiments, we can have more confidence in that the observed pattern is truly a }\emph{\DIFdel{generic pattern}} %DIFAUXCMD
\DIFdel{and readily accessible by evolution}\DIFdelend \DIFaddbegin \DIFadd{we encourage the reader to read this work as though reading about `real' biological evolution, where the experiments reveal new generic patterns and generate new hypotheses}\DIFaddend . With or without \DIFdelbegin \DIFdel{and }\DIFdelend \DIFaddbegin \DIFadd{an }\DIFaddend understanding of the mechanistic details, relatively simple multilevel models can capture the eco-evolutionary dynamics of microbes, allowing us to study what happens, what else emerges from these dynamics ``for free'', and equally important: what needs further explanation?

\smallskip



%In our protocol to evolve WTs of Virtual Microbes, we generate unpredictable environmental conditions while at the same time keeping track of all these changes. We can accurately observe how these changes influence the internal dynamics of the cells, which would of course be very impracticable and expensive in a wet-lab experiment. By studying who survives, and tracing back who the ancestors of those cells are, the model generates a perfect ``fossil record'' ranging from the very first cells to evolved Virtual Microbe wildtypes (WTs), all of which can be further experimented on. Here we focus on what one might expect when WT micro-organisms adapt to the serial transfer protocol like the LTEE, and to what extend prior adaptations influence subsequent evolution.\par


\subsection*{Model overview}
Virtual Microbes metabolise, grow and divide on a spatial grid (Figure \ref{fig:overview}C). Here, we use two parallel 40x40 grids with wrapped boundary conditions. One grid contains the Virtual Microbes and empty grid-points, and the other describes the local environment in which the Virtual Microbes live. This environmental layer holds influxed metabolites, waste products of Virtual Microbes, and spilled metabolites from lysing cells (Figure \ref{fig:overview}B). In order to express proteins, grow, and maintain their cell size, Virtual Microbes must synthesize predefined metabolite(s), which we call building blocks. These building blocks are not directly provided, but must be synthesized by the Virtual Microbes by expressing the right proteins, allowing them to pump \DIFdelbegin \DIFdel{/ }\DIFdelend \DIFaddbegin \DIFadd{metabolites into the cell, and }\DIFaddend convert metabolites into one another (Figure \ref{fig:overview}A). The expression of these proteins depends on genes on genomes that undergo a wide variety of possible mutations upon reproduction (Table \ref{tab:muts}). Genomes are circular lists of genes, each with their own unique properties (\textit{e.g.} K$_m$, V$_{max}$ for enzymes, K$_{ligand}$ and binding motif for TFs). The level of expression is unique for each gene, and is determined by its evolvable basal transcription rate and how this rate is modulated by transcription factors. When an enzyme or transporter gene is expressed, that specific reaction will take place within the cell that carries that gene. Note however that in the complete metabolic universe, many more possible reactions exist. The genome of an evolved Virtual Microbes will typically only use a subset of all the possible reactions. \DIFdelbegin \DIFdel{Proteins }\DIFdelend \DIFaddbegin \DIFadd{Genes }\DIFaddend to catalyse new reactions and novel TFs can be discovered through rare events. \DIFdelbegin %DIFDELCMD < \smallskip
%DIFDELCMD < 

%DIFDELCMD < %%%
\DIFdel{Note that unlike most evolutionary models, fitness is not explicitly defined. Both the rate of }\DIFdelend \DIFaddbegin \DIFadd{Which genes end up being selected for is not explicitely defined, but the result of a }\DIFaddend birth and death \DIFdelbegin \DIFdel{are dynamically defined, and evolvable properties for Virtual Microbes}\DIFdelend \DIFaddbegin \DIFadd{process}\DIFaddend . Birth depends on the availability of empty space and resources to synthesize \DIFaddbegin \DIFadd{new }\DIFaddend building blocks, whereas death depends on the ability to survive under a variety of different conditions and the potential accumulation (and avoidance) of toxicity. The resulting survival of the fittest (referred to as ``competitive fitness'' by Fragata \textit{et al}., 2018) is an emergent phenomenon of eco-evolutionary dynamics\cite{fragata2018evolution}.

\DIFaddbegin \smallskip


\DIFaddend \begin{table}
	\caption{Types of mutations and their probabilities in WT evolution and serial transfer protocol (STP)}
	\resizebox{\linewidth}{!}{%
		%\rowcolors{2}{gray!25}{white}
		\footnotesize
		\begin{tabularx}{\textwidth}{p{2.7cm} p{5cm} p{1.5cm} p{1.5cm}}
			%\rowcolor{gray!50}
			\hline  \noalign{\smallskip}
			\textbf{Mutation}  & \textbf{Description} & \textbf{Prob (WT evolution)} & \textbf{Prob (STP)} \\
			\noalign{\smallskip} \hline  \noalign{\smallskip}
			Duplication & A stretch of 1 or more genes is duplicated in tandem & 0.005 & 0.0015 \\
			Deletion & A stretch of 1 or more genes is deleted & 0.005 & 0.0015\\
			Inversion & A stretch of 1 or more genes is inverted in order & 0.005& 0.0015\\
			Translocation & A stretch of 1 or more genes is moved to a random location & 0.005& 0.0015\\
			(stretch length) & Geometricly distributed with p = 0.3 & - & -  \\
			Gene discovery & Per time-step probability of discovering a new (randomly parameterised) gene. & 0.0002 & (disabled)\\    
			HGT & Per time-step probability of copying a gene from a cell closeby& 0.002 & (disabled)\\
			Point mutation & Per gene per generation probability of modifying a single parameter of a gene (promoter strength, Michaelis Menten constants) & 0.005 & 0.0015\\
			Regulatory mutation & Per gene per generation probability of (partially) modifying the upstream binary operator sequence of a gene & 0.005 & 0.0015\\
			\noalign{\smallskip}
			\hline
		\end{tabularx}
	}
	\DIFdelbeginFL %DIFDELCMD < \smallskip
	%DIFDELCMD < 	\smallskip
	%DIFDELCMD < 	%%%
	\DIFdelendFL 
	
	\label{tab:muts}
\end{table}

%table gene mutations

\begin{table}
	\caption{Gene level mutations and the boundary conditions}
	\resizebox{\linewidth}{!}{%
		
		\footnotesize
		
		\begin{tabularx}{\textwidth}{p{3.4cm} p{5cm} p{5cm}}
			\hline
			\noalign{\smallskip}
			\textbf{Parameter} & \textbf{Gene Types} & \textbf{Value range in simulation}\\ 
			\noalign{\smallskip}  \hline  \noalign{\smallskip}
			
			Promoter Strength   & Enzyme, Transporter, TF                            & $[0.001,10]$ \\
			$K_{substrate}$   & Enzyme, Transporter                                & $[0.001,10]$      \\
			$K_{energy}$       & Transporter                                        & $[0.001,10]$             \\
			$K_{ligand}$       & TF                                                 & $[0.001,10]$             \\
			$K_{operator}$     & TF                                                 & $[0.001,10]$             \\
			$V_{max}$               & Enzyme, Transporter                                & $[0.001,10]$             \\
			effect-bound        & TF                                                 & $[0.001,10]$             \\
			effect-apo          & TF                                                 & $[0.001,10]$             \\
			ligand              & TF                                                 & A, B, C, or e   \\
			exporting           & Transporter                                        & True,False            \\
			sense-external      & TF                                                 & [True,False]            \\
			binding-motif       & TF                                                 & bit flip at random position \\
			operator-sequence   & Enzyme, Transporter, TF                            & bit flip at random position \\
			\noalign{\smallskip}  \hline  \noalign{\smallskip}
		\end{tabularx}
	}
	
	
	\label{tab:geneMuts}
\end{table}


\begin{table}
	\caption{Grid setup and environmental forcing in WT evolution and serial transfer protocol (STP)}
	\footnotesize
	\resizebox{\linewidth}{!}{%
		
		\label{tab:force}
		\begin{tabularx}{\textwidth}{p{2.8cm} p{7cm} p{3cm}}
			\hline
			\textbf{Option (WT evolution)}  & \textbf{Description} & \textbf{Value or range}\\
			\hline
			Maximum population size & As defined by the size of the grid (40x40) & 4900  \\  
			Sub-grids  & The grid is sub-divided into n grids where fluctuations are independent & 4 \\
			Fluctuation frequency & Probability (per time step) of 1 metabolite (A or C) changes in influx in one of the sub-grids & 0.01 \\
			Fluctuation range & New influx of metabolite is sampled uniformly from range & [10e-5, 10e-1] \\
			Extracellular metabolite outflux  & Rate at which metabolites outside of cells wash out & 0.01\\
			
			
		\end{tabularx}
	}
	\resizebox{\linewidth}{!}{%
		\begin{tabularx}{\textwidth}{p{2.8cm} p{7cm} p{3cm}}
			\hline
			\textbf{Option (serial transfer protocol)}  & \textbf{Description} & \textbf{Value}\\
			\hline
			Maximum population size & As defined by the size of the grid (70x70) & 4900  \\    
			Number of cells serially transferred & A (near) tenfold dilution of cells & 500\\
			
			Time steps of cycle  & This represents, for example, the`` 24 hour'' serial transfer protocol of the LTEE & 50 (AUT)\\
			$[$A$]$ at beginning of cycle & Amount of resource A given at the beginning of the cycle&1.25\\
			$[$C$]$ at beginning of cycle & Am mount of resource C given at the beginning of the cycle&1.25\\
			Extracellular metabolite outflux  & Assuming metabolites can no longer wash out of the system & 0.0\\
			
			\hline
		\end{tabularx}
	}
\end{table}

% simulate fluctuations in resource availability. We here simulate differences in resource availability and address the question whether Virtual Microbes will evolve a GRN to regulate their gene expression levels in accordance to the quality of environmental conditions. We next go on to question how these GRNs influence adaption to a much more constant environment, by mimicking the LTEE experiment. Ideally, the evolution of complex Virtual Microbes can enhance our understanding on the complexity of real microbes, and the evolution thereof.





%\paragraph{Metabolic universe}
%In this study, the total set of possible reactions (the ``metabolic universe'') consists of a simple system with 2 resource metabolites, 1 building block metabolite, and an energy carrier (figure \ref{universe}A). Although only 6 possible reactions exists to convert metabolites into one another, the kinetic parameters for the enzymes for these reactions are not predefined. The same is true for the 6 possible transporter proteins, which can freely evolve its maximum rate (V$_{max}$) or the binding affinities to the substrate or the energy metabolite (K$_{e}$ and K$_{s}$). \bigskip
% \paragraph{Evolving Virtual Microbe ``wildtypes''}
%We initialised 16 minimally viable Virtual Microbes, and evolved them for $\sim$10.000-15.000 generations in fluctuating resource conditions by applying random changes in the influx rates for both resources. Because the rate of influx for the two resource metabolites fluctuates between very high ($10^{-1}$) and very low values ($10^{-4}$), conditions can be very poor, very rich, and/or potentially toxic. Since this might cause the whole population of Virtual Microbes to go extinct, we subdivided the grid into 4 subspaces with independently fluctuating resource conditions (see Figure \ref{universe}B). Note however that these subspaces do not impede diffusion and reproduction, but merely define the rate at which resources flux into different positions on the grid. These conditions aim to simulate natural resource fluctuations, evolving what we call ``wildtype'' Virtual Microbes henceforth. We define the wildtypes as the 20 most recent ancestors of each evolved population, \textit{i.e.} all individuals are decedent from these 20 cells. (see supplement S1 for more details)

%\paragraph{LOD analysis}
%The Virtual Microbes does not only store all living individuals, but furthermore keeps track of an accurate phylogeny. By keeping track of all parent-child relationships the model can generate a non-broken line of descent (LOD) ranging from the very first cell to the evolved WTs. This includes all protein concentrations, cell volumes, toxicity values etc. In short, with the help of this tool we can get a grip on why certain mutations were adaptive, and allows us to do experiments such as competition in co-culture.\\
%In this report, we take 20 maximally distant leaves from the phylogenetic tree to represent the genetic makeup of our wildtypes.



%\paragraph{Differential regulation score}
%As an approximation of differential regulation, we implemented a ``differential regulation score'' (or r-score for short) that captures differences in protein expression patterns between clonal individuals. For this, we sampled n cells in the k most abundant clones in the population and calculated the average of an all-against-all distance metric (d) based on the protein allocation.\\ 
%
%\begin{equation}
%\label{eqaaa}
%Rscore =  \frac{1}{k}\sum_{i=1}^k r_{i}
%\end{equation}%
%
%\begin{equation}
%\label{eqaaa}
%r_{i} = \frac{ \sum_{i=1}^n \sum_{j=i+1}^n d(Xi,Xj)}{\frac{1}{2}n(n-1)}
%\end{equation}
%
%The distance metric d is calculated from differences in protein allocation. The intercellular concentrations for all p proteins in the genome is divided by the total protein expression in this cell ($e_{sum}$), yielding a relative expression vector ($\vec{e}$) with length p (see \ref{vector}):\\

%\rowcolors{10}{white!0}{white!0}
%
%\begin{equation}
%\label{vector}
%\vec{e}= 
%\begin{pmatrix} e_1 / e_{sum}\\
% e_2 / e_{sum}\\
% \vdots\\
% e_p / e_{sum}
%\end{pmatrix}
%\end{equation}
%
%Finally, the distance between two cells i and j is the average point-wise distance between $\vec{e_i}$ and $\vec{e_j}$. (equation \ref{distance}):
%\begin{equation}
%\label{distance}
%d(Xi,Xj) = \frac{1}{p}\cdot\sum_{q=1}^p \Bigg ( \Big |\vec{e_i}-\vec{e_j}  \Big | \Bigg )
%\end{equation} 
%


%\begin{center}
%k = number of most abundant clones sampled (10)\\
%n = number of cells in clone\\
%p = number of proteins expressed by genome\\
%$\vec{e_{i}}$ = vector of cellular concentration of proteins\\
%$\vec{e_{i}}$ = vector of cellular concentration of proteins\\

%\end{center}
%artificial biochemistry
\paragraph*{Metabolic universe} The metabolic universe in Virtual Microbes is an automatically generated (or user defined) set of metabolites and reactions between them. The simple metabolic universe used in this study was automatically generated by a simple algorithm that defines 4 classes of molecules, how \DIFdelbegin \DIFdel{then }\DIFdelend \DIFaddbegin \DIFadd{they }\DIFaddend can be converted into one another by means of 6 reactions, how fast they degrade, diffuse over the membranes, \textit{etc.} (see Table \ref{tab:uni}).\DIFdelbegin %DIFDELCMD < \bigskip
%DIFDELCMD < %%%
\DIFdelend \DIFaddbegin \\
\DIFaddend 

\begin{table}
	%\rowcolors{2}{gray!25}{white}
	\footnotesize
	\caption{A priori defined metabolites and reactions in artificial chemistry}
	\label{tab:uni}
	\begin{tabularx}{\textwidth}{X X X X X X}
		\hline
		\textbf{Metabolite}  & \textbf{Mass}& \textbf{Class} & \textbf{Degradation rate} & \textbf{Diffusion rate }& \textbf{Toxicity level } \\
		\hline
		A &4& Resource &  0.01 & 0.02& 0.2 \\
		B &5& Building block & 0.1 &  0.0015& 0.2 \\
		C &6& Resource& 0.01&  0.015& 0.2 \\
		e &1& Energy carrier  & 0.5&  0.0015& 0.2 \\
		\hline
	\end{tabularx}
	
	\begin{tabularx}{\textwidth}{X}
		
		\textbf{Potential reactions (6)} \\
		\hline
	\end{tabularx}
	
	
	\begin{tabularx}{\textwidth}{X X X X X X}
		1C $\rightarrow$ 1B + 1e & 1C $\rightarrow$ 1A + 2e & 1A + 1B $\rightarrow$ 1C & 2A $\rightarrow$ 1C & 2A $\rightarrow$ 1B & 1B $\rightarrow$ 1A + 1D\\
		\hline
	\end{tabularx}
	
\end{table}
\bigskip
The metabolism is simulated on the grid in terms of Ordinary Differential Equations (ODEs) using the Gnu Scientific Library in Cython. These ODEs include the influx of molecules into the system, \DIFdelbegin \DIFdel{diffusion between grid points, }\DIFdelend transport or diffusion across the membrane, intracellular metabolism (including expression and decay of proteins), biomass production, cell volume, \DIFaddbegin \DIFadd{the build-up of toxicity, }\DIFaddend \emph{etc.}. \DIFdelbegin \DIFdel{Due to computational efficiency, the }\DIFdelend \DIFaddbegin \DIFadd{Diffusion between grid points was implemented as a simple local diffusion process, and is interleaved with the ODEs for efficiency. The }\DIFaddend number of simulations was limited to 16 WTs and 16x3 ``lab'' experiments \DIFaddbegin \DIFadd{due to computational feasibility}\DIFaddend . 

% transport
\paragraph*{Transmembrane transport}
For all molecules, transporters exist that import or export molecules across the cell membrane. Michaelis-Menten kinetics determine the transmembrane transportation with rate $v$ :
$$
v = \mathit{v_{{max}_{\mathcal{T}}}}  \cdot [\mathcal{T}] \cdot \frac{[S] \cdot [e] }{([S] + K_S) \cdot ([e] + K_e) } 
$$
where $\mathcal{[T]}$ is the concentration of the transporter protein, $[S]$ is the concentration of substrate transported, and $[e]$ is the concentration of available energy carrier metabolites. $K_S$ and $K_E$ are the Michaelis-Menten constants for the substrate and energy carrier respectfully. Depending on the direction of transport (importing or exporting) $[S]$ is either the external or the internal concentration of the substrate. Note that for any gene on the genome of a Virtual Microbe, $V_{max\mathcal{T}}$, $K_S$ and $K_E$ are all freely evolvable parameters. 

%metabolism
\paragraph*{Metabolism}
Similar to the transport, metabolic rates are catalysed by proteins by Michaelis-Menten kinetics with rate $v$:
$$
v = \mathit{v_{{max}_\mathcal{E}}} \cdot [\mathcal{E}] \cdot\frac{\prod_{R\in \mathcal{R}} [R] }{\prod_{R\in \mathcal{R}} ([R] + K_{R}) }  
$$
where [$\mathcal{E}$] is the concentration of the enzyme catalysing the reaction, $\mathcal{R}$ the set of all reactant metabolites, and $K_{R}$ and $v_{{max}_\mathcal{E}}$ are evolvable kinetic parameters of enzyme $\mathcal{E}$. 

% production
\paragraph*{Biomass production}
Virtual microbes convert building block \emph{B} to a biomass product $P$, which is consumed for cell growth and maintenance $Growth(B)$ and protein production $Prod(B)$, and determines strength with which individuals compete to reproduce. Biomass is next converted to cell volume with a fixed rate, and used for protein expression depending on the demands by the evolved genome.  In other words, high rates of expression demand more biomass product for proteins, leaving less biomass product to invest in cell volume or maintainance (see cell volume growth). In total, the rate of change of $P$ then becomes

$$\frac{dP}{dt} = Production(B) - Growth(B) - \DIFdelbegin \DIFdel{Protein-expression}\DIFdelend \DIFaddbegin \DIFadd{Protein expression}\DIFaddend (B) - dilution - degredation$$

where B is the concentration of building block metabolites. Production is a lineair conversion of B into P, whereas growth, protein expression, and dilution depend on the dynamics of the cell.  Biomass product is then consumed by cellular growth and protein expression which are a function of the building block concentration, is diluted proportional to the changes in cell volume, and degradation is fixed. \bigskip

Consumption for protein expression is summed over all genes: $$\sum_{i=1}^{N_{genes}}{Pr_i\cdot Reg_i }$$

where $Pr_i$ is the basal expression rate of gene $i$, either up or down-regulated if transcription factors are bound to its operator sequence $Reg_i$ (see transcriptional regulation). 

% Growth
\paragraph{Cell volume growth}
We assume that cell volumes a maximum cell size $\mathit{MaxV}$ and that there is a continuous turnover $d$ of the cell volume at steady state, ensuring the necessity to keep on metabolising even if there is no possibility to reproduce (\textit{i.e.} if the grid points are all full). Volume then changes as
$$
\frac{dV}{dt} = g \cdot V \cdot \frac{1-V}{\mathit{MaxV}} -d \cdot V 
$$

% expression
\paragraph*{Transcriptional regulation}The rates at which genes are expressed is a function of the basal expression rate of the gene and the concentrations of binding TFs and their molecular ligands. The intrinsic basal expression rate of a gene is encoded by a strength parameter in a gene's promoter region. This basal expression rate can be modulated by TFs that bind to an operator sequence associated with the gene. Binding sites and TF binding motifs are modelled as bit-strings and matching depends on a certain fraction of sequence complementarity. If a minimum complementarity is chosen $<1$ a match may occur anywhere within the full length of the operator binding sequence and the TF binding motif. The maximum fraction of complementarity achieved between matching sequences linearly scales the strength with which a TF binds the target gene. In addition to binding strength following from sequence complementarity, TFs encode an intrinsic binding affinity for promoters $\mathit{K_{b}}$, representing the structural stability of the TF-DNA binding complex. \bigskip

TFs can, themselves, be bound to small ligand molecules with binding afinity $\mathit{K_{l}}$, altering the regulatory effect they exert on downstream genes. These effects are encoded by parameters $\mathit{eff_{bound}}$ and $\mathit{eff_{apo}}$ for the ligand-bound and ligand-free state of the TF, respectively, and evolve independently. Ligand binding to TFs is assumed to be a fast process, relative to enzymatic and transcription-translation dynamics, and modeled at quasi steady state. We determine the fraction of TF that is not bound by any of its ligands $L$:
$$ 
\mathit{W_{apo}} =  \prod_{l \in L} ( 1 - \frac{[l]}{[l] + K_{l}} ) 
$$
The fraction of time that a TF $\tau$ in a particular state $\sigma$ (bound or apo) is bound to a particular operator $o$:
$$ 
V_o = \frac{[\tau_{\sigma}] \cdot c_{\tau o} \cdot K_{b_{\tau}}}{1 + \sum_{\sigma \in \mathcal{S}} \sum_{\mathit{\tau_{\sigma}} \in \mathcal{T}} [\mathit{\tau_{\sigma}}] \cdot c_{\tau o} \cdot \mathit{K_{b_{\tau}}} }  
$$
depends on the inherent binding affinity $\mathit{K_{b_{\tau}}}$ as well as the sequence complementarity score $c_{\tau o}$ between the tf binding motif and the operator sequence [cite Neyfahk]. The binding polynomial in the denominator is the partition function of all TFs $\mathcal{T}$ in any of the states $\mathcal{S}$ that can bind the operator. Note that small declines in the concentration of free TFs due to binding to operators are neglected.\bigskip

Now, the operator mediated regulation function for any gene is given by
$$
\mathit{Reg} = \sum V_i \cdot E_i  
$$
with $V_i$ the fraction of time that the operator is either unbound or bound by a TF in either ligand bound or unbound state and $E_i$ the regulatory effect of that state (1 if unbound or $\mathit{eff_{bound}}$ or $\mathit{eff_{apo}}$ when bound by a ligand bound or ligand free TF, respectively).
Finally, protein concentrations $[\mathcal{P}]$ are governed by the function:
$$ 
\frac{d[\mathcal{P}]}{dt}=\mathit{Pr} \cdot \mathit{Reg} \cdot \mathit{degr} \cdot [\mathcal{P}] 
$$
where $\mathit{Pr}$ is the evolvable parameter \textit{promoter strength}  and $\mathit{degr}$ a fixed protein degradation rate which is not evolvable. 

% paragraph  (end)


% Toxicity and death
\paragraph{Toxicity and death} Virtual Microbe death is a stochastic process depending on a basal death rate, which is potentially increased when internal metabolite concentrations reach a toxic threshold. A cumulative toxic effect is computed over the current life time $\tau$  of a microbe as
$$
\mathit{e_{tox}} = \sum_{m\in M}{} \int_{t=0}^{\tau} f(m,t) dt
$$ 
for all internal molecules $M$, with 
%$\frac{d[i]}{dt} = max(0, \frac{[i] - tox_i}{tox_i})$ 
$$
f(m,t) = \mathit{max}(0, \frac{[m]_{t} - \mathit{tox_m}}{\mathit{tox_m}})
$$
the toxic effect function for the concentration of molecule $m$ at time $t$ with toxicity threshold $\mathit{tox_m}$. This toxic effect increases the death rate $d$ of microbes starting at the intrinsic death rate $r$ 
$$
d = \frac{\mathit{e_{tox}}}{s+\mathit{e_{tox}}} \cdot (1-r) + r 
$$%e/(s+e) * (1 - r) + r
where $s$ scales the toxic effect. Virtual Microbes that survive after an update cycle retain the toxic level they accumulated so far. \bigskip
Apart from toxicity and stochastic death, cells can also starve. When insufficient biomass product is availble to keep up the slowly decaying volume of the cell, the cells decrease in volume. If the cell volume drops below a \emph{minimally viable volume}, this cell is automatically for death.
% paragraph  (end) 

% Reproduction
\paragraph{Reproduction}
\label{par:}
When \DIFdelbegin \DIFdel{cells }\DIFdelend \DIFaddbegin \DIFadd{an empty grid point is available, the 8 (or less) neighbouring competitors get to compete to reproduce into the grid point. During the `in silico serial transfer protocol' (see below), all cells are continuously mixed, so 8 (or less) random competitors are sampled. When cells }\DIFaddend compete for reproduction, the cells are ranked according to cell size. The ``winner'' is then drawn from a roulette wheel with weights proportional to this ranking. Upon reproduction, cell volume is divided equally between parent and offspring, and the genome is copied with mutations (see below). Molecule and protein concentrations remaining constant. Toxic effects built up during the parent's lifetime do not carry over to offspring. 
% paragraph  (end)
% Mutations
\paragraph{Genome and mutations}
\label{par:}
The genome is a circular list of explicit genes and their promoter region, organised like ``\DIFdelbegin \DIFdel{pearl }\DIFdelend \DIFaddbegin \DIFadd{pearls }\DIFaddend on a string''. Genes can be enzymes, transporters, or transcription factors. At birth, the genome is subject to various types of mutations. Large mutations include duplications, deletions, inversions, and translocations of stretches of genes (see Table \ref{tab:muts}). At the single gene level, point mutations allow all evolvable parameters to mutate individually (see Table \ref{tab:geneMuts}). Horizontal gene transfer can occur on every time step. Innovations are an abstraction of ``HGT from an external (off-grid) source'', and allow randomly parametrised genes to be discovered at any given moment with a low probability. 

%(see equation \ref{eqaaa} and \ref{eqdist}).
%A R-score close to 0 means that all cells have qualitatively the same protein levels, while higher values are an indication of differential protein expression in the current clone. Note that the r-score works only to identify populations with \emph{differential} gene regulation. Fluctuations and or regulation of the total expression rate does not result in a higher score. 
\subsection*{Experimental setup}
\paragraph{Metabolic network and wild type evolution}We use a very simple metabolic network with 2 resource metabolites, 1 building block metabolite, and an energy carrier (Figure \ref{fig:wt_evolution}A). We initialised 16 minimally viable Virtual Microbes, and evolved them for $\sim$10.000-15.000 generations in fluctuating resource conditions by applying random fluctuations of the influx rates for the A and the C resource. Because the rate of influx for the two resource metabolites fluctuates between very high ($10^{-1}$) and very low values ($10^{-5}$), conditions can be very poor, very rich, and/or potentially toxic. To avoid total extinction, we subdivided the 40x40 grid into four 20x20 subspaces, in which these fluctuations are independent (see Figure \ref{fig:wt_evolution}B). Note however that these subspaces do not impede diffusion and reproduction, but merely define the rate at which resources flux into different positions on the grid. In this study, the microbes do not migrate during their lifetime. These conditions, summarized in Table \ref{tab:force}, aim to simulate natural resource fluctuations, evolving what we call ``wild types'' (WTs) of Virtual Microbes. (see supplement S1) \DIFaddbegin \\
\DIFaddend 

The initial population consists of cells that have 3 enzymes, 3 pumps, and 5 transcription factors. All these proteins are randomly parameterized, meaning that these proteins are unlikely to have good binding affinities and catalytic rates. The amount of building block required to grow and produce protein is therefor very minimal in the early stages of evolution, and \DIFdelbegin \DIFdel{increases }\DIFdelend \DIFaddbegin \DIFadd{is increased }\DIFaddend up to a fixed level as the Virtual Microbes \DIFdelbegin \DIFdel{improve}\DIFdelend \DIFaddbegin \DIFadd{become more productive over time}\DIFaddend .

\paragraph{\textit{In silico} serial transfer protocol}
We mimic a serial transfer protocol like \DIFdelbegin \DIFdel{that of the LTEE }\DIFdelend by taking our evolved WTs and -- instead of fluctuating the resource conditions -- periodically supplying a strong pulse of both the A- and the C-resource. While WTs are evolved in a spatial setting where resources flux in and out of the system, we here mix all cells and resources continuously and fully close the system, meaning no metabolites wash \DIFdelbegin \DIFdel{out}\DIFdelend \DIFaddbegin \DIFadd{in or out of the system during the daily cycle}\DIFaddend . To apply strong bottlenecks while at the same time allowing for sufficient growth, we increased the size of the grid from 40x40 to 70x70. We \DIFdelbegin \DIFdel{dilute the }\DIFdelend \DIFaddbegin \DIFadd{then dilute population }\DIFaddend approximately tenfold, transferring 500 cells to the next cycle. \DIFdelbegin \DIFdel{Firstly, horizontal gene transfer }\DIFdelend \DIFaddbegin \DIFadd{Horizontal gene transfer between cells }\DIFaddend was disabled to represent the modified (asexual) \textit{Escherichia coli} \DIFdelbegin \DIFdel{Bc251 }\DIFdelend \DIFaddbegin \DIFadd{REL606 }\DIFaddend clone that is used in the LTEE \cite{lenski1991long}. \DIFdelbegin \DIFdel{Furthermore}\DIFdelend \DIFaddbegin \DIFadd{Finally}\DIFaddend , as the strong bottlenecks cause more genetic drift \DIFdelbegin \DIFdel{than }\DIFdelend \DIFaddbegin \DIFadd{in our small populations than in }\DIFaddend the WT evolution, we found it necessary to dial back the mutation rates for the evolution of WTs to 30\% to avoid over-exploiting mutants from appearing \DIFaddbegin \DIFadd{to easily }\DIFaddend (see Table \ref{tab:muts}). Other parameters of the serial transfer protocol are listed in Table \ref{tab:force}. 

\paragraph{Growth rate and yield measurements}

Yield was approximated by taking sum of all cell volumes\DIFdelbegin \DIFdel{, normalized by the maximum number of cells (i. o.w. the size of the grid). }\DIFdelend \DIFaddbegin \DIFadd{. }\DIFaddend We measured yield both within a single serial transfer cycle (``daily yield''), and as the extended yield when we tested for long-term survival. As all WTs had slightly \DIFdelbegin \DIFdel{different log phases}\DIFdelend \DIFaddbegin \DIFadd{temporal growth rate dynamics}\DIFaddend , we estimated the growth rates as the average building block production during the first half of the protocol. 


\paragraph{\DIFdelbegin \DIFdel{Curating }\DIFdelend \DIFaddbegin \DIFadd{Characterising }\DIFaddend (quasi-)stable coexistence}

Using the neutral lineage markers, we manually \DIFdelbegin \DIFdel{characterized }\DIFdelend \DIFaddbegin \DIFadd{characterised }\DIFaddend coexistence by looking at the dynamics of neutral lineage markers. When two neutral markers had relatively stable frequencies with a daily pattern as visualised in Figure \ref{fig:lineages}C for at least 10.000 time steps (approximately 100 generations), it was scored as coexistence. When this persisted for a while, but later got lost, it was scored as quasi-stable. When two neutral markers had balanced frequencies for at least 10.000 time steps and this pattern lasted until the end of the 800 serial transfers, it was scored as stable. If neither happened, it was annotated at no coexistence. 

\paragraph{Further configuration of Virtual Microbes}
Apart from the parameters within the confines of this article (Table 1-4), we have used the  default settings for Virtual Microbes release 0.1.4, with the configuration files provided in Supplementary Section 2. Further details on the model and parametrisation are available online \url{https://bitbucket.org/thocu/virtual-microbes}


\newpage
%\nocite{oreg,schn,pond,smith,marg,hunn,advi,koha,mouse}
\bibliographystyle{bmc-mathphys} % Style BST file (bmc-mathphys, vancouver, spbasic).
\bibliography{anticipation}      % Bibliography file (usually '*.bib' )
\newpage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%                                          %%
%% Backmatter begins here                   %%
%%                                          %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section*{Declarations}
\begin{backmatter}
	
	\section*{Competing interests} The authors declares no competing financial interests.
	\section*{Ethics approval and consent to participate} Not applicable
	\section*{Consent to publish} Not applicable
	
	\section*{Author contributions} B.D. performed simulations and provided the data. Results were analysed and interpreted by all authors. B.D. wrote the manuscript with input from P.H., J.M., and T.C.. P.H. supervised the project. All authors have approved the manuscript.
	
	\section*{Availability of data and materials} The full python module of Virtual Microbes is publicly available via PyPi. The code is available online on \url{bitbucket.org/thocu/virtual-microbes}. Further help with installation, instructions on how to use Virtual Microbes, and full documentation of the methods, is available on \url{www.virtualmicrobes.com}. As the data to support this study is fully computer generated, and consists of quite a large set of files, we felt it unnecessary and unhelpful to make the data available online. However, all the data that support this study are reproduced using \DIFdelbegin \DIFdel{the code and }\DIFdelend \DIFaddbegin \DIFadd{Virtual Microbes 0.1.4 and the }\DIFaddend configuration from the supplementary materials. Finally, the corresponding author is available for help with the software.
	
	\section*{Funding} The work presented here was brought to funded by, and brought to fruition during, the EvoEvo project (European Commission 7th Framework Programme (FPFP7-ICT-2013.9.6 FET Proactive: Evolving Living Technologies) EvoEvo project ICT-610427). 
	
	\section*{Acknowledgements} The authors want to thank Dominique Schneider and Thomas Hindr\'{e} (Universit\'{e} Grenoble Alpes) for experiments done, and discussions had, during this project. Finally, the authors would like to thank Guillaume Beslon, and all the partners of the EvoEvo project for fruitful discussions. 
\end{backmatter}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%                  The Bibliography                       %%
%%                                                         %%
%%  Bmc_mathpys.bst  will be used to                       %%
%%  create a .BBL file for submission.                     %%
%%  After submission of the .TEX file,                     %%
%%  you will be prompted to submit your .BBL file.         %%
%%                                                         %%
%%                                                         %%
%%  Note that the displayed Bibliography will not          %%
%%  necessarily be rendered by Latex exactly as specified  %%
%%  in the online Instructions for Authors.                %%
%%                                                         %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% if your bibliography is in bibtex format, use those commands:

% for author-year bibliography (bmc-mathphys or spbasic)
% a) write to bib file (bmc-mathphys only)
% @settings{label, options="nameyear"}
% b) uncomment next line
%\nocite{label}

% or include bibliography directly:
% \begin{thebibliography}
% \bibitem{b1}
% \end{thebibliography}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%                               %%
%% Figures                       %%
%%                               %%
%% NB: this is for captions and  %%
%% Titles. All graphics must be  %%
%% submitted separately and NOT  %%
%% included in the Tex document  %%
%%                               %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%
%% Do not use \listoffigures as most will included as separate files
\newpage
\section*{Figure captions}

\begin{figure*}[h]
	
	%DIF < \includegraphics[width=0.85\textwidth]{fig_overview.pdf}
	%DIF > \includegraphics[width=0.85\textwidth]{figures/fig_overview.pdf}
	\caption{\csentence{Virtual Microbes model overview.}
		\textbf{A)} At the basis of the Virtual Microbe model is an artificial ``metabolic universe'', describing all the possible reactions that can be catalysed. Resources (yellow and blue) are fluxed in, but building blocks (purple) and energy (red) must be synthesized to express proteins and transport metabolites across the membrane, respectively.
		\textbf{B)} A Virtual Microbe only needs to express a subset of all possible reactions to be viable, and that no metabolic strategy is necessarily the ``right'' one. 
		\textbf{C)} The individuals grow and reproduce on a spatial grid, and can only reproduce when there is an empty spot. Death happens stochastically or when a cell has accumulated toxicity by having excessively high concentrations of metabolites. Since only cells that have grown sufficiently are allowed to reproduce, we simulate evolution with no prior expectation. }
	
	\label{fig:overview}
\end{figure*}

\begin{figure*}[h!]
	
	%DIF < \includegraphics[width=0.85\textwidth]{fig_wt_evolution.pdf}
	%DIF > \includegraphics[width=0.85\textwidth]{figures/fig_wt_evolution.pdf}
	\caption{\csentence{Evolution of Virtual ``wild types'' under naturally unpredictable and fluctuating resource conditions.}
		\textbf{A)} Natural evolution is mimicked by (harsly) fluctuating resource conditions, resulting in a wide variety of resource conditions. The (actual) grid is 40x40, with four 20x20 subspaces where the rates of influx vary stochastically. These subspaces do not impede diffusion of metabolites or reproduction. The fluctuations of the A and C resource (blue and yellow respectively) are independent, resulting in a variety of different conditions. Building blocks (purple) must be synthesized for growth and protein expression.	\textbf{B)} We repeat the evolution in natural conditions 16 times starting from the same (minimally viable) initial clone (varying the mutations that happen) yielding 16 distinct WTs. These WTs are later transfered to a serial transfer protocol. \textbf{C)} In the white labels we show how many of the evolved WTs adapted to use particular reactions. The thicker arrows represent the shared core genome which consists of two resource importers, a metabolic cycle, and a C-exporter. Transcription factors (diamonds) were always present across WTs, but only 11/16 WTs visibly display changes in gene expression correlated with changes in the environment.
	}
	\label{fig:wt_evolution}
\end{figure*}




\DIFdelbegin %DIFDELCMD < \begin{figure}[h!]
%DIFDELCMD < %%%
%DIF < 	\includegraphics[width=0.85\textwidth]{fig_trajectories.pdf}
%DIFDELCMD < 

%DIFDELCMD < 	%%%
%DIFDELCMD < \caption{%
{%DIFAUXCMD
	%DIFDELCMD < \csentence{Prior evolution determines trajectories of adaptation towards a serial transfer protocol.}
	%DIFDELCMD < 		%%%
	\textbf{\DIFdelFL{A)}} %DIFAUXCMD
	\DIFdelFL{Growth rate (average building block production during log phase) is plotted against daily yield (average population biomass within a single cycle), for all the 48 experiments after adaptation to 800 serial transfers. The black dotted line is a linear regression model (p $<<$ 10e-16, R$^2$ = 0.54). }\textbf{\DIFdelFL{B)}} %DIFAUXCMD
	\DIFdelFL{Shows the initial points for all 16 WTs, which actually have a positive correlation between growth and yield (p $<<$ 10e-5, R$^2$ = 0.32) instead of the negative correlation (black dotted line). }\textbf{\DIFdelFL{C-E)}} %DIFAUXCMD
	\DIFdelFL{These insets display how the repeated evolution of most WTs produces similar trajectories towards the trade-off (time points are day 0, 20, 40, 100, 200 and 800), ending in either high daily yield (C) or low daily yield (D). A minority of WTs diverge after reaching the trade-off, and thus show more diverse trajectories when repeated (E). The colours of the end point symbols depict different modes of adaptation as discussed in the next paragraph (grey = no coexistence, blue = quasi-stable coexistence, purple = stable balanced polymorphisms, black cross = extinction).
	}}
	%DIFAUXCMD
	%DIFDELCMD < \label{fig:trajectories}
	%DIFDELCMD < \end{figure}
	%DIFDELCMD < 
	
	%DIFDELCMD < 	%%%
	\DIFdelend \begin{figure*}[h!]
		
		%DIF < 	\includegraphics[width=0.85\textwidth]{fig_anticipation.pdf}
		%DIF > 	\includegraphics[width=0.85\textwidth]{figures/fig_anticipation.pdf}
		\caption{\csentence{Virtual Microbes adapt to anticipate the regularity of a serial transfer protocol.}
			\textbf{A)} Growth dynamics of WT (green, day 10) and evolved populations (blue, day 760) in terms of cell counts. (WT03\#1 taken as an illustrative example). \textbf{B-C)} Two WTs (green) and the population after prolonged evolution in the serial transfer protocol (blue) are shown as an illustration of the anticipation effects. Over the course of 3 cycles, the average cell volume is plotted against time for the ancestral WT (green) and for the evolved population (blue). The y-axis (cell volume) indicates the minimal viable volume and division volume (which are fixed for the model), and the evolved \DIFdelbeginFL \DIFdelFL{transfer volume }\DIFdelendFL \DIFaddbeginFL \DIFaddFL{volume-at-transfer }\DIFaddendFL (as measured at the end of the third cycle). Daily and extended yield are measured as defined in the method section. After the third cycle, serial transfer is stopped (transparent area), showing decreased survival of the evolved populations with respect to their ancestor.
			\textbf{D)} Stacked density distributions are plotted for the \DIFdelbeginFL \DIFdelFL{transfer volumes }\DIFdelendFL \DIFaddbeginFL \DIFaddFL{volume-at-transfers }\DIFaddendFL both early (transfer 0-40, green) and late (transfer 760-800, blue).
			\textbf{E)} The evolved changes in yield both ``daily'' (within one cycle of the protocol) and ``extended'' (after prolonged starvation) for all 16 WTs.
		}
		\label{fig:anticipation}
	\end{figure*}
	\DIFaddbegin \begin{figure}[h!]
		%DIF > 	\includegraphics[width=0.85\textwidth]{figures/fig_trajectories.pdf}
		\DIFaddendFL 
		
		\DIFaddbeginFL \caption{\csentence{Prior evolution determines trajectories of adaptation towards a serial transfer protocol.}
			\textbf{\DIFaddFL{A)}} \DIFaddFL{Growth rate (average building block production during log phase) is plotted against daily yield (average population biomass within a single cycle), for all the 48 experiments after adaptation to 800 serial transfers. The black dotted line is a linear regression model (p $<<$ 10e-16, R$^2$ = 0.54). }\textbf{\DIFaddFL{B)}} \DIFaddFL{Shows the initial points for all 16 WTs, which actually have a positive correlation between growth and yield (p $<<$ 10e-5, R$^2$ = 0.32) instead of the negative correlation (black dotted line). }\textbf{\DIFaddFL{C-E)}} \DIFaddFL{These insets display how the repeated evolution of most WTs produces similar trajectories towards the trade-off (time points are day 0, 20, 40, 100, 200 and 800), ending in either high daily yield (C) or low daily yield (D). A minority of WTs diverge after reaching the trade-off, and thus show more diverse trajectories when repeated (E). The colours of the end point symbols depict different modes of adaptation as discussed in the next paragraph (grey = no coexistence, purple = (quasi-)stable coexistence, black cross = extinction due to over=exploiting the medium).
			}}
			\label{fig:trajectories}
		\end{figure}
		\DIFaddend \begin{figure*}[h!]
			%DIF < \includegraphics[width=0.85\textwidth]{fig_lineages.pdf}
			%DIF > \includegraphics[width=0.85\textwidth]{figures/fig_lineages.pdf}
			
			\caption{\csentence{Dynamics of neutral lineage markers reveal balanced polymorphisms based on the daily cycle.}			\textbf{A-C)} Neutral lineage markers (random colours) frequencies are plotted along 800 serial transfers (left hand side) and along 3 cycles. Panel A shows an example with no coexistence which is found in 23 out of 44 replicates, and panel B and C show (quasi-)stable coexistence, found in the remaining 21 replicates. \textbf{D)} shows these 3 possible outcomes for all 3 replicates of 16 WTs  (grey = no coexistence, \DIFdelbeginFL \DIFdelFL{blue = quasi-stable coexistence, }\DIFdelendFL purple = \DIFaddbeginFL \DIFaddFL{(quasi-)}\DIFaddendFL stable \DIFdelbeginFL \DIFdelFL{balanced polymorphisms}\DIFdelendFL \DIFaddbeginFL \DIFaddFL{coexistence}\DIFaddendFL , black cross = extinction \DIFdelbeginFL \DIFdelFL{) Four replicates went extinct during the serial transfer experiment }\DIFdelendFL due to \DIFdelbeginFL \DIFdelFL{over-exploiting of }\DIFdelendFL \DIFaddbeginFL \DIFaddFL{over=exploiting }\DIFaddendFL the medium\DIFdelbeginFL \DIFdelFL{(black crosses}\DIFdelendFL )
				\DIFdelbeginFL \DIFdelFL{.
				}\DIFdelendFL }
			\label{fig:lineages}
		\end{figure*}
		
		\begin{figure*}[h!]
			
			%DIF < \includegraphics[width=0.85\textwidth]{fig_anticipation_modes.pdf}
			%DIF > \includegraphics[width=0.85\textwidth]{figures/fig_anticipation_modes.pdf}
			\caption{\csentence{Anticipation can entail polymorphism or a single lineage that switches between two metabolic modes.}
				\textbf{A)} Two lineages occupy different niches on the growth vs. yield trade-off WT02\#01 diverges into a slow growing lineage (yellow lineage, average death rate $\pm$0.015) and a faster growing lineage with elevated death rates (blue lineages, average death rate $\pm$0.048), together anticipating the serial transfer protocol. \textbf{B)} A single-lineage anticipates the daily cycle by trimming and tuning the gene regulatory network. All three replicates of WT07 anticipate as a single lineage with two metabolic modes. The ancestral gene regulatory network (GRN), protein allocation dynamics, and resource concentrations are displayed for WT07 during the first cycle of the serial transfer protocol, and for the three replicated experiments after 400 serial transfers.
			}
			\label{fig:anticipation_modes}
			\DIFaddbeginFL \end{figure*}
		
		\begin{figure*}[h!]
			
			%DIF > \includegraphics[width=0.85\textwidth]{figures/fig_yield_binned.pdf}
			\caption{\csentence{Individual and collective solutions can reach identical yield}
				\DIFaddFL{The daily yield for all the evolved populations is shown, for groups of individual / collective solutions with and without regulated gene expression. Colours and symbols are identical to previous figures. Only the non-regulating, individual lineages perform significantly worse than any of the other groups (performing all 6 Wilcoxon rank-sum tests with $\alpha$ 0.05)}}
			\label{fig:yield_binned}
			\DIFaddendFL \end{figure*}
		
		\clearpage
		
		%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
		%%                               %%
		%% Tables                        %%
		%%                               %%
		%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
		
		
		
		%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
		%%                               %%
		%% Additional Files              %%
		%%                               %%
		%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
		
		\LARGE{\flushleft\textbf{Supplementary materials - S1:\\ Evolution of Virtual Microbes wild types}}
		\normalsize
		\renewcommand{\thefigure}{S\arabic{figure}}
		
		\setcounter{figure}{0}
		
		\setcounter{page}{1}
		\bigskip
		
		%Although a wide variety of possible regulatory mechanisms exist in real organisms (regulated growth arrest, catabolite repression, homeostasis), we will first primarily focus on whether or not differences in expression patterns are found within clones.\\ 
		
		%Even though the maintenance of cell size is equally costly for all Virtual Microbes, the 
		%Regulatory mechanisms allow 
		% and the evolution of regulatory growth arrest.  survival mechanisms. etc. In other words, birth and death are both evolvable properties of Virtual Microbes that evolution can tune to  \\
		\textbf{Convergent and divergent evolution in Virtual Microbe wild types}
		
		In the evolution of our WTs we observed strong convergence as well as divergence in the metabolic and gene regulatory networks that evolved. Because the evolved populations consist of a rich mix of different genotypes, we here describe the WTs by profiling the gene repertoires and GRNs at the end of the simulation ($\sim$10.000 generations). For this, we took 20 (maximally unrelated) individuals from the evolved populations and determined the consensus metabolism (Figure \ref{sfig:metabolism}A). While there is some diversity in the metabolic networks across WTs, the shared gene repertoire constitutes a metabolic network that forms a metabolic cycle complemented with resource importers and an exporter for the C metabolite (Figure \ref{sfig:metabolism}B). We observed that the discovery of both the metabolic cycle as well as the exporter favour survival, as it coincides with an increase in population size and a decrease in the number of generations per time step (Figure \ref{sfig:survival}). Note that in Virtual Microbes survival is improved by avoiding toxic effects of high metabolite concentrations and by only investing in growth when conditions are favourable for growth. The latter can be done via gene regulatory networks that respond to the quality of the environment, but we also found forms of metabolic regulation where microbes accurately fine-tuned kinetic parameters to automatically maintain homeostasis.
		
		\bigskip
		
		
		Although the shared gene repertoire from Figure \ref{sfig:metabolism}B does not contain transcription factors (TFs), all of the 16 WTs have at least one type of TF. These TFs can constitutively repress or activate certain genes, or can respond to environmental conditions by binding to a ligand molecule. The latter response depends on the kinetic properties of the TFs and the properties of the genes which they regulate, all of which are evolvable (see Table S1). To get a better overview of how the WTs respond to environmental stimuli we therefore chose to directly measure the gene expression levels in a variety of different resource concentrations (displayed for 6 WTs in Figure \ref{sfig:regulation}). On the level of these GRNs, and their sensitivity the environment, we clearly see signs of strong divergent evolution. Note however, that the \emph{effect} on the importer and exporter proteins seems very similar between WTs with different networks, showing that similar responses can be encoded by different GRNs. Finally, as seen in these graphs, some WTs have no response to environmental stimuli. We found that these non-regulating WTs are equally ``fit'', in that they have the same rates of building block production and death rates (see Figure \ref{sfig:reg_vs_non}). However, the majority (11/16) WTs evolved clear regulatory mechanisms. 
		
		\bigskip
		In short, during the \textit{de novo} evolution of Virtual Microbe WTs, some evolved features seem highly predictable. Namely, all have evolved the metabolic cycle, all express both resource importer proteins, and all but one WT have a C-exporter. On the other hand, regulatory mechanisms and some of the secondary reactions display considerable diversity. Note that this divergence cannot be explained by differences in initial conditions or fluctuations in resource concentrations, because the WTs only differ with respect to the mutations that have happened in their evolutionary history. However, as shown in the main text, these differences have a profound effect on further evolution. 
		\newpage
		
		
		\newpage
		
		\begin{table}
			\label{TFpar}
			\textbf{Table S1 - Important parameters for TFs for an environmental response}\\
			
			
			\resizebox{\linewidth}{!}{%
				\footnotesize
				\begin{tabularx}{\textwidth}{c X c}
					
					\rowcolor{gray!50}
					\textbf{Property TF}  & \textbf{Description} \\
					\hline
					
					Expression TF & The TF itself needs to be sufficiently expressed \\
					Binding motif & The binary binding motif (10 bits) must have a sufficient match to the operator sequences of genes (50 bits) in order to affect their expression\\
					K$_{ligand}$ & If the binding constant to the ligand K$_{ligand}$ is not in range of the observed concentration of metabolites, the TF will always have the same (up or down) regulatory effect, regardless of the environment or internal concentrations. \\    
					Effect of ligand & The ligand-bound and ligand-unbound regulatory effects of TFs need to be different to effectively change expression of genes given any environmental stimulus\\
					\hline
				\end{tabularx}
			}
		\end{table}
		
		
		\newpage
		
		\begin{table}
			\rowcolors{2}{gray!25}{white}
			\flushleft
			\textbf{Table S2 - Anticipation and polymorphisms are also observed when changing in the serial transfer protocol}
			For different transfer times, dilutions, and resources concentrations, seven WTs (11-16, and WT07 from Figure \ref{fig:anticipation_modes} from the main text) have been tested for the  anticipation effect and polymorphisms. Note that anticipation is not tested by prolonging the cycle (like in the main text), but by comparing the patterns in cell cycle dynamics with those from Figure 3 in the main text. If a clear decrease in cell volume was observed at the end of the cycle, it was scored as anticipation. Polymorphisms are scored as defined in the methods.
			
			\begin{tabularx}{75mm}{|c|X|X|}
				\rowcolor{black}
				\multicolumn{3}{c}{textbf{ \color{white}Shorter transfer time (25), 800 cycles}} \\
				\rowcolor{gray!50}
				\textbf{ WT}  & \textbf{Anticipation (Yes/No)} & \textbf{Polymorph (Yes,No,Quasi)} \\
				
				11 & Y & N \\
				12 & Y & N \\
				13 & Y & Q \\ 
				14 & Y & N \\
				15 & Y & Q \\ 
				16 & Y & Q \\ 
				\rowcolor{blue!20}\hline
				07 & Y & N \\
				\hline
			\end{tabularx}
			
			
			\vspace{2mm}
			\begin{tabularx}{75mm}{|c|X|X|}
				\rowcolor{black}
				\multicolumn{3}{c}{textbf{ \color{white}Higher transfer time (75), $\sim$250 cycles}} \\
				\rowcolor{gray!50}
				\textbf{ WT}  & \textbf{Anticipation (Yes/No)} & \textbf{Polymorph (Yes,No,Quasi)} \\
				
				11 & Y & N \\
				12 & Y & N \\
				13 & Y & Y \\ 
				14 & Y & N \\
				15 & Y & N \\ 
				16 & Y & Q\\
				\rowcolor{blue!20}\hline
				07 & Y & N \\
				\hline
			\end{tabularx}
		\end{table}
		
		
		\clearpage
		\newpage
		\normalsize
		\LARGE{\flushleft\textbf{Supplementary materials - S2:\\ Virtual Microbe configuration}}
		\normalsize
		\bigskip
		
		
		\label{config}
		The evolution of these WTs was done with Virtual Microbes version 0.1.4 which is publicly available as a Python package. Complete documentation on the methods is publicly available on \url{http://bitbucket.org/thocu/virtualmicrobes.}  For this study, we used the configuration below. We removed options that are not relevant for reproducability (\textit{e.g.} memory-limit, thread-count, data-storage-frequency etc.) or are default (\textit{e.g.} universal-mutation-rate scaling=1.0)
		To reproduce these results with the newer versions of Virtual Microbes (0.2.4 as of January 2019), feel free to contact the corresponding author if help is required.
		
		\vspace{8mm}
		\texttt{virtualmicrobes.py @reg\-gen.cfg - evo @reg-evo.cfg --name My\_WT\_Vmicrobe}
		\bigskip
		\normalsize
		\\general\_options.cfg:
		\tiny
		
		\begin{lstlisting}
		--base-death-rate 0.01
		--mutation-rates 
		chrom_dup=0.0
		chrom_del=0.0 
		chrom_fiss=0.0
		chrom_fuse=0.0
		point_mutation=0.005
		tandem_dup=0.005
		stretch_del=0.005
		stretch_invert=0.005
		stretch_translocate=0.005
		stretch_exp_lambda=0.3
		external_hgt=0.0002
		internal_hgt=0.002
		regulatory_mutation=0.005
		reg_stretch_exp_lambda=0.1
		--point-mutation-ratios
		ligand_class=0.1
		exporting=0.1
		--rand-gene-params
		base=10
		lower=-1.0
		upper=1.0
		--mutation-param-space 
		base=10
		lower=-0.5
		upper=0.5
		min=0.01
		max=10.
		--max-historic-max 0.1
		--growth-rate-scaling 1
		--competition-scaling 1
		--selection-pressure historic_window_scaled
		--historic-production-window 1000
		--scale-prod-hist-to-pop
		--small-mol-diff-const 0.02
		--prot-degr-const 0.7
		--transporter-membrane-occupancy .1
		--influx-range
		base=10
		lower=-1.0
		upper=-5.0
		--fluctuate-frequencies 0,0.01
		--init-external-conc 0.
		--small-mol-ext-degr-const 1e-2
		--bb-ext-degr-const 1e-1
		--ene-ext-degr-const 5e-1
		--transcription-cost 0.002
		--energy-transcription-scaling 0.01
		--spill-conc-factor 1.
		--v-max-growth 1
		--min-bind-score 0.85
		--per-grid-cell-volume 8
		--enzyme-volume-occupancy 3
		--grid-sub-div row=2,col=2
		--sub-env-part-influx 1.0
		--grid-cols 40
		--grid-rows 40
		\end{lstlisting}
		\normalsize
		evosim\_options.cfg:
		\tiny
		\begin{lstlisting}
		--duration 1000000
		--env-rand-seed 87
		--reproduce-size-proportional
		--cell-init-volume 1.5
		--cell-growth-rate 2.0
		--cell-shrink-rate 0.6
		--cell-growth-cost 0.2
		--cell-division-volume 2.
		--init-prot-mol-conc .1
		--max-cell-volume 5
		--nr-resource-classes 3
		--nr-energy-classes 1
		--ene-energy-range 1,1
		--res-energy-range 2,10
		--nr-building-blocks 1
		--building-block-stois 1,1
		--nr-cell-building-blocks 1
		--mol-per-ene-class 1
		--mol-per-res-class 1
		--nr-cat-reactions 3
		--nr-ana-reactions 3
		--max-nr-cat-products 2
		--min-cat-energy 1,3
		--max-nr-ana-products 1
		--nr-ana-reactants 2
		--chromosome-compositions tf=0,enz=1,pump=1
		--binding-seq-len 10
		--operator-seq-len 50
		--prioritize-influxed-metabolism
		--init-prot-mol-conc 0.01
		--degradation-variance-shape 100
		--no-toxicity-variance-shape
		--toxicity 0.2
		--toxic-building-blocks
		--toxicity-scaling 1000
		--tf-binding-cooperativity 2
		--homeostatic-bb-scaling 1
		--high-energy-bbs
		--prioritize-energy-rich-influx
		\end{lstlisting}
		
		\newpage
		\begin{figure*}[h!]
			\centerline{%
				\includegraphics[width=1.00\textwidth]{figures/sfig_metabolisms.pdf}}
			\caption{\textbf{The evolved gene repertoires for all 16 WTs} 
				The gene repertoires of WTs (20 maximally unrelated individuals) is displayed for all 16 replicate simulations after 1.000.000 time steps. Rows represent the different types of proteins (transporters, enzymes and TFs), and the columns the gene repertoires. Note that the presence of a gene does not imply it is functional, since properties such as K$_s$ and V$_max$ might be poorly parameterised. Genes found in less than 4 cells or genes with low concentrations (\textit{i.e.} low expression) were omitted. The seperate column depicts the genes found in at least 90\% of WTs. }
			\label{sfig:metabolism}
		\end{figure*}
		\newpage
		\begin{figure*}[h!]
			\centerline{%
				\includegraphics[width=1.00\textwidth]{figures/sfig_regulation_diversity.pdf}}
			\caption{\textbf{WTs have great diversity of transcriptional regulation, and not all respond to changing resource concentrations} The graphs shows how the protein allocation shift to imposed changes in resource concentration of the environment. Single clones from the WTs were taken and resource concentrations of the A- and C-resource were varied from low (0.01) to high (1.0). The gene regulatory network responsible for these changes is displayed next to each graph. The colours for different enzymes are as displayed in the legend. Thicker arrows in the gene regulatory network represent higher expression levels of the transcription factors. Genes with very low expression levels were omitted for clarity.}
			\label{sfig:regulation}
		\end{figure*}
		\newpage
		\begin{figure*}[h!]
			\centerline{%
				\includegraphics[width=0.990\textwidth]{figures/sfig_regvsnon.pdf}}
			\caption{\textbf{Different WTs have similar building block production rates and death rates.} For 6 WTs, the last 2000 generation of WT evolution did not show any differences in ``fitness'', which is approximated by the rates of building block production and death. Furthermore, regulating WTs showed not difference compared to non-regulating WTs.}
			\label{sfig:reg_vs_non}
		\end{figure*}
		
		
		\begin{figure*}[h!]
			\centerline{%
				\includegraphics[width=0.990\textwidth]{figures/sfig_survival.pdf}}
			\caption{\textbf{Decrease in number of generations per time step for WTs coincides with a decrease in toxicity and/or fixation of a metabolic cycle}
				Decrease in number of generations per time step coincides with a decrease in toxicity accumulation and/or fixation of a metabolic cycle. Every dot represents an average over a 100 generations of simulation. For panel A, red dots represent a toxicity level above which death rate is increased at least threefold (toxicity $>$ 20), and black dots represent the lower toxic levels (toxicity $<=$ 20). In panel B, the cyan dots represent the fixation of both the C-exporter and the metabolic cycle, green dots the fixation of only the C-exporter, blue dots the fixation of the metabolic cycle, and black dots the fixation of neither of these features.} 
			\label{sfig:survival}
		\end{figure*}
		
		\clearpage
		
		\newpage
		\begin{figure*}[h!]
			\centerline{%
				\includegraphics[width=0.990\textwidth]{figures/sfig_anticipation_longshort.pdf}
			}
			\caption{\textbf{The anticipation effect is present after evolving in shorter (left) and longer (right) time intervals.} } 
			\label{sfig:longshort}
		\end{figure*}
		
		\newpage
		\begin{figure*}[h!]
			\centerline{%
				\includegraphics[width=0.85\textwidth]{figures/sfig_trajectories.pdf}}
			\caption{\textbf{Three replicate serial transfer experiments for all 16 WTs.}
				This image is shows all the data from the examples from Figure \ref{fig:trajectories}. 
			}
			\label{sfig:trajectories}
		\end{figure*}
		\newpage
		
		\begin{figure*}[h!]
			\centerline{%
				\includegraphics[width=1.0\textwidth]{figures/sfig_mutantsinvading.pdf}}
			\caption{\textbf{Dynamics of different invading mutants}
				A) Neutral lineage markers linked to mutations which cause high growth rates but poor survival increase in frequency early, but are losing in frequency during stationary phase. B) Neutral lineage markers linked to mutations that have higher growth rates without trading off against survival show no such temporal fitness effect. 
			}
			\label{sfig:sfig_mutantsinvading}
		\end{figure*}
		\newpage
		\clearpage
		\begin{figure*}[h!]
			\centerline{%
				\includegraphics[width=0.990\textwidth]{figures/sfig_removelin.pdf}
			}
			\caption{\textbf{Lineages based on resource specialisation (top) and growth vs. yield specialisation (bottom) perform better in the presence of the other} In the upper panel, two resource specialists over-exploit their resource in the absence of the other. In the bottom panel, without evident resource specialisation, both lineages have increased toxicity (given that this happens through enzymatic changes, this is likely due to changes in fluxes), which accumulates to significant levels near the end of the cycle. This figure thus shows that lineages can grow dependent on one another, as they are part of each-others environment.}
			\label{sfig:removelin}
		\end{figure*}
		
		\newpage
		
		\newpage
		%\section*{Additional Files}
		%  \subsection*{Additional file 1 --- Sample additional file title}
		%    Additional file descriptions text (including details of how to
		%    view the file, if it is in a non-standard format or the file extension).  This might
		%    refer to a multi-page table or a figure.
		%
		%  \subsection*{Additional file 2 --- Sample additional file title}
		%    Additional file descriptions text.
		
		
	\end{document}
	to
initilize CA planes. See \verb|InitialSet()| and \verb|InitalSetS()|
functions below. The function is supposed to set boundaries by calling
\verb|Boundaries2()| (see \S\,\ref{sec:initialization}) if the type of
boundary is \verb|FIXED|.

\item{\texttt{void NextState(int {\em row}, int {\em col})}}\\ The
function is supposed to describe the rule of CA. The argument \verb|row|
and \verb|col| will takes the coordinate of the current cell to update.

\item{\texttt{void Update(void)}}\\ The function will be called once
every time step. The function is supposed to contain functions such as
\verb|Diplay()|, \verb|Plot()|, \verb|Asynchronous()|,
\verb|Synchronous| etc (see \S\,\ref{sec:graphics} and
\S\,\ref{sec:updation}). For example, an user can define a new function
to investigate a CA plane, and call it in \texttt{Update()}.
\end{description} 

\subsection{On \texttt{TYPE2}}
\label{section:TYPE2}
\verb|TYPE2| is a \verb|structure| type defined as
\begin{verbatim}
typedef struct __type2{
  int val;
  int val2;
  int val3;
  int val4;
  int val5;
  double fval;
  double fval2;
  double fval3;
  double fval4;
  double fval5;
} TYPE2;
\end{verbatim}

A cell can contains ten different values. \verb|val| has a special
meaning: Its value is used for graphical display of the CA planes as
follows:
\begin{center}
\begin{tabular}{|r|l||r|l||r|l|}\hline
0 & black & 6 & \textcolor{brown}{brown} & 12 & \textcolor{indigo}{indigo} \\
1 & white & 7 & \textcolor{grey}{grey} & 13 & \textcolor{maroon}{maroon} \\
2 & \textcolor{red}{red} & 8 & \textcolor{violet}{violet} & 14 & \textcolor{turquoise}{turquoise} \\
3 & \textcolor{green}{green} & 9 & \textcolor{cyan}{cyan} & 15 & \textcolor{green4}{green4} \\
4 & \textcolor{blue}{blue} & 10 & \textcolor{magenta}{magenta} & & \\
5 & \textcolor{yellow}{yellow} & 11 & \textcolor{orange}{orange} & & \\\hline
\end{tabular}
\end{center}
Apart from the above color table, the colors 16--255 are available. Look
at \verb|default.ctb| file in \verb|cash2-s| directory. To change the
color, see \verb|ColorRGB()| (see\S\,\ref{sec:graphics}).

To obtain the values of variables, say \verb|fval2|, add \verb|.fval2|
at the end of the variable which contains a CA plane. For example, if
the variable of a plane is called \verb|Life|, then the value of
\verb|fval2| of the cell at coordinate \texttt{[row][col]} is obtained by
\verb|Life[row][col].fval2|.

  \subsection{Available functions}
The notations are as follows. Italicized words in brackets are the name
of the arguments, which should be replaced by appropriate names when
functions are called. A word before the name of arguments are the type
of the argument, which should be left out when using the function. A
``\texttt{...}'' in argument lists means that the number of arguments to
the function is not fixed (the function can take multiple arguments).
   \subsubsection{Graphics\label{sec:graphics}}
   \begin{description}
    \item{\texttt{int Display(TYPE2** {\em plane})}}\\ The function
    displays the graphics of CA planes. When the function is called, the
    function will redraw (update) the graphics. The arguments to the
    function should be the variables of planes. The number of arguments
    to the function and \verb|nplane| must be the same. For example, if
    one has two planes, say \texttt{Plane1} and \texttt{Plane2}, then
    one writes \texttt{Display(Plane1,Plane2)}. The order of the
    graphics of the planes displayed on the window is the same as the
    order of the arguments given to the function. For example,
    \texttt{Plane1} is shown on the most left, and \texttt{Plane2} is
    shown next to \texttt{Plane1} on the right hand side.
    \item{\texttt{int ColorRGB(int {\em ncolor},int {\em red},int {\em
    green},int {\em blue})}}\\ The function sets the color
    table. \verb|ncolor| is the index of the color. The color is
    specified by RGB values; the RGB values must be between 0 and 255
    both inclusive. The function must be called within
    \verb|InitialPlane()| function. For example, if one has called
    \verb|ColorRGB(5,0,255,0)|, then the cell which has value 5 in its
    \verb|.val| will be shown green in the graphics.
   \end{description}
   
   \subsubsection{Easy neighborhood retrieval}
   The function makes it possible to access the neighborhood of an
   arbitrary cell of CA. Functions here access only to \texttt{val} of
   the cell. To access the other varialbes, such as \texttt{fval}, one
   can refers to \S\,\ref{sec:advanced-neighbor}.

    \begin{description}
     \item{\texttt{int GetNeighbor(TYPE2** {\em plane},int {\em row},int
     {\em col},int {\em direction})}} \\The function returns the value
     of \verb|.val| of the neighbor cells. \verb|direction| specifies
     the direction of the neighbor. It takes either an symbolic name or
     an integer as defined in the following table.

\begin{center}
\begin{tabular}{|c|c|c|}\hline
NORTHWEST& NORTH & NORTHEAST \\ \hline
WEST & CENTRAL & EAST \\ \hline
SOUTHWEST & SOUTH & SOUTHEAST \\ \hline
\end{tabular}
\hspace{10pt}or\hspace{10pt}
\begin{tabular}{|c|c|c|}\hline
5 & 1 & 6 \\ \hline
2 & 0 & 3 \\ \hline
7 & 4 & 8 \\ \hline
\end{tabular}
\end{center}

    For example, if one writes:
\begin{verbatim}
north = GetNeighbor(Plane1,row,col,NORTH);
\end{verbatim} then
    \texttt{north} gets \texttt{val} of the north neighbor of the cell
    at \texttt{[row][col]}.

     \item{\texttt{int RandomMoore8(TYPE2** {\em plane},int {\em
     row},int {\em col})}}\\ The function returns the value of
     \texttt{val} of the cell which is randomly chosen from Moore
     neighborhood of the cell at \verb|[row][col]|. The number at the
     end of the function name represents the number of cells from which
     random choice is performed.

     For example, one writes:
\begin{verbatim}
rand_neigh = RandomMoore8(Plane1,row,col);
\end{verbatim}
     then \texttt{rand\_neigh} gets the value of \texttt{val} of the
     cell which is randomly chosen from Moore neighborhood. Note that
     one cannot know which neighbor is actually chosen (cf.\
     \S\,\ref{sec:advanced-neighbor}).
     \item{\texttt{int RandomMoore9(TYPE2** {\em plane},int {\em
     row},int {\em col})}}\\ The function returns the value of
     \texttt{val} of the cell which is randomly chosen from Moore
     neighborhood plus the cell at \texttt{[row][col]} (cf.\
     \texttt{RandomMoore8()}).
     \item{\texttt{int RandomNeumann4(TYPE2** {\em plane},int {\em
     row},int {\em col})}}\\ The function is the same as
     \verb|RandomMoore8| except that the neighborhood is von Neumann
     neighborhood (NORTH,EAST,SOUTH,WEST).
     \item{\texttt{int RandomNeumann5(TYPE2** {\em plane},int {\em
     row},int {\em col})}}\\ The function is the same as
     \verb|RandomMoore9| except that the neighborhood is von Neumann
     neighborhood.
     \item{\texttt{int CountMoore8(TYPE2 ** {\em plane},int {\em
     aval},int {\em row},int {\em col})}}\\ The function counts the
     number of cells which have the state \verb|aval| in \texttt{val}
     in Moore neighborhood of the cell at \verb|[row][col]|. \\ For
     example, if one writes \texttt{count} \texttt{=}
     \texttt{CountMoore8(Plane1,1,row,col)}, then \texttt{count} gets
     the number of neighbors which have state 1 in \texttt{val}.
     \item{\texttt{int CountMoore9(TYPE2 ** {\em plane},int {\em
     aval},int {\em row},int {\em col})}}\\ The function counts the
     number of cells which have the state \verb|aval| in \texttt{val}
     in Moore neighborhood plus plus the cell at \texttt{[row][col]}.
     \item{\texttt{int CountNeumann4(TYPE2 ** {\em plane},int {\em
     aval},int {\em row},int {\em col})}}\\ The function is the same as
     \verb|CountMoore8()| function except that the neighborfood is von
     Neumann neighborhood.
     \item{\texttt{int CountNeumann5(TYPE2 ** {\em plane},int {\em
     aval},int {\em row},int {\em col})}}\\ The function is the same as
     \verb|CountMoore9()| function except that the neighborfood is von
     Neumann neighborhood.
     \item{\texttt{int SumMoore8(TYPE2 ** {\em plane},int {\em row},int
     {\em col})}}\\ The function sums up \verb|val|) of the neighbors in
     the Moore neighborhood, and it returns the sum. 
     \item{\texttt{int SumMoore9(TYPE2 ** {\em plane},int {\em row},int
     {\em col})}}\\ The function is the same as \texttt{SumMoore8()}
     except that it include the focal cell in summing.
     \item{\texttt{int SumNeumann4(TYPE2 ** {\em plane},int {\em row},int
     {\em col})}}\\ The function is the same as \texttt{SumMoore8()}
     except that the neighborhood is Neumann neighborhood.
     \item{\texttt{int SumNeumann5(TYPE2 ** {\em plane},int {\em row},int
     {\em col})}}\\ The function is the same as \texttt{SumNeumann4()}
     except that it include the focal cell in summing.
\end{description}
\subsubsection{Advanced neighborhood
   retrieval\label{sec:advanced-neighbor}} In this section, advanced
   methods of accessing the neighborhood will be explained. These
   methods enable one to use not only \texttt{val}, but also the other
   values of a cell such as \texttt{fval} (see \ref{section:TYPE2} for
   the complete list of the available variables).
\begin{description}
     \item{\texttt{TYPE2 GetNeighborS(TYPE2** {\em plane},int {\em
     row},int {\em col},int {\em direction})}}\\The function returns the
     the state of the neighbor cell of the cell at
     \verb|[row][col]|. \verb|direction| specifies the direction of the
     neighbor as in \verb|GetNeighbor()| function. The function is used
     when one wants to obtain the values of all the variables of the
     neighbor cell.

     For example, if one wants to obtain the value of \verb|fval5| of
     the north cell of the cell at \verb|Plane[row][col]|, then writes:
\begin{verbatim}
TYPE2 neigh_state;
neigh_state = GetNeighborS(Plane,row,col,NORTH)
\end{verbatim}
     Then, \verb|neighbor.fval5| will give the value of \texttt{fval5}.

     An important thing to note is that changing the value of the
     variable obtained in this way does not change the value of the
     neighbor cell. For instance, suppose one does the following:
		\begin{verbatim}
neigh_state = GetNeighborS(Plane,row,col,NORTH);
neigh_state.fval5 = 1.4;
		\end{verbatim}
This does not put value \verb|1.4| in the variable \verb|fval5| of the
north neighbor. This is because, \verb|neighbor| is a copy of the
neighbor cell, but not the neighbor cell itself. To change the value of
the neighbor cell, one must use \verb|GetNeigborC()| function family or
\verb|GetNeigborP()| function family (see below).


     \item{\texttt{TYPE2 RandomMooreS8(TYPE2** {\em plane},int {\em
     row},int {\em col})}}

     The runction returns the state of the cell which is randomly chosen
     from Moore neighborhood. Note that one can not modify the state of
     the neighboring cell with this function (see \verb|GetNeighborS()|
     in this section).

     \item{\texttt{TYPE2 RandomMooreS9(TYPE2** {\em plane},int {\em
     row},int {\em col})}}

     The runction returns the state of the cell which is randomly chosen
     from Moore neighborhood plus the cell at \texttt{[row][col]}. Note
     that one can not modify the state of the neighboring cell with this
     function (see \verb|GetNeighborS()| in this section).

     \item{\texttt{TYPE2 RandomNeumannS4(TYPE2** {\em plane},int {\em
     row},int {\em col})}}\\ The same as \verb|RandomMooreS8()| function
		except that the neighborhood is von Neumann neighborhood.
     \item{\texttt{TYPE2 RandomNeumannS5(TYPE2** {\em plane},int {\em
     row},int {\em col})}}\\ The same as \verb|RandomMooreS9()| function
		except that the neighborhood is von Neumann neighborhood.
     \item{\texttt{TYPE2 CountMooreS8(TYPE2 ** {\em plane},int {\em
     aval},int {\em row},int {\em col})}}

     The function counts the number of cells which have \verb|aval|
     value. The counting is done for each integer variable of the cell
     (from \verb|val| to \verb|val5|). The return value is a
     \verb|TYPE2| value. For example, if one writes:
     \begin{verbatim}
TYPE2 count;
count = CountMooreS8(Plane1,3,row,col);
     \end{verbatim}
     then \texttt{count.val} contains the number of neighbors which has
     state 3 in \texttt{val}, and \texttt{count.val2} contains the number
     of neighbors which has state 3 in \texttt{val2}, and so forth.

     \item{\texttt{TYPE2 CountMooreS9(TYPE2 ** {\em plane},int {\em
     aval},int {\em row},int {\em col})}}\\ The function does the same
     job as \verb|CountMooreS8| does, but counting is done in the Moore
     neighborhood plus the cell at \verb|[row][col]|.
     \item{\texttt{TYPE2 CountNeumannS4(TYPE2 ** {\em plane},int {\em
     aval},int {\em row},int {\em col})}}\\ The function is the same as
     \verb|CountMooreS8| except that the neighborhood is von Neumann
     neighborhood.
     \item{\texttt{TYPE2 CountNeumannS5(TYPE2 ** {\em plane},int {\em
     aval},int {\em row},int {\em col})}}\\ The function is the same as
     \verb|CountMooreS9| except that the neighborhood is von Neumann
     neighborhood.
     \item{\texttt{int SumMooreS8(TYPE2 ** {\em plane},int {\em row},int
     {\em col})}}

     The function sums up all cell states of the neighboring cells in
     the Moore neighborhood. It returns the \verb|TYPE2| type value. For
     example, if one writes
\begin{verbatim}
TYPE2 sum;
sum = SumMooreS8(Plane1,row,col);
\end{verbatim}
     then, \texttt{sum.val} is the sum of \texttt{val} in
     Moore neighborhood, and \texttt{sum.fval} is the sum of
     \texttt{fval} in Moore neighborhood, and so forth.

     \item{\texttt{int SumMooreS9(TYPE2 ** {\em plane},int {\em row},int
     {\em col})}}\\ The function is the same as \texttt{SumMooreS8()}
     except that it include the focal cell in summing.
     \item{\texttt{int SumNeumannS4(TYPE2 ** {\em plane},int {\em row},int
     {\em col})}}\\ The function is the same as \texttt{SumMooreS8()}
     except that the neighborhood is Neumann neighborhood.
     \item{\texttt{int SumNeumannS5(TYPE2 ** {\em plane},int {\em row},int
     {\em col})}}\\ The function is the same as \texttt{SumNeumannS4()}
     except that it include the focal cell in summing.
     \item{\texttt{void GetNeighborC(TYPE2** {\em plane},int {\em
     row},int {\em col},int {\em direction},\\int* {\em neirow},int* {\em
     neicol})}}

     The function is used to obtain the coordinate of the neighbor cell
     of the cell at \verb|[row][col]|. \verb|direction| specifies the
     direction of the neighbor as in \verb|GetNeighbor()| function. The
     third and forth arguments must be an address of the variable in
     which the coordinate is stored. One can read and modify the state
     of the neighbor cell by using this funnction. For example, if one
     writes:
\begin{verbatim}
int neirow, neicol;
GetNeighborC(Plane,row,col,NORTH,&neirow,&neicol);
\end{verbatim}
     then, \texttt{neirow} and \texttt{neicol} will get the coordinate
     of the north neighbor of the cell at \texttt{[row][col]}. With the
     obtained coordinate, one can write:
\begin{verbatim}
Plane[neirow][neicol].val2 = 4;
\end{verbatim}
     Then the value of \texttt{val2} of the north neighbor will become 4.

     \item{\texttt{void RandomMooreC8(TYPE2** {\em plane},int {\em
     row},int {\em col},int* {\em neirow},int* {\em neicol})}}
    
     The function puts the coordinate of the randomly chosen cell from
     the Moore neighborhood. With this function, one can read and modify
     the state of the randomly chosen neighbor cell. For example, if one
     wites: \\ \texttt{RandomMooreC8(Life,row,col,\&neirow,\&neicol);}\\
     then \texttt{neirow} and \texttt{neicol} will get the coordinate of
     the cell which is randomly chosen (see also
     \texttt{GetNeighborC()}).
		
     \item{\texttt{void RandomMooreC9(TYPE2** {\em plane},int {\em
     row},int {\em col},int* {\em neirow},int* {\em neicol})}}

     The same as \verb|RandomMooreC8()| function except that the focal
     cell at \verb|[row][col]| is included in the random choise.

     \item{\texttt{void RandomNeumannC4(TYPE2** {\em plane},int {\em
     row},int {\em col},int* {\em neirow},int* {\em neicol})}} 

     The same as \verb|RandomMooreC8()| function except that the
     neighborfood is von Neumann neighborhood.

     \item{\texttt{void RandomNeumannC5(TYPE2** {\em plane},int {\em
     row},int {\em col},int* {\em neirow},int* {\em neicol})}}

     The function is the same as \verb|RandomMooreC9()| function except
     that the neighborhood is von Neumann neighborhood.

     \item{\texttt{TYPE2* GetNeighborP(TYPE2** {\em plane},int {\em
     row},int {\em col}, int {\em nei})}}

     The function is the same as \verb|GetNeighborS()| except that the
     function returns a pointer to the neighbor cell. With this
     function, one can read and modify the state of the randomly chosen
     neighbor cell. For example, if one writes
\begin{verbatim}
TYPE2* neip;
neip = GetNeighborP(Plane,row,col,NORTH);
\end{verbatim}
     then \texttt{neip->val} can be used to read and modify \texttt{val}
     of the north neighbor. One can write \texttt{neip->val = 5} to set
     \texttt{val} to 5. The same is true for the other
     (\texttt{f})\texttt{val}'s. See also \texttt{GetNeighborC()}, which
     is perhaps more simple to use.

     \item{\texttt{TYPE2* RandomMooreP8(TYPE2** {\em plane},int {\em
     row},int {\em col})}}\\ The function returns a pointer to the
     neighbor cell which is randomly chosen from the Moore neighborhood.
     \item{\texttt{TYPE2* RandomMooreP9(TYPE2** {\em plane},int {\em
     row},int {\em col})}}\\ The same as \verb|RandomMooreP8()| function
		except that the random choice includes the focal cell at
		\verb|[row][col]|.
     \item{\texttt{TYPE2* RandomNeumannP4(TYPE2** {\em plane},int {\em
     row},int {\em col})}}\\ The same as \verb|RandomMooreP8| except
		that the neighborhood is von Neumann neighborhood.
     \item{\texttt{TYPE2* RandomNeumannP5(TYPE2** {\em plane},int {\em
     row},int {\em col})}}\\ The same as \verb|RandomMooreP9| except
		that the neighborhood is von Neumann neighborhood.
    \end{description}
    
\subsubsection{Initilization\label{sec:initialization}}
\begin{description}
\item{\texttt{int InitialSet(TYPE2** {\em plane},int {\em nval}, int
{\em bground},...)}}

This function initializes the CA plane. The second argument is the number of
cell states one wants to use in initialization apart from the background
state, which is given as the third argument. If \texttt{\em nval} is
larger than 0, the additional arguments should be supplied: The number
of additional arguments is twice as much as \texttt{\em nval}; the first
additional argument is a cell state; the second additional argument is
the fraction of the space which will get the cell state of the previous
argument (between 0--1); the third (state) and forth (fraction)
arguments are about another cell state, and so on. 

For example, if one wants to put state 1 with the fraction of 0.1 and
state 2 with the fraction of 0.2, and the rest of cells have state 0
(background state), then write
\begin{verbatim}
\InitialSet(plane,2,0,1,0.1,2,0.2);
\end{verbatim}

\item{\texttt{int InitialSpot(TYPE2** {\em plane},int {\em val}, int
{\em size}, {\em offset})}}

An alternative function to initializing your plane, by placing a small
circle in the middle of the grid. For example, if one wants to put a
small clump of cells with state 1 on the grid, one can use val 1, size
20, and offset 0:
\begin{verbatim}
\InitialSpot(plane,1,10,0);
\end{verbatim}

\item{\texttt{int InitialSetS(TYPE2** {\em plane},int {\em nval},TYPE2
{\em bground},...)}}

The function is the same as \verb|InitialSet()| function except that the
function takes \verb|TYPE2| value as arguments for the cell state. For
example, if one wants to set \verb|val| to 1 and \verb|fval| to 0.1 for
30\% of the cells, and \verb|val| to 2 and \verb|fval| to 0.2 for 60\%
of the cells, and the rest of the cells have state 0 in \verb|val| and
value 0.0 in \verb|fval|, then write the following:

\begin{lstlisting}[style=Cstyle,basicstyle=\normalsize\ttfamily,stringstyle=\sffamily,keywordstyle=\ttfamily,ndkeywordstyle=\ttfamily,commentstyle=\itshape,frame=,escapechar=\@]{}
InitialPlane(void){
   TYPE2 bg, s1, s2; /* background; state 1; state 2 */
   bg.val = 0;
   bg.fval 0.0;
   s1.val = 1;
   s1.fval = 0.1;
   s2.val = 2;
   s2.fval = 0.2;
   InitialSetS(plane,2,bg,s1,0.3,s2,0.6);
}
\end{lstlisting}
\item{\texttt{void MakePlane(TYPE2*** {\em plane1},...)}}\\ The function
create---i.e.\ allocate memory to---planes. If one wants to use 3
planes, then set \texttt{nplane} to 3 in \texttt{Initial()}, and write
\texttt{MakePlane(\&Plane1,\&Plane2,\&Plane3)} in \texttt{InitialPlane()},
where the name of planes are arbitrary.

\item{\texttt{void Boundaries2(void)}}\\ The function sets boundaries of
the CA. This is necessary only when the boundary type is
\texttt{FIXED}. The value of boundaries is specified in \texttt{Init()}
by assigning an appropriate value to \texttt{boundaryvalues2}.
\end{description}
\subsubsection{Updation\label{sec:updation}}
\begin{description}
    \item{\texttt{void SpaceTimePlot(TYPE2** {\em spacetime},TYPE2**
    {\em plane})}}\\ The function makes a space-time plot. The space-time
    plot will be stored in \texttt{\em spacetime} and created from
    \texttt{\em plane}. The section will be horizontal at \verb|nrow/2|.
    For example, if one writes 
\begin{verbatim}
SpaceTimePlot(STPlot,Plane);
Display(STPlot,Plane);
\end{verbatim}
    then the row at \texttt{row/2} will be copied into a row of
    \texttt{STPlot} so that \texttt{STPlot} is space time plot. The
    other rows of \texttt{Plane} will not be shown in \texttt{STPlot}.
	       
\item{\texttt{void MDiffusion(TYPE2** {\em plane})}}\\ The function does
one step Margolus diffusion on \texttt{\em plane}. Note that all the
(\texttt{f})\texttt{val}'s move together.

\item{\texttt{void ObstacleMargolus(TYPE2** {\em diffusing\_plane}, TYPE2** {\em obstacle\_plane}, int {\em obstacle\_int})}}

%Diffusion with obstacles (entities can not move into
%obstacles). \verb|obstacle_int|. is the obstacle state of the cell (the
%value of \verb|val|). For example, say some cells in \texttt{ObsPlane}
%has state 4 in \verb|val| as obstacles, and one wants to apply
%Margolus diffusion in \texttt{Plane}, then write \texttt{ObstacleMargolus(Plane,ObsPlane,4)}. 
%(By the way, the name of function should have been ObstacleMargolus).

\item{\texttt{void PerfectMix(TYPE2** {\em plane})}} 

The function mixes the plane perfectly. Note that all the
(\texttt{f})\texttt{val}'s move together.

\item{\texttt{void DiffusionFVAL(TYPE2** {\em plane},double {\em
dconst},int {\em fval\_index})}}

The function performs diffusion on the floating number stored in a
chosen variable on \verb|plane|. \verb|fval_index| specifies the
variable; e.g., if \verb|fval_index=3|, then the diffusion is done for
\verb|fval3|. \verb|dconst| is the diffusion constant; note that if the
diffusion constant is too large, the diffusion does not go correct.

\item{\texttt{void Plot(int npl,TYPE2** Plane1,...)}}\\ The function counts the number
of cells which have state 1, 2, $\ldots$ and 15 in \texttt{val}, then it
plots the population of the cells against \texttt{Time} and will show it
on Xmgrace. The default colors of the cell on the graphics, and the
colors of the lines in Xmgrace are corresponding to each other; e.g.,
state 2 is red, the line which shows the population of cells which has
state 2 is also red. The population of state 1 cell will be displayed in
black although state 1 is white in the default graphics. The first
argument is the number of planes on which one wants to count; thus not
necessarily equal to \verb|nplane|; one may not want to count the cells
on space-time plot. From the second argument, one should supply CA
planes on which one wants to count.

\item{\texttt{void PlotArray(double data[15])}}\\ The function plot what
is in \verb|data|. $x$ in \texttt{data[\textrm{$x$}]} corresponds the
set $x$ in Xmgrace. The size of array must be 15. Do not use
\verb|Plot()| function and \verb|PlotArray()| function together. Given
one wants to plot $f(t)=t$, $f(t)=t^2$ and $f(t)=sin(t)$ where $t$ is
time, then an example is as follows.
\begin{lstlisting}[basicstyle=\scriptsize\ttfamily,stringstyle=\sffamily,keywordstyle=\ttfamily,ndkeywordstyle=\ttfamily,commentstyle=\itshape,frame=escapechar=\@]{}
Update(void)
{
  double x[15] = {0.,}; /* This is called an array. If one does this, one can use
                           it like x[0], x[1], ... ,  x[14]. */

  x[0] = Time; /* Time is already defined in the library */
  x[1] = Time*Time;
  x[2] = sin(Time); 
  PlotArray(x); /* Do not put [] after x */
}
\end{lstlisting}
Then, sets s0, s1 and s2 in Xmgrace will get a value of \verb|x[0]|,
\verb|x[1]| and \verb|x[2]| respectively. Sets s3--s14 will get 0.0
always.

\item{\texttt{void PlotXY(double {\em x},double {\em y})}}

The function plots the value of \texttt{x} and \texttt{y} in
Xmgrace. For example, if one writes
\begin{verbatim}
Update(void){
   double number_now;
   double number_before;
   number_before = countGlobal(Plane1,1);
   Asynchronous();
   number_now = countGlobal(Plane1,1);
   PlotXY(number_before,number_now);
}
\end{verbatim}
then, one can draw a Taken's plot with time interval of one, i.e. the
plot of $(x_t,x_{t+1})$ for $x_{t+1}=f(x_t)$.

 \item{\texttt{int countGlobal(TYPE2** {\em plane}, int {\em state})}}

The function counts the number of cells in CA of which \texttt{val} has
state \texttt{{\em state}}. For example, if one writes \texttt{x}
\texttt{=} \texttt{countGlobal(Plane,5)}, then \texttt{x} gets the
number of cells which has state 5 in \texttt{val}. (See also
\texttt{PlotXY()}).

\item{\texttt{void Asynchronous(void)}}\\ The function does one step of
asynchronous updating depending on \verb|NextState()| function.

\item{\texttt{void Synchronous(int {\em npl}, TYPE2** {\em
plane1},...)}}\\ The function does one step of synchronous updating
depending on \verb|NextState()| function. The argument \verb|npl| should
take the number of planes for which updating should be done, and need
not to be the same as \verb|nplane|; one usually does not want to update
a plane for, say, space-time plot, which will be updated by
\verb|SpaceTimePlot()|. The argument \texttt{\em plane1} takes the plane
which one wants to update. If there is more than one, say three planes,
then one can write:
\begin{verbatim}
Synchronous(3,plane1,plane2,plane3);
\end{verbatim}
It is recommended that \texttt{Update(row,col)} should not modify the
state of cells except for the focal cell at \texttt{row,col} when
\texttt{Shynchronous()} is used. Otherwise, the updating is not done
synchronously anymore.
\end{description}
\subsubsection{IO}
\begin{description}
\item{\texttt{void SavePlane(char* {\em filename},TYPE2** {\em
plane},...)}}\\ (currently obsolete)
\item{\texttt{void ReadSavedData(char* {\em filename},int {\em
npl},TYPE2** {\em plane})}}
Despite SavePlane being obsolete, this one still works. You can even type
your own table to use as input. 
\verb|npl| is the number of planes given to the function. Note that
\verb|npl| does not have to be the same as \verb|nplane|, which the
total number of planes. An example is as follows.

\begin{lstlisting}[style=CStyle,basicstyle=\normalsize\ttfamily,stringstyle=\sffamily,keywordstyle=\ttfamily,ndkeywordstyle=\ttfamily,commentstyle=\itshape,frame=escapechar=\@]{}
InitialPlane(void){
   ReadSavedData(``bud.sav'',1,Obstacle);
}
\end{lstlisting}
\end{description}
\section{If-else\label{sec:if-else}}
If-else statements is one of the standard \textbf{control-flow} statements in C, and
control-flow statements control which line of the code is executed
according to arbitrary rules. The usage of the if-else statements is the
following.
\begin{lstlisting}[style=CStyle,caption={if-else statement}]{}
if(@\textrm{condition 1}@){
   @\textrm{orders 1}@
}
else if(@\textrm{condition 2}@){
   @\textrm{orders 2}@
}
else if(@\textrm{condition 3}@){
   @\textrm{orders 3}@
}
.
.
.
else if(@\textrm{condition $n-1$}@){
   @\textrm{orders $n-1$}@
}
else{
   @\textrm{orders $n$}@
}
\end{lstlisting}
If condition 1 is true, then execute orders 1, else if condition 2 is
true, then execute orders 2, ... , else execute orders $n$. The curry
braces surrounding each set of orders tell the program from which line
to which line the program should execute if the condition is true.  One
can put as many \texttt{else if} as one wants. One can also omit
\texttt{else if} and \texttt{else} completely (but not \texttt{if}). To
define the conditions, we use the following primitives:
\begin{itemize}
\item \verb|(a == b)| \hspace{10pt}\texttt{a} is equal to \texttt{b}
\item \verb|(a  > b)| \hspace{10pt}\texttt{a} larger than \texttt{b}
\item \verb|(a >= b)| \hspace{10pt}\texttt{a} is larger than or equal to
      \texttt{b}
\item \verb|(a <  b)| \hspace{10pt}\texttt{a} is smaller than \texttt{b}
\item \verb|(a <= b)| \hspace{10pt}\texttt{a} is smaller than or equal to
      \texttt{b}
\item \verb|(a != b)| \hspace{10pt}\texttt{a} is not equal \texttt{b}
\end{itemize}
In order to combine several conditions such that ``(if
condition 1 is true) AND (if condition 2 is true)'', we can use
the following primitives:
\begin{itemize}
\item \verb|((a==b) && (c==d))| \hspace{10pt}\texttt{a} is equal to
      \texttt{b} AND \texttt{c} is equal to \texttt{d}
\item \verb!((a==b) || (c==d))! \hspace{10pt}\texttt{a} is equal to
      \texttt{b} OR \texttt{c} is equal to \texttt{d}
\end{itemize}
Brackets ``()'' specifies the order of the evaluation. This is like in
mathematics---$1+3\times 5$ is different from $(1+3)\times
5$. Therefore, \verb!((a==b||c==d)&&(a>c))! is different from
\verb!((a==b)||(c==d && a>c))!. Note that the meaning of \texttt{=} and
\texttt{==} is very different.
\section{For-loop}
\textbf{For-loop} is also one of the control-flow statements in C; it is very
useful. In this section, we will see how to use a for-loop. The following
is the example of the usage where one adds 1, 2, 3, $\ldots$ and 10.
\begin{lstlisting}[style=Cstyle,caption={for-loop statement}]{}
x = 0;
for(i=1;i<=10;i=i+1){
   x = x + i;
}
\end{lstlisting}
In the above example, \verb|i| starts from being 1, and the lines within
the curry braces will be executed many times until \verb|i<=10| is not
true anymore; when \verb|i| becomes 11, the execution goes out of the
curry braces. Each time the execution go thorough the loop, \verb|i=i+1|
is executed one; thus \verb|i| increases by 1 in each time.  The result
will be that \verb|x| is 55. By the way, \verb|i| must be defined
somewhere. In the following example, one counts the number of cells of
which \verb|fval| is larger than 5.0.
\begin{lstlisting}[style=CStyle,caption={Counting something}]{}
counter = 0;
for(i=1;i<=nrow;i=i+1){
   for(j=1;j<=ncol;j=j+1){
      if(Plane[i][j].fval > 0.5){
          counter = counter + 1;
      }
   }
}
\end{lstlisting}
\verb|i|, \verb|j| and \verb|counter| must be defined somewhere, but
\verb|nrow| and \verb|ncol| are already defined. Usually, instead of
\verb|i=i+1;|, the statement \verb|i++;| is used, and it has the same
effect---inclement by 1. Therefore, we can also write
\texttt{counter++;} instead of \texttt{counter=counter+1;}
\section{Pseudo random number generator}
\textbf{Pseudo random number generator} is used for stochastic
simulation. The function \texttt{genrand\_real1()} returns a floating
number (\texttt{double} type) randomly between 0 and 1 (both inclusive)
with uniform distribution. If one writes:
\begin{lstlisting}[style=CStyle,caption={Counting something}]{}
if(genrand_real1() < 0.3){
   something1;
}else{
   something2
}
\end{lstlisting}
then \texttt{something1} is executed with a probability 0.3, while
\texttt{something2} is executed with a probability 0.7.


\chapter{FAQ}

\section{Questions on installing \cash}
\noindent Q: I get errors when launching Ubuntu for Windows for the first time\\
A: You probably did not enable all the developer mode options from step 1/5\bigskip

\noindent Q: I do not get any graphs or display when running \cash \\
A: Windows/Mac users, did you install an X server (VcXsrv or Xquartz)? Are you sure it is running? For Windows, is the global DISPLAY variable in $\sim$/.bashrc correctly set to 0:0?\\

\noindent Q: When compiling, it says 'Error: linker/library not found' \\
A: One of the dependencies (see Chapter on Installation) is not corretly installed, or your machine cannot find it. It could be installed in a different location if you're working from your own computer. For the latter, try adjusting the makefiles -I and -L options by adding your paths. \\


Still not working? Contact bramvandijk88 [AT] gmail.com

\section{Questions on programming in \cash}
\begin{itemize}
\item{I want to count things}

\texttt{countGlobal}, for-loop.

\item{I want to plot things}

\texttt{Plot}, \texttt{PlotArray}, \texttt{PlotXY}
\item{I want to repeat something simple many times}

For-loop.

\item{I want to use more than one variables per cell}

See \S\,\ref{section:TYPE2}.

\item{I want to use more than one plane}

\texttt{MakePlanes()}, \texttt{Display()} and \texttt{nplane}.

\item{I want to modify the state of neighbor cells}

\texttt{RandomMooreC8()} and \texttt{RandomMooreP8()}, etc.

\item{I want to do something once in so many time steps}

\texttt{if(Time\%so\_many\_time\_steps==0)}.

\item{Every time a function is called, a variable gets a unknown number}

Initilize the variable.
Put \texttt{static} in front.

\item{How to do stochastic simulation?}

See \S\,Pseudo random number generator.
\end{itemize}

\end{document}
