CarbMetSim: A discrete-event simulator for carbohydrate metabolism in humans

This paper describes CarbMetSim, a discrete-event simulator that tracks the blood glucose level of a person in response to a timed sequence of diet and exercise activities. CarbMetSim implements broader aspects of carbohydrate metabolism in human beings with the objective of capturing the average impact of various diet/exercise activities on the blood glucose level. Key organs (stomach, intestine, portal vein, liver, kidney, muscles, adipose tissue, brain and heart) are implemented to the extent necessary to capture their impact on the production and consumption of glucose. Key metabolic pathways (glucose oxidation, glycolysis and gluconeogenesis) are accounted for in the operation of different organs. The impact of insulin and insulin resistance on the operation of various organs and pathways is captured in accordance with published research. CarbMetSim provides broad flexibility to configure the insulin production ability, the average flux along various metabolic pathways and the impact of insulin resistance on different aspects of carbohydrate metabolism. The simulator does not yet have a detailed implementation of protein and lipid metabolism. This paper contains a preliminary validation of the simulator’s behavior. Significant additional validation is required before the simulator can be considered ready for use by people with Diabetes.


Introduction
More than 400 million people world wide suffer from diabetes [1]. People with Type 2 Diabetes (around 90% of total diabetic population [1]) usually have at least some ability to produce insulin, however their bodies develop insulin resistance and hence are not able to react strongly enough to the presence of insulin in blood to keep the blood glucose level (BGL) under control. On the other hand, people with Type 1 Diabetes cannot produce insulin endogenously at all and hence must receive external insulin regularly. Keeping BGL under control is a constant struggle for people with diabetes. One wrong meal choice may result in very high BGL and an accompanying feeling of sickness for several hours. Persistently high BGL would ultimately cause a number of severe complications such as heart/kidney failure, blindness and limb a1111111111 a1111111111 a1111111111 a1111111111 a1111111111 amputations. Those using external insulin may suffer life threatening hypoglycemic incidents if too much insulin is injected. Physical exercise allows the muscles to use glucose in the blood even in the absence of insulin but exercise activities need to be carefully coordinated with food and medication intake so as to avoid hypoglycemia. For people with Type 1 Diabetes, physical exercise may even worsen the state of hyperglycemia. In general, people with diabetes need help deciding how they should plan their food and exercise activities so as to keep their BGL under control. There is a real need for tools that help diabetic people understand the impact a particular sequence of food and exercise activities would have on their BGL. Continuous BGL monitoring solutions, now offered by a number of vendors, can significantly help but are either not easily available to a vast majority of diabetic people world-wide or are simply too expensive. Clearly, one solution is to build simulation tools that use our vast knowledge of energy metabolism in human beings to give reasonably accurate prediction of the impact of a diet/exercise sequence on some one's BGL. A few such simulators already exist [2,3] but are geared towards predicting the impact of individual meals and are not available in a format that can be freely used by individuals. This paper describes CarbMetSim (the Carbohydrate Metabolism Simulator), an open-source and freely available [4] simulation software that predicts minute by minute BGL in response to an arbitrary length sequence of food and exercise activities. While the existing simulation tools are based on continuous time models that use differential and algebraic equations to describe physiological details, CarbMetSim is based on a discrete event model where the time increments in units (called ticks) one minute long. At the beginning of each tick, CarbMetSim fires the food/exercise events that need to be fired at this time and directs various simulated body organs to do the work they are supposed to do during this tick.
CarbMetSim implements broader aspects of carbohydrate metabolism in human beings with the objective of capturing the average impact of various diet/exercise activities on the BGL of people with different levels of diabetes. The simulator implements key organs (stomach, intestine, portal vein, liver, kidney, muscles, adipose tissue, brain and heart) to the extent necessary to capture their impact on the production and consumption of glucose. Key metabolic pathways (glucose oxidation, glycolysis and gluconeogenesis) are accounted for in the operation of different organs. The impact of insulin and insulin resistance on the operation of various organs/pathways is captured in accordance with published research. CarbMetSim provides broad flexibility to configure the insulin production ability, the average flux along various metabolic pathways and the impact of insulin resistance on different aspects of carbohydrate metabolism. Thus, it is possible to customize the simulator for a particular user by setting appropriate values to various configurable parameters.
CarbMetSim is not yet a finished product. The protein and lipid metabolism are implemented in a very simplified manner. The simulator does not yet consider monosaccharides other than glucose and assumes that all dietary carbohydrate gets converted to glucose after digestion. The impact of insulin is captured in a simplified manner and other important hormones (e.g. glucagon) are not yet directly modeled. Impact of externally injected short term insulin is not modeled yet. Only aerobic exercise activities can be simulated at present. The simulator is not yet capable of translating a user's diet/exercise/BGL data into the values of simulation parameters governing the behavior of different organs. This paper provides a preliminary validation of CarbMetSim's behavior. Significant additional validation against continuous blood glucose data of individuals representing different demographic groups, different types & levels of Diabetes and different lifestyles is needed before the simulator may be considered ready for use in diabetes self-management applications or for research.
ODEs with insulin and 1 ODE with glucagon. Parker et al. [34,35] updated the Guyton/Sorensen models by accounting for uncertainty in parameter values and by including a model for gastric emptying of carbohydrates in a meal [36]. Hovorka et al. [37] developed a multi-compartment model of glucose and insulin kinetics as part of a model predictive controller for subcutaneous insulin infusion for people with Type 1 Diabetes. This model consists of a twocompartment glucose subsystem (accounting for glucose absorption, distribution and disposal), a two-compartment insulin subsystem (accounting for insulin absorption, distribution and disposal) and an insulin action subsystem (accounting for insulin action on glucose transport, disposal and endogeneous production).
Dalla Man et al. [38] developed a model that related the plasma concentrations of glucose and insulin to various glucose and insulin related rates (the rate of appearance of glucose from the gastro-intestinal tract, the rate at which the glucose is produced by liver and kidney, insulin dependent and independent rates of glucose utilization, the rate of renal extraction of glucose, the rate of insulin secretion by beta cells and the rate of insulin degradation). The parameters of this model were determined using the experimental data collected for 204 normal and 14 Type 2 Diabetic subjects. This model was used to simulate patient behavior in UVA/PADOVA Type 1 Diabetes Simulator [2] aimed at investigating the closed control strategies for insulin pumps. A new version of UVA/PADOVA Type 1 Diabetes Simulator [3] modifies Dalla Man's model by incorporating glucagon secretion/action/kinetics and nonlinear increase in insulin dependent glucose utlization as BGL dips below the normal range.
The CarbMetSim simulator presented in this paper is physiologically complex just like the models presented by Tiran et al. [32], Guyton et al. [33], Sorensen [23] and Dalla Man [38].
The key difference is that CarbMetSim implements the physiological details in software with various body organs implemented as objects whereas the existing models used ODEs to model physiological details. It can be argued that implementing physiological details in software allows for much more complex behavior to be taken in account than what is possible using ODEs. Moreover, it is much easier to modify physiological behavior implemented in software than via ODEs. In that sense, the presented simulator is an improvement over existing ODE based approaches. It is hoped that these benefits coupled with its open-source nature will allow CarbMetSim to emerge as a popular simulation model of human metabolism for both diabetes research and self-management tools for diabetic people.

Key aspects in CarbMetSim design
In the following, we describe some of the key aspects of CarbMetSim's design.

Food, exercise and human subject description
In CarbMetSim, a food is described in terms of its serving size and the amount of rapidly available glucose (RAG), slowly available glucose (SAG), protein and fat per serving. The RAG contents include sugars and the rapidly digestible starch (i.e. starch that gets digested in vitro within 20 minutes [39,40]). The SAG contents include the slowly digestible starch (i.e. starch that gets digested in vitro between 20 and 120 minutes [39,40]). In general, the starch with high amylopectin to amylose ratio is classified as rapidly digestible starch whereas the one with high amylose to amylopectin ratio is classified as slowly digestible starch. The non-starch polysaccharide (also known as dietary fiber) part of the carbohydrates is currently ignored (even though the fiber contents of the food are known to have an impact on the gastric emptying). CarbMetSim currently does not have a detailed implementation of the protein and lipid metabolism. However, it does model the impact of protein and fat contents of food on gastric emptying. Hence, the food description should include the total amount of protein and total amount of fat per serving. CarbMetSim currently does not characterize protein in terms of its amino acid contents. Since only 3 of the 20 amino acids have branched chains, a general assumption is made that 85% of amino acids resulting from protein digestion have unbranched chains and the remaining have branched chains [41].
CarbMetSim can currently simulate only aerobic exercises. In CarbMetSim, an exercise activity is described in terms of its intensity in units of Metabolic Equivalent of Task or METs, where 1 MET is 1 kcal of energy expenditure per kg of body weight per hour. By convention, 1 MET is considered equivalent to 3.5ml of oxygen consumption per kg of body weight per minute. Each individual has a certain maximal rate at which he/she can consume oxygen. This individual-specific maximal rate, called VO 2 max, depends on the gender, age and fitness level of the individual [42]. The intensity of an exercise activity in terms of the associated oxygen consumption rate (described as the%age of the individual's VO 2 max, henceforth referred to as %VO 2 max) determines to a large extent the relative fraction of the glucose and fatty acids oxidized to meet the energy needs of the exercising muscles. Thus, CarbMetSim needs to know the gender, age and (self-assessed) fitness level within the age group.of the human subject being simulated. This information is used to estimate the VO 2 max for the human subject using the tables in Kaminsky et al. [42].

Modeling insulin production
The insulin level in blood generally depends on the BGL. If the BGL is high, the insulin level increases as well so as to signal the liver and the muscles to absorb glucose from the blood stream and also to signal both the liver and the kidneys to slow down or stop the endogeneous glucose production via glycogen breakdown and gluconeogenesis. Also, the insulin level in blood decreases in response to physical exercise [43,[44][45][46][47] so as to signal the liver and the kidneys to ramp up the endogeneous glucose production. In CarbMetSim, the current insulin level in the blood is represented by a variable called insulinLevel (inside the Blood object) that assumes values between 0 and 1. The value of insulinLevel depends on the current BGL, the current exercise intensity (in%VO 2 max) and a number of configurable parameters: minGluco-seLevel_ (typical hypoglycemic BGL), baseGlucoseLevel_ (typical fasting BGL), highGlucoseLe-vel_ (typical peak BGL) (minGlucoseLevel_ < baseGlucoseLevel_ < highGlucoseLevel_), baseInsulinLevel_ (representing the typical fasting insulin level), peakInsulinLevel_ (representing typical insulin level when BGL is at peak) (where 0 � baseInsulinLevel_ � peakInsulinLe-vel_ � 1), restIntensity_ (the oxygen consumption rate in%VO 2 max when the individual is not exercising, by default 2 METs converted to%VO 2 max) and intensityPeakGlucoseProd_ (the exercise intensity in%VO 2 max at which the liver and kidney produce glucose at the maximum rate, by default 20%). The following rules govern the value of insulinLevel: • If the current BGL is less than or equal to the minGlucoseLevel_, the insulinLevel stays at value zero.
• If the current BGL is between the minGlucoseLevel_ and the baseGlucoseLevel_, the insulin-Level depends on whether the individual being simulated is currently engaged in exercise or not. If the individual is exercising and • if the exercise intensity is greater than or equal to intensityPeakGlucoseProd_, the insulin-Level stays at zero.
• otherwise, the insulinLevel depends on the exercise intensity. As the exercise intensity decreases from intensityPeakGlucoseProd_ to the the restIntensity_, the insulinLevel increases linearly from zero to the baseInsulinLevel_.
If the individual is not exercising, as the BGL increases from minGlucoseLevel_ to baseGlu-coseLevel_, the insulinLevel increases linearly from zero to the baseInsulinLevel_.
• As the BGL increases from the baseGlucoseLevel_ to the highGlucoseLevel_, the insulinLevel increases linearly from the baseInsulinLevel_ to the peakInsulinLevel_.
• If the BGL is greater than or equal to the highGlucoseLevel_, the insulinLevel stays at the pea-kInsulinLevel_ value.
In CarbMetSim, the peakInsulinLevel_ represents the peak ability to produce insulin. A value 1 for peakInsulinLevel_ means normal (or excessive, as in the case of initial stages of Type 2 Diabetes) insulin production, whereas a value 0 means that the pancreas does not produce any insulin at all (as in people with Type 1 Diabetes). A value x (between 0 and 1) for pea-kInsulinLevel_ means that peak insulin production is just x times the normal peak.
As described in the later sections, the insulinLevel variable has a profound impact on the operation of different organ objects in CarbMetSim. So, its value should be interpreted in terms of the impact it has on various organ objects, rather than the actual insulin concentration it corresponds to for a particular person. So, it is entirely possible that two very different actual insulin concentrations for two individuals map to the same value for the insulinLevel because they have the same impact on carbohydrate metabolism related functions of the organs.
In CarbMetSim's current implementation, the insulinLevel variable is tightly coupled with the BGL in the manner described above. A future implementation will allow the insulinLevel to vary in a configurable manner by allowing the user to specify the dosage of externally injected short term insulin. This would allow the simulator to be useful for diabetes patients dependent on short term insulin injections or insulin pumps.

Modeling glucose transport
Glucose crosses cell membranes using either active transporters or passive ones. The active transporters, such as Sodium GLucose coTransporters (SGLTs) are able to move glucose from a low concentration to a high concentration. The passive transporters, such as Glucose Transporters (GLUTs) move glucose from a high concentration to a low concentration. CarbMetSim models the operation of active transporters in an organ by specifying the average amount of glucose transferred per minute via active transport. The actual amount transferred is a poisson distributed random variable. The simulator uses Michaelis Menten kinetics to determine the amount of glucose transferred in a minute via passive transport. As per the Michaelis Menten kinetics, the rate of transport (V) across a membrane depends on the difference in the substrate concentration (Y) across the membrane in the following manner: is the maximum rate of transport and K m is the substrate concentration difference at which the transport rate is half the maximum. The V max value associated with a GLUT transporter in an organ indicates the number of transporters involved. Hence, the simulator treats V max associated with a particular GLUT in a particular organ as a poisson distributed random variable with a configurable mean.

Modeling GLUT4 operation in muscles.
Among the GLUTs, the GLUT4 transporters are of particular importance because they allow the muscles to absorb glucose from the bloodstream. When the human body is engaged in exercise, the physical activity itself activates sufficient number of GLUT4 transporters [48][49][50] and the muscles are able to absorb the desired amount of glucose from the bloodstream. CarbMetSim replicates this behavior. However, in the resting state, the number of active GLUT4 transporters depends on the insulin level in the bloodstream. When the insulin level is low (because of low BGL), GLUT4 transporters are inactive and the muscles do not absorb much glucose from the bloodstream. As the insulin level rises in the blood (in response to increase in BGL), GLUT4 transporters become active proportionately and allow the muscles to quickly absorb excess glucose from the blood.
In CarbMetSim, GLUT4 activation during the resting states is modeled by manipulating the V max value associated with GLUT4 transporters in the following manner: • Since a large fraction of the absorbed glucose is converted to glycogen inside muscles and there is a limit on how much glycogen can be stored inside muscles, the current amount of muscle glycogen impacts the V max value. Specifically, as the muscle glycogen storage increases from zero to a configurable maximum value, the V max value reduces linearly from a configurable maximum (7 mg/kg/min by default) to a configurable minimum (3.5 mg/kg/ min by default).
• The impact of insulin level is captured by multiplying the V max value with a factor (between 0 and 1) that increases in value with increase in the insulinLevel. Currently, the insulinLevel itself is used as the value of this factor. Since vigorous physical exercise causes temporary increase in glucose absorption by muscles [51] to make up for the glycogen lost during exercise), the insulinLevel does not impact the V max value in the first hour after an intense physical exercise activity (unless the current BGL drops below the baseGlucoseLevel_).
• The impact of insulin resistance in reducing the activation of GLUT4 transporters is modeled by multiplying the the V max value with a configurable parameter (glut4Impact_) that assumes values between 0 and 1 (by default 1.0).

Modeling glycolysis
Glucose serves as a key source of energy for various tissues, which either oxidize it completely or consume it anaerobically via glycolysis. Complete oxidation of glucose yields 15 times more energy than anaerobic glycolysis but can only be done if oxygen is available. Tissues with access to plenty of oxygen oxidize glucose for their energy needs whereas others (possibly in the same organ) use glycolysis. Glycolysis results in the generation of lactate, which serves as a key substrate for endogenous glucose production via gluconeogenesis (described later).
The following organs in CarbMetSim use anaerobic glycolysis as an energy source: Muscles, Liver, Kidneys, Intestine and Blood. The amount of glucose consumed for glycolysis increases with the glucose availability, which is signaled by the insulin level in the bloodstream. This is modeled in the simulator in the following manner. Each organ using glycolysis as an energy source has two configurable parameters: glycolysisMin_ and glycolysisMax_ (in units of mg of glucose consumed per kg of body weight per minute). At each tick, the organ generates a poisson distributed random number (min) with glycolysisMin_ as the mean value and glycolysis-Max_ as the maximum value. Then, subject to the glucose availability in the organ, the amount of glucose consumed in a tick for glycolysis is given by: min + insulinImpact × (glycoly-sisMax_ − min). Here, insulinImpact is a factor (between 0 and 1) that increases in value with increase in the insulinLevel. This factor is calculated using a sigmoid function, which is currently the CDF of a normal distribution with a configurable mean and standard deviation. The simulator also uses configurable multiplicative parameters glycolysisMinImpact_ and glycolysis-MaxImpact_ (with default values 1.0) to modify the values of glycolysisMin_ and glycolysis-Max_ parameters associated with each organ. These parameters can be used to model the impact of diabetes on glycolysis flux. A fraction (by default 1) of the glucose consumed for glycolysis is converted to lactate, which is added to the Blood object. Table 1 shows the default values for glycolysis related parameters for different organs. Here, the relative contributions of different organs towards overall glycolysis flux were set as suggested in [52,53]. The default values of various configurable parameters in CarbMetSim were determined experimentally to provide a close match with published measurements performed on non-diabetic human subjects before and after a meal event [54].

Modeling gluconeogenesis
Gluconeogenesis is a metabolic pathway that allows the liver and kidneys to produce glucose from lactate, glycerol, glutamine and alanine [40,55]. This pathway assumes special significance as the only source of glucose when no new glucose is arriving in the body via food and the glycogen store in the liver has been exhausted.
Normally, gluconeogenesis occurs when the insulin level is low (i.e. in the post-absorptive state). However, diabetic people may experience high gluconeogenesis flux even in the postprandial state when the insulin level is high [56,57].
In CarbMetSim, the Liver and the Kidneys produce glucose via gluconeogenesis at configurable average rates (gngLiver_ and gngKidneys_ respectively, 0.16 mg/kg/minute each by default) using substrates mentioned above. When the insulinLevel is above the baseInsulinLe-vel_ (i.e. the BGL is more than the baseGlucoseLevel_), the average gluconeogenesis flux is multiplied by a factor (between 0 and 1) that decreases in value with increase in the insulinLevel as per an inverse sigmoid function (currently, the complementary CDF of a normal distribution with a configurable mean and standard deviation). This allows us to model the decrease in gluconeogenesis flux with increase in the insulin level. On the other hand, if the insulinLevel is below the baseInsulinLevel_ (i.e. the BGL is below the baseGlucoseLevel_), the average gluconeogenesis flux is multiplied by a factor that decreases in value from a configurable maximum (gngImpact_ � 1, by default 6.0) to the minimum value 1 as the insulinLevel increases from zero to the baseInsulinLevel_. This allows us to model the increased gluconeogenesis flux when BGL is low and gluconeogenesis is probably the only source of glucose for the body. The simulator currently assumes that the substrates are always available in sufficient quantity to allow gluconeogenesis to take place in the manner described above.

Modeling liver glycogen synthesis & breakdown
In human body, the liver helps maintain glucose homeostasis by storing excess glucose in blood during the post-prandial state (when the insulin levels are high) as glycogen and releasing glucose to the blood during the post-absorptive and exercising states (when insulin level is low) by breaking down the stored glycogen. Diabetes may effect both glycogen synthesis and breakdown in the liver.
Subject to the availability of glucose, the amount of glycogen synthesized by the Liver object in CarbMetSim simulator during each tick is a poisson distributed random variable with a configurable average (glucoseToGlycogenInLiver_, 4.5 mg/kg/min by default) that is modified multiplicatively by two factors. The first factor models the impact of insulin on glycogen synthesis. This factor (with values between 0 and 1) increases in value with increase in the insulin-Level and is calculated using a sigmoid function, which is currently the CDF of a normal distribution with a configurable mean and standard deviation. The second factor called liver-GlycogenSynthesisImpact_ (by default 1.0) simply modifies the configured average multiplicatively and can be used to model the impact of diabetes on glycogen synthesis in the liver. The Liver object has a finite capacity to store glycogen and hence any excess glycogen is converted to fat and stored in the AdiposeTissue object. Glycogen breakdown in the liver serves as the key source of glucose when no new glucose is entering the body via food or when the glucose needs of the body increase due to intense physical exercise. Accordingly, in CarbMetSim, the amount of glycogen stored in the Liver that is broken down to glucose during a tick closely depends on the insulinLevel (and hence on the current BGL). When the insulinLevel is above the baseInsulinLevel_ (i.e. the BGL is more than the baseGlucoseLevel_), the average glycogen breakdown flux in the Liver (glycogenToGluco-seInLiver_, 0.9 mg/kg/min by default) is multiplied by a factor (between 0 and 1) that decreases in value with increase in the insulinLevel as per an inverse sigmoid function (currently, the complementary CDF of a normal distribution with a configurable mean and standard deviation). This allows us to model the decrease in liver glycogen breakdown with increase in the insulin level. On the other hand, if the insulinLevel is below the baseInsulinLevel_ (i.e. the BGL is below the baseGlucoseLevel_), the average Liver glycogen breakdown flux is multiplied by a factor that decreases in value from a configurable maximum (liverGlycogenBreakdownImpact_ � 1, by default 6.0) to the minimum value 1 as the insulinLevel increases from zero to the base-InsulinLevel_. This allows us to model the increased liver glycogen breakdown when BGL is low.

CarbMetSim design and implementation
CarbMetSim is a discrete event simulator implemented in an object-oriented manner. At the top level, CarbMetSim consists of a SimCtl (SIMulation ConTroLler) object and a HumanBody object. The SimCtl object maintains the simulation time (in ticks, where each tick is a minute) and contains a priority queue of food/exercise events sorted in order of their firing times. At the beginning of the simulation, the SimCtl object reads all the food/exercise events into the priority queue. At each tick, the SimCtl object fires the events whose firing time has arrived (by invoking appropriate methods on the HumanBody object) and then causes each organ to do its work during that tick (again by invoking a HumanBody object method).
In the following, we describe the implementation and operation of various objects that together implement the CarbMetSim simulator. The default values of various parameters listed here were determined experimentally to provide a close match with published measurements performed on non-diabetic human subjects before and after a meal event [54]. Validation of simulation results against these and other published measurements is described in later sections. Table 1 shows the default values for glycolysis related parameters for different organs. Default values of configurable parameters that determine the impact of insulinLevel on various metabolic processes are shown in Table 2.

HumanBody
The HumanBody object serves as the container for following organ objects: Stomach, Intestine, PortalVein, Liver, Kidneys, Muscles, AdiposeTissue, Brain, Heart and Blood. At the beginning of a simulation, the HumanBody object does the following: • It reads the description of various foods: their composition in terms of rapidly/slowly available glucose (RAG/SAG), protein and fat.
• It reads the description of various exercise activities: their intensity in units of METs.
• It estimates the maximal rate of glucose consumption (VO 2 max, see Section 4.8) associated with the individual being simulated using the tables in Kaminsky et al. [42] given this individual's gender, age and self-assessed fitness level within his/her age group, which are all supplied as simulation parameters.
• It reads other simulation parameters that affect the operation of different organs.
The HumanBody contains methods that cause the food to be added to the stomach when SimCtl fires a food event and update the energy needs of the body when SimCtl fires an exercise event. When an exercise event gets over, the HumanBody resets the energy needs to the resting state. When the Stomach has no food left, it informs the HumanBody about the situation. Thus, at any given time, the HumanBody remembers whether the stomach has some undigested food (Fed) or not (PostAbsorptive) and whether the body is currently engaged in some exercise (Exercising) or not (Resting). Accordingly, there are four body states: Fed_Resting, Fed_Exercising, PostAbsorptive_Resting and PostAbsorptive_Exercising. Different body states allow different values to be in effect for the configurable parameters governing the operation of the organs.
As mentioned before, the HumanBody object provides a method, which is invoked by the SimCtl object at each tick and causes methods to be invoked on individual organ objects that allow the organs to do their work during that tick.

Blood
The Blood object represents the bloodstream and interacts with various organs to exchange glucose, amino acids and other substrates. The Blood object maintains the following substrate variables: glucose, lactate, branchedAminoAcids (consumed by muscles, adipose tissue and brain) and unbranchedAminoAcids. The Blood object also maintains the insulinLevel variable discussed earlier and a fluidVolume_ variable representing the blood volume (5 liters by default). Hormones other than insulin are not currently maintained. At each tick, the Blood object updates the insulinLevel in the manner described in Seection 3.2. Also, some glucose is consumed for glycolysis in the manner described in Section 3.4.

Stomach
The gradual emptying of stomach contents into the intestine, also known as gastric emptying, is a complex phenomenon affected by a number of factors such as the volume, particle size,

PLOS ONE
viscosity, osmolarity, acidity and nutritional contents of the meal [58][59][60]. A variety of models have been suggested in the past for the emptying of food from the stomach into the intestine. Many of these models were based on mathematical functions such as exponential [61,62] and power exponential [63]. Lehmann and Deutsch [36] presented a simple model for gastric emptying of carboydrates in a meal, where the rate of gastric empyting has three phases-a linear increase phase, a constant maximum rate phase and a linear decrease phase. Dalla Man et al. [64] presented a three-compartment model of the gastrointestinal tract where the gastric emptying rate follows a trough-shaped pattern (initially high followed by a non-linear decrease to a minimum value followed by a non-linear increase back to the initial maximum value).
In CarbMetSim, when a food event is fired, the eaten food enters the Stomach instantaneously, where its contents are added to any existing stores of RAG, SAG, protein and fat. The simulator currently uses a simple model for gastric emptying where all the food in the stomach is assumed to be in the chyme form and the amount of chyme leaking to the intestine each minute consists of one part determined using a poisson distribution (with default mean 500 mg) and another part proportional to the total amount of chyme currently present in the stomach. This proportionality constant increases linearly with decrease in the energy density of the chyme. The minimum value of this proportionality constant (0.03 by default) represents the fraction leaking out of stomach each minute when the chyme consists entirely of fat (with energy density 9.0 kcal/g). On the other hand, the maximum value (9.0/4.0 times the minimum value) represents the fraction leaking out of stomach each minute when the chyme consists entirely of carbs (with energy density 4.0 kcal/g). The nutritional composition of leaked chyme is same as that of chyme present in the stomach. This simple model, inspired from [65], allows us to take in account the fat/protein induced slowdown of gastric emptying. There are many other factors that affect the gastric emptying process (the solid/liquid nature of food, fiber content, osmolarity, viscosity etc.) which CarbMetSim currently does not take in account. Thus, a bolus of chyme leaks from the Stomach into the Intestine every tick (i.e. every minute) until the Stomach is empty.

Intestine
Carbohydrate Digestion: The intestine digests the carbohydrate in the chyme using a number of enzymes to produce monosaccharides such as glucose, fructose and galactose [40]. Currently, the Intestine object in CarbMetSim converts all the carbohydrate in the chyme to just one monosaccharide-glucose. The Intestine receives a bolus of chyme from the Stomach every tick as long as there is some food in the Stomach. The Intestine maintains a list of Chyme objects where each object contains the undigested RAG/SAG contents of each bolus received from the Stomach and the time when the bolus was received. At each tick, the Intestine digests some amount of RAG/SAG from each Chyme object. The amount digested from a particular Chyme object is determined using normal distributions (default mean & standard-deviation: 2 minutes & 0.5 minutes for RAG and 30 minutes & 10 minutes for SAG) such that most of the RAG and SAG contents of a bolus are digested within 20 and 120 minutes respectively after the bolus's entry into the Intestine. The glucose resulting from digested RAG/SAG is added to the glucoseInLumen variable in Intestine, which represents the total glucose present in the intestinal lumen. This glucose is processed as described later in this section.
Fat and Protein Digestion: As a chyme bolus enters the Intestine from the Stomach, its fat contents are simply added to the AdiposeTissue and its protein contents are added to a common protein pool in Intestine. At each tick, the Intestine digests a small amount of this protein (determined as per a poisson distribution with default mean 1mg) and transfers the resulting amino acids to the PortalVein. The simulator does not keep track of the amino acid contents of dietary protein and makes a simple assumption that 85% of these amino acids are unbranched and the remaining 15% are branched.
Glucose Absorption from Intestine to PortalVein: The glucose moves from the intestinal lumen to the enterocytes across the brush border membrane and then from the enterocytes to the portal vein across the basolateral membrane. The transfer from the intestinal lumen to the enterocytes takes place via a combination of active (SGLT-1) and passive (GLUT2) transporters, where the number of GLUT2 transporters in action depends on the glucose concentration on the lumen side. The transfer from the enterocytes to the portal vein takes place solely via passive GLUT2 transporters [40]. The Intestine object maintains two variables: glucoseInLumen and glucoseInEnterocytes, which represent total glucose present in the intestinal lumen and in enterocytes respectively. At each tick, the Intestine moves some glucose from glucoseIn-Lumen to glucoseInEnterocytes. The amount moved has an active transport component (poisson distributed with default mean 30 mg/minute) and a passive transport component determined using Michaelis Menten kinetics (assuming configurable volumes for the lumen and the enterocytes). The V max value used for Michaelis Menten kinetics increases with glucose concentration in the lumen with default maximum value 800 mg/minute. The K m value used is 20 mmol/l by default [40]. Glucose transport from the enterocytes to the portal vein is modeled by moving some glucose from glucoseInEnterocytes to the PortalVein at each tick. The amount moved is determined using Michaelis Menten kinetics (average V max = 800 mg/ minute, K m = 20 mmol/l by default [40]).
Glycolysis: The intestinal cells get some of their energy via glycolysis of glucose to lactate in the manner described in Section 3.4. If the glucose in enterocytes (glucoseInEnterocytes) is not sufficient, the extra glucose needed for glycolysis comes from the bloodstream (the Blood object).

PortalVein
The portal vein carries blood that has passed through the intestinal tract to the liver. Due to its special status as the conduit from the intestine to the liver, CarbMetSim maintains the portal vein as a separate entity (the PortalVein object) from rest of the circulatory system (represented by the Blood object). The glucose and amino acids resulting from the food digestion in the Intestine travel to the Liver via the PortalVein.
Since the portal vein is a part of the circulatory system, it must have the same glucose concentration as rest of the circulatory system when no new glucose is being received from the intestine. This is achieved in CarbMetSim in the following manner. At the beginning of a tick, there is no glucose in the PortalVein. During each tick, the following sequence of actions take place: • The PortalVein imports glucose from the Blood so that the glucose concentration in the Por-talVein matches that of Blood before the import. The PortalVein's volume, used to calculate the glucose concentration, is a configurable parameter with default value 5 dl.
• Glucose transfer takes place from the Intestine to the PortalVein (as described previously in Section 4.4) and then from the PortalVein to the Liver (as described next in Section 4.6).
• Finally, any remaining glucose in the PortalVein is moved back to the Blood.
All the amino acids received from the Intestine into the PortalVein during a tick are moved to the Liver during that tick itself.

Liver
The hepatocytes in the liver absorb glucose from the portal vein via GLUT2s when the glucose concentration in the portal vein is higher. The absorbed glucose is phosphorylated to glucose 6-phosphate, which is used either for glycogen synthesis or for glycolysis. Insulin and glucose activate the enzymes associated with glycogen synthesis and inhibit those associated with glycogen breakdown. Insulin also activates glycolysis of glucose 6-phosphate in hepatocytes to form pyruvate, some of which is oxidized and the remaining is converted to lactate and released to the bloodstream. On the other hand, lack of insulin (and presence of glucagon) activates glycogen breakdown (to glucose) as well as gluconeogenesis (which again produces glucose). The gluconeogenesis flux increases with the availability of the substrates (such as lactate, alanine and glycerol) in the bloodstream even if the insulin level is high. Excess glucose in the hepatocytes is either used for glycogen synthesis (if the insulin level is high) or leaves the cells via GLUT2s and possibly other means (if the insulin level is low). High insulin level also causes some of the excess glucose to be converted to lipid. Thus, the liver absorbs glucose during the fed state and uses it for glycogen synthesis and glycolysis. On the other hand, the liver releases glucose to the bloodstream during the post-absorptive and exercising states via glycogen breakdown and gluconeogenesis. Another important aspect of the liver operation is its oxidation of unbranched amino acids which provides for almost half of the liver's energy requirements.
CarbMetSim implements the liver operation in the Liver object. The simulator allows the initial amount of glycogen stored in the Liver as well as the maximum amount it can hold to be set via configurable parameters. By default, the Liver has sufficient glycogen at the beginning of a simulation to produce 100 grams of glucose. Also, by default, an amount equivalent to 120 grams of glucose is the upper limit on the amount of glycogen that the Liver object can store. At each tick, the Liver does the following: • Glucose Absorption/Release: If the glucose concentration in higher in the PortalVein than in the Liver, some glucose will be absorbed in the Liver via GLUT2s. Similarly, if the glucose concentration is higher in the Liver than in the Blood, some glucose will be released to the Blood via GLUT2s. The amount of the glucose absorbed/released is determined using Michaelis Menten kinetics (with default average V max = 50mg/kg/min and default K m = 20 mmol/l [40]).
• Glycogen Synthesis/Breakdown: The Liver performs glycogen synthesis or breakdown in the manner described in Section 3.6.
• Lipogenesis: If the glycogen storage in the Liver exceeds its maximum configured value, the excess glycogen is converted to fat, which is stored in AdiposeTissue.
• Glycolysis and Gluconeogenesis: The Liver consumes some glucose for glycolysis in the manner described in Section 3.4 and produces glucose via gluconeogenesis in the manner described in Section 3.5.
• Amino Acid Consumption: The Liver consumes 93% of unbranched amino acids received from the PortalVein and releases the rest (along with all the branched amino acids) to the Blood object.

Kidneys
The kidneys filter the blood and require significant amount of energy for this task. Their outer layer (the cortex) is well supplied with oxygen and hence meets its energy needs via oxidation of glucose and fatty acids absorbed from the bloodstream. The inner core (the medulla) uses anaerobic glycolysis for energy. The kidneys also generate glucose via gluconeogenesis.
CarbMetSim implements the kidney operation in the Kidneys object. At each tick, the Kidneys do the following: • Glycolysis: The renal medulla in Kidneys meets its energy requirements via glycolysis, which is implemented in the manner described in Section 3.4. The glucose consumed for glycolysis is absorbed from the Blood object and the resulting lactate is released to the Blood object.
• Gluconeogenesis: The Kidneys produce glucose via gluconeogenesis in the manner described in Section 3.5 and release it to the Blood object.
• Glucose Excretion in Urine: As the the glucose concentration in Blood increases from one threshold (11 mmol/l [52,66] by default) to another (22 mmol/l by default), the glucose excretion in urine increases linearly from zero to a certain peak level (100 mg/min by default). The simulator supports a configurable parameter excretionKidneysImpact_ (with default value 1) to multiplicatively modify the amount of glucose excreted per tick in urine.

Muscles
The skeletal muscles have two types of cells or fibers: the red fibers oxidize substrates (fatty acids, glucose) absorbed from the bloodstream to meet their energy needs while the white fibers rely on glycolysis of glucose 6-phosphate obtained from the glycogen stored within the white fibers for energy. The glucose absorption from the bloodstream occurs mainly via insulin-sensitive GLUT4 transporters with some basal level absorption taking place via GLUT1 transporters. The skeletal muscles also use some branched chain amino acids absorbed from the bloodstream to meet their energy needs.
Muscles Operation During Rest [40,67,43]: In the resting state, the muscles meet 85-90% of their energy needs via the oxidation of fatty acids. About 10% of the energy comes from oxidation of glucose and 1-2% from amino acids. The glucose is absorbed from the bloodstream using GLUT4 and GLUT1 transporters as mentioned earlier. The absorbed glucose is used for oxidation, glycogen synthesis and glycolysis [68]. The glucose oxidation and glycolysis in muscles under resting conditions increases with the insulin level in the bloodstream.
Muscles Operation During Aerobic Activity [40,67,69]: Oxidation of glucose and fatty acids is the main source of energy for exercising muscles. The relative fraction of these substrates used to meet the energy needs depends on the exercise intensity, which in turn is decided based on the rate at which the individual consumes oxygen while doing this exercise. Each individual has a certain maximal rate at which he/she can consume oxygen. This individualspecific maximal rate, called VO 2 max, depends on the gender, age and fitness level of the individual [42]. So, the intensity of an exercise activity can be described by the oxygen consumption rate (as the%age of the individual's VO 2 max) associated with this exercise. The exercise intensity can also be described in an individual-independent manner in units of Metabolic Equivalent of Task or METs, where 1 MET is 1 kcal of energy expenditure per kg of body weight per hour. By convention, 1 MET is considered equivalent to 3.5ml of oxygen consumption per kg of body weight per minute. So, an exercise with a certain intensity in terms of METs may translate to very different intensities in terms of%VO 2 max for different individuals.
Romijn et al. [69] reported that about 10% of the energy needs during aerobic exercise are met by oxidizing glucose absorbed from the blood via GLUT4/GLUT1 transporters. The aerobic activity is sufficient to activate GLUT4 transporters. So, their action is not dependent on the insulin during the aerobic exercise [48][49][50]. For low intensity (e.g. 25%VO 2 max) exercise, almost all of the remaining energy needs are met by oxidizing fatty acids [69]. For moderate and high intensity exercise, a significant fraction of energy needs is met by oxidation of glucose PLOS ONE derived from the glycogen stored locally in the exercising muscles. Romijn et al. [69] reported about 30% of the energy coming from the oxidation of glucose derived from locally stored glycogen when the intensity of the aerobic exercise was 65%VO 2 max. Horton [67] reported oxidation of glucose (absorbed from the blood and derived from local glycogen) providing for about 50% and almost 100% of the energy needs when the exercise intensities were 50% VO 2 max and 100%VO 2 max respectively. Most of the remaining energy needs are met by oxidation of fatty acids [70]. Once the glycogen stored in the liver and the muscles is over, it becomes impossible for the individual to perform very high intensity exercise. A small fraction of the energy needs is met by glycolysis of glucose 6-phosphate derived from locally stored glycogen. The glycolysis level increases linearly with exercise intensity. Finally, a very small fraction of energy needs is met by consuming branched amino acids absorbed from the blood [70].

Implementation in CarbMetSim.
In CarbMetSim, the skeletal muscles are implemented as the Muscles object. Currently, the simulator implements response to the resting condition and the aerobic exercise only. Specifically, exercise with a significant anaerobic component cannot yet be simulated. Also, it is not yet possible to distinguish among different muscle groups.
At the beginning of a simulation, the HumanBody object estimates the VO 2 max associated with the individual being simulated using the tables in Kaminsky et al. [42] given this individual's gender, age and self-assessed fitness level within his/her age group, which are all supplied to the simulator as input parameters. When an exercise event is fired, the exercise intensity is translated from the units of METs into%VO 2 max. The exercise intensity determines the fraction of the energy needs met via oxidation of glucose derived from locally stored glycogen. The simulator allows the initial amount of glycogen stored in the Muscles as well as the maximum amount it can hold to be set via configurable parameters. By default, both these parameters have values equivalent to 500 grams of glucose.
When the HumanBody is in Fed_Exercising or PostAbsorptive_Exercising state during a tick, the Muscles object performs the following actions: • Oxidation of glucose absorbed from the Blood: The Muscles absorb a random amount of glucose from the Blood (up to a configurable limit which is 30μmol/kg/min by default) so that it can be oxidized to meet on average 10% of the energy needs during this tick. This absorption does not depend on the current insulinLevel in the Blood.
• Oxidation of glucose derived from local glycogen: The exercise intensity (in%VO 2 max) is used to determine the fraction of energy needs that will be met by oxidizing glucose derived from locally stored glycogen. As the exercise intensity increases from 0%VO 2 max to 100% VO 2 max, a value between 0 and 0.9 is determined using a sigmoid function (currently, the compressed CDF of a normal distribution) such that exercise intensities 50%VO 2 max and 100%VO 2 max yield values close to 0.4 and 0.9 respectively. This value is then used as the mean to generate a random value that gives the fraction of energy needs during this tick to be met by oxidizing glucose derived from local glycogen (as long as a sufficient amount of local glycogen is available).
• Glycolysis: The glycolysis flux during the tick increases linearly from a (poisson distributed) random value (with glycolysisMin_ as the mean) to glycolysisMax_ as the exercise intensity increases from 0%VO 2 max to 100%VO 2 max. The glucose 6-phosphate consumed for glycolysis comes from locally stored glycogen. The resulting lactate is added to the Blood object.
• Fatty Acid Consumption: If glucose oxidation and glycolysis described above do not meet the current energy needs, Muscles consume fat (representing fatty acids) from the AdiposeTissue to meet the remaining energy needs.
When the HumanBody is in Fed_Resting or PostAbsorptive_Resting state during a tick, the Muscles object performs the following actions: • Glucose Absorption: GLUT4 based glucose absorption [40] occurs in the manner described in Section 3.3.1. Also, basal absorption via GLUT1s occurs at a configured rate (by default zero).
• Glycolysis: A fraction of the absorbed glucose (determined as described in Section 3.4) is consumed via glycolysis and the resulting lactate is added to the Blood object.
• Glycogen Synthesis: If the glycogen store of the Muscles is less than the maximum amount that Muscles could hold [40], a (poisson distributed) random amount of the absorbed glucose (with a configurable mean, 7.0mg/kg/min by default) is converted to glycogen.
• Oxidation: Remainder of the absorbed glucose is considered consumed via oxidation.
• Fatty Acid Consumption: If glycolysis and glucose oxidation described above do not meet the energy needs during the resting state, Muscles consume fat (representing fatty acids) from the AdiposeTissue to meet the remaining energy needs.

Adipose tissue
CarbMetSim does not yet have a detailed implementation of lipid metabolism. Currently, the AdiposeTissue object serves as the storage for fat. The Intestine object directly adds the fat contents in chyme to the AdiposeTissue object. Similarly, the Liver object converts excess glycogen to fat to be stored in the AdiposeTissue object. The Muscles object directly removes fat from the AdiposeTissue in accordance with its energy needs.

Brain
The brain meets its energy needs by oxidizing glucose (although under starvation conditions it can also use ketone bodies). The nerve cells in the brain use GLUT3 transporters to absorb glucose from the bloodstream. Since the K m value associated with GLUT3 transporters is quite low, the rate of glucose absorption by the nerve cells does not change much with glucose concentration in the bloodstream (unless it drops way below the normal levels). The brain oxidizes about 120 g of glucose per day, equivalent to absorption of about 83.33 mg of glucose per minute [40,68]. In CarbMetSim, the brain operation is modeled as the Brain object which consumes a (poisson distributed) random amount (with mean 83.33 mg) of glucose every minute from the Blood object.

Heart
The heart meets most of its energy needs by oxidizing fatty acids. Depending upon their availability, up to 30% of the heart's energy needs are met by consuming glucose and lactate [71]. A much smaller part of the energy needs is met from amino acids and ketone bodies. The heart uses both GLUT1 and GLUT4 transporters to absorb glucose from the bloodstream. The Heart object in CarbMetSim models the heart operation. It absorbs a poisson distributed random amount of glucose (with default mean 14 mg/minute [68]) from Blood and oxidizes it to meet its energy needs.

Validation of CarbMetSim for a meal event
In order to determine the default values of various configurable parameters for normal subjects and to illustrate CarbMetSim's ability to model carbohydrate metabolism in normal subjects and those with Type 2 Diabetes (T2D) in post-absorptive and post-prandial phases, we configured the simulator to provide a close match with measurements reported in Woerle et al. [54]. Woerle et al. [54] did extensive measurements on 26 subjects with Type 2 Diabetes and 15 age/weight/sex-matched subjects without diabetes to determine the flux along different pathways for glucose arrival and consumption following a standard meal. The T2D subjects included 16 men and 10 women with following characteristics: age 53 ± 2 years, body weight 93 ± 4 kg, BMI 30 ± 1kg/m 2 , body fat 34 ± 3%, average HbA1c 8.6 ± 0.3%. The normal subjects included 7 men and 8 women with following characteristics: age 49 ± 3 years, body weight 89 ± 4 kg, BMI 30 ± 1kg/m 2 , body fat 36 ± 3%. All the subjects consumed a standard breakfast, consisting of 84 g of glucose, 10 g of fat and 26 g of protein, at 10am on the day of the measurements after a fast of more than 14 hours. Measurements were performed for the post-absorptive phase before the breakfast and the post-prandial phase assumed to be six hours in duration after the breakfast. Two sets of simulations were performed using CarbMetSim: one for a normal subject and one for a T2D subject (see Table 3). Each set consisted of 30 simulations with different seeds for random number generation. Default values were used for most of the configurable simulation parameters. These values (already reported in the previous sections) were set so that the normal subject simulations achieves a close match with measurements reported in [54]. In particular, the impact of insulin level on the gluconeogenesis flux was disabled because insulin level did not seem to influence the gluconeogenesis flux in the reported measurements. Configurable parameters for which the default values were not used are shown in Table 3. In all the simulations reported in this section and the remaining ones, the parameters did not change in value with the body state (although the simulator is capable of using different values for a parameter depending on the body state). Simulation parameters bodyWeight and age_ were set to the average values reported for subjects in each category in [54]. Parameters age_, gender_ and fitnessLevel_ are used to determine VO 2 max, the maximal rate of oxygen consumption for the subject being simulated and are not relevant for the simulations reported in this section. The following parameters were set as per the data reported in [54] (see Tables 4 and 5):

PLOS ONE
• The baseGlucoseLevel_ and highGlucoseLevel_ values were set to the reported values for the fasting and the peak BGL [54].
• The peakInsulinLevel_ values were set according to the reported peak plasma insulin levels [54].
• The average glycogen breakdown flux in the Liver (glycogenToGlucoseInLiver_) values was set to achieve a good match with the reported values for the post-absorptive glycogen breakdown flux and the total glycogen breakdown in the liver during the post-prandial phase.

PLOS ONE
Each simulation ran for 18 hours of simulated time: from 12am in midnight till 6pm in the next evening with one meal (consisting of 84 g of glucose, 10 g of fat and 26 g of protein) intake event happening at 10am. There were no other events during the simulated time and the simulated subject was already in the post-absorptive state when the simulation started at 12am. Fig 1 shows the minute-by-minute values of interest in two simulations with a particular seed value (for random number generation): one for the normal subject and the other for the T2D subject. Fig 1a shows that the gastric emptying is complete within 45 minutes of meal intake. The fat contents of the meal was responsible for some of the delay in gastric emptying. Fig 1b shows the rapid digestion of glucose as it arrives in the Intestine and Fig 1c shows the appearance of digested glucose in the PortalVein as described in Section IV-D. Fig 1d shows the change in BGL throughout the post-prandial phase starting from the post-absorptive levels before 10am.
Post-Absorptive Phase: During the post-absorptive phase (before 10am), the insulinLevel (Fig 1e) is low enough to ensure that the glucose production via glycogen breakdown in the Liver (Fig 1g) takes place at the peak level, there is no glycogen synthesis in the Liver (Fig 1f) and glucose consumption via oxidation (Fig 1j) & glycolysis (Fig 1i) in various organs is at their minimum levels. Gluconeogenesis (Fig 1h) takes place in the Liver and the Kidneys, unaffected by the insulinLevel (as reported in [54]), at the configured rates specified in [54] and provides the second source of glucose during the post-absorptive phase. While the minimum glucose oxidation flux is largely determined by the needs of the Brain and Heart, the configured values for the minimum glycolysis flux are chosen so that total glucose consumption during the post-absorptive phase matches the glucose production during this phase. Accordingly, the glycolysisMinImpact_ parameter was set to value 4.0 in simulations for the T2D subject and hence the glycolysis flux for the T2D subject during the post-absorptive phase is much higher than that for the normal subject (Fig 1i). Thus, during the post-absorptive phase, total glucose production (glycogen breakdown + gluconeogenesis) is matched closely by the total glucose consumption (oxidation + glycolysis + excretion in urine) and the BGL stabilizes to a value near the baseGlucoseLevel_. Since the glycogen breakdown in Liver is configured to rapidly slow down with increase in the insulinLevel, any temporary mismatch between glucose production and consumption is quickly corrected.
Post-Prandial Phase: The post-prandial phase in these simulations begins with the meal intake at 10am. The BGL begins to rise (as shown in Fig 1d) with the arrival of the digested glucose in the PortalVein. Increase in the BGL causes the insulinLevel to increase (Fig 1e) which rapidly brings glycogen breakdown in the Liver to a halt (Fig 1g). However, the influx of digested glucose (� 700 mg/minute at peak) is more than sufficient to compensate for the halt in glycogen breakdown (peak value � 120 and 80 mg/minute for T2D and normal subjects respectively) and the BGL (and hence the insulinLevel) continues to rise. Glucose production via gluconeogenesis (Fig 1h) continues as before unaffected by the increase in the insulinLevel (as reported in [54]). In the simulation for the normal subject, increase in the insulinLevel causes a proportional increase in the GLUT4 activation and hence in the glucose absorption by Muscles (Fig 1l). The glucose absorbed by the Muscles is consumed via glycolysis and oxidation. Since the glycogen stores in the Muscles are already full, none of the absorbed glucose is stored as glycogen in the Muscles. Increased oxidation flux seen in Fig 1j between 10am and 1pm in the normal subject is mainly due to the increased glucose oxidation in the Muscles. Impaired GLUT4 activation in the T2D subject (caused by glut4Impact_ value 0.25) means that the diabetic Muscles are not able to absorb as much glucose as the normal Muscles (Fig 1l). Also, almost all of the glucose absorbed by the diabetic Muscles is consumed via glycolysis (since the oxidation flux shown in Fig 1j does not show any rise in the post-prandial phase for the T2D subject). This is because of the much higher value of the minimum glycolysis flux in

PLOS ONE
the T2D subject than for the normal subject (caused by the glycolysisMinImpact_ parameter having value 4.0 for the T2D subject and 1.0 for the normal subject). Increase in the insulinLevel causes glycolysis flux to increase in other organs too (Fig 1i). The peak glycolysis flux for the T2D subject is configured to be higher than that for the normal subject (by setting glycoly-sisMaxImpact_ to 1.25 for the T2D subject) so as to achieve a close match with reported results in [54] for the total glycolysis flux during the post-prandial phase assumed to be between 10am and 4pm (see Table 5). As the BGL approaches the highGlucoseLevel_ (and insulinLevel approaches the peakInsulinLevel_), glycogen synthesis in the Liver starts and quickly ramps up to its peak level (see Fig 1f) thereby significantly slowing down any further increase in BGL. Note that the total glycogen storage during the post-prandial phase as reported in [54] (and shown in Tables 4 and 5) is higher for the T2D subjects than for the normal subjects even though the T2D subjects have much smaller peak insulin levels. As described in Section 3.6, the insulinLevel has a big impact on glycogen synthesis in the Liver. In order to compensate for lower insulin levels in the T2D subjects, the glucoseToGlycogenInLiver_ parameter in the simulations is assigned a much higher value for the T2D subject than for the normal subject (6.75 mg/kg/min versus 4.5 mg/kg/min). For the T2D subject, a significant amount of glucose is also lost via excretion in urine (see Fig 1k). Thus, BGL stays around the highGlucoseLevel_ as long as the digested glucose is appearing in the PortalVein at the peak rate. As the digested glucose appearance in the PortalVein slows down, the BGL begins to drop and the glycogen synthesis in the Liver quickly comes to a halt thereby slowing down the rate at which the BGL falls. Decrease in BGL also causes decrease in the glycolysis flux, the glucose absorption by the Muscles and the glucose excretion in the urine, which further slows down the rate of BGL decrease. As BGL approaches the baseGlucoseLevel_, the glycogen breakdown in the Liver quickly ramps up to prevent any further decrease in the BGL and another post-absorptive phase begins.
Comparison with Measurements from Woerle et al. [54]: Tables 4 and 5 show the key measurements from [54] for normal and T2D subjects respectively along with the corresponding results from the simulations. The simulations were configured to use the post-absorptive (peak) glycogen breakdown and gluconeogenesis flux values reported in [54]. With appropriate settings for other configurable parameters (Table 3), the post-absorptive BGLs in the simulations were close to the values reported in [54] for both normal and T2D subjects. The simulations were configured to ensure that the insulinLevel does not have any impact on gluconeogenesis flux (as reported in [54]). Accordingly, the gluconeogenesis flux in simulations 90 minutes after the breakfast was same as that before the breakfast matching the numbers reported in [54]. The glycogen breakdown 90 minutes after the breakfast was still substantial in [54] but had completely halted in the simulations. Overall, the peak post-prandial BGLs in simulations matched the ones reported in [54]. Total glucose produced/consumed along various pathways in the simulations for the normal subject during 6 hours after the breakfast was similar to values reported in [54]. The only exception was glycogen breakdown. It is clear from Fig 1 that the post-prandial phase in simulations was over by 1pm and hence glycogen breakdown happened at the peak level between 1pm and 4pm (Fig 1g). Apparently, this was not the case during measurements reported in [54] and the average glycogen breakdown flux during 6 hours after the breakfast was quite low. This combined with the fact that the glycogen breakdown was still substantial 90 minutes after the breakfast (when insulin levels were at their peak) means that glycogen breakdown process is relatively slow in reacting to the insulin levels. We observed a similar mismatch between the simulation results for the T2D subject and the values reported in [54] for total glycogen breakdown during 6 hours after the breakfast. Also, for the T2D subjects, [54] reported somewhat higher total gluconeogenesis flux during 6 hours after the breakfast (26.9±2.2 g) than what we observed in the simulations (23.069±0.001 g). Since gluconeogenesis flux in the simulation had same values during both post-prandial and post-absorptive phase, higher total flux reported in [54] means that gluconeogenesis flux actually increased during the post-prandial phase (perhaps due to higher availability of gluconeogenesis substrates). The simulator currently does not support increase in gluconeogenesis flux due to increased availability of substrates. Other results for T2D subjects in [54] were quite similar to what we observed in the simulations. Overall, it can be said that the simulation results closely matched those reported in [54] for both normal and T2D subjects.

Validation of CarbMetSim for an exercise event
Carbohydrate metabolism during and after an exercise event has been extensively studied for both normal and diabetic subjects [50,67,[72][73][74][75]. As described in Section 4.8, glucose oxidation plays a major role in meeting energy needs during physical exercise. The exercising muscles get the glucose they need by breaking down locally stored glycogen and by absorbing glucose from the bloodstream. The glucose absorption from the bloodstream does not depend on the insulin levels since the physical exercise itself is sufficient to activate GLUT4 transporters [48][49][50].
In case of normal people, physical exercise inhibits insulin secretion [43,[44][45][46][47] and promotes secretion of other hormones such as glucogon [43,46,47,76]. These changes allow the liver to break sufficient glycogen to meet the increased glucose needs. So, as long as glycogen is available in the liver and in the exercising muscles, the glucose production via glycogenolysis (in the liver and the exercising muscles) and gluconeogenesis (in the liver and kidneys) generally matches the glucose consumption by exercising muscles (and other organs) and the blood glucose level stays in the normal range [50,67]. The blood glucose level will drop once the glycogen stores have been exhausted and gluconeogenesis alone is not sufficient to match the glucose consumption by the exercising muscles. In case of people with Type 2 Diabetes or insulin-treated Type 1 Diabetes, physical exercise fails to sufficiently reduce insulin level in the blood and as a result the glycogen breakdown in the liver may not be sufficient to meet the additional glucose needs [77]. Thus, the blood glucose level may drop significantly during physical exercise. Finally, people with Type 1 Diabetes with too little insulin in their system may experience an increase in BGL (which was already high before the exercise) when they indulge in physical exercise. This may happen because the secretion of glucagon and other hormones during exercise increases glucose production via glycogen breakdown in the liver to a rate much higher than the impaired rate at which the exercising muscles absorb glucose in some people with Type 1 Diabetes [50,78,79,67].
In order to demonstrate CarbMetSim's ability to simulate the impact of aerobic physical exercise, we report in this section the simulations where normal male subjects perform a long aerobic exercise following an overnight fast. These simulations replicate the experiments reported in [51] and [80]. Ahlborg and Felig [51] observed 20 normal male subjects as they performed a leg exercise at intensity 58%VO 2 max for 3 to 3.5 hours after a 12 to 14 hour overnight fast. In a later study, Ahlborg et. al. [80] observed 12 normal male subjects as they performed a leg/arm exercise at intensity 30%VO 2 max for 2 hours after a 12 to 14 hour overnight fast. The characteristics of these subjects are shown in Table 6. For each subject, the concentrations in the blood were recorded for a number of substrates and hormones including glucose. The relevant BGL data reported in [51] and [80] is shown in Table 7 and Fig 2. In the following subsections, we interpret each set of BGL data and demonstrate that with proper configuration CarbMetSim can be made to replicate each pattern.

Exercise at intensity 58% VO 2 max
In the case of experiments involving physical exercise at intensity 58% VO 2 max, Table 7 and Fig 2 show that there is a continuous drop in the BGL as the exercise progresses. The BGL approaches hypoglycemic levels towards the end of the exercise. Also, there is only a modest recovery from hypoglycemic BGL once the exercise concludes. These observations, coupled with the fact that the exercise began after a long fast, indicate that the liver glycogen was exhausted some time after the start of the exercise and that the local glycogen and the gluconeogenesis were the only sources of glucose for the exercising muscles. The BGL dropped continuously because the gluconeogenesis alone was not sufficient to compensate for the absorption of glucose from the blood by the exercising muscles. After the completion of the exercise, gluconeogenesis continues to be the only source of glucose and is insufficient to bring the BGL to pre-exercise level.
We generated 20 age and weight value pairs for normal male subjects to simulate using the average and standard error values specified in [51] (see Table 6) and simulated the described experiment on these subjects. Each simulation started at simulated time 12am and had the subject perform a 210 minute long exercise (at intensity 58%VO 2 max) starting at 12pm. Each simulation ended at simulated time 5pm and used the same seed value for the random number generation. We adjusted the simulation parameters so as to cause the liver glycogen exhaustion early on in the exercise and thus match the BGL trends reported in [51]. The simulation

PLOS ONE
parameters (that differed from the default values) for the simulated subjects are shown in Table 8. In each simulation, the initial glycogen store in the Liver was set to 60 grams so that very little glycogen was left in the Liver by the time the exercise event began at 12pm. The gngImpact_ parameter was set to values between 13.2 and 15.5 so as to appropriately limit the glucose production via gluconeogenesis during the exercise event.   Fig 3 shows the results of CarbMetSim simulations replicating the physical exercise event at intensity 58% VO 2 max as reported in [51]. The BGL values for each simulated subject, along with the average BGL values reported in [51], are shown in Fig 3a. As this figure shows, the BGLs in the simulations have a close match with the measurements reported in [51]. For all subjects, the BGL hovered around its pre-exercise level for some time once the exercise began and then dropped continuously throughout the exercise duration with final values being in the hypoglycemic range. After the conclusion of the exercise activity, the BGL recovered but failed to reach its pre-exercise level. Fig 3b shows the amount of glycogen left in the Liver for a particular simulated subject. As mentioned before, the initial amount of glycogen in the Liver was set so that all this glycogen would be exhausted in the early stages of the exercise activity. As is clear from Fig 3b, all the glycogen in the Liver was exhausted by 1pm after which the gluconeogenesis was the only source of glucose for this particular subject. Fig 3c and 3d show the glycogen breakdown flux in the Liver and the combined gluconeogenesis flux in the Liver and Kidneys for this particular

PLOS ONE
subject. Note that the glycogen breakdown flux and the gluconeogenesis flux fluctuated between high and low values once the exercise began (and before the Liver glycogen was exhausted). This behavior is in accordance with the manner in which the insulinLevel varies (Section 3.2) and the manner in which the glycogen breakdown in the Liver (Section 3.6) and gluconeogenesis in the Liver and Kidneys (Section 3.5) react to the insulinLevel. As described in Section 3.2, when the BGL falls below the baseGlucoseLevel_, the insulinLevel becomes zero if the body is engaged in an exercise at an intensity higher than the intensityPeakGlucoseProd_ (default value 20% VO 2 max). Since the exercise intensity (58% VO 2 max) was indeed higher than the intensityPeakGlucoseProd_, the insulinLevel fell to zero whenever the BGL fell below the baseGlucoseLevel_. This caused both glycogen breakdown in the Liver and gluconeogenesis in the Liver and Kidneys to proceed at the highest levels. When the BGL exceeded the baseGlu-coseLevel_, the insulinLevel exceeded the baseInsulinLevel_ and the glycogen breakdown & gluconeogenesis fluxes dropped down to the regular levels.
Once the liver glycogen was exhausted, the gluconeogenesis alone (even when occurring at the highest level) was not sufficient to push BGL above the baseGlucoseLevel_ and hence the insulinLevel stayed at zero level for rest of the exercise duration and the gluconeogenesis continued to occur at its highest level as the only source of glucose for the blood. Once the exercise was over, the insulinLevel increased to a positive value below baseInsulinLevel_ (as per the rules described in Section 3.2) and in response the gluconeogenesis flux assumed a value between the regular and the highest levels (as per the rules described in Section 3.5). Gluconeogenesis at this level allowed the BGL to climb up from the hypoglycemic range to a level below the baseGlucoseLevel_.

Arm exercise at intensity 30% VO 2 max
In the case of experiments involving an arm exercise at intensity 30% VO 2 max, it is clear from Table 7 and Fig 2 that the BGL largely maintains its pre-exercise level during the entire exercise duration (although there is a small drop in the BGL during the recovery phase). These observations indicate that the liver glycogen was not exhausted during the exercise and that the breakdown of liver glycogen and gluconeogenesis together were sufficient to meet the needs of the exercising muscles. Once the exercise was over, the liver glycogen breakdown and gluconeogenesis returned to their pre-exercise levels and accordingly the BGL also returned to its preexercise level.
We generated 6 age and weight value pairs for normal male subjects to simulate using the average and standard error values specified in [80] for the arm exercise experiments (see Table 6) and simulated the described experiment on these subjects. CarbMetSim does not currently distinguish between different muscles and hence the arm exercise was simulated as a regular exercise. Each simulation started at 12am and had the subject perform a 120 minute long exercise (at intensity 30% VO 2 max) starting at 12pm. Each simulation ended at 5pm and used the same seed value for the random number generation. The simulation parameters (that differed from the default values) for the simulated subjects are shown in Table 9. In each simulation, the initial glycogen store in the Liver was set to 100 grams so that the liver glycogen does not get exhausted during the exercise. The gngImpact_ parameter was set to value 15.0 so that the glucose production via gluconeogenesis can ramp up to a high enough level when required during the exercise. Fig 4 shows the results of CarbMetSim simulations replicating the arm exercise event at intensity 30% VO 2 max as reported in [80]. The BGL values for each simulated subject, along with the average BGL values reported in [80], are shown in Fig 4a. As this figure shows, the BGLs in the simulations have a close match with the measurements reported in [80]. For all subjects, the BGL hovered around its pre-exercise level throughout the exercise duration and then went back to the pre-exercise level. Fig 4b shows the amount of glycogen left in the Liver for a particular simulated subject. As desired, the liver glycogen did not get exhausted during the exercise and in the recovery phase. Fig 4c and 4d show the glycogen breakdown flux in the Liver and the combined gluconeogenesis flux in the Liver and Kidneys for this particular subject. As was the case with the 58% VO 2 max simulations reported in the previous section, the glycogen breakdown flux and the gluconeogenesis flux fluctuated between high and low values once the exercise began. The explanation for this behavior was provided in the previous section. These oscillations explain the BGL oscillations throughout the exercise duration. Once the exercise was over, the insulinLevel increased to the baseInsulinLevel_ (as per the rules described in Section 3.2) and in response the liver glycogen breakdown and gluconeogenesis fluxes (and hence the BGL) assumed their pre-exercise levels.

Leg exercise at intensity 30% VO 2 max
Finally, we have the experiments involving a leg exercise at intensity 30%VO 2 max. In these experiments, the BGL dropped modestly during the exercise and then seemed to climb back to the pre-exercise level (see Table 7 and Fig 2). The fact that the post-exercise BGL approached pre-exercise level indicates that the liver glycogen was not exhausted during the exercise or in the recovery phase. However, the fact that the BGL dropped modestly throughout the exercise indicates that glucose production during exercise (via liver glycogen breakdown and gluconeogenesis) was a little less than the amount absorbed from the blood by the exercising muscles. Clearly, in these experiments, the physical exercise was not able to stimulate liver glycogen breakdown and gluconeogenesis sufficiently so that their combined glucose production could match the demands of the exercising muscles. We generated 6 age and weight value pairs for normal male subjects to simulate using the average and standard error values specified in [80] for the leg exercise experiments (see Table 6) and simulated the described experiment on these subjects. As mentioned before, CarbMetSim does not currently distinguish between different muscles and hence the leg exercise was simulated as a regular exercise. Each simulation started at 12am and had the subject perform a 120 minute long exercise (at intensity 30%VO 2 max) starting at 12pm. Each simulation ended at 5pm and used the same seed value for the random number generation. In these simulations, we wanted to precisely control the glucose production via liver glycogen breakdown and gluconeogenesis during exercise. The total glucose production during exercise had to be just a little less than what the exercising muscles were absorbing from the blood. To achieve this end, we reduced the liverGlycogenBreakdownImpact_ (that controls the liver glycogen breakdown during exercise; see Sections 3.6 and 3.2) to value 1.0 (i.e. no extra glycogen breakdown in the Liver during the exercise) while increasing the glycogenToGlucoseInLiver_ parameter (that controls the regular glycogen breakdown in the Liver) value appropriately. The gngImpact_ parameter (that controls the gluconeogenesis flux during exercise; see Sections 3.5 and 3.2) was also set appropriately to limit glucose production via gluconeogenesis during exercise. All simulation parameters (that differed from the default values) for the simulated subjects are shown in Table 10. In each simulation, the initial glycogen store in the Liver was set to 100 grams so that the liver glycogen would not be exhausted during the exercise or the recovery phase. Fig 5 shows the results of CarbMetSim simulations replicating the leg exercise event at intensity 30% VO 2 max as reported in [80]. The BGL values for each simulated subject, along with the average BGL values reported in [80], are shown in Fig 5a. As this figure shows, the BGLs in the simulations have a reasonably good match with the measurements reported in [80]. As desired, for all subjects, the BGL dropped modestly during the exercise duration and then went back to the pre-exercise level. Fig 5b shows  Since the BGL was always below the baseGlucoseLevel_ throughout the exercise duration and the exercise intensity was greater than intensityPeakGlucoseProd_, the insulinLevel was zero throughout the exercise duration and hence the gluconeogenesis took place at its highest level throughout the exercise duration. However, the zero value of the insulinLevel was not able to stimulate liver glycogen breakdown because the liverGlycogenBreakdownImpact_ was set to value 1. The combined glucose production via gluconeogenesis and liver glycogen breakdown was just below the glucose absorbed from the blood by the exercising muscles and hence the BGL dropped modestly throughout the exercise duration as desired. Once the exercise was over, the insulinLevel increased to the baseInsulinLevel_ and in response the gluconeogenesis flux (and hence the BGL) assumed their pre-exercise level.

Conclusion
This paper described CarbMetSim, a discrete event simulator that models the carbohydrate metabolism in human beings and predicts a subject's BGL in response to a timed sequence of diet and exercise activities. The paper also presented a preliminary validation of CarbMetSim's behavior in response to single meal and exercise events where the simulator's predictions were compared against the group-level averages reported in the published literature. The simulator needs significant additional validation against continuous blood glucose data of individuals representing different demographic groups, different types & levels of Diabetes and different lifestyles before it may be considered ready for use in diabetes self-management and researchrelated applications. Besides more elaborate validation, our future work on CarbMetSim will include expanding its functionality to correct its current limitations identified towards the end of Section 1. With all this additional work, CarbMetSim will reach a stage where it can be immensely useful as the underlying engine for a variety of diabetes self-management and educational tools. With its open source nature and ease of modification/extension, CarbMet-Sim also has the potential to emerge as a good simulation framework for diabetes research.