Skip to content

Commit

Permalink
Simulation Structure - Health Modeling (#12)
Browse files Browse the repository at this point in the history
* Add images for Simulation Structure - Health System

* Add labels to subsection in Simulation Structure

* Write Health System

* Change the name "Health System" for "Health Modeling"

* Update 002_simulation_structure/002_simulation_structure.tex

Co-authored-by: Jason Zheng <[email protected]>

* Update 002_simulation_structure/002_simulation_structure.tex

Co-authored-by: Jason Zheng <[email protected]>

* Update 002_simulation_structure/002_simulation_structure.tex

Co-authored-by: Jason Zheng <[email protected]>

* Update 002_simulation_structure/002_simulation_structure.tex

Co-authored-by: Jason Zheng <[email protected]>

* Update 002_simulation_structure/002_simulation_structure.tex

Co-authored-by: Jason Zheng <[email protected]>

* Update 002_simulation_structure/002_simulation_structure.tex

Co-authored-by: Jason Zheng <[email protected]>

* Update 002_simulation_structure/002_simulation_structure.tex

Co-authored-by: Jason Zheng <[email protected]>

* Update 002_simulation_structure/002_simulation_structure.tex

Co-authored-by: Jason Zheng <[email protected]>

* Update 002_simulation_structure/002_simulation_structure.tex

Co-authored-by: Jason Zheng <[email protected]>

* Update 002_simulation_structure/002_simulation_structure.tex

Co-authored-by: Jason Zheng <[email protected]>

* Update 002_simulation_structure/002_simulation_structure.tex

Co-authored-by: Jason Zheng <[email protected]>

* Update 002_simulation_structure/002_simulation_structure.tex

Co-authored-by: Jason Zheng <[email protected]>

* Update 002_simulation_structure/002_simulation_structure.tex

Co-authored-by: Jason Zheng <[email protected]>

* Update 002_simulation_structure/002_simulation_structure.tex

Co-authored-by: Jason Zheng <[email protected]>

* Update 002_simulation_structure/002_simulation_structure.tex

Co-authored-by: Jason Zheng <[email protected]>

* Update 002_simulation_structure/002_simulation_structure.tex

Co-authored-by: Jason Zheng <[email protected]>

* Update 002_simulation_structure/002_simulation_structure.tex

Co-authored-by: Jason Zheng <[email protected]>

* Update 002_simulation_structure/002_simulation_structure.tex

Co-authored-by: Jason Zheng <[email protected]>

* Update 002_simulation_structure/002_simulation_structure.tex

Co-authored-by: Jason Zheng <[email protected]>

* \usepackage{listings} added

* change label name - no multiple same label names

* update packages and fix warnings/errors

* Address comments of the PR. Referring to important equations in the text

* Add Golang listings package

Co-authored-by: Jason Zheng <[email protected]>
  • Loading branch information
mdubied and jzzheng22 authored Jan 5, 2022
1 parent c4c5dad commit db80c69
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 25 deletions.
104 changes: 99 additions & 5 deletions 002_simulation_structure/002_simulation_structure.tex
Original file line number Diff line number Diff line change
@@ -1,14 +1,108 @@
\chapter{Simulation Structure}\label{simulation_structure}

\section{Simulation Environment}
%%%%%%%%
%%%%%%%% Simulation Environment
%%%%%%%%
\section{Simulation Environment}\label{simulation_environment}
Goes over the backend design

\section{Simulation Flow}
%%%%%%%%
%%%%%%%% Simulation Flow
%%%%%%%%
\section{Simulation Flow}\label{simulation_flow}
The order in which events happen
Need a nice diagram for this

\section{Message Passing}
%%%%%%%%
%%%%%%%% Message Passing
%%%%%%%%
\section{Message Passing}\label{message_passing}
Need a nice diagram for this

\section{Health Decay System}
Need a nice diagram for this
%%%%%%%%
%%%%%%%% Health Modeling
%%%%%%%%
\section{Health Modeling}\label{health_modeling}

\ToDo{Add diagram with a possible scenario of several days in a row?}

%
%%%%%%%% Global Description
%
\subsection{Global Description}

The health of the agents living in the tower is represented by Health Points (HP). Two mechanisms affect an agent's HP: how much food they eat, and their ``cost of living''. The cost of living represents how many calories a human needs to eat each day to stay healthy. These two mechanisms are implemented using the functions \lstinline$updateHP$ and \lstinline$hpDecay$, respectively. These two functions are described below.

At the end of each day, agents are assigned an HP value based on how much food they have eaten and their cost of living. This HP value is an integer and has a maximum value of \lstinline$MaxHP$, and a minimum value of \lstinline$HPCritical$. As its name suggests, \lstinline$HPCritical$ is a critical HP value for the agents: they can only survive a certain number of days (\lstinline$MaxDayCritical$) at this level. When in the critical state, if agents can increase their HP by \lstinline$HPReqCToW$ (``HP Required to move from Critical To Weak''), then they move into the ``weak state'' (\Cref{fig:health_system}), and their HP takes the value of \lstinline$WeakLevel$. The amount that an agent's HP increases from eating is determined by the function \lstinline$updateHP()$.

\begin{figure}[htb]
\centering
\includegraphics[width=0.3\linewidth]{002_simulation_structure/images/health_global.pdf}
\caption{The health of the agents is represented by a HP value between \lstinline$HPCritical$ and \lstinline$MaxHP$. All HP values which are below \lstinline$WeakLevel$ are classed as critical. The diagram is not drawn to scale.}
\label{fig:health_system}
\end{figure}

\subsection{Food and Health: \texorpdfstring{\lstinline$updateHP$}{updateHP}}\label{updateHP}
To increase their HP, agents need to eat. However, the amount an agent's HP improves can saturate in a single day; eating more than a certain amount will provide an agent with no extra benefit to their HP. Moreover, eating more food will lead to diminishing returns in terms of HP change. Mathematically, the ideas of diminishing returns and saturation are well captured by the step response of a 1st-order system \eqref{updateHP_general}:

\begin{equation}\label{updateHP_general}
\text{newHP}= \text{currentHP} +\underbrace{w(1-e^{\frac{-\text{foodTaken}}{\tau}})}_{\text{HPChange}}
\end{equation}

The two parameters $w$ and $\tau$ are defined at the beginning of the simulation. The shape of this curve is given in \Cref{fig:updateHP} together with some important parameters.

\begin{figure}[htb]%
\centering
\subfloat[\centering Overview]{{\includegraphics[width=0.36\linewidth]{002_simulation_structure/images/health_updateHP_overview.pdf}}}%
\qquad
\subfloat[\centering Detailed representation]{{\includegraphics[width=0.36\linewidth]{002_simulation_structure/images/health_updateHP_detailed.pdf}}}%
\caption{\texttt{updateHP} as a function of the amount of food eaten (``FoodTaken'').}%
\label{fig:updateHP}%
\end{figure}

It is not possible to gain more HP than $w$ over the duration of one day; this is an intentional limit to prevent an agent's health from improving too quickly. As an example, we can think of an agent that starts from the weak level and wants to reach the maximum HP value. It would take several days for this agent to ``recover'' from this weak level and stabilise its health to a high HP value.

Note that it is possible for an agent to achieve an HP value that is larger than \texttt{MaxHP} inside \lstinline$hpDecay()$. At the end of each day, the \lstinline$hpDecay()$ function will apply the cost of living and then bound the final HP value by \lstinline$MaxHP$.


Agents in the critical state are treated differently. For these agents, HP is updated according to equation \eqref{updateHP_critical}:

\begin{equation}\label{updateHP_critical}
\text{newHP} = \min\left\{\text{HPCritical}+\text{HPReqCToW}, \text{currentHP} +w(1-e^{\frac{-\text{foodTaken}}{\tau}})\right\}
\end{equation}

\subsection{Cost of Living: \texorpdfstring{\lstinline$hpDecay()$}{hpDecay}}\label{hpDecay}
At the end of each day, the HP value of the agents will be reduced by the cost of living. The cost of living is larger for an agent with larger HP value than for an agent with lower HP value. This fact is motivated by a simple observation: humans that have stronger bodies and immune systems also need more food to sustain their level of health. The exact relation between HP value, cost of living, and HP value after applying the cost of living is given by the linear relation \eqref{hpDecay_equation}:

\begin{equation}\label{hpDecay_equation}
\text{newHP} = \text{currentHP}-\left[b + s(\text{currentHP}-\text{WeakLevel})\right]
\end{equation}


The parameter $b$ is a (constant) base cost, and $s$ is the slope of the linear function. These parameters are initialised at the beginning of the simulation. \ToDo{Add a diagram for this?}

To ensure that the HP value at the end of the day is bounded by \texttt{MaxHP}, we slightly modify (\ref{hpDecay_equation}) to produce (\ref{hpDecay_bounded}):

\begin{equation}\label{hpDecay_bounded}
\text{newHP} =\max\left\{\text{MaxHP}, \text{currentHP}-\left[b + s(\text{currentHP}-\text{WeakLevel})\right]\right\}
\end{equation}

For agents in the critical state that gain \texttt{HPReqCToW} HP in a single day, i.e. their HP after eating is

\begin{equation}\label{HPReqCToW}
\text{currentHP} \geq \text{HPCritical}+\text{HPReqCToW},
\end{equation}

their HP will be set to \texttt{WeakLevel}:

\begin{equation}\label{hpDecay_critical_upgrade}
\text{newHP} = \text{WeakLevel}
\end{equation}

Agents in the critical state which do not manage to improve their HP by \lstinline$HPReqCToW$ will be kept in the critical state:

\begin{equation}\label{hpDecay_critical_stay}
\text{newHP} = \text{HPCritical}
\end{equation}

with the \texttt{daysAtCritical} counter incremented by 1. If \texttt{daysAtCritical} reaches \texttt{MaxDayCritical}, the agent dies and is replaced. This counter is reset to 0 if an agent exits the critical state.
Binary file added 002_simulation_structure/images/health_global.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
23 changes: 23 additions & 0 deletions listings-golang.sty
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
%% Golang definition for listings
%% http://github.io/julienc91/lstlistings-golang
%%
\RequirePackage{listings}

\lstdefinelanguage{Golang}%
{morekeywords=[1]{package,import,func,type,struct,return,defer,panic,%
recover,select,var,const,iota,},%
morekeywords=[2]{string,uint,uint8,uint16,uint32,uint64,int,int8,int16,%
int32,int64,bool,float32,float64,complex64,complex128,byte,rune,uintptr,%
error,interface},%
morekeywords=[3]{map,slice,make,new,nil,len,cap,copy,close,true,false,%
delete,append,real,imag,complex,chan,},%
morekeywords=[4]{for,break,continue,range,go,goto,switch,case,fallthrough,if,%
else,default,},%
morekeywords=[5]{Println,Printf,Error,Print,},%
sensitive=true,%
morecomment=[l]{//},%
morecomment=[s]{/*}{*/},%
morestring=[b]',%
morestring=[b]",%
morestring=[s]{`}{`},%
}
Binary file added main.pdf
Binary file not shown.
56 changes: 36 additions & 20 deletions main.tex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
\documentclass[a4paper,11pt]{report}
\usepackage[utf8]{inputenc}
\usepackage[a4paper, top=3cm, bottom=3cm, left=2.5cm, right=2.5cm, marginparwidth=2cm, headsep=1.2cm]{geometry} % layout
\usepackage[bookmarks=true]{hyperref} % enables hyperlinks in the PDF
\usepackage[pdfencoding=auto]{hyperref} % enables hyperlinks in the PDF
\hypersetup{colorlinks=true, linkcolor=black, urlcolor=blue, citecolor=black} \urlstyle{same}
\usepackage{amsmath}
\usepackage{cleveref} \Crefformat{figure}{#2Fig.~#1#3} % makes referencing customizable (e.g. \Cref{}). See: https://texblog.org/2013/05/06/cleveref-a-clever-way-to-reference-in-latex/)
Expand All @@ -26,6 +26,22 @@
\usepackage{amsfonts}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{listings}
\usepackage{listings-golang}

\lstset{
language=golang,
showstringspaces=false,
columns=flexible,
basicstyle={\small\ttfamily},
numbers=none,
numberstyle=\tiny\color{mygray},
keywordstyle=\color{blue},
commentstyle=\color{mygreen},
stringstyle=\color{mymauve},
breakatwhitespace=true,
tabsize=4
}

\usepackage[ruled,vlined,linesnumbered]{algorithm2e}
\usepackage{siunitx}
Expand All @@ -38,7 +54,7 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Author
% Use \\ to separate multiple authors (e.g. Robert\\Nathalie\\Mike)
\newcommand{\myName}{SOMAS Class 2021-2022}
\newcommand{\myName}{SOMAS Class 2021--2022}

% Title
% Introduce line breaks with \\
Expand All @@ -53,7 +69,7 @@
% Supervisors
% Use \\ to separate multiple supervisors (e.g. Robert\\Nathalie\\Mike)
% Use full titles (e.g. Prof. Dr., Dr. )
\newcommand{\supervisors}{Prof. Jeremy Pitt}
\newcommand{\supervisors}{Prof.\ Jeremy Pitt}

% ToDo Command
\newcommand{\ToDo}[1]{\textcolor{red}{#1}}
Expand All @@ -79,23 +95,22 @@

\tikz[remember picture,overlay] \node[opacity=1,inner sep=0pt, anchor=west] (A) at (2cm,-1.5cm){\includegraphics[scale=0.5]{template_figures/logo.eps}};

\begin{center}
\vspace*{6cm}
\huge \textbf{\thesisType}\\
\vspace*{0.75cm}
\Huge \myTitle\\
\vspace{0.5cm}
\Large {Department of Electrical and Electronic Engineering}\\
\Large {Imperial College London}\\
\vspace*{5cm}
\huge \myName\\
\vspace*{0.5cm}
\LARGE \myDate\\
\vfill
Lecturer\\
\vspace*{0.5cm}
\huge \supervisors
\end{center}
\begin{center}
\vspace*{6cm}
\huge \textbf{\thesisType}\\
\vspace*{0.75cm}
\Huge \myTitle\\
\vspace{0.5cm}
\Large {Department of Electrical and Electronic Engineering}\\
\Large {Imperial College London}\\
\vspace*{5cm}
\huge \myName\\
\vspace*{0.5cm}
\LARGE \myDate\\
\vfill
Lecturer\\
\vspace*{0.5cm}
\huge \supervisors\end{center}

\end{titlepage}

Expand Down Expand Up @@ -140,6 +155,7 @@

% References
\newpage
\nocite{*}
\bibliography{references}
\bibliographystyle{IEEEtranN}

Expand Down

0 comments on commit db80c69

Please sign in to comment.