From ae811b1789e38328795dc7c532bcf738fa2884f9 Mon Sep 17 00:00:00 2001 From: Matthew Gretton-Dann Date: Thu, 18 Jun 2020 10:40:04 +0100 Subject: [PATCH 1/6] Add clang-format file. --- .clang-format | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 000000000..05261b72d --- /dev/null +++ b/.clang-format @@ -0,0 +1,12 @@ +--- +BasedOnStyle: Microsoft +AccessModifierOffset: -2 +BreakBeforeBraces: Allman +ColumnLimit: 100 +IndentWidth: 2 +Language: Cpp +Standard: Cpp11 +TabWidth: 2 +UseTab: Always + +... From 6ad0a96011ebcbb77a1df6ced542fae929fd756e Mon Sep 17 00:00:00 2001 From: Matthew Gretton-Dann Date: Thu, 18 Jun 2020 14:41:46 +0100 Subject: [PATCH 2/6] Update editorconfig to reflect clang-format better --- .editorconfig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.editorconfig b/.editorconfig index 3852da819..cad894f54 100644 --- a/.editorconfig +++ b/.editorconfig @@ -26,4 +26,5 @@ indent_size = 2 # C++ source [*.c,*.cpp,*.h] indent_style = tab -indent_size = 2 +indent_size = tab +tab_width = 2 From 10622f8ec7210d68fb33fbbd5bcfd274ed27e614 Mon Sep 17 00:00:00 2001 From: Matthew Gretton-Dann Date: Thu, 18 Jun 2020 11:20:38 +0100 Subject: [PATCH 3/6] Add CI workflow that clang-formats sources This adds a workflow that will automatically clang-format any code on a pull_request. --- .github/workflows/clang-format.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .github/workflows/clang-format.yml diff --git a/.github/workflows/clang-format.yml b/.github/workflows/clang-format.yml new file mode 100644 index 000000000..eb6927c00 --- /dev/null +++ b/.github/workflows/clang-format.yml @@ -0,0 +1,14 @@ +name: clang-format + +on: [pull_request] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: DoozyX/clang-format-lint-action@v0.6 + with: + source: './src' + extensions: 'h,cpp,hpp' + clangFormatVersion: 9 From 0637a6e7b539ccaaceaa035acc4146b006a740ac Mon Sep 17 00:00:00 2001 From: Matthew Gretton-Dann Date: Thu, 18 Jun 2020 14:42:33 +0100 Subject: [PATCH 4/6] Apply clang-format to everything in src/ This is the automatic part of applying clang-format. Not everything may build yet. --- src/BinIO.cpp | 54 +- src/BinIO.h | 4 +- src/Bitmap.cpp | 303 +- src/Bitmap.h | 6 +- src/CalcInfSusc.cpp | 99 +- src/Constants.h | 6 +- src/Country.h | 1 - src/CovidSim.cpp | 6835 ++++++++++++++++++++++++------------ src/CovidSim.h | 10 +- src/Direction.cpp | 18 +- src/Direction.hpp | 9 +- src/Dist.cpp | 64 +- src/Dist.h | 10 +- src/Error.cpp | 16 +- src/Error.h | 6 +- src/Geometry/BoundingBox.h | 58 +- src/Geometry/Size.h | 155 +- src/Geometry/Vector2.cpp | 12 +- src/Geometry/Vector2.h | 224 +- src/InfStat.h | 18 +- src/Kernels.cpp | 22 +- src/MicroCellPosition.cpp | 21 +- src/MicroCellPosition.hpp | 6 +- src/Model.h | 289 +- src/ModelMacros.h | 19 +- src/Models/Cell.h | 8 +- src/Models/Microcell.h | 14 +- src/Models/Person.h | 62 +- src/Param.cpp | 28 +- src/Param.h | 508 ++- src/Rand.cpp | 459 ++- src/Rand.h | 6 +- src/SetupModel.cpp | 1185 ++++--- src/SetupModel.h | 10 +- src/Sweep.cpp | 2093 ++++++----- src/Sweep.h | 8 +- src/Update.cpp | 868 +++-- src/Update.h | 13 +- 38 files changed, 8602 insertions(+), 4925 deletions(-) diff --git a/src/BinIO.cpp b/src/BinIO.cpp index 7cfc0f5b8..08596f869 100644 --- a/src/BinIO.cpp +++ b/src/BinIO.cpp @@ -1,40 +1,40 @@ -#include #include "BinIO.h" +#include -size_t fwrite_big(void *buffer,size_t size,size_t count, FILE *stream) +size_t fwrite_big(void *buffer, size_t size, size_t count, FILE *stream) { - const unsigned long long mx=0x80000000; - unsigned long long j,n,st; - size_t ret=0; + const unsigned long long mx = 0x80000000; + unsigned long long j, n, st; + size_t ret = 0; char *buf2; - st=mx/((unsigned long long) size); - n=count/st; - for(j=0;j +#include +#include #include #include -#include -#include #include "BinIO.h" #include "Bitmap.h" #include "Error.h" -#include "Param.h" #include "Model.h" +#include "Param.h" -//// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** -//// **** BITMAP stuff. +//// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** +/////// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** / **** BITMAP +/// stuff. #ifdef _WIN32 -//HAVI avi; +// HAVI avi; static ULONG_PTR m_gdiplusToken; static HBITMAP bmpdib; -static CLSID encoderClsid; +static CLSID encoderClsid; #endif #ifndef _WIN32 #include // for mkdir #endif -static unsigned char* bmf, *bmPixels, *bmp; +static unsigned char *bmf, *bmPixels, *bmp; // externs from CovidSim.cpp // TODO: move these to a header files extern char OutFile[1024], OutFileBase[1024]; @@ -42,7 +43,8 @@ void CaptureBitmap() { fst = 0; int32_t maxPop = 0; - for (int i = 0; i < mi; i++) bmPopulation[i] = 0; + for (int i = 0; i < mi; i++) + bmPopulation[i] = 0; for (int i = 0; i < P.PopSize; i++) { x = ((int)(Households[Hosts[i].hh].loc.x * P.scale.x)) - P.bmin.x; @@ -53,7 +55,8 @@ void CaptureBitmap() if ((j < bmh->imagesize) && (j >= 0)) { bmPopulation[j]++; - if (bmPopulation[j] > maxPop) maxPop = bmPopulation[j]; + if (bmPopulation[j] > maxPop) + maxPop = bmPopulation[j]; } } } @@ -62,20 +65,46 @@ void CaptureBitmap() if (Mcells[i].n > 0) { f = 0; - if ((i < P.NMC - 1) && (i / P.get_number_of_micro_cells_high() == (i + 1) / P.get_number_of_micro_cells_high()) && (Mcells[i + 1].n > 0) && ((Mcells[i].country != Mcells[i + 1].country) - || ((P.DoAdunitBoundaryOutput) && ((AdUnits[Mcells[i].adunit].id % P.AdunitLevel1Mask) / P.AdunitBitmapDivisor != (AdUnits[Mcells[i + 1].adunit].id % P.AdunitLevel1Mask) / P.AdunitBitmapDivisor)))) f = 1; - if ((i > 0) && (i / P.get_number_of_micro_cells_high() == (i - 1) / P.get_number_of_micro_cells_high()) && (Mcells[i - 1].n > 0) && (Mcells[i].country != Mcells[i - 1].country)) f = 1; - if ((i < P.NMC - P.get_number_of_micro_cells_high()) && (Mcells[i + P.get_number_of_micro_cells_high()].n > 0) && ((Mcells[i].country != Mcells[i + P.get_number_of_micro_cells_high()].country) - || ((P.DoAdunitBoundaryOutput) && ((AdUnits[Mcells[i].adunit].id % P.AdunitLevel1Mask) / P.AdunitBitmapDivisor != (AdUnits[Mcells[i + P.get_number_of_micro_cells_high()].adunit].id % P.AdunitLevel1Mask) / P.AdunitBitmapDivisor)))) f = 1; - if ((i >= P.get_number_of_micro_cells_high()) && (Mcells[i - P.get_number_of_micro_cells_high()].n > 0) && (Mcells[i].country != Mcells[i - P.get_number_of_micro_cells_high()].country)) f = 1; + if ((i < P.NMC - 1) && + (i / P.get_number_of_micro_cells_high() == + (i + 1) / P.get_number_of_micro_cells_high()) && + (Mcells[i + 1].n > 0) && + ((Mcells[i].country != Mcells[i + 1].country) || + ((P.DoAdunitBoundaryOutput) && + ((AdUnits[Mcells[i].adunit].id % P.AdunitLevel1Mask) / P.AdunitBitmapDivisor != + (AdUnits[Mcells[i + 1].adunit].id % P.AdunitLevel1Mask) / P.AdunitBitmapDivisor)))) + f = 1; + if ((i > 0) && + (i / P.get_number_of_micro_cells_high() == + (i - 1) / P.get_number_of_micro_cells_high()) && + (Mcells[i - 1].n > 0) && (Mcells[i].country != Mcells[i - 1].country)) + f = 1; + if ((i < P.NMC - P.get_number_of_micro_cells_high()) && + (Mcells[i + P.get_number_of_micro_cells_high()].n > 0) && + ((Mcells[i].country != Mcells[i + P.get_number_of_micro_cells_high()].country) || + ((P.DoAdunitBoundaryOutput) && + ((AdUnits[Mcells[i].adunit].id % P.AdunitLevel1Mask) / P.AdunitBitmapDivisor != + (AdUnits[Mcells[i + P.get_number_of_micro_cells_high()].adunit].id % + P.AdunitLevel1Mask) / + P.AdunitBitmapDivisor)))) + f = 1; + if ((i >= P.get_number_of_micro_cells_high()) && + (Mcells[i - P.get_number_of_micro_cells_high()].n > 0) && + (Mcells[i].country != Mcells[i - P.get_number_of_micro_cells_high()].country)) + f = 1; if (f) { - x = (int)(P.in_microcells_.width * (((double)(i / P.get_number_of_micro_cells_high())) + 0.5) * P.scale.x) - P.bmin.x; - y = (int)(P.in_microcells_.height * (((double)(i % P.get_number_of_micro_cells_high())) + 0.5) * P.scale.y) - P.bmin.y; + x = (int)(P.in_microcells_.width * + (((double)(i / P.get_number_of_micro_cells_high())) + 0.5) * P.scale.x) - + P.bmin.x; + y = (int)(P.in_microcells_.height * + (((double)(i % P.get_number_of_micro_cells_high())) + 0.5) * P.scale.y) - + P.bmin.y; if ((x >= 0) && (x < P.b.width) && (y >= 0) && (y < P.b.height)) { j = y * bmh->width + x; - if ((j < bmh->imagesize) && (j >= 0)) bmPopulation[j] = -1; + if ((j < bmh->imagesize) && (j >= 0)) + bmPopulation[j] = -1; } } } @@ -89,20 +118,24 @@ void CaptureBitmap() } } } -#pragma omp parallel for schedule(static,5000) default(none) \ +#pragma omp parallel for schedule(static, 5000) default(none) \ shared(mi, bmPixels, bmPopulation, bmInfected, bmTreated, bmRecovered, logMaxPop) for (int i = 0; i < mi; i++) { if (bmPopulation[i] == -1) bmPixels[i] = BWCOLS - 1; /* black for country boundary */ else if (bmInfected[i] > 0) - bmPixels[i] = (unsigned char)(BWCOLS + BWCOLS * log((double)bmInfected[i]) / logMaxPop); /* red for infected */ + bmPixels[i] = (unsigned char)(BWCOLS + BWCOLS * log((double)bmInfected[i]) / + logMaxPop); /* red for infected */ else if (bmTreated[i] > 0) - bmPixels[i] = (unsigned char)(2 * BWCOLS + BWCOLS * log((double)bmTreated[i]) / logMaxPop); /* blue for treated */ + bmPixels[i] = (unsigned char)(2 * BWCOLS + BWCOLS * log((double)bmTreated[i]) / + logMaxPop); /* blue for treated */ else if (bmRecovered[i] > 0) - bmPixels[i] = (unsigned char)(3 * BWCOLS + BWCOLS * log((double)bmRecovered[i]) / logMaxPop); /* green for recovered */ + bmPixels[i] = (unsigned char)(3 * BWCOLS + BWCOLS * log((double)bmRecovered[i]) / + logMaxPop); /* green for recovered */ else if (bmPopulation[i] > 0) - bmPixels[i] = (unsigned char)(BWCOLS * log((double)bmPopulation[i]) / logMaxPop); /* grey for just people */ + bmPixels[i] = (unsigned char)(BWCOLS * log((double)bmPopulation[i]) / + logMaxPop); /* grey for just people */ else bmPixels[i] = 0; } @@ -116,10 +149,12 @@ void OutputBitmap(int tp) char *OutBaseName = strrchr(OutFile, '/'); char *OutBaseName2 = strrchr(OutFile, '\\'); - if (OutBaseName2 != nullptr && (OutBaseName == nullptr || OutBaseName2 > OutBaseName)) { + if (OutBaseName2 != nullptr && (OutBaseName == nullptr || OutBaseName2 > OutBaseName)) + { OutBaseName = OutBaseName2; } - if (OutBaseName == nullptr) { + if (OutBaseName == nullptr) + { OutBaseName = OutFile; } @@ -151,72 +186,83 @@ void OutputBitmap(int tp) if (P.BitmapFormat == BitmapFormats::PNG) { #ifdef IMAGE_MAGICK - FILE* dat; - using namespace Magick; - fprintf(stderr, "\noutputing ImageMagick stuff"); - sprintf(buf, "%s.bmp", OutF); - if (!(dat = fopen(buf, "wb"))) ERR_CRITICAL("Unable to open bitmap file\n"); - fprintf(dat, "BM"); - //fwrite_big((void *) &bmf,sizeof(unsigned char),(sizeof(bitmap_header)/sizeof(unsigned char))+bmh->imagesize,dat); - fwrite_big((void*)bmf, sizeof(bitmap_header), 1, dat); - for (int i = 0; i < bmh->imagesize; i++) fputc(bmPixels[i], dat); - fclose(dat); - Image bmap(buf); - sprintf(buf, "%s.%d.png", OutF, j); - ColorRGB white(1.0, 1.0, 1.0); - bmap.transparent(white); - bmap.write(buf); + FILE *dat; + using namespace Magick; + fprintf(stderr, "\noutputing ImageMagick stuff"); + sprintf(buf, "%s.bmp", OutF); + if (!(dat = fopen(buf, "wb"))) + ERR_CRITICAL("Unable to open bitmap file\n"); + fprintf(dat, "BM"); + // fwrite_big((void *) &bmf,sizeof(unsigned char),(sizeof(bitmap_header)/sizeof(unsigned + // char))+bmh->imagesize,dat); + fwrite_big((void *)bmf, sizeof(bitmap_header), 1, dat); + for (int i = 0; i < bmh->imagesize; i++) + fputc(bmPixels[i], dat); + fclose(dat); + Image bmap(buf); + sprintf(buf, "%s.%d.png", OutF, j); + ColorRGB white(1.0, 1.0, 1.0); + bmap.transparent(white); + bmap.write(buf); #elif defined(_WIN32) - //Windows specific bitmap manipulation code - could be recoded using LIBGD or another unix graphics library - using namespace Gdiplus; + // Windows specific bitmap manipulation code - could be recoded using LIBGD or another unix + // graphics library + using namespace Gdiplus; - wchar_t wbuf[1024]; - size_t a; + wchar_t wbuf[1024]; + size_t a; - //Add new bitmap to AVI - //if ((P.OutputBitmap == 1) && (tp == 0)) AddAviFrame(avi, bmpdib, (unsigned char*)(&bmh->palette[0][0])); + // Add new bitmap to AVI + // if ((P.OutputBitmap == 1) && (tp == 0)) AddAviFrame(avi, bmpdib, (unsigned + // char*)(&bmh->palette[0][0])); - //This transfers HBITMAP to GDI+ Bitmap object - Bitmap* gdip_bmp = Bitmap::FromHBITMAP(bmpdib, NULL); - //Now change White in palette (first entry) to be transparent - if ((cn1 == 1) && (tp == 0)) - { - static UINT palsize; - static ColorPalette* palette; - palsize = gdip_bmp->GetPaletteSize(); - palette = (ColorPalette*)malloc(palsize); - if (!palette) ERR_CRITICAL("Unable to allocate palette memory\n"); - (void)gdip_bmp->GetPalette(palette, palsize); - palette->Flags = PaletteFlagsHasAlpha; - palette->Entries[0] = 0x00ffffff; // Transparent white - gdip_bmp->SetPalette(palette); - } - //Now save as png - sprintf(buf, "%s.%05i.png", OutF, j + 1); //sprintf(buf,"%s.ge" DIRECTORY_SEPARATOR "%s.%05i.png",OutFileBase,OutF,j+1); - mbstowcs_s(&a, wbuf, strlen(buf) + 1, buf, _TRUNCATE); - gdip_bmp->Save(wbuf, &encoderClsid, NULL); - delete gdip_bmp; + // This transfers HBITMAP to GDI+ Bitmap object + Bitmap *gdip_bmp = Bitmap::FromHBITMAP(bmpdib, NULL); + // Now change White in palette (first entry) to be transparent + if ((cn1 == 1) && (tp == 0)) + { + static UINT palsize; + static ColorPalette *palette; + palsize = gdip_bmp->GetPaletteSize(); + palette = (ColorPalette *)malloc(palsize); + if (!palette) + ERR_CRITICAL("Unable to allocate palette memory\n"); + (void)gdip_bmp->GetPalette(palette, palsize); + palette->Flags = PaletteFlagsHasAlpha; + palette->Entries[0] = 0x00ffffff; // Transparent white + gdip_bmp->SetPalette(palette); + } + // Now save as png + sprintf(buf, "%s.%05i.png", OutF, + j + 1); // sprintf(buf,"%s.ge" DIRECTORY_SEPARATOR "%s.%05i.png",OutFileBase,OutF,j+1); + mbstowcs_s(&a, wbuf, strlen(buf) + 1, buf, _TRUNCATE); + gdip_bmp->Save(wbuf, &encoderClsid, NULL); + delete gdip_bmp; #else - fprintf(stderr, "Do not know how to output PNG\n"); + fprintf(stderr, "Do not know how to output PNG\n"); #endif } - else if (P.BitmapFormat == BitmapFormats::BMP) { - sprintf(buf, "%s.%05i.bmp", OutF, j); - FILE* dat; - if (!(dat = fopen(buf, "wb"))) { - char* errMsg = strerror(errno); - if (errMsg == nullptr) { - ERR_CRITICAL("strerror failed.\n"); - } - ERR_CRITICAL_FMT("Unable to open bitmap file %s (%d): %s\n", buf, errno, errMsg); - } - fprintf(dat, "BM"); - fwrite_big((void*)bmf, sizeof(unsigned char), sizeof(BitmapHeader) / sizeof(unsigned char) + bmh->imagesize, dat); - fclose(dat); + else if (P.BitmapFormat == BitmapFormats::BMP) + { + sprintf(buf, "%s.%05i.bmp", OutF, j); + FILE *dat; + if (!(dat = fopen(buf, "wb"))) + { + char *errMsg = strerror(errno); + if (errMsg == nullptr) + { + ERR_CRITICAL("strerror failed.\n"); + } + ERR_CRITICAL_FMT("Unable to open bitmap file %s (%d): %s\n", buf, errno, errMsg); + } + fprintf(dat, "BM"); + fwrite_big((void *)bmf, sizeof(unsigned char), + sizeof(BitmapHeader) / sizeof(unsigned char) + bmh->imagesize, dat); + fclose(dat); } else { - fprintf(stderr, "Unknown Bitmap format: %d\n", (int)P.BitmapFormat); + fprintf(stderr, "Unknown Bitmap format: %d\n", (int)P.BitmapFormat); } } void InitBMHead() @@ -227,26 +273,26 @@ void InitBMHead() k = P.b.width * P.bheight2; k2 = sizeof(BitmapHeader) / sizeof(unsigned char); - if (!(bmf = (unsigned char*)calloc((size_t)k + k2, sizeof(unsigned char)))) + if (!(bmf = (unsigned char *)calloc((size_t)k + k2, sizeof(unsigned char)))) ERR_CRITICAL("Unable to allocate storage for bitmap\n"); bmPixels = &(bmf[k2]); bmp = &(bmf[12]); - bmh = (BitmapHeader*)bmf; + bmh = (BitmapHeader *)bmf; bmh->spare = 0; bmh->boffset = 2 + sizeof(BitmapHeader); bmh->headersize = 40; // BITMAPINFOHEADER bmh->width = P.b.width; bmh->height = P.bheight2; - bmh->PlanesAndBitspp = 1 // Number of colour planes; must be 1 - + (8 << 16); // Colour depth: 8 bits per pixel - bmh->compr = 0; // No compression (BI_RGB) + bmh->PlanesAndBitspp = 1 // Number of colour planes; must be 1 + + (8 << 16); // Colour depth: 8 bits per pixel + bmh->compr = 0; // No compression (BI_RGB) bmh->imagesize = bmh->width * bmh->height; - bmh->filesize = 2 // "BM" - + ((unsigned int) sizeof(BitmapHeader)) // BITMAP_HEADER - + bmh->imagesize; // Image data - bmh->hres = bmh->vres = (int)(bmh->width * 10); // Resolution, in pixels per metre - bmh->colours = BWCOLS * 4; // Number of colours in the palette - bmh->impcol = 0; // Every colour is important + bmh->filesize = 2 // "BM" + + ((unsigned int)sizeof(BitmapHeader)) // BITMAP_HEADER + + bmh->imagesize; // Image data + bmh->hres = bmh->vres = (int)(bmh->width * 10); // Resolution, in pixels per metre + bmh->colours = BWCOLS * 4; // Number of colours in the palette + bmh->impcol = 0; // Every colour is important for (i = 0; i < BWCOLS * 4; i++) bmh->palette[i][3] = 0; for (j = 0; j < BWCOLS; j++) @@ -267,57 +313,62 @@ void InitBMHead() bmh->palette[3 * BWCOLS + j][1] = (unsigned char)value; bmh->palette[3 * BWCOLS + j][2] = 0; } - if (!(bmPopulation = (int32_t*)malloc(bmh->imagesize * sizeof(int32_t))) || - !(bmInfected = (int32_t*)malloc(bmh->imagesize * sizeof(int32_t))) || - !(bmRecovered = (int32_t*)malloc(bmh->imagesize * sizeof(int32_t))) || - !(bmTreated = (int32_t*)malloc(bmh->imagesize * sizeof(int32_t)))) + if (!(bmPopulation = (int32_t *)malloc(bmh->imagesize * sizeof(int32_t))) || + !(bmInfected = (int32_t *)malloc(bmh->imagesize * sizeof(int32_t))) || + !(bmRecovered = (int32_t *)malloc(bmh->imagesize * sizeof(int32_t))) || + !(bmTreated = (int32_t *)malloc(bmh->imagesize * sizeof(int32_t)))) ERR_CRITICAL("Unable to allocate storage for bitmap\n"); - if (P.BitmapFormat == BitmapFormats::PNG) { #ifdef _WIN32 - bmpdib = CreateDIBSection(GetDC(NULL), (BITMAPINFO*)bmp, DIB_RGB_COLORS, (void**)&bmPixels, NULL, NULL); - Gdiplus::GdiplusStartupInput gdiplusStartupInput; - Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL); + bmpdib = CreateDIBSection(GetDC(NULL), (BITMAPINFO *)bmp, DIB_RGB_COLORS, (void **)&bmPixels, + NULL, NULL); + Gdiplus::GdiplusStartupInput gdiplusStartupInput; + Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL); - UINT num = 0; // number of image encoders - UINT size = 0; // size of the image encoder array in bytes + UINT num = 0; // number of image encoders + UINT size = 0; // size of the image encoder array in bytes - Gdiplus::ImageCodecInfo* pImageCodecInfo = NULL; - Gdiplus::GetImageEncodersSize(&num, &size); - if (!(pImageCodecInfo = (Gdiplus::ImageCodecInfo*)(malloc(size)))) - ERR_CRITICAL("Unable to allocate storage for bitmap\n"); - Gdiplus::GetImageEncoders(num, size, pImageCodecInfo); - for (UINT j = 0; j < num; ++j) { - // Visual Studio Analyze incorrectly reports this because it doesn't understand Gdiplus::GetImageEncodersSize() - // warning C6385: Reading invalid data from 'pImageCodecInfo': the readable size is 'size' bytes, but '208' bytes may be read. -#pragma warning( suppress: 6385 ) - const WCHAR* type = pImageCodecInfo[j].MimeType; - if (wcscmp(type, L"image/png") == 0) { - encoderClsid = pImageCodecInfo[j].Clsid; - j = num; - } - } - free(pImageCodecInfo); + Gdiplus::ImageCodecInfo *pImageCodecInfo = NULL; + Gdiplus::GetImageEncodersSize(&num, &size); + if (!(pImageCodecInfo = (Gdiplus::ImageCodecInfo *)(malloc(size)))) + ERR_CRITICAL("Unable to allocate storage for bitmap\n"); + Gdiplus::GetImageEncoders(num, size, pImageCodecInfo); + for (UINT j = 0; j < num; ++j) + { + // Visual Studio Analyze incorrectly reports this because it doesn't understand + // Gdiplus::GetImageEncodersSize() warning C6385: Reading invalid data from 'pImageCodecInfo': + // the readable size is 'size' bytes, but '208' bytes may be read. +#pragma warning(suppress : 6385) + const WCHAR *type = pImageCodecInfo[j].MimeType; + if (wcscmp(type, L"image/png") == 0) + { + encoderClsid = pImageCodecInfo[j].Clsid; + j = num; + } + } + free(pImageCodecInfo); #endif } - char buf[1024+3]; + char buf[1024 + 3]; sprintf(buf, "%s.ge", OutFileBase); #ifdef _WIN32 - if (!(CreateDirectory(buf, NULL))) fprintf(stderr, "Unable to create directory %s\n", buf); + if (!(CreateDirectory(buf, NULL))) + fprintf(stderr, "Unable to create directory %s\n", buf); #else - if (!(mkdir(buf, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH))) fprintf(stderr, "Unable to create directory %s\n", buf); + if (!(mkdir(buf, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH))) + fprintf(stderr, "Unable to create directory %s\n", buf); #endif } void Bitmap_Finalise() { #ifdef _WIN32 - if (P.BitmapFormat == BitmapFormats::PNG) - { - Gdiplus::GdiplusShutdown(m_gdiplusToken); - } + if (P.BitmapFormat == BitmapFormats::PNG) + { + Gdiplus::GdiplusShutdown(m_gdiplusToken); + } #endif } diff --git a/src/Bitmap.h b/src/Bitmap.h index a11d53155..31b85ef2f 100644 --- a/src/Bitmap.h +++ b/src/Bitmap.h @@ -13,9 +13,9 @@ #ifdef _WIN32 #define _WIN32_WINNT 0x0400 #define WIN32_LEAN_AND_MEAN -#include -#include #include +#include +#include #endif #ifdef IMAGE_MAGICK #include "Magick++.h" @@ -39,7 +39,7 @@ struct BitmapHeader }; extern int32_t *bmPopulation, *bmInfected, *bmRecovered, *bmTreated; -extern BitmapHeader* bmh; +extern BitmapHeader *bmh; void CaptureBitmap(); void OutputBitmap(int); diff --git a/src/CalcInfSusc.cpp b/src/CalcInfSusc.cpp index 5bcee58bf..89da1cfd4 100644 --- a/src/CalcInfSusc.cpp +++ b/src/CalcInfSusc.cpp @@ -7,64 +7,91 @@ #include "ModelMacros.h" #include "Param.h" -//// Infectiousness functions (House, Place, Spatial, Person). Idea is that in addition to a person's personal infectiousness, they have separate "infectiousnesses" for their house, place and on other cells (spatial). -//// These functions consider one person only. A person has an infectiousness that is independent of other people. Slightly different therefore than susceptibility functions. +//// Infectiousness functions (House, Place, Spatial, Person). Idea is that in addition to a +/// person's personal infectiousness, they have separate "infectiousnesses" for their house, place +/// and on other cells (spatial). / These functions consider one person only. A person has an +/// infectiousness that is independent of other people. Slightly different therefore than +/// susceptibility functions. double CalcHouseInf(int j, unsigned short int ts) { - return ((HOST_ISOLATED(j) && (Hosts[j].digitalContactTraced != 1)) ? P.CaseIsolationHouseEffectiveness : 1.0) - * ((Hosts[j].digitalContactTraced==1) ? P.DCTCaseIsolationHouseEffectiveness : 1.0) - * ((HOST_QUARANTINED(j) && (Hosts[j].digitalContactTraced != 1) && (!(HOST_ISOLATED(j))))? P.HQuarantineHouseEffect : 1.0) - * P.HouseholdDenomLookup[Households[Hosts[j].hh].nhr - 1] * CalcPersonInf(j, ts); + return ((HOST_ISOLATED(j) && (Hosts[j].digitalContactTraced != 1)) + ? P.CaseIsolationHouseEffectiveness + : 1.0) * + ((Hosts[j].digitalContactTraced == 1) ? P.DCTCaseIsolationHouseEffectiveness : 1.0) * + ((HOST_QUARANTINED(j) && (Hosts[j].digitalContactTraced != 1) && (!(HOST_ISOLATED(j)))) + ? P.HQuarantineHouseEffect + : 1.0) * + P.HouseholdDenomLookup[Households[Hosts[j].hh].nhr - 1] * CalcPersonInf(j, ts); } double CalcPlaceInf(int j, int k, unsigned short int ts) { - return ((HOST_ISOLATED(j) && (Hosts[j].digitalContactTraced != 1)) ? P.CaseIsolationEffectiveness : 1.0) - * ((Hosts[j].digitalContactTraced==1) ? P.DCTCaseIsolationEffectiveness : 1.0) - * ((HOST_QUARANTINED(j) && (Hosts[j].digitalContactTraced != 1) && (!(HOST_ISOLATED(j)))) ? P.HQuarantinePlaceEffect[k] : 1.0) - * ((Hosts[j].inf == InfStat_Case) ? P.SymptPlaceTypeContactRate[k] : 1.0) - * P.PlaceTypeTrans[k] / P.PlaceTypeGroupSizeParam1[k] * CalcPersonInf(j, ts); + return ((HOST_ISOLATED(j) && (Hosts[j].digitalContactTraced != 1)) ? P.CaseIsolationEffectiveness + : 1.0) * + ((Hosts[j].digitalContactTraced == 1) ? P.DCTCaseIsolationEffectiveness : 1.0) * + ((HOST_QUARANTINED(j) && (Hosts[j].digitalContactTraced != 1) && (!(HOST_ISOLATED(j)))) + ? P.HQuarantinePlaceEffect[k] + : 1.0) * + ((Hosts[j].inf == InfStat_Case) ? P.SymptPlaceTypeContactRate[k] : 1.0) * + P.PlaceTypeTrans[k] / P.PlaceTypeGroupSizeParam1[k] * CalcPersonInf(j, ts); } double CalcSpatialInf(int j, unsigned short int ts) { - return ((HOST_ISOLATED(j) && (Hosts[j].digitalContactTraced != 1)) ? P.CaseIsolationEffectiveness : 1.0) - * ((Hosts[j].digitalContactTraced==1) ? P.DCTCaseIsolationEffectiveness : 1.0) - * ((HOST_QUARANTINED(j) && (Hosts[j].digitalContactTraced != 1) && (!(HOST_ISOLATED(j)))) ? P.HQuarantineSpatialEffect : 1.0) - * ((Hosts[j].inf == InfStat_Case) ? P.SymptSpatialContactRate : 1.0) - * P.RelativeSpatialContact[HOST_AGE_GROUP(j)] - * CalcPersonInf(j, ts); /* *Hosts[j].spatial_norm */ + return ((HOST_ISOLATED(j) && (Hosts[j].digitalContactTraced != 1)) ? P.CaseIsolationEffectiveness + : 1.0) * + ((Hosts[j].digitalContactTraced == 1) ? P.DCTCaseIsolationEffectiveness : 1.0) * + ((HOST_QUARANTINED(j) && (Hosts[j].digitalContactTraced != 1) && (!(HOST_ISOLATED(j)))) + ? P.HQuarantineSpatialEffect + : 1.0) * + ((Hosts[j].inf == InfStat_Case) ? P.SymptSpatialContactRate : 1.0) * + P.RelativeSpatialContact[HOST_AGE_GROUP(j)] * + CalcPersonInf(j, ts); /* *Hosts[j].spatial_norm */ } double CalcPersonInf(int j, unsigned short int ts) { - return (HOST_TREATED(j) ? P.TreatInfDrop : 1.0) - * (HOST_VACCED(j) ? P.VaccInfDrop : 1.0) - * fabs(Hosts[j].infectiousness) - * P.infectiousness[ts - Hosts[j].latent_time - 1]; + return (HOST_TREATED(j) ? P.TreatInfDrop : 1.0) * (HOST_VACCED(j) ? P.VaccInfDrop : 1.0) * + fabs(Hosts[j].infectiousness) * P.infectiousness[ts - Hosts[j].latent_time - 1]; } -//// Susceptibility functions (House, Place, Spatial, Person). Similarly, idea is that in addition to a person's personal susceptibility, they have separate "susceptibilities" for their house, place and on other cells (spatial) -//// These functions consider two people. A person has a susceptibility TO ANOTHER PERSON/infector. Slightly different therefore than infectiousness functions. +//// Susceptibility functions (House, Place, Spatial, Person). Similarly, idea is that in addition +/// to a person's personal susceptibility, they have separate "susceptibilities" for their house, +/// place and on other cells (spatial) / These functions consider two people. A person has a +/// susceptibility TO ANOTHER PERSON/infector. Slightly different therefore than infectiousness +/// functions. double CalcHouseSusc(int ai, unsigned short int ts, int infector, int tn) { - return CalcPersonSusc(ai, ts, infector, tn) - * ((Mcells[Hosts[ai].mcell].socdist == 2) ? ((Hosts[ai].esocdist_comply) ? P.EnhancedSocDistHouseholdEffectCurrent : P.SocDistHouseholdEffectCurrent) : 1.0) - * (Hosts[ai].digitalContactTraced==1 ? P.DCTCaseIsolationHouseEffectiveness : 1.0); + return CalcPersonSusc(ai, ts, infector, tn) * + ((Mcells[Hosts[ai].mcell].socdist == 2) + ? ((Hosts[ai].esocdist_comply) ? P.EnhancedSocDistHouseholdEffectCurrent + : P.SocDistHouseholdEffectCurrent) + : 1.0) * + (Hosts[ai].digitalContactTraced == 1 ? P.DCTCaseIsolationHouseEffectiveness : 1.0); } double CalcPlaceSusc(int ai, int k, unsigned short int ts, int infector, int tn) { - return ((HOST_QUARANTINED(ai) && (Hosts[ai].digitalContactTraced != 1)) ? P.HQuarantinePlaceEffect[k] : 1.0) - * ((Mcells[Hosts[ai].mcell].socdist == 2) ? ((Hosts[ai].esocdist_comply) ? P.EnhancedSocDistPlaceEffectCurrent[k] : P.SocDistPlaceEffectCurrent[k]) : 1.0) - * (Hosts[ai].digitalContactTraced==1 ? P.DCTCaseIsolationEffectiveness : 1.0); + return ((HOST_QUARANTINED(ai) && (Hosts[ai].digitalContactTraced != 1)) + ? P.HQuarantinePlaceEffect[k] + : 1.0) * + ((Mcells[Hosts[ai].mcell].socdist == 2) + ? ((Hosts[ai].esocdist_comply) ? P.EnhancedSocDistPlaceEffectCurrent[k] + : P.SocDistPlaceEffectCurrent[k]) + : 1.0) * + (Hosts[ai].digitalContactTraced == 1 ? P.DCTCaseIsolationEffectiveness : 1.0); } double CalcSpatialSusc(int ai, unsigned short int ts, int infector, int tn) { - return ((HOST_QUARANTINED(ai) && (Hosts[ai].digitalContactTraced != 1)) ? P.HQuarantineSpatialEffect : 1.0) - * ((Mcells[Hosts[ai].mcell].socdist == 2) ? ((Hosts[ai].esocdist_comply) ? P.EnhancedSocDistSpatialEffectCurrent : P.SocDistSpatialEffectCurrent) : 1.0) - * (Hosts[ai].digitalContactTraced==1 ? P.DCTCaseIsolationEffectiveness : 1.0); + return ((HOST_QUARANTINED(ai) && (Hosts[ai].digitalContactTraced != 1)) + ? P.HQuarantineSpatialEffect + : 1.0) * + ((Mcells[Hosts[ai].mcell].socdist == 2) + ? ((Hosts[ai].esocdist_comply) ? P.EnhancedSocDistSpatialEffectCurrent + : P.SocDistSpatialEffectCurrent) + : 1.0) * + (Hosts[ai].digitalContactTraced == 1 ? P.DCTCaseIsolationEffectiveness : 1.0); } double CalcPersonSusc(int ai, unsigned short int ts, int infector, int tn) { - return P.WAIFW_Matrix[HOST_AGE_GROUP(ai)][HOST_AGE_GROUP(infector)] - * P.AgeSusceptibility[HOST_AGE_GROUP(ai)] * Hosts[ai].susc - * (HOST_TREATED(ai) ? P.TreatSuscDrop : 1.0) - * (HOST_VACCED(ai) ? (HOST_VACCED_SWITCH(ai) ? P.VaccSuscDrop2 : P.VaccSuscDrop) : 1.0); + return P.WAIFW_Matrix[HOST_AGE_GROUP(ai)][HOST_AGE_GROUP(infector)] * + P.AgeSusceptibility[HOST_AGE_GROUP(ai)] * Hosts[ai].susc * + (HOST_TREATED(ai) ? P.TreatSuscDrop : 1.0) * + (HOST_VACCED(ai) ? (HOST_VACCED_SWITCH(ai) ? P.VaccSuscDrop2 : P.VaccSuscDrop) : 1.0); } diff --git a/src/Constants.h b/src/Constants.h index 678ea161e..08b936bd9 100644 --- a/src/Constants.h +++ b/src/Constants.h @@ -91,11 +91,13 @@ const int MAX_DUR_IMPORT_PROFILE = 10245; const int MAX_AIRPORTS = 5000; const int NNA = 10; -// Need to use define for MAX_DIST_AIRPORT_TO_HOTEL to avoid differences between GCC and clang in requirements to share const doubles in OpenMP default(none) pragmas +// Need to use define for MAX_DIST_AIRPORT_TO_HOTEL to avoid differences between GCC and clang in +// requirements to share const doubles in OpenMP default(none) pragmas #define MAX_DIST_AIRPORT_TO_HOTEL 200000.0 const int MIN_HOTELS_PER_AIRPORT = 20; const int HOTELS_PER_1000PASSENGER = 10; -const int MAX_NUM_INTERVENTION_CHANGE_TIMES = 100; // may want to make this intervention-specifc, but keep simple for now. +const int MAX_NUM_INTERVENTION_CHANGE_TIMES = + 100; // may want to make this intervention-specifc, but keep simple for now. #endif // COVIDSIM_CONSTANTS_H_INCLUDED_ diff --git a/src/Country.h b/src/Country.h index e3ff6ac70..16203d495 100644 --- a/src/Country.h +++ b/src/Country.h @@ -1,7 +1,6 @@ #ifndef COVIDSIM_COUNTRY_H_INCLUDED_ #define COVIDSIM_COUNTRY_H_INCLUDED_ - const int MAX_HOUSEHOLD_SIZE = 10; const int MAX_INTERVENTION_TYPES = 1; const int MAX_INTERVENTIONS_PER_ADUNIT = 10; diff --git a/src/CovidSim.cpp b/src/CovidSim.cpp index 539a8d414..0a6f1b90d 100644 --- a/src/CovidSim.cpp +++ b/src/CovidSim.cpp @@ -5,21 +5,21 @@ #include #include -#include "CovidSim.h" #include "BinIO.h" -#include "Rand.h" -#include "Error.h" +#include "Bitmap.h" +#include "CalcInfSusc.h" +#include "CovidSim.h" #include "Dist.h" +#include "Error.h" +#include "InfStat.h" #include "Kernels.h" -#include "Bitmap.h" #include "Model.h" +#include "ModelMacros.h" #include "Param.h" +#include "Rand.h" #include "SetupModel.h" -#include "ModelMacros.h" -#include "InfStat.h" -#include "CalcInfSusc.h" -#include "Update.h" #include "Sweep.h" +#include "Update.h" #ifdef _OPENMP #include @@ -34,95 +34,117 @@ #include #endif -void ReadParams(char*, char*); -void ReadInterventions(char*); -int GetXMLNode(FILE*, const char*, const char*, char*, int); -void ReadAirTravel(char*); -void InitModel(int); //adding run number as a parameter for event log: ggilani - 15/10/2014 -void SeedInfection(double, int*, int, int); //adding run number as a parameter for event log: ggilani - 15/10/2014 -int RunModel(int); //adding run number as a parameter for event log: ggilani - 15/10/2014 +void ReadParams(char *, char *); +void ReadInterventions(char *); +int GetXMLNode(FILE *, const char *, const char *, char *, int); +void ReadAirTravel(char *); +void InitModel(int); // adding run number as a parameter for event log: ggilani - 15/10/2014 +void SeedInfection(double, int *, int, + int); // adding run number as a parameter for event log: ggilani - 15/10/2014 +int RunModel(int); // adding run number as a parameter for event log: ggilani - 15/10/2014 void SaveDistribs(void); -void SaveOriginDestMatrix(void); //added function to save origin destination matrix so it can be done separately to the main results: ggilani - 13/02/15 +void SaveOriginDestMatrix(void); // added function to save origin destination matrix so it can be + // done separately to the main results: ggilani - 13/02/15 void SaveResults(void); void SaveSummaryResults(void); -void SaveRandomSeeds(void); //added this function to save random seeds for each run: ggilani - 09/03/17 -void SaveEvents(void); //added this function to save infection events from all realisations: ggilani - 15/10/14 +void SaveRandomSeeds( + void); // added this function to save random seeds for each run: ggilani - 09/03/17 +void SaveEvents( + void); // added this function to save infection events from all realisations: ggilani - 15/10/14 void LoadSnapshot(void); void SaveSnapshot(void); void RecordInfTypes(void); void RecordSample(double, int); -void CalcOriginDestMatrix_adunit(void); //added function to calculate origin destination matrix: ggilani 28/01/15 +void CalcOriginDestMatrix_adunit( + void); // added function to calculate origin destination matrix: ggilani 28/01/15 -int GetInputParameter(FILE*, FILE*, const char*, const char*, void*, int, int, int); -int GetInputParameter2(FILE*, FILE*, const char*, const char*, void*, int, int, int); -int GetInputParameter2all(FILE*, FILE*, FILE*, const char*, const char*, void*, int, int, int); -int GetInputParameter3(FILE*, const char*, const char*, void*, int, int, int); +int GetInputParameter(FILE *, FILE *, const char *, const char *, void *, int, int, int); +int GetInputParameter2(FILE *, FILE *, const char *, const char *, void *, int, int, int); +int GetInputParameter2all(FILE *, FILE *, FILE *, const char *, const char *, void *, int, int, + int); +int GetInputParameter3(FILE *, const char *, const char *, void *, int, int, int); -void SetICDF(double* icdf, double startValue); +void SetICDF(double *icdf, double startValue); - -///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// -///// ***** ///// ***** ///// ***** ///// ***** ///// ***** GLOBAL VARIABLES (some structures in CovidSim.h file and some containers) - memory allocated later. -///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// +///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** +//////// ***** ///// ***** ///// ***** ///// ***** ///// +///// ***** ///// ***** ///// ***** ///// ***** ///// ***** GLOBAL VARIABLES (some structures in +/// CovidSim.h file and some containers) - memory allocated later. +///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** +//////// ***** ///// ***** ///// ***** ///// ***** ///// Param P; -Person* Hosts; -Household* Households; +Person *Hosts; +Household *Households; PopVar State, StateT[MAX_NUM_THREADS]; -Cell* Cells; // Cells[i] is the i'th cell -Cell ** CellLookup; // CellLookup[i] is a pointer to the i'th populated cell -Microcell* Mcells, ** McellLookup; -Place** Places; +Cell *Cells; // Cells[i] is the i'th cell +Cell **CellLookup; // CellLookup[i] is a pointer to the i'th populated cell +Microcell *Mcells, **McellLookup; +Place **Places; AdminUnit AdUnits[MAX_ADUNITS]; //// Time Series defs: -//// TimeSeries is an array of type results, used to store (unsurprisingly) a time series of every quantity in results. Mostly used in RecordSample. -//// TSMeanNE and TSVarNE are the mean and variance of non-extinct time series. TSMeanE and TSVarE are the mean and variance of extinct time series. TSMean and TSVar are pointers that point to either extinct or non-extinct. -Results* TimeSeries, * TSMean, * TSVar, * TSMeanNE, * TSVarNE, * TSMeanE, * TSVarE; //// TimeSeries used in RecordSample, RecordInfTypes, SaveResults. TSMean and TSVar -Airport* Airports; -BitmapHeader* bmh; -//added declaration of pointer to events log: ggilani - 10/10/2014 -Events* InfEventLog; +//// TimeSeries is an array of type results, used to store (unsurprisingly) a time series of every +/// quantity in results. Mostly used in RecordSample. / TSMeanNE and TSVarNE are the mean and +/// variance of non-extinct time series. TSMeanE and TSVarE are the mean and variance of extinct +/// time series. TSMean and TSVar are pointers that point to either extinct or non-extinct. +Results *TimeSeries, *TSMean, *TSVar, *TSMeanNE, *TSVarNE, *TSMeanE, + *TSVarE; //// TimeSeries used in RecordSample, RecordInfTypes, SaveResults. TSMean and TSVar +Airport *Airports; +BitmapHeader *bmh; +// added declaration of pointer to events log: ggilani - 10/10/2014 +Events *InfEventLog; int nEvents; -double inftype[INFECT_TYPE_MASK], inftype_av[INFECT_TYPE_MASK], infcountry[MAX_COUNTRIES], infcountry_av[MAX_COUNTRIES], infcountry_num[MAX_COUNTRIES]; +double inftype[INFECT_TYPE_MASK], inftype_av[INFECT_TYPE_MASK], infcountry[MAX_COUNTRIES], + infcountry_av[MAX_COUNTRIES], infcountry_num[MAX_COUNTRIES]; double indivR0[MAX_SEC_REC][MAX_GEN_REC], indivR0_av[MAX_SEC_REC][MAX_GEN_REC]; -double inf_household[MAX_HOUSEHOLD_SIZE + 1][MAX_HOUSEHOLD_SIZE + 1], denom_household[MAX_HOUSEHOLD_SIZE + 1]; -double inf_household_av[MAX_HOUSEHOLD_SIZE + 1][MAX_HOUSEHOLD_SIZE + 1], AgeDist[NUM_AGE_GROUPS], AgeDist2[NUM_AGE_GROUPS]; -double case_household[MAX_HOUSEHOLD_SIZE + 1][MAX_HOUSEHOLD_SIZE + 1], case_household_av[MAX_HOUSEHOLD_SIZE + 1][MAX_HOUSEHOLD_SIZE + 1]; +double inf_household[MAX_HOUSEHOLD_SIZE + 1][MAX_HOUSEHOLD_SIZE + 1], + denom_household[MAX_HOUSEHOLD_SIZE + 1]; +double inf_household_av[MAX_HOUSEHOLD_SIZE + 1][MAX_HOUSEHOLD_SIZE + 1], AgeDist[NUM_AGE_GROUPS], + AgeDist2[NUM_AGE_GROUPS]; +double case_household[MAX_HOUSEHOLD_SIZE + 1][MAX_HOUSEHOLD_SIZE + 1], + case_household_av[MAX_HOUSEHOLD_SIZE + 1][MAX_HOUSEHOLD_SIZE + 1]; double PropPlaces[NUM_AGE_GROUPS * AGE_GROUP_WIDTH][NUM_PLACE_TYPES]; double PropPlacesC[NUM_AGE_GROUPS * AGE_GROUP_WIDTH][NUM_PLACE_TYPES], AirTravelDist[MAX_DIST]; double PeakHeightSum, PeakHeightSS, PeakTimeSum, PeakTimeSS; // These allow up to about 2 billion people per pixel, which should be ample. -int32_t *bmPopulation; // The population in each bitmap pixel. Special value -1 means "country boundary" -int32_t *bmInfected; // The number of infected people in each bitmap pixel. +int32_t + *bmPopulation; // The population in each bitmap pixel. Special value -1 means "country boundary" +int32_t *bmInfected; // The number of infected people in each bitmap pixel. int32_t *bmRecovered; // The number of recovered people in each bitmap pixel. -int32_t *bmTreated; // The number of treated people in each bitmap pixel. +int32_t *bmTreated; // The number of treated people in each bitmap pixel. -char OutFile[1024], OutFileBase[1024], OutDensFile[1024], SnapshotLoadFile[1024], SnapshotSaveFile[1024], AdunitFile[1024]; +char OutFile[1024], OutFileBase[1024], OutDensFile[1024], SnapshotLoadFile[1024], + SnapshotSaveFile[1024], AdunitFile[1024]; int ns, DoInitUpdateProbs, InterruptRun = 0; int PlaceDistDistrib[NUM_PLACE_TYPES][MAX_DIST], PlaceSizeDistrib[NUM_PLACE_TYPES][MAX_PLACE_SIZE]; - /* int NumPC,NumPCD; */ const int MAXINTFILE = 10; /* default start value for icdf arrays */ const int ICDF_START = 100; -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { - char ParamFile[1024]{}, DensityFile[1024]{}, NetworkFile[1024]{}, AirTravelFile[1024]{}, SchoolFile[1024]{}, RegDemogFile[1024]{}, InterventionFile[MAXINTFILE][1024]{}, PreParamFile[1024]{}, buf[2048]{}, * sep; + char ParamFile[1024]{}, DensityFile[1024]{}, NetworkFile[1024]{}, AirTravelFile[1024]{}, + SchoolFile[1024]{}, RegDemogFile[1024]{}, InterventionFile[MAXINTFILE][1024]{}, + PreParamFile[1024]{}, buf[2048]{}, *sep; int i, GotP, GotPP, GotO, GotL, GotS, GotAP, GotScF, GotNR, Perr, cl; ///// Flags to ensure various parameters have been read; set to false as default. GotP = GotO = GotL = GotS = GotAP = GotScF = GotPP = GotNR = 0; Perr = 0; - fprintf(stderr, "sizeof(int)=%i sizeof(long)=%i sizeof(float)=%i sizeof(double)=%i sizeof(unsigned short int)=%i sizeof(int *)=%i\n", (int)sizeof(int), (int)sizeof(long), (int)sizeof(float), (int)sizeof(double), (int)sizeof(unsigned short int), (int)sizeof(int*)); + fprintf(stderr, + "sizeof(int)=%i sizeof(long)=%i sizeof(float)=%i sizeof(double)=%i sizeof(unsigned short " + "int)=%i sizeof(int *)=%i\n", + (int)sizeof(int), (int)sizeof(long), (int)sizeof(float), (int)sizeof(double), + (int)sizeof(unsigned short int), (int)sizeof(int *)); cl = clock(); // Default bitmap format is platform dependent. @@ -132,9 +154,11 @@ int main(int argc, char* argv[]) P.BitmapFormat = BitmapFormats::BMP; #endif - ///// Read in command line arguments - lots of things, e.g. random number seeds; (pre)parameter files; binary files; population data; output directory? etc. + ///// Read in command line arguments - lots of things, e.g. random number seeds; (pre)parameter + /// files; binary files; population data; output directory? etc. - if (argc < 7) Perr = 1; + if (argc < 7) + Perr = 1; else { ///// Get seeds. @@ -145,16 +169,22 @@ int main(int argc, char* argv[]) sscanf(argv[i + 3], "%i", &P.runSeed2); ///// Set parameter defaults - read them in after - P.PlaceCloseIndepThresh = P.LoadSaveNetwork = P.DoHeteroDensity = P.DoPeriodicBoundaries = P.DoSchoolFile = P.DoAdunitDemog = P.OutputDensFile = P.MaxNumThreads = P.DoInterventionFile = 0; + P.PlaceCloseIndepThresh = P.LoadSaveNetwork = P.DoHeteroDensity = P.DoPeriodicBoundaries = + P.DoSchoolFile = P.DoAdunitDemog = P.OutputDensFile = P.MaxNumThreads = + P.DoInterventionFile = 0; P.CaseOrDeathThresholdBeforeAlert = 0; P.R0scale = 1.0; - P.KernelOffsetScale = P.KernelPowerScale = 1.0; //added this so that kernel parameters are only changed if input from the command line: ggilani - 15/10/2014 - P.DoSaveSnapshot = P.DoLoadSnapshot = 0; + P.KernelOffsetScale = P.KernelPowerScale = + 1.0; // added this so that kernel parameters are only changed if input from the command + // line: ggilani - 15/10/2014 + P.DoSaveSnapshot = P.DoLoadSnapshot = 0; - //// scroll through command line arguments, anticipating what they can be using various if statements. + //// scroll through command line arguments, anticipating what they can be using various if + /// statements. for (i = 1; i < argc - 4; i++) { - if ((argv[i][0] != '/') && ((argv[i][2] != ':') && (argv[i][3] != ':'))) Perr = 1; + if ((argv[i][0] != '/') && ((argv[i][2] != ':') && (argv[i][3] != ':'))) + Perr = 1; if (argv[i][1] == 'P' && argv[i][2] == ':') { GotP = 1; @@ -195,7 +225,10 @@ int main(int argc, char* argv[]) { sscanf(&argv[i][4], "%i", &GotNR); } - else if (argv[i][1] == 'K' && argv[i][2] == 'P' && argv[i][3] == ':') //added Kernel Power and Offset scaling so that it can easily be altered from the command line in order to vary the kernel quickly: ggilani - 15/10/14 + else if (argv[i][1] == 'K' && argv[i][2] == 'P' && + argv[i][3] == ':') // added Kernel Power and Offset scaling so that it can easily be + // altered from the command line in order to vary the kernel + // quickly: ggilani - 15/10/14 { sscanf(&argv[i][4], "%lf", &P.KernelPowerScale); } @@ -203,30 +236,42 @@ int main(int argc, char* argv[]) { sscanf(&argv[i][4], "%lf", &P.KernelOffsetScale); } - else if (argv[i][1] == 'C' && argv[i][2] == 'L' && argv[i][3] == 'P' && argv[i][4] == '1' && argv[i][5] == ':') // generic command line specified param - matched to #1 in param file + else if (argv[i][1] == 'C' && argv[i][2] == 'L' && argv[i][3] == 'P' && argv[i][4] == '1' && + argv[i][5] == + ':') // generic command line specified param - matched to #1 in param file { sscanf(&argv[i][6], "%lf", &P.clP1); } - else if (argv[i][1] == 'C' && argv[i][2] == 'L' && argv[i][3] == 'P' && argv[i][4] == '2' && argv[i][5] == ':') // generic command line specified param - matched to #2 in param file + else if (argv[i][1] == 'C' && argv[i][2] == 'L' && argv[i][3] == 'P' && argv[i][4] == '2' && + argv[i][5] == + ':') // generic command line specified param - matched to #2 in param file { sscanf(&argv[i][6], "%lf", &P.clP2); } - else if(argv[i][1] == 'C' && argv[i][2] == 'L' && argv[i][3] == 'P' && argv[i][4] == '3' && argv[i][5] == ':') // generic command line specified param - matched to #3 in param file - { + else if (argv[i][1] == 'C' && argv[i][2] == 'L' && argv[i][3] == 'P' && argv[i][4] == '3' && + argv[i][5] == + ':') // generic command line specified param - matched to #3 in param file + { sscanf(&argv[i][6], "%lf", &P.clP3); - } - else if(argv[i][1] == 'C' && argv[i][2] == 'L' && argv[i][3] == 'P' && argv[i][4] == '4' && argv[i][5] == ':') // generic command line specified param - matched to #4 in param file - { + } + else if (argv[i][1] == 'C' && argv[i][2] == 'L' && argv[i][3] == 'P' && argv[i][4] == '4' && + argv[i][5] == + ':') // generic command line specified param - matched to #4 in param file + { sscanf(&argv[i][6], "%lf", &P.clP4); - } - else if(argv[i][1] == 'C' && argv[i][2] == 'L' && argv[i][3] == 'P' && argv[i][4] == '5' && argv[i][5] == ':') // generic command line specified param - matched to #5 in param file - { + } + else if (argv[i][1] == 'C' && argv[i][2] == 'L' && argv[i][3] == 'P' && argv[i][4] == '5' && + argv[i][5] == + ':') // generic command line specified param - matched to #5 in param file + { sscanf(&argv[i][6], "%lf", &P.clP5); - } - else if(argv[i][1] == 'C' && argv[i][2] == 'L' && argv[i][3] == 'P' && argv[i][4] == '6' && argv[i][5] == ':') // generic command line specified param - matched to #6 in param file - { + } + else if (argv[i][1] == 'C' && argv[i][2] == 'L' && argv[i][3] == 'P' && argv[i][4] == '6' && + argv[i][5] == + ':') // generic command line specified param - matched to #6 in param file + { sscanf(&argv[i][6], "%lf", &P.clP6); - } + } else if (argv[i][1] == 'A' && argv[i][2] == 'P' && argv[i][3] == ':') { GotAP = 1; @@ -294,24 +339,26 @@ int main(int argc, char* argv[]) if (strcasecmp(buf, "png") == 0) { #if defined(IMAGE_MAGICK) || defined(_WIN32) - P.BitmapFormat = BitmapFormats::PNG; + P.BitmapFormat = BitmapFormats::PNG; #else - fprintf(stderr, "PNG Bitmaps not supported - please build with Image Magic or WIN32 support\n"); - Perr = 1; + fprintf(stderr, + "PNG Bitmaps not supported - please build with Image Magic or WIN32 support\n"); + Perr = 1; #endif } else if (strcasecmp(buf, "bmp") == 0) { - P.BitmapFormat = BitmapFormats::BMP; + P.BitmapFormat = BitmapFormats::BMP; } else { - fprintf(stderr, "Unrecognised bitmap format: %s\n", buf); - Perr = 1; + fprintf(stderr, "Unrecognised bitmap format: %s\n", buf); + Perr = 1; } } } - if (((GotS) && (GotL)) || (!GotP) || (!GotO)) Perr = 1; + if (((GotS) && (GotL)) || (!GotP) || (!GotO)) + Perr = 1; } ///// END Read in command line arguments @@ -320,18 +367,25 @@ int main(int argc, char* argv[]) fprintf(stderr, "Param=%s\nOut=%s\nDens=%s\n", ParamFile, OutFile, DensityFile); fprintf(stderr, "Bitmap Format = *.%s\n", P.BitmapFormat == BitmapFormats::PNG ? "png" : "bmp"); - if (Perr) ERR_CRITICAL_FMT("Syntax:\n%s /P:ParamFile /O:OutputFile [/AP:AirTravelFile] [/s:SchoolFile] [/D:DensityFile] [/L:NetworkFileToLoad | /S:NetworkFileToSave] [/R:R0scaling] SetupSeed1 SetupSeed2 RunSeed1 RunSeed2\n", argv[0]); + if (Perr) + ERR_CRITICAL_FMT("Syntax:\n%s /P:ParamFile /O:OutputFile [/AP:AirTravelFile] [/s:SchoolFile] " + "[/D:DensityFile] [/L:NetworkFileToLoad | /S:NetworkFileToSave] " + "[/R:R0scaling] SetupSeed1 SetupSeed2 RunSeed1 RunSeed2\n", + argv[0]); - //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** - //// **** SET UP OMP / THREADS - //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** + //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// + ///**** //// **** //// **** //// **** //// **** / **** SET UP OMP / THREADS / **** //// **** + /////// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** + /////// **** //// **** //// **** #ifdef _OPENMP P.NumThreads = omp_get_max_threads(); - if ((P.MaxNumThreads > 0) && (P.MaxNumThreads < P.NumThreads)) P.NumThreads = P.MaxNumThreads; + if ((P.MaxNumThreads > 0) && (P.MaxNumThreads < P.NumThreads)) + P.NumThreads = P.MaxNumThreads; if (P.NumThreads > MAX_NUM_THREADS) { - fprintf(stderr, "Assigned number of threads (%d) > MAX_NUM_THREADS (%d)\n", P.NumThreads, MAX_NUM_THREADS); + fprintf(stderr, "Assigned number of threads (%d) > MAX_NUM_THREADS (%d)\n", P.NumThreads, + MAX_NUM_THREADS); P.NumThreads = MAX_NUM_THREADS; } fprintf(stderr, "Using %d threads\n", P.NumThreads); @@ -341,7 +395,8 @@ int main(int argc, char* argv[]) { fprintf(stderr, "Thread %i initialised\n", omp_get_thread_num()); } - /* fprintf(stderr,"int=%i\tfloat=%i\tdouble=%i\tint *=%i\n",(int) sizeof(int),(int) sizeof(float),(int) sizeof(double),(int) sizeof(int *)); */ + /* fprintf(stderr,"int=%i\tfloat=%i\tdouble=%i\tint *=%i\n",(int) sizeof(int),(int) + * sizeof(float),(int) sizeof(double),(int) sizeof(int *)); */ #else P.NumThreads = 1; #endif @@ -350,52 +405,63 @@ int main(int argc, char* argv[]) sprintf(PreParamFile, ".." DIRECTORY_SEPARATOR "Pre_%s", ParamFile); } - //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** - //// **** READ IN PARAMETERS, DATA ETC. - //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** - + //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// + ///**** //// **** //// **** //// **** //// **** / **** READ IN PARAMETERS, DATA ETC. / **** //// + ///**** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** + /////// **** //// **** //// **** P.NumRealisations = GotNR; ReadParams(ParamFile, PreParamFile); - if (GotScF) P.DoSchoolFile = 1; + if (GotScF) + P.DoSchoolFile = 1; if (P.DoAirports) { - if (!GotAP) ERR_CRITICAL_FMT("Syntax:\n%s /P:ParamFile /O:OutputFile /AP:AirTravelFile [/s:SchoolFile] [/D:DensityFile] [/L:NetworkFileToLoad | /S:NetworkFileToSave] [/R:R0scaling] SetupSeed1 SetupSeed2 RunSeed1 RunSeed2\n", argv[0]); + if (!GotAP) + ERR_CRITICAL_FMT("Syntax:\n%s /P:ParamFile /O:OutputFile /AP:AirTravelFile [/s:SchoolFile] " + "[/D:DensityFile] [/L:NetworkFileToLoad | /S:NetworkFileToSave] " + "[/R:R0scaling] SetupSeed1 SetupSeed2 RunSeed1 RunSeed2\n", + argv[0]); ReadAirTravel(AirTravelFile); } - //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** - //// **** INITIALIZE - //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** + //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// + ///**** //// **** //// **** //// **** //// **** / **** INITIALIZE / **** //// **** //// **** //// + ///**** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** + /////// **** ///// initialize model (for all realisations). SetupModel(DensityFile, NetworkFile, SchoolFile, RegDemogFile); - for (i = 0; i < MAX_ADUNITS; i++) AdUnits[i].NI = 0; + for (i = 0; i < MAX_ADUNITS; i++) + AdUnits[i].NI = 0; if (P.DoInterventionFile > 0) for (i = 0; i < P.DoInterventionFile; i++) ReadInterventions(InterventionFile[i]); fprintf(stderr, "Model setup in %lf seconds\n", ((double)(clock() - cl)) / CLOCKS_PER_SEC); - //print out number of calls to random number generator - - //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** - //// **** RUN MODEL - //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** + // print out number of calls to random number generator + //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// + ///**** //// **** //// **** //// **** //// **** / **** RUN MODEL / **** //// **** //// **** //// + ///**** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** + /////// **** P.NRactE = P.NRactNE = 0; - for (i = 0; (i < P.NumRealisations) && (P.NRactNE < P.NumNonExtinctRealisations) ; i++) + for (i = 0; (i < P.NumRealisations) && (P.NRactNE < P.NumNonExtinctRealisations); i++) { if (P.NumRealisations > 1) { sprintf(OutFile, "%s.%i", OutFileBase, i); - fprintf(stderr, "Realisation %i of %i (time=%lf nr_ne=%i)\n", i + 1, P.NumRealisations,((double)(clock() - cl)) / CLOCKS_PER_SEC, P.NRactNE); + fprintf(stderr, "Realisation %i of %i (time=%lf nr_ne=%i)\n", i + 1, P.NumRealisations, + ((double)(clock() - cl)) / CLOCKS_PER_SEC, P.NRactNE); } - P.StopCalibration = P.ModelCalibIteration = 0; // needed for calibration to work for multiple realisations + P.StopCalibration = P.ModelCalibIteration = + 0; // needed for calibration to work for multiple realisations P.HolidaysStartDay_SimTime = 0; // needed for calibration to work for multiple realisations - P.CaseOrDeathThresholdBeforeAlert = P.CaseOrDeathThresholdBeforeAlert_Fixed; // needed for calibration to work for multiple realisations + P.CaseOrDeathThresholdBeforeAlert = + P.CaseOrDeathThresholdBeforeAlert_Fixed; // needed for calibration to work for multiple + // realisations P.SeedingScaling = 1.0; // needed for calibration to work for multiple realisations ///// Set and save seeds if (i == 0 || (P.ResetSeeds && P.KeepSameSeeds)) @@ -403,31 +469,37 @@ int main(int argc, char* argv[]) P.nextRunSeed1 = P.runSeed1; P.nextRunSeed2 = P.runSeed2; } - if (P.ResetSeeds) { - //save these seeds to file + if (P.ResetSeeds) + { + // save these seeds to file SaveRandomSeeds(); } // Now that we have set P.nextRunSeed* ready for the run, we need to save the values in case // we need to reinitialise the RNG after the run is interrupted. int32_t thisRunSeed1 = P.nextRunSeed1; int32_t thisRunSeed2 = P.nextRunSeed2; -// if (i == 0 || P.ResetSeeds) - setall(&P.nextRunSeed1, &P.nextRunSeed2); + // if (i == 0 || P.ResetSeeds) + setall(&P.nextRunSeed1, &P.nextRunSeed2); ///// initialize model (for this realisation). - InitModel(i); //passing run number into RunModel so we can save run number in the infection event log: ggilani - 15/10/2014 - if (P.DoLoadSnapshot) LoadSnapshot(); + InitModel(i); // passing run number into RunModel so we can save run number in the infection + // event log: ggilani - 15/10/2014 + if (P.DoLoadSnapshot) + LoadSnapshot(); int ModelCalibLoop = 0; while (RunModel(i)) - { // has been interrupted to reset holiday time. Note that this currently only happens in the first run, regardless of how many realisations are being run. + { // has been interrupted to reset holiday time. Note that this currently only happens in the + // first run, regardless of how many realisations are being run. if ((P.ModelCalibIteration == 10) && (ModelCalibLoop < 3)) { thisRunSeed1 = P.nextRunSeed1; thisRunSeed2 = P.nextRunSeed2; setall(&P.nextRunSeed1, &P.nextRunSeed2); - P.ModelCalibIteration = 0; // needed for calibration to work for multiple realisations + P.ModelCalibIteration = 0; // needed for calibration to work for multiple realisations P.HolidaysStartDay_SimTime = 0; // needed for calibration to work for multiple realisations - P.CaseOrDeathThresholdBeforeAlert = P.CaseOrDeathThresholdBeforeAlert_Fixed; // needed for calibration to work for multiple realisations + P.CaseOrDeathThresholdBeforeAlert = + P.CaseOrDeathThresholdBeforeAlert_Fixed; // needed for calibration to work for multiple + // realisations P.SeedingScaling = 1.0; // needed for calibration to work for multiple realisations ModelCalibLoop++; } @@ -435,13 +507,15 @@ int main(int argc, char* argv[]) { int32_t tmp1 = thisRunSeed1; int32_t tmp2 = thisRunSeed2; - setall(&tmp1, &tmp2); // reset random number seeds to generate same run again after calibration. + setall(&tmp1, + &tmp2); // reset random number seeds to generate same run again after calibration. } InitModel(i); } if (P.OutputNonSummaryResults) { - if (((!TimeSeries[P.NumSamples - 1].extinct) || (!P.OutputOnlyNonExtinct)) && (P.OutputEveryRealisation)) + if (((!TimeSeries[P.NumSamples - 1].extinct) || (!P.OutputOnlyNonExtinct)) && + (P.OutputEveryRealisation)) { SaveResults(); } @@ -453,7 +527,7 @@ int main(int argc, char* argv[]) } sprintf(OutFile, "%s", OutFileBase); - //Calculate origin destination matrix if needed + // Calculate origin destination matrix if needed if ((P.DoAdUnits) && (P.DoOriginDestinationMatrix)) { CalcOriginDestMatrix_adunit(); @@ -461,7 +535,8 @@ int main(int argc, char* argv[]) } P.NRactual = P.NRactNE; - TSMean = TSMeanNE; TSVar = TSVarNE; + TSMean = TSMeanNE; + TSVar = TSVarNE; if ((P.DoRecordInfEvents) && (P.RecordInfEventsPerRun == 0)) { SaveEvents(); @@ -469,9 +544,10 @@ int main(int argc, char* argv[]) sprintf(OutFile, "%s.avNE", OutFileBase); SaveSummaryResults(); P.NRactual = P.NRactE; - TSMean = TSMeanE; TSVar = TSVarE; + TSMean = TSMeanE; + TSVar = TSVarE; sprintf(OutFile, "%s.avE", OutFileBase); - //SaveSummaryResults(); + // SaveSummaryResults(); Bitmap_Finalise(); @@ -480,90 +556,163 @@ int main(int argc, char* argv[]) fprintf(stderr, "Model finished\n"); } - -void ReadParams(char* ParamFile, char* PreParamFile) +void ReadParams(char *ParamFile, char *PreParamFile) { - FILE* ParamFile_dat, * PreParamFile_dat, * AdminFile_dat; + FILE *ParamFile_dat, *PreParamFile_dat, *AdminFile_dat; double s, t, AgeSuscScale; int i, j, k, f, nc, na; char CountryNameBuf[128 * MAX_COUNTRIES], AdunitListNamesBuf[128 * MAX_ADUNITS]; - char* CountryNames[MAX_COUNTRIES]; - for (i = 0; i < MAX_COUNTRIES; i++) { CountryNames[i] = CountryNameBuf + 128 * i; CountryNames[i][0] = 0; } - char* AdunitListNames[MAX_ADUNITS]; - for (i = 0; i < MAX_ADUNITS; i++) { AdunitListNames[i] = AdunitListNamesBuf + 128 * i; AdunitListNames[i][0] = 0; } - if (!(ParamFile_dat = fopen(ParamFile, "rb"))) ERR_CRITICAL("Unable to open parameter file\n"); + char *CountryNames[MAX_COUNTRIES]; + for (i = 0; i < MAX_COUNTRIES; i++) + { + CountryNames[i] = CountryNameBuf + 128 * i; + CountryNames[i][0] = 0; + } + char *AdunitListNames[MAX_ADUNITS]; + for (i = 0; i < MAX_ADUNITS; i++) + { + AdunitListNames[i] = AdunitListNamesBuf + 128 * i; + AdunitListNames[i][0] = 0; + } + if (!(ParamFile_dat = fopen(ParamFile, "rb"))) + ERR_CRITICAL("Unable to open parameter file\n"); PreParamFile_dat = fopen(PreParamFile, "rb"); - if (!(AdminFile_dat = fopen(AdunitFile, "rb"))) AdminFile_dat = ParamFile_dat; - if (!GetInputParameter2(ParamFile_dat, AdminFile_dat, "Longitude cut line", "%lf", (void*)&(P.LongitudeCutLine), 1, 1, 0)) { + if (!(AdminFile_dat = fopen(AdunitFile, "rb"))) + AdminFile_dat = ParamFile_dat; + if (!GetInputParameter2(ParamFile_dat, AdminFile_dat, "Longitude cut line", "%lf", + (void *)&(P.LongitudeCutLine), 1, 1, 0)) + { P.LongitudeCutLine = -360.0; } AgeSuscScale = 1.0; - GetInputParameter(ParamFile_dat, PreParamFile_dat, "Update timestep", "%lf", (void*)&(P.TimeStep), 1, 1, 0); - GetInputParameter(ParamFile_dat, PreParamFile_dat, "Sampling timestep", "%lf", (void*)&(P.SampleStep), 1, 1, 0); - if (P.TimeStep > P.SampleStep) ERR_CRITICAL("Update step must be smaller than sampling step\n"); + GetInputParameter(ParamFile_dat, PreParamFile_dat, "Update timestep", "%lf", + (void *)&(P.TimeStep), 1, 1, 0); + GetInputParameter(ParamFile_dat, PreParamFile_dat, "Sampling timestep", "%lf", + (void *)&(P.SampleStep), 1, 1, 0); + if (P.TimeStep > P.SampleStep) + ERR_CRITICAL("Update step must be smaller than sampling step\n"); t = ceil(P.SampleStep / P.TimeStep - 1e-6); P.UpdatesPerSample = (int)t; P.TimeStep = P.SampleStep / t; P.TimeStepsPerDay = ceil(1.0 / P.TimeStep - 1e-6); - fprintf(stderr, "Update step = %lf\nSampling step = %lf\nUpdates per sample=%i\nTimeStepsPerDay=%lf\n", P.TimeStep, P.SampleStep, P.UpdatesPerSample, P.TimeStepsPerDay); - GetInputParameter(ParamFile_dat, PreParamFile_dat, "Sampling time", "%lf", (void*)&(P.SampleTime), 1, 1, 0); + fprintf(stderr, + "Update step = %lf\nSampling step = %lf\nUpdates per sample=%i\nTimeStepsPerDay=%lf\n", + P.TimeStep, P.SampleStep, P.UpdatesPerSample, P.TimeStepsPerDay); + GetInputParameter(ParamFile_dat, PreParamFile_dat, "Sampling time", "%lf", + (void *)&(P.SampleTime), 1, 1, 0); P.NumSamples = 1 + (int)ceil(P.SampleTime / P.SampleStep); - GetInputParameter(PreParamFile_dat, AdminFile_dat, "Population size", "%i", (void*)&(P.PopSize), 1, 1, 0); + GetInputParameter(PreParamFile_dat, AdminFile_dat, "Population size", "%i", (void *)&(P.PopSize), + 1, 1, 0); if (P.NumRealisations == 0) - { - GetInputParameter(ParamFile_dat, PreParamFile_dat, "Number of realisations", "%i", (void*)&(P.NumRealisations), 1, 1, 0); - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Number of non-extinct realisations", "%i", (void*)&(P.NumNonExtinctRealisations), 1, 1, 0)) P.NumNonExtinctRealisations = P.NumRealisations; - } + { + GetInputParameter(ParamFile_dat, PreParamFile_dat, "Number of realisations", "%i", + (void *)&(P.NumRealisations), 1, 1, 0); + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Number of non-extinct realisations", + "%i", (void *)&(P.NumNonExtinctRealisations), 1, 1, 0)) + P.NumNonExtinctRealisations = P.NumRealisations; + } else P.NumNonExtinctRealisations = P.NumRealisations; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Maximum number of cases defining small outbreak", "%i", (void*) & (P.SmallEpidemicCases), 1, 1, 0)) P.SmallEpidemicCases = -1; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Maximum number of cases defining small outbreak", "%i", + (void *)&(P.SmallEpidemicCases), 1, 1, 0)) + P.SmallEpidemicCases = -1; P.NC = -1; - GetInputParameter(ParamFile_dat, PreParamFile_dat, "Number of micro-cells per spatial cell width", "%i", (void*) & (P.NMCL), 1, 1, 0); - //added parameter to reset seeds after every run - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Reset seeds for every run", "%i", (void*) & (P.ResetSeeds), 1, 1, 0)) P.ResetSeeds = 0; + GetInputParameter(ParamFile_dat, PreParamFile_dat, "Number of micro-cells per spatial cell width", + "%i", (void *)&(P.NMCL), 1, 1, 0); + // added parameter to reset seeds after every run + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Reset seeds for every run", "%i", + (void *)&(P.ResetSeeds), 1, 1, 0)) + P.ResetSeeds = 0; if (P.ResetSeeds) { - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Keep same seeds for every run", "%i", (void*) & (P.KeepSameSeeds), 1, 1, 0)) P.KeepSameSeeds = 0; //added this to control which seeds are used: ggilani 27/11/19 + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Keep same seeds for every run", "%i", + (void *)&(P.KeepSameSeeds), 1, 1, 0)) + P.KeepSameSeeds = 0; // added this to control which seeds are used: ggilani 27/11/19 } - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Reset seeds after intervention", "%i", (void*) & (P.ResetSeedsPostIntervention), 1, 1, 0)) P.ResetSeedsPostIntervention = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Reset seeds after intervention", "%i", + (void *)&(P.ResetSeedsPostIntervention), 1, 1, 0)) + P.ResetSeedsPostIntervention = 0; if (P.ResetSeedsPostIntervention) { - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Time to reset seeds after intervention", "%i", (void*) & (P.TimeToResetSeeds), 1, 1, 0)) P.TimeToResetSeeds = 1000000; - } - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Include households", "%i", (void*) & (P.DoHouseholds), 1, 1, 0)) P.DoHouseholds = 1; - - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "OutputAge" , "%i", (void*) & (P.OutputAge) , 1, 1, 0)) P.OutputAge = 1; //// ON by default. - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "OutputSeverityAdminUnit" , "%i", (void*) & (P.OutputSeverityAdminUnit) , 1, 1, 0)) P.OutputSeverityAdminUnit = 1; //// ON by default. - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "OutputSeverityAge" , "%i", (void*) & (P.OutputSeverityAge) , 1, 1, 0)) P.OutputSeverityAge = 1; //// ON by default. - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "OutputAdUnitAge" , "%i", (void*) & (P.OutputAdUnitAge) , 1, 1, 0)) P.OutputAdUnitAge = 0; //// OFF by default. - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "OutputR0" , "%i", (void*) & (P.OutputR0) , 1, 1, 0)) P.OutputR0 = 0; //// OFF by default. - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "OutputControls" , "%i", (void*) & (P.OutputControls) , 1, 1, 0)) P.OutputControls = 0; //// OFF by default. - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "OutputCountry" , "%i", (void*) & (P.OutputCountry) , 1, 1, 0)) P.OutputCountry = 0; //// OFF by default. - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "OutputAdUnitVar" , "%i", (void*) & (P.OutputAdUnitVar) , 1, 1, 0)) P.OutputAdUnitVar = 0; //// OFF by default. - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "OutputHousehold" , "%i", (void*) & (P.OutputHousehold) , 1, 1, 0)) P.OutputHousehold = 0; //// OFF by default. - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "OutputInfType" , "%i", (void*) & (P.OutputInfType) , 1, 1, 0)) P.OutputInfType = 0; //// OFF by default. - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "OutputNonSeverity" , "%i", (void*) & (P.OutputNonSeverity) , 1, 1, 0)) P.OutputNonSeverity = 0; //// OFF by default. - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "OutputNonSummaryResults" , "%i", (void*) & (P.OutputNonSummaryResults) , 1, 1, 0)) P.OutputNonSummaryResults = 0; //// OFF by default. - - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Kernel resolution", "%i", (void*)&P.NKR, 1, 1, 0)) P.NKR = 4000000; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Time to reset seeds after intervention", "%i", + (void *)&(P.TimeToResetSeeds), 1, 1, 0)) + P.TimeToResetSeeds = 1000000; + } + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Include households", "%i", + (void *)&(P.DoHouseholds), 1, 1, 0)) + P.DoHouseholds = 1; + + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "OutputAge", "%i", + (void *)&(P.OutputAge), 1, 1, 0)) + P.OutputAge = 1; //// ON by default. + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "OutputSeverityAdminUnit", "%i", + (void *)&(P.OutputSeverityAdminUnit), 1, 1, 0)) + P.OutputSeverityAdminUnit = 1; //// ON by default. + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "OutputSeverityAge", "%i", + (void *)&(P.OutputSeverityAge), 1, 1, 0)) + P.OutputSeverityAge = 1; //// ON by default. + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "OutputAdUnitAge", "%i", + (void *)&(P.OutputAdUnitAge), 1, 1, 0)) + P.OutputAdUnitAge = 0; //// OFF by default. + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "OutputR0", "%i", (void *)&(P.OutputR0), + 1, 1, 0)) + P.OutputR0 = 0; //// OFF by default. + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "OutputControls", "%i", + (void *)&(P.OutputControls), 1, 1, 0)) + P.OutputControls = 0; //// OFF by default. + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "OutputCountry", "%i", + (void *)&(P.OutputCountry), 1, 1, 0)) + P.OutputCountry = 0; //// OFF by default. + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "OutputAdUnitVar", "%i", + (void *)&(P.OutputAdUnitVar), 1, 1, 0)) + P.OutputAdUnitVar = 0; //// OFF by default. + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "OutputHousehold", "%i", + (void *)&(P.OutputHousehold), 1, 1, 0)) + P.OutputHousehold = 0; //// OFF by default. + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "OutputInfType", "%i", + (void *)&(P.OutputInfType), 1, 1, 0)) + P.OutputInfType = 0; //// OFF by default. + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "OutputNonSeverity", "%i", + (void *)&(P.OutputNonSeverity), 1, 1, 0)) + P.OutputNonSeverity = 0; //// OFF by default. + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "OutputNonSummaryResults", "%i", + (void *)&(P.OutputNonSummaryResults), 1, 1, 0)) + P.OutputNonSummaryResults = 0; //// OFF by default. + + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Kernel resolution", "%i", + (void *)&P.NKR, 1, 1, 0)) + P.NKR = 4000000; if (P.NKR < 2000000) { ERR_CRITICAL_FMT("[Kernel resolution] needs to be at least 2000000 - not %d", P.NKR); } - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Kernel higher resolution factor", "%i", (void*)&P.NK_HR, 1, 1, 0)) P.NK_HR = P.NKR / 1600; + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Kernel higher resolution factor", "%i", + (void *)&P.NK_HR, 1, 1, 0)) + P.NK_HR = P.NKR / 1600; if (P.NK_HR < 1 || P.NK_HR >= P.NKR) { - ERR_CRITICAL_FMT("[Kernel higher resolution factor] needs to be in range [1, P.NKR = %d) - not %d", P.NKR, P.NK_HR); + ERR_CRITICAL_FMT( + "[Kernel higher resolution factor] needs to be in range [1, P.NKR = %d) - not %d", P.NKR, + P.NK_HR); } if (P.DoHouseholds) { - GetInputParameter(PreParamFile_dat, AdminFile_dat, "Household size distribution", "%lf", (void*)P.HouseholdSizeDistrib[0], MAX_HOUSEHOLD_SIZE, 1, 0); - GetInputParameter(ParamFile_dat, PreParamFile_dat, "Household attack rate", "%lf", (void*) & (P.HouseholdTrans), 1, 1, 0); - GetInputParameter(ParamFile_dat, PreParamFile_dat, "Household transmission denominator power", "%lf", (void*) & (P.HouseholdTransPow), 1, 1, 0); - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Correct age distribution after household allocation to exactly match specified demography", "%i", (void*)&(P.DoCorrectAgeDist), 1, 1, 0)) P.DoCorrectAgeDist = 0; + GetInputParameter(PreParamFile_dat, AdminFile_dat, "Household size distribution", "%lf", + (void *)P.HouseholdSizeDistrib[0], MAX_HOUSEHOLD_SIZE, 1, 0); + GetInputParameter(ParamFile_dat, PreParamFile_dat, "Household attack rate", "%lf", + (void *)&(P.HouseholdTrans), 1, 1, 0); + GetInputParameter(ParamFile_dat, PreParamFile_dat, "Household transmission denominator power", + "%lf", (void *)&(P.HouseholdTransPow), 1, 1, 0); + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, + "Correct age distribution after household allocation to exactly match " + "specified demography", + "%i", (void *)&(P.DoCorrectAgeDist), 1, 1, 0)) + P.DoCorrectAgeDist = 0; } else { @@ -577,13 +726,20 @@ void ReadParams(char* ParamFile, char* PreParamFile) P.HouseholdSizeDistrib[0][i] = P.HouseholdSizeDistrib[0][i] + P.HouseholdSizeDistrib[0][i - 1]; for (i = 0; i < MAX_HOUSEHOLD_SIZE; i++) P.HouseholdDenomLookup[i] = 1 / pow(((double)(i + 1)), P.HouseholdTransPow); - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Include administrative units within countries", "%i", (void*) & (P.DoAdUnits), 1, 1, 0)) P.DoAdUnits = 1; - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Divisor for countries", "%i", (void*) & (P.CountryDivisor), 1, 1, 0)) P.CountryDivisor = 1; + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, + "Include administrative units within countries", "%i", + (void *)&(P.DoAdUnits), 1, 1, 0)) + P.DoAdUnits = 1; + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Divisor for countries", "%i", + (void *)&(P.CountryDivisor), 1, 1, 0)) + P.CountryDivisor = 1; if (P.DoAdUnits) { - char** AdunitNames, * AdunitNamesBuf; - if (!(AdunitNames = (char**)malloc(3 * ADUNIT_LOOKUP_SIZE * sizeof(char*)))) ERR_CRITICAL("Unable to allocate temp storage\n"); - if (!(AdunitNamesBuf = (char*)malloc(3 * ADUNIT_LOOKUP_SIZE * 360 * sizeof(char)))) ERR_CRITICAL("Unable to allocate temp storage\n"); + char **AdunitNames, *AdunitNamesBuf; + if (!(AdunitNames = (char **)malloc(3 * ADUNIT_LOOKUP_SIZE * sizeof(char *)))) + ERR_CRITICAL("Unable to allocate temp storage\n"); + if (!(AdunitNamesBuf = (char *)malloc(3 * ADUNIT_LOOKUP_SIZE * 360 * sizeof(char)))) + ERR_CRITICAL("Unable to allocate temp storage\n"); for (i = 0; i < ADUNIT_LOOKUP_SIZE; i++) { @@ -592,53 +748,83 @@ void ReadParams(char* ParamFile, char* PreParamFile) AdunitNames[3 * i + 1] = AdunitNamesBuf + 3 * i * 360 + 60; AdunitNames[3 * i + 2] = AdunitNamesBuf + 3 * i * 360 + 160; } - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Divisor for level 1 administrative units", "%i", (void*)&(P.AdunitLevel1Divisor), 1, 1, 0)) P.AdunitLevel1Divisor = 1; - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Mask for level 1 administrative units", "%i", (void*)&(P.AdunitLevel1Mask), 1, 1, 0)) P.AdunitLevel1Mask = 1000000000; - na = (GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Codes and country/province names for admin units", "%s", (void*)AdunitNames, 3 * ADUNIT_LOOKUP_SIZE, 1, 0)) / 3; - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Number of countries to include", "%i", (void*)&nc, 1, 1, 0)) nc = 0; - if ((na > 0) && (nc>0)) + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, + "Divisor for level 1 administrative units", "%i", + (void *)&(P.AdunitLevel1Divisor), 1, 1, 0)) + P.AdunitLevel1Divisor = 1; + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, + "Mask for level 1 administrative units", "%i", + (void *)&(P.AdunitLevel1Mask), 1, 1, 0)) + P.AdunitLevel1Mask = 1000000000; + na = (GetInputParameter2(PreParamFile_dat, AdminFile_dat, + "Codes and country/province names for admin units", "%s", + (void *)AdunitNames, 3 * ADUNIT_LOOKUP_SIZE, 1, 0)) / + 3; + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Number of countries to include", "%i", + (void *)&nc, 1, 1, 0)) + nc = 0; + if ((na > 0) && (nc > 0)) { P.DoAdunitBoundaries = (nc > 0); nc = abs(nc); - GetInputParameter(PreParamFile_dat, AdminFile_dat, "List of names of countries to include", "%s", (nc > 1) ? ((void*)CountryNames) : ((void*)CountryNames[0]), nc, 1, 0); + GetInputParameter(PreParamFile_dat, AdminFile_dat, "List of names of countries to include", + "%s", (nc > 1) ? ((void *)CountryNames) : ((void *)CountryNames[0]), nc, 1, + 0); P.NumAdunits = 0; for (i = 0; i < na; i++) for (j = 0; j < nc; j++) - if ((AdunitNames[3 * i + 1][0]) && (!strcmp(AdunitNames[3 * i + 1], CountryNames[j])) && (atoi(AdunitNames[3 * i]) != 0)) + if ((AdunitNames[3 * i + 1][0]) && (!strcmp(AdunitNames[3 * i + 1], CountryNames[j])) && + (atoi(AdunitNames[3 * i]) != 0)) { AdUnits[P.NumAdunits].id = atoi(AdunitNames[3 * i]); - P.AdunitLevel1Lookup[(AdUnits[P.NumAdunits].id % P.AdunitLevel1Mask) / P.AdunitLevel1Divisor] = P.NumAdunits; - if (strlen(AdunitNames[3 * i + 1]) < 100) strcpy(AdUnits[P.NumAdunits].cnt_name, AdunitNames[3 * i + 1]); - if (strlen(AdunitNames[3 * i + 2]) < 200) strcpy(AdUnits[P.NumAdunits].ad_name, AdunitNames[3 * i + 2]); - // fprintf(stderr,"%i %s %s ## ",AdUnits[P.NumAdunits].id,AdUnits[P.NumAdunits].cnt_name,AdUnits[P.NumAdunits].ad_name); + P.AdunitLevel1Lookup[(AdUnits[P.NumAdunits].id % P.AdunitLevel1Mask) / + P.AdunitLevel1Divisor] = P.NumAdunits; + if (strlen(AdunitNames[3 * i + 1]) < 100) + strcpy(AdUnits[P.NumAdunits].cnt_name, AdunitNames[3 * i + 1]); + if (strlen(AdunitNames[3 * i + 2]) < 200) + strcpy(AdUnits[P.NumAdunits].ad_name, AdunitNames[3 * i + 2]); + // fprintf(stderr,"%i %s %s ## + //",AdUnits[P.NumAdunits].id,AdUnits[P.NumAdunits].cnt_name,AdUnits[P.NumAdunits].ad_name); P.NumAdunits++; } } else { - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Number of level 1 administrative units to include", "%i", (void*) & (P.NumAdunits), 1, 1, 0)) P.NumAdunits = 0; + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, + "Number of level 1 administrative units to include", "%i", + (void *)&(P.NumAdunits), 1, 1, 0)) + P.NumAdunits = 0; if (P.NumAdunits > 0) { P.DoAdunitBoundaries = 1; - if (P.NumAdunits > MAX_ADUNITS) ERR_CRITICAL("MAX_ADUNITS too small.\n"); - GetInputParameter(PreParamFile_dat, AdminFile_dat, "List of level 1 administrative units to include", "%s", (P.NumAdunits > 1) ? ((void*)AdunitListNames) : ((void*)AdunitListNames[0]), P.NumAdunits, 1, 0); + if (P.NumAdunits > MAX_ADUNITS) + ERR_CRITICAL("MAX_ADUNITS too small.\n"); + GetInputParameter( + PreParamFile_dat, AdminFile_dat, "List of level 1 administrative units to include", + "%s", (P.NumAdunits > 1) ? ((void *)AdunitListNames) : ((void *)AdunitListNames[0]), + P.NumAdunits, 1, 0); na = P.NumAdunits; for (i = 0; i < P.NumAdunits; i++) { f = 0; if (na > 0) { - for (j = 0; (j < na) && (!f); j++) f = (!strcmp(AdunitNames[3 * j + 2], AdunitListNames[i])); - if(f) k = atoi(AdunitNames[3 * (j-1)]); + for (j = 0; (j < na) && (!f); j++) + f = (!strcmp(AdunitNames[3 * j + 2], AdunitListNames[i])); + if (f) + k = atoi(AdunitNames[3 * (j - 1)]); } - if ((na == 0) || (!f)) k = atoi(AdunitListNames[i]); + if ((na == 0) || (!f)) + k = atoi(AdunitListNames[i]); AdUnits[i].id = k; P.AdunitLevel1Lookup[(k % P.AdunitLevel1Mask) / P.AdunitLevel1Divisor] = i; for (j = 0; j < na; j++) if (atoi(AdunitNames[3 * j]) == k) { - if (strlen(AdunitNames[3 * j + 1]) < 100) strcpy(AdUnits[i].cnt_name, AdunitNames[3 * j + 1]); - if (strlen(AdunitNames[3 * j + 2]) < 200) strcpy(AdUnits[i].ad_name, AdunitNames[3 * j + 2]); + if (strlen(AdunitNames[3 * j + 1]) < 100) + strcpy(AdUnits[i].cnt_name, AdunitNames[3 * j + 1]); + if (strlen(AdunitNames[3 * j + 2]) < 200) + strcpy(AdUnits[i].ad_name, AdunitNames[3 * j + 2]); j = na; } } @@ -646,29 +832,57 @@ void ReadParams(char* ParamFile, char* PreParamFile) else P.DoAdunitBoundaries = 0; } - free(AdunitNames); - free(AdunitNamesBuf); - - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Output incidence by administrative unit", "%i", (void*) & (P.DoAdunitOutput), 1, 1, 0)) P.DoAdunitOutput = 0; - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Draw administrative unit boundaries on maps", "%i", (void*) & (P.DoAdunitBoundaryOutput), 1, 1, 0)) P.DoAdunitBoundaryOutput = 0; - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Correct administrative unit populations", "%i", (void*) & (P.DoCorrectAdunitPop), 1, 1, 0)) P.DoCorrectAdunitPop = 0; - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Fix population size at specified value", "%i", (void*) & (P.DoSpecifyPop), 1, 1, 0)) P.DoSpecifyPop = 0; + free(AdunitNames); + free(AdunitNamesBuf); + + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Output incidence by administrative unit", "%i", + (void *)&(P.DoAdunitOutput), 1, 1, 0)) + P.DoAdunitOutput = 0; + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, + "Draw administrative unit boundaries on maps", "%i", + (void *)&(P.DoAdunitBoundaryOutput), 1, 1, 0)) + P.DoAdunitBoundaryOutput = 0; + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, + "Correct administrative unit populations", "%i", + (void *)&(P.DoCorrectAdunitPop), 1, 1, 0)) + P.DoCorrectAdunitPop = 0; + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, + "Fix population size at specified value", "%i", + (void *)&(P.DoSpecifyPop), 1, 1, 0)) + P.DoSpecifyPop = 0; fprintf(stderr, "Using %i administrative units\n", P.NumAdunits); - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Divisor for administrative unit codes for boundary plotting on bitmaps", "%i", (void*) & (P.AdunitBitmapDivisor), 1, 1, 0)) P.AdunitBitmapDivisor = 1; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Only output household to place distance distribution for one administrative unit", "%i", (void*) & (P.DoOutputPlaceDistForOneAdunit), 1, 1, 0)) P.DoOutputPlaceDistForOneAdunit = 0; + if (!GetInputParameter2( + PreParamFile_dat, AdminFile_dat, + "Divisor for administrative unit codes for boundary plotting on bitmaps", "%i", + (void *)&(P.AdunitBitmapDivisor), 1, 1, 0)) + P.AdunitBitmapDivisor = 1; + if (!GetInputParameter2( + ParamFile_dat, PreParamFile_dat, + "Only output household to place distance distribution for one administrative unit", + "%i", (void *)&(P.DoOutputPlaceDistForOneAdunit), 1, 1, 0)) + P.DoOutputPlaceDistForOneAdunit = 0; if (P.DoOutputPlaceDistForOneAdunit) { - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Administrative unit for which household to place distance distribution to be output", "%i", (void*) & (P.OutputPlaceDistAdunit), 1, 1, 0)) P.DoOutputPlaceDistForOneAdunit = 0; + if (!GetInputParameter2( + ParamFile_dat, PreParamFile_dat, + "Administrative unit for which household to place distance distribution to be output", + "%i", (void *)&(P.OutputPlaceDistAdunit), 1, 1, 0)) + P.DoOutputPlaceDistForOneAdunit = 0; } } else { - P.DoAdunitBoundaries = P.DoAdunitBoundaryOutput = P.DoAdunitOutput = P.DoCorrectAdunitPop = P.DoSpecifyPop = 0; - P.AdunitLevel1Divisor = 1; P.AdunitLevel1Mask = 1000000000; + P.DoAdunitBoundaries = P.DoAdunitBoundaryOutput = P.DoAdunitOutput = P.DoCorrectAdunitPop = + P.DoSpecifyPop = 0; + P.AdunitLevel1Divisor = 1; + P.AdunitLevel1Mask = 1000000000; P.AdunitBitmapDivisor = P.AdunitLevel1Divisor; } - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Include age", "%i", (void*) & (P.DoAge), 1, 1, 0)) P.DoAge = 1; + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Include age", "%i", (void *)&(P.DoAge), + 1, 1, 0)) + P.DoAge = 1; if (!P.DoAge) { for (i = 0; i < NUM_AGE_GROUPS; i++) @@ -683,26 +897,38 @@ void ReadParams(char* ParamFile, char* PreParamFile) else { - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Initial immunity acts as partial immunity", "%i", (void*)&(P.DoPartialImmunity), 1, 1, 0)) P.DoPartialImmunity = 1; - if ((P.DoHouseholds)&&(!P.DoPartialImmunity)) + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Initial immunity acts as partial immunity", "%i", + (void *)&(P.DoPartialImmunity), 1, 1, 0)) + P.DoPartialImmunity = 1; + if ((P.DoHouseholds) && (!P.DoPartialImmunity)) { - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Initial immunity applied to all household members", "%i", (void*) & (P.DoWholeHouseholdImmunity), 1, 1, 0)) P.DoWholeHouseholdImmunity = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Initial immunity applied to all household members", "%i", + (void *)&(P.DoWholeHouseholdImmunity), 1, 1, 0)) + P.DoWholeHouseholdImmunity = 0; } else P.DoWholeHouseholdImmunity = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Initial immunity profile by age", "%lf", (void*)P.InitialImmunity, NUM_AGE_GROUPS, 1, 0)) + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Initial immunity profile by age", + "%lf", (void *)P.InitialImmunity, NUM_AGE_GROUPS, 1, 0)) for (i = 0; i < NUM_AGE_GROUPS; i++) P.InitialImmunity[i] = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Relative spatial contact rates by age", "%lf", (void*)P.RelativeSpatialContact, NUM_AGE_GROUPS, 1, 0)) + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Relative spatial contact rates by age", "%lf", + (void *)P.RelativeSpatialContact, NUM_AGE_GROUPS, 1, 0)) for (i = 0; i < NUM_AGE_GROUPS; i++) P.RelativeSpatialContact[i] = 1; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Age-dependent infectiousness", "%lf", (void*)P.AgeInfectiousness, NUM_AGE_GROUPS, 1, 0)) + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Age-dependent infectiousness", "%lf", + (void *)P.AgeInfectiousness, NUM_AGE_GROUPS, 1, 0)) for (i = 0; i < NUM_AGE_GROUPS; i++) P.AgeInfectiousness[i] = 1.0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Age-dependent susceptibility", "%lf", (void*)P.AgeSusceptibility, NUM_AGE_GROUPS, 1, 0)) + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Age-dependent susceptibility", "%lf", + (void *)P.AgeSusceptibility, NUM_AGE_GROUPS, 1, 0)) for (i = 0; i < NUM_AGE_GROUPS; i++) P.AgeSusceptibility[i] = 1.0; - GetInputParameter(PreParamFile_dat, AdminFile_dat, "Age distribution of population", "%lf", (void*)P.PropAgeGroup[0], NUM_AGE_GROUPS, 1, 0); + GetInputParameter(PreParamFile_dat, AdminFile_dat, "Age distribution of population", "%lf", + (void *)P.PropAgeGroup[0], NUM_AGE_GROUPS, 1, 0); t = 0; for (i = 0; i < NUM_AGE_GROUPS; i++) t += P.PropAgeGroup[0][i]; @@ -710,15 +936,19 @@ void ReadParams(char* ParamFile, char* PreParamFile) P.PropAgeGroup[0][i] /= t; t = 0; for (i = 0; i < NUM_AGE_GROUPS; i++) - if (P.AgeSusceptibility[i] > t) t = P.AgeSusceptibility[i]; //peak susc has to be 1 + if (P.AgeSusceptibility[i] > t) + t = P.AgeSusceptibility[i]; // peak susc has to be 1 for (i = 0; i < NUM_AGE_GROUPS; i++) P.AgeSusceptibility[i] /= t; AgeSuscScale = t; - if (P.DoHouseholds) P.HouseholdTrans *= AgeSuscScale; - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Relative travel rates by age", "%lf", (void*)P.RelativeTravelRate, NUM_AGE_GROUPS, 1, 0)) + if (P.DoHouseholds) + P.HouseholdTrans *= AgeSuscScale; + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Relative travel rates by age", "%lf", + (void *)P.RelativeTravelRate, NUM_AGE_GROUPS, 1, 0)) for (i = 0; i < NUM_AGE_GROUPS; i++) P.RelativeTravelRate[i] = 1; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "WAIFW matrix", "%lf", (void*)P.WAIFW_Matrix, NUM_AGE_GROUPS, NUM_AGE_GROUPS, 0)) + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "WAIFW matrix", "%lf", + (void *)P.WAIFW_Matrix, NUM_AGE_GROUPS, NUM_AGE_GROUPS, 0)) { for (i = 0; i < NUM_AGE_GROUPS; i++) for (j = 0; j < NUM_AGE_GROUPS; j++) @@ -733,7 +963,8 @@ void ReadParams(char* ParamFile, char* PreParamFile) t = 0; for (i = 0; i < NUM_AGE_GROUPS; i++) for (j = 0; j < NUM_AGE_GROUPS; j++) - if (P.WAIFW_Matrix[i][j] > t) t = P.WAIFW_Matrix[i][j]; + if (P.WAIFW_Matrix[i][j] > t) + t = P.WAIFW_Matrix[i][j]; if (t > 0) { for (i = 0; i < NUM_AGE_GROUPS; i++) @@ -749,44 +980,77 @@ void ReadParams(char* ParamFile, char* PreParamFile) } P.DoDeath = 0; t = 0; - for (i = 0; i < NUM_AGE_GROUPS; i++) t += P.AgeInfectiousness[i] * P.PropAgeGroup[0][i]; - for (i = 0; i < NUM_AGE_GROUPS; i++) P.AgeInfectiousness[i] /= t; - } - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Include spatial transmission", "%i", (void*) & (P.DoSpatial), 1, 1, 0)) P.DoSpatial = 1; - GetInputParameter(PreParamFile_dat, AdminFile_dat, "Kernel type", "%i", (void*) & (P.MoveKernelType), 1, 1, 0); - GetInputParameter(PreParamFile_dat, AdminFile_dat, "Kernel scale", "%lf", (void*) & (P.MoveKernelScale), 1, 1, 0); + for (i = 0; i < NUM_AGE_GROUPS; i++) + t += P.AgeInfectiousness[i] * P.PropAgeGroup[0][i]; + for (i = 0; i < NUM_AGE_GROUPS; i++) + P.AgeInfectiousness[i] /= t; + } + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Include spatial transmission", "%i", + (void *)&(P.DoSpatial), 1, 1, 0)) + P.DoSpatial = 1; + GetInputParameter(PreParamFile_dat, AdminFile_dat, "Kernel type", "%i", + (void *)&(P.MoveKernelType), 1, 1, 0); + GetInputParameter(PreParamFile_dat, AdminFile_dat, "Kernel scale", "%lf", + (void *)&(P.MoveKernelScale), 1, 1, 0); if (P.KernelOffsetScale != 1) { P.MoveKernelScale *= P.KernelOffsetScale; } - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Kernel 3rd param", "%lf", (void*) & (P.MoveKernelP3), 1, 1, 0)) P.MoveKernelP3 = 0; - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Kernel 4th param", "%lf", (void*) & (P.MoveKernelP4), 1, 1, 0)) P.MoveKernelP4 = 0; - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Kernel Shape", "%lf", (void*) & (P.MoveKernelShape), 1, 1, 0)) P.MoveKernelShape = 1.0; + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Kernel 3rd param", "%lf", + (void *)&(P.MoveKernelP3), 1, 1, 0)) + P.MoveKernelP3 = 0; + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Kernel 4th param", "%lf", + (void *)&(P.MoveKernelP4), 1, 1, 0)) + P.MoveKernelP4 = 0; + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Kernel Shape", "%lf", + (void *)&(P.MoveKernelShape), 1, 1, 0)) + P.MoveKernelShape = 1.0; if (P.KernelPowerScale != 1) { P.MoveKernelShape *= P.KernelPowerScale; } - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Airport Kernel Type", "%i", (void*) & (P.AirportKernelType), 1, 1, 0)) P.AirportKernelType = P.MoveKernelType; - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Airport Kernel Scale", "%lf", (void*) & (P.AirportKernelScale), 1, 1, 0)) P.AirportKernelScale = P.MoveKernelScale; - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Airport Kernel Shape", "%lf", (void*) & (P.AirportKernelShape), 1, 1, 0)) P.AirportKernelShape = P.MoveKernelShape; - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Airport Kernel 3rd param", "%lf", (void*) & (P.AirportKernelP3), 1, 1, 0)) P.AirportKernelP3 = P.MoveKernelP3; - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Airport Kernel 4th param", "%lf", (void*) & (P.AirportKernelP4), 1, 1, 0)) P.AirportKernelP4 = P.MoveKernelP4; - - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Include places", "%i", (void*)&(P.DoPlaces), 1, 1, 0)) P.DoPlaces = 1; + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Airport Kernel Type", "%i", + (void *)&(P.AirportKernelType), 1, 1, 0)) + P.AirportKernelType = P.MoveKernelType; + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Airport Kernel Scale", "%lf", + (void *)&(P.AirportKernelScale), 1, 1, 0)) + P.AirportKernelScale = P.MoveKernelScale; + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Airport Kernel Shape", "%lf", + (void *)&(P.AirportKernelShape), 1, 1, 0)) + P.AirportKernelShape = P.MoveKernelShape; + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Airport Kernel 3rd param", "%lf", + (void *)&(P.AirportKernelP3), 1, 1, 0)) + P.AirportKernelP3 = P.MoveKernelP3; + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Airport Kernel 4th param", "%lf", + (void *)&(P.AirportKernelP4), 1, 1, 0)) + P.AirportKernelP4 = P.MoveKernelP4; + + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Include places", "%i", + (void *)&(P.DoPlaces), 1, 1, 0)) + P.DoPlaces = 1; if (P.DoPlaces) { - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Number of types of places", "%i", (void*)&(P.PlaceTypeNum), 1, 1, 0)) P.PlaceTypeNum = 0; - if (P.PlaceTypeNum == 0) P.DoPlaces = P.DoAirports = 0; + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Number of types of places", "%i", + (void *)&(P.PlaceTypeNum), 1, 1, 0)) + P.PlaceTypeNum = 0; + if (P.PlaceTypeNum == 0) + P.DoPlaces = P.DoAirports = 0; } else P.PlaceTypeNum = P.DoAirports = 0; if (P.DoPlaces) { - if (P.PlaceTypeNum > NUM_PLACE_TYPES) ERR_CRITICAL("Too many place types\n"); - GetInputParameter(PreParamFile_dat, AdminFile_dat, "Minimum age for age group 1 in place types", "%i", (void*)P.PlaceTypeAgeMin, P.PlaceTypeNum, 1, 0); - GetInputParameter(PreParamFile_dat, AdminFile_dat, "Maximum age for age group 1 in place types", "%i", (void*)P.PlaceTypeAgeMax, P.PlaceTypeNum, 1, 0); - GetInputParameter(PreParamFile_dat, AdminFile_dat, "Proportion of age group 1 in place types", "%lf", (void*) & (P.PlaceTypePropAgeGroup), P.PlaceTypeNum, 1, 0); - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Proportion of age group 2 in place types", "%lf", (void*) & (P.PlaceTypePropAgeGroup2), P.PlaceTypeNum, 1, 0)) + if (P.PlaceTypeNum > NUM_PLACE_TYPES) + ERR_CRITICAL("Too many place types\n"); + GetInputParameter(PreParamFile_dat, AdminFile_dat, "Minimum age for age group 1 in place types", + "%i", (void *)P.PlaceTypeAgeMin, P.PlaceTypeNum, 1, 0); + GetInputParameter(PreParamFile_dat, AdminFile_dat, "Maximum age for age group 1 in place types", + "%i", (void *)P.PlaceTypeAgeMax, P.PlaceTypeNum, 1, 0); + GetInputParameter(PreParamFile_dat, AdminFile_dat, "Proportion of age group 1 in place types", + "%lf", (void *)&(P.PlaceTypePropAgeGroup), P.PlaceTypeNum, 1, 0); + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, + "Proportion of age group 2 in place types", "%lf", + (void *)&(P.PlaceTypePropAgeGroup2), P.PlaceTypeNum, 1, 0)) { for (i = 0; i < NUM_PLACE_TYPES; i++) { @@ -797,10 +1061,16 @@ void ReadParams(char* ParamFile, char* PreParamFile) } else { - GetInputParameter(PreParamFile_dat, AdminFile_dat, "Minimum age for age group 2 in place types", "%i", (void*)P.PlaceTypeAgeMin2, P.PlaceTypeNum, 1, 0); - GetInputParameter(PreParamFile_dat, AdminFile_dat, "Maximum age for age group 2 in place types", "%i", (void*)P.PlaceTypeAgeMax2, P.PlaceTypeNum, 1, 0); + GetInputParameter(PreParamFile_dat, AdminFile_dat, + "Minimum age for age group 2 in place types", "%i", + (void *)P.PlaceTypeAgeMin2, P.PlaceTypeNum, 1, 0); + GetInputParameter(PreParamFile_dat, AdminFile_dat, + "Maximum age for age group 2 in place types", "%i", + (void *)P.PlaceTypeAgeMax2, P.PlaceTypeNum, 1, 0); } - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Proportion of age group 3 in place types", "%lf", (void*) & (P.PlaceTypePropAgeGroup3), P.PlaceTypeNum, 1, 0)) + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, + "Proportion of age group 3 in place types", "%lf", + (void *)&(P.PlaceTypePropAgeGroup3), P.PlaceTypeNum, 1, 0)) { for (i = 0; i < NUM_PLACE_TYPES; i++) { @@ -811,10 +1081,15 @@ void ReadParams(char* ParamFile, char* PreParamFile) } else { - GetInputParameter(PreParamFile_dat, AdminFile_dat, "Minimum age for age group 3 in place types", "%i", (void*)P.PlaceTypeAgeMin3, P.PlaceTypeNum, 1, 0); - GetInputParameter(PreParamFile_dat, AdminFile_dat, "Maximum age for age group 3 in place types", "%i", (void*)P.PlaceTypeAgeMax3, P.PlaceTypeNum, 1, 0); + GetInputParameter(PreParamFile_dat, AdminFile_dat, + "Minimum age for age group 3 in place types", "%i", + (void *)P.PlaceTypeAgeMin3, P.PlaceTypeNum, 1, 0); + GetInputParameter(PreParamFile_dat, AdminFile_dat, + "Maximum age for age group 3 in place types", "%i", + (void *)P.PlaceTypeAgeMax3, P.PlaceTypeNum, 1, 0); } - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Kernel shape params for place types", "%lf", (void*) & (P.PlaceTypeKernelShape), P.PlaceTypeNum, 1, 0)) + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Kernel shape params for place types", + "%lf", (void *)&(P.PlaceTypeKernelShape), P.PlaceTypeNum, 1, 0)) { for (i = 0; i < NUM_PLACE_TYPES; i++) { @@ -823,8 +1098,10 @@ void ReadParams(char* ParamFile, char* PreParamFile) } } else - GetInputParameter(PreParamFile_dat, AdminFile_dat, "Kernel scale params for place types", "%lf", (void*) & (P.PlaceTypeKernelScale), P.PlaceTypeNum, 1, 0); - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Kernel 3rd param for place types", "%lf", (void*) & (P.PlaceTypeKernelP3), P.PlaceTypeNum, 1, 0)) + GetInputParameter(PreParamFile_dat, AdminFile_dat, "Kernel scale params for place types", + "%lf", (void *)&(P.PlaceTypeKernelScale), P.PlaceTypeNum, 1, 0); + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Kernel 3rd param for place types", + "%lf", (void *)&(P.PlaceTypeKernelP3), P.PlaceTypeNum, 1, 0)) { for (i = 0; i < NUM_PLACE_TYPES; i++) { @@ -833,18 +1110,27 @@ void ReadParams(char* ParamFile, char* PreParamFile) } } else - GetInputParameter(PreParamFile_dat, AdminFile_dat, "Kernel 4th param for place types", "%lf", (void*) & (P.PlaceTypeKernelP4), P.PlaceTypeNum, 1, 0); - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Number of closest places people pick from (0=all) for place types", "%i", (void*) & (P.PlaceTypeNearestNeighb), P.PlaceTypeNum, 1, 0)) + GetInputParameter(PreParamFile_dat, AdminFile_dat, "Kernel 4th param for place types", "%lf", + (void *)&(P.PlaceTypeKernelP4), P.PlaceTypeNum, 1, 0); + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, + "Number of closest places people pick from (0=all) for place types", + "%i", (void *)&(P.PlaceTypeNearestNeighb), P.PlaceTypeNum, 1, 0)) for (i = 0; i < NUM_PLACE_TYPES; i++) P.PlaceTypeNearestNeighb[i] = 0; if (P.DoAdUnits) { - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Degree to which crossing administrative unit boundaries to go to places is inhibited", "%lf", (void*) & (P.InhibitInterAdunitPlaceAssignment), P.PlaceTypeNum, 1, 0)) + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Degree to which crossing administrative unit boundaries to go to " + "places is inhibited", + "%lf", (void *)&(P.InhibitInterAdunitPlaceAssignment), P.PlaceTypeNum, + 1, 0)) for (i = 0; i < NUM_PLACE_TYPES; i++) P.InhibitInterAdunitPlaceAssignment[i] = 0; } - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Include air travel", "%i", (void*)&(P.DoAirports), 1, 1, 0)) P.DoAirports = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Include air travel", "%i", + (void *)&(P.DoAirports), 1, 1, 0)) + P.DoAirports = 0; if (!P.DoAirports) { // Airports disabled => all places are not to do with airports, and we @@ -856,24 +1142,41 @@ void ReadParams(char* ParamFile, char* PreParamFile) { // When airports are activated we must have at least one airport place // // and a hotel type. - GetInputParameter(PreParamFile_dat, AdminFile_dat, "Number of non-airport places", "%i", (void*)&(P.PlaceTypeNoAirNum), 1, 1, 0); - GetInputParameter(PreParamFile_dat, AdminFile_dat, "Hotel place type", "%i", (void*)&(P.HotelPlaceType), 1, 1, 0); - if (P.PlaceTypeNoAirNum >= P.PlaceTypeNum) { - ERR_CRITICAL_FMT("[Number of non-airport places] parameter (%d) is greater than number of places (%d).\n", P.PlaceTypeNoAirNum, P.PlaceTypeNum); + GetInputParameter(PreParamFile_dat, AdminFile_dat, "Number of non-airport places", "%i", + (void *)&(P.PlaceTypeNoAirNum), 1, 1, 0); + GetInputParameter(PreParamFile_dat, AdminFile_dat, "Hotel place type", "%i", + (void *)&(P.HotelPlaceType), 1, 1, 0); + if (P.PlaceTypeNoAirNum >= P.PlaceTypeNum) + { + ERR_CRITICAL_FMT("[Number of non-airport places] parameter (%d) is greater than number of " + "places (%d).\n", + P.PlaceTypeNoAirNum, P.PlaceTypeNum); } - if (P.HotelPlaceType < P.PlaceTypeNoAirNum || P.HotelPlaceType >= P.PlaceTypeNum) { - ERR_CRITICAL_FMT("[Hotel place type] parameter (%d) not in the range [%d, %d)\n", P.HotelPlaceType, P.PlaceTypeNoAirNum, P.PlaceTypeNum); + if (P.HotelPlaceType < P.PlaceTypeNoAirNum || P.HotelPlaceType >= P.PlaceTypeNum) + { + ERR_CRITICAL_FMT("[Hotel place type] parameter (%d) not in the range [%d, %d)\n", + P.HotelPlaceType, P.PlaceTypeNoAirNum, P.PlaceTypeNum); } - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Scaling factor for input file to convert to daily traffic", "%lf", (void*) & (P.AirportTrafficScale), 1, 1, 0)) P.AirportTrafficScale = 1.0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Proportion of hotel attendees who are local", "%lf", (void*) & (P.HotelPropLocal), 1, 1, 0)) P.HotelPropLocal = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Distribution of duration of air journeys", "%lf", (void*) & (P.JourneyDurationDistrib), MAX_TRAVEL_TIME, 1, 0)) + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Scaling factor for input file to convert to daily traffic", "%lf", + (void *)&(P.AirportTrafficScale), 1, 1, 0)) + P.AirportTrafficScale = 1.0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Proportion of hotel attendees who are local", "%lf", + (void *)&(P.HotelPropLocal), 1, 1, 0)) + P.HotelPropLocal = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Distribution of duration of air journeys", "%lf", + (void *)&(P.JourneyDurationDistrib), MAX_TRAVEL_TIME, 1, 0)) { P.JourneyDurationDistrib[0] = 1; for (i = 0; i < MAX_TRAVEL_TIME; i++) P.JourneyDurationDistrib[i] = 0; } - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Distribution of duration of local journeys", "%lf", (void*) & (P.LocalJourneyDurationDistrib), MAX_TRAVEL_TIME, 1, 0)) + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Distribution of duration of local journeys", "%lf", + (void *)&(P.LocalJourneyDurationDistrib), MAX_TRAVEL_TIME, 1, 0)) { P.LocalJourneyDurationDistrib[0] = 1; for (i = 0; i < MAX_TRAVEL_TIME; i++) @@ -894,42 +1197,60 @@ void ReadParams(char* ParamFile, char* PreParamFile) for (i = j = 0; i <= 1024; i++) { s = ((double)i) / 1024; - while (P.JourneyDurationDistrib[j] < s)j++; + while (P.JourneyDurationDistrib[j] < s) + j++; P.InvJourneyDurationDistrib[i] = j; } for (i = j = 0; i <= 1024; i++) { s = ((double)i) / 1024; - while (P.LocalJourneyDurationDistrib[j] < s)j++; + while (P.LocalJourneyDurationDistrib[j] < s) + j++; P.InvLocalJourneyDurationDistrib[i] = j; } } - GetInputParameter(PreParamFile_dat, AdminFile_dat, "Mean size of place types", "%lf", (void*)P.PlaceTypeMeanSize, P.PlaceTypeNum, 1, 0); - GetInputParameter(PreParamFile_dat, AdminFile_dat, "Param 1 of place group size distribution", "%lf", (void*)P.PlaceTypeGroupSizeParam1, P.PlaceTypeNum, 1, 0); - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Power of place size distribution", "%lf", (void*)P.PlaceTypeSizePower, P.PlaceTypeNum, 1, 0)) + GetInputParameter(PreParamFile_dat, AdminFile_dat, "Mean size of place types", "%lf", + (void *)P.PlaceTypeMeanSize, P.PlaceTypeNum, 1, 0); + GetInputParameter(PreParamFile_dat, AdminFile_dat, "Param 1 of place group size distribution", + "%lf", (void *)P.PlaceTypeGroupSizeParam1, P.PlaceTypeNum, 1, 0); + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Power of place size distribution", + "%lf", (void *)P.PlaceTypeSizePower, P.PlaceTypeNum, 1, 0)) for (i = 0; i < NUM_PLACE_TYPES; i++) P.PlaceTypeSizePower[i] = 0; - //added to enable lognormal distribution - ggilani 09/02/17 - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Standard deviation of place size distribution", "%lf", (void*)P.PlaceTypeSizeSD, P.PlaceTypeNum, 1, 0)) + // added to enable lognormal distribution - ggilani 09/02/17 + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, + "Standard deviation of place size distribution", "%lf", + (void *)P.PlaceTypeSizeSD, P.PlaceTypeNum, 1, 0)) for (i = 0; i < NUM_PLACE_TYPES; i++) P.PlaceTypeSizeSD[i] = 0; - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Offset of place size distribution", "%lf", (void*)P.PlaceTypeSizeOffset, P.PlaceTypeNum, 1, 0)) + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Offset of place size distribution", + "%lf", (void *)P.PlaceTypeSizeOffset, P.PlaceTypeNum, 1, 0)) for (i = 0; i < NUM_PLACE_TYPES; i++) P.PlaceTypeSizeOffset[i] = 0; - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Maximum of place size distribution", "%lf", (void*)P.PlaceTypeSizeMax, P.PlaceTypeNum, 1, 0)) + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Maximum of place size distribution", + "%lf", (void *)P.PlaceTypeSizeMax, P.PlaceTypeNum, 1, 0)) for (i = 0; i < NUM_PLACE_TYPES; i++) P.PlaceTypeSizeMax[i] = 1e20; - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Kernel type for place types", "%i", (void*)P.PlaceTypeKernelType, P.PlaceTypeNum, 1, 0)) + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Kernel type for place types", "%i", + (void *)P.PlaceTypeKernelType, P.PlaceTypeNum, 1, 0)) for (i = 0; i < NUM_PLACE_TYPES; i++) P.PlaceTypeKernelType[i] = P.MoveKernelType; - GetInputParameter(PreParamFile_dat, AdminFile_dat, "Place overlap matrix", "%lf", (void*)P.PlaceExclusivityMatrix, P.PlaceTypeNum * P.PlaceTypeNum, 1, 0); //changed from P.PlaceTypeNum,P.PlaceTypeNum,0); -/* Note P.PlaceExclusivityMatrix not used at present - places assumed exclusive (each person belongs to 0 or 1 place) */ - - GetInputParameter(ParamFile_dat, PreParamFile_dat, "Proportion of between group place links", "%lf", (void*)P.PlaceTypePropBetweenGroupLinks, P.PlaceTypeNum, 1, 0); - GetInputParameter(ParamFile_dat, PreParamFile_dat, "Relative transmission rates for place types", "%lf", (void*)P.PlaceTypeTrans, P.PlaceTypeNum, 1, 0); - for (i = 0; i < P.PlaceTypeNum; i++) P.PlaceTypeTrans[i] *= AgeSuscScale; - } - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Daily seasonality coefficients", "%lf", (void*)P.Seasonality, DAYS_PER_YEAR, 1, 0)) + GetInputParameter(PreParamFile_dat, AdminFile_dat, "Place overlap matrix", "%lf", + (void *)P.PlaceExclusivityMatrix, P.PlaceTypeNum * P.PlaceTypeNum, 1, + 0); // changed from P.PlaceTypeNum,P.PlaceTypeNum,0); + /* Note P.PlaceExclusivityMatrix not used at present - places assumed exclusive (each person + * belongs to 0 or 1 place) */ + + GetInputParameter(ParamFile_dat, PreParamFile_dat, "Proportion of between group place links", + "%lf", (void *)P.PlaceTypePropBetweenGroupLinks, P.PlaceTypeNum, 1, 0); + GetInputParameter(ParamFile_dat, PreParamFile_dat, + "Relative transmission rates for place types", "%lf", + (void *)P.PlaceTypeTrans, P.PlaceTypeNum, 1, 0); + for (i = 0; i < P.PlaceTypeNum; i++) + P.PlaceTypeTrans[i] *= AgeSuscScale; + } + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Daily seasonality coefficients", "%lf", + (void *)P.Seasonality, DAYS_PER_YEAR, 1, 0)) { P.DoSeasonality = 0; for (i = 0; i < DAYS_PER_YEAR; i++) @@ -946,75 +1267,142 @@ void ReadParams(char* ParamFile, char* PreParamFile) for (i = 0; i < DAYS_PER_YEAR; i++) P.Seasonality[i] /= s; } - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Number of seed locations", "%i", (void*) & (P.NumSeedLocations), 1, 1, 0)) P.NumSeedLocations = 1; + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Number of seed locations", "%i", + (void *)&(P.NumSeedLocations), 1, 1, 0)) + P.NumSeedLocations = 1; if (P.NumSeedLocations > MAX_NUM_SEED_LOCATIONS) { fprintf(stderr, "Too many seed locations\n"); P.NumSeedLocations = MAX_NUM_SEED_LOCATIONS; } - GetInputParameter(PreParamFile_dat, AdminFile_dat, "Initial number of infecteds", "%i", (void*)P.NumInitialInfections, P.NumSeedLocations, 1, 0); - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Location of initial infecteds", "%lf", (void*)&(P.LocationInitialInfection[0][0]), P.NumSeedLocations * 2, 1, 0)) P.LocationInitialInfection[0][0] = P.LocationInitialInfection[0][1] = 0.0; - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Minimum population in microcell of initial infection", "%i", (void*) & (P.MinPopDensForInitialInfection), 1, 1, 0)) P.MinPopDensForInitialInfection = 0; - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Maximum population in microcell of initial infection", "%i", (void*)&(P.MaxPopDensForInitialInfection), 1, 1, 0)) P.MaxPopDensForInitialInfection = 10000000; - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Randomise initial infection location", "%i", (void*) & (P.DoRandomInitialInfectionLoc), 1, 1, 0)) P.DoRandomInitialInfectionLoc=1; - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "All initial infections located in same microcell", "%i", (void*) & (P.DoAllInitialInfectioninSameLoc), 1, 1, 0)) P.DoAllInitialInfectioninSameLoc=0; + GetInputParameter(PreParamFile_dat, AdminFile_dat, "Initial number of infecteds", "%i", + (void *)P.NumInitialInfections, P.NumSeedLocations, 1, 0); + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Location of initial infecteds", "%lf", + (void *)&(P.LocationInitialInfection[0][0]), P.NumSeedLocations * 2, 1, + 0)) + P.LocationInitialInfection[0][0] = P.LocationInitialInfection[0][1] = 0.0; + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, + "Minimum population in microcell of initial infection", "%i", + (void *)&(P.MinPopDensForInitialInfection), 1, 1, 0)) + P.MinPopDensForInitialInfection = 0; + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, + "Maximum population in microcell of initial infection", "%i", + (void *)&(P.MaxPopDensForInitialInfection), 1, 1, 0)) + P.MaxPopDensForInitialInfection = 10000000; + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Randomise initial infection location", + "%i", (void *)&(P.DoRandomInitialInfectionLoc), 1, 1, 0)) + P.DoRandomInitialInfectionLoc = 1; + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, + "All initial infections located in same microcell", "%i", + (void *)&(P.DoAllInitialInfectioninSameLoc), 1, 1, 0)) + P.DoAllInitialInfectioninSameLoc = 0; if (P.DoAdUnits) { - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Administrative unit to seed initial infection into", "%s", (P.NumSeedLocations > 1) ? ((void*)AdunitListNames) : ((void*)AdunitListNames[0]), P.NumSeedLocations, 1, 0)) - for (i = 0; i < P.NumSeedLocations; i++) P.InitialInfectionsAdminUnit[i] = 0; + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, + "Administrative unit to seed initial infection into", "%s", + (P.NumSeedLocations > 1) ? ((void *)AdunitListNames) + : ((void *)AdunitListNames[0]), + P.NumSeedLocations, 1, 0)) + for (i = 0; i < P.NumSeedLocations; i++) + P.InitialInfectionsAdminUnit[i] = 0; else for (i = 0; i < P.NumSeedLocations; i++) { f = 0; if (P.NumAdunits > 0) { - for (j = 0; (j < P.NumAdunits) && (!f); j++) f = (!strcmp(AdUnits[j].ad_name, AdunitListNames[i])); - if (f) k = AdUnits[j-1].id; + for (j = 0; (j < P.NumAdunits) && (!f); j++) + f = (!strcmp(AdUnits[j].ad_name, AdunitListNames[i])); + if (f) + k = AdUnits[j - 1].id; } - if (!f) k = atoi(AdunitListNames[i]); + if (!f) + k = atoi(AdunitListNames[i]); P.InitialInfectionsAdminUnit[i] = k; - P.InitialInfectionsAdminUnitId[i]=P.AdunitLevel1Lookup[(k % P.AdunitLevel1Mask) / P.AdunitLevel1Divisor]; + P.InitialInfectionsAdminUnitId[i] = + P.AdunitLevel1Lookup[(k % P.AdunitLevel1Mask) / P.AdunitLevel1Divisor]; } - if(!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Administrative unit seeding weights", "%lf", (void*) & (P.InitialInfectionsAdminUnitWeight[0]), P.NumSeedLocations, 1, 0)) - for(i = 0; i < P.NumSeedLocations; i++) P.InitialInfectionsAdminUnitWeight[i] = 1.0; - s=0; - for(i = 0; i < P.NumSeedLocations; i++) s+=P.InitialInfectionsAdminUnitWeight[i]; - for(i = 0; i < P.NumSeedLocations; i++) P.InitialInfectionsAdminUnitWeight[i]/=s; - // for (i = 0; i < P.NumSeedLocations; i++) fprintf(stderr, "## %i %s %i %i %lf\n",i, AdUnits[P.InitialInfectionsAdminUnitId[i]].ad_name, P.InitialInfectionsAdminUnitId[i], P.InitialInfectionsAdminUnit[i], P.InitialInfectionsAdminUnitWeight[i]); + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Administrative unit seeding weights", + "%lf", (void *)&(P.InitialInfectionsAdminUnitWeight[0]), + P.NumSeedLocations, 1, 0)) + for (i = 0; i < P.NumSeedLocations; i++) + P.InitialInfectionsAdminUnitWeight[i] = 1.0; + s = 0; + for (i = 0; i < P.NumSeedLocations; i++) + s += P.InitialInfectionsAdminUnitWeight[i]; + for (i = 0; i < P.NumSeedLocations; i++) + P.InitialInfectionsAdminUnitWeight[i] /= s; + // for (i = 0; i < P.NumSeedLocations; i++) fprintf(stderr, "## %i %s %i %i %lf\n",i, + // AdUnits[P.InitialInfectionsAdminUnitId[i]].ad_name, P.InitialInfectionsAdminUnitId[i], + // P.InitialInfectionsAdminUnit[i], P.InitialInfectionsAdminUnitWeight[i]); } else { - for (i = 0; i < P.NumSeedLocations; i++) P.InitialInfectionsAdminUnit[i] = 0; - } - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Initial rate of importation of infections", "%lf", (void*)&(P.InfectionImportRate1), 1, 1, 0)) P.InfectionImportRate1 = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Changed rate of importation of infections", "%lf", (void*)&(P.InfectionImportRate2), 1, 1, 0)) P.InfectionImportRate2 = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Time when infection rate changes", "%lf", (void*)&(P.InfectionImportChangeTime), 1, 1, 0)) P.InfectionImportChangeTime = 1e10; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Imports via air travel", "%i", (void*)&(P.DoImportsViaAirports), 1, 1, 0)) P.DoImportsViaAirports = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Length of importation time profile provided", "%i", (void*)&(P.DurImportTimeProfile), 1, 1, 0)) P.DurImportTimeProfile = 0; + for (i = 0; i < P.NumSeedLocations; i++) + P.InitialInfectionsAdminUnit[i] = 0; + } + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Initial rate of importation of infections", "%lf", + (void *)&(P.InfectionImportRate1), 1, 1, 0)) + P.InfectionImportRate1 = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Changed rate of importation of infections", "%lf", + (void *)&(P.InfectionImportRate2), 1, 1, 0)) + P.InfectionImportRate2 = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Time when infection rate changes", + "%lf", (void *)&(P.InfectionImportChangeTime), 1, 1, 0)) + P.InfectionImportChangeTime = 1e10; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Imports via air travel", "%i", + (void *)&(P.DoImportsViaAirports), 1, 1, 0)) + P.DoImportsViaAirports = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Length of importation time profile provided", "%i", + (void *)&(P.DurImportTimeProfile), 1, 1, 0)) + P.DurImportTimeProfile = 0; if (P.DurImportTimeProfile > 0) { - if (P.DurImportTimeProfile >= MAX_DUR_IMPORT_PROFILE) ERR_CRITICAL("MAX_DUR_IMPORT_PROFILE too small\n"); - GetInputParameter(ParamFile_dat, PreParamFile_dat, "Daily importation time profile", "%lf", (void*)P.ImportInfectionTimeProfile, P.DurImportTimeProfile, 1, 0); - } - GetInputParameter(ParamFile_dat, PreParamFile_dat, "Reproduction number", "%lf", (void*) & (P.R0), 1, 1, 0); - GetInputParameter(ParamFile_dat, PreParamFile_dat, "Infectious period", "%lf", (void*) & (P.InfectiousPeriod), 1, 1, 0); - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "SD of individual variation in susceptibility", "%lf", (void*)&(P.SusceptibilitySD), 1, 1, 0)) P.SusceptibilitySD = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "SD of individual variation in infectiousness", "%lf", (void*) & (P.InfectiousnessSD), 1, 1, 0)) P.InfectiousnessSD = 0; - if (GetInputParameter2(ParamFile_dat, PreParamFile_dat, "k of individual variation in infectiousness", "%lf", (void*)& s, 1, 1, 0)) P.InfectiousnessSD = 1.0 / sqrt(s); - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Model time varying infectiousness", "%i", (void*) & (P.DoInfectiousnessProfile), 1, 1, 0)) P.DoInfectiousnessProfile = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Power of scaling of spatial R0 with density", "%lf", (void*) & (P.R0DensityScalePower), 1, 1, 0)) P.R0DensityScalePower = 0; + if (P.DurImportTimeProfile >= MAX_DUR_IMPORT_PROFILE) + ERR_CRITICAL("MAX_DUR_IMPORT_PROFILE too small\n"); + GetInputParameter(ParamFile_dat, PreParamFile_dat, "Daily importation time profile", "%lf", + (void *)P.ImportInfectionTimeProfile, P.DurImportTimeProfile, 1, 0); + } + GetInputParameter(ParamFile_dat, PreParamFile_dat, "Reproduction number", "%lf", (void *)&(P.R0), + 1, 1, 0); + GetInputParameter(ParamFile_dat, PreParamFile_dat, "Infectious period", "%lf", + (void *)&(P.InfectiousPeriod), 1, 1, 0); + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "SD of individual variation in susceptibility", "%lf", + (void *)&(P.SusceptibilitySD), 1, 1, 0)) + P.SusceptibilitySD = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "SD of individual variation in infectiousness", "%lf", + (void *)&(P.InfectiousnessSD), 1, 1, 0)) + P.InfectiousnessSD = 0; + if (GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "k of individual variation in infectiousness", "%lf", (void *)&s, 1, 1, 0)) + P.InfectiousnessSD = 1.0 / sqrt(s); + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Model time varying infectiousness", + "%i", (void *)&(P.DoInfectiousnessProfile), 1, 1, 0)) + P.DoInfectiousnessProfile = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Power of scaling of spatial R0 with density", "%lf", + (void *)&(P.R0DensityScalePower), 1, 1, 0)) + P.R0DensityScalePower = 0; if (P.DoInfectiousnessProfile) { - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Infectiousness profile", "%lf", (void*)P.infectious_prof, INFPROF_RES, 1, 0)) + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Infectiousness profile", "%lf", + (void *)P.infectious_prof, INFPROF_RES, 1, 0)) { for (i = 0; i < INFPROF_RES; i++) P.infectious_prof[i] = 1; } k = (int)ceil(P.InfectiousPeriod / P.TimeStep); - if (k >= MAX_INFECTIOUS_STEPS) ERR_CRITICAL("MAX_INFECTIOUS_STEPS not big enough\n"); + if (k >= MAX_INFECTIOUS_STEPS) + ERR_CRITICAL("MAX_INFECTIOUS_STEPS not big enough\n"); s = 0; P.infectious_prof[INFPROF_RES] = 0; - for (i = 0; i < MAX_INFECTIOUS_STEPS; i++) P.infectiousness[i] = 0; + for (i = 0; i < MAX_INFECTIOUS_STEPS; i++) + P.infectiousness[i] = 0; for (i = 0; i < k; i++) { t = (((double)i) * P.TimeStep / P.InfectiousPeriod * INFPROF_RES); @@ -1026,26 +1414,36 @@ void ReadParams(char* ParamFile, char* PreParamFile) s += (P.infectiousness[i] = P.infectious_prof[INFPROF_RES]); } s /= ((double)k); - for (i = 0; i <= k; i++) P.infectiousness[i] /= s; - for (i = 0; i <= CDF_RES; i++) P.infectious_icdf[i] = exp(-1.0); + for (i = 0; i <= k; i++) + P.infectiousness[i] /= s; + for (i = 0; i <= CDF_RES; i++) + P.infectious_icdf[i] = exp(-1.0); } else { - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Infectious period inverse CDF", "%lf", (void*)P.infectious_icdf, CDF_RES + 1, 1, 0)) + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Infectious period inverse CDF", "%lf", + (void *)P.infectious_icdf, CDF_RES + 1, 1, 0)) { SetICDF(P.infectious_icdf, ICDF_START); } k = (int)ceil(P.InfectiousPeriod * P.infectious_icdf[CDF_RES] / P.TimeStep); - if (k >= MAX_INFECTIOUS_STEPS) ERR_CRITICAL("MAX_INFECTIOUS_STEPS not big enough\n"); - for (i = 0; i < k; i++) P.infectiousness[i] = 1.0; + if (k >= MAX_INFECTIOUS_STEPS) + ERR_CRITICAL("MAX_INFECTIOUS_STEPS not big enough\n"); + for (i = 0; i < k; i++) + P.infectiousness[i] = 1.0; P.infectiousness[k] = 0; - for (i = 0; i <= CDF_RES; i++) P.infectious_icdf[i] = exp(-P.infectious_icdf[i]); + for (i = 0; i <= CDF_RES; i++) + P.infectious_icdf[i] = exp(-P.infectious_icdf[i]); } - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Include latent period", "%i", (void*) & (P.DoLatent), 1, 1, 0)) P.DoLatent = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Include latent period", "%i", + (void *)&(P.DoLatent), 1, 1, 0)) + P.DoLatent = 0; if (P.DoLatent) { - GetInputParameter(ParamFile_dat, PreParamFile_dat, "Latent period", "%lf", (void*) & (P.LatentPeriod), 1, 1, 0); - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Latent period inverse CDF", "%lf", (void*)P.latent_icdf, CDF_RES + 1, 1, 0)) + GetInputParameter(ParamFile_dat, PreParamFile_dat, "Latent period", "%lf", + (void *)&(P.LatentPeriod), 1, 1, 0); + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Latent period inverse CDF", "%lf", + (void *)P.latent_icdf, CDF_RES + 1, 1, 0)) { SetICDF(P.latent_icdf, 1e10); } @@ -1053,7 +1451,9 @@ void ReadParams(char* ParamFile, char* PreParamFile) P.latent_icdf[i] = exp(-P.latent_icdf[i]); } - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Include symptoms", "%i", (void*) & (P.DoSymptoms), 1, 1, 0)) P.DoSymptoms = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Include symptoms", "%i", + (void *)&(P.DoSymptoms), 1, 1, 0)) + P.DoSymptoms = 0; if (!P.DoSymptoms) { for (i = 0; i < NUM_AGE_GROUPS; i++) @@ -1065,20 +1465,33 @@ void ReadParams(char* ParamFile, char* PreParamFile) else { if (P.DoAge) - GetInputParameter(ParamFile_dat, PreParamFile_dat, "Proportion symptomatic by age group", "%lf", (void*)P.ProportionSymptomatic, NUM_AGE_GROUPS, 1, 0); + GetInputParameter(ParamFile_dat, PreParamFile_dat, "Proportion symptomatic by age group", + "%lf", (void *)P.ProportionSymptomatic, NUM_AGE_GROUPS, 1, 0); else { - GetInputParameter(ParamFile_dat, PreParamFile_dat, "Proportion symptomatic", "%lf", (void*)P.ProportionSymptomatic, 1, 1, 0); + GetInputParameter(ParamFile_dat, PreParamFile_dat, "Proportion symptomatic", "%lf", + (void *)P.ProportionSymptomatic, 1, 1, 0); for (i = 1; i < NUM_AGE_GROUPS; i++) P.ProportionSymptomatic[i] = P.ProportionSymptomatic[0]; } - GetInputParameter(ParamFile_dat, PreParamFile_dat, "Delay from end of latent period to start of symptoms", "%lf", (void*) & (P.LatentToSymptDelay), 1, 1, 0); - GetInputParameter(ParamFile_dat, PreParamFile_dat, "Relative rate of random contacts if symptomatic", "%lf", (void*) & (P.SymptSpatialContactRate), 1, 1, 0); - GetInputParameter(ParamFile_dat, PreParamFile_dat, "Symptomatic infectiousness relative to asymptomatic", "%lf", (void*) & (P.SymptInfectiousness), 1, 1, 0); - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Model symptomatic withdrawal to home as true absenteeism", "%i", (void*)& P.DoRealSymptWithdrawal, 1, 1, 0)) P.DoRealSymptWithdrawal = 0; + GetInputParameter(ParamFile_dat, PreParamFile_dat, + "Delay from end of latent period to start of symptoms", "%lf", + (void *)&(P.LatentToSymptDelay), 1, 1, 0); + GetInputParameter(ParamFile_dat, PreParamFile_dat, + "Relative rate of random contacts if symptomatic", "%lf", + (void *)&(P.SymptSpatialContactRate), 1, 1, 0); + GetInputParameter(ParamFile_dat, PreParamFile_dat, + "Symptomatic infectiousness relative to asymptomatic", "%lf", + (void *)&(P.SymptInfectiousness), 1, 1, 0); + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Model symptomatic withdrawal to home as true absenteeism", "%i", + (void *)&P.DoRealSymptWithdrawal, 1, 1, 0)) + P.DoRealSymptWithdrawal = 0; if (P.DoPlaces) { - GetInputParameter(ParamFile_dat, PreParamFile_dat, "Relative level of place attendance if symptomatic", "%lf", (void*)P.SymptPlaceTypeContactRate, P.PlaceTypeNum, 1, 0); + GetInputParameter(ParamFile_dat, PreParamFile_dat, + "Relative level of place attendance if symptomatic", "%lf", + (void *)P.SymptPlaceTypeContactRate, P.PlaceTypeNum, 1, 0); if (P.DoRealSymptWithdrawal) { for (j = 0; j < NUM_PLACE_TYPES; j++) @@ -1088,186 +1501,348 @@ void ReadParams(char* ParamFile, char* PreParamFile) } } else - for (j = 0; j < NUM_PLACE_TYPES; j++) P.SymptPlaceTypeWithdrawalProp[j] = 0.0; - } - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Maximum age of child at home for whom one adult also stays at home", "%i", (void*)& P.CaseAbsentChildAgeCutoff, 1, 1, 0)) P.CaseAbsentChildAgeCutoff = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Proportion of children at home for whom one adult also stays at home", "%lf", (void*)& P.CaseAbsentChildPropAdultCarers, 1, 1, 0)) P.CaseAbsentChildPropAdultCarers = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Place close round household", "%i", (void*)&P.PlaceCloseRoundHousehold, 1, 1, 0)) P.PlaceCloseRoundHousehold = 1; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Absenteeism place closure", "%i", (void*)&P.AbsenteeismPlaceClosure, 1, 1, 0)) P.AbsenteeismPlaceClosure = 0; + for (j = 0; j < NUM_PLACE_TYPES; j++) + P.SymptPlaceTypeWithdrawalProp[j] = 0.0; + } + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Maximum age of child at home for whom one adult also stays at home", + "%i", (void *)&P.CaseAbsentChildAgeCutoff, 1, 1, 0)) + P.CaseAbsentChildAgeCutoff = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Proportion of children at home for whom one adult also stays at home", + "%lf", (void *)&P.CaseAbsentChildPropAdultCarers, 1, 1, 0)) + P.CaseAbsentChildPropAdultCarers = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Place close round household", "%i", + (void *)&P.PlaceCloseRoundHousehold, 1, 1, 0)) + P.PlaceCloseRoundHousehold = 1; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Absenteeism place closure", "%i", + (void *)&P.AbsenteeismPlaceClosure, 1, 1, 0)) + P.AbsenteeismPlaceClosure = 0; if (P.AbsenteeismPlaceClosure) { - P.CaseAbsenteeismDelay = 0; // Set to zero for tracking absenteeism - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Max absent time", "%i", (void*)&P.MaxAbsentTime, 1, 1, 0)) P.MaxAbsentTime = MAX_ABSENT_TIME; + P.CaseAbsenteeismDelay = 0; // Set to zero for tracking absenteeism + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Max absent time", "%i", + (void *)&P.MaxAbsentTime, 1, 1, 0)) + P.MaxAbsentTime = MAX_ABSENT_TIME; if (P.MaxAbsentTime > MAX_ABSENT_TIME || P.MaxAbsentTime < 0) { - ERR_CRITICAL_FMT("[Max absent time] out of range (%d), should be in range [0, %d]", P.MaxAbsentTime, MAX_ABSENT_TIME); + ERR_CRITICAL_FMT("[Max absent time] out of range (%d), should be in range [0, %d]", + P.MaxAbsentTime, MAX_ABSENT_TIME); } } else { - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Delay in starting place absenteeism for cases who withdraw", "%lf", (void*)& P.CaseAbsenteeismDelay, 1, 1, 0)) P.CaseAbsenteeismDelay = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Delay in starting place absenteeism for cases who withdraw", "%lf", + (void *)&P.CaseAbsenteeismDelay, 1, 1, 0)) + P.CaseAbsenteeismDelay = 0; P.MaxAbsentTime = 0; // Not used when !P.AbsenteeismPlaceClosure } - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Duration of place absenteeism for cases who withdraw", "%lf", (void*)& P.CaseAbsenteeismDuration, 1, 1, 0)) P.CaseAbsenteeismDuration = 7; - - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "False positive rate", "%lf", (void*) & (P.FalsePositiveRate), 1, 1, 0)) P.FalsePositiveRate = 0.0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "False positive per capita incidence", "%lf", (void*) & (P.FalsePositivePerCapitaIncidence), 1, 1, 0)) P.FalsePositivePerCapitaIncidence = 0.0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "False positive relative incidence by age", "%lf", (void*)P.FalsePositiveAgeRate, NUM_AGE_GROUPS, 1, 0)) - for (j = 0; j < NUM_AGE_GROUPS; j++) P.FalsePositiveAgeRate[j] = 1.0; - } - - if(!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Do Severity Analysis", "%i", (void*) & (P.DoSeverity), 1, 1, 0)) P.DoSeverity = 0; - if(P.DoSeverity == 1) + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Duration of place absenteeism for cases who withdraw", "%lf", + (void *)&P.CaseAbsenteeismDuration, 1, 1, 0)) + P.CaseAbsenteeismDuration = 7; + + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "False positive rate", "%lf", + (void *)&(P.FalsePositiveRate), 1, 1, 0)) + P.FalsePositiveRate = 0.0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "False positive per capita incidence", + "%lf", (void *)&(P.FalsePositivePerCapitaIncidence), 1, 1, 0)) + P.FalsePositivePerCapitaIncidence = 0.0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "False positive relative incidence by age", "%lf", + (void *)P.FalsePositiveAgeRate, NUM_AGE_GROUPS, 1, 0)) + for (j = 0; j < NUM_AGE_GROUPS; j++) + P.FalsePositiveAgeRate[j] = 1.0; + } + + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Do Severity Analysis", "%i", + (void *)&(P.DoSeverity), 1, 1, 0)) + P.DoSeverity = 0; + if (P.DoSeverity == 1) { //// Means for icdf's. - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "MeanTimeToTest", "%lf", (void*)&(P.Mean_TimeToTest), 1, 1, 0)) P.Mean_TimeToTest = 0.0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "MeanTimeToTestOffset", "%lf", (void*)&(P.Mean_TimeToTestOffset), 1, 1, 0)) P.Mean_TimeToTestOffset = 1.0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "MeanTimeToTestCriticalOffset", "%lf", (void*)&(P.Mean_TimeToTestCriticalOffset), 1, 1, 0)) P.Mean_TimeToTestCriticalOffset = 1.0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "MeanTimeToTestCritRecovOffset", "%lf", (void*)&(P.Mean_TimeToTestCritRecovOffset), 1, 1, 0)) P.Mean_TimeToTestCritRecovOffset = 1.0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Age dependent severity delays", "%i", (void*)&i, 1, 1, 0)) i = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "MeanTimeToTest", "%lf", + (void *)&(P.Mean_TimeToTest), 1, 1, 0)) + P.Mean_TimeToTest = 0.0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "MeanTimeToTestOffset", "%lf", + (void *)&(P.Mean_TimeToTestOffset), 1, 1, 0)) + P.Mean_TimeToTestOffset = 1.0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "MeanTimeToTestCriticalOffset", "%lf", + (void *)&(P.Mean_TimeToTestCriticalOffset), 1, 1, 0)) + P.Mean_TimeToTestCriticalOffset = 1.0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "MeanTimeToTestCritRecovOffset", "%lf", + (void *)&(P.Mean_TimeToTestCritRecovOffset), 1, 1, 0)) + P.Mean_TimeToTestCritRecovOffset = 1.0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Age dependent severity delays", "%i", + (void *)&i, 1, 1, 0)) + i = 0; if (!i) { - GetInputParameter(ParamFile_dat, PreParamFile_dat, "Mean_MildToRecovery", "%lf", (void*)&(P.Mean_MildToRecovery[0]), 1, 1, 0); - GetInputParameter(ParamFile_dat, PreParamFile_dat, "Mean_ILIToRecovery", "%lf", (void*)&(P.Mean_ILIToRecovery[0]), 1, 1, 0); - GetInputParameter(ParamFile_dat, PreParamFile_dat, "Mean_SARIToRecovery", "%lf", (void*)&(P.Mean_SARIToRecovery[0]), 1, 1, 0); - GetInputParameter(ParamFile_dat, PreParamFile_dat, "Mean_CriticalToCritRecov", "%lf", (void*)&(P.Mean_CriticalToCritRecov[0]), 1, 1, 0); - GetInputParameter(ParamFile_dat, PreParamFile_dat, "Mean_CritRecovToRecov", "%lf", (void*)&(P.Mean_CritRecovToRecov[0]), 1, 1, 0); - GetInputParameter(ParamFile_dat, PreParamFile_dat, "Mean_ILIToSARI", "%lf", (void*)&(P.Mean_ILIToSARI[0]), 1, 1, 0); - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Mean_ILIToDeath", "%lf", (void*)&(P.Mean_ILIToDeath[0]), 1, 1, 0)) P.Mean_ILIToDeath[0] = 7.0; - GetInputParameter(ParamFile_dat, PreParamFile_dat, "Mean_SARIToCritical", "%lf", (void*)&(P.Mean_SARIToCritical[0]), 1, 1, 0); - GetInputParameter(ParamFile_dat, PreParamFile_dat, "Mean_SARIToDeath", "%lf", (void*)&(P.Mean_SARIToDeath[0]), 1, 1, 0); - GetInputParameter(ParamFile_dat, PreParamFile_dat, "Mean_CriticalToDeath", "%lf", (void*)&(P.Mean_CriticalToDeath[0]), 1, 1, 0); + GetInputParameter(ParamFile_dat, PreParamFile_dat, "Mean_MildToRecovery", "%lf", + (void *)&(P.Mean_MildToRecovery[0]), 1, 1, 0); + GetInputParameter(ParamFile_dat, PreParamFile_dat, "Mean_ILIToRecovery", "%lf", + (void *)&(P.Mean_ILIToRecovery[0]), 1, 1, 0); + GetInputParameter(ParamFile_dat, PreParamFile_dat, "Mean_SARIToRecovery", "%lf", + (void *)&(P.Mean_SARIToRecovery[0]), 1, 1, 0); + GetInputParameter(ParamFile_dat, PreParamFile_dat, "Mean_CriticalToCritRecov", "%lf", + (void *)&(P.Mean_CriticalToCritRecov[0]), 1, 1, 0); + GetInputParameter(ParamFile_dat, PreParamFile_dat, "Mean_CritRecovToRecov", "%lf", + (void *)&(P.Mean_CritRecovToRecov[0]), 1, 1, 0); + GetInputParameter(ParamFile_dat, PreParamFile_dat, "Mean_ILIToSARI", "%lf", + (void *)&(P.Mean_ILIToSARI[0]), 1, 1, 0); + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Mean_ILIToDeath", "%lf", + (void *)&(P.Mean_ILIToDeath[0]), 1, 1, 0)) + P.Mean_ILIToDeath[0] = 7.0; + GetInputParameter(ParamFile_dat, PreParamFile_dat, "Mean_SARIToCritical", "%lf", + (void *)&(P.Mean_SARIToCritical[0]), 1, 1, 0); + GetInputParameter(ParamFile_dat, PreParamFile_dat, "Mean_SARIToDeath", "%lf", + (void *)&(P.Mean_SARIToDeath[0]), 1, 1, 0); + GetInputParameter(ParamFile_dat, PreParamFile_dat, "Mean_CriticalToDeath", "%lf", + (void *)&(P.Mean_CriticalToDeath[0]), 1, 1, 0); for (int AgeGroup = 1; AgeGroup < NUM_AGE_GROUPS; AgeGroup++) { - P.Mean_MildToRecovery [AgeGroup] = P.Mean_MildToRecovery [0]; - P.Mean_ILIToRecovery [AgeGroup] = P.Mean_ILIToRecovery [0]; - P.Mean_SARIToRecovery [AgeGroup] = P.Mean_SARIToRecovery [0]; - P.Mean_CriticalToCritRecov [AgeGroup] = P.Mean_CriticalToCritRecov [0]; - P.Mean_CritRecovToRecov [AgeGroup] = P.Mean_CritRecovToRecov [0]; - P.Mean_ILIToSARI [AgeGroup] = P.Mean_ILIToSARI [0]; - P.Mean_ILIToDeath [AgeGroup] = P.Mean_ILIToDeath [0]; - P.Mean_SARIToCritical [AgeGroup] = P.Mean_SARIToCritical [0]; - P.Mean_SARIToDeath [AgeGroup] = P.Mean_SARIToDeath [0]; - P.Mean_CriticalToDeath [AgeGroup] = P.Mean_CriticalToDeath [0]; + P.Mean_MildToRecovery[AgeGroup] = P.Mean_MildToRecovery[0]; + P.Mean_ILIToRecovery[AgeGroup] = P.Mean_ILIToRecovery[0]; + P.Mean_SARIToRecovery[AgeGroup] = P.Mean_SARIToRecovery[0]; + P.Mean_CriticalToCritRecov[AgeGroup] = P.Mean_CriticalToCritRecov[0]; + P.Mean_CritRecovToRecov[AgeGroup] = P.Mean_CritRecovToRecov[0]; + P.Mean_ILIToSARI[AgeGroup] = P.Mean_ILIToSARI[0]; + P.Mean_ILIToDeath[AgeGroup] = P.Mean_ILIToDeath[0]; + P.Mean_SARIToCritical[AgeGroup] = P.Mean_SARIToCritical[0]; + P.Mean_SARIToDeath[AgeGroup] = P.Mean_SARIToDeath[0]; + P.Mean_CriticalToDeath[AgeGroup] = P.Mean_CriticalToDeath[0]; } } else { - GetInputParameter(ParamFile_dat, PreParamFile_dat, "Mean_MildToRecovery", "%lf", (void*)(P.Mean_MildToRecovery), NUM_AGE_GROUPS, 1, 0); - GetInputParameter(ParamFile_dat, PreParamFile_dat, "Mean_ILIToRecovery", "%lf", (void*)(P.Mean_ILIToRecovery), NUM_AGE_GROUPS, 1, 0); - GetInputParameter(ParamFile_dat, PreParamFile_dat, "Mean_SARIToRecovery", "%lf", (void*)(P.Mean_SARIToRecovery), NUM_AGE_GROUPS, 1, 0); - GetInputParameter(ParamFile_dat, PreParamFile_dat, "Mean_CriticalToCritRecov", "%lf", (void*)(P.Mean_CriticalToCritRecov), NUM_AGE_GROUPS, 1, 0); - GetInputParameter(ParamFile_dat, PreParamFile_dat, "Mean_CritRecovToRecov", "%lf", (void*)(P.Mean_CritRecovToRecov), NUM_AGE_GROUPS, 1, 0); - GetInputParameter(ParamFile_dat, PreParamFile_dat, "Mean_ILIToSARI", "%lf", (void*)(P.Mean_ILIToSARI), NUM_AGE_GROUPS, 1, 0); - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Mean_ILIToDeath", "%lf", (void*)(P.Mean_ILIToDeath), NUM_AGE_GROUPS, 1, 0)) - for (j = 0; j < NUM_AGE_GROUPS; j++) P.Mean_ILIToDeath[j] = 7.0; - GetInputParameter(ParamFile_dat, PreParamFile_dat, "Mean_SARIToCritical", "%lf", (void*)(P.Mean_SARIToCritical), NUM_AGE_GROUPS, 1, 0); - GetInputParameter(ParamFile_dat, PreParamFile_dat, "Mean_SARIToDeath", "%lf", (void*)(P.Mean_SARIToDeath), NUM_AGE_GROUPS, 1, 0); - GetInputParameter(ParamFile_dat, PreParamFile_dat, "Mean_CriticalToDeath", "%lf", (void*)(P.Mean_CriticalToDeath), NUM_AGE_GROUPS, 1, 0); + GetInputParameter(ParamFile_dat, PreParamFile_dat, "Mean_MildToRecovery", "%lf", + (void *)(P.Mean_MildToRecovery), NUM_AGE_GROUPS, 1, 0); + GetInputParameter(ParamFile_dat, PreParamFile_dat, "Mean_ILIToRecovery", "%lf", + (void *)(P.Mean_ILIToRecovery), NUM_AGE_GROUPS, 1, 0); + GetInputParameter(ParamFile_dat, PreParamFile_dat, "Mean_SARIToRecovery", "%lf", + (void *)(P.Mean_SARIToRecovery), NUM_AGE_GROUPS, 1, 0); + GetInputParameter(ParamFile_dat, PreParamFile_dat, "Mean_CriticalToCritRecov", "%lf", + (void *)(P.Mean_CriticalToCritRecov), NUM_AGE_GROUPS, 1, 0); + GetInputParameter(ParamFile_dat, PreParamFile_dat, "Mean_CritRecovToRecov", "%lf", + (void *)(P.Mean_CritRecovToRecov), NUM_AGE_GROUPS, 1, 0); + GetInputParameter(ParamFile_dat, PreParamFile_dat, "Mean_ILIToSARI", "%lf", + (void *)(P.Mean_ILIToSARI), NUM_AGE_GROUPS, 1, 0); + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Mean_ILIToDeath", "%lf", + (void *)(P.Mean_ILIToDeath), NUM_AGE_GROUPS, 1, 0)) + for (j = 0; j < NUM_AGE_GROUPS; j++) + P.Mean_ILIToDeath[j] = 7.0; + GetInputParameter(ParamFile_dat, PreParamFile_dat, "Mean_SARIToCritical", "%lf", + (void *)(P.Mean_SARIToCritical), NUM_AGE_GROUPS, 1, 0); + GetInputParameter(ParamFile_dat, PreParamFile_dat, "Mean_SARIToDeath", "%lf", + (void *)(P.Mean_SARIToDeath), NUM_AGE_GROUPS, 1, 0); + GetInputParameter(ParamFile_dat, PreParamFile_dat, "Mean_CriticalToDeath", "%lf", + (void *)(P.Mean_CriticalToDeath), NUM_AGE_GROUPS, 1, 0); } //// Get ICDFs - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "MildToRecovery_icdf" , "%lf", (void*)P.MildToRecovery_icdf , CDF_RES + 1, 1, 0)) SetICDF(P.MildToRecovery_icdf , ICDF_START); - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "ILIToRecovery_icdf" , "%lf", (void*)P.ILIToRecovery_icdf , CDF_RES + 1, 1, 0)) SetICDF(P.ILIToRecovery_icdf , ICDF_START); - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "ILIToDeath_icdf" , "%lf", (void*)P.ILIToDeath_icdf , CDF_RES + 1, 1, 0)) SetICDF(P.ILIToDeath_icdf , ICDF_START); - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "SARIToRecovery_icdf" , "%lf", (void*)P.SARIToRecovery_icdf , CDF_RES + 1, 1, 0)) SetICDF(P.SARIToRecovery_icdf , ICDF_START); - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "CriticalToCritRecov_icdf" , "%lf", (void*)P.CriticalToCritRecov_icdf , CDF_RES + 1, 1, 0)) SetICDF(P.CriticalToCritRecov_icdf , ICDF_START); - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "CritRecovToRecov_icdf" , "%lf", (void*)P.CritRecovToRecov_icdf , CDF_RES + 1, 1, 0)) SetICDF(P.CritRecovToRecov_icdf , ICDF_START); - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "ILIToSARI_icdf" , "%lf", (void*)P.ILIToSARI_icdf , CDF_RES + 1, 1, 0)) SetICDF(P.ILIToSARI_icdf , ICDF_START); - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "SARIToCritical_icdf" , "%lf", (void*)P.SARIToCritical_icdf , CDF_RES + 1, 1, 0)) SetICDF(P.SARIToCritical_icdf , ICDF_START); - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "SARIToDeath_icdf" , "%lf", (void*)P.SARIToDeath_icdf , CDF_RES + 1, 1, 0)) SetICDF(P.SARIToDeath_icdf , ICDF_START); - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "CriticalToDeath_icdf" , "%lf", (void*)P.CriticalToDeath_icdf , CDF_RES + 1, 1, 0)) SetICDF(P.CriticalToDeath_icdf , ICDF_START); + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "MildToRecovery_icdf", "%lf", + (void *)P.MildToRecovery_icdf, CDF_RES + 1, 1, 0)) + SetICDF(P.MildToRecovery_icdf, ICDF_START); + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "ILIToRecovery_icdf", "%lf", + (void *)P.ILIToRecovery_icdf, CDF_RES + 1, 1, 0)) + SetICDF(P.ILIToRecovery_icdf, ICDF_START); + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "ILIToDeath_icdf", "%lf", + (void *)P.ILIToDeath_icdf, CDF_RES + 1, 1, 0)) + SetICDF(P.ILIToDeath_icdf, ICDF_START); + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "SARIToRecovery_icdf", "%lf", + (void *)P.SARIToRecovery_icdf, CDF_RES + 1, 1, 0)) + SetICDF(P.SARIToRecovery_icdf, ICDF_START); + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "CriticalToCritRecov_icdf", "%lf", + (void *)P.CriticalToCritRecov_icdf, CDF_RES + 1, 1, 0)) + SetICDF(P.CriticalToCritRecov_icdf, ICDF_START); + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "CritRecovToRecov_icdf", "%lf", + (void *)P.CritRecovToRecov_icdf, CDF_RES + 1, 1, 0)) + SetICDF(P.CritRecovToRecov_icdf, ICDF_START); + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "ILIToSARI_icdf", "%lf", + (void *)P.ILIToSARI_icdf, CDF_RES + 1, 1, 0)) + SetICDF(P.ILIToSARI_icdf, ICDF_START); + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "SARIToCritical_icdf", "%lf", + (void *)P.SARIToCritical_icdf, CDF_RES + 1, 1, 0)) + SetICDF(P.SARIToCritical_icdf, ICDF_START); + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "SARIToDeath_icdf", "%lf", + (void *)P.SARIToDeath_icdf, CDF_RES + 1, 1, 0)) + SetICDF(P.SARIToDeath_icdf, ICDF_START); + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "CriticalToDeath_icdf", "%lf", + (void *)P.CriticalToDeath_icdf, CDF_RES + 1, 1, 0)) + SetICDF(P.CriticalToDeath_icdf, ICDF_START); // exponentiate for (int quantile = 0; quantile <= CDF_RES; quantile++) { - P.MildToRecovery_icdf [quantile] = exp(- P.MildToRecovery_icdf [quantile]); - P.ILIToRecovery_icdf [quantile] = exp(- P.ILIToRecovery_icdf [quantile]); - P.ILIToDeath_icdf [quantile] = exp(- P.ILIToDeath_icdf [quantile]); - P.ILIToSARI_icdf [quantile] = exp(- P.ILIToSARI_icdf [quantile]); - P.SARIToRecovery_icdf [quantile] = exp(- P.SARIToRecovery_icdf [quantile]); - P.SARIToDeath_icdf [quantile] = exp(- P.SARIToDeath_icdf [quantile]); - P.SARIToCritical_icdf [quantile] = exp(- P.SARIToCritical_icdf [quantile]); - P.CriticalToCritRecov_icdf [quantile] = exp(- P.CriticalToCritRecov_icdf [quantile]); - P.CritRecovToRecov_icdf [quantile] = exp(- P.CritRecovToRecov_icdf [quantile]); - P.CriticalToDeath_icdf [quantile] = exp(- P.CriticalToDeath_icdf [quantile]); + P.MildToRecovery_icdf[quantile] = exp(-P.MildToRecovery_icdf[quantile]); + P.ILIToRecovery_icdf[quantile] = exp(-P.ILIToRecovery_icdf[quantile]); + P.ILIToDeath_icdf[quantile] = exp(-P.ILIToDeath_icdf[quantile]); + P.ILIToSARI_icdf[quantile] = exp(-P.ILIToSARI_icdf[quantile]); + P.SARIToRecovery_icdf[quantile] = exp(-P.SARIToRecovery_icdf[quantile]); + P.SARIToDeath_icdf[quantile] = exp(-P.SARIToDeath_icdf[quantile]); + P.SARIToCritical_icdf[quantile] = exp(-P.SARIToCritical_icdf[quantile]); + P.CriticalToCritRecov_icdf[quantile] = exp(-P.CriticalToCritRecov_icdf[quantile]); + P.CritRecovToRecov_icdf[quantile] = exp(-P.CritRecovToRecov_icdf[quantile]); + P.CriticalToDeath_icdf[quantile] = exp(-P.CriticalToDeath_icdf[quantile]); } - if(!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Prop_Mild_ByAge", "%lf", (void*)P.Prop_Mild_ByAge, NUM_AGE_GROUPS, 1, 0)) - for(i = 0; i < NUM_AGE_GROUPS; i++) + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Prop_Mild_ByAge", "%lf", + (void *)P.Prop_Mild_ByAge, NUM_AGE_GROUPS, 1, 0)) + for (i = 0; i < NUM_AGE_GROUPS; i++) P.Prop_Mild_ByAge[i] = 0.5; - if(!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Prop_ILI_ByAge", "%lf", (void*)P.Prop_ILI_ByAge, NUM_AGE_GROUPS, 1, 0)) - for(i = 0; i < NUM_AGE_GROUPS; i++) + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Prop_ILI_ByAge", "%lf", + (void *)P.Prop_ILI_ByAge, NUM_AGE_GROUPS, 1, 0)) + for (i = 0; i < NUM_AGE_GROUPS; i++) P.Prop_ILI_ByAge[i] = 0.3; - if(!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Prop_SARI_ByAge", "%lf", (void*)P.Prop_SARI_ByAge, NUM_AGE_GROUPS, 1, 0)) - for(i = 0; i < NUM_AGE_GROUPS; i++) + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Prop_SARI_ByAge", "%lf", + (void *)P.Prop_SARI_ByAge, NUM_AGE_GROUPS, 1, 0)) + for (i = 0; i < NUM_AGE_GROUPS; i++) P.Prop_SARI_ByAge[i] = 0.15; - if(!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Prop_Critical_ByAge", "%lf", (void*)P.Prop_Critical_ByAge, NUM_AGE_GROUPS, 1, 0)) - for(i = 0; i < NUM_AGE_GROUPS; i++) + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Prop_Critical_ByAge", "%lf", + (void *)P.Prop_Critical_ByAge, NUM_AGE_GROUPS, 1, 0)) + for (i = 0; i < NUM_AGE_GROUPS; i++) P.Prop_Critical_ByAge[i] = 0.05; - if(!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "CFR_SARI_ByAge", "%lf", (void*)P.CFR_SARI_ByAge, NUM_AGE_GROUPS, 1, 0)) - for(i = 0; i < NUM_AGE_GROUPS; i++) + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "CFR_SARI_ByAge", "%lf", + (void *)P.CFR_SARI_ByAge, NUM_AGE_GROUPS, 1, 0)) + for (i = 0; i < NUM_AGE_GROUPS; i++) P.CFR_SARI_ByAge[i] = 0.50; - if(!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "CFR_Critical_ByAge", "%lf", (void*)P.CFR_Critical_ByAge, NUM_AGE_GROUPS, 1, 0)) - for(i = 0; i < NUM_AGE_GROUPS; i++) + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "CFR_Critical_ByAge", "%lf", + (void *)P.CFR_Critical_ByAge, NUM_AGE_GROUPS, 1, 0)) + for (i = 0; i < NUM_AGE_GROUPS; i++) P.CFR_Critical_ByAge[i] = 0.50; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "CFR_ILI_ByAge", "%lf", (void*)P.CFR_ILI_ByAge, NUM_AGE_GROUPS, 1, 0)) + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "CFR_ILI_ByAge", "%lf", + (void *)P.CFR_ILI_ByAge, NUM_AGE_GROUPS, 1, 0)) for (i = 0; i < NUM_AGE_GROUPS; i++) P.CFR_ILI_ByAge[i] = 0.00; } - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Bounding box for bitmap", "%lf", (void*) & (P.BoundingBox[0]), 4, 1, 0)) + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Bounding box for bitmap", "%lf", + (void *)&(P.BoundingBox[0]), 4, 1, 0)) { P.BoundingBox[0] = P.BoundingBox[1] = 0.0; P.BoundingBox[2] = P.BoundingBox[3] = 1.0; } - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Spatial domain for simulation", "%lf", (void*) & (P.SpatialBoundingBox[0]), 4, 1, 0)) + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Spatial domain for simulation", "%lf", + (void *)&(P.SpatialBoundingBox[0]), 4, 1, 0)) { P.SpatialBoundingBox[0] = P.SpatialBoundingBox[1] = 0.0; P.SpatialBoundingBox[2] = P.SpatialBoundingBox[3] = 1.0; } - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Grid size", "%lf", (void*) & (P.in_cells_.width), 1, 1, 0)) P.in_cells_.width = 1.0 / 120.0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Use long/lat coord system", "%i", (void*) & (P.DoUTM_coords), 1, 1, 0)) P.DoUTM_coords = 1; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Bitmap scale", "%lf", (void*) & (P.BitmapScale), 1, 1, 0)) P.BitmapScale = 1.0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Bitmap y:x aspect scaling", "%lf", (void*) & (P.BitmapAspectScale), 1, 1, 0)) P.BitmapAspectScale = 1.0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Bitmap movie frame interval", "%i", (void*) & (P.BitmapMovieFrame), 1, 1, 0)) P.BitmapMovieFrame = 250; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Output bitmap", "%i", (void*) & (P.OutputBitmap), 1, 1, 0)) P.OutputBitmap = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Output bitmap detected", "%i", (void*) & (P.OutputBitmapDetected), 1, 1, 0)) P.OutputBitmapDetected = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Output immunity on bitmap", "%i", (void*) & (P.DoImmuneBitmap), 1, 1, 0)) P.DoImmuneBitmap = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Output infection tree", "%i", (void*) & (P.DoInfectionTree), 1, 1, 0)) P.DoInfectionTree = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Do one generation", "%i", (void*) & (P.DoOneGen), 1, 1, 0)) P.DoOneGen = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Output every realisation", "%i", (void*) & (P.OutputEveryRealisation), 1, 1, 0)) P.OutputEveryRealisation = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Maximum number to sample for correlations", "%i", (void*) & (P.MaxCorrSample), 1, 1, 0)) P.MaxCorrSample = 1000000000; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Assume SI model", "%i", (void*) & (P.DoSI), 1, 1, 0)) P.DoSI = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Assume periodic boundary conditions", "%i", (void*) & (P.DoPeriodicBoundaries), 1, 1, 0)) P.DoPeriodicBoundaries = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Only output non-extinct realisations", "%i", (void*) & (P.OutputOnlyNonExtinct), 1, 1, 0)) P.OutputOnlyNonExtinct = 0; - - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Use cases per thousand threshold for area controls", "%i", (void*) & (P.DoPerCapitaTriggers), 1, 1, 0)) P.DoPerCapitaTriggers = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Use global triggers for interventions", "%i", (void*) & (P.DoGlobalTriggers), 1, 1, 0)) P.DoGlobalTriggers = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Use admin unit triggers for interventions", "%i", (void*) & (P.DoAdminTriggers), 1, 1, 0)) P.DoAdminTriggers = 0; - if(!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Use ICU case triggers for interventions", "%i", (void*) & (P.DoICUTriggers), 1, 1, 0)) P.DoICUTriggers = 0; - if (P.DoGlobalTriggers) P.DoAdminTriggers = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Divisor for per-capita area threshold (default 1000)", "%i", (void*) & (P.IncThreshPop), 1, 1, 0)) P.IncThreshPop = 1000; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Divisor for per-capita global threshold (default 1000)", "%i", (void*) & (P.GlobalIncThreshPop), 1, 1, 0)) P.GlobalIncThreshPop = 1000; - - - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Number of sampling intervals over which cumulative incidence measured for global trigger", "%i", (void*) & (P.TriggersSamplingInterval), 1, 1, 0)) P.TriggersSamplingInterval = 10000000; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Proportion of cases detected for treatment", "%lf", (void*) & (P.PostAlertControlPropCasesId), 1, 1, 0)) P.PostAlertControlPropCasesId = 1; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Proportion of cases detected before outbreak alert", "%lf", (void*) & (P.PreAlertControlPropCasesId), 1, 1, 0)) P.PreAlertControlPropCasesId = 1.0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Trigger alert on deaths", "%i", (void*)&(P.TriggerAlertOnDeaths), 1, 1, 0)) P.TriggerAlertOnDeaths = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Grid size", "%lf", + (void *)&(P.in_cells_.width), 1, 1, 0)) + P.in_cells_.width = 1.0 / 120.0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Use long/lat coord system", "%i", + (void *)&(P.DoUTM_coords), 1, 1, 0)) + P.DoUTM_coords = 1; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Bitmap scale", "%lf", + (void *)&(P.BitmapScale), 1, 1, 0)) + P.BitmapScale = 1.0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Bitmap y:x aspect scaling", "%lf", + (void *)&(P.BitmapAspectScale), 1, 1, 0)) + P.BitmapAspectScale = 1.0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Bitmap movie frame interval", "%i", + (void *)&(P.BitmapMovieFrame), 1, 1, 0)) + P.BitmapMovieFrame = 250; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Output bitmap", "%i", + (void *)&(P.OutputBitmap), 1, 1, 0)) + P.OutputBitmap = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Output bitmap detected", "%i", + (void *)&(P.OutputBitmapDetected), 1, 1, 0)) + P.OutputBitmapDetected = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Output immunity on bitmap", "%i", + (void *)&(P.DoImmuneBitmap), 1, 1, 0)) + P.DoImmuneBitmap = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Output infection tree", "%i", + (void *)&(P.DoInfectionTree), 1, 1, 0)) + P.DoInfectionTree = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Do one generation", "%i", + (void *)&(P.DoOneGen), 1, 1, 0)) + P.DoOneGen = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Output every realisation", "%i", + (void *)&(P.OutputEveryRealisation), 1, 1, 0)) + P.OutputEveryRealisation = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Maximum number to sample for correlations", "%i", + (void *)&(P.MaxCorrSample), 1, 1, 0)) + P.MaxCorrSample = 1000000000; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Assume SI model", "%i", + (void *)&(P.DoSI), 1, 1, 0)) + P.DoSI = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Assume periodic boundary conditions", + "%i", (void *)&(P.DoPeriodicBoundaries), 1, 1, 0)) + P.DoPeriodicBoundaries = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Only output non-extinct realisations", + "%i", (void *)&(P.OutputOnlyNonExtinct), 1, 1, 0)) + P.OutputOnlyNonExtinct = 0; + + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Use cases per thousand threshold for area controls", "%i", + (void *)&(P.DoPerCapitaTriggers), 1, 1, 0)) + P.DoPerCapitaTriggers = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Use global triggers for interventions", + "%i", (void *)&(P.DoGlobalTriggers), 1, 1, 0)) + P.DoGlobalTriggers = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Use admin unit triggers for interventions", "%i", + (void *)&(P.DoAdminTriggers), 1, 1, 0)) + P.DoAdminTriggers = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Use ICU case triggers for interventions", "%i", + (void *)&(P.DoICUTriggers), 1, 1, 0)) + P.DoICUTriggers = 0; + if (P.DoGlobalTriggers) + P.DoAdminTriggers = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Divisor for per-capita area threshold (default 1000)", "%i", + (void *)&(P.IncThreshPop), 1, 1, 0)) + P.IncThreshPop = 1000; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Divisor for per-capita global threshold (default 1000)", "%i", + (void *)&(P.GlobalIncThreshPop), 1, 1, 0)) + P.GlobalIncThreshPop = 1000; + + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Number of sampling intervals over which cumulative incidence measured " + "for global trigger", + "%i", (void *)&(P.TriggersSamplingInterval), 1, 1, 0)) + P.TriggersSamplingInterval = 10000000; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Proportion of cases detected for treatment", "%lf", + (void *)&(P.PostAlertControlPropCasesId), 1, 1, 0)) + P.PostAlertControlPropCasesId = 1; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Proportion of cases detected before outbreak alert", "%lf", + (void *)&(P.PreAlertControlPropCasesId), 1, 1, 0)) + P.PreAlertControlPropCasesId = 1.0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Trigger alert on deaths", "%i", + (void *)&(P.TriggerAlertOnDeaths), 1, 1, 0)) + P.TriggerAlertOnDeaths = 0; if (P.TriggerAlertOnDeaths) { if (P.CaseOrDeathThresholdBeforeAlert == 0) - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Number of deaths accummulated before alert", "%i", (void*)&(P.CaseOrDeathThresholdBeforeAlert), 1, 1, 0)) P.CaseOrDeathThresholdBeforeAlert = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Number of deaths accummulated before alert", "%i", + (void *)&(P.CaseOrDeathThresholdBeforeAlert), 1, 1, 0)) + P.CaseOrDeathThresholdBeforeAlert = 0; } else if (P.CaseOrDeathThresholdBeforeAlert == 0) { - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Number of detected cases needed before outbreak alert triggered", "%i", (void*) & (P.CaseOrDeathThresholdBeforeAlert), 1, 1, 0)) P.CaseOrDeathThresholdBeforeAlert = 0; - } - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Alert trigger starts after interventions", "%i", (void*)&(P.DoAlertTriggerAfterInterv), 1, 1, 0)) P.DoAlertTriggerAfterInterv = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Day of year trigger is reached", "%lf", (void*)&(P.DateTriggerReached_CalTime), 1, 1, 0)) P.DateTriggerReached_CalTime = -1; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Number of detected cases needed before outbreak alert triggered", "%i", + (void *)&(P.CaseOrDeathThresholdBeforeAlert), 1, 1, 0)) + P.CaseOrDeathThresholdBeforeAlert = 0; + } + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Alert trigger starts after interventions", "%i", + (void *)&(P.DoAlertTriggerAfterInterv), 1, 1, 0)) + P.DoAlertTriggerAfterInterv = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Day of year trigger is reached", "%lf", + (void *)&(P.DateTriggerReached_CalTime), 1, 1, 0)) + P.DateTriggerReached_CalTime = -1; if (P.DoAlertTriggerAfterInterv) { - GetInputParameter(ParamFile_dat, PreParamFile_dat, "Day of year interventions start", "%lf", (void*)&(P.Interventions_StartDate_CalTime), 1, 1, 0); + GetInputParameter(ParamFile_dat, PreParamFile_dat, "Day of year interventions start", "%lf", + (void *)&(P.Interventions_StartDate_CalTime), 1, 1, 0); if (P.DateTriggerReached_CalTime <= P.Interventions_StartDate_CalTime) P.DoAlertTriggerAfterInterv = 0; else @@ -1279,173 +1854,413 @@ void ReadParams(char* ParamFile, char* PreParamFile) else P.Interventions_StartDate_CalTime = P.DateTriggerReached_CalTime; P.CaseOrDeathThresholdBeforeAlert_Fixed = P.CaseOrDeathThresholdBeforeAlert; - //if (P.DoAlertTriggerAfterInterv) P.ResetSeeds =P.KeepSameSeeds = 1; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Number of days to accummulate cases/deaths before alert", "%i", (void*)&(P.WindowToEvaluateTriggerAlert), 1, 1, 0)) P.WindowToEvaluateTriggerAlert = 1000; - - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Only use confirmed cases to trigger alert", "%i", (void*) & (P.DoEarlyCaseDiagnosis), 1, 1, 0)) P.DoEarlyCaseDiagnosis = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Only treat mixing groups within places", "%i", (void*) & (P.DoPlaceGroupTreat), 1, 1, 0)) P.DoPlaceGroupTreat = 0; - - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Treatment trigger incidence per cell" , "%lf", (void*) & (P.TreatCellIncThresh) , 1, 1, 0)) P.TreatCellIncThresh = 1000000000; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Case isolation trigger incidence per cell" , "%lf", (void*) & (P.CaseIsolation_CellIncThresh) , 1, 1, 0)) P.CaseIsolation_CellIncThresh = P.TreatCellIncThresh; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Household quarantine trigger incidence per cell" , "%lf", (void*) & (P.HHQuar_CellIncThresh) , 1, 1, 0)) P.HHQuar_CellIncThresh = P.TreatCellIncThresh; - - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Relative susceptibility of treated individual", "%lf", (void*) & (P.TreatSuscDrop), 1, 1, 0)) P.TreatSuscDrop = 1; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Relative infectiousness of treated individual", "%lf", (void*) & (P.TreatInfDrop), 1, 1, 0)) P.TreatInfDrop = 1; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Proportion of symptomatic cases resulting in death prevented by treatment", "%lf", (void*) & (P.TreatDeathDrop), 1, 1, 0)) P.TreatDeathDrop = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Proportion of symptomatic cases prevented by treatment", "%lf", (void*) & (P.TreatSympDrop), 1, 1, 0)) P.TreatSympDrop = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Delay to treat cell", "%lf", (void*) & (P.TreatDelayMean), 1, 1, 0)) P.TreatDelayMean = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Duration of course of treatment", "%lf", (void*) & (P.TreatCaseCourseLength), 1, 1, 0)) P.TreatCaseCourseLength = 5; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Duration of course of prophylaxis", "%lf", (void*) & (P.TreatProphCourseLength), 1, 1, 0)) P.TreatProphCourseLength = 10; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Proportion of detected cases treated", "%lf", (void*) & (P.TreatPropCases), 1, 1, 0)) P.TreatPropCases = 1; + // if (P.DoAlertTriggerAfterInterv) P.ResetSeeds =P.KeepSameSeeds = 1; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Number of days to accummulate cases/deaths before alert", "%i", + (void *)&(P.WindowToEvaluateTriggerAlert), 1, 1, 0)) + P.WindowToEvaluateTriggerAlert = 1000; + + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Only use confirmed cases to trigger alert", "%i", + (void *)&(P.DoEarlyCaseDiagnosis), 1, 1, 0)) + P.DoEarlyCaseDiagnosis = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Only treat mixing groups within places", + "%i", (void *)&(P.DoPlaceGroupTreat), 1, 1, 0)) + P.DoPlaceGroupTreat = 0; + + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Treatment trigger incidence per cell", + "%lf", (void *)&(P.TreatCellIncThresh), 1, 1, 0)) + P.TreatCellIncThresh = 1000000000; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Case isolation trigger incidence per cell", "%lf", + (void *)&(P.CaseIsolation_CellIncThresh), 1, 1, 0)) + P.CaseIsolation_CellIncThresh = P.TreatCellIncThresh; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Household quarantine trigger incidence per cell", "%lf", + (void *)&(P.HHQuar_CellIncThresh), 1, 1, 0)) + P.HHQuar_CellIncThresh = P.TreatCellIncThresh; + + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Relative susceptibility of treated individual", "%lf", + (void *)&(P.TreatSuscDrop), 1, 1, 0)) + P.TreatSuscDrop = 1; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Relative infectiousness of treated individual", "%lf", + (void *)&(P.TreatInfDrop), 1, 1, 0)) + P.TreatInfDrop = 1; + if (!GetInputParameter2( + ParamFile_dat, PreParamFile_dat, + "Proportion of symptomatic cases resulting in death prevented by treatment", "%lf", + (void *)&(P.TreatDeathDrop), 1, 1, 0)) + P.TreatDeathDrop = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Proportion of symptomatic cases prevented by treatment", "%lf", + (void *)&(P.TreatSympDrop), 1, 1, 0)) + P.TreatSympDrop = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Delay to treat cell", "%lf", + (void *)&(P.TreatDelayMean), 1, 1, 0)) + P.TreatDelayMean = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Duration of course of treatment", "%lf", + (void *)&(P.TreatCaseCourseLength), 1, 1, 0)) + P.TreatCaseCourseLength = 5; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Duration of course of prophylaxis", + "%lf", (void *)&(P.TreatProphCourseLength), 1, 1, 0)) + P.TreatProphCourseLength = 10; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Proportion of detected cases treated", + "%lf", (void *)&(P.TreatPropCases), 1, 1, 0)) + P.TreatPropCases = 1; if (P.DoHouseholds) { - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Proportion of households of cases treated", "%lf", (void*) & (P.TreatPropCaseHouseholds), 1, 1, 0)) P.TreatPropCaseHouseholds = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Duration of household prophylaxis policy", "%lf", (void*) & (P.TreatHouseholdsDuration), 1, 1, 0)) P.TreatHouseholdsDuration = USHRT_MAX / P.TimeStepsPerDay; - } - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Proportion treated", "%lf", (void*) & (P.TreatPropRadial), 1, 1, 0)) P.TreatPropRadial = 1.0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Proportion treated in radial prophylaxis", "%lf", (void*) & (P.TreatPropRadial), 1, 1, 0)) P.TreatPropRadial = 1.0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Treatment radius", "%lf", (void*) & (P.TreatRadius), 1, 1, 0)) P.TreatRadius = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Duration of place/geographic prophylaxis policy", "%lf", (void*) & (P.TreatPlaceGeogDuration), 1, 1, 0)) P.TreatPlaceGeogDuration = USHRT_MAX / P.TimeStepsPerDay; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Treatment start time", "%lf", (void*) & (P.TreatTimeStartBase), 1, 1, 0)) P.TreatTimeStartBase = USHRT_MAX / P.TimeStepsPerDay; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Proportion of households of cases treated", "%lf", + (void *)&(P.TreatPropCaseHouseholds), 1, 1, 0)) + P.TreatPropCaseHouseholds = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Duration of household prophylaxis policy", "%lf", + (void *)&(P.TreatHouseholdsDuration), 1, 1, 0)) + P.TreatHouseholdsDuration = USHRT_MAX / P.TimeStepsPerDay; + } + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Proportion treated", "%lf", + (void *)&(P.TreatPropRadial), 1, 1, 0)) + P.TreatPropRadial = 1.0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Proportion treated in radial prophylaxis", "%lf", + (void *)&(P.TreatPropRadial), 1, 1, 0)) + P.TreatPropRadial = 1.0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Treatment radius", "%lf", + (void *)&(P.TreatRadius), 1, 1, 0)) + P.TreatRadius = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Duration of place/geographic prophylaxis policy", "%lf", + (void *)&(P.TreatPlaceGeogDuration), 1, 1, 0)) + P.TreatPlaceGeogDuration = USHRT_MAX / P.TimeStepsPerDay; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Treatment start time", "%lf", + (void *)&(P.TreatTimeStartBase), 1, 1, 0)) + P.TreatTimeStartBase = USHRT_MAX / P.TimeStepsPerDay; if (P.DoPlaces) { - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Proportion of places treated after case detected", "%lf", (void*)P.TreatPlaceProbCaseId, P.PlaceTypeNum, 1, 0)) - for (i = 0; i < NUM_PLACE_TYPES; i++) P.TreatPlaceProbCaseId[i] = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Proportion of people treated in targeted places", "%lf", (void*)P.TreatPlaceTotalProp, P.PlaceTypeNum, 1, 0)) - for (i = 0; i < NUM_PLACE_TYPES; i++) P.TreatPlaceTotalProp[i] = 0; - } - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Maximum number of doses available", "%lf", (void*) & (P.TreatMaxCoursesBase), 1, 1, 0)) P.TreatMaxCoursesBase = 1e20; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Start time of additional treatment production", "%lf", (void*) & (P.TreatNewCoursesStartTime), 1, 1, 0)) P.TreatNewCoursesStartTime = USHRT_MAX / P.TimeStepsPerDay; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Rate of additional treatment production (courses per day)", "%lf", (void*) & (P.TreatNewCoursesRate), 1, 1, 0)) P.TreatNewCoursesRate = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Maximum number of people targeted with radial prophylaxis per case", "%i", (void*) & (P.TreatMaxCoursesPerCase), 1, 1, 0)) P.TreatMaxCoursesPerCase = 1000000000; - + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Proportion of places treated after case detected", "%lf", + (void *)P.TreatPlaceProbCaseId, P.PlaceTypeNum, 1, 0)) + for (i = 0; i < NUM_PLACE_TYPES; i++) + P.TreatPlaceProbCaseId[i] = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Proportion of people treated in targeted places", "%lf", + (void *)P.TreatPlaceTotalProp, P.PlaceTypeNum, 1, 0)) + for (i = 0; i < NUM_PLACE_TYPES; i++) + P.TreatPlaceTotalProp[i] = 0; + } + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Maximum number of doses available", + "%lf", (void *)&(P.TreatMaxCoursesBase), 1, 1, 0)) + P.TreatMaxCoursesBase = 1e20; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Start time of additional treatment production", "%lf", + (void *)&(P.TreatNewCoursesStartTime), 1, 1, 0)) + P.TreatNewCoursesStartTime = USHRT_MAX / P.TimeStepsPerDay; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Rate of additional treatment production (courses per day)", "%lf", + (void *)&(P.TreatNewCoursesRate), 1, 1, 0)) + P.TreatNewCoursesRate = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Maximum number of people targeted with radial prophylaxis per case", + "%i", (void *)&(P.TreatMaxCoursesPerCase), 1, 1, 0)) + P.TreatMaxCoursesPerCase = 1000000000; if (P.DoAdUnits) { - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Treat administrative units rather than rings", "%i", (void*) & (P.TreatByAdminUnit), 1, 1, 0)) P.TreatByAdminUnit = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Administrative unit divisor for treatment", "%i", (void*) & (P.TreatAdminUnitDivisor), 1, 1, 0)) P.TreatAdminUnitDivisor = 1; - if ((P.TreatAdminUnitDivisor == 0) || (P.TreatByAdminUnit == 0)) { P.TreatByAdminUnit = 0; P.TreatAdminUnitDivisor = 1; } + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Treat administrative units rather than rings", "%i", + (void *)&(P.TreatByAdminUnit), 1, 1, 0)) + P.TreatByAdminUnit = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Administrative unit divisor for treatment", "%i", + (void *)&(P.TreatAdminUnitDivisor), 1, 1, 0)) + P.TreatAdminUnitDivisor = 1; + if ((P.TreatAdminUnitDivisor == 0) || (P.TreatByAdminUnit == 0)) + { + P.TreatByAdminUnit = 0; + P.TreatAdminUnitDivisor = 1; + } } else { - P.TreatAdminUnitDivisor = 1; P.TreatByAdminUnit = 0; - } - - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Vaccination trigger incidence per cell", "%lf", (void*) & (P.VaccCellIncThresh), 1, 1, 0)) P.VaccCellIncThresh = 1000000000; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Relative susceptibility of vaccinated individual", "%lf", (void*) & (P.VaccSuscDrop), 1, 1, 0)) P.VaccSuscDrop = 1; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Relative susceptibility of individual vaccinated after switch time", "%lf", (void*) & (P.VaccSuscDrop2), 1, 1, 0)) P.VaccSuscDrop2 = 1; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Switch time at which vaccine efficacy increases", "%lf", (void*) & (P.VaccTimeEfficacySwitch), 1, 1, 0)) P.VaccTimeEfficacySwitch = USHRT_MAX / P.TimeStepsPerDay; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Decay rate of vaccine efficacy (per year)", "%lf", (void*) & (P.VaccEfficacyDecay), 1, 1, 0)) P.VaccEfficacyDecay = 0; + P.TreatAdminUnitDivisor = 1; + P.TreatByAdminUnit = 0; + } + + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Vaccination trigger incidence per cell", + "%lf", (void *)&(P.VaccCellIncThresh), 1, 1, 0)) + P.VaccCellIncThresh = 1000000000; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Relative susceptibility of vaccinated individual", "%lf", + (void *)&(P.VaccSuscDrop), 1, 1, 0)) + P.VaccSuscDrop = 1; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Relative susceptibility of individual vaccinated after switch time", + "%lf", (void *)&(P.VaccSuscDrop2), 1, 1, 0)) + P.VaccSuscDrop2 = 1; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Switch time at which vaccine efficacy increases", "%lf", + (void *)&(P.VaccTimeEfficacySwitch), 1, 1, 0)) + P.VaccTimeEfficacySwitch = USHRT_MAX / P.TimeStepsPerDay; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Decay rate of vaccine efficacy (per year)", "%lf", + (void *)&(P.VaccEfficacyDecay), 1, 1, 0)) + P.VaccEfficacyDecay = 0; P.VaccEfficacyDecay /= DAYS_PER_YEAR; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Relative infectiousness of vaccinated individual", "%lf", (void*) & (P.VaccInfDrop), 1, 1, 0)) P.VaccInfDrop = 1; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Proportion of symptomatic cases resulting in death prevented by vaccination", "%lf", (void*) & (P.VaccMortDrop), 1, 1, 0)) P.VaccMortDrop = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Proportion of symptomatic cases prevented by vaccination", "%lf", (void*) & (P.VaccSympDrop), 1, 1, 0)) P.VaccSympDrop = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Delay to vaccinate", "%lf", (void*) & (P.VaccDelayMean), 1, 1, 0)) P.VaccDelayMean = 0; - - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Delay from vaccination to full protection", "%lf", (void*) & (P.VaccTimeToEfficacy), 1, 1, 0)) P.VaccTimeToEfficacy = 0; - - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Years between rounds of vaccination", "%lf", (void*) & (P.VaccCampaignInterval), 1, 1, 0)) P.VaccCampaignInterval = 1e10; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Max vaccine doses per day", "%i", (void*) & (P.VaccDosePerDay), 1, 1, 0)) P.VaccDosePerDay = -1; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Relative infectiousness of vaccinated individual", "%lf", + (void *)&(P.VaccInfDrop), 1, 1, 0)) + P.VaccInfDrop = 1; + if (!GetInputParameter2( + ParamFile_dat, PreParamFile_dat, + "Proportion of symptomatic cases resulting in death prevented by vaccination", "%lf", + (void *)&(P.VaccMortDrop), 1, 1, 0)) + P.VaccMortDrop = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Proportion of symptomatic cases prevented by vaccination", "%lf", + (void *)&(P.VaccSympDrop), 1, 1, 0)) + P.VaccSympDrop = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Delay to vaccinate", "%lf", + (void *)&(P.VaccDelayMean), 1, 1, 0)) + P.VaccDelayMean = 0; + + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Delay from vaccination to full protection", "%lf", + (void *)&(P.VaccTimeToEfficacy), 1, 1, 0)) + P.VaccTimeToEfficacy = 0; + + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Years between rounds of vaccination", + "%lf", (void *)&(P.VaccCampaignInterval), 1, 1, 0)) + P.VaccCampaignInterval = 1e10; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Max vaccine doses per day", "%i", + (void *)&(P.VaccDosePerDay), 1, 1, 0)) + P.VaccDosePerDay = -1; P.VaccCampaignInterval *= DAYS_PER_YEAR; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Maximum number of rounds of vaccination", "%i", (void*) & (P.VaccMaxRounds), 1, 1, 0)) P.VaccMaxRounds = 1; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Maximum number of rounds of vaccination", "%i", + (void *)&(P.VaccMaxRounds), 1, 1, 0)) + P.VaccMaxRounds = 1; if (P.DoHouseholds) { - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Proportion of households of cases vaccinated", "%lf", (void*) & (P.VaccPropCaseHouseholds), 1, 1, 0)) P.VaccPropCaseHouseholds = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Duration of household vaccination policy", "%lf", (void*) & (P.VaccHouseholdsDuration), 1, 1, 0)) P.VaccHouseholdsDuration = USHRT_MAX / P.TimeStepsPerDay; - } - - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Vaccination start time", "%lf", (void*) & (P.VaccTimeStartBase), 1, 1, 0)) P.VaccTimeStartBase = USHRT_MAX / P.TimeStepsPerDay; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Proportion of population vaccinated", "%lf", (void*) & (P.VaccProp), 1, 1, 0)) P.VaccProp = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Time taken to reach max vaccination coverage (in years)", "%lf", (void*) & (P.VaccCoverageIncreasePeriod), 1, 1, 0)) P.VaccCoverageIncreasePeriod = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Proportion of households of cases vaccinated", "%lf", + (void *)&(P.VaccPropCaseHouseholds), 1, 1, 0)) + P.VaccPropCaseHouseholds = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Duration of household vaccination policy", "%lf", + (void *)&(P.VaccHouseholdsDuration), 1, 1, 0)) + P.VaccHouseholdsDuration = USHRT_MAX / P.TimeStepsPerDay; + } + + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Vaccination start time", "%lf", + (void *)&(P.VaccTimeStartBase), 1, 1, 0)) + P.VaccTimeStartBase = USHRT_MAX / P.TimeStepsPerDay; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Proportion of population vaccinated", + "%lf", (void *)&(P.VaccProp), 1, 1, 0)) + P.VaccProp = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Time taken to reach max vaccination coverage (in years)", "%lf", + (void *)&(P.VaccCoverageIncreasePeriod), 1, 1, 0)) + P.VaccCoverageIncreasePeriod = 0; P.VaccCoverageIncreasePeriod *= DAYS_PER_YEAR; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Time to start geographic vaccination", "%lf", (void*) & (P.VaccTimeStartGeo), 1, 1, 0)) P.VaccTimeStartGeo = 1e10; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Vaccination radius", "%lf", (void*) & (P.VaccRadius), 1, 1, 0)) P.VaccRadius = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Minimum radius from case to vaccinate", "%lf", (void*) & (P.VaccMinRadius), 1, 1, 0)) P.VaccMinRadius = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Maximum number of vaccine courses available", "%lf", (void*) & (P.VaccMaxCoursesBase), 1, 1, 0)) P.VaccMaxCoursesBase = 1e20; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Start time of additional vaccine production", "%lf", (void*) & (P.VaccNewCoursesStartTime), 1, 1, 0)) P.VaccNewCoursesStartTime = USHRT_MAX / P.TimeStepsPerDay; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "End time of additional vaccine production", "%lf", (void*) & (P.VaccNewCoursesEndTime), 1, 1, 0)) P.VaccNewCoursesEndTime = USHRT_MAX / P.TimeStepsPerDay; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Rate of additional vaccine production (courses per day)", "%lf", (void*) & (P.VaccNewCoursesRate), 1, 1, 0)) P.VaccNewCoursesRate = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Apply mass rather than reactive vaccination", "%i", (void*) & (P.DoMassVacc), 1, 1, 0)) P.DoMassVacc = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Priority age range for mass vaccination", "%i", (void*)P.VaccPriorityGroupAge, 2, 1, 0)) { P.VaccPriorityGroupAge[0] = 1; P.VaccPriorityGroupAge[1] = 0; } + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Time to start geographic vaccination", + "%lf", (void *)&(P.VaccTimeStartGeo), 1, 1, 0)) + P.VaccTimeStartGeo = 1e10; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Vaccination radius", "%lf", + (void *)&(P.VaccRadius), 1, 1, 0)) + P.VaccRadius = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Minimum radius from case to vaccinate", + "%lf", (void *)&(P.VaccMinRadius), 1, 1, 0)) + P.VaccMinRadius = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Maximum number of vaccine courses available", "%lf", + (void *)&(P.VaccMaxCoursesBase), 1, 1, 0)) + P.VaccMaxCoursesBase = 1e20; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Start time of additional vaccine production", "%lf", + (void *)&(P.VaccNewCoursesStartTime), 1, 1, 0)) + P.VaccNewCoursesStartTime = USHRT_MAX / P.TimeStepsPerDay; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "End time of additional vaccine production", "%lf", + (void *)&(P.VaccNewCoursesEndTime), 1, 1, 0)) + P.VaccNewCoursesEndTime = USHRT_MAX / P.TimeStepsPerDay; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Rate of additional vaccine production (courses per day)", "%lf", + (void *)&(P.VaccNewCoursesRate), 1, 1, 0)) + P.VaccNewCoursesRate = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Apply mass rather than reactive vaccination", "%i", + (void *)&(P.DoMassVacc), 1, 1, 0)) + P.DoMassVacc = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Priority age range for mass vaccination", "%i", + (void *)P.VaccPriorityGroupAge, 2, 1, 0)) + { + P.VaccPriorityGroupAge[0] = 1; + P.VaccPriorityGroupAge[1] = 0; + } if (P.DoAdUnits) { - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Vaccinate administrative units rather than rings", "%i", (void*) & (P.VaccByAdminUnit), 1, 1, 0)) P.VaccByAdminUnit = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Administrative unit divisor for vaccination", "%i", (void*) & (P.VaccAdminUnitDivisor), 1, 1, 0)) P.VaccAdminUnitDivisor = 1; - if ((P.VaccAdminUnitDivisor == 0) || (P.VaccByAdminUnit == 0)) P.VaccAdminUnitDivisor = 1; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Vaccinate administrative units rather than rings", "%i", + (void *)&(P.VaccByAdminUnit), 1, 1, 0)) + P.VaccByAdminUnit = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Administrative unit divisor for vaccination", "%i", + (void *)&(P.VaccAdminUnitDivisor), 1, 1, 0)) + P.VaccAdminUnitDivisor = 1; + if ((P.VaccAdminUnitDivisor == 0) || (P.VaccByAdminUnit == 0)) + P.VaccAdminUnitDivisor = 1; } else { - P.VaccAdminUnitDivisor = 1; P.VaccByAdminUnit = 0; - } - - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Movement restrictions trigger incidence per cell", "%i", (void*) & (P.MoveRestrCellIncThresh), 1, 1, 0)) P.MoveRestrCellIncThresh = 1000000000; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Delay to start movement restrictions", "%lf", (void*) & (P.MoveDelayMean), 1, 1, 0)) P.MoveDelayMean = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Duration of movement restrictions", "%lf", (void*) & (P.MoveRestrDuration), 1, 1, 0)) P.MoveRestrDuration = 7; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Residual movements after restrictions", "%lf", (void*) & (P.MoveRestrEffect), 1, 1, 0)) P.MoveRestrEffect = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Minimum radius of movement restrictions", "%lf", (void*) & (P.MoveRestrRadius), 1, 1, 0)) P.MoveRestrRadius = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Movement restrictions start time", "%lf", (void*) & (P.MoveRestrTimeStartBase), 1, 1, 0)) P.MoveRestrTimeStartBase = USHRT_MAX / P.TimeStepsPerDay; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Impose blanket movement restrictions", "%i", (void*) & (P.DoBlanketMoveRestr), 1, 1, 0)) P.DoBlanketMoveRestr = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Movement restrictions only once", "%i", (void*) & (P.DoMoveRestrOnceOnly), 1, 1, 0)) P.DoMoveRestrOnceOnly = 0; - if (P.DoMoveRestrOnceOnly) P.DoMoveRestrOnceOnly = 4; + P.VaccAdminUnitDivisor = 1; + P.VaccByAdminUnit = 0; + } + + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Movement restrictions trigger incidence per cell", "%i", + (void *)&(P.MoveRestrCellIncThresh), 1, 1, 0)) + P.MoveRestrCellIncThresh = 1000000000; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Delay to start movement restrictions", + "%lf", (void *)&(P.MoveDelayMean), 1, 1, 0)) + P.MoveDelayMean = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Duration of movement restrictions", + "%lf", (void *)&(P.MoveRestrDuration), 1, 1, 0)) + P.MoveRestrDuration = 7; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Residual movements after restrictions", + "%lf", (void *)&(P.MoveRestrEffect), 1, 1, 0)) + P.MoveRestrEffect = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Minimum radius of movement restrictions", "%lf", + (void *)&(P.MoveRestrRadius), 1, 1, 0)) + P.MoveRestrRadius = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Movement restrictions start time", + "%lf", (void *)&(P.MoveRestrTimeStartBase), 1, 1, 0)) + P.MoveRestrTimeStartBase = USHRT_MAX / P.TimeStepsPerDay; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Impose blanket movement restrictions", + "%i", (void *)&(P.DoBlanketMoveRestr), 1, 1, 0)) + P.DoBlanketMoveRestr = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Movement restrictions only once", "%i", + (void *)&(P.DoMoveRestrOnceOnly), 1, 1, 0)) + P.DoMoveRestrOnceOnly = 0; + if (P.DoMoveRestrOnceOnly) + P.DoMoveRestrOnceOnly = 4; if (P.DoAdUnits) { - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Movement restrictions in administrative units rather than rings", "%i", (void*) & (P.MoveRestrByAdminUnit), 1, 1, 0)) P.MoveRestrByAdminUnit = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Administrative unit divisor for movement restrictions", "%i", (void*) & (P.MoveRestrAdminUnitDivisor), 1, 1, 0)) P.MoveRestrAdminUnitDivisor = 1; - if ((P.MoveRestrAdminUnitDivisor == 0) || (P.MoveRestrByAdminUnit == 0)) P.MoveRestrAdminUnitDivisor = 1; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Movement restrictions in administrative units rather than rings", "%i", + (void *)&(P.MoveRestrByAdminUnit), 1, 1, 0)) + P.MoveRestrByAdminUnit = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Administrative unit divisor for movement restrictions", "%i", + (void *)&(P.MoveRestrAdminUnitDivisor), 1, 1, 0)) + P.MoveRestrAdminUnitDivisor = 1; + if ((P.MoveRestrAdminUnitDivisor == 0) || (P.MoveRestrByAdminUnit == 0)) + P.MoveRestrAdminUnitDivisor = 1; } else { - P.MoveRestrAdminUnitDivisor = 1; P.MoveRestrByAdminUnit = 0; + P.MoveRestrAdminUnitDivisor = 1; + P.MoveRestrByAdminUnit = 0; } - //Intervention delays and durations by admin unit: ggilani 16/03/20 - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Include intervention delays by admin unit", "%i", (void*) & (P.DoInterventionDelaysByAdUnit), 1, 1, 0)) P.DoInterventionDelaysByAdUnit = 0; + // Intervention delays and durations by admin unit: ggilani 16/03/20 + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Include intervention delays by admin unit", "%i", + (void *)&(P.DoInterventionDelaysByAdUnit), 1, 1, 0)) + P.DoInterventionDelaysByAdUnit = 0; if (P.DoInterventionDelaysByAdUnit) { - //Set up arrays to temporarily store parameters per admin unit - double AdunitDelayToSocialDistance [MAX_ADUNITS]; - double AdunitDelayToHQuarantine [MAX_ADUNITS]; - double AdunitDelayToCaseIsolation [MAX_ADUNITS]; - double AdunitDelayToPlaceClose [MAX_ADUNITS]; - double AdunitDurationSocialDistance [MAX_ADUNITS]; - double AdunitDurationHQuarantine [MAX_ADUNITS]; - double AdunitDurationCaseIsolation [MAX_ADUNITS]; - double AdunitDurationPlaceClose [MAX_ADUNITS]; - - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Delay to social distancing by admin unit" , "%lf", (void*)AdunitDelayToSocialDistance , P.NumAdunits, 1, 0)) for (i = 0; i < P.NumAdunits; i++) AdunitDelayToSocialDistance [i] = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Delay to household quarantine by admin unit" , "%lf", (void*)AdunitDelayToHQuarantine , P.NumAdunits, 1, 0)) for (i = 0; i < P.NumAdunits; i++) AdunitDelayToHQuarantine [i] = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Delay to case isolation by admin unit" , "%lf", (void*)AdunitDelayToCaseIsolation , P.NumAdunits, 1, 0)) for (i = 0; i < P.NumAdunits; i++) AdunitDelayToCaseIsolation [i] = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Delay to place closure by admin unit" , "%lf", (void*)AdunitDelayToPlaceClose , P.NumAdunits, 1, 0)) for (i = 0; i < P.NumAdunits; i++) AdunitDelayToPlaceClose [i] = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Duration of social distancing by admin unit" , "%lf", (void*)AdunitDurationSocialDistance, P.NumAdunits, 1, 0)) for (i = 0; i < P.NumAdunits; i++) AdunitDurationSocialDistance [i] = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Duration of household quarantine by admin unit" , "%lf", (void*)AdunitDurationHQuarantine , P.NumAdunits, 1, 0)) for (i = 0; i < P.NumAdunits; i++) AdunitDurationHQuarantine [i] = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Duration of case isolation by admin unit" , "%lf", (void*)AdunitDurationCaseIsolation , P.NumAdunits, 1, 0)) for (i = 0; i < P.NumAdunits; i++) AdunitDurationCaseIsolation [i] = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Duration of place closure by admin unit" , "%lf", (void*)AdunitDurationPlaceClose , P.NumAdunits, 1, 0)) for (i = 0; i < P.NumAdunits; i++) AdunitDurationPlaceClose [i] = 0; + // Set up arrays to temporarily store parameters per admin unit + double AdunitDelayToSocialDistance[MAX_ADUNITS]; + double AdunitDelayToHQuarantine[MAX_ADUNITS]; + double AdunitDelayToCaseIsolation[MAX_ADUNITS]; + double AdunitDelayToPlaceClose[MAX_ADUNITS]; + double AdunitDurationSocialDistance[MAX_ADUNITS]; + double AdunitDurationHQuarantine[MAX_ADUNITS]; + double AdunitDurationCaseIsolation[MAX_ADUNITS]; + double AdunitDurationPlaceClose[MAX_ADUNITS]; + + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Delay to social distancing by admin unit", "%lf", + (void *)AdunitDelayToSocialDistance, P.NumAdunits, 1, 0)) + for (i = 0; i < P.NumAdunits; i++) + AdunitDelayToSocialDistance[i] = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Delay to household quarantine by admin unit", "%lf", + (void *)AdunitDelayToHQuarantine, P.NumAdunits, 1, 0)) + for (i = 0; i < P.NumAdunits; i++) + AdunitDelayToHQuarantine[i] = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Delay to case isolation by admin unit", "%lf", + (void *)AdunitDelayToCaseIsolation, P.NumAdunits, 1, 0)) + for (i = 0; i < P.NumAdunits; i++) + AdunitDelayToCaseIsolation[i] = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Delay to place closure by admin unit", + "%lf", (void *)AdunitDelayToPlaceClose, P.NumAdunits, 1, 0)) + for (i = 0; i < P.NumAdunits; i++) + AdunitDelayToPlaceClose[i] = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Duration of social distancing by admin unit", "%lf", + (void *)AdunitDurationSocialDistance, P.NumAdunits, 1, 0)) + for (i = 0; i < P.NumAdunits; i++) + AdunitDurationSocialDistance[i] = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Duration of household quarantine by admin unit", "%lf", + (void *)AdunitDurationHQuarantine, P.NumAdunits, 1, 0)) + for (i = 0; i < P.NumAdunits; i++) + AdunitDurationHQuarantine[i] = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Duration of case isolation by admin unit", "%lf", + (void *)AdunitDurationCaseIsolation, P.NumAdunits, 1, 0)) + for (i = 0; i < P.NumAdunits; i++) + AdunitDurationCaseIsolation[i] = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Duration of place closure by admin unit", "%lf", + (void *)AdunitDurationPlaceClose, P.NumAdunits, 1, 0)) + for (i = 0; i < P.NumAdunits; i++) + AdunitDurationPlaceClose[i] = 0; for (i = 0; i < P.NumAdunits; i++) { - AdUnits[i].SocialDistanceDelay = AdunitDelayToSocialDistance [i]; - AdUnits[i].SocialDistanceDuration = AdunitDurationSocialDistance [i]; - AdUnits[i].HQuarantineDelay = AdunitDelayToHQuarantine [i]; - AdUnits[i].HQuarantineDuration = AdunitDurationHQuarantine [i]; - AdUnits[i].CaseIsolationDelay = AdunitDelayToCaseIsolation [i]; - AdUnits[i].CaseIsolationPolicyDuration = AdunitDurationCaseIsolation [i]; - AdUnits[i].PlaceCloseDelay = AdunitDelayToPlaceClose [i]; - AdUnits[i].PlaceCloseDuration = AdunitDurationPlaceClose [i]; + AdUnits[i].SocialDistanceDelay = AdunitDelayToSocialDistance[i]; + AdUnits[i].SocialDistanceDuration = AdunitDurationSocialDistance[i]; + AdUnits[i].HQuarantineDelay = AdunitDelayToHQuarantine[i]; + AdUnits[i].HQuarantineDuration = AdunitDurationHQuarantine[i]; + AdUnits[i].CaseIsolationDelay = AdunitDelayToCaseIsolation[i]; + AdUnits[i].CaseIsolationPolicyDuration = AdunitDurationCaseIsolation[i]; + AdUnits[i].PlaceCloseDelay = AdunitDelayToPlaceClose[i]; + AdUnits[i].PlaceCloseDuration = AdunitDurationPlaceClose[i]; } } - ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** + ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** + //////// **** ///// **** ///// **** ///// **** DIGITAL CONTACT TRACING - ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** + ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** + //////// **** ///// **** ///// **** - //New code for digital contact tracing - ggilani: 09/03/20 - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Include digital contact tracing", "%i", (void*) & (P.DoDigitalContactTracing), 1, 1, 0)) P.DoDigitalContactTracing = 0; + // New code for digital contact tracing - ggilani: 09/03/20 + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Include digital contact tracing", "%i", + (void *)&(P.DoDigitalContactTracing), 1, 1, 0)) + P.DoDigitalContactTracing = 0; if (P.DoDigitalContactTracing) { - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Digital contact tracing trigger incidence per cell", "%lf", (void*) & (P.DigitalContactTracing_CellIncThresh), 1, 1, 0)) P.DigitalContactTracing_CellIncThresh = 1000000000; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Digital contact tracing trigger incidence per cell", "%lf", + (void *)&(P.DigitalContactTracing_CellIncThresh), 1, 1, 0)) + P.DigitalContactTracing_CellIncThresh = 1000000000; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Proportion of population or households covered by digital contact tracing", "%lf", (void*) & (P.PropPopUsingDigitalContactTracing), 1, 1, 0)) P.PropPopUsingDigitalContactTracing = 1; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Proportion of smartphone users by age", "%lf", (void*)P.ProportionSmartphoneUsersByAge, NUM_AGE_GROUPS, 1, 0)) + if (!GetInputParameter2( + ParamFile_dat, PreParamFile_dat, + "Proportion of population or households covered by digital contact tracing", "%lf", + (void *)&(P.PropPopUsingDigitalContactTracing), 1, 1, 0)) + P.PropPopUsingDigitalContactTracing = 1; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Proportion of smartphone users by age", "%lf", + (void *)P.ProportionSmartphoneUsersByAge, NUM_AGE_GROUPS, 1, 0)) { for (i = 0; i < NUM_AGE_GROUPS; i++) { @@ -1454,219 +2269,493 @@ void ReadParams(char* ParamFile, char* PreParamFile) } if (P.DoPlaces) { - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Cluster digital app clusters by household", "%i", (void*) & (P.ClusterDigitalContactUsers), 1, 1, 0)) P.ClusterDigitalContactUsers = 0; // by default, don't cluster by location + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Cluster digital app clusters by household", "%i", + (void *)&(P.ClusterDigitalContactUsers), 1, 1, 0)) + P.ClusterDigitalContactUsers = 0; // by default, don't cluster by location } else { P.ClusterDigitalContactUsers = 0; } - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Proportion of digital contacts who self-isolate", "%lf", (void*) & (P.ProportionDigitalContactsIsolate), 1, 1, 0)) P.ProportionDigitalContactsIsolate = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Maximum number of contacts to trace per index case", "%i", (void*)&(P.MaxDigitalContactsToTrace), 1, 1, 0)) P.MaxDigitalContactsToTrace = MAX_CONTACTS; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Delay between isolation of index case and contacts", "%lf", (void*) & (P.DigitalContactTracingDelay), 1, 1, 0)) P.DigitalContactTracingDelay = P.TimeStep; - //we really need one timestep between to make sure contact is not processed before index - if (P.DigitalContactTracingDelay == 0) P.DigitalContactTracingDelay = P.TimeStep; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Length of self-isolation for digital contacts", "%lf", (void*) & (P.LengthDigitalContactIsolation), 1, 1, 0)) P.LengthDigitalContactIsolation = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Spatial scaling factor - digital contact tracing", "%lf", (void*) & (P.ScalingFactorSpatialDigitalContacts), 1, 1, 0)) P.ScalingFactorSpatialDigitalContacts = 1; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Place scaling factor - digital contact tracing", "%lf", (void*)&(P.ScalingFactorPlaceDigitalContacts), 1, 1, 0)) P.ScalingFactorPlaceDigitalContacts = 1; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Digital contact tracing start time", "%lf", (void*) & (P.DigitalContactTracingTimeStartBase), 1, 1, 0)) P.DigitalContactTracingTimeStartBase = USHRT_MAX / P.TimeStepsPerDay; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Duration of digital contact tracing policy", "%lf", (void*) & (P.DigitalContactTracingPolicyDuration), 1, 1, 0)) P.DigitalContactTracingPolicyDuration = 7; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Output digital contact tracing", "%i", (void*) & (P.OutputDigitalContactTracing), 1, 1, 0)) P.OutputDigitalContactTracing = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Output digital contact distribution", "%i", (void*)&(P.OutputDigitalContactDist), 1, 1, 0)) P.OutputDigitalContactDist = 0; - - //if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Include household contacts in digital contact tracing", "%i", (void*) & (P.IncludeHouseholdDigitalContactTracing), 1, 1, 0)) P.IncludeHouseholdDigitalContactTracing = 1; - //if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Include place group contacts in digital contact tracing", "%i", (void*) & (P.IncludePlaceGroupDigitalContactTracing), 1, 1, 0)) P.IncludePlaceGroupDigitalContactTracing = 1; - - //added admin unit specific delays by admin unit + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Proportion of digital contacts who self-isolate", "%lf", + (void *)&(P.ProportionDigitalContactsIsolate), 1, 1, 0)) + P.ProportionDigitalContactsIsolate = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Maximum number of contacts to trace per index case", "%i", + (void *)&(P.MaxDigitalContactsToTrace), 1, 1, 0)) + P.MaxDigitalContactsToTrace = MAX_CONTACTS; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Delay between isolation of index case and contacts", "%lf", + (void *)&(P.DigitalContactTracingDelay), 1, 1, 0)) + P.DigitalContactTracingDelay = P.TimeStep; + // we really need one timestep between to make sure contact is not processed before index + if (P.DigitalContactTracingDelay == 0) + P.DigitalContactTracingDelay = P.TimeStep; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Length of self-isolation for digital contacts", "%lf", + (void *)&(P.LengthDigitalContactIsolation), 1, 1, 0)) + P.LengthDigitalContactIsolation = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Spatial scaling factor - digital contact tracing", "%lf", + (void *)&(P.ScalingFactorSpatialDigitalContacts), 1, 1, 0)) + P.ScalingFactorSpatialDigitalContacts = 1; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Place scaling factor - digital contact tracing", "%lf", + (void *)&(P.ScalingFactorPlaceDigitalContacts), 1, 1, 0)) + P.ScalingFactorPlaceDigitalContacts = 1; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Digital contact tracing start time", + "%lf", (void *)&(P.DigitalContactTracingTimeStartBase), 1, 1, 0)) + P.DigitalContactTracingTimeStartBase = USHRT_MAX / P.TimeStepsPerDay; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Duration of digital contact tracing policy", "%lf", + (void *)&(P.DigitalContactTracingPolicyDuration), 1, 1, 0)) + P.DigitalContactTracingPolicyDuration = 7; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Output digital contact tracing", "%i", + (void *)&(P.OutputDigitalContactTracing), 1, 1, 0)) + P.OutputDigitalContactTracing = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Output digital contact distribution", + "%i", (void *)&(P.OutputDigitalContactDist), 1, 1, 0)) + P.OutputDigitalContactDist = 0; + + // if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Include household contacts in + // digital contact tracing", "%i", (void*) & (P.IncludeHouseholdDigitalContactTracing), 1, 1, + // 0)) P.IncludeHouseholdDigitalContactTracing = 1; if (!GetInputParameter2(ParamFile_dat, + // PreParamFile_dat, "Include place group contacts in digital contact tracing", "%i", (void*) & + // (P.IncludePlaceGroupDigitalContactTracing), 1, 1, 0)) + // P.IncludePlaceGroupDigitalContactTracing = 1; + + // added admin unit specific delays by admin unit if (P.DoInterventionDelaysByAdUnit) { double AdunitDelayToDCT[MAX_ADUNITS]; double AdunitDurationDCT[MAX_ADUNITS]; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Delay to digital contact tracing by admin unit", "%lf", (void*)AdunitDelayToDCT, P.NumAdunits, 1, 0)) for (i = 0; i < P.NumAdunits; i++) AdunitDelayToDCT[i] = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Duration of digital contact tracing by admin unit", "%lf", (void*)AdunitDurationDCT, P.NumAdunits, 1, 0)) for (i = 0; i < P.NumAdunits; i++) AdunitDurationDCT[i] = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Delay to digital contact tracing by admin unit", "%lf", + (void *)AdunitDelayToDCT, P.NumAdunits, 1, 0)) + for (i = 0; i < P.NumAdunits; i++) + AdunitDelayToDCT[i] = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Duration of digital contact tracing by admin unit", "%lf", + (void *)AdunitDurationDCT, P.NumAdunits, 1, 0)) + for (i = 0; i < P.NumAdunits; i++) + AdunitDurationDCT[i] = 0; for (i = 0; i < P.NumAdunits; i++) { AdUnits[i].DCTDelay = AdunitDelayToDCT[i]; AdUnits[i].DCTDuration = AdunitDurationDCT[i]; } } - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Isolate index cases in digital contact tracing", "%i", (void*)&(P.DCTIsolateIndexCases), 1, 1, 0)) P.DCTIsolateIndexCases = 1; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Residual contacts after digital contact tracing isolation", "%lf", (void*)&(P.DCTCaseIsolationEffectiveness), 1, 1, 0)) P.DCTCaseIsolationEffectiveness = P.CaseIsolationEffectiveness; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Residual household contacts after digital contact tracing isolation", "%lf", (void*)&(P.DCTCaseIsolationHouseEffectiveness), 1, 1, 0)) P.DCTCaseIsolationHouseEffectiveness = P.CaseIsolationHouseEffectiveness; - //initialise total number of users to 0 + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Isolate index cases in digital contact tracing", "%i", + (void *)&(P.DCTIsolateIndexCases), 1, 1, 0)) + P.DCTIsolateIndexCases = 1; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Residual contacts after digital contact tracing isolation", "%lf", + (void *)&(P.DCTCaseIsolationEffectiveness), 1, 1, 0)) + P.DCTCaseIsolationEffectiveness = P.CaseIsolationEffectiveness; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Residual household contacts after digital contact tracing isolation", + "%lf", (void *)&(P.DCTCaseIsolationHouseEffectiveness), 1, 1, 0)) + P.DCTCaseIsolationHouseEffectiveness = P.CaseIsolationHouseEffectiveness; + // initialise total number of users to 0 P.NDigitalContactUsers = 0; P.NDigitalHouseholdUsers = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Delay between symptom onset and isolation for index case", "%lf", (void*)&(P.DelayFromIndexCaseDetectionToDCTIsolation), 1, 1, 0)) P.DelayFromIndexCaseDetectionToDCTIsolation = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Test index cases and contacts", "%i", (void*)&(P.DoDCTTest), 1, 1, 0)) P.DoDCTTest = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Delay to test index case", "%lf", (void*)&(P.DelayToTestIndexCase), 1, 1, 0)) P.DelayToTestIndexCase = 1; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Delay to test DCT contacts", "%lf", (void*)&(P.DelayToTestDCTContacts), 1, 1, 0)) P.DelayToTestDCTContacts = 7; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Testing specificity - DCT", "%lf", (void*)&(P.SpecificityDCT), 1, 1, 0)) P.SpecificityDCT = 1; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Testing sensitivity - DCT", "%lf", (void*)&(P.SensitivityDCT), 1, 1, 0)) P.SensitivityDCT = 1; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Find contacts of digital contacts", "%i", (void*)&(P.FindContactsOfDCTContacts), 1, 1, 0)) P.FindContactsOfDCTContacts = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Remove contacts of a negative index case", "%i", (void*)&(P.RemoveContactsOfNegativeIndexCase), 1, 1, 0)) P.RemoveContactsOfNegativeIndexCase = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Delay between symptom onset and isolation for index case", "%lf", + (void *)&(P.DelayFromIndexCaseDetectionToDCTIsolation), 1, 1, 0)) + P.DelayFromIndexCaseDetectionToDCTIsolation = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Test index cases and contacts", "%i", + (void *)&(P.DoDCTTest), 1, 1, 0)) + P.DoDCTTest = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Delay to test index case", "%lf", + (void *)&(P.DelayToTestIndexCase), 1, 1, 0)) + P.DelayToTestIndexCase = 1; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Delay to test DCT contacts", "%lf", + (void *)&(P.DelayToTestDCTContacts), 1, 1, 0)) + P.DelayToTestDCTContacts = 7; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Testing specificity - DCT", "%lf", + (void *)&(P.SpecificityDCT), 1, 1, 0)) + P.SpecificityDCT = 1; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Testing sensitivity - DCT", "%lf", + (void *)&(P.SensitivityDCT), 1, 1, 0)) + P.SensitivityDCT = 1; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Find contacts of digital contacts", + "%i", (void *)&(P.FindContactsOfDCTContacts), 1, 1, 0)) + P.FindContactsOfDCTContacts = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Remove contacts of a negative index case", "%i", + (void *)&(P.RemoveContactsOfNegativeIndexCase), 1, 1, 0)) + P.RemoveContactsOfNegativeIndexCase = 0; } else { - //Set these to 1 so it doesn't interfere with code if we aren't using digital contact tracing. + // Set these to 1 so it doesn't interfere with code if we aren't using digital contact tracing. P.ScalingFactorSpatialDigitalContacts = 1; P.ScalingFactorPlaceDigitalContacts = 1; } - ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** + ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** + //////// **** ///// **** ///// **** ///// **** PLACE CLOSURE - ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** - - - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Trigger incidence per cell for place closure", "%i", (void*) & (P.PlaceCloseCellIncThresh1), 1, 1, 0)) P.PlaceCloseCellIncThresh1 = 1000000000; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Trigger incidence per cell for second place closure", "%i", (void*)&(P.PlaceCloseCellIncThresh2), 1, 1, 0)) P.PlaceCloseCellIncThresh2 = 1000000000; - if (P.PlaceCloseCellIncThresh1 < 0) P.PlaceCloseCellIncThresh1 = 1000000000; - if (P.PlaceCloseCellIncThresh2 < 0) P.PlaceCloseCellIncThresh2 = 1000000000; - if(!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Trigger incidence per cell for end of place closure", "%i", (void*) & (P.PlaceCloseCellIncStopThresh), 1, 1, 0)) P.PlaceCloseCellIncStopThresh = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Delay to start place closure", "%lf", (void*) & (P.PlaceCloseDelayMean), 1, 1, 0)) P.PlaceCloseDelayMean = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Duration of place closure", "%lf", (void*) & (P.PlaceCloseDurationBase), 1, 1, 0)) P.PlaceCloseDurationBase = 7; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Duration of second place closure", "%lf", (void*) & (P.PlaceCloseDuration2), 1, 1, 0)) P.PlaceCloseDuration2 = 7; + ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** + //////// **** ///// **** ///// **** + + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Trigger incidence per cell for place closure", "%i", + (void *)&(P.PlaceCloseCellIncThresh1), 1, 1, 0)) + P.PlaceCloseCellIncThresh1 = 1000000000; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Trigger incidence per cell for second place closure", "%i", + (void *)&(P.PlaceCloseCellIncThresh2), 1, 1, 0)) + P.PlaceCloseCellIncThresh2 = 1000000000; + if (P.PlaceCloseCellIncThresh1 < 0) + P.PlaceCloseCellIncThresh1 = 1000000000; + if (P.PlaceCloseCellIncThresh2 < 0) + P.PlaceCloseCellIncThresh2 = 1000000000; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Trigger incidence per cell for end of place closure", "%i", + (void *)&(P.PlaceCloseCellIncStopThresh), 1, 1, 0)) + P.PlaceCloseCellIncStopThresh = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Delay to start place closure", "%lf", + (void *)&(P.PlaceCloseDelayMean), 1, 1, 0)) + P.PlaceCloseDelayMean = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Duration of place closure", "%lf", + (void *)&(P.PlaceCloseDurationBase), 1, 1, 0)) + P.PlaceCloseDurationBase = 7; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Duration of second place closure", + "%lf", (void *)&(P.PlaceCloseDuration2), 1, 1, 0)) + P.PlaceCloseDuration2 = 7; if (P.DoPlaces) { - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Proportion of places remaining open after closure by place type", "%lf", (void*)P.PlaceCloseEffect, P.PlaceTypeNum, 1, 0)) - for (i = 0; i < NUM_PLACE_TYPES; i++) P.PlaceCloseEffect[i] = 1; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Proportional attendance after closure by place type", "%lf", (void*)P.PlaceClosePropAttending, P.PlaceTypeNum, 1, 0)) - for (i = 0; i < NUM_PLACE_TYPES; i++) P.PlaceClosePropAttending[i] = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Proportion of places remaining open after closure by place type", + "%lf", (void *)P.PlaceCloseEffect, P.PlaceTypeNum, 1, 0)) + for (i = 0; i < NUM_PLACE_TYPES; i++) + P.PlaceCloseEffect[i] = 1; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Proportional attendance after closure by place type", "%lf", + (void *)P.PlaceClosePropAttending, P.PlaceTypeNum, 1, 0)) + for (i = 0; i < NUM_PLACE_TYPES; i++) + P.PlaceClosePropAttending[i] = 0; } if (P.DoHouseholds) - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Relative household contact rate after closure", "%lf", (void*)& P.PlaceCloseHouseholdRelContact, 1, 1, 0)) P.PlaceCloseHouseholdRelContact = 1; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Relative spatial contact rate after closure", "%lf", (void*)& P.PlaceCloseSpatialRelContact, 1, 1, 0)) P.PlaceCloseSpatialRelContact = 1; - - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Include holidays", "%i", (void*) & (P.DoHolidays), 1, 1, 0)) P.DoHolidays = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Relative household contact rate after closure", "%lf", + (void *)&P.PlaceCloseHouseholdRelContact, 1, 1, 0)) + P.PlaceCloseHouseholdRelContact = 1; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Relative spatial contact rate after closure", "%lf", + (void *)&P.PlaceCloseSpatialRelContact, 1, 1, 0)) + P.PlaceCloseSpatialRelContact = 1; + + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Include holidays", "%i", + (void *)&(P.DoHolidays), 1, 1, 0)) + P.DoHolidays = 0; if (P.DoHolidays) { - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Proportion of places remaining open during holidays by place type", "%lf", (void*)P.HolidayEffect, P.PlaceTypeNum, 1, 0)) - for (i = 0; i < NUM_PLACE_TYPES; i++) P.HolidayEffect[i] = 1; - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Number of holidays", "%i", (void*) & (P.NumHolidays), 1, 1, 0)) P.NumHolidays = 0; - if (P.NumHolidays > DAYS_PER_YEAR) P.NumHolidays = DAYS_PER_YEAR; + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, + "Proportion of places remaining open during holidays by place type", + "%lf", (void *)P.HolidayEffect, P.PlaceTypeNum, 1, 0)) + for (i = 0; i < NUM_PLACE_TYPES; i++) + P.HolidayEffect[i] = 1; + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Number of holidays", "%i", + (void *)&(P.NumHolidays), 1, 1, 0)) + P.NumHolidays = 0; + if (P.NumHolidays > DAYS_PER_YEAR) + P.NumHolidays = DAYS_PER_YEAR; if (P.NumHolidays > 0) { - GetInputParameter(PreParamFile_dat, AdminFile_dat, "Holiday start times", "%lf", (void*)P.HolidayStartTime, P.NumHolidays, 1, 0); - GetInputParameter(PreParamFile_dat, AdminFile_dat, "Holiday durations", "%lf", (void*)P.HolidayDuration, P.NumHolidays, 1, 0); + GetInputParameter(PreParamFile_dat, AdminFile_dat, "Holiday start times", "%lf", + (void *)P.HolidayStartTime, P.NumHolidays, 1, 0); + GetInputParameter(PreParamFile_dat, AdminFile_dat, "Holiday durations", "%lf", + (void *)P.HolidayDuration, P.NumHolidays, 1, 0); } } else P.NumHolidays = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Minimum radius for place closure", "%lf", (void*) & (P.PlaceCloseRadius), 1, 1, 0)) P.PlaceCloseRadius = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Place closure start time", "%lf", (void*) & (P.PlaceCloseTimeStartBase), 1, 1, 0)) P.PlaceCloseTimeStartBase = USHRT_MAX / P.TimeStepsPerDay; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Place closure second start time", "%lf", (void*) & (P.PlaceCloseTimeStartBase2), 1, 1, 0)) P.PlaceCloseTimeStartBase2 = USHRT_MAX / P.TimeStepsPerDay; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Places close only once", "%i", (void*) & (P.DoPlaceCloseOnceOnly), 1, 1, 0)) P.DoPlaceCloseOnceOnly = 0; - if (P.DoPlaceCloseOnceOnly) P.DoPlaceCloseOnceOnly = 4; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Place closure incidence threshold", "%i", (void*) & (P.PlaceCloseIncTrig1), 1, 1, 0)) P.PlaceCloseIncTrig1 = 1; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Place closure second incidence threshold", "%i", (void*)&(P.PlaceCloseIncTrig2), 1, 1, 0)) P.PlaceCloseIncTrig2 = P.PlaceCloseIncTrig1; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Place closure fractional incidence threshold", "%lf", (void*) & (P.PlaceCloseFracIncTrig), 1, 1, 0)) P.PlaceCloseFracIncTrig = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Minimum radius for place closure", + "%lf", (void *)&(P.PlaceCloseRadius), 1, 1, 0)) + P.PlaceCloseRadius = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Place closure start time", "%lf", + (void *)&(P.PlaceCloseTimeStartBase), 1, 1, 0)) + P.PlaceCloseTimeStartBase = USHRT_MAX / P.TimeStepsPerDay; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Place closure second start time", "%lf", + (void *)&(P.PlaceCloseTimeStartBase2), 1, 1, 0)) + P.PlaceCloseTimeStartBase2 = USHRT_MAX / P.TimeStepsPerDay; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Places close only once", "%i", + (void *)&(P.DoPlaceCloseOnceOnly), 1, 1, 0)) + P.DoPlaceCloseOnceOnly = 0; + if (P.DoPlaceCloseOnceOnly) + P.DoPlaceCloseOnceOnly = 4; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Place closure incidence threshold", + "%i", (void *)&(P.PlaceCloseIncTrig1), 1, 1, 0)) + P.PlaceCloseIncTrig1 = 1; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Place closure second incidence threshold", "%i", + (void *)&(P.PlaceCloseIncTrig2), 1, 1, 0)) + P.PlaceCloseIncTrig2 = P.PlaceCloseIncTrig1; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Place closure fractional incidence threshold", "%lf", + (void *)&(P.PlaceCloseFracIncTrig), 1, 1, 0)) + P.PlaceCloseFracIncTrig = 0; if ((P.DoAdUnits) && (P.DoPlaces)) { - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Place closure in administrative units rather than rings", "%i", (void*) & (P.PlaceCloseByAdminUnit), 1, 1, 0)) P.PlaceCloseByAdminUnit = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Administrative unit divisor for place closure", "%i", (void*) & (P.PlaceCloseAdminUnitDivisor), 1, 1, 0)) P.PlaceCloseAdminUnitDivisor = 1; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Place types to close for admin unit closure (0/1 array)", "%i", (void*) & (P.PlaceCloseAdunitPlaceTypes), P.PlaceTypeNum, 1, 0)) - for (i = 0; i < P.PlaceTypeNum; i++) P.PlaceCloseAdunitPlaceTypes[i] = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Cumulative proportion of place members needing to become sick for admin unit closure", "%lf", (void*) & (P.PlaceCloseCasePropThresh), 1, 1, 0)) P.PlaceCloseCasePropThresh = 2; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Proportion of places in admin unit needing to pass threshold for place closure", "%lf", (void*) & (P.PlaceCloseAdunitPropThresh), 1, 1, 0)) P.PlaceCloseAdunitPropThresh = 2; - if ((P.PlaceCloseAdminUnitDivisor < 1) || (P.PlaceCloseByAdminUnit == 0)) P.PlaceCloseAdminUnitDivisor = 1; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Place closure in administrative units rather than rings", "%i", + (void *)&(P.PlaceCloseByAdminUnit), 1, 1, 0)) + P.PlaceCloseByAdminUnit = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Administrative unit divisor for place closure", "%i", + (void *)&(P.PlaceCloseAdminUnitDivisor), 1, 1, 0)) + P.PlaceCloseAdminUnitDivisor = 1; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Place types to close for admin unit closure (0/1 array)", "%i", + (void *)&(P.PlaceCloseAdunitPlaceTypes), P.PlaceTypeNum, 1, 0)) + for (i = 0; i < P.PlaceTypeNum; i++) + P.PlaceCloseAdunitPlaceTypes[i] = 0; + if (!GetInputParameter2( + ParamFile_dat, PreParamFile_dat, + "Cumulative proportion of place members needing to become sick for admin unit closure", + "%lf", (void *)&(P.PlaceCloseCasePropThresh), 1, 1, 0)) + P.PlaceCloseCasePropThresh = 2; + if (!GetInputParameter2( + ParamFile_dat, PreParamFile_dat, + "Proportion of places in admin unit needing to pass threshold for place closure", "%lf", + (void *)&(P.PlaceCloseAdunitPropThresh), 1, 1, 0)) + P.PlaceCloseAdunitPropThresh = 2; + if ((P.PlaceCloseAdminUnitDivisor < 1) || (P.PlaceCloseByAdminUnit == 0)) + P.PlaceCloseAdminUnitDivisor = 1; } else { - P.PlaceCloseAdminUnitDivisor = 1; P.PlaceCloseByAdminUnit = 0; + P.PlaceCloseAdminUnitDivisor = 1; + P.PlaceCloseByAdminUnit = 0; } - ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** + ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** + //////// **** ///// **** ///// **** ///// **** SOCIAL DISTANCING - ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** - - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Trigger incidence per cell for social distancing", "%i", (void*) & (P.SocDistCellIncThresh), 1, 1, 0)) P.SocDistCellIncThresh = 1000000000; - if(!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Trigger incidence per cell for end of social distancing", "%i", (void*) & (P.SocDistCellIncStopThresh), 1, 1, 0)) P.SocDistCellIncStopThresh = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Duration of social distancing", "%lf", (void*) & (P.SocDistDuration), 1, 1, 0)) P.SocDistDuration = 7; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Duration of social distancing after change", "%lf", (void*) & (P.SocDistDuration2), 1, 1, 0)) P.SocDistDuration2 = 7; + ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** + //////// **** ///// **** ///// **** + + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Trigger incidence per cell for social distancing", "%i", + (void *)&(P.SocDistCellIncThresh), 1, 1, 0)) + P.SocDistCellIncThresh = 1000000000; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Trigger incidence per cell for end of social distancing", "%i", + (void *)&(P.SocDistCellIncStopThresh), 1, 1, 0)) + P.SocDistCellIncStopThresh = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Duration of social distancing", "%lf", + (void *)&(P.SocDistDuration), 1, 1, 0)) + P.SocDistDuration = 7; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Duration of social distancing after change", "%lf", + (void *)&(P.SocDistDuration2), 1, 1, 0)) + P.SocDistDuration2 = 7; if (P.DoPlaces) { - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Relative place contact rate given social distancing by place type", "%lf", (void*)P.SocDistPlaceEffect, P.PlaceTypeNum, 1, 0)) - for (i = 0; i < NUM_PLACE_TYPES; i++) P.SocDistPlaceEffect[i] = 1; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Relative place contact rate given enhanced social distancing by place type", "%lf", (void*)P.EnhancedSocDistPlaceEffect, P.PlaceTypeNum, 1, 0)) - for (i = 0; i < NUM_PLACE_TYPES; i++) P.EnhancedSocDistPlaceEffect[i] = 1; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Relative place contact rate given social distancing by place type after change", "%lf", (void*)P.SocDistPlaceEffect2, P.PlaceTypeNum, 1, 0)) - for (i = 0; i < NUM_PLACE_TYPES; i++) P.SocDistPlaceEffect2[i] = P.SocDistPlaceEffect[i]; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Relative place contact rate given enhanced social distancing by place type after change", "%lf", (void*)P.EnhancedSocDistPlaceEffect2, P.PlaceTypeNum, 1, 0)) - for (i = 0; i < NUM_PLACE_TYPES; i++) P.EnhancedSocDistPlaceEffect2[i] = P.EnhancedSocDistPlaceEffect[i]; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Relative place contact rate given social distancing by place type", + "%lf", (void *)P.SocDistPlaceEffect, P.PlaceTypeNum, 1, 0)) + for (i = 0; i < NUM_PLACE_TYPES; i++) + P.SocDistPlaceEffect[i] = 1; + if (!GetInputParameter2( + ParamFile_dat, PreParamFile_dat, + "Relative place contact rate given enhanced social distancing by place type", "%lf", + (void *)P.EnhancedSocDistPlaceEffect, P.PlaceTypeNum, 1, 0)) + for (i = 0; i < NUM_PLACE_TYPES; i++) + P.EnhancedSocDistPlaceEffect[i] = 1; + if (!GetInputParameter2( + ParamFile_dat, PreParamFile_dat, + "Relative place contact rate given social distancing by place type after change", "%lf", + (void *)P.SocDistPlaceEffect2, P.PlaceTypeNum, 1, 0)) + for (i = 0; i < NUM_PLACE_TYPES; i++) + P.SocDistPlaceEffect2[i] = P.SocDistPlaceEffect[i]; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Relative place contact rate given enhanced social distancing by place " + "type after change", + "%lf", (void *)P.EnhancedSocDistPlaceEffect2, P.PlaceTypeNum, 1, 0)) + for (i = 0; i < NUM_PLACE_TYPES; i++) + P.EnhancedSocDistPlaceEffect2[i] = P.EnhancedSocDistPlaceEffect[i]; } if (P.DoHouseholds) { - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Relative household contact rate given social distancing", "%lf", (void*)&P.SocDistHouseholdEffect, 1, 1, 0)) P.SocDistHouseholdEffect = 1; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Relative household contact rate given enhanced social distancing", "%lf", (void*)&P.EnhancedSocDistHouseholdEffect, 1, 1, 0)) P.EnhancedSocDistHouseholdEffect = 1; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Relative household contact rate given social distancing after change", "%lf", (void*)&P.SocDistHouseholdEffect2, 1, 1, 0)) P.SocDistHouseholdEffect2 = P.SocDistHouseholdEffect; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Relative household contact rate given enhanced social distancing after change", "%lf", (void*)&P.EnhancedSocDistHouseholdEffect2, 1, 1, 0)) P.EnhancedSocDistHouseholdEffect2 = P.EnhancedSocDistHouseholdEffect; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Cluster compliance with enhanced social distancing by household", "%i", (void*)&P.EnhancedSocDistClusterByHousehold, 1, 1, 0)) P.EnhancedSocDistClusterByHousehold = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Relative household contact rate given social distancing", "%lf", + (void *)&P.SocDistHouseholdEffect, 1, 1, 0)) + P.SocDistHouseholdEffect = 1; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Relative household contact rate given enhanced social distancing", + "%lf", (void *)&P.EnhancedSocDistHouseholdEffect, 1, 1, 0)) + P.EnhancedSocDistHouseholdEffect = 1; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Relative household contact rate given social distancing after change", + "%lf", (void *)&P.SocDistHouseholdEffect2, 1, 1, 0)) + P.SocDistHouseholdEffect2 = P.SocDistHouseholdEffect; + if (!GetInputParameter2( + ParamFile_dat, PreParamFile_dat, + "Relative household contact rate given enhanced social distancing after change", "%lf", + (void *)&P.EnhancedSocDistHouseholdEffect2, 1, 1, 0)) + P.EnhancedSocDistHouseholdEffect2 = P.EnhancedSocDistHouseholdEffect; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Cluster compliance with enhanced social distancing by household", "%i", + (void *)&P.EnhancedSocDistClusterByHousehold, 1, 1, 0)) + P.EnhancedSocDistClusterByHousehold = 0; } else P.EnhancedSocDistClusterByHousehold = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Relative spatial contact rate given social distancing", "%lf", (void*)& P.SocDistSpatialEffect, 1, 1, 0)) P.SocDistSpatialEffect = 1; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Relative spatial contact rate given social distancing after change", "%lf", (void*)&P.SocDistSpatialEffect2, 1, 1, 0)) P.SocDistSpatialEffect2 = P.SocDistSpatialEffect; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Minimum radius for social distancing", "%lf", (void*) & (P.SocDistRadius), 1, 1, 0)) P.SocDistRadius = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Social distancing start time", "%lf", (void*) & (P.SocDistTimeStartBase), 1, 1, 0)) P.SocDistTimeStartBase = USHRT_MAX / P.TimeStepsPerDay; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Delay for change in effectiveness of social distancing", "%lf", (void*)&(P.SocDistChangeDelay), 1, 1, 0)) P.SocDistChangeDelay = USHRT_MAX / P.TimeStepsPerDay; - if(!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Proportion compliant with enhanced social distancing by age group", "%lf", (void*)P.EnhancedSocDistProportionCompliant, NUM_AGE_GROUPS, 1, 0)) - { - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Proportion compliant with enhanced social distancing", "%lf", (void*)&t, 1, 1, 0)) t = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Relative spatial contact rate given social distancing", "%lf", + (void *)&P.SocDistSpatialEffect, 1, 1, 0)) + P.SocDistSpatialEffect = 1; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Relative spatial contact rate given social distancing after change", + "%lf", (void *)&P.SocDistSpatialEffect2, 1, 1, 0)) + P.SocDistSpatialEffect2 = P.SocDistSpatialEffect; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Minimum radius for social distancing", + "%lf", (void *)&(P.SocDistRadius), 1, 1, 0)) + P.SocDistRadius = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Social distancing start time", "%lf", + (void *)&(P.SocDistTimeStartBase), 1, 1, 0)) + P.SocDistTimeStartBase = USHRT_MAX / P.TimeStepsPerDay; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Delay for change in effectiveness of social distancing", "%lf", + (void *)&(P.SocDistChangeDelay), 1, 1, 0)) + P.SocDistChangeDelay = USHRT_MAX / P.TimeStepsPerDay; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Proportion compliant with enhanced social distancing by age group", + "%lf", (void *)P.EnhancedSocDistProportionCompliant, NUM_AGE_GROUPS, 1, + 0)) + { + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Proportion compliant with enhanced social distancing", "%lf", + (void *)&t, 1, 1, 0)) + t = 0; for (i = 0; i < NUM_AGE_GROUPS; i++) P.EnhancedSocDistProportionCompliant[i] = t; } - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Relative spatial contact rate given enhanced social distancing", "%lf", (void*)& P.EnhancedSocDistSpatialEffect, 1, 1, 0)) P.EnhancedSocDistSpatialEffect = 1; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Relative spatial contact rate given enhanced social distancing after change", "%lf", (void*)&P.EnhancedSocDistSpatialEffect2, 1, 1, 0)) P.EnhancedSocDistSpatialEffect2 = P.EnhancedSocDistSpatialEffect; - - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Social distancing only once", "%i", (void*) & (P.DoSocDistOnceOnly), 1, 1, 0)) P.DoSocDistOnceOnly = 0; - if (P.DoSocDistOnceOnly) P.DoSocDistOnceOnly = 4; - - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Airport closure effectiveness", "%lf", (void*) & (P.AirportCloseEffectiveness), 1, 1, 0)) P.AirportCloseEffectiveness = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Relative spatial contact rate given enhanced social distancing", "%lf", + (void *)&P.EnhancedSocDistSpatialEffect, 1, 1, 0)) + P.EnhancedSocDistSpatialEffect = 1; + if (!GetInputParameter2( + ParamFile_dat, PreParamFile_dat, + "Relative spatial contact rate given enhanced social distancing after change", "%lf", + (void *)&P.EnhancedSocDistSpatialEffect2, 1, 1, 0)) + P.EnhancedSocDistSpatialEffect2 = P.EnhancedSocDistSpatialEffect; + + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Social distancing only once", "%i", + (void *)&(P.DoSocDistOnceOnly), 1, 1, 0)) + P.DoSocDistOnceOnly = 0; + if (P.DoSocDistOnceOnly) + P.DoSocDistOnceOnly = 4; + + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Airport closure effectiveness", "%lf", + (void *)&(P.AirportCloseEffectiveness), 1, 1, 0)) + P.AirportCloseEffectiveness = 0; P.AirportCloseEffectiveness = 1.0 - P.AirportCloseEffectiveness; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Airport closure start time", "%lf", (void*) & (P.AirportCloseTimeStartBase), 1, 1, 0)) P.AirportCloseTimeStartBase = USHRT_MAX / P.TimeStepsPerDay; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Airport closure duration", "%lf", (void*) & (P.AirportCloseDuration), 1, 1, 0)) P.AirportCloseDuration = USHRT_MAX / P.TimeStepsPerDay; - - ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Airport closure start time", "%lf", + (void *)&(P.AirportCloseTimeStartBase), 1, 1, 0)) + P.AirportCloseTimeStartBase = USHRT_MAX / P.TimeStepsPerDay; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Airport closure duration", "%lf", + (void *)&(P.AirportCloseDuration), 1, 1, 0)) + P.AirportCloseDuration = USHRT_MAX / P.TimeStepsPerDay; + + ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** + //////// **** ///// **** ///// **** ///// **** HOUSEHOLD QUARANTINE - ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** + ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** + //////// **** ///// **** ///// **** if (P.DoHouseholds) { - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Retrigger household quarantine with each new case in quarantine window", "%i", (void*) & (P.DoHQretrigger), 1, 1, 0)) P.DoHQretrigger =0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Household quarantine start time", "%lf", (void*) & (P.HQuarantineTimeStartBase), 1, 1, 0)) P.HQuarantineTimeStartBase = USHRT_MAX / P.TimeStepsPerDay; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Delay to start household quarantine", "%lf", (void*) & (P.HQuarantineDelay), 1, 1, 0)) P.HQuarantineDelay = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Length of time households are quarantined", "%lf", (void*) & (P.HQuarantineHouseDuration), 1, 1, 0)) P.HQuarantineHouseDuration = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Duration of household quarantine policy", "%lf", (void*) & (P.HQuarantinePolicyDuration), 1, 1, 0)) P.HQuarantinePolicyDuration = USHRT_MAX / P.TimeStepsPerDay; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Relative household contact rate after quarantine", "%lf", (void*) & (P.HQuarantineHouseEffect), 1, 1, 0)) P.HQuarantineHouseEffect = 1; + if (!GetInputParameter2( + ParamFile_dat, PreParamFile_dat, + "Retrigger household quarantine with each new case in quarantine window", "%i", + (void *)&(P.DoHQretrigger), 1, 1, 0)) + P.DoHQretrigger = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Household quarantine start time", + "%lf", (void *)&(P.HQuarantineTimeStartBase), 1, 1, 0)) + P.HQuarantineTimeStartBase = USHRT_MAX / P.TimeStepsPerDay; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Delay to start household quarantine", + "%lf", (void *)&(P.HQuarantineDelay), 1, 1, 0)) + P.HQuarantineDelay = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Length of time households are quarantined", "%lf", + (void *)&(P.HQuarantineHouseDuration), 1, 1, 0)) + P.HQuarantineHouseDuration = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Duration of household quarantine policy", "%lf", + (void *)&(P.HQuarantinePolicyDuration), 1, 1, 0)) + P.HQuarantinePolicyDuration = USHRT_MAX / P.TimeStepsPerDay; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Relative household contact rate after quarantine", "%lf", + (void *)&(P.HQuarantineHouseEffect), 1, 1, 0)) + P.HQuarantineHouseEffect = 1; if (P.DoPlaces) { - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Residual place contacts after household quarantine by place type", "%lf", (void*)P.HQuarantinePlaceEffect, P.PlaceTypeNum, 1, 0)) - for (i = 0; i < NUM_PLACE_TYPES; i++) P.HQuarantinePlaceEffect[i] = 1; - } - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Residual spatial contacts after household quarantine", "%lf", (void*) & (P.HQuarantineSpatialEffect), 1, 1, 0)) P.HQuarantineSpatialEffect = 1; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Household level compliance with quarantine", "%lf", (void*) & (P.HQuarantinePropHouseCompliant), 1, 1, 0)) P.HQuarantinePropHouseCompliant = 1; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Individual level compliance with quarantine", "%lf", (void*) & (P.HQuarantinePropIndivCompliant), 1, 1, 0)) P.HQuarantinePropIndivCompliant = 1; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Residual place contacts after household quarantine by place type", + "%lf", (void *)P.HQuarantinePlaceEffect, P.PlaceTypeNum, 1, 0)) + for (i = 0; i < NUM_PLACE_TYPES; i++) + P.HQuarantinePlaceEffect[i] = 1; + } + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Residual spatial contacts after household quarantine", "%lf", + (void *)&(P.HQuarantineSpatialEffect), 1, 1, 0)) + P.HQuarantineSpatialEffect = 1; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Household level compliance with quarantine", "%lf", + (void *)&(P.HQuarantinePropHouseCompliant), 1, 1, 0)) + P.HQuarantinePropHouseCompliant = 1; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Individual level compliance with quarantine", "%lf", + (void *)&(P.HQuarantinePropIndivCompliant), 1, 1, 0)) + P.HQuarantinePropIndivCompliant = 1; } else P.HQuarantineTimeStartBase = 1e10; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Case isolation start time", "%lf", (void*) & (P.CaseIsolationTimeStartBase), 1, 1, 0)) P.CaseIsolationTimeStartBase = USHRT_MAX / P.TimeStepsPerDay; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Proportion of detected cases isolated", "%lf", (void*) & (P.CaseIsolationProp), 1, 1, 0)) P.CaseIsolationProp = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Delay to start case isolation", "%lf", (void*) & (P.CaseIsolationDelay), 1, 1, 0)) P.CaseIsolationDelay = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Duration of case isolation", "%lf", (void*) & (P.CaseIsolationDuration), 1, 1, 0)) P.CaseIsolationDuration = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Duration of case isolation policy", "%lf", (void*) & (P.CaseIsolationPolicyDuration), 1, 1, 0)) P.CaseIsolationPolicyDuration = 1e10; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Residual contacts after case isolation", "%lf", (void*) & (P.CaseIsolationEffectiveness), 1, 1, 0)) P.CaseIsolationEffectiveness = 1; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Case isolation start time", "%lf", + (void *)&(P.CaseIsolationTimeStartBase), 1, 1, 0)) + P.CaseIsolationTimeStartBase = USHRT_MAX / P.TimeStepsPerDay; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Proportion of detected cases isolated", + "%lf", (void *)&(P.CaseIsolationProp), 1, 1, 0)) + P.CaseIsolationProp = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Delay to start case isolation", "%lf", + (void *)&(P.CaseIsolationDelay), 1, 1, 0)) + P.CaseIsolationDelay = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Duration of case isolation", "%lf", + (void *)&(P.CaseIsolationDuration), 1, 1, 0)) + P.CaseIsolationDuration = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Duration of case isolation policy", + "%lf", (void *)&(P.CaseIsolationPolicyDuration), 1, 1, 0)) + P.CaseIsolationPolicyDuration = 1e10; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Residual contacts after case isolation", + "%lf", (void *)&(P.CaseIsolationEffectiveness), 1, 1, 0)) + P.CaseIsolationEffectiveness = 1; if (P.DoHouseholds) { - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Residual household contacts after case isolation", "%lf", (void*) & (P.CaseIsolationHouseEffectiveness), 1, 1, 0)) + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Residual household contacts after case isolation", "%lf", + (void *)&(P.CaseIsolationHouseEffectiveness), 1, 1, 0)) P.CaseIsolationHouseEffectiveness = P.CaseIsolationEffectiveness; } - ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** + ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** + //////// **** ///// **** ///// **** ///// **** VARIABLE EFFICACIES OVER TIME - ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** + ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** + //////// **** ///// **** ///// **** - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Vary efficacies over time", "%i", (void*) & (P.VaryEfficaciesOverTime), 1, 1, 0)) P.VaryEfficaciesOverTime = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Vary efficacies over time", "%i", + (void *)&(P.VaryEfficaciesOverTime), 1, 1, 0)) + P.VaryEfficaciesOverTime = 0; //// **** number of change times if (!P.VaryEfficaciesOverTime) { @@ -1678,280 +2767,494 @@ void ReadParams(char* ParamFile, char* PreParamFile) } else { - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Number of change times for levels of social distancing" , "%i", (void*) & (P.Num_SD_ChangeTimes) , 1, 1, 0)) P.Num_SD_ChangeTimes = 1; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Number of change times for levels of case isolation" , "%i", (void*) & (P.Num_CI_ChangeTimes) , 1, 1, 0)) P.Num_CI_ChangeTimes = 1; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Number of change times for levels of household quarantine" , "%i", (void*) & (P.Num_HQ_ChangeTimes) , 1, 1, 0)) P.Num_HQ_ChangeTimes = 1; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Number of change times for levels of place closure" , "%i", (void*) & (P.Num_PC_ChangeTimes) , 1, 1, 0)) P.Num_PC_ChangeTimes = 1; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Number of change times for levels of digital contact tracing" , "%i", (void*) & (P.Num_DCT_ChangeTimes) , 1, 1, 0)) P.Num_DCT_ChangeTimes = 1; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Number of change times for levels of social distancing", "%i", + (void *)&(P.Num_SD_ChangeTimes), 1, 1, 0)) + P.Num_SD_ChangeTimes = 1; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Number of change times for levels of case isolation", "%i", + (void *)&(P.Num_CI_ChangeTimes), 1, 1, 0)) + P.Num_CI_ChangeTimes = 1; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Number of change times for levels of household quarantine", "%i", + (void *)&(P.Num_HQ_ChangeTimes), 1, 1, 0)) + P.Num_HQ_ChangeTimes = 1; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Number of change times for levels of place closure", "%i", + (void *)&(P.Num_PC_ChangeTimes), 1, 1, 0)) + P.Num_PC_ChangeTimes = 1; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Number of change times for levels of digital contact tracing", "%i", + (void *)&(P.Num_DCT_ChangeTimes), 1, 1, 0)) + P.Num_DCT_ChangeTimes = 1; } //// **** change times: - //// By default, initialize first change time to zero and all subsequent change times to occur after simulation time, i.e. single value of efficacy for social distancing. - P.SD_ChangeTimes [0] = 0; - P.CI_ChangeTimes [0] = 0; - P.HQ_ChangeTimes [0] = 0; - P.PC_ChangeTimes [0] = 0; - P.DCT_ChangeTimes [0] = 0; + //// By default, initialize first change time to zero and all subsequent change times to occur + /// after simulation time, i.e. single value of efficacy for social distancing. + P.SD_ChangeTimes[0] = 0; + P.CI_ChangeTimes[0] = 0; + P.HQ_ChangeTimes[0] = 0; + P.PC_ChangeTimes[0] = 0; + P.DCT_ChangeTimes[0] = 0; for (int ChangeTime = 1; ChangeTime < MAX_NUM_INTERVENTION_CHANGE_TIMES; ChangeTime++) { - P.SD_ChangeTimes [ChangeTime] = 1e10; - P.CI_ChangeTimes [ChangeTime] = 1e10; - P.HQ_ChangeTimes [ChangeTime] = 1e10; - P.PC_ChangeTimes [ChangeTime] = 1e10; - P.DCT_ChangeTimes [ChangeTime] = 1e10; + P.SD_ChangeTimes[ChangeTime] = 1e10; + P.CI_ChangeTimes[ChangeTime] = 1e10; + P.HQ_ChangeTimes[ChangeTime] = 1e10; + P.PC_ChangeTimes[ChangeTime] = 1e10; + P.DCT_ChangeTimes[ChangeTime] = 1e10; } //// Get real values from (pre)param file - GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Change times for levels of social distancing" , "%lf", (void*)P.SD_ChangeTimes , P.Num_SD_ChangeTimes , 1, 0); - GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Change times for levels of case isolation" , "%lf", (void*)P.CI_ChangeTimes , P.Num_CI_ChangeTimes , 1, 0); - GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Change times for levels of household quarantine" , "%lf", (void*)P.HQ_ChangeTimes , P.Num_HQ_ChangeTimes , 1, 0); - GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Change times for levels of place closure" , "%lf", (void*)P.PC_ChangeTimes , P.Num_PC_ChangeTimes , 1, 0); - GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Change times for levels of digital contact tracing", "%lf", (void*)P.DCT_ChangeTimes, P.Num_DCT_ChangeTimes , 1, 0); + GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Change times for levels of social distancing", "%lf", + (void *)P.SD_ChangeTimes, P.Num_SD_ChangeTimes, 1, 0); + GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Change times for levels of case isolation", + "%lf", (void *)P.CI_ChangeTimes, P.Num_CI_ChangeTimes, 1, 0); + GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Change times for levels of household quarantine", "%lf", + (void *)P.HQ_ChangeTimes, P.Num_HQ_ChangeTimes, 1, 0); + GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Change times for levels of place closure", + "%lf", (void *)P.PC_ChangeTimes, P.Num_PC_ChangeTimes, 1, 0); + GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Change times for levels of digital contact tracing", "%lf", + (void *)P.DCT_ChangeTimes, P.Num_DCT_ChangeTimes, 1, 0); // initialize to zero (regardless of whether doing places or households). for (int ChangeTime = 0; ChangeTime < MAX_NUM_INTERVENTION_CHANGE_TIMES; ChangeTime++) { //// **** "efficacies" //// spatial - P.SD_SpatialEffects_OverTime [ChangeTime] = 0; - P.Enhanced_SD_SpatialEffects_OverTime [ChangeTime] = 0; - P.CI_SpatialAndPlaceEffects_OverTime [ChangeTime] = 0; - P.HQ_SpatialEffects_OverTime [ChangeTime] = 0; - P.PC_SpatialEffects_OverTime [ChangeTime] = 0; - P.DCT_SpatialAndPlaceEffects_OverTime [ChangeTime] = 0; + P.SD_SpatialEffects_OverTime[ChangeTime] = 0; + P.Enhanced_SD_SpatialEffects_OverTime[ChangeTime] = 0; + P.CI_SpatialAndPlaceEffects_OverTime[ChangeTime] = 0; + P.HQ_SpatialEffects_OverTime[ChangeTime] = 0; + P.PC_SpatialEffects_OverTime[ChangeTime] = 0; + P.DCT_SpatialAndPlaceEffects_OverTime[ChangeTime] = 0; //// Household - P.SD_HouseholdEffects_OverTime [ChangeTime] = 0; - P.Enhanced_SD_HouseholdEffects_OverTime [ChangeTime] = 0; - P.CI_HouseholdEffects_OverTime [ChangeTime] = 0; - P.HQ_HouseholdEffects_OverTime [ChangeTime] = 0; - P.PC_HouseholdEffects_OverTime [ChangeTime] = 0; - P.DCT_HouseholdEffects_OverTime [ChangeTime] = 0; + P.SD_HouseholdEffects_OverTime[ChangeTime] = 0; + P.Enhanced_SD_HouseholdEffects_OverTime[ChangeTime] = 0; + P.CI_HouseholdEffects_OverTime[ChangeTime] = 0; + P.HQ_HouseholdEffects_OverTime[ChangeTime] = 0; + P.PC_HouseholdEffects_OverTime[ChangeTime] = 0; + P.DCT_HouseholdEffects_OverTime[ChangeTime] = 0; //// place for (int PlaceType = 0; PlaceType < P.PlaceTypeNum; PlaceType++) { - P.SD_PlaceEffects_OverTime [ChangeTime][PlaceType] = 0; - P.Enhanced_SD_PlaceEffects_OverTime [ChangeTime][PlaceType] = 0; - P.HQ_PlaceEffects_OverTime [ChangeTime][PlaceType] = 0; - P.PC_PlaceEffects_OverTime [ChangeTime][PlaceType] = 0; + P.SD_PlaceEffects_OverTime[ChangeTime][PlaceType] = 0; + P.Enhanced_SD_PlaceEffects_OverTime[ChangeTime][PlaceType] = 0; + P.HQ_PlaceEffects_OverTime[ChangeTime][PlaceType] = 0; + P.PC_PlaceEffects_OverTime[ChangeTime][PlaceType] = 0; } P.PC_Durs_OverTime[ChangeTime] = 0; //// **** compliance - P.CI_Prop_OverTime [ChangeTime] = 0; - P.HQ_Individual_PropComply_OverTime [ChangeTime] = 0; - P.HQ_Household_PropComply_OverTime [ChangeTime] = 0; - P.DCT_Prop_OverTime [ChangeTime] = 0; + P.CI_Prop_OverTime[ChangeTime] = 0; + P.HQ_Individual_PropComply_OverTime[ChangeTime] = 0; + P.HQ_Household_PropComply_OverTime[ChangeTime] = 0; + P.DCT_Prop_OverTime[ChangeTime] = 0; } - //// **** "efficacies": by default, initialize to values read in previously. ///// spatial contact rates rates over time (and place too for CI and DCT) //// soc dist - if (!P.VaryEfficaciesOverTime || !GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Relative spatial contact rates over time given social distancing" , "%lf", (void*)P.SD_SpatialEffects_OverTime, P.Num_SD_ChangeTimes, 1, 0)) - for (int ChangeTime = 0; ChangeTime < P.Num_SD_ChangeTimes; ChangeTime++) P.SD_SpatialEffects_OverTime[ChangeTime] = P.SocDistSpatialEffect; //// by default, initialize to Relative spatial contact rate given social distancing + if (!P.VaryEfficaciesOverTime || + !GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Relative spatial contact rates over time given social distancing", "%lf", + (void *)P.SD_SpatialEffects_OverTime, P.Num_SD_ChangeTimes, 1, 0)) + for (int ChangeTime = 0; ChangeTime < P.Num_SD_ChangeTimes; ChangeTime++) + P.SD_SpatialEffects_OverTime[ChangeTime] = + P.SocDistSpatialEffect; //// by default, initialize to Relative spatial contact rate given + /// social distancing //// enhanced soc dist - if (!P.VaryEfficaciesOverTime || !GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Relative spatial contact rates over time given enhanced social distancing" , "%lf", (void*)P.Enhanced_SD_SpatialEffects_OverTime, P.Num_SD_ChangeTimes, 1, 0)) - for (int ChangeTime = 0; ChangeTime < P.Num_SD_ChangeTimes; ChangeTime++) P.Enhanced_SD_SpatialEffects_OverTime[ChangeTime] = P.EnhancedSocDistSpatialEffect; //// by default, initialize to Relative spatial contact rate given enhanced social distancing + if (!P.VaryEfficaciesOverTime || + !GetInputParameter2( + ParamFile_dat, PreParamFile_dat, + "Relative spatial contact rates over time given enhanced social distancing", "%lf", + (void *)P.Enhanced_SD_SpatialEffects_OverTime, P.Num_SD_ChangeTimes, 1, 0)) + for (int ChangeTime = 0; ChangeTime < P.Num_SD_ChangeTimes; ChangeTime++) + P.Enhanced_SD_SpatialEffects_OverTime[ChangeTime] = + P.EnhancedSocDistSpatialEffect; //// by default, initialize to Relative spatial contact + /// rate given enhanced social distancing //// case isolation - if (!P.VaryEfficaciesOverTime || !GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Residual contacts after case isolation over time" , "%lf", (void*)P.CI_SpatialAndPlaceEffects_OverTime, P.Num_CI_ChangeTimes, 1, 0)) - for (int ChangeTime = 0; ChangeTime < P.Num_CI_ChangeTimes; ChangeTime++) P.CI_SpatialAndPlaceEffects_OverTime[ChangeTime] = P.CaseIsolationEffectiveness; + if (!P.VaryEfficaciesOverTime || + !GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Residual contacts after case isolation over time", "%lf", + (void *)P.CI_SpatialAndPlaceEffects_OverTime, P.Num_CI_ChangeTimes, 1, 0)) + for (int ChangeTime = 0; ChangeTime < P.Num_CI_ChangeTimes; ChangeTime++) + P.CI_SpatialAndPlaceEffects_OverTime[ChangeTime] = P.CaseIsolationEffectiveness; //// household quarantine - if (!P.VaryEfficaciesOverTime || !GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Residual spatial contacts over time after household quarantine" , "%lf", (void*)P.HQ_SpatialEffects_OverTime, P.Num_HQ_ChangeTimes, 1, 0)) - for (int ChangeTime = 0; ChangeTime < P.Num_HQ_ChangeTimes; ChangeTime++) P.HQ_SpatialEffects_OverTime[ChangeTime] = P.HQuarantineSpatialEffect; + if (!P.VaryEfficaciesOverTime || + !GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Residual spatial contacts over time after household quarantine", "%lf", + (void *)P.HQ_SpatialEffects_OverTime, P.Num_HQ_ChangeTimes, 1, 0)) + for (int ChangeTime = 0; ChangeTime < P.Num_HQ_ChangeTimes; ChangeTime++) + P.HQ_SpatialEffects_OverTime[ChangeTime] = P.HQuarantineSpatialEffect; //// place closure - if (!P.VaryEfficaciesOverTime || !GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Relative spatial contact rates over time after place closure" , "%lf", (void*)P.PC_SpatialEffects_OverTime, P.Num_PC_ChangeTimes, 1, 0)) - for (int ChangeTime = 0; ChangeTime < P.Num_PC_ChangeTimes; ChangeTime++) P.PC_SpatialEffects_OverTime[ChangeTime] = P.PlaceCloseSpatialRelContact; + if (!P.VaryEfficaciesOverTime || + !GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Relative spatial contact rates over time after place closure", "%lf", + (void *)P.PC_SpatialEffects_OverTime, P.Num_PC_ChangeTimes, 1, 0)) + for (int ChangeTime = 0; ChangeTime < P.Num_PC_ChangeTimes; ChangeTime++) + P.PC_SpatialEffects_OverTime[ChangeTime] = P.PlaceCloseSpatialRelContact; //// digital contact tracing - if (!P.VaryEfficaciesOverTime || !GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Residual contacts after digital contact tracing isolation over time" , "%lf", (void*)P.DCT_SpatialAndPlaceEffects_OverTime, P.Num_DCT_ChangeTimes, 1, 0)) - for (int ChangeTime = 0; ChangeTime < P.Num_DCT_ChangeTimes; ChangeTime++) P.DCT_SpatialAndPlaceEffects_OverTime[ChangeTime] = P.DCTCaseIsolationEffectiveness; + if (!P.VaryEfficaciesOverTime || + !GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Residual contacts after digital contact tracing isolation over time", + "%lf", (void *)P.DCT_SpatialAndPlaceEffects_OverTime, + P.Num_DCT_ChangeTimes, 1, 0)) + for (int ChangeTime = 0; ChangeTime < P.Num_DCT_ChangeTimes; ChangeTime++) + P.DCT_SpatialAndPlaceEffects_OverTime[ChangeTime] = P.DCTCaseIsolationEffectiveness; ///// Household contact rates over time if (P.DoHouseholds) { //// soc dist - if (!P.VaryEfficaciesOverTime || !GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Relative household contact rates over time given social distancing" , "%lf", (void*)P.SD_HouseholdEffects_OverTime, P.Num_SD_ChangeTimes, 1, 0)) - for (int ChangeTime = 0; ChangeTime < P.Num_SD_ChangeTimes; ChangeTime++) P.SD_HouseholdEffects_OverTime[ChangeTime] = P.SocDistHouseholdEffect; + if (!P.VaryEfficaciesOverTime || + !GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Relative household contact rates over time given social distancing", + "%lf", (void *)P.SD_HouseholdEffects_OverTime, P.Num_SD_ChangeTimes, 1, + 0)) + for (int ChangeTime = 0; ChangeTime < P.Num_SD_ChangeTimes; ChangeTime++) + P.SD_HouseholdEffects_OverTime[ChangeTime] = P.SocDistHouseholdEffect; //// enhanced soc dist - if (!P.VaryEfficaciesOverTime || !GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Relative household contact rates over time given enhanced social distancing" , "%lf", (void*)P.Enhanced_SD_HouseholdEffects_OverTime, P.Num_SD_ChangeTimes, 1, 0)) - for (int ChangeTime = 0; ChangeTime < P.Num_SD_ChangeTimes; ChangeTime++) P.Enhanced_SD_HouseholdEffects_OverTime[ChangeTime] = P.EnhancedSocDistHouseholdEffect; + if (!P.VaryEfficaciesOverTime || + !GetInputParameter2( + ParamFile_dat, PreParamFile_dat, + "Relative household contact rates over time given enhanced social distancing", "%lf", + (void *)P.Enhanced_SD_HouseholdEffects_OverTime, P.Num_SD_ChangeTimes, 1, 0)) + for (int ChangeTime = 0; ChangeTime < P.Num_SD_ChangeTimes; ChangeTime++) + P.Enhanced_SD_HouseholdEffects_OverTime[ChangeTime] = P.EnhancedSocDistHouseholdEffect; //// case isolation - if (!P.VaryEfficaciesOverTime || !GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Residual household contacts after case isolation over time" , "%lf", (void*)P.CI_HouseholdEffects_OverTime, P.Num_CI_ChangeTimes, 1, 0)) - for (int ChangeTime = 0; ChangeTime < P.Num_CI_ChangeTimes; ChangeTime++) P.CI_HouseholdEffects_OverTime[ChangeTime] = P.CaseIsolationHouseEffectiveness; + if (!P.VaryEfficaciesOverTime || + !GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Residual household contacts after case isolation over time", "%lf", + (void *)P.CI_HouseholdEffects_OverTime, P.Num_CI_ChangeTimes, 1, 0)) + for (int ChangeTime = 0; ChangeTime < P.Num_CI_ChangeTimes; ChangeTime++) + P.CI_HouseholdEffects_OverTime[ChangeTime] = P.CaseIsolationHouseEffectiveness; //// household quarantine - if (!P.VaryEfficaciesOverTime || !GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Relative household contact rates over time after quarantine" , "%lf", (void*)P.HQ_HouseholdEffects_OverTime, P.Num_HQ_ChangeTimes, 1, 0)) - for (int ChangeTime = 0; ChangeTime < P.Num_HQ_ChangeTimes; ChangeTime++) P.HQ_HouseholdEffects_OverTime[ChangeTime] = P.HQuarantineHouseEffect; + if (!P.VaryEfficaciesOverTime || + !GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Relative household contact rates over time after quarantine", "%lf", + (void *)P.HQ_HouseholdEffects_OverTime, P.Num_HQ_ChangeTimes, 1, 0)) + for (int ChangeTime = 0; ChangeTime < P.Num_HQ_ChangeTimes; ChangeTime++) + P.HQ_HouseholdEffects_OverTime[ChangeTime] = P.HQuarantineHouseEffect; //// place closure - if (!P.VaryEfficaciesOverTime || !GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Relative household contact rates over time after place closure" , "%lf", (void*)P.PC_HouseholdEffects_OverTime, P.Num_PC_ChangeTimes, 1, 0)) - for (int ChangeTime = 0; ChangeTime < P.Num_PC_ChangeTimes; ChangeTime++) P.PC_HouseholdEffects_OverTime[ChangeTime] = P.PlaceCloseHouseholdRelContact; + if (!P.VaryEfficaciesOverTime || + !GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Relative household contact rates over time after place closure", "%lf", + (void *)P.PC_HouseholdEffects_OverTime, P.Num_PC_ChangeTimes, 1, 0)) + for (int ChangeTime = 0; ChangeTime < P.Num_PC_ChangeTimes; ChangeTime++) + P.PC_HouseholdEffects_OverTime[ChangeTime] = P.PlaceCloseHouseholdRelContact; //// digital contact tracing - if (!P.VaryEfficaciesOverTime || !GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Residual household contacts after digital contact tracing isolation over time", "%lf", (void*)P.DCT_HouseholdEffects_OverTime, P.Num_DCT_ChangeTimes, 1, 0)) - for (int ChangeTime = 0; ChangeTime < P.Num_DCT_ChangeTimes; ChangeTime++) P.DCT_HouseholdEffects_OverTime[ChangeTime] = P.DCTCaseIsolationHouseEffectiveness; + if (!P.VaryEfficaciesOverTime || + !GetInputParameter2( + ParamFile_dat, PreParamFile_dat, + "Residual household contacts after digital contact tracing isolation over time", "%lf", + (void *)P.DCT_HouseholdEffects_OverTime, P.Num_DCT_ChangeTimes, 1, 0)) + for (int ChangeTime = 0; ChangeTime < P.Num_DCT_ChangeTimes; ChangeTime++) + P.DCT_HouseholdEffects_OverTime[ChangeTime] = P.DCTCaseIsolationHouseEffectiveness; } ///// place contact rates over time if (P.DoPlaces) { //// soc dist - if (!P.VaryEfficaciesOverTime || !GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Relative place contact rates over time given social distancing by place type", "%lf", (void*) &P.SD_PlaceEffects_OverTime[0][0], P.Num_SD_ChangeTimes * P.PlaceTypeNum, 1, 0)) - for (int ChangeTime = 0; ChangeTime < P.Num_SD_ChangeTimes; ChangeTime++) //// by default populate to values of P.SocDistPlaceEffect + if (!P.VaryEfficaciesOverTime || + !GetInputParameter2( + ParamFile_dat, PreParamFile_dat, + "Relative place contact rates over time given social distancing by place type", "%lf", + (void *)&P.SD_PlaceEffects_OverTime[0][0], P.Num_SD_ChangeTimes * P.PlaceTypeNum, 1, 0)) + for (int ChangeTime = 0; ChangeTime < P.Num_SD_ChangeTimes; + ChangeTime++) //// by default populate to values of P.SocDistPlaceEffect for (int PlaceType = 0; PlaceType < P.PlaceTypeNum; PlaceType++) P.SD_PlaceEffects_OverTime[ChangeTime][PlaceType] = P.SocDistPlaceEffect[PlaceType]; //// enhanced soc dist - if (!P.VaryEfficaciesOverTime || !GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Relative place contact rates over time given enhanced social distancing by place type", "%lf", (void*) &P.Enhanced_SD_PlaceEffects_OverTime[0][0], P.Num_SD_ChangeTimes * P.PlaceTypeNum, 1, 0)) - for (int ChangeTime = 0; ChangeTime < P.Num_SD_ChangeTimes; ChangeTime++) //// by default populate to values of P.EnhancedSocDistPlaceEffect + if (!P.VaryEfficaciesOverTime || + !GetInputParameter2( + ParamFile_dat, PreParamFile_dat, + "Relative place contact rates over time given enhanced social distancing by place type", + "%lf", (void *)&P.Enhanced_SD_PlaceEffects_OverTime[0][0], + P.Num_SD_ChangeTimes * P.PlaceTypeNum, 1, 0)) + for (int ChangeTime = 0; ChangeTime < P.Num_SD_ChangeTimes; + ChangeTime++) //// by default populate to values of P.EnhancedSocDistPlaceEffect for (int PlaceType = 0; PlaceType < P.PlaceTypeNum; PlaceType++) - P.Enhanced_SD_PlaceEffects_OverTime[ChangeTime][PlaceType] = P.EnhancedSocDistPlaceEffect[PlaceType]; + P.Enhanced_SD_PlaceEffects_OverTime[ChangeTime][PlaceType] = + P.EnhancedSocDistPlaceEffect[PlaceType]; //// household quarantine - if (!P.VaryEfficaciesOverTime || !GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Residual place contacts over time after household quarantine by place type", "%lf", (void*) &P.HQ_PlaceEffects_OverTime[0][0], P.Num_HQ_ChangeTimes * P.PlaceTypeNum, 1, 0)) - for (int ChangeTime = 0; ChangeTime < P.Num_HQ_ChangeTimes; ChangeTime++) //// by default populate to values of P.HQuarantinePlaceEffect + if (!P.VaryEfficaciesOverTime || + !GetInputParameter2( + ParamFile_dat, PreParamFile_dat, + "Residual place contacts over time after household quarantine by place type", "%lf", + (void *)&P.HQ_PlaceEffects_OverTime[0][0], P.Num_HQ_ChangeTimes * P.PlaceTypeNum, 1, 0)) + for (int ChangeTime = 0; ChangeTime < P.Num_HQ_ChangeTimes; + ChangeTime++) //// by default populate to values of P.HQuarantinePlaceEffect for (int PlaceType = 0; PlaceType < P.PlaceTypeNum; PlaceType++) P.HQ_PlaceEffects_OverTime[ChangeTime][PlaceType] = P.HQuarantinePlaceEffect[PlaceType]; //// place closure - if (!P.VaryEfficaciesOverTime || !GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Proportion of places remaining open after closure by place type over time", "%lf", (void*) &P.PC_PlaceEffects_OverTime[0][0], P.Num_PC_ChangeTimes * P.PlaceTypeNum, 1, 0)) - for (int ChangeTime = 0; ChangeTime < P.Num_PC_ChangeTimes; ChangeTime++) //// by default populate to values of P.PlaceCloseEffect + if (!P.VaryEfficaciesOverTime || + !GetInputParameter2( + ParamFile_dat, PreParamFile_dat, + "Proportion of places remaining open after closure by place type over time", "%lf", + (void *)&P.PC_PlaceEffects_OverTime[0][0], P.Num_PC_ChangeTimes * P.PlaceTypeNum, 1, 0)) + for (int ChangeTime = 0; ChangeTime < P.Num_PC_ChangeTimes; + ChangeTime++) //// by default populate to values of P.PlaceCloseEffect for (int PlaceType = 0; PlaceType < P.PlaceTypeNum; PlaceType++) P.PC_PlaceEffects_OverTime[ChangeTime][PlaceType] = P.PlaceCloseEffect[PlaceType]; - if (!P.VaryEfficaciesOverTime || !GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Proportional attendance after closure by place type over time", "%lf", (void*) &P.PC_PropAttending_OverTime[0][0], P.Num_PC_ChangeTimes * P.PlaceTypeNum, 1, 0)) - for (int ChangeTime = 0; ChangeTime < P.Num_PC_ChangeTimes; ChangeTime++) //// by default populate to values of P.PlaceClosePropAttending + if (!P.VaryEfficaciesOverTime || + !GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Proportional attendance after closure by place type over time", "%lf", + (void *)&P.PC_PropAttending_OverTime[0][0], + P.Num_PC_ChangeTimes * P.PlaceTypeNum, 1, 0)) + for (int ChangeTime = 0; ChangeTime < P.Num_PC_ChangeTimes; + ChangeTime++) //// by default populate to values of P.PlaceClosePropAttending for (int PlaceType = 0; PlaceType < P.PlaceTypeNum; PlaceType++) P.PC_PropAttending_OverTime[ChangeTime][PlaceType] = P.PlaceClosePropAttending[PlaceType]; } - //// **** compliance //// case isolation - if (!P.VaryEfficaciesOverTime || !GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Proportion of detected cases isolated over time", "%lf", (void*)P.CI_Prop_OverTime, P.Num_CI_ChangeTimes, 1, 0)) - for (int ChangeTime = 0; ChangeTime < P.Num_CI_ChangeTimes; ChangeTime++) P.CI_Prop_OverTime[ChangeTime] = P.CaseIsolationProp; + if (!P.VaryEfficaciesOverTime || + !GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Proportion of detected cases isolated over time", "%lf", + (void *)P.CI_Prop_OverTime, P.Num_CI_ChangeTimes, 1, 0)) + for (int ChangeTime = 0; ChangeTime < P.Num_CI_ChangeTimes; ChangeTime++) + P.CI_Prop_OverTime[ChangeTime] = P.CaseIsolationProp; //// household quarantine (individual level) - if (!P.VaryEfficaciesOverTime || !GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Individual level compliance with quarantine over time" , "%lf", (void*)P.HQ_Individual_PropComply_OverTime, P.Num_HQ_ChangeTimes, 1, 0)) - for (int ChangeTime = 0; ChangeTime < P.Num_HQ_ChangeTimes; ChangeTime++) P.HQ_Individual_PropComply_OverTime[ChangeTime] = P.HQuarantinePropIndivCompliant; + if (!P.VaryEfficaciesOverTime || + !GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Individual level compliance with quarantine over time", "%lf", + (void *)P.HQ_Individual_PropComply_OverTime, P.Num_HQ_ChangeTimes, 1, 0)) + for (int ChangeTime = 0; ChangeTime < P.Num_HQ_ChangeTimes; ChangeTime++) + P.HQ_Individual_PropComply_OverTime[ChangeTime] = P.HQuarantinePropIndivCompliant; //// household quarantine (Household level) - if (!P.VaryEfficaciesOverTime || !GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Household level compliance with quarantine over time" , "%lf", (void*)P.HQ_Household_PropComply_OverTime, P.Num_HQ_ChangeTimes, 1, 0)) - for (int ChangeTime = 0; ChangeTime < P.Num_HQ_ChangeTimes; ChangeTime++) P.HQ_Household_PropComply_OverTime[ChangeTime] = P.HQuarantinePropHouseCompliant; + if (!P.VaryEfficaciesOverTime || + !GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Household level compliance with quarantine over time", "%lf", + (void *)P.HQ_Household_PropComply_OverTime, P.Num_HQ_ChangeTimes, 1, 0)) + for (int ChangeTime = 0; ChangeTime < P.Num_HQ_ChangeTimes; ChangeTime++) + P.HQ_Household_PropComply_OverTime[ChangeTime] = P.HQuarantinePropHouseCompliant; //// digital contact tracing - if (!P.VaryEfficaciesOverTime || !GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Proportion of digital contacts who self-isolate over time", "%lf", (void*)P.DCT_Prop_OverTime, P.Num_DCT_ChangeTimes, 1, 0)) - for (int ChangeTime = 0; ChangeTime < P.Num_DCT_ChangeTimes; ChangeTime++) P.DCT_Prop_OverTime[ChangeTime] = P.ProportionDigitalContactsIsolate; - if (!P.VaryEfficaciesOverTime || !GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Maximum number of contacts to trace per index case over time", "%i", (void*)P.DCT_MaxToTrace_OverTime, P.Num_DCT_ChangeTimes, 1, 0)) - for (int ChangeTime = 0; ChangeTime < P.Num_DCT_ChangeTimes; ChangeTime++) P.DCT_MaxToTrace_OverTime[ChangeTime] = P.MaxDigitalContactsToTrace; + if (!P.VaryEfficaciesOverTime || + !GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Proportion of digital contacts who self-isolate over time", "%lf", + (void *)P.DCT_Prop_OverTime, P.Num_DCT_ChangeTimes, 1, 0)) + for (int ChangeTime = 0; ChangeTime < P.Num_DCT_ChangeTimes; ChangeTime++) + P.DCT_Prop_OverTime[ChangeTime] = P.ProportionDigitalContactsIsolate; + if (!P.VaryEfficaciesOverTime || + !GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Maximum number of contacts to trace per index case over time", "%i", + (void *)P.DCT_MaxToTrace_OverTime, P.Num_DCT_ChangeTimes, 1, 0)) + for (int ChangeTime = 0; ChangeTime < P.Num_DCT_ChangeTimes; ChangeTime++) + P.DCT_MaxToTrace_OverTime[ChangeTime] = P.MaxDigitalContactsToTrace; if (P.DoPlaces) { //// **** thresholds //// place closure (global threshold) - if (!P.VaryEfficaciesOverTime || !GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Place closure incidence threshold over time", "%lf", (void*)P.PC_IncThresh_OverTime, P.Num_PC_ChangeTimes, 1, 0)) - for (int ChangeTime = 0; ChangeTime < P.Num_PC_ChangeTimes; ChangeTime++) P.PC_IncThresh_OverTime[ChangeTime] = P.PlaceCloseIncTrig1; + if (!P.VaryEfficaciesOverTime || + !GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Place closure incidence threshold over time", "%lf", + (void *)P.PC_IncThresh_OverTime, P.Num_PC_ChangeTimes, 1, 0)) + for (int ChangeTime = 0; ChangeTime < P.Num_PC_ChangeTimes; ChangeTime++) + P.PC_IncThresh_OverTime[ChangeTime] = P.PlaceCloseIncTrig1; //// place closure (fractional global threshold) - if (!P.VaryEfficaciesOverTime || !GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Place closure fractional incidence threshold over time", "%lf", (void*)P.PC_FracIncThresh_OverTime, P.Num_PC_ChangeTimes, 1, 0)) - for (int ChangeTime = 0; ChangeTime < P.Num_PC_ChangeTimes; ChangeTime++) P.PC_FracIncThresh_OverTime[ChangeTime] = P.PlaceCloseFracIncTrig; + if (!P.VaryEfficaciesOverTime || + !GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Place closure fractional incidence threshold over time", "%lf", + (void *)P.PC_FracIncThresh_OverTime, P.Num_PC_ChangeTimes, 1, 0)) + for (int ChangeTime = 0; ChangeTime < P.Num_PC_ChangeTimes; ChangeTime++) + P.PC_FracIncThresh_OverTime[ChangeTime] = P.PlaceCloseFracIncTrig; //// place closure (cell incidence threshold) - if (!P.VaryEfficaciesOverTime || !GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Trigger incidence per cell for place closure over time", "%i", (void*)P.PC_CellIncThresh_OverTime, P.Num_PC_ChangeTimes, 1, 0)) - for (int ChangeTime = 0; ChangeTime < P.Num_PC_ChangeTimes; ChangeTime++) P.PC_CellIncThresh_OverTime[ChangeTime] = P.PlaceCloseCellIncThresh1; - for (int ChangeTime = 0; ChangeTime < P.Num_PC_ChangeTimes; ChangeTime++) if(P.PC_CellIncThresh_OverTime[ChangeTime]<0) P.PC_CellIncThresh_OverTime[ChangeTime] = 1000000000; // allows -1 to be used as a proxy for no cell-based triggering + if (!P.VaryEfficaciesOverTime || + !GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Trigger incidence per cell for place closure over time", "%i", + (void *)P.PC_CellIncThresh_OverTime, P.Num_PC_ChangeTimes, 1, 0)) + for (int ChangeTime = 0; ChangeTime < P.Num_PC_ChangeTimes; ChangeTime++) + P.PC_CellIncThresh_OverTime[ChangeTime] = P.PlaceCloseCellIncThresh1; + for (int ChangeTime = 0; ChangeTime < P.Num_PC_ChangeTimes; ChangeTime++) + if (P.PC_CellIncThresh_OverTime[ChangeTime] < 0) + P.PC_CellIncThresh_OverTime[ChangeTime] = + 1000000000; // allows -1 to be used as a proxy for no cell-based triggering } //// household quarantine - if (!P.VaryEfficaciesOverTime || !GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Household quarantine trigger incidence per cell over time", "%lf", (void*)P.HQ_CellIncThresh_OverTime, P.Num_HQ_ChangeTimes, 1, 0)) - for (int ChangeTime = 0; ChangeTime < P.Num_HQ_ChangeTimes; ChangeTime++) P.HQ_CellIncThresh_OverTime[ChangeTime] = P.HHQuar_CellIncThresh; + if (!P.VaryEfficaciesOverTime || + !GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Household quarantine trigger incidence per cell over time", "%lf", + (void *)P.HQ_CellIncThresh_OverTime, P.Num_HQ_ChangeTimes, 1, 0)) + for (int ChangeTime = 0; ChangeTime < P.Num_HQ_ChangeTimes; ChangeTime++) + P.HQ_CellIncThresh_OverTime[ChangeTime] = P.HHQuar_CellIncThresh; //// case isolation - if (!P.VaryEfficaciesOverTime || !GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Case isolation trigger incidence per cell over time", "%lf", (void*)P.CI_CellIncThresh_OverTime, P.Num_CI_ChangeTimes, 1, 0)) - for (int ChangeTime = 0; ChangeTime < P.Num_CI_ChangeTimes; ChangeTime++) P.CI_CellIncThresh_OverTime[ChangeTime] = P.CaseIsolation_CellIncThresh; + if (!P.VaryEfficaciesOverTime || + !GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Case isolation trigger incidence per cell over time", "%lf", + (void *)P.CI_CellIncThresh_OverTime, P.Num_CI_ChangeTimes, 1, 0)) + for (int ChangeTime = 0; ChangeTime < P.Num_CI_ChangeTimes; ChangeTime++) + P.CI_CellIncThresh_OverTime[ChangeTime] = P.CaseIsolation_CellIncThresh; //// soc dists - if (!P.VaryEfficaciesOverTime || !GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Trigger incidence per cell for social distancing over time", "%i", (void*)P.SD_CellIncThresh_OverTime, P.Num_SD_ChangeTimes, 1, 0)) - for (int ChangeTime = 0; ChangeTime < P.Num_SD_ChangeTimes; ChangeTime++) P.SD_CellIncThresh_OverTime[ChangeTime] = P.SocDistCellIncThresh; + if (!P.VaryEfficaciesOverTime || + !GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Trigger incidence per cell for social distancing over time", "%i", + (void *)P.SD_CellIncThresh_OverTime, P.Num_SD_ChangeTimes, 1, 0)) + for (int ChangeTime = 0; ChangeTime < P.Num_SD_ChangeTimes; ChangeTime++) + P.SD_CellIncThresh_OverTime[ChangeTime] = P.SocDistCellIncThresh; //// **** Durations (later add Case isolation and Household quarantine) // place closure - if (!P.VaryEfficaciesOverTime || !GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Duration of place closure over time", "%lf", (void*)P.PC_Durs_OverTime, P.Num_PC_ChangeTimes, 1, 0)) - for (int ChangeTime = 0; ChangeTime < P.Num_PC_ChangeTimes; ChangeTime++) P.PC_Durs_OverTime[ChangeTime] = P.PlaceCloseDurationBase; + if (!P.VaryEfficaciesOverTime || + !GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Duration of place closure over time", + "%lf", (void *)P.PC_Durs_OverTime, P.Num_PC_ChangeTimes, 1, 0)) + for (int ChangeTime = 0; ChangeTime < P.Num_PC_ChangeTimes; ChangeTime++) + P.PC_Durs_OverTime[ChangeTime] = P.PlaceCloseDurationBase; //// Guards: make unused change values in array equal to final used value if (P.VaryEfficaciesOverTime) { //// soc dist - for (int SD_ChangeTime = P.Num_SD_ChangeTimes; SD_ChangeTime < MAX_NUM_INTERVENTION_CHANGE_TIMES - 1; SD_ChangeTime++) + for (int SD_ChangeTime = P.Num_SD_ChangeTimes; + SD_ChangeTime < MAX_NUM_INTERVENTION_CHANGE_TIMES - 1; SD_ChangeTime++) { //// non-enhanced - P.SD_SpatialEffects_OverTime [SD_ChangeTime] = P.SD_SpatialEffects_OverTime [P.Num_SD_ChangeTimes - 1]; - P.SD_HouseholdEffects_OverTime [SD_ChangeTime] = P.SD_HouseholdEffects_OverTime [P.Num_SD_ChangeTimes - 1]; + P.SD_SpatialEffects_OverTime[SD_ChangeTime] = + P.SD_SpatialEffects_OverTime[P.Num_SD_ChangeTimes - 1]; + P.SD_HouseholdEffects_OverTime[SD_ChangeTime] = + P.SD_HouseholdEffects_OverTime[P.Num_SD_ChangeTimes - 1]; for (int PlaceType = 0; PlaceType < P.PlaceTypeNum; PlaceType++) - P.SD_PlaceEffects_OverTime[SD_ChangeTime][PlaceType] = P.SD_PlaceEffects_OverTime[P.Num_SD_ChangeTimes - 1][PlaceType]; + P.SD_PlaceEffects_OverTime[SD_ChangeTime][PlaceType] = + P.SD_PlaceEffects_OverTime[P.Num_SD_ChangeTimes - 1][PlaceType]; //// enhanced - P.Enhanced_SD_SpatialEffects_OverTime [SD_ChangeTime] = P.Enhanced_SD_SpatialEffects_OverTime [P.Num_SD_ChangeTimes - 1]; - P.Enhanced_SD_HouseholdEffects_OverTime [SD_ChangeTime] = P.Enhanced_SD_HouseholdEffects_OverTime [P.Num_SD_ChangeTimes - 1]; + P.Enhanced_SD_SpatialEffects_OverTime[SD_ChangeTime] = + P.Enhanced_SD_SpatialEffects_OverTime[P.Num_SD_ChangeTimes - 1]; + P.Enhanced_SD_HouseholdEffects_OverTime[SD_ChangeTime] = + P.Enhanced_SD_HouseholdEffects_OverTime[P.Num_SD_ChangeTimes - 1]; for (int PlaceType = 0; PlaceType < P.PlaceTypeNum; PlaceType++) - P.Enhanced_SD_PlaceEffects_OverTime[SD_ChangeTime][PlaceType] = P.Enhanced_SD_PlaceEffects_OverTime[P.Num_SD_ChangeTimes - 1][PlaceType]; + P.Enhanced_SD_PlaceEffects_OverTime[SD_ChangeTime][PlaceType] = + P.Enhanced_SD_PlaceEffects_OverTime[P.Num_SD_ChangeTimes - 1][PlaceType]; - P.SD_CellIncThresh_OverTime [SD_ChangeTime] = P.SD_CellIncThresh_OverTime [P.Num_SD_ChangeTimes - 1]; + P.SD_CellIncThresh_OverTime[SD_ChangeTime] = + P.SD_CellIncThresh_OverTime[P.Num_SD_ChangeTimes - 1]; } //// case isolation - for (int CI_ChangeTime = P.Num_CI_ChangeTimes; CI_ChangeTime < MAX_NUM_INTERVENTION_CHANGE_TIMES - 1; CI_ChangeTime++) + for (int CI_ChangeTime = P.Num_CI_ChangeTimes; + CI_ChangeTime < MAX_NUM_INTERVENTION_CHANGE_TIMES - 1; CI_ChangeTime++) { - P.CI_SpatialAndPlaceEffects_OverTime[CI_ChangeTime] = P.CI_SpatialAndPlaceEffects_OverTime [P.Num_CI_ChangeTimes - 1]; - P.CI_HouseholdEffects_OverTime [CI_ChangeTime] = P.CI_HouseholdEffects_OverTime [P.Num_CI_ChangeTimes - 1]; - P.CI_Prop_OverTime [CI_ChangeTime] = P.CI_Prop_OverTime [P.Num_CI_ChangeTimes - 1]; - P.CI_CellIncThresh_OverTime [CI_ChangeTime] = P.CI_CellIncThresh_OverTime [P.Num_CI_ChangeTimes - 1]; + P.CI_SpatialAndPlaceEffects_OverTime[CI_ChangeTime] = + P.CI_SpatialAndPlaceEffects_OverTime[P.Num_CI_ChangeTimes - 1]; + P.CI_HouseholdEffects_OverTime[CI_ChangeTime] = + P.CI_HouseholdEffects_OverTime[P.Num_CI_ChangeTimes - 1]; + P.CI_Prop_OverTime[CI_ChangeTime] = P.CI_Prop_OverTime[P.Num_CI_ChangeTimes - 1]; + P.CI_CellIncThresh_OverTime[CI_ChangeTime] = + P.CI_CellIncThresh_OverTime[P.Num_CI_ChangeTimes - 1]; } //// household quarantine - for (int HQ_ChangeTime = P.Num_HQ_ChangeTimes; HQ_ChangeTime < MAX_NUM_INTERVENTION_CHANGE_TIMES - 1; HQ_ChangeTime++) + for (int HQ_ChangeTime = P.Num_HQ_ChangeTimes; + HQ_ChangeTime < MAX_NUM_INTERVENTION_CHANGE_TIMES - 1; HQ_ChangeTime++) { - P.HQ_SpatialEffects_OverTime [HQ_ChangeTime] = P.HQ_SpatialEffects_OverTime [P.Num_HQ_ChangeTimes - 1]; - P.HQ_HouseholdEffects_OverTime [HQ_ChangeTime] = P.HQ_HouseholdEffects_OverTime[P.Num_HQ_ChangeTimes - 1]; + P.HQ_SpatialEffects_OverTime[HQ_ChangeTime] = + P.HQ_SpatialEffects_OverTime[P.Num_HQ_ChangeTimes - 1]; + P.HQ_HouseholdEffects_OverTime[HQ_ChangeTime] = + P.HQ_HouseholdEffects_OverTime[P.Num_HQ_ChangeTimes - 1]; for (int PlaceType = 0; PlaceType < P.PlaceTypeNum; PlaceType++) - P.HQ_PlaceEffects_OverTime[HQ_ChangeTime][PlaceType] = P.HQ_PlaceEffects_OverTime[P.Num_HQ_ChangeTimes - 1][PlaceType]; + P.HQ_PlaceEffects_OverTime[HQ_ChangeTime][PlaceType] = + P.HQ_PlaceEffects_OverTime[P.Num_HQ_ChangeTimes - 1][PlaceType]; - P.HQ_Individual_PropComply_OverTime [HQ_ChangeTime] = P.HQ_Individual_PropComply_OverTime [P.Num_HQ_ChangeTimes - 1]; - P.HQ_Household_PropComply_OverTime [HQ_ChangeTime] = P.HQ_Household_PropComply_OverTime [P.Num_HQ_ChangeTimes - 1]; + P.HQ_Individual_PropComply_OverTime[HQ_ChangeTime] = + P.HQ_Individual_PropComply_OverTime[P.Num_HQ_ChangeTimes - 1]; + P.HQ_Household_PropComply_OverTime[HQ_ChangeTime] = + P.HQ_Household_PropComply_OverTime[P.Num_HQ_ChangeTimes - 1]; - P.HQ_CellIncThresh_OverTime [HQ_ChangeTime] = P.HQ_CellIncThresh_OverTime [P.Num_HQ_ChangeTimes - 1]; + P.HQ_CellIncThresh_OverTime[HQ_ChangeTime] = + P.HQ_CellIncThresh_OverTime[P.Num_HQ_ChangeTimes - 1]; } //// place closure - for (int PC_ChangeTime = P.Num_PC_ChangeTimes; PC_ChangeTime < MAX_NUM_INTERVENTION_CHANGE_TIMES - 1; PC_ChangeTime++) + for (int PC_ChangeTime = P.Num_PC_ChangeTimes; + PC_ChangeTime < MAX_NUM_INTERVENTION_CHANGE_TIMES - 1; PC_ChangeTime++) { - P.PC_SpatialEffects_OverTime [PC_ChangeTime] = P.PC_SpatialEffects_OverTime [P.Num_PC_ChangeTimes - 1]; - P.PC_HouseholdEffects_OverTime [PC_ChangeTime] = P.PC_HouseholdEffects_OverTime[P.Num_PC_ChangeTimes - 1]; + P.PC_SpatialEffects_OverTime[PC_ChangeTime] = + P.PC_SpatialEffects_OverTime[P.Num_PC_ChangeTimes - 1]; + P.PC_HouseholdEffects_OverTime[PC_ChangeTime] = + P.PC_HouseholdEffects_OverTime[P.Num_PC_ChangeTimes - 1]; for (int PlaceType = 0; PlaceType < P.PlaceTypeNum; PlaceType++) { - P.PC_PlaceEffects_OverTime[PC_ChangeTime][PlaceType] = P.PC_PlaceEffects_OverTime[P.Num_PC_ChangeTimes - 1][PlaceType]; - P.PC_PropAttending_OverTime[PC_ChangeTime][PlaceType] = P.PC_PropAttending_OverTime[P.Num_PC_ChangeTimes - 1][PlaceType]; + P.PC_PlaceEffects_OverTime[PC_ChangeTime][PlaceType] = + P.PC_PlaceEffects_OverTime[P.Num_PC_ChangeTimes - 1][PlaceType]; + P.PC_PropAttending_OverTime[PC_ChangeTime][PlaceType] = + P.PC_PropAttending_OverTime[P.Num_PC_ChangeTimes - 1][PlaceType]; } - P.PC_IncThresh_OverTime [PC_ChangeTime] = P.PC_IncThresh_OverTime [P.Num_PC_ChangeTimes - 1]; - P.PC_FracIncThresh_OverTime [PC_ChangeTime] = P.PC_FracIncThresh_OverTime [P.Num_PC_ChangeTimes - 1]; - P.PC_CellIncThresh_OverTime [PC_ChangeTime] = P.PC_CellIncThresh_OverTime [P.Num_PC_ChangeTimes - 1]; + P.PC_IncThresh_OverTime[PC_ChangeTime] = P.PC_IncThresh_OverTime[P.Num_PC_ChangeTimes - 1]; + P.PC_FracIncThresh_OverTime[PC_ChangeTime] = + P.PC_FracIncThresh_OverTime[P.Num_PC_ChangeTimes - 1]; + P.PC_CellIncThresh_OverTime[PC_ChangeTime] = + P.PC_CellIncThresh_OverTime[P.Num_PC_ChangeTimes - 1]; } //// digital contact tracing - for (int DCT_ChangeTime = P.Num_DCT_ChangeTimes; DCT_ChangeTime < MAX_NUM_INTERVENTION_CHANGE_TIMES - 1; DCT_ChangeTime++) + for (int DCT_ChangeTime = P.Num_DCT_ChangeTimes; + DCT_ChangeTime < MAX_NUM_INTERVENTION_CHANGE_TIMES - 1; DCT_ChangeTime++) { - P.DCT_SpatialAndPlaceEffects_OverTime [DCT_ChangeTime] = P.DCT_SpatialAndPlaceEffects_OverTime[P.Num_DCT_ChangeTimes - 1]; - P.DCT_HouseholdEffects_OverTime [DCT_ChangeTime] = P.DCT_HouseholdEffects_OverTime [P.Num_DCT_ChangeTimes - 1]; - P.DCT_Prop_OverTime [DCT_ChangeTime] = P.DCT_Prop_OverTime [P.Num_DCT_ChangeTimes - 1]; - P.DCT_MaxToTrace_OverTime [DCT_ChangeTime] = P.DCT_MaxToTrace_OverTime [P.Num_DCT_ChangeTimes - 1]; + P.DCT_SpatialAndPlaceEffects_OverTime[DCT_ChangeTime] = + P.DCT_SpatialAndPlaceEffects_OverTime[P.Num_DCT_ChangeTimes - 1]; + P.DCT_HouseholdEffects_OverTime[DCT_ChangeTime] = + P.DCT_HouseholdEffects_OverTime[P.Num_DCT_ChangeTimes - 1]; + P.DCT_Prop_OverTime[DCT_ChangeTime] = P.DCT_Prop_OverTime[P.Num_DCT_ChangeTimes - 1]; + P.DCT_MaxToTrace_OverTime[DCT_ChangeTime] = + P.DCT_MaxToTrace_OverTime[P.Num_DCT_ChangeTimes - 1]; } } if (P.DoPlaces) { - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Number of key workers randomly distributed in the population", "%i", (void*) & (P.KeyWorkerPopNum), 1, 1, 0)) P.KeyWorkerPopNum = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Number of key workers in different places by place type", "%i", (void*)P.KeyWorkerPlaceNum, P.PlaceTypeNum, 1, 0)) - for (i = 0; i < NUM_PLACE_TYPES; i++) P.KeyWorkerPlaceNum[i] = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Proportion of staff who are key workers per chosen place by place type", "%lf", (void*)P.KeyWorkerPropInKeyPlaces, P.PlaceTypeNum, 1, 0)) - for (i = 0; i < NUM_PLACE_TYPES; i++) P.KeyWorkerPropInKeyPlaces[i] = 1.0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Trigger incidence per cell for key worker prophylaxis", "%i", (void*) & (P.KeyWorkerProphCellIncThresh), 1, 1, 0)) P.KeyWorkerProphCellIncThresh = 1000000000; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Key worker prophylaxis start time", "%lf", (void*) & (P.KeyWorkerProphTimeStartBase), 1, 1, 0)) P.KeyWorkerProphTimeStartBase = USHRT_MAX / P.TimeStepsPerDay; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Duration of key worker prophylaxis", "%lf", (void*) & (P.KeyWorkerProphDuration), 1, 1, 0)) P.KeyWorkerProphDuration = 0; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Time interval from start of key worker prophylaxis before policy restarted", "%lf", (void*) & (P.KeyWorkerProphRenewalDuration), 1, 1, 0)) P.KeyWorkerProphRenewalDuration = P.KeyWorkerProphDuration; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Number of key workers randomly distributed in the population", "%i", + (void *)&(P.KeyWorkerPopNum), 1, 1, 0)) + P.KeyWorkerPopNum = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Number of key workers in different places by place type", "%i", + (void *)P.KeyWorkerPlaceNum, P.PlaceTypeNum, 1, 0)) + for (i = 0; i < NUM_PLACE_TYPES; i++) + P.KeyWorkerPlaceNum[i] = 0; + if (!GetInputParameter2( + ParamFile_dat, PreParamFile_dat, + "Proportion of staff who are key workers per chosen place by place type", "%lf", + (void *)P.KeyWorkerPropInKeyPlaces, P.PlaceTypeNum, 1, 0)) + for (i = 0; i < NUM_PLACE_TYPES; i++) + P.KeyWorkerPropInKeyPlaces[i] = 1.0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Trigger incidence per cell for key worker prophylaxis", "%i", + (void *)&(P.KeyWorkerProphCellIncThresh), 1, 1, 0)) + P.KeyWorkerProphCellIncThresh = 1000000000; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Key worker prophylaxis start time", + "%lf", (void *)&(P.KeyWorkerProphTimeStartBase), 1, 1, 0)) + P.KeyWorkerProphTimeStartBase = USHRT_MAX / P.TimeStepsPerDay; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Duration of key worker prophylaxis", + "%lf", (void *)&(P.KeyWorkerProphDuration), 1, 1, 0)) + P.KeyWorkerProphDuration = 0; + if (!GetInputParameter2( + ParamFile_dat, PreParamFile_dat, + "Time interval from start of key worker prophylaxis before policy restarted", "%lf", + (void *)&(P.KeyWorkerProphRenewalDuration), 1, 1, 0)) + P.KeyWorkerProphRenewalDuration = P.KeyWorkerProphDuration; if (P.DoHouseholds) { - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Proportion of key workers whose households are also treated as key workers", "%lf", (void*) & (P.KeyWorkerHouseProp), 1, 1, 0)) P.KeyWorkerHouseProp = 0; + if (!GetInputParameter2( + ParamFile_dat, PreParamFile_dat, + "Proportion of key workers whose households are also treated as key workers", "%lf", + (void *)&(P.KeyWorkerHouseProp), 1, 1, 0)) + P.KeyWorkerHouseProp = 0; } - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Minimum radius for key worker prophylaxis", "%lf", (void*) & (P.KeyWorkerProphRadius), 1, 1, 0)) P.KeyWorkerProphRadius = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Minimum radius for key worker prophylaxis", "%lf", + (void *)&(P.KeyWorkerProphRadius), 1, 1, 0)) + P.KeyWorkerProphRadius = 0; } else { @@ -1959,57 +3262,137 @@ void ReadParams(char* ParamFile, char* PreParamFile) P.KeyWorkerProphTimeStartBase = 1e10; } - //Added this to parameter list so that recording infection events (and the number to record) can easily be turned off and on: ggilani - 10/10/2014 - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Record infection events", "%i", (void*) & (P.DoRecordInfEvents), 1, 1, 0)) P.DoRecordInfEvents = 0; + // Added this to parameter list so that recording infection events (and the number to record) can + // easily be turned off and on: ggilani - 10/10/2014 + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Record infection events", "%i", + (void *)&(P.DoRecordInfEvents), 1, 1, 0)) + P.DoRecordInfEvents = 0; if (P.DoRecordInfEvents) { - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Max number of infection events to record", "%i", (void*) & (P.MaxInfEvents), 1, 1, 0)) P.MaxInfEvents = 1000; - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Record infection events per run", "%i", (void*) & (P.RecordInfEventsPerRun), 1, 1, 0)) P.RecordInfEventsPerRun = 0; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, + "Max number of infection events to record", "%i", + (void *)&(P.MaxInfEvents), 1, 1, 0)) + P.MaxInfEvents = 1000; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Record infection events per run", + "%i", (void *)&(P.RecordInfEventsPerRun), 1, 1, 0)) + P.RecordInfEventsPerRun = 0; } else { P.MaxInfEvents = 0; } - //Include a limit to the number of infections to simulate, if this happens before time runs out - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Limit number of infections", "%i", (void*) & (P.LimitNumInfections), 1, 1, 0)) P.LimitNumInfections = 0; + // Include a limit to the number of infections to simulate, if this happens before time runs out + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Limit number of infections", "%i", + (void *)&(P.LimitNumInfections), 1, 1, 0)) + P.LimitNumInfections = 0; if (P.LimitNumInfections) { - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Max number of infections", "%i", (void*) & (P.MaxNumInfections), 1, 1, 0)) P.MaxNumInfections = 60000; - } - //Add origin-destination matrix parameter - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Output origin destination matrix", "%i", (void*) & (P.DoOriginDestinationMatrix), 1, 1, 0)) P.DoOriginDestinationMatrix = 0; - - if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat,AdminFile_dat, "Mean child age gap", "%i", (void*) & (P.MeanChildAgeGap), 1, 1, 0)) P.MeanChildAgeGap=2; - if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat,AdminFile_dat, "Min adult age", "%i", (void*)&(P.MinAdultAge), 1, 1, 0)) P.MinAdultAge = 19; - if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat,AdminFile_dat, "Max MF partner age gap", "%i", (void*) & (P.MaxMFPartnerAgeGap), 1, 1, 0)) P.MaxMFPartnerAgeGap = 5; - if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat,AdminFile_dat, "Max FM partner age gap", "%i", (void*) & (P.MaxFMPartnerAgeGap), 1, 1, 0)) P.MaxFMPartnerAgeGap = 5; - if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat,AdminFile_dat, "Min parent age gap", "%i", (void*) & (P.MinParentAgeGap), 1, 1, 0)) P.MinParentAgeGap = 19; - if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat,AdminFile_dat, "Max parent age gap", "%i", (void*) & (P.MaxParentAgeGap), 1, 1, 0)) P.MaxParentAgeGap = 44; - if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat,AdminFile_dat, "Max child age", "%i", (void*) & (P.MaxChildAge), 1, 1, 0)) P.MaxChildAge = 20; - if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat,AdminFile_dat, "One Child Two Pers Prob", "%lf", (void*) & (P.OneChildTwoPersProb), 1, 1, 0)) P.OneChildTwoPersProb = 0.08; - if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat,AdminFile_dat, "Two Child Three Pers Prob", "%lf", (void*) & (P.TwoChildThreePersProb), 1, 1, 0)) P.TwoChildThreePersProb = 0.11; - if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat,AdminFile_dat, "One Pers House Prob Old", "%lf", (void*) & (P.OnePersHouseProbOld), 1, 1, 0)) P.OnePersHouseProbOld = 0.5; - if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat,AdminFile_dat, "Two Pers House Prob Old", "%lf", (void*) & (P.TwoPersHouseProbOld), 1, 1, 0)) P.TwoPersHouseProbOld = 0.5; - if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat,AdminFile_dat, "One Pers House Prob Young", "%lf", (void*) & (P.OnePersHouseProbYoung), 1, 1, 0)) P.OnePersHouseProbYoung = 0.23; - if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat,AdminFile_dat, "Two Pers House Prob Young", "%lf", (void*) & (P.TwoPersHouseProbYoung), 1, 1, 0)) P.TwoPersHouseProbYoung = 0.23; - if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat,AdminFile_dat, "One Child Prob Youngest Child Under Five", "%lf", (void*) & (P.OneChildProbYoungestChildUnderFive), 1, 1, 0)) P.OneChildProbYoungestChildUnderFive = 0.5; - if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat,AdminFile_dat, "Two Children Prob Youngest Under Five", "%lf", (void*) & (P.TwoChildrenProbYoungestUnderFive), 1, 1, 0)) P.TwoChildrenProbYoungestUnderFive = 0.0; - if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat,AdminFile_dat, "Prob Youngest Child Under Five", "%lf", (void*) & (P.ProbYoungestChildUnderFive), 1, 1, 0)) P.ProbYoungestChildUnderFive = 0; - if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat,AdminFile_dat, "Zero Child Three Pers Prob", "%lf", (void*) & (P.ZeroChildThreePersProb), 1, 1, 0)) P.ZeroChildThreePersProb = 0.25; - if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat,AdminFile_dat, "One Child Four Pers Prob", "%lf", (void*) & (P.OneChildFourPersProb), 1, 1, 0)) P.OneChildFourPersProb = 0.2; - if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat,AdminFile_dat, "Young And Single Slope", "%lf", (void*) & (P.YoungAndSingleSlope), 1, 1, 0)) P.YoungAndSingleSlope = 0.7; - if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat,AdminFile_dat, "Young And Single", "%i", (void*) & (P.YoungAndSingle), 1, 1, 0)) P.YoungAndSingle = 36; - if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat,AdminFile_dat, "No Child Pers Age", "%i", (void*) & (P.NoChildPersAge), 1, 1, 0)) P.NoChildPersAge = 44; - if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat,AdminFile_dat, "Old Pers Age", "%i", (void*) & (P.OldPersAge), 1, 1, 0)) P.OldPersAge = 60; - if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat,AdminFile_dat, "Three Child Five Pers Prob", "%lf", (void*) & (P.ThreeChildFivePersProb), 1, 1, 0)) P.ThreeChildFivePersProb = 0.5; - if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat,AdminFile_dat, "Older Gen Gap", "%i", (void*) & (P.OlderGenGap), 1, 1, 0)) P.OlderGenGap = 19; + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Max number of infections", "%i", + (void *)&(P.MaxNumInfections), 1, 1, 0)) + P.MaxNumInfections = 60000; + } + // Add origin-destination matrix parameter + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Output origin destination matrix", "%i", + (void *)&(P.DoOriginDestinationMatrix), 1, 1, 0)) + P.DoOriginDestinationMatrix = 0; + + if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat, AdminFile_dat, "Mean child age gap", + "%i", (void *)&(P.MeanChildAgeGap), 1, 1, 0)) + P.MeanChildAgeGap = 2; + if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat, AdminFile_dat, "Min adult age", "%i", + (void *)&(P.MinAdultAge), 1, 1, 0)) + P.MinAdultAge = 19; + if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat, AdminFile_dat, + "Max MF partner age gap", "%i", (void *)&(P.MaxMFPartnerAgeGap), 1, 1, + 0)) + P.MaxMFPartnerAgeGap = 5; + if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat, AdminFile_dat, + "Max FM partner age gap", "%i", (void *)&(P.MaxFMPartnerAgeGap), 1, 1, + 0)) + P.MaxFMPartnerAgeGap = 5; + if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat, AdminFile_dat, "Min parent age gap", + "%i", (void *)&(P.MinParentAgeGap), 1, 1, 0)) + P.MinParentAgeGap = 19; + if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat, AdminFile_dat, "Max parent age gap", + "%i", (void *)&(P.MaxParentAgeGap), 1, 1, 0)) + P.MaxParentAgeGap = 44; + if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat, AdminFile_dat, "Max child age", "%i", + (void *)&(P.MaxChildAge), 1, 1, 0)) + P.MaxChildAge = 20; + if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat, AdminFile_dat, + "One Child Two Pers Prob", "%lf", (void *)&(P.OneChildTwoPersProb), 1, + 1, 0)) + P.OneChildTwoPersProb = 0.08; + if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat, AdminFile_dat, + "Two Child Three Pers Prob", "%lf", (void *)&(P.TwoChildThreePersProb), + 1, 1, 0)) + P.TwoChildThreePersProb = 0.11; + if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat, AdminFile_dat, + "One Pers House Prob Old", "%lf", (void *)&(P.OnePersHouseProbOld), 1, + 1, 0)) + P.OnePersHouseProbOld = 0.5; + if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat, AdminFile_dat, + "Two Pers House Prob Old", "%lf", (void *)&(P.TwoPersHouseProbOld), 1, + 1, 0)) + P.TwoPersHouseProbOld = 0.5; + if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat, AdminFile_dat, + "One Pers House Prob Young", "%lf", (void *)&(P.OnePersHouseProbYoung), + 1, 1, 0)) + P.OnePersHouseProbYoung = 0.23; + if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat, AdminFile_dat, + "Two Pers House Prob Young", "%lf", (void *)&(P.TwoPersHouseProbYoung), + 1, 1, 0)) + P.TwoPersHouseProbYoung = 0.23; + if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat, AdminFile_dat, + "One Child Prob Youngest Child Under Five", "%lf", + (void *)&(P.OneChildProbYoungestChildUnderFive), 1, 1, 0)) + P.OneChildProbYoungestChildUnderFive = 0.5; + if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat, AdminFile_dat, + "Two Children Prob Youngest Under Five", "%lf", + (void *)&(P.TwoChildrenProbYoungestUnderFive), 1, 1, 0)) + P.TwoChildrenProbYoungestUnderFive = 0.0; + if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat, AdminFile_dat, + "Prob Youngest Child Under Five", "%lf", + (void *)&(P.ProbYoungestChildUnderFive), 1, 1, 0)) + P.ProbYoungestChildUnderFive = 0; + if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat, AdminFile_dat, + "Zero Child Three Pers Prob", "%lf", + (void *)&(P.ZeroChildThreePersProb), 1, 1, 0)) + P.ZeroChildThreePersProb = 0.25; + if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat, AdminFile_dat, + "One Child Four Pers Prob", "%lf", (void *)&(P.OneChildFourPersProb), + 1, 1, 0)) + P.OneChildFourPersProb = 0.2; + if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat, AdminFile_dat, + "Young And Single Slope", "%lf", (void *)&(P.YoungAndSingleSlope), 1, + 1, 0)) + P.YoungAndSingleSlope = 0.7; + if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat, AdminFile_dat, "Young And Single", + "%i", (void *)&(P.YoungAndSingle), 1, 1, 0)) + P.YoungAndSingle = 36; + if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat, AdminFile_dat, "No Child Pers Age", + "%i", (void *)&(P.NoChildPersAge), 1, 1, 0)) + P.NoChildPersAge = 44; + if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat, AdminFile_dat, "Old Pers Age", "%i", + (void *)&(P.OldPersAge), 1, 1, 0)) + P.OldPersAge = 60; + if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat, AdminFile_dat, + "Three Child Five Pers Prob", "%lf", + (void *)&(P.ThreeChildFivePersProb), 1, 1, 0)) + P.ThreeChildFivePersProb = 0.5; + if (!GetInputParameter2all(ParamFile_dat, PreParamFile_dat, AdminFile_dat, "Older Gen Gap", "%i", + (void *)&(P.OlderGenGap), 1, 1, 0)) + P.OlderGenGap = 19; // Close input files. fclose(ParamFile_dat); - if (PreParamFile_dat != NULL) fclose(PreParamFile_dat); - if (ParamFile_dat != AdminFile_dat && AdminFile_dat != NULL) fclose(AdminFile_dat); + if (PreParamFile_dat != NULL) + fclose(PreParamFile_dat); + if (ParamFile_dat != AdminFile_dat && AdminFile_dat != NULL) + fclose(AdminFile_dat); - if (P.DoOneGen != 0) P.DoOneGen = 1; + if (P.DoOneGen != 0) + P.DoOneGen = 1; P.ColourPeriod = 2000; P.MoveRestrRadius2 = P.MoveRestrRadius * P.MoveRestrRadius; P.SocDistRadius2 = P.SocDistRadius * P.SocDistRadius; @@ -2018,29 +3401,38 @@ void ReadParams(char* ParamFile, char* PreParamFile) P.TreatRadius2 = P.TreatRadius * P.TreatRadius; P.PlaceCloseRadius2 = P.PlaceCloseRadius * P.PlaceCloseRadius; P.KeyWorkerProphRadius2 = P.KeyWorkerProphRadius * P.KeyWorkerProphRadius; - if (P.TreatRadius2 == 0) P.TreatRadius2 = -1; - if (P.VaccRadius2 == 0) P.VaccRadius2 = -1; - if (P.PlaceCloseRadius2 == 0) P.PlaceCloseRadius2 = -1; - if (P.MoveRestrRadius2 == 0) P.MoveRestrRadius2 = -1; - if (P.SocDistRadius2 == 0) P.SocDistRadius2 = -1; - if (P.KeyWorkerProphRadius2 == 0) P.KeyWorkerProphRadius2 = -1; -/* if (P.TreatCellIncThresh < 1) P.TreatCellIncThresh = 1; - if (P.CaseIsolation_CellIncThresh < 1) P.CaseIsolation_CellIncThresh = 1; - if (P.DigitalContactTracing_CellIncThresh < 1) P.DigitalContactTracing_CellIncThresh = 1; - if (P.HHQuar_CellIncThresh < 1) P.HHQuar_CellIncThresh = 1; - if (P.MoveRestrCellIncThresh < 1) P.MoveRestrCellIncThresh = 1; - if (P.PlaceCloseCellIncThresh < 1) P.PlaceCloseCellIncThresh = 1; - if (P.KeyWorkerProphCellIncThresh < 1) P.KeyWorkerProphCellIncThresh = 1; -*/ + if (P.TreatRadius2 == 0) + P.TreatRadius2 = -1; + if (P.VaccRadius2 == 0) + P.VaccRadius2 = -1; + if (P.PlaceCloseRadius2 == 0) + P.PlaceCloseRadius2 = -1; + if (P.MoveRestrRadius2 == 0) + P.MoveRestrRadius2 = -1; + if (P.SocDistRadius2 == 0) + P.SocDistRadius2 = -1; + if (P.KeyWorkerProphRadius2 == 0) + P.KeyWorkerProphRadius2 = -1; + /* if (P.TreatCellIncThresh < 1) P.TreatCellIncThresh = 1; + if (P.CaseIsolation_CellIncThresh < 1) P.CaseIsolation_CellIncThresh = 1; + if (P.DigitalContactTracing_CellIncThresh < 1) P.DigitalContactTracing_CellIncThresh = 1; + if (P.HHQuar_CellIncThresh < 1) P.HHQuar_CellIncThresh = 1; + if (P.MoveRestrCellIncThresh < 1) P.MoveRestrCellIncThresh = 1; + if (P.PlaceCloseCellIncThresh < 1) P.PlaceCloseCellIncThresh = 1; + if (P.KeyWorkerProphCellIncThresh < 1) P.KeyWorkerProphCellIncThresh = 1; + */ - //// Make unsigned short versions of various intervention variables. And scaled them by number of timesteps per day - P.usHQuarantineHouseDuration = ((unsigned short int) (P.HQuarantineHouseDuration * P.TimeStepsPerDay)); - P.usVaccTimeToEfficacy = ((unsigned short int) (P.VaccTimeToEfficacy * P.TimeStepsPerDay)); - P.usVaccTimeEfficacySwitch = ((unsigned short int) (P.VaccTimeEfficacySwitch * P.TimeStepsPerDay)); - P.usCaseIsolationDelay = ((unsigned short int) (P.CaseIsolationDelay * P.TimeStepsPerDay)); - P.usCaseIsolationDuration = ((unsigned short int) (P.CaseIsolationDuration * P.TimeStepsPerDay)); - P.usCaseAbsenteeismDuration = ((unsigned short int) (P.CaseAbsenteeismDuration * P.TimeStepsPerDay)); - P.usCaseAbsenteeismDelay = ((unsigned short int) (P.CaseAbsenteeismDelay * P.TimeStepsPerDay)); + //// Make unsigned short versions of various intervention variables. And scaled them by number of + /// timesteps per day + P.usHQuarantineHouseDuration = + ((unsigned short int)(P.HQuarantineHouseDuration * P.TimeStepsPerDay)); + P.usVaccTimeToEfficacy = ((unsigned short int)(P.VaccTimeToEfficacy * P.TimeStepsPerDay)); + P.usVaccTimeEfficacySwitch = ((unsigned short int)(P.VaccTimeEfficacySwitch * P.TimeStepsPerDay)); + P.usCaseIsolationDelay = ((unsigned short int)(P.CaseIsolationDelay * P.TimeStepsPerDay)); + P.usCaseIsolationDuration = ((unsigned short int)(P.CaseIsolationDuration * P.TimeStepsPerDay)); + P.usCaseAbsenteeismDuration = + ((unsigned short int)(P.CaseAbsenteeismDuration * P.TimeStepsPerDay)); + P.usCaseAbsenteeismDelay = ((unsigned short int)(P.CaseAbsenteeismDelay * P.TimeStepsPerDay)); if (P.DoUTM_coords) { for (i = 0; i <= 1000; i++) @@ -2056,41 +3448,51 @@ void ReadParams(char* ParamFile, char* PreParamFile) } fprintf(stderr, "Parameters read\n"); } -void ReadInterventions(char* IntFile) +void ReadInterventions(char *IntFile) { - FILE* dat; + FILE *dat; double r, s, startt, stopt; int j, k, au, ni, f, nsr; char buf[65536], txt[65536]; Intervention CurInterv; fprintf(stderr, "Reading intervention file.\n"); - if (!(dat = fopen(IntFile, "rb"))) ERR_CRITICAL("Unable to open intervention file\n"); - if(fscanf(dat, "%*[^<]") != 0) { // needs to be separate line because start of file - ERR_CRITICAL("fscanf failed in ReadInterventions\n"); - } - if(fscanf(dat, "<%[^>]", txt) != 1) { - ERR_CRITICAL("fscanf failed in ReadInterventions\n"); - } - if (strcmp(txt, "\?xml version=\"1.0\" encoding=\"ISO-8859-1\"\?") != 0) ERR_CRITICAL("Intervention file not XML.\n"); - if(fscanf(dat, "%*[^<]<%[^>]", txt) != 1) { - ERR_CRITICAL("fscanf failed in ReadInterventions\n"); - } - if (strcmp(txt, "InterventionSettings") != 0) ERR_CRITICAL("Intervention has no top level.\n"); + if (!(dat = fopen(IntFile, "rb"))) + ERR_CRITICAL("Unable to open intervention file\n"); + if (fscanf(dat, "%*[^<]") != 0) + { // needs to be separate line because start of file + ERR_CRITICAL("fscanf failed in ReadInterventions\n"); + } + if (fscanf(dat, "<%[^>]", txt) != 1) + { + ERR_CRITICAL("fscanf failed in ReadInterventions\n"); + } + if (strcmp(txt, "\?xml version=\"1.0\" encoding=\"ISO-8859-1\"\?") != 0) + ERR_CRITICAL("Intervention file not XML.\n"); + if (fscanf(dat, "%*[^<]<%[^>]", txt) != 1) + { + ERR_CRITICAL("fscanf failed in ReadInterventions\n"); + } + if (strcmp(txt, "InterventionSettings") != 0) + ERR_CRITICAL("Intervention has no top level.\n"); ni = 0; while (!feof(dat)) { - if(fscanf(dat, "%*[^<]<%[^>]", txt) != 1) { - ERR_CRITICAL("fscanf failed in ReadInterventions\n"); - } + if (fscanf(dat, "%*[^<]<%[^>]", txt) != 1) + { + ERR_CRITICAL("fscanf failed in ReadInterventions\n"); + } if (strcmp(txt, "intervention") == 0) { ni++; - if(fscanf(dat, "%*[^<]<%[^>]", txt) != 1) { - ERR_CRITICAL("fscanf failed in ReadInterventions\n"); - } - if (strcmp(txt, "parameters") != 0) ERR_CRITICAL("Incomplete intervention parameter specification in intervention file\n"); - if (!GetXMLNode(dat, "Type", "parameters", txt, 1)) ERR_CRITICAL("Incomplete intervention parameter specification in intervention file\n"); + if (fscanf(dat, "%*[^<]<%[^>]", txt) != 1) + { + ERR_CRITICAL("fscanf failed in ReadInterventions\n"); + } + if (strcmp(txt, "parameters") != 0) + ERR_CRITICAL("Incomplete intervention parameter specification in intervention file\n"); + if (!GetXMLNode(dat, "Type", "parameters", txt, 1)) + ERR_CRITICAL("Incomplete intervention parameter specification in intervention file\n"); if (strcmp(txt, "Treatment") == 0) CurInterv.InterventionType = 0; else if (strcmp(txt, "Vaccination") == 0) @@ -2105,31 +3507,40 @@ void ReadInterventions(char* IntFile) CurInterv.InterventionType = 5; else sscanf(txt, "%i", &CurInterv.InterventionType); - if (!GetXMLNode(dat, "AUThresh", "parameters", txt, 1)) ERR_CRITICAL("Incomplete intervention parameter specification in intervention file\n"); + if (!GetXMLNode(dat, "AUThresh", "parameters", txt, 1)) + ERR_CRITICAL("Incomplete intervention parameter specification in intervention file\n"); sscanf(txt, "%i", &CurInterv.DoAUThresh); - if (!GetXMLNode(dat, "StartTime", "parameters", txt, 1)) ERR_CRITICAL("Incomplete intervention parameter specification in intervention file\n"); + if (!GetXMLNode(dat, "StartTime", "parameters", txt, 1)) + ERR_CRITICAL("Incomplete intervention parameter specification in intervention file\n"); sscanf(txt, "%lf", &CurInterv.StartTime); startt = CurInterv.StartTime; - if (!GetXMLNode(dat, "StopTime", "parameters", txt, 1)) ERR_CRITICAL("Incomplete intervention parameter specification in intervention file\n"); + if (!GetXMLNode(dat, "StopTime", "parameters", txt, 1)) + ERR_CRITICAL("Incomplete intervention parameter specification in intervention file\n"); sscanf(txt, "%lf", &CurInterv.StopTime); stopt = CurInterv.StopTime; - if (!GetXMLNode(dat, "MinDuration", "parameters", txt, 1)) ERR_CRITICAL("Incomplete intervention parameter specification in intervention file\n"); + if (!GetXMLNode(dat, "MinDuration", "parameters", txt, 1)) + ERR_CRITICAL("Incomplete intervention parameter specification in intervention file\n"); sscanf(txt, "%lf", &CurInterv.MinDuration); CurInterv.MinDuration *= DAYS_PER_YEAR; - if (!GetXMLNode(dat, "RepeatInterval", "parameters", txt, 1)) ERR_CRITICAL("Incomplete intervention parameter specification in intervention file\n"); + if (!GetXMLNode(dat, "RepeatInterval", "parameters", txt, 1)) + ERR_CRITICAL("Incomplete intervention parameter specification in intervention file\n"); sscanf(txt, "%lf", &CurInterv.RepeatInterval); CurInterv.RepeatInterval *= DAYS_PER_YEAR; - if (!GetXMLNode(dat, "MaxPrevAtStart", "parameters", txt, 1)) ERR_CRITICAL("Incomplete intervention parameter specification in intervention file\n"); + if (!GetXMLNode(dat, "MaxPrevAtStart", "parameters", txt, 1)) + ERR_CRITICAL("Incomplete intervention parameter specification in intervention file\n"); sscanf(txt, "%lf", &CurInterv.StartThresholdHigh); - if (!GetXMLNode(dat, "MinPrevAtStart", "parameters", txt, 1)) ERR_CRITICAL("Incomplete intervention parameter specification in intervention file\n"); + if (!GetXMLNode(dat, "MinPrevAtStart", "parameters", txt, 1)) + ERR_CRITICAL("Incomplete intervention parameter specification in intervention file\n"); sscanf(txt, "%lf", &CurInterv.StartThresholdLow); - if (!GetXMLNode(dat, "MaxPrevAtStop", "parameters", txt, 1)) ERR_CRITICAL("Incomplete intervention parameter specification in intervention file\n"); + if (!GetXMLNode(dat, "MaxPrevAtStop", "parameters", txt, 1)) + ERR_CRITICAL("Incomplete intervention parameter specification in intervention file\n"); sscanf(txt, "%lf", &CurInterv.StopThreshold); if (GetXMLNode(dat, "NoStartAfterMinDur", "parameters", txt, 1)) sscanf(txt, "%i", &CurInterv.NoStartAfterMin); else CurInterv.NoStartAfterMin = 0; - if (!GetXMLNode(dat, "Level", "parameters", txt, 1)) ERR_CRITICAL("Incomplete intervention parameter specification in intervention file\n"); + if (!GetXMLNode(dat, "Level", "parameters", txt, 1)) + ERR_CRITICAL("Incomplete intervention parameter specification in intervention file\n"); sscanf(txt, "%lf", &CurInterv.Level); if (GetXMLNode(dat, "LevelCellVar", "parameters", txt, 1)) sscanf(txt, "%lf", &CurInterv.LevelCellVar); @@ -2156,24 +3567,32 @@ void ReadInterventions(char* IntFile) else CurInterv.TimeOffset = 0; - if (!GetXMLNode(dat, "MaxRounds", "parameters", txt, 1)) ERR_CRITICAL("Incomplete intervention parameter specification in intervention file\n"); + if (!GetXMLNode(dat, "MaxRounds", "parameters", txt, 1)) + ERR_CRITICAL("Incomplete intervention parameter specification in intervention file\n"); sscanf(txt, "%u", &CurInterv.MaxRounds); - if (!GetXMLNode(dat, "MaxResource", "parameters", txt, 1)) ERR_CRITICAL("Incomplete intervention parameter specification in intervention file\n"); + if (!GetXMLNode(dat, "MaxResource", "parameters", txt, 1)) + ERR_CRITICAL("Incomplete intervention parameter specification in intervention file\n"); sscanf(txt, "%u", &CurInterv.MaxResource); if (GetXMLNode(dat, "NumSequentialReplicas", "parameters", txt, 1)) sscanf(txt, "%i", &nsr); else nsr = 0; - do { - if(fscanf(dat, "%*[^<]<%[^>]", txt) != 1) { - ERR_CRITICAL("fscanf failed in ReadInterventions\n"); - } - } while ((strcmp(txt, "/intervention") != 0) && (strcmp(txt, "/parameters") != 0) && (!feof(dat))); - if (strcmp(txt, "/parameters") != 0) ERR_CRITICAL("Incomplete intervention parameter specification in intervention file\n"); - if(fscanf(dat, "%*[^<]<%[^>]", txt) != 1) { - ERR_CRITICAL("fscanf failed in ReadInterventions\n"); - } - if ((strcmp(txt, "adunits") != 0) && (strcmp(txt, "countries") != 0)) ERR_CRITICAL("Incomplete adunits/countries specification in intervention file\n"); + do + { + if (fscanf(dat, "%*[^<]<%[^>]", txt) != 1) + { + ERR_CRITICAL("fscanf failed in ReadInterventions\n"); + } + } while ((strcmp(txt, "/intervention") != 0) && (strcmp(txt, "/parameters") != 0) && + (!feof(dat))); + if (strcmp(txt, "/parameters") != 0) + ERR_CRITICAL("Incomplete intervention parameter specification in intervention file\n"); + if (fscanf(dat, "%*[^<]<%[^>]", txt) != 1) + { + ERR_CRITICAL("fscanf failed in ReadInterventions\n"); + } + if ((strcmp(txt, "adunits") != 0) && (strcmp(txt, "countries") != 0)) + ERR_CRITICAL("Incomplete adunits/countries specification in intervention file\n"); if (strcmp(txt, "adunits") == 0) { while (GetXMLNode(dat, "A", "adunits", buf, 0)) @@ -2182,10 +3601,12 @@ void ReadInterventions(char* IntFile) j = atoi(txt); if (j == 0) { - f = 1; au = -1; + f = 1; + au = -1; do { - au++; f = strcmp(txt, AdUnits[au].ad_name); + au++; + f = strcmp(txt, AdUnits[au].ad_name); } while ((f) && (au < P.NumAdunits)); if (!f) { @@ -2198,8 +3619,10 @@ void ReadInterventions(char* IntFile) { AdUnits[au].InterventionList[AdUnits[au].NI] = CurInterv; AdUnits[au].InterventionList[AdUnits[au].NI].Level = r; - AdUnits[au].InterventionList[AdUnits[au].NI].StartTime = startt + ((double)k) * (stopt - startt); - AdUnits[au].InterventionList[AdUnits[au].NI].StopTime = stopt + ((double)k) * (stopt - startt); + AdUnits[au].InterventionList[AdUnits[au].NI].StartTime = + startt + ((double)k) * (stopt - startt); + AdUnits[au].InterventionList[AdUnits[au].NI].StopTime = + stopt + ((double)k) * (stopt - startt); AdUnits[au].NI++; } } @@ -2219,8 +3642,10 @@ void ReadInterventions(char* IntFile) { AdUnits[au].InterventionList[AdUnits[au].NI] = CurInterv; AdUnits[au].InterventionList[AdUnits[au].NI].Level = r; - AdUnits[au].InterventionList[AdUnits[au].NI].StartTime = startt + ((double)k) * (stopt - startt); - AdUnits[au].InterventionList[AdUnits[au].NI].StopTime = stopt + ((double)k) * (stopt - startt); + AdUnits[au].InterventionList[AdUnits[au].NI].StartTime = + startt + ((double)k) * (stopt - startt); + AdUnits[au].InterventionList[AdUnits[au].NI].StopTime = + stopt + ((double)k) * (stopt - startt); AdUnits[au].NI++; } } @@ -2235,7 +3660,8 @@ void ReadInterventions(char* IntFile) sscanf(buf, "%s", txt); j = atoi(txt); for (au = 0; au < P.NumAdunits; au++) - if (((j == 0) && (strcmp(txt, AdUnits[au].cnt_name) == 0)) || ((j > 0) && (j == AdUnits[au].cnt_id))) + if (((j == 0) && (strcmp(txt, AdUnits[au].cnt_name) == 0)) || + ((j > 0) && (j == AdUnits[au].cnt_id))) { r = CurInterv.Level + (2.0 * ranf() - 1) * CurInterv.LevelAUVar + s; if ((CurInterv.Level < 1) && (r > 1)) @@ -2246,27 +3672,34 @@ void ReadInterventions(char* IntFile) { AdUnits[au].InterventionList[AdUnits[au].NI] = CurInterv; AdUnits[au].InterventionList[AdUnits[au].NI].Level = r; - AdUnits[au].InterventionList[AdUnits[au].NI].StartTime = startt + ((double)k) * (stopt - startt); - AdUnits[au].InterventionList[AdUnits[au].NI].StopTime = stopt + ((double)k) * (stopt - startt); + AdUnits[au].InterventionList[AdUnits[au].NI].StartTime = + startt + ((double)k) * (stopt - startt); + AdUnits[au].InterventionList[AdUnits[au].NI].StopTime = + stopt + ((double)k) * (stopt - startt); AdUnits[au].NI++; } } } } - if(fscanf(dat, "%*[^<]<%[^>]", txt) != 1) { - ERR_CRITICAL("fscanf failed in ReadInterventions\n"); - } - if (strcmp(txt, "/intervention") != 0) ERR_CRITICAL("Incorrect intervention specification in intervention file\n"); + if (fscanf(dat, "%*[^<]<%[^>]", txt) != 1) + { + ERR_CRITICAL("fscanf failed in ReadInterventions\n"); + } + if (strcmp(txt, "/intervention") != 0) + ERR_CRITICAL("Incorrect intervention specification in intervention file\n"); } } - if (strcmp(txt, "/InterventionSettings") != 0) ERR_CRITICAL("Intervention has no top level closure.\n"); + if (strcmp(txt, "/InterventionSettings") != 0) + ERR_CRITICAL("Intervention has no top level closure.\n"); fprintf(stderr, "%i interventions read\n", ni); fclose(dat); } -int GetXMLNode(FILE* dat, const char* NodeName, const char* ParentName, char* Value, int ResetFilePos) +int GetXMLNode(FILE *dat, const char *NodeName, const char *ParentName, char *Value, + int ResetFilePos) { - // ResetFilePos=1 leaves dat cursor in same position as when function was called. 0 leaves it at end of NodeName closure - // GetXMLNode returns 1 if NodeName found, 0 otherwise. If NodeName not found, ParentName closure must be + // ResetFilePos=1 leaves dat cursor in same position as when function was called. 0 leaves it at + // end of NodeName closure GetXMLNode returns 1 if NodeName found, 0 otherwise. If NodeName not + // found, ParentName closure must be char buf[65536], CloseNode[2048], CloseParent[2048]; int CurPos, ret; @@ -2275,57 +3708,73 @@ int GetXMLNode(FILE* dat, const char* NodeName, const char* ParentName, char* Va CurPos = ftell(dat); do { - if(fscanf(dat, "%*[^<]<%[^>]", buf) != 1) { - ERR_CRITICAL("fscanf failed in GetXMLNode"); - } + if (fscanf(dat, "%*[^<]<%[^>]", buf) != 1) + { + ERR_CRITICAL("fscanf failed in GetXMLNode"); + } } while ((strcmp(buf, CloseParent) != 0) && (strcmp(buf, NodeName) != 0) && (!feof(dat))); if (strcmp(buf, CloseParent) == 0) ret = 0; else { - if (strcmp(buf, NodeName) != 0) ERR_CRITICAL("Incomplete node specification in XML file\n"); - if(fscanf(dat, ">%[^<]", buf) != 1) { - ERR_CRITICAL("fscanf failed in GetXMLNode"); - } - if (strlen(buf) < 2048) strcpy(Value, buf); + if (strcmp(buf, NodeName) != 0) + ERR_CRITICAL("Incomplete node specification in XML file\n"); + if (fscanf(dat, ">%[^<]", buf) != 1) + { + ERR_CRITICAL("fscanf failed in GetXMLNode"); + } + if (strlen(buf) < 2048) + strcpy(Value, buf); // fprintf(stderr,"# %s=%s\n",NodeName,Value); - if(fscanf(dat, "<%[^>]", buf) != 1) { - ERR_CRITICAL("fscanf failed in GetXMLNode"); - } + if (fscanf(dat, "<%[^>]", buf) != 1) + { + ERR_CRITICAL("fscanf failed in GetXMLNode"); + } sprintf(CloseNode, "/%s", NodeName); - if (strcmp(buf, CloseNode) != 0) ERR_CRITICAL("Incomplete node specification in XML file\n"); + if (strcmp(buf, CloseNode) != 0) + ERR_CRITICAL("Incomplete node specification in XML file\n"); ret = 1; } - if (ResetFilePos) fseek(dat, CurPos, 0); + if (ResetFilePos) + fseek(dat, CurPos, 0); return ret; } -void ReadAirTravel(char* AirTravelFile) +void ReadAirTravel(char *AirTravelFile) { int i, j, k, l; float sc, t, t2; - float* buf; + float *buf; double traf; char outname[1024]; - FILE* dat; + FILE *dat; fprintf(stderr, "Reading airport data...\nAirports with no connections = "); - if (!(dat = fopen(AirTravelFile, "rb"))) ERR_CRITICAL("Unable to open airport file\n"); - if(fscanf(dat, "%i %i", &P.Nairports, &P.Air_popscale) != 2) { - ERR_CRITICAL("fscanf failed in void ReadAirTravel\n"); - } + if (!(dat = fopen(AirTravelFile, "rb"))) + ERR_CRITICAL("Unable to open airport file\n"); + if (fscanf(dat, "%i %i", &P.Nairports, &P.Air_popscale) != 2) + { + ERR_CRITICAL("fscanf failed in void ReadAirTravel\n"); + } sc = (float)((double)P.PopSize / (double)P.Air_popscale); - if (P.Nairports > MAX_AIRPORTS) ERR_CRITICAL("Too many airports\n"); - if (P.Nairports < 2) ERR_CRITICAL("Too few airports\n"); - if (!(buf = (float*)calloc(P.Nairports + 1, sizeof(float)))) ERR_CRITICAL("Unable to allocate airport storage\n"); - if (!(Airports = (Airport*)calloc(P.Nairports, sizeof(Airport)))) ERR_CRITICAL("Unable to allocate airport storage\n"); + if (P.Nairports > MAX_AIRPORTS) + ERR_CRITICAL("Too many airports\n"); + if (P.Nairports < 2) + ERR_CRITICAL("Too few airports\n"); + if (!(buf = (float *)calloc(P.Nairports + 1, sizeof(float)))) + ERR_CRITICAL("Unable to allocate airport storage\n"); + if (!(Airports = (Airport *)calloc(P.Nairports, sizeof(Airport)))) + ERR_CRITICAL("Unable to allocate airport storage\n"); for (i = 0; i < P.Nairports; i++) { - if(fscanf(dat, "%f %f %lf", &(Airports[i].loc.x), &(Airports[i].loc.y), &traf) != 3) { - ERR_CRITICAL("fscanf failed in void ReadAirTravel\n"); - } + if (fscanf(dat, "%f %f %lf", &(Airports[i].loc.x), &(Airports[i].loc.y), &traf) != 3) + { + ERR_CRITICAL("fscanf failed in void ReadAirTravel\n"); + } traf *= (P.AirportTrafficScale * sc); - if ((Airports[i].loc.x < P.SpatialBoundingBox[0]) || (Airports[i].loc.x >= P.SpatialBoundingBox[2]) - || (Airports[i].loc.y < P.SpatialBoundingBox[1]) || (Airports[i].loc.y >= P.SpatialBoundingBox[3])) + if ((Airports[i].loc.x < P.SpatialBoundingBox[0]) || + (Airports[i].loc.x >= P.SpatialBoundingBox[2]) || + (Airports[i].loc.y < P.SpatialBoundingBox[1]) || + (Airports[i].loc.y >= P.SpatialBoundingBox[3])) { Airports[i].loc.x = Airports[i].loc.y = -1; Airports[i].total_traffic = 0; @@ -2339,16 +3788,24 @@ void ReadAirTravel(char* AirTravelFile) t = 0; for (j = k = 0; j < P.Nairports; j++) { - if(fscanf(dat, "%f", buf + j) != 1) { - ERR_CRITICAL("fscanf failed in void ReadAirTravel\n"); - } - if (buf[j] > 0) { k++; t += buf[j]; } + if (fscanf(dat, "%f", buf + j) != 1) + { + ERR_CRITICAL("fscanf failed in void ReadAirTravel\n"); + } + if (buf[j] > 0) + { + k++; + t += buf[j]; + } } Airports[i].num_connected = k; if (Airports[i].num_connected > 0) { - if (!(Airports[i].prop_traffic = (float*)calloc(Airports[i].num_connected, sizeof(float)))) ERR_CRITICAL("Unable to allocate airport storage\n"); - if (!(Airports[i].conn_airports = (unsigned short int*) calloc(Airports[i].num_connected, sizeof(unsigned short int)))) ERR_CRITICAL("Unable to allocate airport storage\n"); + if (!(Airports[i].prop_traffic = (float *)calloc(Airports[i].num_connected, sizeof(float)))) + ERR_CRITICAL("Unable to allocate airport storage\n"); + if (!(Airports[i].conn_airports = (unsigned short int *)calloc(Airports[i].num_connected, + sizeof(unsigned short int)))) + ERR_CRITICAL("Unable to allocate airport storage\n"); for (j = k = 0; j < P.Nairports; j++) if (buf[j] > 0) { @@ -2371,82 +3828,93 @@ void ReadAirTravel(char* AirTravelFile) for (i = 0; i < P.Nairports; i++) { /* fprintf(stderr,"(%f %i|",Airports[i].total_traffic,Airports[i].num_connected); - */ t = 0; k = 0; - for (j = Airports[i].num_connected - 1; j >= 0; j--) - { - if ((Airports[i].prop_traffic[j] > 0) && (Airports[Airports[i].conn_airports[j]].total_traffic == 0)) + */ + t = 0; + k = 0; + for (j = Airports[i].num_connected - 1; j >= 0; j--) { - t += Airports[i].prop_traffic[j]; - Airports[i].num_connected--; - if (j < Airports[i].num_connected) + if ((Airports[i].prop_traffic[j] > 0) && + (Airports[Airports[i].conn_airports[j]].total_traffic == 0)) { - Airports[i].prop_traffic[j] = Airports[i].prop_traffic[Airports[i].num_connected]; - Airports[i].conn_airports[j] = Airports[i].conn_airports[Airports[i].num_connected]; + t += Airports[i].prop_traffic[j]; + Airports[i].num_connected--; + if (j < Airports[i].num_connected) + { + Airports[i].prop_traffic[j] = Airports[i].prop_traffic[Airports[i].num_connected]; + Airports[i].conn_airports[j] = Airports[i].conn_airports[Airports[i].num_connected]; + } + Airports[i].prop_traffic[Airports[i].num_connected] = 0; + Airports[i].conn_airports[Airports[i].num_connected] = 0; } - Airports[i].prop_traffic[Airports[i].num_connected] = 0; - Airports[i].conn_airports[Airports[i].num_connected] = 0; + else if (Airports[i].prop_traffic[j] > 0) + k = 1; } - else if (Airports[i].prop_traffic[j] > 0) - k = 1; - } - /* fprintf(stderr,"%f %i ",t,k); - */ t = 1.0f - t; - if (k) - { - Airports[i].total_traffic *= t; - t2 = 0; - for (j = 0; j < Airports[i].num_connected; j++) + /* fprintf(stderr,"%f %i ",t,k); + */ + t = 1.0f - t; + if (k) { - Airports[i].prop_traffic[j] = t2 + Airports[i].prop_traffic[j]; - t2 = Airports[i].prop_traffic[j]; + Airports[i].total_traffic *= t; + t2 = 0; + for (j = 0; j < Airports[i].num_connected; j++) + { + Airports[i].prop_traffic[j] = t2 + Airports[i].prop_traffic[j]; + t2 = Airports[i].prop_traffic[j]; + } + for (j = 0; j < Airports[i].num_connected; j++) + Airports[i].prop_traffic[j] /= t2; + /* if((Airports[i].num_connected>0)&&(Airports[i].prop_traffic[Airports[i].num_connected-1]!=1)) + fprintf(stderr,"<%f> ",Airports[i].prop_traffic[Airports[i].num_connected-1]); + */ } - for (j = 0; j < Airports[i].num_connected; j++) - Airports[i].prop_traffic[j] /= t2; - /* if((Airports[i].num_connected>0)&&(Airports[i].prop_traffic[Airports[i].num_connected-1]!=1)) - fprintf(stderr,"<%f> ",Airports[i].prop_traffic[Airports[i].num_connected-1]); - */ - } - else - { - Airports[i].total_traffic = 0; Airports[i].num_connected = 0; - } - if (Airports[i].num_connected > 0) - { - for (j = k = 0; k < 128; k++) + else { - t = (float)((double)k / 128); - while (Airports[i].prop_traffic[j] < t) j++; - Airports[i].Inv_prop_traffic[k] = j; + Airports[i].total_traffic = 0; + Airports[i].num_connected = 0; } - Airports[i].Inv_prop_traffic[128] = Airports[i].num_connected - 1; - } - /* fprintf(stderr,"%f) ",Airports[i].total_traffic); - */ + if (Airports[i].num_connected > 0) + { + for (j = k = 0; k < 128; k++) + { + t = (float)((double)k / 128); + while (Airports[i].prop_traffic[j] < t) + j++; + Airports[i].Inv_prop_traffic[k] = j; + } + Airports[i].Inv_prop_traffic[128] = Airports[i].num_connected - 1; + } + /* fprintf(stderr,"%f) ",Airports[i].total_traffic); + */ } fprintf(stderr, "Airport data clipped OK.\n"); - for (i = 0; i < MAX_DIST; i++) AirTravelDist[i] = 0; + for (i = 0; i < MAX_DIST; i++) + AirTravelDist[i] = 0; for (i = 0; i < P.Nairports; i++) if (Airports[i].total_traffic > 0) { for (j = 0; j < Airports[i].num_connected; j++) { k = (int)Airports[i].conn_airports[j]; - traf = floor(sqrt(dist2_raw(Airports[i].loc.x, Airports[i].loc.y, Airports[k].loc.x, Airports[k].loc.y)) / OUTPUT_DIST_SCALE); + traf = floor(sqrt(dist2_raw(Airports[i].loc.x, Airports[i].loc.y, Airports[k].loc.x, + Airports[k].loc.y)) / + OUTPUT_DIST_SCALE); l = (int)traf; - //fprintf(stderr,"%(%i) ",l); + // fprintf(stderr,"%(%i) ",l); if (l < MAX_DIST) AirTravelDist[l] += Airports[i].total_traffic * Airports[i].prop_traffic[j]; } } sprintf(outname, "%s.airdist.xls", OutFile); - if (!(dat = fopen(outname, "wb"))) ERR_CRITICAL("Unable to open air travel output file\n"); + if (!(dat = fopen(outname, "wb"))) + ERR_CRITICAL("Unable to open air travel output file\n"); fprintf(dat, "dist\tfreq\n"); for (i = 0; i < MAX_DIST; i++) fprintf(dat, "%i\t%.10f\n", i, AirTravelDist[i]); fclose(dat); } -void InitModel(int run) // passing run number so we can save run number in the infection event log: ggilani - 15/10/2014 +void InitModel(int run) // passing run number so we can save run number in the infection event log: + // ggilani - 15/10/2014 { int nim; int NumSeedingInfections_byLocation[MAX_NUM_SEED_LOCATIONS]; @@ -2454,7 +3922,7 @@ void InitModel(int run) // passing run number so we can save run number in the i if (P.OutputBitmap) { #ifdef _WIN32 - //if (P.OutputBitmap == 1) + // if (P.OutputBitmap == 1) //{ // char buf[200]; // sprintf(buf, "%s.ge" DIRECTORY_SEPARATOR "%s.avi", OutFile, OutFile); @@ -2469,33 +3937,41 @@ void InitModel(int run) // passing run number so we can save run number in the i ns = 0; State.S = P.PopSize; State.L = State.I = State.R = State.D = 0; - State.cumI = State.cumR = State.cumC = State.cumFC = State.cumCT = State.cumCC = State.cumTC = State.cumD = State.cumDC = State.trigDetectedCases = State.DCT = State.cumDCT - = State.cumTG = State.cumSI = State.nTG = State.cumHQ = State.cumAC = State.cumAH = State.cumAA = State.cumACS = State.cumAPC = State.cumAPA = State.cumAPCS = 0; - State.cumT = State.cumUT = State.cumTP = State.cumV = State.sumRad2 = State.maxRad2 = State.cumV_daily = State.cumVG = 0; //added State.cumVG + State.cumI = State.cumR = State.cumC = State.cumFC = State.cumCT = State.cumCC = State.cumTC = + State.cumD = State.cumDC = State.trigDetectedCases = State.DCT = State.cumDCT = State.cumTG = + State.cumSI = State.nTG = State.cumHQ = State.cumAC = State.cumAH = State.cumAA = + State.cumACS = State.cumAPC = State.cumAPA = State.cumAPCS = 0; + State.cumT = State.cumUT = State.cumTP = State.cumV = State.sumRad2 = State.maxRad2 = + State.cumV_daily = State.cumVG = 0; // added State.cumVG State.mvacc_cum = 0; if (P.DoSeverity) { - State.Mild = State.ILI = State.SARI = State.Critical = State.CritRecov = 0; - State.cumMild = State.cumILI = State.cumSARI = State.cumCritical = State.cumCritRecov = 0; + State.Mild = State.ILI = State.SARI = State.Critical = State.CritRecov = 0; + State.cumMild = State.cumILI = State.cumSARI = State.cumCritical = State.cumCritRecov = 0; State.cumDeath_ILI = State.cumDeath_SARI = State.cumDeath_Critical = 0; if (P.DoAdUnits) for (int AdminUnit = 0; AdminUnit <= P.NumAdunits; AdminUnit++) { - State.Mild_adunit[AdminUnit] = State.ILI_adunit[AdminUnit] = - State.SARI_adunit[AdminUnit] = State.Critical_adunit[AdminUnit] = State.CritRecov_adunit[AdminUnit] = - State.cumMild_adunit[AdminUnit] = State.cumILI_adunit[AdminUnit] = - State.cumSARI_adunit[AdminUnit] = State.cumCritical_adunit[AdminUnit] = State.cumCritRecov_adunit[AdminUnit] = - State.cumDeath_ILI_adunit[AdminUnit] = State.cumDeath_SARI_adunit[AdminUnit] = State.cumDeath_Critical_adunit[AdminUnit] = - State.cumD_adunit[AdminUnit] = 0; + State.Mild_adunit[AdminUnit] = State.ILI_adunit[AdminUnit] = State.SARI_adunit[AdminUnit] = + State.Critical_adunit[AdminUnit] = State.CritRecov_adunit[AdminUnit] = + State.cumMild_adunit[AdminUnit] = State.cumILI_adunit[AdminUnit] = + State.cumSARI_adunit[AdminUnit] = State.cumCritical_adunit[AdminUnit] = + State.cumCritRecov_adunit[AdminUnit] = + State.cumDeath_ILI_adunit[AdminUnit] = + State.cumDeath_SARI_adunit[AdminUnit] = + State.cumDeath_Critical_adunit[AdminUnit] = + State.cumD_adunit[AdminUnit] = 0; } for (int AgeGroup = 0; AgeGroup < NUM_AGE_GROUPS; AgeGroup++) { - State.Mild_age[AgeGroup] = State.ILI_age[AgeGroup] = - State.SARI_age[AgeGroup] = State.Critical_age[AgeGroup] = State.CritRecov_age[AgeGroup] = - State.cumMild_age[AgeGroup] = State.cumILI_age[AgeGroup] = - State.cumSARI_age[AgeGroup] = State.cumCritical_age[AgeGroup] = State.cumCritRecov_age[AgeGroup] = - State.cumDeath_ILI_age[AgeGroup] = State.cumDeath_SARI_age[AgeGroup] = State.cumDeath_Critical_age[AgeGroup] = 0; + State.Mild_age[AgeGroup] = State.ILI_age[AgeGroup] = State.SARI_age[AgeGroup] = + State.Critical_age[AgeGroup] = State.CritRecov_age[AgeGroup] = + State.cumMild_age[AgeGroup] = State.cumILI_age[AgeGroup] = + State.cumSARI_age[AgeGroup] = State.cumCritical_age[AgeGroup] = + State.cumCritRecov_age[AgeGroup] = State.cumDeath_ILI_age[AgeGroup] = + State.cumDeath_SARI_age[AgeGroup] = + State.cumDeath_Critical_age[AgeGroup] = 0; } } if (P.DoAdUnits && P.OutputAdUnitAge) @@ -2503,74 +3979,106 @@ void InitModel(int run) // passing run number so we can save run number in the i for (int AgeGroup = 0; AgeGroup < NUM_AGE_GROUPS; AgeGroup++) { State.prevInf_age_adunit[AgeGroup][Adunit] = 0; - State.cumInf_age_adunit [AgeGroup][Adunit] = 0; + State.cumInf_age_adunit[AgeGroup][Adunit] = 0; } - for (int i = 0; i < NUM_AGE_GROUPS; i++) State.cumCa[i] = State.cumIa[i] = State.cumDa[i] = 0; - for (int i = 0; i < 2; i++) State.cumC_keyworker[i] = State.cumI_keyworker[i] = State.cumT_keyworker[i] = 0; - for (int i = 0; i < NUM_PLACE_TYPES; i++) State.NumPlacesClosed[i] = 0; - for (int i = 0; i < INFECT_TYPE_MASK; i++) State.cumItype[i] = 0; - //initialise cumulative case counts per country to zero: ggilani 12/11/14 - for (int i = 0; i < MAX_COUNTRIES; i++) State.cumC_country[i] = 0; + for (int i = 0; i < NUM_AGE_GROUPS; i++) + State.cumCa[i] = State.cumIa[i] = State.cumDa[i] = 0; + for (int i = 0; i < 2; i++) + State.cumC_keyworker[i] = State.cumI_keyworker[i] = State.cumT_keyworker[i] = 0; + for (int i = 0; i < NUM_PLACE_TYPES; i++) + State.NumPlacesClosed[i] = 0; + for (int i = 0; i < INFECT_TYPE_MASK; i++) + State.cumItype[i] = 0; + // initialise cumulative case counts per country to zero: ggilani 12/11/14 + for (int i = 0; i < MAX_COUNTRIES; i++) + State.cumC_country[i] = 0; if (P.DoAdUnits) for (int i = 0; i <= P.NumAdunits; i++) { - State.cumI_adunit[i] = State.cumC_adunit[i] = State.cumD_adunit[i] = State.cumT_adunit[i] = State.cumH_adunit[i] = - State.cumDC_adunit[i] = State.cumCT_adunit[i] = State.cumCC_adunit[i] = State.trigDC_adunit[i] = State.DCT_adunit[i] = State.cumDCT_adunit[i] = 0; //added hospitalisation, added detected cases, contact tracing per adunit, cases who are contacts: ggilani 03/02/15, 15/06/17 + State.cumI_adunit[i] = State.cumC_adunit[i] = State.cumD_adunit[i] = State.cumT_adunit[i] = + State.cumH_adunit[i] = State.cumDC_adunit[i] = State.cumCT_adunit[i] = + State.cumCC_adunit[i] = State.trigDC_adunit[i] = State.DCT_adunit[i] = + State.cumDCT_adunit[i] = + 0; // added hospitalisation, added detected cases, contact tracing per adunit, + // cases who are contacts: ggilani 03/02/15, 15/06/17 AdUnits[i].place_close_trig = 0; - AdUnits[i].CaseIsolationTimeStart = AdUnits[i].HQuarantineTimeStart = AdUnits[i].DigitalContactTracingTimeStart = AdUnits[i].SocialDistanceTimeStart = AdUnits[i].PlaceCloseTimeStart = 1e10; - AdUnits[i].ndct = 0; //noone being digitally contact traced at beginning of run + AdUnits[i].CaseIsolationTimeStart = AdUnits[i].HQuarantineTimeStart = + AdUnits[i].DigitalContactTracingTimeStart = AdUnits[i].SocialDistanceTimeStart = + AdUnits[i].PlaceCloseTimeStart = 1e10; + AdUnits[i].ndct = 0; // noone being digitally contact traced at beginning of run } - //update state variables for storing contact distribution - for (int i = 0; i < MAX_CONTACTS+1; i++) State.contact_dist[i] = 0; + // update state variables for storing contact distribution + for (int i = 0; i < MAX_CONTACTS + 1; i++) + State.contact_dist[i] = 0; for (int j = 0; j < MAX_NUM_THREADS; j++) { StateT[j].L = StateT[j].I = StateT[j].R = StateT[j].D = 0; - StateT[j].cumI = StateT[j].cumR = StateT[j].cumC = StateT[j].cumFC = StateT[j].cumCT = StateT[j].cumCC = StateT[j].DCT = StateT[j].cumDCT - = StateT[j].cumTG = StateT[j].cumSI = StateT[j].nTG = StateT[j].cumTC = StateT[j].cumD = StateT[j].cumDC = StateT[j].cumHQ = StateT[j].cumAC - = StateT[j].cumACS = StateT[j].cumAH = StateT[j].cumAA = StateT[j].cumAPC = StateT[j].cumAPA = StateT[j].cumAPCS = 0; - StateT[j].cumT = StateT[j].cumUT = StateT[j].cumTP = StateT[j].cumV = StateT[j].sumRad2 = StateT[j].maxRad2 = StateT[j].cumV_daily = 0; - for (int i = 0; i < NUM_AGE_GROUPS; i++) StateT[j].cumCa[i] = StateT[j].cumIa[i] = StateT[j].cumDa[i] = 0; - for (int i = 0; i < 2; i++) StateT[j].cumC_keyworker[i] = StateT[j].cumI_keyworker[i] = StateT[j].cumT_keyworker[i] = 0; - for (int i = 0; i < NUM_PLACE_TYPES; i++) StateT[j].NumPlacesClosed[i] = 0; - for (int i = 0; i < INFECT_TYPE_MASK; i++) StateT[j].cumItype[i] = 0; - //initialise cumulative case counts per country per thread to zero: ggilani 12/11/14 - for (int i = 0; i < MAX_COUNTRIES; i++) StateT[j].cumC_country[i] = 0; + StateT[j].cumI = StateT[j].cumR = StateT[j].cumC = StateT[j].cumFC = StateT[j].cumCT = + StateT[j].cumCC = StateT[j].DCT = StateT[j].cumDCT = StateT[j].cumTG = StateT[j].cumSI = + StateT[j].nTG = StateT[j].cumTC = StateT[j].cumD = StateT[j].cumDC = StateT[j].cumHQ = + StateT[j].cumAC = StateT[j].cumACS = StateT[j].cumAH = StateT[j].cumAA = + StateT[j].cumAPC = StateT[j].cumAPA = StateT[j].cumAPCS = 0; + StateT[j].cumT = StateT[j].cumUT = StateT[j].cumTP = StateT[j].cumV = StateT[j].sumRad2 = + StateT[j].maxRad2 = StateT[j].cumV_daily = 0; + for (int i = 0; i < NUM_AGE_GROUPS; i++) + StateT[j].cumCa[i] = StateT[j].cumIa[i] = StateT[j].cumDa[i] = 0; + for (int i = 0; i < 2; i++) + StateT[j].cumC_keyworker[i] = StateT[j].cumI_keyworker[i] = StateT[j].cumT_keyworker[i] = 0; + for (int i = 0; i < NUM_PLACE_TYPES; i++) + StateT[j].NumPlacesClosed[i] = 0; + for (int i = 0; i < INFECT_TYPE_MASK; i++) + StateT[j].cumItype[i] = 0; + // initialise cumulative case counts per country per thread to zero: ggilani 12/11/14 + for (int i = 0; i < MAX_COUNTRIES; i++) + StateT[j].cumC_country[i] = 0; if (P.DoAdUnits) for (int i = 0; i <= P.NumAdunits; i++) - StateT[j].cumI_adunit[i] = StateT[j].cumC_adunit[i] = StateT[j].cumD_adunit[i] = StateT[j].cumT_adunit[i] = StateT[j].cumH_adunit[i] = StateT[j].cumDC_adunit[i] = - StateT[j].cumCT_adunit[i] = StateT[j].cumCC_adunit[i] = StateT[j].nct_queue[i] = StateT[j].cumDCT_adunit[i] = StateT[j].DCT_adunit[i] = StateT[j].ndct_queue[i] = 0; //added hospitalisation, detected cases, contact tracing per adunit, cases who are contacts: ggilani 03/02/15, 15/06/17 + StateT[j].cumI_adunit[i] = StateT[j].cumC_adunit[i] = StateT[j].cumD_adunit[i] = + StateT[j].cumT_adunit[i] = StateT[j].cumH_adunit[i] = StateT[j].cumDC_adunit[i] = + StateT[j].cumCT_adunit[i] = StateT[j].cumCC_adunit[i] = StateT[j].nct_queue[i] = + StateT[j].cumDCT_adunit[i] = StateT[j].DCT_adunit[i] = StateT[j].ndct_queue[i] = + 0; // added hospitalisation, detected cases, contact tracing per adunit, + // cases who are contacts: ggilani 03/02/15, 15/06/17 if (P.DoSeverity) { - StateT[j].Mild = StateT[j].ILI = StateT[j].SARI = StateT[j].Critical = StateT[j].CritRecov = 0; - StateT[j].cumMild = StateT[j].cumILI = StateT[j].cumSARI = StateT[j].cumCritical = StateT[j].cumCritRecov = 0; + StateT[j].Mild = StateT[j].ILI = StateT[j].SARI = StateT[j].Critical = StateT[j].CritRecov = + 0; + StateT[j].cumMild = StateT[j].cumILI = StateT[j].cumSARI = StateT[j].cumCritical = + StateT[j].cumCritRecov = 0; StateT[j].cumDeath_ILI = StateT[j].cumDeath_SARI = StateT[j].cumDeath_Critical = 0; for (int AdminUnit = 0; AdminUnit <= P.NumAdunits; AdminUnit++) { StateT[j].Mild_adunit[AdminUnit] = StateT[j].ILI_adunit[AdminUnit] = - StateT[j].SARI_adunit[AdminUnit] = StateT[j].Critical_adunit[AdminUnit] = StateT[j].CritRecov_adunit[AdminUnit] = - StateT[j].cumMild_adunit[AdminUnit] = StateT[j].cumILI_adunit[AdminUnit] = - StateT[j].cumSARI_adunit[AdminUnit] = StateT[j].cumCritical_adunit[AdminUnit] = StateT[j].cumCritRecov_adunit[AdminUnit] = - StateT[j].cumDeath_ILI_adunit[AdminUnit] = StateT[j].cumDeath_SARI_adunit[AdminUnit] = StateT[j].cumDeath_Critical_adunit[AdminUnit] = - StateT[j].cumD_adunit[AdminUnit] = 0; + StateT[j].SARI_adunit[AdminUnit] = StateT[j].Critical_adunit[AdminUnit] = + StateT[j].CritRecov_adunit[AdminUnit] = StateT[j].cumMild_adunit[AdminUnit] = + StateT[j].cumILI_adunit[AdminUnit] = StateT[j].cumSARI_adunit[AdminUnit] = + StateT[j].cumCritical_adunit[AdminUnit] = + StateT[j].cumCritRecov_adunit[AdminUnit] = + StateT[j].cumDeath_ILI_adunit[AdminUnit] = + StateT[j].cumDeath_SARI_adunit[AdminUnit] = + StateT[j].cumDeath_Critical_adunit[AdminUnit] = + StateT[j].cumD_adunit[AdminUnit] = 0; } for (int AgeGroup = 0; AgeGroup < NUM_AGE_GROUPS; AgeGroup++) { - StateT[j].Mild_age[AgeGroup] = StateT[j].ILI_age[AgeGroup] = - StateT[j].SARI_age[AgeGroup] = StateT[j].Critical_age[AgeGroup] = StateT[j].CritRecov_age[AgeGroup] = - StateT[j].cumMild_age[AgeGroup] = StateT[j].cumILI_age[AgeGroup] = - StateT[j].cumSARI_age[AgeGroup] = StateT[j].cumCritical_age[AgeGroup] = StateT[j].cumCritRecov_age[AgeGroup] = - StateT[j].cumDeath_ILI_age[AgeGroup] = StateT[j].cumDeath_SARI_age[AgeGroup] = StateT[j].cumDeath_Critical_age[AgeGroup] = 0; + StateT[j].Mild_age[AgeGroup] = StateT[j].ILI_age[AgeGroup] = StateT[j].SARI_age[AgeGroup] = + StateT[j].Critical_age[AgeGroup] = StateT[j].CritRecov_age[AgeGroup] = + StateT[j].cumMild_age[AgeGroup] = StateT[j].cumILI_age[AgeGroup] = + StateT[j].cumSARI_age[AgeGroup] = StateT[j].cumCritical_age[AgeGroup] = + StateT[j].cumCritRecov_age[AgeGroup] = + StateT[j].cumDeath_ILI_age[AgeGroup] = + StateT[j].cumDeath_SARI_age[AgeGroup] = + StateT[j].cumDeath_Critical_age[AgeGroup] = 0; } - } - //resetting thread specific parameters for storing contact distribution - for (int i = 0; i < MAX_CONTACTS+1; i++) StateT[j].contact_dist[i] = 0; - + // resetting thread specific parameters for storing contact distribution + for (int i = 0; i < MAX_CONTACTS + 1; i++) + StateT[j].contact_dist[i] = 0; } nim = 0; @@ -2580,39 +4088,45 @@ void InitModel(int run) // passing run number so we can save run number in the i for (int AgeGroup = 0; AgeGroup < NUM_AGE_GROUPS; AgeGroup++) { StateT[Thread].prevInf_age_adunit[AgeGroup][Adunit] = 0; - StateT[Thread].cumInf_age_adunit [AgeGroup][Adunit] = 0; + StateT[Thread].cumInf_age_adunit[AgeGroup][Adunit] = 0; } - -#pragma omp parallel for schedule(static,1) default(none) \ - shared(P, Hosts) +#pragma omp parallel for schedule(static, 1) default(none) shared(P, Hosts) for (int tn = 0; tn < P.NumThreads; tn++) - for (int k = tn; k < P.PopSize; k+= P.NumThreads) + for (int k = tn; k < P.PopSize; k += P.NumThreads) { Hosts[k].absent_start_time = USHRT_MAX - 1; Hosts[k].absent_stop_time = 0; - if (P.DoAirports) Hosts[k].PlaceLinks[P.HotelPlaceType] = -1; - Hosts[k].vacc_start_time = Hosts[k].treat_start_time = Hosts[k].quar_start_time = Hosts[k].isolation_start_time = Hosts[k].absent_start_time = Hosts[k].dct_start_time = Hosts[k].dct_trigger_time = USHRT_MAX - 1; + if (P.DoAirports) + Hosts[k].PlaceLinks[P.HotelPlaceType] = -1; + Hosts[k].vacc_start_time = Hosts[k].treat_start_time = Hosts[k].quar_start_time = + Hosts[k].isolation_start_time = Hosts[k].absent_start_time = Hosts[k].dct_start_time = + Hosts[k].dct_trigger_time = USHRT_MAX - 1; Hosts[k].treat_stop_time = Hosts[k].absent_stop_time = Hosts[k].dct_end_time = 0; Hosts[k].quar_comply = 2; Hosts[k].to_die = 0; Hosts[k].Travelling = 0; - Hosts[k].detected = 0; //set detected to zero initially: ggilani - 19/02/15 + Hosts[k].detected = 0; // set detected to zero initially: ggilani - 19/02/15 Hosts[k].detected_time = 0; Hosts[k].digitalContactTraced = 0; Hosts[k].inf = InfStat_Susceptible; Hosts[k].num_treats = 0; - Hosts[k].latent_time = Hosts[k].recovery_or_death_time = 0; //also set hospitalisation time to zero: ggilani 28/10/2014 + Hosts[k].latent_time = Hosts[k].recovery_or_death_time = + 0; // also set hospitalisation time to zero: ggilani 28/10/2014 Hosts[k].infector = -1; Hosts[k].infect_type = 0; Hosts[k].index_case_dct = 0; - Hosts[k].ProbAbsent =(float) ranf_mt(tn); - Hosts[k].ProbCare = (float) ranf_mt(tn); - Hosts[k].susc = (float)((P.DoPartialImmunity) ? (1.0 - P.InitialImmunity[HOST_AGE_GROUP(k)]) : 1.0); - if(P.SusceptibilitySD > 0) Hosts[k].susc *= (float) gen_gamma_mt(1 / (P.SusceptibilitySD * P.SusceptibilitySD), 1 / (P.SusceptibilitySD * P.SusceptibilitySD), tn); + Hosts[k].ProbAbsent = (float)ranf_mt(tn); + Hosts[k].ProbCare = (float)ranf_mt(tn); + Hosts[k].susc = + (float)((P.DoPartialImmunity) ? (1.0 - P.InitialImmunity[HOST_AGE_GROUP(k)]) : 1.0); + if (P.SusceptibilitySD > 0) + Hosts[k].susc *= (float)gen_gamma_mt(1 / (P.SusceptibilitySD * P.SusceptibilitySD), + 1 / (P.SusceptibilitySD * P.SusceptibilitySD), tn); if (P.DoSeverity) { - Hosts[k].SARI_time = USHRT_MAX - 1; //// think better to set to initialize to maximum possible value, but keep this way for now. + Hosts[k].SARI_time = USHRT_MAX - 1; //// think better to set to initialize to maximum + /// possible value, but keep this way for now. Hosts[k].Critical_time = USHRT_MAX - 1; Hosts[k].RecoveringFromCritical_time = USHRT_MAX - 1; Hosts[k].Severity_Current = Severity_Asymptomatic; @@ -2625,30 +4139,33 @@ void InitModel(int run) // passing run number so we can save run number in the i shared(P, Cells, Hosts, Households) for (int tn = 0; tn < P.NumThreads; tn++) { - for (int i = tn; i < P.NC; i+=P.NumThreads) + for (int i = tn; i < P.NC; i += P.NumThreads) { - if ((Cells[i].tot_treat != 0) || (Cells[i].tot_vacc != 0) || (Cells[i].S != Cells[i].n) || (Cells[i].D > 0) || (Cells[i].R > 0)) + if ((Cells[i].tot_treat != 0) || (Cells[i].tot_vacc != 0) || (Cells[i].S != Cells[i].n) || + (Cells[i].D > 0) || (Cells[i].R > 0)) { for (int j = 0; j < Cells[i].n; j++) { int k = Cells[i].members[j]; - Cells[i].susceptible[j] = k; //added this in here instead + Cells[i].susceptible[j] = k; // added this in here instead Hosts[k].listpos = j; } Cells[i].S = Cells[i].n; Cells[i].L = Cells[i].I = Cells[i].R = Cells[i].cumTC = Cells[i].D = 0; Cells[i].infected = Cells[i].latent = Cells[i].susceptible + Cells[i].S; Cells[i].tot_treat = Cells[i].tot_vacc = 0; - for (int l = 0; l < MAX_INTERVENTION_TYPES; l++) Cells[i].CurInterv[l] = -1; + for (int l = 0; l < MAX_INTERVENTION_TYPES; l++) + Cells[i].CurInterv[l] = -1; // Next loop needs to count down for DoImmune host list reordering to work - if(!P.DoPartialImmunity) + if (!P.DoPartialImmunity) for (int j = Cells[i].n - 1; j >= 0; j--) { int k = Cells[i].members[j]; if (P.DoWholeHouseholdImmunity) { - // note that this breaks determinism of runs if executed due to reordering of Cell members list each realisation + // note that this breaks determinism of runs if executed due to reordering of Cell + // members list each realisation if (P.InitialImmunity[0] != 0) { if (Households[Hosts[k].hh].FirstPerson == k) @@ -2665,9 +4182,11 @@ void InitModel(int run) // passing run number so we can save run number in the i else { int m = HOST_AGE_GROUP(k); - if ((P.InitialImmunity[m] == 1) || ((P.InitialImmunity[m] > 0) && (ranf_mt(tn) < P.InitialImmunity[m]))) + if ((P.InitialImmunity[m] == 1) || + ((P.InitialImmunity[m] > 0) && (ranf_mt(tn) < P.InitialImmunity[m]))) { - DoImmune(k); nim += 1; + DoImmune(k); + nim += 1; } } } @@ -2675,116 +4194,123 @@ void InitModel(int run) // passing run number so we can save run number in the i } } -#pragma omp parallel for schedule(static,500) default(none) \ - shared(P, Mcells, McellLookup) +#pragma omp parallel for schedule(static, 500) default(none) shared(P, Mcells, McellLookup) for (int l = 0; l < P.NMCP; l++) { int i = (int)(McellLookup[l] - Mcells); Mcells[i].vacc_start_time = Mcells[i].treat_start_time = USHRT_MAX - 1; Mcells[i].treat_end_time = 0; Mcells[i].treat_trig = Mcells[i].vacc_trig = Mcells[i].vacc = Mcells[i].treat = 0; - Mcells[i].place_trig = Mcells[i].move_trig = Mcells[i].socdist_trig = Mcells[i].keyworkerproph_trig = - Mcells[i].placeclose = Mcells[i].moverest = Mcells[i].socdist = Mcells[i].keyworkerproph = 0; + Mcells[i].place_trig = Mcells[i].move_trig = Mcells[i].socdist_trig = + Mcells[i].keyworkerproph_trig = Mcells[i].placeclose = Mcells[i].moverest = + Mcells[i].socdist = Mcells[i].keyworkerproph = 0; Mcells[i].move_start_time = USHRT_MAX - 1; - Mcells[i].place_end_time = Mcells[i].move_end_time = - Mcells[i].socdist_end_time = Mcells[i].keyworkerproph_end_time = 0; + Mcells[i].place_end_time = Mcells[i].move_end_time = Mcells[i].socdist_end_time = + Mcells[i].keyworkerproph_end_time = 0; } if (P.DoPlaces) -#pragma omp parallel for schedule(static,1) default(none) \ - shared(P, Places) +#pragma omp parallel for schedule(static, 1) default(none) shared(P, Places) for (int m = 0; m < P.PlaceTypeNum; m++) { - for(int l = 0; l < P.Nplace[m]; l++) + for (int l = 0; l < P.Nplace[m]; l++) { Places[m][l].close_start_time = USHRT_MAX - 1; Places[m][l].treat = Places[m][l].control_trig = 0; Places[m][l].treat_end_time = Places[m][l].close_end_time = 0; - Places[m][l].ProbClose = (float) ranf_mt(m); + Places[m][l].ProbClose = (float)ranf_mt(m); if (P.AbsenteeismPlaceClosure) { Places[m][l].AbsentLastUpdateTime = 0; - for (int i2 = 0; i2 < P.MaxAbsentTime; i2++) Places[m][l].Absent[i2] = 0; + for (int i2 = 0; i2 < P.MaxAbsentTime; i2++) + Places[m][l].Absent[i2] = 0; } } } //// **** //// **** //// **** Initialize Current effects //// **** soc dist - P.SocDistDurationCurrent = P.SocDistDuration; - P.SocDistSpatialEffectCurrent = P.SD_SpatialEffects_OverTime [0]; //// spatial - P.SocDistHouseholdEffectCurrent = P.SD_HouseholdEffects_OverTime[0]; //// household + P.SocDistDurationCurrent = P.SocDistDuration; + P.SocDistSpatialEffectCurrent = P.SD_SpatialEffects_OverTime[0]; //// spatial + P.SocDistHouseholdEffectCurrent = P.SD_HouseholdEffects_OverTime[0]; //// household for (int PlaceType = 0; PlaceType < P.PlaceTypeNum; PlaceType++) - P.SocDistPlaceEffectCurrent[PlaceType] = P.SD_PlaceEffects_OverTime[0][PlaceType]; //// place - P.SocDistCellIncThresh = P.SD_CellIncThresh_OverTime [0]; //// cell incidence threshold + P.SocDistPlaceEffectCurrent[PlaceType] = P.SD_PlaceEffects_OverTime[0][PlaceType]; //// place + P.SocDistCellIncThresh = P.SD_CellIncThresh_OverTime[0]; //// cell incidence threshold //// **** enhanced soc dist - P.EnhancedSocDistSpatialEffectCurrent = P.Enhanced_SD_SpatialEffects_OverTime [0]; //// spatial - P.EnhancedSocDistHouseholdEffectCurrent = P.Enhanced_SD_HouseholdEffects_OverTime [0]; //// household + P.EnhancedSocDistSpatialEffectCurrent = P.Enhanced_SD_SpatialEffects_OverTime[0]; //// spatial + P.EnhancedSocDistHouseholdEffectCurrent = + P.Enhanced_SD_HouseholdEffects_OverTime[0]; //// household for (int PlaceType = 0; PlaceType < P.PlaceTypeNum; PlaceType++) - P.EnhancedSocDistPlaceEffectCurrent[PlaceType] = P.Enhanced_SD_PlaceEffects_OverTime[0][PlaceType]; //// place + P.EnhancedSocDistPlaceEffectCurrent[PlaceType] = + P.Enhanced_SD_PlaceEffects_OverTime[0][PlaceType]; //// place //// **** case isolation - P.CaseIsolationEffectiveness = P.CI_SpatialAndPlaceEffects_OverTime [0]; //// spatial / place - P.CaseIsolationHouseEffectiveness = P.CI_HouseholdEffects_OverTime [0]; //// household - P.CaseIsolationProp = P.CI_Prop_OverTime [0]; //// compliance - P.CaseIsolation_CellIncThresh = P.CI_CellIncThresh_OverTime [0]; //// cell incidence threshold - + P.CaseIsolationEffectiveness = P.CI_SpatialAndPlaceEffects_OverTime[0]; //// spatial / place + P.CaseIsolationHouseEffectiveness = P.CI_HouseholdEffects_OverTime[0]; //// household + P.CaseIsolationProp = P.CI_Prop_OverTime[0]; //// compliance + P.CaseIsolation_CellIncThresh = P.CI_CellIncThresh_OverTime[0]; //// cell incidence threshold //// **** household quarantine - P.HQuarantineSpatialEffect = P.HQ_SpatialEffects_OverTime [0]; //// spatial - P.HQuarantineHouseEffect = P.HQ_HouseholdEffects_OverTime[0]; //// household + P.HQuarantineSpatialEffect = P.HQ_SpatialEffects_OverTime[0]; //// spatial + P.HQuarantineHouseEffect = P.HQ_HouseholdEffects_OverTime[0]; //// household for (int PlaceType = 0; PlaceType < P.PlaceTypeNum; PlaceType++) - P.HQuarantinePlaceEffect[PlaceType] = P.HQ_PlaceEffects_OverTime [0][PlaceType]; //// place - P.HQuarantinePropIndivCompliant = P.HQ_Individual_PropComply_OverTime [0]; //// individual compliance - P.HQuarantinePropHouseCompliant = P.HQ_Household_PropComply_OverTime [0]; //// household compliance - P.HHQuar_CellIncThresh = P.HQ_CellIncThresh_OverTime [0]; //// cell incidence threshold - + P.HQuarantinePlaceEffect[PlaceType] = P.HQ_PlaceEffects_OverTime[0][PlaceType]; //// place + P.HQuarantinePropIndivCompliant = + P.HQ_Individual_PropComply_OverTime[0]; //// individual compliance + P.HQuarantinePropHouseCompliant = P.HQ_Household_PropComply_OverTime[0]; //// household compliance + P.HHQuar_CellIncThresh = P.HQ_CellIncThresh_OverTime[0]; //// cell incidence threshold //// **** place closure - P.PlaceCloseSpatialRelContact = P.PC_SpatialEffects_OverTime [0]; //// spatial - P.PlaceCloseHouseholdRelContact = P.PC_HouseholdEffects_OverTime[0]; //// household + P.PlaceCloseSpatialRelContact = P.PC_SpatialEffects_OverTime[0]; //// spatial + P.PlaceCloseHouseholdRelContact = P.PC_HouseholdEffects_OverTime[0]; //// household for (int PlaceType = 0; PlaceType < P.PlaceTypeNum; PlaceType++) { - P.PlaceCloseEffect[PlaceType] = P.PC_PlaceEffects_OverTime[0][PlaceType]; //// place + P.PlaceCloseEffect[PlaceType] = P.PC_PlaceEffects_OverTime[0][PlaceType]; //// place P.PlaceClosePropAttending[PlaceType] = P.PC_PropAttending_OverTime[0][PlaceType]; } - P.PlaceCloseIncTrig1 = P.PC_IncThresh_OverTime [0]; //// global incidence threshold - P.PlaceCloseFracIncTrig = P.PC_FracIncThresh_OverTime [0]; //// fractional incidence threshold - P.PlaceCloseCellIncThresh1 = P.PC_CellIncThresh_OverTime [0]; //// cell incidence threshold - P.PlaceCloseDurationBase = P.PC_Durs_OverTime[0]; //// duration of place closure - + P.PlaceCloseIncTrig1 = P.PC_IncThresh_OverTime[0]; //// global incidence threshold + P.PlaceCloseFracIncTrig = P.PC_FracIncThresh_OverTime[0]; //// fractional incidence threshold + P.PlaceCloseCellIncThresh1 = P.PC_CellIncThresh_OverTime[0]; //// cell incidence threshold + P.PlaceCloseDurationBase = P.PC_Durs_OverTime[0]; //// duration of place closure //// **** digital contact tracing - P.DCTCaseIsolationEffectiveness = P.DCT_SpatialAndPlaceEffects_OverTime [0]; //// spatial / place - P.DCTCaseIsolationHouseEffectiveness = P.DCT_HouseholdEffects_OverTime [0]; //// household - P.ProportionDigitalContactsIsolate = P.DCT_Prop_OverTime [0]; //// compliance - P.MaxDigitalContactsToTrace = P.DCT_MaxToTrace_OverTime [0]; - - + P.DCTCaseIsolationEffectiveness = P.DCT_SpatialAndPlaceEffects_OverTime[0]; //// spatial / place + P.DCTCaseIsolationHouseEffectiveness = P.DCT_HouseholdEffects_OverTime[0]; //// household + P.ProportionDigitalContactsIsolate = P.DCT_Prop_OverTime[0]; //// compliance + P.MaxDigitalContactsToTrace = P.DCT_MaxToTrace_OverTime[0]; for (int i = 0; i < MAX_NUM_THREADS; i++) { - for (int j = 0; j < MAX_NUM_THREADS; j++) StateT[i].n_queue[j] = 0; - for (int j = 0; j < P.PlaceTypeNum; j++) StateT[i].np_queue[j] = 0; + for (int j = 0; j < MAX_NUM_THREADS; j++) + StateT[i].n_queue[j] = 0; + for (int j = 0; j < P.PlaceTypeNum; j++) + StateT[i].np_queue[j] = 0; } if (DoInitUpdateProbs) { UpdateProbs(0); DoInitUpdateProbs = 0; } - //initialise event log to zero at the beginning of every run: ggilani - 10/10/2014. UPDATE: 15/10/14 - we are now going to store all events from all realisations in one file + // initialise event log to zero at the beginning of every run: ggilani - 10/10/2014. UPDATE: + // 15/10/14 - we are now going to store all events from all realisations in one file if ((P.DoRecordInfEvents) && (P.RecordInfEventsPerRun)) { nEvents = 0; for (int i = 0; i < P.MaxInfEvents; i++) { - InfEventLog[i].t = InfEventLog[i].infectee_x = InfEventLog[i].infectee_y = InfEventLog[i].t_infector = 0.0; + InfEventLog[i].t = InfEventLog[i].infectee_x = InfEventLog[i].infectee_y = + InfEventLog[i].t_infector = 0.0; InfEventLog[i].infectee_ind = InfEventLog[i].infector_ind = 0; - InfEventLog[i].infectee_adunit = InfEventLog[i].listpos = InfEventLog[i].infectee_cell = InfEventLog[i].infector_cell = InfEventLog[i].thread = 0; + InfEventLog[i].infectee_adunit = InfEventLog[i].listpos = InfEventLog[i].infectee_cell = + InfEventLog[i].infector_cell = InfEventLog[i].thread = 0; } } - for (int i = 0; i < P.NumSeedLocations; i++) NumSeedingInfections_byLocation[i] = (int) (((double) P.NumInitialInfections[i]) * P.InitialInfectionsAdminUnitWeight[i]* P.SeedingScaling +0.5); + for (int i = 0; i < P.NumSeedLocations; i++) + NumSeedingInfections_byLocation[i] = + (int)(((double)P.NumInitialInfections[i]) * P.InitialInfectionsAdminUnitWeight[i] * + P.SeedingScaling + + 0.5); SeedInfection(0, NumSeedingInfections_byLocation, 0, run); P.ControlPropCasesId = P.PreAlertControlPropCasesId; P.TreatTimeStart = 1e10; @@ -2795,7 +4321,7 @@ void InitModel(int run) // passing run number so we can save run number in the i P.PlaceCloseTimeStart2 = 2e10; P.SocDistTimeStart = 1e10; P.AirportCloseTimeStart = 1e10; - //P.DigitalContactTracingTimeStart = 1e10; + // P.DigitalContactTracingTimeStart = 1e10; P.HQuarantineTimeStart = 1e10; P.KeyWorkerProphTimeStart = 1e10; P.TreatMaxCourses = P.TreatMaxCoursesBase; @@ -2804,28 +4330,37 @@ void InitModel(int run) // passing run number so we can save run number in the i P.PlaceCloseIncTrig = P.PlaceCloseIncTrig1; P.PlaceCloseTimeStartPrevious = 1e10; P.PlaceCloseCellIncThresh = P.PlaceCloseCellIncThresh1; - P.ResetSeedsFlag = 0; //added this to allow resetting seeds part way through run: ggilani 27/11/2019 - if (!P.StopCalibration) P.DateTriggerReached_SimTime = 0; + P.ResetSeedsFlag = + 0; // added this to allow resetting seeds part way through run: ggilani 27/11/2019 + if (!P.StopCalibration) + P.DateTriggerReached_SimTime = 0; fprintf(stderr, "Finished InitModel.\n"); } -void SeedInfection(double t, int* NumSeedingInfections_byLocation, int rf, int run) //adding run number to pass it to event log +void SeedInfection(double t, int *NumSeedingInfections_byLocation, int rf, + int run) // adding run number to pass it to event log { - /* *NumSeedingInfections_byLocation is an array of the number of seeding infections by location. During runtime, usually just a single int (given by a poisson distribution)*/ + /* *NumSeedingInfections_byLocation is an array of the number of seeding infections by location. + * During runtime, usually just a single int (given by a poisson distribution)*/ /*rf set to 0 when initializing model, otherwise set to 1 during runtime. */ int i /*seed location index*/; int j /*microcell number*/; - int k, l /*k,l are grid coords at first, then l changed to be person within Microcell j, then k changed to be index of new infection*/; - int m = 0/*guard against too many infections and infinite loop*/; + int k, l /*k,l are grid coords at first, then l changed to be person within Microcell j, then k + changed to be index of new infection*/ + ; + int m = 0 /*guard against too many infections and infinite loop*/; int f /*range = {0, 1000}*/; int n /*number of seed locations?*/; n = ((rf == 0) ? P.NumSeedLocations : 1); for (i = 0; i < n; i++) { - if ((!P.DoRandomInitialInfectionLoc) || ((P.DoAllInitialInfectioninSameLoc) && (rf))) //// either non-random locations, doing all initial infections in same location, and not initializing. + if ((!P.DoRandomInitialInfectionLoc) || + ((P.DoAllInitialInfectioninSameLoc) && + (rf))) //// either non-random locations, doing all initial infections in same location, and + /// not initializing. { k = (int)(P.LocationInitialInfection[i][0] / P.in_microcells_.width); l = (int)(P.LocationInitialInfection[i][1] / P.in_microcells_.height); @@ -2833,12 +4368,15 @@ void SeedInfection(double t, int* NumSeedingInfections_byLocation, int rf, int r m = 0; for (k = 0; (k < NumSeedingInfections_byLocation[i]) && (m < 10000); k++) { - l = Mcells[j].members[(int)(ranf() * ((double)Mcells[j].n))]; //// randomly choose member of microcell j. Name this member l - if (Hosts[l].inf == InfStat_Susceptible) //// If Host l is uninfected. + l = Mcells[j] + .members[(int)(ranf() * ((double)Mcells[j].n))]; //// randomly choose member of + /// microcell j. Name this member l + if (Hosts[l].inf == InfStat_Susceptible) //// If Host l is uninfected. { if (CalcPersonSusc(l, 0, 0, 0) > 0) { - //only reset the initial location if rf==0, i.e. when initial seeds are being set, not when imported cases are being set + // only reset the initial location if rf==0, i.e. when initial seeds are being set, not + // when imported cases are being set if (rf == 0) { P.LocationInitialInfection[i][0] = Households[Hosts[l].hh].loc.x; @@ -2846,11 +4384,17 @@ void SeedInfection(double t, int* NumSeedingInfections_byLocation, int rf, int r } Hosts[l].infector = -2; Hosts[l].infect_type = INFECT_TYPE_MASK - 1; - DoInfect(l, t, 0, run); ///// guessing this updates a number of things about person l at time t in thread 0 for this run. + DoInfect(l, t, 0, run); ///// guessing this updates a number of things about person l at + /// time t in thread 0 for this run. m = 0; } } - else { k--; m++; } //// k-- means if person l chosen is already infected, go again. The m < 10000 is a guard against a) too many infections; b) an infinite loop if no more uninfected people left. + else + { + k--; + m++; + } //// k-- means if person l chosen is already infected, go again. The m < 10000 is a guard + /// against a) too many infections; b) an infinite loop if no more uninfected people left. } } else if (P.DoAllInitialInfectioninSameLoc) @@ -2863,10 +4407,14 @@ void SeedInfection(double t, int* NumSeedingInfections_byLocation, int rf, int r { l = (int)(ranf() * ((double)P.PopSize)); j = Hosts[l].mcell; - //fprintf(stderr,"%i ",AdUnits[Mcells[j].adunit].id); - } while ((Mcells[j].n < NumSeedingInfections_byLocation[i]) || (Mcells[j].n > P.MaxPopDensForInitialInfection) - || (Mcells[j].n < P.MinPopDensForInitialInfection) - || ((P.InitialInfectionsAdminUnit[i] > 0) && ((AdUnits[Mcells[j].adunit].id % P.AdunitLevel1Mask) / P.AdunitLevel1Divisor != (P.InitialInfectionsAdminUnit[i] % P.AdunitLevel1Mask) / P.AdunitLevel1Divisor))); + // fprintf(stderr,"%i ",AdUnits[Mcells[j].adunit].id); + } while ( + (Mcells[j].n < NumSeedingInfections_byLocation[i]) || + (Mcells[j].n > P.MaxPopDensForInitialInfection) || + (Mcells[j].n < P.MinPopDensForInitialInfection) || + ((P.InitialInfectionsAdminUnit[i] > 0) && + ((AdUnits[Mcells[j].adunit].id % P.AdunitLevel1Mask) / P.AdunitLevel1Divisor != + (P.InitialInfectionsAdminUnit[i] % P.AdunitLevel1Mask) / P.AdunitLevel1Divisor))); for (k = 0; (k < NumSeedingInfections_byLocation[i]) && (m < 10000); k++) { l = Mcells[j].members[(int)(ranf() * ((double)Mcells[j].n))]; @@ -2876,14 +4424,16 @@ void SeedInfection(double t, int* NumSeedingInfections_byLocation, int rf, int r { P.LocationInitialInfection[i][0] = Households[Hosts[l].hh].loc.x; P.LocationInitialInfection[i][1] = Households[Hosts[l].hh].loc.y; - Hosts[l].infector = -2; Hosts[l].infect_type = INFECT_TYPE_MASK - 1; + Hosts[l].infector = -2; + Hosts[l].infect_type = INFECT_TYPE_MASK - 1; DoInfect(l, t, 0, run); m = 0; } } else { - k--; m++; + k--; + m++; } } if (m) @@ -2901,10 +4451,14 @@ void SeedInfection(double t, int* NumSeedingInfections_byLocation, int rf, int r { l = (int)(ranf() * ((double)P.PopSize)); j = Hosts[l].mcell; - //fprintf(stderr,"@@ %i %i ",AdUnits[Mcells[j].adunit].id, (int)(AdUnits[Mcells[j].adunit].id / P.CountryDivisor)); - } while ((Mcells[j].n == 0) || (Mcells[j].n > P.MaxPopDensForInitialInfection) - || (Mcells[j].n < P.MinPopDensForInitialInfection) - || ((P.InitialInfectionsAdminUnit[i] > 0) && ((AdUnits[Mcells[j].adunit].id % P.AdunitLevel1Mask) / P.AdunitLevel1Divisor != (P.InitialInfectionsAdminUnit[i] % P.AdunitLevel1Mask) / P.AdunitLevel1Divisor))); + // fprintf(stderr,"@@ %i %i ",AdUnits[Mcells[j].adunit].id, + // (int)(AdUnits[Mcells[j].adunit].id / P.CountryDivisor)); + } while ( + (Mcells[j].n == 0) || (Mcells[j].n > P.MaxPopDensForInitialInfection) || + (Mcells[j].n < P.MinPopDensForInitialInfection) || + ((P.InitialInfectionsAdminUnit[i] > 0) && + ((AdUnits[Mcells[j].adunit].id % P.AdunitLevel1Mask) / P.AdunitLevel1Divisor != + (P.InitialInfectionsAdminUnit[i] % P.AdunitLevel1Mask) / P.AdunitLevel1Divisor))); l = Mcells[j].members[(int)(ranf() * ((double)Mcells[j].n))]; if (Hosts[l].inf == InfStat_Susceptible) { @@ -2912,65 +4466,76 @@ void SeedInfection(double t, int* NumSeedingInfections_byLocation, int rf, int r { P.LocationInitialInfection[i][0] = Households[Hosts[l].hh].loc.x; P.LocationInitialInfection[i][1] = Households[Hosts[l].hh].loc.y; - Hosts[l].infector = -2; Hosts[l].infect_type = INFECT_TYPE_MASK - 1; + Hosts[l].infector = -2; + Hosts[l].infect_type = INFECT_TYPE_MASK - 1; DoInfect(l, t, 0, run); m = 0; } else { - k--; m++; + k--; + m++; } } else { - k--; m++; + k--; + m++; } } } } - if (m > 0) fprintf(stderr, "### Seeding error ###\n"); + if (m > 0) + fprintf(stderr, "### Seeding error ###\n"); } - -int RunModel(int run) //added run number as parameter +int RunModel(int run) // added run number as parameter { - int j, k, l, fs, fs2, NumSeedingInfections, NumSeedingInfections_byLocation[MAX_NUM_SEED_LOCATIONS] /*Denotes either Num imported Infections given rate ir, or number false positive "infections"*/; + int j, k, l, fs, fs2, NumSeedingInfections, + NumSeedingInfections_byLocation[MAX_NUM_SEED_LOCATIONS] /*Denotes either Num imported + Infections given rate ir, or number + false positive "infections"*/ + ; double ir; // infection import rate?; double t, cI, lcI, t2; unsigned short int ts; int continueEvents = 1; - -/* fprintf(stderr, "Checking consistency of initial state...\n"); - int i, i2, k2; - for (i = j = k = ni = fs2 = i2 = 0; i < P.N; i++) - { - if (i % 1000 == 0) fprintf(stderr, "\r*** %i ", i); - if (Hosts[i].inf == 0) j++; - if ((Hosts[i].pcell < P.NC) && (Hosts[i].pcell >= 0)) + /* fprintf(stderr, "Checking consistency of initial state...\n"); + int i, i2, k2; + for (i = j = k = ni = fs2 = i2 = 0; i < P.N; i++) { - if (Cells[Hosts[i].pcell].susceptible[Hosts[i].listpos] != i) + if (i % 1000 == 0) fprintf(stderr, "\r*** %i ", i); + if (Hosts[i].inf == 0) j++; + if ((Hosts[i].pcell < P.NC) && (Hosts[i].pcell >= 0)) { - k++; - for (l = fs = 0; (l < Cells[Hosts[i].pcell].n) && (!fs); l++) - fs = (Cells[Hosts[i].pcell].susceptible[l] == i); - if (!fs) NumSeedingInfections++; + if (Cells[Hosts[i].pcell].susceptible[Hosts[i].listpos] != i) + { + k++; + for (l = fs = 0; (l < Cells[Hosts[i].pcell].n) && (!fs); l++) + fs = (Cells[Hosts[i].pcell].susceptible[l] == i); + if (!fs) NumSeedingInfections++; + } + else + { + if ((Hosts[i].listpos > Cells[Hosts[i].pcell].S - 1) && (Hosts[i].inf == + InfStat_Susceptible)) i2++; if ((Hosts[i].listpos < Cells[Hosts[i].pcell].S + + Cells[Hosts[i].pcell].L + Cells[Hosts[i].pcell].I - 1) && (abs(Hosts[i].inf) == + InfStat_Recovered)) i2++; + } + if ((Cells[Hosts[i].pcell].S + Cells[Hosts[i].pcell].L + Cells[Hosts[i].pcell].I + + Cells[Hosts[i].pcell].R + Cells[Hosts[i].pcell].D) != Cells[Hosts[i].pcell].n) + { + k2++; + } } else - { - if ((Hosts[i].listpos > Cells[Hosts[i].pcell].S - 1) && (Hosts[i].inf == InfStat_Susceptible)) i2++; - if ((Hosts[i].listpos < Cells[Hosts[i].pcell].S + Cells[Hosts[i].pcell].L + Cells[Hosts[i].pcell].I - 1) && (abs(Hosts[i].inf) == InfStat_Recovered)) i2++; - } - if ((Cells[Hosts[i].pcell].S + Cells[Hosts[i].pcell].L + Cells[Hosts[i].pcell].I + Cells[Hosts[i].pcell].R + Cells[Hosts[i].pcell].D) != Cells[Hosts[i].pcell].n) - { - k2++; - } + fs2++; } - else - fs2++; - } - fprintf(stderr, "\n*** susceptibles=%i\nincorrect listpos=%i\nhosts not found in cell list=%i\nincorrect cell refs=%i\nincorrect positioning in cell susc list=%i\nwrong cell totals=%i\n", j, k, NumSeedingInfections, fs2, i2, k2); -*/ + fprintf(stderr, "\n*** susceptibles=%i\nincorrect listpos=%i\nhosts not found in cell + list=%i\nincorrect cell refs=%i\nincorrect positioning in cell susc list=%i\nwrong cell + totals=%i\n", j, k, NumSeedingInfections, fs2, i2, k2); + */ InterruptRun = 0; lcI = 1; if (P.DoLoadSnapshot) @@ -2990,17 +4555,20 @@ int RunModel(int run) //added run number as parameter { RecordSample(t, ns - 1); fprintf(stderr, "\r t=%lg %i %i|%i %i %i [=%i] %i (%lg %lg %lg) %lg ", t, - State.S, State.L, State.I, State.R, State.D, State.S + State.L + State.I + State.R + State.D, State.cumD, State.cumT, State.cumV, State.cumVG, sqrt(State.maxRad2) / 1000); //added State.cumVG + State.S, State.L, State.I, State.R, State.D, + State.S + State.L + State.I + State.R + State.D, State.cumD, State.cumT, State.cumV, + State.cumVG, sqrt(State.maxRad2) / 1000); // added State.cumVG if (!InterruptRun) { - //Only run to a certain number of infections: ggilani 28/10/14 - if (P.LimitNumInfections) continueEvents = (State.cumI < P.MaxNumInfections); + // Only run to a certain number of infections: ggilani 28/10/14 + if (P.LimitNumInfections) + continueEvents = (State.cumI < P.MaxNumInfections); for (j = 0; ((j < P.UpdatesPerSample) && (!InterruptRun) && (continueEvents)); j++) { - ts = (unsigned short int) (P.TimeStepsPerDay * t); + ts = (unsigned short int)(P.TimeStepsPerDay * t); - //if we are to reset random numbers after an intervention event, specific time + // if we are to reset random numbers after an intervention event, specific time if (P.ResetSeedsPostIntervention) if ((P.ResetSeedsFlag == 0) && (ts >= (P.TimeToResetSeeds * P.TimeStepsPerDay))) { @@ -3010,56 +4578,95 @@ int RunModel(int run) //added run number as parameter if (fs) { - if (P.DoAirports) TravelDepartSweep(t); + if (P.DoAirports) + TravelDepartSweep(t); k = (int)t; if (P.DurImportTimeProfile > 0) { if (k < P.DurImportTimeProfile) - ir = P.ImportInfectionTimeProfile[k] * ((t > P.InfectionImportChangeTime) ? (P.InfectionImportRate2 / P.InfectionImportRate1) : 1.0); + ir = P.ImportInfectionTimeProfile[k] * + ((t > P.InfectionImportChangeTime) + ? (P.InfectionImportRate2 / P.InfectionImportRate1) + : 1.0); else ir = 0; } - else ir = (t > P.InfectionImportChangeTime) ? P.InfectionImportRate2 : P.InfectionImportRate1; + else + ir = + (t > P.InfectionImportChangeTime) ? P.InfectionImportRate2 : P.InfectionImportRate1; if (ir > 0) //// if infection import rate > 0, seed some infections { - for (k = NumSeedingInfections = 0; k < P.NumSeedLocations; k++) NumSeedingInfections += (NumSeedingInfections_byLocation[k] = (int)ignpoi(P.TimeStep * ir * P.InitialInfectionsAdminUnitWeight[k] * P.SeedingScaling)); //// sample number imported infections from Poisson distribution. - if (NumSeedingInfections > 0) SeedInfection(t, NumSeedingInfections_byLocation, 1, run); + for (k = NumSeedingInfections = 0; k < P.NumSeedLocations; k++) + NumSeedingInfections += + (NumSeedingInfections_byLocation[k] = + (int)ignpoi(P.TimeStep * ir * P.InitialInfectionsAdminUnitWeight[k] * + P.SeedingScaling)); //// sample number imported infections from + /// Poisson distribution. + if (NumSeedingInfections > 0) + SeedInfection(t, NumSeedingInfections_byLocation, 1, run); } if (P.FalsePositivePerCapitaIncidence > 0) { - NumSeedingInfections = (int)ignpoi(P.TimeStep * P.FalsePositivePerCapitaIncidence * ((double)P.PopSize)); + NumSeedingInfections = + (int)ignpoi(P.TimeStep * P.FalsePositivePerCapitaIncidence * ((double)P.PopSize)); if (NumSeedingInfections > 0) { for (k = 0; k < NumSeedingInfections; k++) { do { - l = (int)(((double)P.PopSize) * ranf()); //// choose person l randomly from entire population. (but change l if while condition not satisfied?) - } while ((abs(Hosts[l].inf) == InfStat_Dead) || (ranf() > P.FalsePositiveAgeRate[HOST_AGE_GROUP(l)])); + l = (int)(((double)P.PopSize) * + ranf()); //// choose person l randomly from entire population. (but + /// change l if while condition not satisfied?) + } while ((abs(Hosts[l].inf) == InfStat_Dead) || + (ranf() > P.FalsePositiveAgeRate[HOST_AGE_GROUP(l)])); DoFalseCase(l, t, ts, 0); } } } - InfectSweep(t, run); // loops over all infectious people and decides which susceptible people to infect (at household, place and spatial level), and adds them to queue. Then changes each person's various characteristics using DoInfect function. adding run number as a parameter to infect sweep so we can track run number: ggilani - 15/10/14 - //// IncubRecoverySweep loops over all infecteds (either latent or infectious). If t is the right time, latent people moved to being infected, and infectious people moved to being clinical cases. Possibly also add them to recoveries or deaths. Add them to hospitalisation & hospitalisation discharge queues. - if (!P.DoSI) IncubRecoverySweep(t, run); - // If doing new contact tracing, update numbers of people under contact tracing after each time step - - if (P.DoDigitalContactTracing) DigitalContactTracingSweep(t); - - fs2 = ((P.DoDeath) || (State.L + State.I > 0) || (ir > 0) || (P.FalsePositivePerCapitaIncidence > 0)); - ///// TreatSweep loops over microcells to decide which cells are treated (either with treatment, vaccine, social distancing, movement restrictions etc.). Calls DoVacc, DoPlaceClose, DoProphNoDelay etc. to change (threaded) State variables + InfectSweep(t, run); // loops over all infectious people and decides which susceptible + // people to infect (at household, place and spatial level), and adds + // them to queue. Then changes each person's various characteristics + // using DoInfect function. adding run number as a parameter to + // infect sweep so we can track run number: ggilani - 15/10/14 + //// IncubRecoverySweep loops over all infecteds (either latent or infectious). If t is + /// the right time, latent people moved to being infected, and infectious people moved to + /// being clinical cases. Possibly also add them to recoveries or deaths. Add them to + /// hospitalisation & hospitalisation discharge queues. + if (!P.DoSI) + IncubRecoverySweep(t, run); + // If doing new contact tracing, update numbers of people under contact tracing after each + // time step + + if (P.DoDigitalContactTracing) + DigitalContactTracingSweep(t); + + fs2 = ((P.DoDeath) || (State.L + State.I > 0) || (ir > 0) || + (P.FalsePositivePerCapitaIncidence > 0)); + ///// TreatSweep loops over microcells to decide which cells are treated (either with + /// treatment, vaccine, social distancing, movement restrictions etc.). Calls DoVacc, + /// DoPlaceClose, DoProphNoDelay etc. to change (threaded) State variables if (!TreatSweep(t)) { - if ((!fs2) && (State.L + State.I == 0) && (P.FalsePositivePerCapitaIncidence == 0)) { if ((ir == 0) && (((int)t) > P.DurImportTimeProfile)) fs = 0; } + if ((!fs2) && (State.L + State.I == 0) && (P.FalsePositivePerCapitaIncidence == 0)) + { + if ((ir == 0) && (((int)t) > P.DurImportTimeProfile)) + fs = 0; + } } - if (P.DoAirports) TravelReturnSweep(t); + if (P.DoAirports) + TravelReturnSweep(t); } t += P.TimeStep; - if (P.DoDeath) P.ts_age++; - if ((P.DoSaveSnapshot) && (t <= P.SnapshotSaveTime) && (t + P.TimeStep > P.SnapshotSaveTime)) SaveSnapshot(); - if (t > P.TreatNewCoursesStartTime) P.TreatMaxCourses += P.TimeStep * P.TreatNewCoursesRate; - if ((t > P.VaccNewCoursesStartTime) && (t < P.VaccNewCoursesEndTime)) P.VaccMaxCourses += P.TimeStep * P.VaccNewCoursesRate; + if (P.DoDeath) + P.ts_age++; + if ((P.DoSaveSnapshot) && (t <= P.SnapshotSaveTime) && + (t + P.TimeStep > P.SnapshotSaveTime)) + SaveSnapshot(); + if (t > P.TreatNewCoursesStartTime) + P.TreatMaxCourses += P.TimeStep * P.TreatNewCoursesRate; + if ((t > P.VaccNewCoursesStartTime) && (t < P.VaccNewCoursesEndTime)) + P.VaccMaxCourses += P.TimeStep * P.VaccNewCoursesRate; cI = ((double)(State.S)) / ((double)P.PopSize); if ((lcI - cI) > 0.2) { @@ -3070,10 +4677,11 @@ int RunModel(int run) //added run number as parameter } } } - if (!InterruptRun) RecordSample(t, P.NumSamples - 1); + if (!InterruptRun) + RecordSample(t, P.NumSamples - 1); fprintf(stderr, "\nEnd of run\n"); t2 = t + P.SampleTime; -// if(!InterruptRun) + // if(!InterruptRun) while (fs) { fs = TreatSweep(t2); @@ -3086,47 +4694,53 @@ int RunModel(int run) //added run number as parameter for (t2 = t; t2 <= t + MAX_TRAVEL_TIME; t2 += P.TimeStep) TravelReturnSweep(t2); } -/* if (!InterruptRun) - { - fprintf(stderr, "Checking consistency of final state...\n"); - int i, i2, k2; - for (i = j = k = NumSeedingInfections = fs2 = i2 = 0; i < P.PopSize; i++) + /* if (!InterruptRun) { - if (i % 1000 == 0) fprintf(stderr, "\r*** %i ", i); - if (Hosts[i].inf == 0) j++; - if ((Hosts[i].pcell < P.NC) && (Hosts[i].pcell >= 0)) + fprintf(stderr, "Checking consistency of final state...\n"); + int i, i2, k2; + for (i = j = k = NumSeedingInfections = fs2 = i2 = 0; i < P.PopSize; i++) { - if (Cells[Hosts[i].pcell].susceptible[Hosts[i].listpos] != i) + if (i % 1000 == 0) fprintf(stderr, "\r*** %i ", i); + if (Hosts[i].inf == 0) j++; + if ((Hosts[i].pcell < P.NC) && (Hosts[i].pcell >= 0)) { - k++; - for (l = fs = 0; (l < Cells[Hosts[i].pcell].n) && (!fs); l++) - fs = (Cells[Hosts[i].pcell].susceptible[l] == i); - if (!fs) NumSeedingInfections++; + if (Cells[Hosts[i].pcell].susceptible[Hosts[i].listpos] != i) + { + k++; + for (l = fs = 0; (l < Cells[Hosts[i].pcell].n) && (!fs); l++) + fs = (Cells[Hosts[i].pcell].susceptible[l] == i); + if (!fs) NumSeedingInfections++; + } + else + { + if ((Hosts[i].listpos > Cells[Hosts[i].pcell].S - 1) && (Hosts[i].inf == + InfStat_Susceptible)) i2++; if ((Hosts[i].listpos < Cells[Hosts[i].pcell].S + + Cells[Hosts[i].pcell].L + Cells[Hosts[i].pcell].I - 1) && (abs(Hosts[i].inf) == + InfStat_Recovered)) i2++; + } + if ((Cells[Hosts[i].pcell].S + Cells[Hosts[i].pcell].L + Cells[Hosts[i].pcell].I + + Cells[Hosts[i].pcell].R + Cells[Hosts[i].pcell].D) != Cells[Hosts[i].pcell].n) + { + k2++; + } } else - { - if ((Hosts[i].listpos > Cells[Hosts[i].pcell].S - 1) && (Hosts[i].inf == InfStat_Susceptible)) i2++; - if ((Hosts[i].listpos < Cells[Hosts[i].pcell].S + Cells[Hosts[i].pcell].L + Cells[Hosts[i].pcell].I - 1) && (abs(Hosts[i].inf) == InfStat_Recovered)) i2++; - } - if ((Cells[Hosts[i].pcell].S + Cells[Hosts[i].pcell].L + Cells[Hosts[i].pcell].I + Cells[Hosts[i].pcell].R + Cells[Hosts[i].pcell].D) != Cells[Hosts[i].pcell].n) - { - k2++; - } + fs2++; } - else - fs2++; + fprintf(stderr, "\n*** susceptibles=%i\nincorrect listpos=%i\nhosts not found in cell + list=%i\nincorrect cell refs=%i\nincorrect positioning in cell susc list=%i\nwrong cell + totals=%i\n", j, k, NumSeedingInfections, fs2, i2, k2); } - fprintf(stderr, "\n*** susceptibles=%i\nincorrect listpos=%i\nhosts not found in cell list=%i\nincorrect cell refs=%i\nincorrect positioning in cell susc list=%i\nwrong cell totals=%i\n", j, k, NumSeedingInfections, fs2, i2, k2); - } -*/ - if(!InterruptRun) RecordInfTypes(); + */ + if (!InterruptRun) + RecordInfTypes(); return (InterruptRun); } void SaveDistribs(void) { int i, j, k; - FILE* dat; + FILE *dat; char outname[1024]; double s; @@ -3155,12 +4769,17 @@ void SaveDistribs(void) if (Hosts[i].PlaceLinks[j] >= P.Nplace[j]) fprintf(stderr, "*%i %i: %i ", i, j, Hosts[i].PlaceLinks[j]); else if ((!P.DoOutputPlaceDistForOneAdunit) || - ((AdUnits[Mcells[Hosts[i].mcell].adunit].id % P.AdunitLevel1Mask) / P.AdunitLevel1Divisor == (P.OutputPlaceDistAdunit % P.AdunitLevel1Mask) / P.AdunitLevel1Divisor)) + ((AdUnits[Mcells[Hosts[i].mcell].adunit].id % P.AdunitLevel1Mask) / + P.AdunitLevel1Divisor == + (P.OutputPlaceDistAdunit % P.AdunitLevel1Mask) / P.AdunitLevel1Divisor)) { k = Hosts[i].PlaceLinks[j]; - s = sqrt(dist2_raw(Households[Hosts[i].hh].loc.x, Households[Hosts[i].hh].loc.y, Places[j][k].loc.x, Places[j][k].loc.y)) / OUTPUT_DIST_SCALE; + s = sqrt(dist2_raw(Households[Hosts[i].hh].loc.x, Households[Hosts[i].hh].loc.y, + Places[j][k].loc.x, Places[j][k].loc.y)) / + OUTPUT_DIST_SCALE; k = (int)s; - if (k < MAX_DIST) PlaceDistDistrib[j][k]++; + if (k < MAX_DIST) + PlaceDistDistrib[j][k]++; } } for (j = 0; j < P.PlaceTypeNum; j++) @@ -3172,7 +4791,8 @@ void SaveDistribs(void) if (Places[j][i].n < MAX_PLACE_SIZE) PlaceSizeDistrib[j][Places[j][i].n]++; sprintf(outname, "%s.placedist.xls", OutFile); - if (!(dat = fopen(outname, "wb"))) ERR_CRITICAL("Unable to open output file\n"); + if (!(dat = fopen(outname, "wb"))) + ERR_CRITICAL("Unable to open output file\n"); fprintf(dat, "dist"); for (j = 0; j < P.PlaceTypeNum; j++) if (j != P.HotelPlaceType) @@ -3188,7 +4808,8 @@ void SaveDistribs(void) } fclose(dat); sprintf(outname, "%s.placesize.xls", OutFile); - if (!(dat = fopen(outname, "wb"))) ERR_CRITICAL("Unable to open output file\n"); + if (!(dat = fopen(outname, "wb"))) + ERR_CRITICAL("Unable to open output file\n"); fprintf(dat, "size"); for (j = 0; j < P.PlaceTypeNum; j++) if (j != P.HotelPlaceType) @@ -3216,13 +4837,15 @@ void SaveOriginDestMatrix(void) * author: ggilani, 13/02/15 */ int i, j; - FILE* dat; + FILE *dat; char outname[1024]; sprintf(outname, "%s.origdestmat.xls", OutFile); - if (!(dat = fopen(outname, "wb"))) ERR_CRITICAL("Unable to open output file\n"); + if (!(dat = fopen(outname, "wb"))) + ERR_CRITICAL("Unable to open output file\n"); fprintf(dat, "0,"); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "%i,", (AdUnits[i].id % P.AdunitLevel1Mask) / P.AdunitLevel1Divisor); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "%i,", (AdUnits[i].id % P.AdunitLevel1Mask) / P.AdunitLevel1Divisor); fprintf(dat, "\n"); for (i = 0; i < P.NumAdunits; i++) { @@ -3239,21 +4862,29 @@ void SaveOriginDestMatrix(void) void SaveResults(void) { int i, j; - FILE* dat; + FILE *dat; char outname[1024]; if (P.OutputNonSeverity) { sprintf(outname, "%s.xls", OutFile); - if(!(dat = fopen(outname, "wb"))) ERR_CRITICAL("Unable to open output file\n"); - fprintf(dat, "t\tS\tL\tI\tR\tD\tincI\tincR\tincFC\tincC\tincDC\tincTC\tincCT\tincCC\tcumT\tcumTP\tcumV\tcumVG\tExtinct\trmsRad\tmaxRad\n");//\t\t%.10f\t%.10f\t%.10f\n",P.R0household,P.R0places,P.R0spatial); - for(i = 0; i < P.NumSamples; i++) + if (!(dat = fopen(outname, "wb"))) + ERR_CRITICAL("Unable to open output file\n"); + fprintf( + dat, + "t\tS\tL\tI\tR\tD\tincI\tincR\tincFC\tincC\tincDC\tincTC\tincCT\tincCC\tcumT\tcumTP\tcumV\t" + "cumVG\tExtinct\trmsRad\tmaxRad\n"); //\t\t%.10f\t%.10f\t%.10f\n",P.R0household,P.R0places,P.R0spatial); + for (i = 0; i < P.NumSamples; i++) { - fprintf(dat, "%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10ft%.10f\t%.10f\t%.10f\t%.10f\t%.10f\n", - TimeSeries[i].t, TimeSeries[i].S, TimeSeries[i].L, TimeSeries[i].I, - TimeSeries[i].R, TimeSeries[i].D, TimeSeries[i].incI, - TimeSeries[i].incR, TimeSeries[i].incFC, TimeSeries[i].incC, TimeSeries[i].incDC, TimeSeries[i].incTC, TimeSeries[i].incCT, TimeSeries[i].incCC, - TimeSeries[i].cumT, TimeSeries[i].cumTP, TimeSeries[i].cumV, TimeSeries[i].cumVG, TimeSeries[i].extinct, TimeSeries[i].rmsRad, TimeSeries[i].maxRad); + fprintf(dat, + "%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%." + "10f\t%.10f\t%.10f\t%.10f\t%.10ft%.10f\t%.10f\t%.10f\t%.10f\t%.10f\n", + TimeSeries[i].t, TimeSeries[i].S, TimeSeries[i].L, TimeSeries[i].I, TimeSeries[i].R, + TimeSeries[i].D, TimeSeries[i].incI, TimeSeries[i].incR, TimeSeries[i].incFC, + TimeSeries[i].incC, TimeSeries[i].incDC, TimeSeries[i].incTC, TimeSeries[i].incCT, + TimeSeries[i].incCC, TimeSeries[i].cumT, TimeSeries[i].cumTP, TimeSeries[i].cumV, + TimeSeries[i].cumVG, TimeSeries[i].extinct, TimeSeries[i].rmsRad, + TimeSeries[i].maxRad); } fclose(dat); } @@ -3261,11 +4892,15 @@ void SaveResults(void) if ((P.DoAdUnits) && (P.DoAdunitOutput)) { sprintf(outname, "%s.adunit.xls", OutFile); - if (!(dat = fopen(outname, "wb"))) ERR_CRITICAL("Unable to open output file\n"); + if (!(dat = fopen(outname, "wb"))) + ERR_CRITICAL("Unable to open output file\n"); fprintf(dat, "t"); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tI_%s", AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tC_%s", AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tDC_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tI_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tC_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tDC_%s", AdUnits[i].ad_name); fprintf(dat, "\n"); for (i = 0; i < P.NumSamples; i++) @@ -3284,9 +4919,10 @@ void SaveResults(void) if ((P.DoDigitalContactTracing) && (P.DoAdUnits) && (P.OutputDigitalContactTracing)) { - sprintf(outname, "%s.digitalcontacttracing.xls", OutFile); //modifying to csv file - if (!(dat = fopen(outname, "wb"))) ERR_CRITICAL("Unable to open output file\n"); - fprintf(dat, "t"); + sprintf(outname, "%s.digitalcontacttracing.xls", OutFile); // modifying to csv file + if (!(dat = fopen(outname, "wb"))) + ERR_CRITICAL("Unable to open output file\n"); + fprintf(dat, "t"); for (i = 0; i < P.NumAdunits; i++) { fprintf(dat, "\tincDCT_%s", AdUnits[i].ad_name); @@ -3296,8 +4932,8 @@ void SaveResults(void) fprintf(dat, "\tDCT_%s", AdUnits[i].ad_name); } fprintf(dat, "\n"); - //print actual output - for(i=0; i 0) - fprintf(dat, "%i\t%i\t%i\t%i\n", i, Hosts[i].infector, Hosts[i].infect_type % INFECT_TYPE_MASK, (int)HOST_AGE_YEAR(i)); + if (!(dat = fopen(outname, "wb"))) + ERR_CRITICAL("Unable to open output file\n"); + for (i = 0; i < P.PopSize; i++) + if (Hosts[i].infect_type % INFECT_TYPE_MASK > 0) + fprintf(dat, "%i\t%i\t%i\t%i\n", i, Hosts[i].infector, + Hosts[i].infect_type % INFECT_TYPE_MASK, (int)HOST_AGE_YEAR(i)); fclose(dat); - } + } #if defined(_WIN32) || defined(IMAGE_MAGICK) - static int dm[13] ={0,31,28,31,30,31,30,31,31,30,31,30,31}; + static int dm[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int d, m, y, dml, f; #ifdef _WIN32 - //if(P.OutputBitmap == 1) CloseAvi(avi); - //if((TimeSeries[P.NumSamples - 1].extinct) && (P.OutputOnlyNonExtinct)) + // if(P.OutputBitmap == 1) CloseAvi(avi); + // if((TimeSeries[P.NumSamples - 1].extinct) && (P.OutputOnlyNonExtinct)) // { // sprintf(outname, "%s.ge" DIRECTORY_SEPARATOR "%s.avi", OutFile, OutFile); // DeleteFile(outname); // } #endif - if(P.OutputBitmap >= 1 && P.BitmapFormat == BitmapFormats::PNG) - { + if (P.OutputBitmap >= 1 && P.BitmapFormat == BitmapFormats::PNG) + { // Generate Google Earth .kml file - sprintf(outname, "%s.ge" DIRECTORY_SEPARATOR "%s.ge.kml", OutFile, OutFile); //sprintf(outname,"%s.ge" DIRECTORY_SEPARATOR "%s.kml",OutFileBase,OutFile); - if(!(dat = fopen(outname, "wb"))) - { + sprintf(outname, "%s.ge" DIRECTORY_SEPARATOR "%s.ge.kml", OutFile, + OutFile); // sprintf(outname,"%s.ge" DIRECTORY_SEPARATOR "%s.kml",OutFileBase,OutFile); + if (!(dat = fopen(outname, "wb"))) + { ERR_CRITICAL("Unable to open output kml file\n"); - } - fprintf(dat, "\n\n\n"); + } + fprintf(dat, "\n\n\n"); fprintf(dat, "%s\n", OutFile); y = 2009; m = 1; d = 1; - for(i = 0; i < P.NumSamples; i++) - { + for (i = 0; i < P.NumSamples; i++) + { fprintf(dat, "\nSnapshot %i\n", i + 1); fprintf(dat, "\n%i-%02i-%02iT00:00:00Z\n", y, m, d); d += (int)P.SampleStep; // SampleStep has to be an integer here. do - { + { f = 1; dml = dm[m]; - if((m == 2) && (y % 4 == 0)) dml = 29; - if(d > dml) - { + if ((m == 2) && (y % 4 == 0)) + dml = 29; + if (d > dml) + { m++; - if(m > 12) - { + if (m > 12) + { m -= 12; y++; - } + } d -= dml; f = 0; - } - } while(!f); - fprintf(dat, "%i-%02i-%02iT00:00:00Z\n\n", y, m, d); - sprintf(outname, "%s.ge" DIRECTORY_SEPARATOR "%s.%i.png", OutFile, OutFile, i + 1); - fprintf(dat, "\n%s\n\n", outname); - fprintf(dat, "\n%.10f\n%.10f\n%.10f\n%.10f\n\n", - P.SpatialBoundingBox[3], P.SpatialBoundingBox[1], P.SpatialBoundingBox[2], P.SpatialBoundingBox[0]); - fprintf(dat, "\n"); - } + } + } while (!f); + fprintf(dat, "%i-%02i-%02iT00:00:00Z\n\n", y, m, d); + sprintf(outname, "%s.ge" DIRECTORY_SEPARATOR "%s.%i.png", OutFile, OutFile, i + 1); + fprintf(dat, "\n%s\n\n", outname); + fprintf(dat, + "\n%.10f\n%.10f\n%.10f\n%.10f\n\n", + P.SpatialBoundingBox[3], P.SpatialBoundingBox[1], P.SpatialBoundingBox[2], + P.SpatialBoundingBox[0]); + fprintf(dat, "\n"); + } fprintf(dat, "\n\n"); fclose(dat); - } + } #endif - - if(P.DoSeverity) + if (P.DoSeverity) { sprintf(outname, "%s.severity.xls", OutFile); - if(!(dat = fopen(outname, "wb"))) ERR_CRITICAL("Unable to open severity output file\n"); - fprintf(dat, "t\tRt\tTG\tSI\tS\tI\tR\tincI\tMild\tILI\tSARI\tCritical\tCritRecov\tincMild\tincILI\tincSARI\tincCritical\tincCritRecov\tincDeath\tincDeath_ILI\tincDeath_SARI\tincDeath_Critical\tcumMild\tcumILI\tcumSARI\tcumCritical\tcumCritRecov\tcumDeath\tcumDeath_ILI\tcumDeath_SARI\tcumDeath_Critical\n");//\t\t%.10f\t%.10f\t%.10f\n",P.R0household,P.R0places,P.R0spatial); + if (!(dat = fopen(outname, "wb"))) + ERR_CRITICAL("Unable to open severity output file\n"); + fprintf( + dat, + "t\tRt\tTG\tSI\tS\tI\tR\tincI\tMild\tILI\tSARI\tCritical\tCritRecov\tincMild\tincILI\tincSA" + "RI\tincCritical\tincCritRecov\tincDeath\tincDeath_ILI\tincDeath_SARI\tincDeath_" + "Critical\tcumMild\tcumILI\tcumSARI\tcumCritical\tcumCritRecov\tcumDeath\tcumDeath_" + "ILI\tcumDeath_SARI\tcumDeath_Critical\n"); //\t\t%.10f\t%.10f\t%.10f\n",P.R0household,P.R0places,P.R0spatial); for (i = 0; i < P.NumSamples; i++) { - fprintf(dat, "%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\n", - TimeSeries[i].t, TimeSeries[i].Rdenom, TimeSeries[i].meanTG, TimeSeries[i].meanSI, TimeSeries[i].S, TimeSeries[i].I, TimeSeries[i].R, TimeSeries[i].incI, - TimeSeries[i].Mild , TimeSeries[i].ILI , TimeSeries[i].SARI , TimeSeries[i].Critical , TimeSeries[i].CritRecov , - TimeSeries[i].incMild , TimeSeries[i].incILI , TimeSeries[i].incSARI , TimeSeries[i].incCritical , TimeSeries[i].incCritRecov, - TimeSeries[i].incD, TimeSeries[i].incDeath_ILI, TimeSeries[i].incDeath_SARI, TimeSeries[i].incDeath_Critical, - TimeSeries[i].cumMild , TimeSeries[i].cumILI , TimeSeries[i].cumSARI , TimeSeries[i].cumCritical , TimeSeries[i].cumCritRecov, TimeSeries[i].D , - TimeSeries[i].cumDeath_ILI, TimeSeries[i].cumDeath_SARI, TimeSeries[i].cumDeath_Critical); + fprintf(dat, + "%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%." + "10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%." + "10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\n", + TimeSeries[i].t, TimeSeries[i].Rdenom, TimeSeries[i].meanTG, TimeSeries[i].meanSI, + TimeSeries[i].S, TimeSeries[i].I, TimeSeries[i].R, TimeSeries[i].incI, + TimeSeries[i].Mild, TimeSeries[i].ILI, TimeSeries[i].SARI, TimeSeries[i].Critical, + TimeSeries[i].CritRecov, TimeSeries[i].incMild, TimeSeries[i].incILI, + TimeSeries[i].incSARI, TimeSeries[i].incCritical, TimeSeries[i].incCritRecov, + TimeSeries[i].incD, TimeSeries[i].incDeath_ILI, TimeSeries[i].incDeath_SARI, + TimeSeries[i].incDeath_Critical, TimeSeries[i].cumMild, TimeSeries[i].cumILI, + TimeSeries[i].cumSARI, TimeSeries[i].cumCritical, TimeSeries[i].cumCritRecov, + TimeSeries[i].D, TimeSeries[i].cumDeath_ILI, TimeSeries[i].cumDeath_SARI, + TimeSeries[i].cumDeath_Critical); } fclose(dat); - if((P.DoAdUnits) && (P.OutputSeverityAdminUnit)) + if ((P.DoAdUnits) && (P.OutputSeverityAdminUnit)) { //// output severity results by admin unit sprintf(outname, "%s.severity.adunit.xls", OutFile); - if(!(dat = fopen(outname, "wb"))) ERR_CRITICAL("Unable to open output file\n"); + if (!(dat = fopen(outname, "wb"))) + ERR_CRITICAL("Unable to open output file\n"); fprintf(dat, "t"); /////// ****** /////// ****** /////// ****** COLNAMES //// prevalence - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tMild_%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tILI_%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tSARI_%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tCritical_%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tCritRecov_%s" , AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tMild_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tILI_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tSARI_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tCritical_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tCritRecov_%s", AdUnits[i].ad_name); //// incidence - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tincI_%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tincMild_%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tincILI_%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tincSARI_%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tincCritical_%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tincCritRecov_%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tincDeath_adu%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tincDeath_ILI_adu%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tincDeath_SARI_adu%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tincDeath_Critical_adu%s" , AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tincI_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tincMild_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tincILI_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tincSARI_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tincCritical_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tincCritRecov_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tincDeath_adu%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tincDeath_ILI_adu%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tincDeath_SARI_adu%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tincDeath_Critical_adu%s", AdUnits[i].ad_name); //// cumulative incidence - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tcumMild_%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tcumILI_%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tcumSARI_%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tcumCritical_%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tcumCritRecov_%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tcumDeaths_%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tcumDeath_ILI_%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tcumDeath_SARI_%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tcumDeath_Critical_%s" , AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tcumMild_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tcumILI_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tcumSARI_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tcumCritical_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tcumCritRecov_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tcumDeaths_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tcumDeath_ILI_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tcumDeath_SARI_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tcumDeath_Critical_%s", AdUnits[i].ad_name); fprintf(dat, "\n"); /////// ****** /////// ****** /////// ****** Populate table. - for(i = 0; i < P.NumSamples; i++) + for (i = 0; i < P.NumSamples; i++) { fprintf(dat, "%.10f", TimeSeries[i].t); //// prevalence - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", TimeSeries[i].Mild_adunit[j]); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", TimeSeries[i].ILI_adunit[j]); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", TimeSeries[i].SARI_adunit[j]); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", TimeSeries[i].Critical_adunit[j]); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", TimeSeries[i].CritRecov_adunit[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", TimeSeries[i].Mild_adunit[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", TimeSeries[i].ILI_adunit[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", TimeSeries[i].SARI_adunit[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", TimeSeries[i].Critical_adunit[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", TimeSeries[i].CritRecov_adunit[j]); //// incidence - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", TimeSeries[i].incI_adunit[j]); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", TimeSeries[i].incMild_adunit[j]); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", TimeSeries[i].incILI_adunit[j]); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", TimeSeries[i].incSARI_adunit[j]); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", TimeSeries[i].incCritical_adunit[j]); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", TimeSeries[i].incCritRecov_adunit[j]); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", TimeSeries[i].incD_adunit[j]); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", TimeSeries[i].incDeath_ILI_adunit[j]); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", TimeSeries[i].incDeath_SARI_adunit[j]); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", TimeSeries[i].incDeath_Critical_adunit[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", TimeSeries[i].incI_adunit[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", TimeSeries[i].incMild_adunit[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", TimeSeries[i].incILI_adunit[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", TimeSeries[i].incSARI_adunit[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", TimeSeries[i].incCritical_adunit[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", TimeSeries[i].incCritRecov_adunit[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", TimeSeries[i].incD_adunit[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", TimeSeries[i].incDeath_ILI_adunit[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", TimeSeries[i].incDeath_SARI_adunit[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", TimeSeries[i].incDeath_Critical_adunit[j]); //// cumulative incidence - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", TimeSeries[i].cumMild_adunit[j]); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", TimeSeries[i].cumILI_adunit[j]); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", TimeSeries[i].cumSARI_adunit[j]); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", TimeSeries[i].cumCritical_adunit[j]); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", TimeSeries[i].cumCritRecov_adunit[j]); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", TimeSeries[i].cumD_adunit[j]); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", TimeSeries[i].cumDeath_ILI_adunit[j]); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", TimeSeries[i].cumDeath_SARI_adunit[j]); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", TimeSeries[i].cumDeath_Critical_adunit[j]); - - if(i != P.NumSamples - 1) fprintf(dat, "\n"); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", TimeSeries[i].cumMild_adunit[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", TimeSeries[i].cumILI_adunit[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", TimeSeries[i].cumSARI_adunit[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", TimeSeries[i].cumCritical_adunit[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", TimeSeries[i].cumCritRecov_adunit[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", TimeSeries[i].cumD_adunit[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", TimeSeries[i].cumDeath_ILI_adunit[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", TimeSeries[i].cumDeath_SARI_adunit[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", TimeSeries[i].cumDeath_Critical_adunit[j]); + + if (i != P.NumSamples - 1) + fprintf(dat, "\n"); } fclose(dat); } @@ -3520,19 +5230,21 @@ void SaveResults(void) { //// output infections by age and admin unit sprintf(outname, "%s.age.adunit.xls", OutFile); - if (!(dat = fopen(outname, "wb"))) ERR_CRITICAL("Unable to open output file\n"); + if (!(dat = fopen(outname, "wb"))) + ERR_CRITICAL("Unable to open output file\n"); fprintf(dat, "t"); // colnames for (int AdUnit = 0; AdUnit < P.NumAdunits; AdUnit++) for (int AgeGroup = 0; AgeGroup < NUM_AGE_GROUPS; AgeGroup++) - fprintf(dat, "\tincInf_AG_%i_%s", AgeGroup, AdUnits[AdUnit].ad_name); // incidence + fprintf(dat, "\tincInf_AG_%i_%s", AgeGroup, AdUnits[AdUnit].ad_name); // incidence for (int AdUnit = 0; AdUnit < P.NumAdunits; AdUnit++) for (int AgeGroup = 0; AgeGroup < NUM_AGE_GROUPS; AgeGroup++) - fprintf(dat, "\tprevInf_AG_%i_%s", AgeGroup, AdUnits[AdUnit].ad_name); // prevalence + fprintf(dat, "\tprevInf_AG_%i_%s", AgeGroup, AdUnits[AdUnit].ad_name); // prevalence for (int AdUnit = 0; AdUnit < P.NumAdunits; AdUnit++) for (int AgeGroup = 0; AgeGroup < NUM_AGE_GROUPS; AgeGroup++) - fprintf(dat, "\tcumInf_AG_%i_%s", AgeGroup, AdUnits[AdUnit].ad_name); // cumulative incidence + fprintf(dat, "\tcumInf_AG_%i_%s", AgeGroup, + AdUnits[AdUnit].ad_name); // cumulative incidence fprintf(dat, "\n"); // Populate @@ -3541,23 +5253,27 @@ void SaveResults(void) fprintf(dat, "%.10f", TSMean[Time].t); for (int AdUnit = 0; AdUnit < P.NumAdunits; AdUnit++) for (int AgeGroup = 0; AgeGroup < NUM_AGE_GROUPS; AgeGroup++) - fprintf(dat, "\t%.10f", TimeSeries[Time].incInf_age_adunit[AgeGroup][AdUnit]); // incidence + fprintf(dat, "\t%.10f", + TimeSeries[Time].incInf_age_adunit[AgeGroup][AdUnit]); // incidence for (int AdUnit = 0; AdUnit < P.NumAdunits; AdUnit++) for (int AgeGroup = 0; AgeGroup < NUM_AGE_GROUPS; AgeGroup++) - fprintf(dat, "\t%.10f", TimeSeries[Time].prevInf_age_adunit[AgeGroup][AdUnit]); // prevalence + fprintf(dat, "\t%.10f", + TimeSeries[Time].prevInf_age_adunit[AgeGroup][AdUnit]); // prevalence for (int AdUnit = 0; AdUnit < P.NumAdunits; AdUnit++) for (int AgeGroup = 0; AgeGroup < NUM_AGE_GROUPS; AgeGroup++) - fprintf(dat, "\t%.10f", TimeSeries[Time].cumInf_age_adunit[AgeGroup][AdUnit]); // cumulative incidence + fprintf(dat, "\t%.10f", + TimeSeries[Time].cumInf_age_adunit[AgeGroup][AdUnit]); // cumulative incidence fprintf(dat, "\n"); } } } -void SaveSummaryResults(void) //// calculates and saves summary results (called for average of extinct and non-extinct realisation time series - look in main) +void SaveSummaryResults(void) //// calculates and saves summary results (called for average of + /// extinct and non-extinct realisation time series - look in main) { int i, j; double c, t; - FILE* dat; + FILE *dat; char outname[1024]; c = 1 / ((double)(P.NRactE + P.NRactNE)); @@ -3565,32 +5281,45 @@ void SaveSummaryResults(void) //// calculates and saves summary results (called if (P.OutputNonSeverity) { sprintf(outname, "%s.xls", OutFile); - if(!(dat = fopen(outname, "wb"))) ERR_CRITICAL("Unable to open output file\n"); + if (!(dat = fopen(outname, "wb"))) + ERR_CRITICAL("Unable to open output file\n"); //// set colnames - fprintf(dat, "t\tS\tL\tI\tR\tD\tincI\tincR\tincD\tincC\tincDC\tincTC\tcumT\tcumTmax\tcumTP\tcumV\tcumVmax\tExtinct\trmsRad\tmaxRad\tvS\tvI\tvR\tvD\tvincI\tvincR\tvincFC\tvincC\tvincDC\tvincTC\tvrmsRad\tvmaxRad\t\t%i\t%i\t%.10f\t%.10f\t%.10f\t\t%.10f\t%.10f\t%.10f\t%.10f\n", - P.NRactNE, P.NRactE, P.R0household, P.R0places, P.R0spatial, c * PeakHeightSum, c * PeakHeightSS - c * c * PeakHeightSum * PeakHeightSum, c * PeakTimeSum, c * PeakTimeSS - c * c * PeakTimeSum * PeakTimeSum); + fprintf( + dat, + "t\tS\tL\tI\tR\tD\tincI\tincR\tincD\tincC\tincDC\tincTC\tcumT\tcumTmax\tcumTP\tcumV\tcumVma" + "x\tExtinct\trmsRad\tmaxRad\tvS\tvI\tvR\tvD\tvincI\tvincR\tvincFC\tvincC\tvincDC\tvincTC\tv" + "rmsRad\tvmaxRad\t\t%i\t%i\t%.10f\t%.10f\t%.10f\t\t%.10f\t%.10f\t%.10f\t%.10f\n", + P.NRactNE, P.NRactE, P.R0household, P.R0places, P.R0spatial, c * PeakHeightSum, + c * PeakHeightSS - c * c * PeakHeightSum * PeakHeightSum, c * PeakTimeSum, + c * PeakTimeSS - c * c * PeakTimeSum * PeakTimeSum); c = 1 / ((double)P.NRactual); //// populate table - for(i = 0; i < P.NumSamples; i++) - { - fprintf(dat, "%.10f\t%10lf\t%10lf\t%10lf\t%10lf\t%10lf\t%10lf\t%10lf\t%10lf\t%10lf\t%10lf\t%10lf\t%10lf\t%10lf\t%10lf\t%10lf\t%10lf\t%10lf\t%10lf\t%10lf\t", - c * TSMean[i].t, c * TSMean[i].S, c * TSMean[i].L, c * TSMean[i].I, c * TSMean[i].R, - c * TSMean[i].D, c * TSMean[i].incI, c * TSMean[i].incR, c * TSMean[i].incFC, c * TSMean[i].incC, c * TSMean[i].incDC, c * TSMean[i].incTC, - c * TSMean[i].cumT, TSMean[i].cumTmax, c * TSMean[i].cumTP, c * TSMean[i].cumV, TSMean[i].cumVmax, c * TSMean[i].extinct, c * TSMean[i].rmsRad, c * TSMean[i].maxRad); - fprintf(dat, "%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\n", - c * TSVar[i].S - c * c * TSMean[i].S * TSMean[i].S, - c * TSVar[i].I - c * c * TSMean[i].I * TSMean[i].I, - c * TSVar[i].R - c * c * TSMean[i].R * TSMean[i].R, - c * TSVar[i].D - c * c * TSMean[i].D * TSMean[i].D, - c * TSVar[i].incI - c * c * TSMean[i].incI * TSMean[i].incI, - c * TSVar[i].incR - c * c * TSMean[i].incR * TSMean[i].incR, - c * TSVar[i].incD - c * c * TSMean[i].incD * TSMean[i].incD, - c * TSVar[i].incC - c * c * TSMean[i].incC * TSMean[i].incC, - c * TSVar[i].incDC - c * c * TSMean[i].incDC * TSMean[i].incDC, //added detected cases - c * TSVar[i].incTC - c * c * TSMean[i].incTC * TSMean[i].incTC, - c * TSVar[i].rmsRad - c * c * TSMean[i].rmsRad * TSMean[i].rmsRad, - c * TSVar[i].maxRad - c * c * TSMean[i].maxRad * TSMean[i].maxRad); + for (i = 0; i < P.NumSamples; i++) + { + fprintf(dat, + "%.10f\t%10lf\t%10lf\t%10lf\t%10lf\t%10lf\t%10lf\t%10lf\t%10lf\t%10lf\t%10lf\t%" + "10lf\t%10lf\t%10lf\t%10lf\t%10lf\t%10lf\t%10lf\t%10lf\t%10lf\t", + c * TSMean[i].t, c * TSMean[i].S, c * TSMean[i].L, c * TSMean[i].I, c * TSMean[i].R, + c * TSMean[i].D, c * TSMean[i].incI, c * TSMean[i].incR, c * TSMean[i].incFC, + c * TSMean[i].incC, c * TSMean[i].incDC, c * TSMean[i].incTC, c * TSMean[i].cumT, + TSMean[i].cumTmax, c * TSMean[i].cumTP, c * TSMean[i].cumV, TSMean[i].cumVmax, + c * TSMean[i].extinct, c * TSMean[i].rmsRad, c * TSMean[i].maxRad); + fprintf( + dat, + "%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\n", + c * TSVar[i].S - c * c * TSMean[i].S * TSMean[i].S, + c * TSVar[i].I - c * c * TSMean[i].I * TSMean[i].I, + c * TSVar[i].R - c * c * TSMean[i].R * TSMean[i].R, + c * TSVar[i].D - c * c * TSMean[i].D * TSMean[i].D, + c * TSVar[i].incI - c * c * TSMean[i].incI * TSMean[i].incI, + c * TSVar[i].incR - c * c * TSMean[i].incR * TSMean[i].incR, + c * TSVar[i].incD - c * c * TSMean[i].incD * TSMean[i].incD, + c * TSVar[i].incC - c * c * TSMean[i].incC * TSMean[i].incC, + c * TSVar[i].incDC - c * c * TSMean[i].incDC * TSMean[i].incDC, // added detected cases + c * TSVar[i].incTC - c * c * TSMean[i].incTC * TSMean[i].incTC, + c * TSVar[i].rmsRad - c * c * TSMean[i].rmsRad * TSMean[i].rmsRad, + c * TSVar[i].maxRad - c * c * TSMean[i].maxRad * TSMean[i].maxRad); } fclose(dat); } @@ -3598,88 +5327,105 @@ void SaveSummaryResults(void) //// calculates and saves summary results (called if (P.OutputControls) { sprintf(outname, "%s.controls.xls", OutFile); - if(!(dat = fopen(outname, "wb"))) ERR_CRITICAL("Unable to open output file\n"); - fprintf(dat, "t\tS\tincC\tincTC\tincFC\tcumT\tcumUT\tcumTP\tcumV\tincHQ\tincAC\tincAH\tincAA\tincACS\tincAPC\tincAPA\tincAPCS\tpropSocDist"); - for(j = 0; j < NUM_PLACE_TYPES; j++) fprintf(dat, "\tprClosed_%i", j); + if (!(dat = fopen(outname, "wb"))) + ERR_CRITICAL("Unable to open output file\n"); + fprintf(dat, "t\tS\tincC\tincTC\tincFC\tcumT\tcumUT\tcumTP\tcumV\tincHQ\tincAC\tincAH\tincAA\ti" + "ncACS\tincAPC\tincAPA\tincAPCS\tpropSocDist"); + for (j = 0; j < NUM_PLACE_TYPES; j++) + fprintf(dat, "\tprClosed_%i", j); fprintf(dat, "t\tvS\tvincC\tvincTC\tvincFC\tvcumT\tvcumUT\tvcumTP\tvcumV"); - for(j = 0; j < NUM_PLACE_TYPES; j++) fprintf(dat, "\tvprClosed_%i", j); + for (j = 0; j < NUM_PLACE_TYPES; j++) + fprintf(dat, "\tvprClosed_%i", j); fprintf(dat, "\n"); - for(i = 0; i < P.NumSamples; i++) - { - fprintf(dat, "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf", - c * TSMean[i].t, c * TSMean[i].S, c * TSMean[i].incC, c * TSMean[i].incTC, c * TSMean[i].incFC, - c * TSMean[i].cumT, c * TSMean[i].cumUT, c * TSMean[i].cumTP, c * TSMean[i].cumV, c * TSMean[i].incHQ, - c * TSMean[i].incAC, c * TSMean[i].incAH, c * TSMean[i].incAA, c * TSMean[i].incACS, - c * TSMean[i].incAPC, c * TSMean[i].incAPA, c * TSMean[i].incAPCS,c*TSMean[i].PropSocDist); - for(j = 0; j < NUM_PLACE_TYPES; j++) fprintf(dat, "\t%lf", c * TSMean[i].PropPlacesClosed[j]); + for (i = 0; i < P.NumSamples; i++) + { + fprintf(dat, + "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%" + "lf\t%lf", + c * TSMean[i].t, c * TSMean[i].S, c * TSMean[i].incC, c * TSMean[i].incTC, + c * TSMean[i].incFC, c * TSMean[i].cumT, c * TSMean[i].cumUT, c * TSMean[i].cumTP, + c * TSMean[i].cumV, c * TSMean[i].incHQ, c * TSMean[i].incAC, c * TSMean[i].incAH, + c * TSMean[i].incAA, c * TSMean[i].incACS, c * TSMean[i].incAPC, c * TSMean[i].incAPA, + c * TSMean[i].incAPCS, c * TSMean[i].PropSocDist); + for (j = 0; j < NUM_PLACE_TYPES; j++) + fprintf(dat, "\t%lf", c * TSMean[i].PropPlacesClosed[j]); fprintf(dat, "\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf", - c * TSVar[i].S - c * c * TSMean[i].S * TSMean[i].S, - c * TSVar[i].incC - c * c * TSMean[i].incC * TSMean[i].incC, - c * TSVar[i].incTC - c * c * TSMean[i].incTC * TSMean[i].incTC, - c * TSVar[i].incFC - c * c * TSMean[i].incFC * TSMean[i].incFC, - c * TSVar[i].cumT - c * c * TSMean[i].cumT * TSMean[i].cumT, - c * TSVar[i].cumUT - c * c * TSMean[i].cumUT * TSMean[i].cumUT, - c * TSVar[i].cumTP - c * c * TSMean[i].cumTP * TSMean[i].cumTP, - c * TSVar[i].cumV - c * c * TSMean[i].cumV * TSMean[i].cumV); - for(j = 0; j < NUM_PLACE_TYPES; j++) fprintf(dat, "\t%lf", TSVar[i].PropPlacesClosed[j]); + c * TSVar[i].S - c * c * TSMean[i].S * TSMean[i].S, + c * TSVar[i].incC - c * c * TSMean[i].incC * TSMean[i].incC, + c * TSVar[i].incTC - c * c * TSMean[i].incTC * TSMean[i].incTC, + c * TSVar[i].incFC - c * c * TSMean[i].incFC * TSMean[i].incFC, + c * TSVar[i].cumT - c * c * TSMean[i].cumT * TSMean[i].cumT, + c * TSVar[i].cumUT - c * c * TSMean[i].cumUT * TSMean[i].cumUT, + c * TSVar[i].cumTP - c * c * TSMean[i].cumTP * TSMean[i].cumTP, + c * TSVar[i].cumV - c * c * TSMean[i].cumV * TSMean[i].cumV); + for (j = 0; j < NUM_PLACE_TYPES; j++) + fprintf(dat, "\t%lf", TSVar[i].PropPlacesClosed[j]); fprintf(dat, "\n"); - } + } fclose(dat); - } if (P.OutputAge) { sprintf(outname, "%s.age.xls", OutFile); - if(!(dat = fopen(outname, "wb"))) ERR_CRITICAL("Unable to open output file\n"); + if (!(dat = fopen(outname, "wb"))) + ERR_CRITICAL("Unable to open output file\n"); fprintf(dat, "t"); - for(i = 0; i < NUM_AGE_GROUPS; i++) + for (i = 0; i < NUM_AGE_GROUPS; i++) fprintf(dat, "\tI%i-%i", AGE_GROUP_WIDTH * i, AGE_GROUP_WIDTH * (i + 1)); - for(i = 0; i < NUM_AGE_GROUPS; i++) + for (i = 0; i < NUM_AGE_GROUPS; i++) fprintf(dat, "\tC%i-%i", AGE_GROUP_WIDTH * i, AGE_GROUP_WIDTH * (i + 1)); - for(i = 0; i < NUM_AGE_GROUPS; i++) + for (i = 0; i < NUM_AGE_GROUPS; i++) fprintf(dat, "\tD%i-%i", AGE_GROUP_WIDTH * i, AGE_GROUP_WIDTH * (i + 1)); fprintf(dat, "\n"); - for(i = 0; i < P.NumSamples; i++) - { + for (i = 0; i < P.NumSamples; i++) + { fprintf(dat, "%.10f", c * TSMean[i].t); - for(j = 0; j < NUM_AGE_GROUPS; j++) + for (j = 0; j < NUM_AGE_GROUPS; j++) fprintf(dat, "\t%.10f", c * TSMean[i].incIa[j]); - for(j = 0; j < NUM_AGE_GROUPS; j++) + for (j = 0; j < NUM_AGE_GROUPS; j++) fprintf(dat, "\t%.10f", c * TSMean[i].incCa[j]); - for(j = 0; j < NUM_AGE_GROUPS; j++) + for (j = 0; j < NUM_AGE_GROUPS; j++) fprintf(dat, "\t%.10f", c * TSMean[i].incDa[j]); fprintf(dat, "\n"); - } + } fprintf(dat, "dist"); - for(j = 0; j < NUM_AGE_GROUPS; j++) + for (j = 0; j < NUM_AGE_GROUPS; j++) fprintf(dat, "\t%.10f", AgeDist[j]); fprintf(dat, "\n"); fclose(dat); } - if((P.DoAdUnits) && (P.DoAdunitOutput)) + if ((P.DoAdUnits) && (P.DoAdunitOutput)) { sprintf(outname, "%s.adunit.xls", OutFile); - if(!(dat = fopen(outname, "wb"))) ERR_CRITICAL("Unable to open output file\n"); + if (!(dat = fopen(outname, "wb"))) + ERR_CRITICAL("Unable to open output file\n"); fprintf(dat, "t"); - for(i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tI_%s", AdUnits[i].ad_name); - for(i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tC_%s", AdUnits[i].ad_name); - for(i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tDC_%s", AdUnits[i].ad_name); //added detected cases: ggilani 03/02/15 - for(i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tT_%s", AdUnits[i].ad_name); - for(i = 0; i < P.NumAdunits; i++) fprintf(dat, "\t%.10f", P.PopByAdunit[i][0]); - for(i = 0; i < P.NumAdunits; i++) fprintf(dat, "\t%.10f", P.PopByAdunit[i][1]); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tI_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tC_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tDC_%s", AdUnits[i].ad_name); // added detected cases: ggilani 03/02/15 + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tT_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\t%.10f", P.PopByAdunit[i][0]); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\t%.10f", P.PopByAdunit[i][1]); fprintf(dat, "\n"); - for(i = 0; i < P.NumSamples; i++) + for (i = 0; i < P.NumSamples; i++) { fprintf(dat, "%.10f", c * TSMean[i].t); - for(j = 0; j < P.NumAdunits; j++) + for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", c * TSMean[i].incI_adunit[j]); - for(j = 0; j < P.NumAdunits; j++) + for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", c * TSMean[i].incC_adunit[j]); - for(j = 0; j < P.NumAdunits; j++) - fprintf(dat, "\t%.10f", c * TSMean[i].incDC_adunit[j]); //added detected cases: ggilani 03/02/15 - for(j = 0; j < P.NumAdunits; j++) + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", + c * TSMean[i].incDC_adunit[j]); // added detected cases: ggilani 03/02/15 + for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", c * TSMean[i].cumT_adunit[j]); fprintf(dat, "\n"); } @@ -3688,24 +5434,38 @@ void SaveSummaryResults(void) //// calculates and saves summary results (called if (P.OutputAdUnitVar) { sprintf(outname, "%s.adunitVar.xls", OutFile); - if (!(dat = fopen(outname, "wb"))) ERR_CRITICAL("Unable to open output file\n"); + if (!(dat = fopen(outname, "wb"))) + ERR_CRITICAL("Unable to open output file\n"); fprintf(dat, "t"); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tI_%s", AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tC_%s", AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tDC_%s", AdUnits[i].ad_name); //added detected cases: ggilani 03/02/15 - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tT_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tI_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tC_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tDC_%s", AdUnits[i].ad_name); // added detected cases: ggilani 03/02/15 + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tT_%s", AdUnits[i].ad_name); fprintf(dat, "\n"); for (i = 0; i < P.NumSamples; i++) { fprintf(dat, "%.10f", c * TSMean[i].t); for (j = 0; j < P.NumAdunits; j++) - fprintf(dat, "\t%.10f", c * TSVar[i].incI_adunit[j] - c * c * TSMean[i].incI_adunit[j] * TSMean[i].incI_adunit[j]); + fprintf(dat, "\t%.10f", + c * TSVar[i].incI_adunit[j] - + c * c * TSMean[i].incI_adunit[j] * TSMean[i].incI_adunit[j]); for (j = 0; j < P.NumAdunits; j++) - fprintf(dat, "\t%.10f", c * TSVar[i].incC_adunit[j] - c * c * TSMean[i].incC_adunit[j] * TSMean[i].incC_adunit[j]); + fprintf(dat, "\t%.10f", + c * TSVar[i].incC_adunit[j] - + c * c * TSMean[i].incC_adunit[j] * TSMean[i].incC_adunit[j]); for (j = 0; j < P.NumAdunits; j++) - fprintf(dat, "\t%.10f", c * TSVar[i].incDC_adunit[j] - c * c * TSMean[i].incDC_adunit[j] * TSMean[i].incDC_adunit[j]); //added detected cases: ggilani 03/02/15 + fprintf(dat, "\t%.10f", + c * TSVar[i].incDC_adunit[j] - + c * c * TSMean[i].incDC_adunit[j] * + TSMean[i].incDC_adunit[j]); // added detected cases: ggilani 03/02/15 for (j = 0; j < P.NumAdunits; j++) - fprintf(dat, "\t%.10f", c * TSVar[i].cumT_adunit[j] - c * c * TSMean[i].cumT_adunit[j] * TSMean[i].cumT_adunit[j]); + fprintf(dat, "\t%.10f", + c * TSVar[i].cumT_adunit[j] - + c * c * TSMean[i].cumT_adunit[j] * TSMean[i].cumT_adunit[j]); fprintf(dat, "\n"); } fclose(dat); @@ -3715,7 +5475,8 @@ void SaveSummaryResults(void) //// calculates and saves summary results (called if ((P.DoDigitalContactTracing) && (P.DoAdUnits) && (P.OutputDigitalContactTracing)) { sprintf(outname, "%s.digitalcontacttracing.xls", OutFile); - if (!(dat = fopen(outname, "wb"))) ERR_CRITICAL("Unable to open output file\n"); + if (!(dat = fopen(outname, "wb"))) + ERR_CRITICAL("Unable to open output file\n"); fprintf(dat, "t"); for (i = 0; i < P.NumAdunits; i++) { @@ -3723,13 +5484,14 @@ void SaveSummaryResults(void) //// calculates and saves summary results (called } for (i = 0; i < P.NumAdunits; i++) { - fprintf(dat, "\tDCT_%s", AdUnits[i].ad_name); // //printing headers for prevalence of digital contact tracing per admin unit + fprintf(dat, "\tDCT_%s", AdUnits[i].ad_name); // //printing headers for prevalence of digital + // contact tracing per admin unit } fprintf(dat, "\n"); - //print actual output + // print actual output for (i = 0; i < P.NumSamples; i++) { - fprintf(dat, "%.10lf", c* TSMean[i].t); + fprintf(dat, "%.10lf", c * TSMean[i].t); for (j = 0; j < P.NumAdunits; j++) { fprintf(dat, "\t%.10lf", c * TSMean[i].incDCT_adunit[j]); @@ -3742,56 +5504,76 @@ void SaveSummaryResults(void) //// calculates and saves summary results (called } fclose(dat); - } - if(P.KeyWorkerProphTimeStartBase < P.SampleTime) + if (P.KeyWorkerProphTimeStartBase < P.SampleTime) { sprintf(outname, "%s.keyworker.xls", OutFile); - if(!(dat = fopen(outname, "wb"))) ERR_CRITICAL("Unable to open output file\n"); + if (!(dat = fopen(outname, "wb"))) + ERR_CRITICAL("Unable to open output file\n"); fprintf(dat, "t"); - for(i = 0; i < 2; i++) fprintf(dat, "\tI%i", i); - for(i = 0; i < 2; i++) fprintf(dat, "\tC%i", i); - for(i = 0; i < 2; i++) fprintf(dat, "\tT%i", i); - for(i = 0; i < 2; i++) fprintf(dat, "\tvI%i", i); - for(i = 0; i < 2; i++) fprintf(dat, "\tvC%i", i); - for(i = 0; i < 2; i++) fprintf(dat, "\tvT%i", i); + for (i = 0; i < 2; i++) + fprintf(dat, "\tI%i", i); + for (i = 0; i < 2; i++) + fprintf(dat, "\tC%i", i); + for (i = 0; i < 2; i++) + fprintf(dat, "\tT%i", i); + for (i = 0; i < 2; i++) + fprintf(dat, "\tvI%i", i); + for (i = 0; i < 2; i++) + fprintf(dat, "\tvC%i", i); + for (i = 0; i < 2; i++) + fprintf(dat, "\tvT%i", i); fprintf(dat, "\t%i\t%i\n", P.KeyWorkerNum, P.KeyWorkerIncHouseNum); - for(i = 0; i < P.NumSamples; i++) - { + for (i = 0; i < P.NumSamples; i++) + { fprintf(dat, "%.10f", c * TSMean[i].t); - for(j = 0; j < 2; j++) + for (j = 0; j < 2; j++) fprintf(dat, "\t%.10f", c * TSMean[i].incI_keyworker[j]); - for(j = 0; j < 2; j++) + for (j = 0; j < 2; j++) fprintf(dat, "\t%.10f", c * TSMean[i].incC_keyworker[j]); - for(j = 0; j < 2; j++) + for (j = 0; j < 2; j++) fprintf(dat, "\t%.10f", c * TSMean[i].cumT_keyworker[j]); - for(j = 0; j < 2; j++) - fprintf(dat, "\t%.10f", c * TSVar[i].incI_keyworker[j] - c * c * TSMean[i].incI_keyworker[j] * TSMean[i].incI_keyworker[j]); - for(j = 0; j < 2; j++) - fprintf(dat, "\t%.10f", c * TSVar[i].incC_keyworker[j] - c * c * TSMean[i].incC_keyworker[j] * TSMean[i].incC_keyworker[j]); - for(j = 0; j < 2; j++) - fprintf(dat, "\t%.10f", c * TSVar[i].cumT_keyworker[j] - c * c * TSMean[i].cumT_keyworker[j] * TSMean[i].cumT_keyworker[j]); + for (j = 0; j < 2; j++) + fprintf(dat, "\t%.10f", + c * TSVar[i].incI_keyworker[j] - + c * c * TSMean[i].incI_keyworker[j] * TSMean[i].incI_keyworker[j]); + for (j = 0; j < 2; j++) + fprintf(dat, "\t%.10f", + c * TSVar[i].incC_keyworker[j] - + c * c * TSMean[i].incC_keyworker[j] * TSMean[i].incC_keyworker[j]); + for (j = 0; j < 2; j++) + fprintf(dat, "\t%.10f", + c * TSVar[i].cumT_keyworker[j] - + c * c * TSMean[i].cumT_keyworker[j] * TSMean[i].cumT_keyworker[j]); fprintf(dat, "\n"); - } + } fclose(dat); } if (P.OutputInfType) { sprintf(outname, "%s.inftype.xls", OutFile); - if (!(dat = fopen(outname, "wb"))) ERR_CRITICAL("Unable to open output file\n"); + if (!(dat = fopen(outname, "wb"))) + ERR_CRITICAL("Unable to open output file\n"); fprintf(dat, "t\tR\tTG\tSI"); - for (j = 0; j < INFECT_TYPE_MASK; j++) fprintf(dat, "\tRtype_%i", j); - for (j = 0; j < INFECT_TYPE_MASK; j++) fprintf(dat, "\tincItype_%i", j); - for (j = 0; j < NUM_AGE_GROUPS; j++) fprintf(dat, "\tRage_%i", j); + for (j = 0; j < INFECT_TYPE_MASK; j++) + fprintf(dat, "\tRtype_%i", j); + for (j = 0; j < INFECT_TYPE_MASK; j++) + fprintf(dat, "\tincItype_%i", j); + for (j = 0; j < NUM_AGE_GROUPS; j++) + fprintf(dat, "\tRage_%i", j); fprintf(dat, "\n"); for (i = 0; i < P.NumSamples; i++) { - fprintf(dat, "%lf\t%lf\t%lf\t%lf", c * TSMean[i].t, c * TSMean[i].Rdenom, c* TSMean[i].meanTG, c* TSMean[i].meanSI); - for (j = 0; j < INFECT_TYPE_MASK; j++) fprintf(dat, "\t%lf", c * TSMean[i].Rtype[j]); - for (j = 0; j < INFECT_TYPE_MASK; j++) fprintf(dat, "\t%lf", c * TSMean[i].incItype[j]); - for (j = 0; j < NUM_AGE_GROUPS; j++) fprintf(dat, "\t%lf", c * TSMean[i].Rage[j]); + fprintf(dat, "%lf\t%lf\t%lf\t%lf", c * TSMean[i].t, c * TSMean[i].Rdenom, + c * TSMean[i].meanTG, c * TSMean[i].meanSI); + for (j = 0; j < INFECT_TYPE_MASK; j++) + fprintf(dat, "\t%lf", c * TSMean[i].Rtype[j]); + for (j = 0; j < INFECT_TYPE_MASK; j++) + fprintf(dat, "\t%lf", c * TSMean[i].incItype[j]); + for (j = 0; j < NUM_AGE_GROUPS; j++) + fprintf(dat, "\t%lf", c * TSMean[i].Rage[j]); fprintf(dat, "\n"); } fclose(dat); @@ -3800,7 +5582,8 @@ void SaveSummaryResults(void) //// calculates and saves summary results (called if (P.OutputR0) { sprintf(outname, "%s.R0.xls", OutFile); - if (!(dat = fopen(outname, "wb"))) ERR_CRITICAL("Unable to open output file\n"); + if (!(dat = fopen(outname, "wb"))) + ERR_CRITICAL("Unable to open output file\n"); for (i = 0; i < MAX_SEC_REC; i++) { fprintf(dat, "%i", i); @@ -3828,7 +5611,8 @@ void SaveSummaryResults(void) //// calculates and saves summary results (called t += case_household_av[i][j]; case_household_av[i][0] = denom_household[i] / c - t; } - if (!(dat = fopen(outname, "wb"))) ERR_CRITICAL("Unable to open output file\n"); + if (!(dat = fopen(outname, "wb"))) + ERR_CRITICAL("Unable to open output file\n"); for (i = 1; i <= MAX_HOUSEHOLD_SIZE; i++) fprintf(dat, "\t%i", i); fprintf(dat, "\n"); @@ -3856,7 +5640,8 @@ void SaveSummaryResults(void) //// calculates and saves summary results (called if (P.OutputCountry) { sprintf(outname, "%s.country.xls", OutFile); - if (!(dat = fopen(outname, "wb"))) ERR_CRITICAL("Unable to open output file\n"); + if (!(dat = fopen(outname, "wb"))) + ERR_CRITICAL("Unable to open output file\n"); for (i = 0; i < MAX_COUNTRIES; i++) fprintf(dat, "%i\t%.10f\t%.10f\n", i, infcountry_av[i] * c, infcountry_num[i] * c); fclose(dat); @@ -3867,14 +5652,27 @@ void SaveSummaryResults(void) //// calculates and saves summary results (called //// output separate severity file (can integrate with main if need be) sprintf(outname, "%s.severity.xls", OutFile); - if (!(dat = fopen(outname, "wb"))) ERR_CRITICAL("Unable to open severity output file\n"); - fprintf(dat, "t\tPropSocDist\tRt\tTG\tSI\tS\tI\tR\tincI\tincC\tMild\tILI\tSARI\tCritical\tCritRecov\tSARIP\tCriticalP\tCritRecovP\tprevQuarNotInfected\tprevQuarNotSymptomatic\tincMild\tincILI\tincSARI\tincCritical\tincCritRecov\tincSARIP\tincCriticalP\tincCritRecovP\tincDeath\tincDeath_ILI\tincDeath_SARI\tincDeath_Critical\tcumMild\tcumILI\tcumSARI\tcumCritical\tcumCritRecov\tcumDeath\tcumDeath_ILI\tcumDeath_SARI\tcumDeath_Critical\t"); - fprintf(dat, "PropSocDist_v\tRt_v\tTG_v\tSI_v\tS_v\tI_v\tR_v\tincI_v\tincC_v\tMild_v\tILI_v\tSARI_v\tCritical_v\tCritRecov_v\tincMild_v\tincILI_v\tincSARI_v\tincCritical_v\tincCritRecov_v\tincDeath_v\tincDeath_ILI_v\tincDeath_SARI_v\tincDeath_Critical_v\tcumMild_v\tcumILI_v\tcumSARI_v\tcumCritical_v\tcumCritRecov_v\tcumDeath_v\tcumDeath_ILI_v\tcumDeath_SARI_v\tcumDeath_Critical_v\n"); - double SARI, Critical, CritRecov, incSARI, incCritical, incCritRecov, sc1, sc2,sc3,sc4; //this stuff corrects bed prevalence for exponentially distributed time to test results in hospital + if (!(dat = fopen(outname, "wb"))) + ERR_CRITICAL("Unable to open severity output file\n"); + fprintf(dat, "t\tPropSocDist\tRt\tTG\tSI\tS\tI\tR\tincI\tincC\tMild\tILI\tSARI\tCritical\tCritR" + "ecov\tSARIP\tCriticalP\tCritRecovP\tprevQuarNotInfected\tprevQuarNotSymptomatic\t" + "incMild\tincILI\tincSARI\tincCritical\tincCritRecov\tincSARIP\tincCriticalP\tincC" + "ritRecovP\tincDeath\tincDeath_ILI\tincDeath_SARI\tincDeath_" + "Critical\tcumMild\tcumILI\tcumSARI\tcumCritical\tcumCritRecov\tcumDeath\tcumDeath" + "_ILI\tcumDeath_SARI\tcumDeath_Critical\t"); + fprintf(dat, "PropSocDist_v\tRt_v\tTG_v\tSI_v\tS_v\tI_v\tR_v\tincI_v\tincC_v\tMild_v\tILI_" + "v\tSARI_v\tCritical_v\tCritRecov_v\tincMild_v\tincILI_v\tincSARI_v\tincCritical_" + "v\tincCritRecov_v\tincDeath_v\tincDeath_ILI_v\tincDeath_SARI_v\tincDeath_" + "Critical_v\tcumMild_v\tcumILI_v\tcumSARI_v\tcumCritical_v\tcumCritRecov_" + "v\tcumDeath_v\tcumDeath_ILI_v\tcumDeath_SARI_v\tcumDeath_Critical_v\n"); + double SARI, Critical, CritRecov, incSARI, incCritical, incCritRecov, sc1, sc2, sc3, + sc4; // this stuff corrects bed prevalence for exponentially distributed time to test + // results in hospital sc1 = (P.Mean_TimeToTest > 0) ? exp(-1.0 / P.Mean_TimeToTest) : 0.0; sc2 = (P.Mean_TimeToTest > 0) ? exp(-P.Mean_TimeToTestOffset / P.Mean_TimeToTest) : 0.0; sc3 = (P.Mean_TimeToTest > 0) ? exp(-P.Mean_TimeToTestCriticalOffset / P.Mean_TimeToTest) : 0.0; - sc4 = (P.Mean_TimeToTest > 0) ? exp(-P.Mean_TimeToTestCritRecovOffset / P.Mean_TimeToTest) : 0.0; + sc4 = + (P.Mean_TimeToTest > 0) ? exp(-P.Mean_TimeToTestCritRecovOffset / P.Mean_TimeToTest) : 0.0; incSARI = incCritical = incCritRecov = 0; for (i = 0; i < P.NumSamples; i++) { @@ -3894,105 +5692,164 @@ void SaveSummaryResults(void) //// calculates and saves summary results (called CritRecov = TSMean[i].CritRecov * sc4; } - fprintf(dat, "%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.17f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t", - c* TSMean[i].t, c* TSMean[i].PropSocDist, c* TSMean[i].Rdenom, c* TSMean[i].meanTG, c* TSMean[i].meanSI, c* TSMean[i].S, c* TSMean[i].I, c* TSMean[i].R, c* TSMean[i].incI, c* TSMean[i].incC, - c* TSMean[i].Mild, c* TSMean[i].ILI, c* TSMean[i].SARI,c* TSMean[i].Critical, c* TSMean[i].CritRecov,c* (TSMean[i].SARI - SARI), c* (TSMean[i].Critical - Critical), c* (TSMean[i].CritRecov - CritRecov), - c * TSMean[i].prevQuarNotInfected, c * TSMean[i].prevQuarNotSymptomatic, - c * TSMean[i].incMild, c * TSMean[i].incILI, c * TSMean[i].incSARI, c * TSMean[i].incCritical, c * TSMean[i].incCritRecov, c * incSARI, c * incCritical, c * incCritRecov, c * TSMean[i].incD, - c * TSMean[i].incDeath_ILI, c * TSMean[i].incDeath_SARI, c * TSMean[i].incDeath_Critical, - c * TSMean[i].cumMild, c * TSMean[i].cumILI, c * TSMean[i].cumSARI, c * TSMean[i].cumCritical, c * TSMean[i].cumCritRecov, c*TSMean[i].D, - c * TSMean[i].cumDeath_ILI, c * TSMean[i].cumDeath_SARI, c * TSMean[i].cumDeath_Critical); - fprintf(dat, "%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\n", - c* TSVar[i].PropSocDist- c * TSMean[i].PropSocDist* c * TSMean[i].PropSocDist, - c* TSVar[i].Rdenom - c * TSMean[i].Rdenom * c * TSMean[i].Rdenom, - c* TSVar[i].meanTG - c * TSMean[i].meanTG * c * TSMean[i].meanTG, - c* TSVar[i].meanSI - c * TSMean[i].meanSI * c * TSMean[i].meanSI, - c* TSVar[i].S- c * TSMean[i].S* c * TSMean[i].S, - c* TSVar[i].I- c * TSMean[i].I* c * TSMean[i].I, - c* TSVar[i].R- c * TSMean[i].R* c * TSMean[i].R, - c* TSVar[i].incI- c * TSMean[i].incI* c * TSMean[i].incI, - c* TSVar[i].incC- c * TSMean[i].incC* c * TSMean[i].incC, - c* TSVar[i].Mild- c * TSMean[i].Mild* c * TSMean[i].Mild, - c* TSVar[i].ILI- c * TSMean[i].incILI* c * TSMean[i].incILI, - c* TSVar[i].SARI- c * TSMean[i].SARI* c * TSMean[i].SARI, - c* TSVar[i].Critical- c * TSMean[i].Critical* c * TSMean[i].Critical, - c* TSVar[i].CritRecov- c * TSMean[i].CritRecov* c * TSMean[i].CritRecov, - c* TSVar[i].incMild- c * TSMean[i].incMild* c * TSMean[i].incMild, - c* TSVar[i].incILI- c * TSMean[i].incILI* c * TSMean[i].incILI, - c* TSVar[i].incSARI- c * TSMean[i].incSARI* c * TSMean[i].incSARI, - c* TSVar[i].incCritical- c * TSMean[i].incCritical* c * TSMean[i].incCritical, - c* TSVar[i].incCritRecov- c * TSMean[i].incCritRecov* c * TSMean[i].incCritRecov, - c* TSVar[i].incD- c * TSMean[i].incD* c * TSMean[i].incD, - c* TSVar[i].incDeath_ILI- c * TSMean[i].incDeath_ILI* c * TSMean[i].incDeath_ILI, - c* TSVar[i].incDeath_SARI- c * TSMean[i].incDeath_SARI* c * TSMean[i].incDeath_SARI, - c* TSVar[i].incDeath_Critical- c * TSMean[i].incDeath_Critical* c * TSMean[i].incDeath_Critical, - c* TSVar[i].cumMild- c * TSMean[i].cumMild* c * TSMean[i].cumMild, - c* TSVar[i].cumILI- c * TSMean[i].cumILI* c * TSMean[i].cumILI, - c* TSVar[i].cumSARI- c * TSMean[i].cumSARI* c * TSMean[i].cumSARI, - c* TSVar[i].cumCritical- c * TSMean[i].cumCritical* c * TSMean[i].cumCritical, - c* TSVar[i].cumCritRecov- c * TSMean[i].cumCritRecov* c * TSMean[i].cumCritRecov, - c* TSVar[i].D- c * TSMean[i].D* c * TSMean[i].D, - c* TSVar[i].cumDeath_ILI- c * TSMean[i].cumDeath_ILI* c * TSMean[i].cumDeath_ILI, - c* TSVar[i].cumDeath_SARI- c * TSMean[i].cumDeath_SARI* c * TSMean[i].cumDeath_SARI, - c* TSVar[i].cumDeath_Critical- c * TSMean[i].cumDeath_Critical* c * TSMean[i].cumDeath_Critical); + fprintf(dat, + "%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.17f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%." + "10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%." + "10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%." + "10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t", + c * TSMean[i].t, c * TSMean[i].PropSocDist, c * TSMean[i].Rdenom, + c * TSMean[i].meanTG, c * TSMean[i].meanSI, c * TSMean[i].S, c * TSMean[i].I, + c * TSMean[i].R, c * TSMean[i].incI, c * TSMean[i].incC, c * TSMean[i].Mild, + c * TSMean[i].ILI, c * TSMean[i].SARI, c * TSMean[i].Critical, + c * TSMean[i].CritRecov, c * (TSMean[i].SARI - SARI), + c * (TSMean[i].Critical - Critical), c * (TSMean[i].CritRecov - CritRecov), + c * TSMean[i].prevQuarNotInfected, c * TSMean[i].prevQuarNotSymptomatic, + c * TSMean[i].incMild, c * TSMean[i].incILI, c * TSMean[i].incSARI, + c * TSMean[i].incCritical, c * TSMean[i].incCritRecov, c * incSARI, c * incCritical, + c * incCritRecov, c * TSMean[i].incD, c * TSMean[i].incDeath_ILI, + c * TSMean[i].incDeath_SARI, c * TSMean[i].incDeath_Critical, c * TSMean[i].cumMild, + c * TSMean[i].cumILI, c * TSMean[i].cumSARI, c * TSMean[i].cumCritical, + c * TSMean[i].cumCritRecov, c * TSMean[i].D, c * TSMean[i].cumDeath_ILI, + c * TSMean[i].cumDeath_SARI, c * TSMean[i].cumDeath_Critical); + fprintf( + dat, + "%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%." + "10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%." + "10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\t%.10f\n", + c * TSVar[i].PropSocDist - c * TSMean[i].PropSocDist * c * TSMean[i].PropSocDist, + c * TSVar[i].Rdenom - c * TSMean[i].Rdenom * c * TSMean[i].Rdenom, + c * TSVar[i].meanTG - c * TSMean[i].meanTG * c * TSMean[i].meanTG, + c * TSVar[i].meanSI - c * TSMean[i].meanSI * c * TSMean[i].meanSI, + c * TSVar[i].S - c * TSMean[i].S * c * TSMean[i].S, + c * TSVar[i].I - c * TSMean[i].I * c * TSMean[i].I, + c * TSVar[i].R - c * TSMean[i].R * c * TSMean[i].R, + c * TSVar[i].incI - c * TSMean[i].incI * c * TSMean[i].incI, + c * TSVar[i].incC - c * TSMean[i].incC * c * TSMean[i].incC, + c * TSVar[i].Mild - c * TSMean[i].Mild * c * TSMean[i].Mild, + c * TSVar[i].ILI - c * TSMean[i].incILI * c * TSMean[i].incILI, + c * TSVar[i].SARI - c * TSMean[i].SARI * c * TSMean[i].SARI, + c * TSVar[i].Critical - c * TSMean[i].Critical * c * TSMean[i].Critical, + c * TSVar[i].CritRecov - c * TSMean[i].CritRecov * c * TSMean[i].CritRecov, + c * TSVar[i].incMild - c * TSMean[i].incMild * c * TSMean[i].incMild, + c * TSVar[i].incILI - c * TSMean[i].incILI * c * TSMean[i].incILI, + c * TSVar[i].incSARI - c * TSMean[i].incSARI * c * TSMean[i].incSARI, + c * TSVar[i].incCritical - c * TSMean[i].incCritical * c * TSMean[i].incCritical, + c * TSVar[i].incCritRecov - c * TSMean[i].incCritRecov * c * TSMean[i].incCritRecov, + c * TSVar[i].incD - c * TSMean[i].incD * c * TSMean[i].incD, + c * TSVar[i].incDeath_ILI - c * TSMean[i].incDeath_ILI * c * TSMean[i].incDeath_ILI, + c * TSVar[i].incDeath_SARI - c * TSMean[i].incDeath_SARI * c * TSMean[i].incDeath_SARI, + c * TSVar[i].incDeath_Critical - + c * TSMean[i].incDeath_Critical * c * TSMean[i].incDeath_Critical, + c * TSVar[i].cumMild - c * TSMean[i].cumMild * c * TSMean[i].cumMild, + c * TSVar[i].cumILI - c * TSMean[i].cumILI * c * TSMean[i].cumILI, + c * TSVar[i].cumSARI - c * TSMean[i].cumSARI * c * TSMean[i].cumSARI, + c * TSVar[i].cumCritical - c * TSMean[i].cumCritical * c * TSMean[i].cumCritical, + c * TSVar[i].cumCritRecov - c * TSMean[i].cumCritRecov * c * TSMean[i].cumCritRecov, + c * TSVar[i].D - c * TSMean[i].D * c * TSMean[i].D, + c * TSVar[i].cumDeath_ILI - c * TSMean[i].cumDeath_ILI * c * TSMean[i].cumDeath_ILI, + c * TSVar[i].cumDeath_SARI - c * TSMean[i].cumDeath_SARI * c * TSMean[i].cumDeath_SARI, + c * TSVar[i].cumDeath_Critical - + c * TSMean[i].cumDeath_Critical * c * TSMean[i].cumDeath_Critical); } fclose(dat); if (P.OutputSeverityAge) { - double* SARI_a, * Critical_a, * CritRecov_a, * incSARI_a, * incCritical_a, * incCritRecov_a, sc1a, sc2a, sc3a, sc4a; //this stuff corrects bed prevalence for exponentially distributed time to test results in hospital - - if (!(SARI_a = (double*)malloc(NUM_AGE_GROUPS * sizeof(double)))) ERR_CRITICAL("Unable to allocate temp storage\n"); - if (!(Critical_a = (double*)malloc(NUM_AGE_GROUPS * sizeof(double)))) ERR_CRITICAL("Unable to allocate temp storage\n"); - if (!(CritRecov_a = (double*)malloc(NUM_AGE_GROUPS * sizeof(double)))) ERR_CRITICAL("Unable to allocate temp storage\n"); - if (!(incSARI_a = (double*)malloc(NUM_AGE_GROUPS * sizeof(double)))) ERR_CRITICAL("Unable to allocate temp storage\n"); - if (!(incCritical_a = (double*)malloc(NUM_AGE_GROUPS * sizeof(double)))) ERR_CRITICAL("Unable to allocate temp storage\n"); - if (!(incCritRecov_a = (double*)malloc(NUM_AGE_GROUPS * sizeof(double)))) ERR_CRITICAL("Unable to allocate temp storage\n"); + double *SARI_a, *Critical_a, *CritRecov_a, *incSARI_a, *incCritical_a, *incCritRecov_a, sc1a, + sc2a, sc3a, sc4a; // this stuff corrects bed prevalence for exponentially distributed time + // to test results in hospital + + if (!(SARI_a = (double *)malloc(NUM_AGE_GROUPS * sizeof(double)))) + ERR_CRITICAL("Unable to allocate temp storage\n"); + if (!(Critical_a = (double *)malloc(NUM_AGE_GROUPS * sizeof(double)))) + ERR_CRITICAL("Unable to allocate temp storage\n"); + if (!(CritRecov_a = (double *)malloc(NUM_AGE_GROUPS * sizeof(double)))) + ERR_CRITICAL("Unable to allocate temp storage\n"); + if (!(incSARI_a = (double *)malloc(NUM_AGE_GROUPS * sizeof(double)))) + ERR_CRITICAL("Unable to allocate temp storage\n"); + if (!(incCritical_a = (double *)malloc(NUM_AGE_GROUPS * sizeof(double)))) + ERR_CRITICAL("Unable to allocate temp storage\n"); + if (!(incCritRecov_a = (double *)malloc(NUM_AGE_GROUPS * sizeof(double)))) + ERR_CRITICAL("Unable to allocate temp storage\n"); sc1a = (P.Mean_TimeToTest > 0) ? exp(-1.0 / P.Mean_TimeToTest) : 0.0; sc2a = (P.Mean_TimeToTest > 0) ? exp(-P.Mean_TimeToTestOffset / P.Mean_TimeToTest) : 0.0; - sc3a = (P.Mean_TimeToTest > 0) ? exp(-P.Mean_TimeToTestCriticalOffset / P.Mean_TimeToTest) : 0.0; - sc4a = (P.Mean_TimeToTest > 0) ? exp(-P.Mean_TimeToTestCritRecovOffset / P.Mean_TimeToTest) : 0.0; - for (i = 0; i < NUM_AGE_GROUPS; i++) incSARI_a[i] = incCritical_a[i] = incCritRecov_a[i] = 0; + sc3a = + (P.Mean_TimeToTest > 0) ? exp(-P.Mean_TimeToTestCriticalOffset / P.Mean_TimeToTest) : 0.0; + sc4a = (P.Mean_TimeToTest > 0) ? exp(-P.Mean_TimeToTestCritRecovOffset / P.Mean_TimeToTest) + : 0.0; + for (i = 0; i < NUM_AGE_GROUPS; i++) + incSARI_a[i] = incCritical_a[i] = incCritRecov_a[i] = 0; //// output severity results by age group sprintf(outname, "%s.severity.age.xls", OutFile); - if (!(dat = fopen(outname, "wb"))) ERR_CRITICAL("Unable to open output file\n"); + if (!(dat = fopen(outname, "wb"))) + ERR_CRITICAL("Unable to open output file\n"); fprintf(dat, "t"); /////// ****** /////// ****** /////// ****** COLNAMES //// prevalance - for (i = 0; i < NUM_AGE_GROUPS; i++) fprintf(dat, "\tMild_%i", i); - for (i = 0; i < NUM_AGE_GROUPS; i++) fprintf(dat, "\tILI_%i", i); - for (i = 0; i < NUM_AGE_GROUPS; i++) fprintf(dat, "\tSARI_%i", i); - for (i = 0; i < NUM_AGE_GROUPS; i++) fprintf(dat, "\tCritical_%i", i); - for (i = 0; i < NUM_AGE_GROUPS; i++) fprintf(dat, "\tCritRecov_%i", i); - for (i = 0; i < NUM_AGE_GROUPS; i++) fprintf(dat, "\tSARIP_%i", i); - for (i = 0; i < NUM_AGE_GROUPS; i++) fprintf(dat, "\tCriticalP_%i", i); - for (i = 0; i < NUM_AGE_GROUPS; i++) fprintf(dat, "\tCritRecovP_%i", i); + for (i = 0; i < NUM_AGE_GROUPS; i++) + fprintf(dat, "\tMild_%i", i); + for (i = 0; i < NUM_AGE_GROUPS; i++) + fprintf(dat, "\tILI_%i", i); + for (i = 0; i < NUM_AGE_GROUPS; i++) + fprintf(dat, "\tSARI_%i", i); + for (i = 0; i < NUM_AGE_GROUPS; i++) + fprintf(dat, "\tCritical_%i", i); + for (i = 0; i < NUM_AGE_GROUPS; i++) + fprintf(dat, "\tCritRecov_%i", i); + for (i = 0; i < NUM_AGE_GROUPS; i++) + fprintf(dat, "\tSARIP_%i", i); + for (i = 0; i < NUM_AGE_GROUPS; i++) + fprintf(dat, "\tCriticalP_%i", i); + for (i = 0; i < NUM_AGE_GROUPS; i++) + fprintf(dat, "\tCritRecovP_%i", i); //// incidence - for (i = 0; i < NUM_AGE_GROUPS; i++) fprintf(dat, "\tincI_%i", i); - for (i = 0; i < NUM_AGE_GROUPS; i++) fprintf(dat, "\tincMild_%i", i); - for (i = 0; i < NUM_AGE_GROUPS; i++) fprintf(dat, "\tincILI_%i", i); - for (i = 0; i < NUM_AGE_GROUPS; i++) fprintf(dat, "\tincSARI_%i", i); - for (i = 0; i < NUM_AGE_GROUPS; i++) fprintf(dat, "\tincCritical_%i", i); - for (i = 0; i < NUM_AGE_GROUPS; i++) fprintf(dat, "\tincCritRecov_%i", i); - for (i = 0; i < NUM_AGE_GROUPS; i++) fprintf(dat, "\tincSARIP_%i", i); - for (i = 0; i < NUM_AGE_GROUPS; i++) fprintf(dat, "\tincCriticalP_%i", i); - for (i = 0; i < NUM_AGE_GROUPS; i++) fprintf(dat, "\tincCritRecovP_%i", i); - for (i = 0; i < NUM_AGE_GROUPS; i++) fprintf(dat, "\tincDeath_%i", i); - for (i = 0; i < NUM_AGE_GROUPS; i++) fprintf(dat, "\tincDeath_ILI_%i", i); - for (i = 0; i < NUM_AGE_GROUPS; i++) fprintf(dat, "\tincDeath_SARI_%i", i); - for (i = 0; i < NUM_AGE_GROUPS; i++) fprintf(dat, "\tincDeath__Critical_%i", i); + for (i = 0; i < NUM_AGE_GROUPS; i++) + fprintf(dat, "\tincI_%i", i); + for (i = 0; i < NUM_AGE_GROUPS; i++) + fprintf(dat, "\tincMild_%i", i); + for (i = 0; i < NUM_AGE_GROUPS; i++) + fprintf(dat, "\tincILI_%i", i); + for (i = 0; i < NUM_AGE_GROUPS; i++) + fprintf(dat, "\tincSARI_%i", i); + for (i = 0; i < NUM_AGE_GROUPS; i++) + fprintf(dat, "\tincCritical_%i", i); + for (i = 0; i < NUM_AGE_GROUPS; i++) + fprintf(dat, "\tincCritRecov_%i", i); + for (i = 0; i < NUM_AGE_GROUPS; i++) + fprintf(dat, "\tincSARIP_%i", i); + for (i = 0; i < NUM_AGE_GROUPS; i++) + fprintf(dat, "\tincCriticalP_%i", i); + for (i = 0; i < NUM_AGE_GROUPS; i++) + fprintf(dat, "\tincCritRecovP_%i", i); + for (i = 0; i < NUM_AGE_GROUPS; i++) + fprintf(dat, "\tincDeath_%i", i); + for (i = 0; i < NUM_AGE_GROUPS; i++) + fprintf(dat, "\tincDeath_ILI_%i", i); + for (i = 0; i < NUM_AGE_GROUPS; i++) + fprintf(dat, "\tincDeath_SARI_%i", i); + for (i = 0; i < NUM_AGE_GROUPS; i++) + fprintf(dat, "\tincDeath__Critical_%i", i); //// cumulative incidence - for (i = 0; i < NUM_AGE_GROUPS; i++) fprintf(dat, "\tcumMild_%i", i); - for (i = 0; i < NUM_AGE_GROUPS; i++) fprintf(dat, "\tcumILI_%i", i); - for (i = 0; i < NUM_AGE_GROUPS; i++) fprintf(dat, "\tcumSARI_%i", i); - for (i = 0; i < NUM_AGE_GROUPS; i++) fprintf(dat, "\tcumCritical_%i", i); - for (i = 0; i < NUM_AGE_GROUPS; i++) fprintf(dat, "\tcumCritRecov_%i", i); - for (i = 0; i < NUM_AGE_GROUPS; i++) fprintf(dat, "\tcumDeaths_%i", i); - for (i = 0; i < NUM_AGE_GROUPS; i++) fprintf(dat, "\tcumDeaths_ILI_%i", i); - for (i = 0; i < NUM_AGE_GROUPS; i++) fprintf(dat, "\tcumDeaths_SARI_%i", i); - for (i = 0; i < NUM_AGE_GROUPS; i++) fprintf(dat, "\tcumDeaths_Critical_%i", i); + for (i = 0; i < NUM_AGE_GROUPS; i++) + fprintf(dat, "\tcumMild_%i", i); + for (i = 0; i < NUM_AGE_GROUPS; i++) + fprintf(dat, "\tcumILI_%i", i); + for (i = 0; i < NUM_AGE_GROUPS; i++) + fprintf(dat, "\tcumSARI_%i", i); + for (i = 0; i < NUM_AGE_GROUPS; i++) + fprintf(dat, "\tcumCritical_%i", i); + for (i = 0; i < NUM_AGE_GROUPS; i++) + fprintf(dat, "\tcumCritRecov_%i", i); + for (i = 0; i < NUM_AGE_GROUPS; i++) + fprintf(dat, "\tcumDeaths_%i", i); + for (i = 0; i < NUM_AGE_GROUPS; i++) + fprintf(dat, "\tcumDeaths_ILI_%i", i); + for (i = 0; i < NUM_AGE_GROUPS; i++) + fprintf(dat, "\tcumDeaths_SARI_%i", i); + for (i = 0; i < NUM_AGE_GROUPS; i++) + fprintf(dat, "\tcumDeaths_Critical_%i", i); fprintf(dat, "\n"); @@ -4003,12 +5860,17 @@ void SaveSummaryResults(void) //// calculates and saves summary results (called { if (i > 0) { - SARI_a[j] = (TSMean[i].SARI_age[j] - TSMean[i - 1].SARI_age[j]) * sc2a + SARI_a[j] * sc1a; - Critical_a[j] = (TSMean[i].Critical_age[j] - TSMean[i - 1].Critical_age[j]) * sc3a + Critical_a[j] * sc1a; - CritRecov_a[j] = (TSMean[i].CritRecov_age[j] - TSMean[i - 1].CritRecov_age[j]) * sc4a + CritRecov_a[j] * sc1a; + SARI_a[j] = + (TSMean[i].SARI_age[j] - TSMean[i - 1].SARI_age[j]) * sc2a + SARI_a[j] * sc1a; + Critical_a[j] = (TSMean[i].Critical_age[j] - TSMean[i - 1].Critical_age[j]) * sc3a + + Critical_a[j] * sc1a; + CritRecov_a[j] = (TSMean[i].CritRecov_age[j] - TSMean[i - 1].CritRecov_age[j]) * sc4a + + CritRecov_a[j] * sc1a; incSARI_a[j] = TSMean[i].incSARI_age[j] * (1.0 - sc2a) + incSARI_a[j] * sc1a; - incCritical_a[j] = TSMean[i].incCritical_age[j] * (1.0 - sc3a) + incCritical_a[j] * sc1a; - incCritRecov_a[j] = TSMean[i].incCritRecov_age[j] * (1.0 - sc4a) + incCritRecov_a[j] * sc1a; + incCritical_a[j] = + TSMean[i].incCritical_age[j] * (1.0 - sc3a) + incCritical_a[j] * sc1a; + incCritRecov_a[j] = + TSMean[i].incCritRecov_age[j] * (1.0 - sc4a) + incCritRecov_a[j] * sc1a; } else { @@ -4019,102 +5881,180 @@ void SaveSummaryResults(void) //// calculates and saves summary results (called } fprintf(dat, "%.10f", c * TSMean[i].t); //// prevalance - for (j = 0; j < NUM_AGE_GROUPS; j++) fprintf(dat, "\t%.10f", c * TSMean[i].Mild_age[j]); - for (j = 0; j < NUM_AGE_GROUPS; j++) fprintf(dat, "\t%.10f", c * TSMean[i].ILI_age[j]); - for (j = 0; j < NUM_AGE_GROUPS; j++) fprintf(dat, "\t%.10f", c * TSMean[i].SARI_age[j]); - for (j = 0; j < NUM_AGE_GROUPS; j++) fprintf(dat, "\t%.10f", c * TSMean[i].Critical_age[j]); - for (j = 0; j < NUM_AGE_GROUPS; j++) fprintf(dat, "\t%.10f", c * TSMean[i].CritRecov_age[j]); - for (j = 0; j < NUM_AGE_GROUPS; j++) fprintf(dat, "\t%.10f", c * (TSMean[i].SARI_age[j] - SARI_a[j])); - for (j = 0; j < NUM_AGE_GROUPS; j++) fprintf(dat, "\t%.10f", c * (TSMean[i].Critical_age[j] - Critical_a[j])); - for (j = 0; j < NUM_AGE_GROUPS; j++) fprintf(dat, "\t%.10f", c * (TSMean[i].CritRecov_age[j] - CritRecov_a[j])); + for (j = 0; j < NUM_AGE_GROUPS; j++) + fprintf(dat, "\t%.10f", c * TSMean[i].Mild_age[j]); + for (j = 0; j < NUM_AGE_GROUPS; j++) + fprintf(dat, "\t%.10f", c * TSMean[i].ILI_age[j]); + for (j = 0; j < NUM_AGE_GROUPS; j++) + fprintf(dat, "\t%.10f", c * TSMean[i].SARI_age[j]); + for (j = 0; j < NUM_AGE_GROUPS; j++) + fprintf(dat, "\t%.10f", c * TSMean[i].Critical_age[j]); + for (j = 0; j < NUM_AGE_GROUPS; j++) + fprintf(dat, "\t%.10f", c * TSMean[i].CritRecov_age[j]); + for (j = 0; j < NUM_AGE_GROUPS; j++) + fprintf(dat, "\t%.10f", c * (TSMean[i].SARI_age[j] - SARI_a[j])); + for (j = 0; j < NUM_AGE_GROUPS; j++) + fprintf(dat, "\t%.10f", c * (TSMean[i].Critical_age[j] - Critical_a[j])); + for (j = 0; j < NUM_AGE_GROUPS; j++) + fprintf(dat, "\t%.10f", c * (TSMean[i].CritRecov_age[j] - CritRecov_a[j])); //// incidence - for (j = 0; j < NUM_AGE_GROUPS; j++) fprintf(dat, "\t%.10f", c * TSMean[i].incIa[j]); - for (j = 0; j < NUM_AGE_GROUPS; j++) fprintf(dat, "\t%.10f", c * TSMean[i].incMild_age[j]); - for (j = 0; j < NUM_AGE_GROUPS; j++) fprintf(dat, "\t%.10f", c * TSMean[i].incILI_age[j]); - for (j = 0; j < NUM_AGE_GROUPS; j++) fprintf(dat, "\t%.10f", c * TSMean[i].incSARI_age[j]); - for (j = 0; j < NUM_AGE_GROUPS; j++) fprintf(dat, "\t%.10f", c * TSMean[i].incCritical_age[j]); - for (j = 0; j < NUM_AGE_GROUPS; j++) fprintf(dat, "\t%.10f", c * TSMean[i].incCritRecov_age[j]); - for (j = 0; j < NUM_AGE_GROUPS; j++) fprintf(dat, "\t%.10f", c * incSARI_a[j]); - for (j = 0; j < NUM_AGE_GROUPS; j++) fprintf(dat, "\t%.10f", c * incCritical_a[j]); - for (j = 0; j < NUM_AGE_GROUPS; j++) fprintf(dat, "\t%.10f", c * incCritRecov_a[j]); - for (j = 0; j < NUM_AGE_GROUPS; j++) fprintf(dat, "\t%.10f", c * TSMean[i].incDa[j]); - for (j = 0; j < NUM_AGE_GROUPS; j++) fprintf(dat, "\t%.10f", c * TSMean[i].incDeath_ILI_age[j]); - for (j = 0; j < NUM_AGE_GROUPS; j++) fprintf(dat, "\t%.10f", c * TSMean[i].incDeath_SARI_age[j]); - for (j = 0; j < NUM_AGE_GROUPS; j++) fprintf(dat, "\t%.10f", c * TSMean[i].incDeath_Critical_age[j]); + for (j = 0; j < NUM_AGE_GROUPS; j++) + fprintf(dat, "\t%.10f", c * TSMean[i].incIa[j]); + for (j = 0; j < NUM_AGE_GROUPS; j++) + fprintf(dat, "\t%.10f", c * TSMean[i].incMild_age[j]); + for (j = 0; j < NUM_AGE_GROUPS; j++) + fprintf(dat, "\t%.10f", c * TSMean[i].incILI_age[j]); + for (j = 0; j < NUM_AGE_GROUPS; j++) + fprintf(dat, "\t%.10f", c * TSMean[i].incSARI_age[j]); + for (j = 0; j < NUM_AGE_GROUPS; j++) + fprintf(dat, "\t%.10f", c * TSMean[i].incCritical_age[j]); + for (j = 0; j < NUM_AGE_GROUPS; j++) + fprintf(dat, "\t%.10f", c * TSMean[i].incCritRecov_age[j]); + for (j = 0; j < NUM_AGE_GROUPS; j++) + fprintf(dat, "\t%.10f", c * incSARI_a[j]); + for (j = 0; j < NUM_AGE_GROUPS; j++) + fprintf(dat, "\t%.10f", c * incCritical_a[j]); + for (j = 0; j < NUM_AGE_GROUPS; j++) + fprintf(dat, "\t%.10f", c * incCritRecov_a[j]); + for (j = 0; j < NUM_AGE_GROUPS; j++) + fprintf(dat, "\t%.10f", c * TSMean[i].incDa[j]); + for (j = 0; j < NUM_AGE_GROUPS; j++) + fprintf(dat, "\t%.10f", c * TSMean[i].incDeath_ILI_age[j]); + for (j = 0; j < NUM_AGE_GROUPS; j++) + fprintf(dat, "\t%.10f", c * TSMean[i].incDeath_SARI_age[j]); + for (j = 0; j < NUM_AGE_GROUPS; j++) + fprintf(dat, "\t%.10f", c * TSMean[i].incDeath_Critical_age[j]); //// cumulative incidence - for (j = 0; j < NUM_AGE_GROUPS; j++) fprintf(dat, "\t%.10f", c * TSMean[i].cumMild_age[j]); - for (j = 0; j < NUM_AGE_GROUPS; j++) fprintf(dat, "\t%.10f", c * TSMean[i].cumILI_age[j]); - for (j = 0; j < NUM_AGE_GROUPS; j++) fprintf(dat, "\t%.10f", c * TSMean[i].cumSARI_age[j]); - for (j = 0; j < NUM_AGE_GROUPS; j++) fprintf(dat, "\t%.10f", c * TSMean[i].cumCritical_age[j]); - for (j = 0; j < NUM_AGE_GROUPS; j++) fprintf(dat, "\t%.10f", c * TSMean[i].cumCritRecov_age[j]); - for (j = 0; j < NUM_AGE_GROUPS; j++) fprintf(dat, "\t%.10f", c * (TSMean[i].cumDeath_ILI_age[j] + TSMean[i].cumDeath_SARI_age[j] + TSMean[i].cumDeath_Critical_age[j])); - for (j = 0; j < NUM_AGE_GROUPS; j++) fprintf(dat, "\t%.10f", c * TSMean[i].cumDeath_ILI_age[j]); - for (j = 0; j < NUM_AGE_GROUPS; j++) fprintf(dat, "\t%.10f", c * TSMean[i].cumDeath_SARI_age[j]); - for (j = 0; j < NUM_AGE_GROUPS; j++) fprintf(dat, "\t%.10f", c * TSMean[i].cumDeath_Critical_age[j]); + for (j = 0; j < NUM_AGE_GROUPS; j++) + fprintf(dat, "\t%.10f", c * TSMean[i].cumMild_age[j]); + for (j = 0; j < NUM_AGE_GROUPS; j++) + fprintf(dat, "\t%.10f", c * TSMean[i].cumILI_age[j]); + for (j = 0; j < NUM_AGE_GROUPS; j++) + fprintf(dat, "\t%.10f", c * TSMean[i].cumSARI_age[j]); + for (j = 0; j < NUM_AGE_GROUPS; j++) + fprintf(dat, "\t%.10f", c * TSMean[i].cumCritical_age[j]); + for (j = 0; j < NUM_AGE_GROUPS; j++) + fprintf(dat, "\t%.10f", c * TSMean[i].cumCritRecov_age[j]); + for (j = 0; j < NUM_AGE_GROUPS; j++) + fprintf(dat, "\t%.10f", + c * (TSMean[i].cumDeath_ILI_age[j] + TSMean[i].cumDeath_SARI_age[j] + + TSMean[i].cumDeath_Critical_age[j])); + for (j = 0; j < NUM_AGE_GROUPS; j++) + fprintf(dat, "\t%.10f", c * TSMean[i].cumDeath_ILI_age[j]); + for (j = 0; j < NUM_AGE_GROUPS; j++) + fprintf(dat, "\t%.10f", c * TSMean[i].cumDeath_SARI_age[j]); + for (j = 0; j < NUM_AGE_GROUPS; j++) + fprintf(dat, "\t%.10f", c * TSMean[i].cumDeath_Critical_age[j]); fprintf(dat, "\n"); } fclose(dat); - free(SARI_a); free(Critical_a); free(CritRecov_a); - free(incSARI_a); free(incCritical_a); free(incCritRecov_a); + free(SARI_a); + free(Critical_a); + free(CritRecov_a); + free(incSARI_a); + free(incCritical_a); + free(incCritRecov_a); } if ((P.DoAdUnits) && (P.OutputSeverityAdminUnit)) { - double* SARI_a, * Critical_a, * CritRecov_a, * incSARI_a, * incCritical_a, * incCritRecov_a, sc1a, sc2a,sc3a,sc4a; //this stuff corrects bed prevalence for exponentially distributed time to test results in hospital - - if (!(SARI_a = (double*)malloc(MAX_ADUNITS * sizeof(double)))) ERR_CRITICAL("Unable to allocate temp storage\n"); - if (!(Critical_a = (double*)malloc(MAX_ADUNITS * sizeof(double)))) ERR_CRITICAL("Unable to allocate temp storage\n"); - if (!(CritRecov_a = (double*)malloc(MAX_ADUNITS * sizeof(double)))) ERR_CRITICAL("Unable to allocate temp storage\n"); - if (!(incSARI_a = (double*)malloc(MAX_ADUNITS * sizeof(double)))) ERR_CRITICAL("Unable to allocate temp storage\n"); - if (!(incCritical_a = (double*)malloc(MAX_ADUNITS * sizeof(double)))) ERR_CRITICAL("Unable to allocate temp storage\n"); - if (!(incCritRecov_a = (double*)malloc(MAX_ADUNITS * sizeof(double)))) ERR_CRITICAL("Unable to allocate temp storage\n"); + double *SARI_a, *Critical_a, *CritRecov_a, *incSARI_a, *incCritical_a, *incCritRecov_a, sc1a, + sc2a, sc3a, sc4a; // this stuff corrects bed prevalence for exponentially distributed time + // to test results in hospital + + if (!(SARI_a = (double *)malloc(MAX_ADUNITS * sizeof(double)))) + ERR_CRITICAL("Unable to allocate temp storage\n"); + if (!(Critical_a = (double *)malloc(MAX_ADUNITS * sizeof(double)))) + ERR_CRITICAL("Unable to allocate temp storage\n"); + if (!(CritRecov_a = (double *)malloc(MAX_ADUNITS * sizeof(double)))) + ERR_CRITICAL("Unable to allocate temp storage\n"); + if (!(incSARI_a = (double *)malloc(MAX_ADUNITS * sizeof(double)))) + ERR_CRITICAL("Unable to allocate temp storage\n"); + if (!(incCritical_a = (double *)malloc(MAX_ADUNITS * sizeof(double)))) + ERR_CRITICAL("Unable to allocate temp storage\n"); + if (!(incCritRecov_a = (double *)malloc(MAX_ADUNITS * sizeof(double)))) + ERR_CRITICAL("Unable to allocate temp storage\n"); sc1a = (P.Mean_TimeToTest > 0) ? exp(-1.0 / P.Mean_TimeToTest) : 0.0; sc2a = (P.Mean_TimeToTest > 0) ? exp(-P.Mean_TimeToTestOffset / P.Mean_TimeToTest) : 0.0; - sc3a = (P.Mean_TimeToTest > 0) ? exp(-P.Mean_TimeToTestCriticalOffset / P.Mean_TimeToTest) : 0.0; - sc4a = (P.Mean_TimeToTest > 0) ? exp(-P.Mean_TimeToTestCritRecovOffset / P.Mean_TimeToTest) : 0.0; - for (i = 0; i < P.NumAdunits; i++) incSARI_a[i] = incCritical_a[i] = incCritRecov_a[i] = 0; + sc3a = + (P.Mean_TimeToTest > 0) ? exp(-P.Mean_TimeToTestCriticalOffset / P.Mean_TimeToTest) : 0.0; + sc4a = (P.Mean_TimeToTest > 0) ? exp(-P.Mean_TimeToTestCritRecovOffset / P.Mean_TimeToTest) + : 0.0; + for (i = 0; i < P.NumAdunits; i++) + incSARI_a[i] = incCritical_a[i] = incCritRecov_a[i] = 0; //// output severity results by admin unit sprintf(outname, "%s.severity.adunit.xls", OutFile); - if (!(dat = fopen(outname, "wb"))) ERR_CRITICAL("Unable to open output file\n"); + if (!(dat = fopen(outname, "wb"))) + ERR_CRITICAL("Unable to open output file\n"); fprintf(dat, "t"); /////// ****** /////// ****** /////// ****** COLNAMES //// prevalance - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tMild_%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tILI_%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tSARI_%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tCritical_%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tCritRecov_%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tSARIP_%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tCriticalP_%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tCritRecovP_%s" , AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tMild_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tILI_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tSARI_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tCritical_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tCritRecov_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tSARIP_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tCriticalP_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tCritRecovP_%s", AdUnits[i].ad_name); //// incidence - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tincI_%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tincMild_%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tincILI_%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tincSARI_%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tincCritical_%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tincCritRecov_%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tincSARIP_%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tincCriticalP_%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tincCritRecovP_%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tincDeath_%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tincDeath_ILI_%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tincDeath_SARI_%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tincDeath__Critical_%s" , AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tincI_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tincMild_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tincILI_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tincSARI_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tincCritical_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tincCritRecov_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tincSARIP_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tincCriticalP_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tincCritRecovP_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tincDeath_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tincDeath_ILI_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tincDeath_SARI_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tincDeath__Critical_%s", AdUnits[i].ad_name); //// cumulative incidence - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tcumMild_%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tcumILI_%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tcumSARI_%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tcumCritical_%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tcumCritRecov_%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tcumDeaths_%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tcumDeaths_ILI_%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tcumDeaths_SARI_%s" , AdUnits[i].ad_name); - for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tcumDeaths_Critical_%s" , AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tcumMild_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tcumILI_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tcumSARI_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tcumCritical_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tcumCritRecov_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tcumDeaths_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tcumDeaths_ILI_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tcumDeaths_SARI_%s", AdUnits[i].ad_name); + for (i = 0; i < P.NumAdunits; i++) + fprintf(dat, "\tcumDeaths_Critical_%s", AdUnits[i].ad_name); fprintf(dat, "\n"); @@ -4125,12 +6065,19 @@ void SaveSummaryResults(void) //// calculates and saves summary results (called { if (i > 0) { - SARI_a[j] = (TSMean[i].SARI_adunit[j] - TSMean[i - 1].SARI_adunit[j]) * sc2a + SARI_a[j] * sc1a; - Critical_a[j] = (TSMean[i].Critical_adunit[j] - TSMean[i - 1].Critical_adunit[j]) * sc3a + Critical_a[j] * sc1a; - CritRecov_a[j] = (TSMean[i].CritRecov_adunit[j] - TSMean[i - 1].CritRecov_adunit[j]) * sc4a + CritRecov_a[j] * sc1a; + SARI_a[j] = + (TSMean[i].SARI_adunit[j] - TSMean[i - 1].SARI_adunit[j]) * sc2a + SARI_a[j] * sc1a; + Critical_a[j] = + (TSMean[i].Critical_adunit[j] - TSMean[i - 1].Critical_adunit[j]) * sc3a + + Critical_a[j] * sc1a; + CritRecov_a[j] = + (TSMean[i].CritRecov_adunit[j] - TSMean[i - 1].CritRecov_adunit[j]) * sc4a + + CritRecov_a[j] * sc1a; incSARI_a[j] = TSMean[i].incSARI_adunit[j] * (1.0 - sc2a) + incSARI_a[j] * sc1a; - incCritical_a[j] = TSMean[i].incCritical_adunit[j] * (1.0 - sc3a) + incCritical_a[j] * sc1a; - incCritRecov_a[j] = TSMean[i].incCritRecov_adunit[j] * (1.0 - sc4a) + incCritRecov_a[j] * sc1a; + incCritical_a[j] = + TSMean[i].incCritical_adunit[j] * (1.0 - sc3a) + incCritical_a[j] * sc1a; + incCritRecov_a[j] = + TSMean[i].incCritRecov_adunit[j] * (1.0 - sc4a) + incCritRecov_a[j] * sc1a; } else { @@ -4139,48 +6086,82 @@ void SaveSummaryResults(void) //// calculates and saves summary results (called CritRecov_a[j] = TSMean[i].CritRecov_adunit[j] * sc4a; } } - fprintf(dat, "%.10f", c*TSMean[i].t); + fprintf(dat, "%.10f", c * TSMean[i].t); //// prevalance - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", c * TSMean[i].Mild_adunit[j]); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", c * TSMean[i].ILI_adunit[j]); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", c * TSMean[i].SARI_adunit[j]); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", c * TSMean[i].Critical_adunit[j]); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", c * TSMean[i].CritRecov_adunit[j]); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", c * (TSMean[i].SARI_adunit[j] - SARI_a[j])); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", c * (TSMean[i].Critical_adunit[j] - Critical_a[j])); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", c * (TSMean[i].CritRecov_adunit[j] - CritRecov_a[j])); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", c * TSMean[i].Mild_adunit[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", c * TSMean[i].ILI_adunit[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", c * TSMean[i].SARI_adunit[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", c * TSMean[i].Critical_adunit[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", c * TSMean[i].CritRecov_adunit[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", c * (TSMean[i].SARI_adunit[j] - SARI_a[j])); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", c * (TSMean[i].Critical_adunit[j] - Critical_a[j])); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", c * (TSMean[i].CritRecov_adunit[j] - CritRecov_a[j])); //// incidence - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", c * TSMean[i].incI_adunit[j]); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", c * TSMean[i].incMild_adunit[j]); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", c * TSMean[i].incILI_adunit[j]); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", c * TSMean[i].incSARI_adunit[j]); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", c * TSMean[i].incCritical_adunit[j]); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", c * TSMean[i].incCritRecov_adunit[j]); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", c * incSARI_a[j]); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", c * incCritical_a[j]); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", c * incCritRecov_a[j]); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", c * TSMean[i].incD_adunit[j]); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", c * TSMean[i].incDeath_ILI_adunit[j]); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", c * TSMean[i].incDeath_SARI_adunit[j]); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", c * TSMean[i].incDeath_Critical_adunit[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", c * TSMean[i].incI_adunit[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", c * TSMean[i].incMild_adunit[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", c * TSMean[i].incILI_adunit[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", c * TSMean[i].incSARI_adunit[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", c * TSMean[i].incCritical_adunit[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", c * TSMean[i].incCritRecov_adunit[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", c * incSARI_a[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", c * incCritical_a[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", c * incCritRecov_a[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", c * TSMean[i].incD_adunit[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", c * TSMean[i].incDeath_ILI_adunit[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", c * TSMean[i].incDeath_SARI_adunit[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", c * TSMean[i].incDeath_Critical_adunit[j]); //// cumulative incidence - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", c * TSMean[i].cumMild_adunit[j]); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", c * TSMean[i].cumILI_adunit[j]); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", c * TSMean[i].cumSARI_adunit[j]); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", c * TSMean[i].cumCritical_adunit[j]); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", c * TSMean[i].cumCritRecov_adunit[j]); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", c * TSMean[i].cumD_adunit[j]); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", c * TSMean[i].cumDeath_ILI_adunit[j]); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", c * TSMean[i].cumDeath_SARI_adunit[j]); - for (j = 0; j < P.NumAdunits; j++) fprintf(dat, "\t%.10f", c * TSMean[i].cumDeath_Critical_adunit[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", c * TSMean[i].cumMild_adunit[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", c * TSMean[i].cumILI_adunit[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", c * TSMean[i].cumSARI_adunit[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", c * TSMean[i].cumCritical_adunit[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", c * TSMean[i].cumCritRecov_adunit[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", c * TSMean[i].cumD_adunit[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", c * TSMean[i].cumDeath_ILI_adunit[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", c * TSMean[i].cumDeath_SARI_adunit[j]); + for (j = 0; j < P.NumAdunits; j++) + fprintf(dat, "\t%.10f", c * TSMean[i].cumDeath_Critical_adunit[j]); fprintf(dat, "\n"); } fclose(dat); - free(SARI_a); free(Critical_a); free(CritRecov_a); - free(incSARI_a); free(incCritical_a); free(incCritRecov_a); + free(SARI_a); + free(Critical_a); + free(CritRecov_a); + free(incSARI_a); + free(incCritical_a); + free(incCritRecov_a); } } @@ -4188,19 +6169,21 @@ void SaveSummaryResults(void) //// calculates and saves summary results (called { //// output infections by age and admin unit sprintf(outname, "%s.age.adunit.xls", OutFile); - if (!(dat = fopen(outname, "wb"))) ERR_CRITICAL("Unable to open output file\n"); + if (!(dat = fopen(outname, "wb"))) + ERR_CRITICAL("Unable to open output file\n"); fprintf(dat, "t"); // colnames for (int AdUnit = 0; AdUnit < P.NumAdunits; AdUnit++) for (int AgeGroup = 0; AgeGroup < NUM_AGE_GROUPS; AgeGroup++) - fprintf(dat, "\tincInf_AG_%i_%s", AgeGroup, AdUnits[AdUnit].ad_name); // incidence + fprintf(dat, "\tincInf_AG_%i_%s", AgeGroup, AdUnits[AdUnit].ad_name); // incidence for (int AdUnit = 0; AdUnit < P.NumAdunits; AdUnit++) for (int AgeGroup = 0; AgeGroup < NUM_AGE_GROUPS; AgeGroup++) - fprintf(dat, "\tprevInf_AG_%i_%s", AgeGroup, AdUnits[AdUnit].ad_name); // prevalence + fprintf(dat, "\tprevInf_AG_%i_%s", AgeGroup, AdUnits[AdUnit].ad_name); // prevalence for (int AdUnit = 0; AdUnit < P.NumAdunits; AdUnit++) for (int AgeGroup = 0; AgeGroup < NUM_AGE_GROUPS; AgeGroup++) - fprintf(dat, "\tcumInf_AG_%i_%s", AgeGroup, AdUnits[AdUnit].ad_name); // cumulative incidence + fprintf(dat, "\tcumInf_AG_%i_%s", AgeGroup, + AdUnits[AdUnit].ad_name); // cumulative incidence fprintf(dat, "\n"); // Populate @@ -4209,17 +6192,19 @@ void SaveSummaryResults(void) //// calculates and saves summary results (called fprintf(dat, "%.10f", c * TSMean[Time].t); for (int AdUnit = 0; AdUnit < P.NumAdunits; AdUnit++) for (int AgeGroup = 0; AgeGroup < NUM_AGE_GROUPS; AgeGroup++) - fprintf(dat, "\t%.10f", c * TSMean[Time].incInf_age_adunit[AgeGroup][AdUnit]); // incidence + fprintf(dat, "\t%.10f", + c * TSMean[Time].incInf_age_adunit[AgeGroup][AdUnit]); // incidence for (int AdUnit = 0; AdUnit < P.NumAdunits; AdUnit++) for (int AgeGroup = 0; AgeGroup < NUM_AGE_GROUPS; AgeGroup++) - fprintf(dat, "\t%.10f", c * TSMean[Time].prevInf_age_adunit[AgeGroup][AdUnit]); // prevalence + fprintf(dat, "\t%.10f", + c * TSMean[Time].prevInf_age_adunit[AgeGroup][AdUnit]); // prevalence for (int AdUnit = 0; AdUnit < P.NumAdunits; AdUnit++) for (int AgeGroup = 0; AgeGroup < NUM_AGE_GROUPS; AgeGroup++) - fprintf(dat, "\t%.10f", c * TSMean[Time].cumInf_age_adunit[AgeGroup][AdUnit]); // cumulative incidence + fprintf(dat, "\t%.10f", + c * TSMean[Time].cumInf_age_adunit[AgeGroup][AdUnit]); // cumulative incidence fprintf(dat, "\n"); } } - } void SaveRandomSeeds(void) @@ -4232,11 +6217,12 @@ void SaveRandomSeeds(void) * * Author: ggilani, 09/03/17 */ - FILE* dat; + FILE *dat; char outname[1024]; sprintf(outname, "%s.seeds.xls", OutFile); - if (!(dat = fopen(outname, "wb"))) ERR_CRITICAL("Unable to open output file\n"); + if (!(dat = fopen(outname, "wb"))) + ERR_CRITICAL("Unable to open output file\n"); fprintf(dat, "%i\t%i\n", P.nextRunSeed1, P.nextRunSeed2); fclose(dat); } @@ -4252,36 +6238,46 @@ void SaveEvents(void) * Author: ggilani, 15/10/2014 */ int i; - FILE* dat; + FILE *dat; char outname[1024]; sprintf(outname, "%s.infevents.xls", OutFile); - if (!(dat = fopen(outname, "wb"))) ERR_CRITICAL("Unable to open output file\n"); - fprintf(dat, "type,t,thread,ind_infectee,cell_infectee,listpos_infectee,adunit_infectee,x_infectee,y_infectee,t_infector,ind_infector,cell_infector\n"); + if (!(dat = fopen(outname, "wb"))) + ERR_CRITICAL("Unable to open output file\n"); + fprintf(dat, "type,t,thread,ind_infectee,cell_infectee,listpos_infectee,adunit_infectee,x_" + "infectee,y_infectee,t_infector,ind_infector,cell_infector\n"); for (i = 0; i < nEvents; i++) { fprintf(dat, "%i\t%.10f\t%i\t%i\t%i\t%i\t%i\t%.10f\t%.10f\t%.10f\t%i\t%i\n", - InfEventLog[i].type, InfEventLog[i].t, InfEventLog[i].thread, InfEventLog[i].infectee_ind, InfEventLog[i].infectee_cell, InfEventLog[i].listpos, InfEventLog[i].infectee_adunit, InfEventLog[i].infectee_x, InfEventLog[i].infectee_y, InfEventLog[i].t_infector, InfEventLog[i].infector_ind, InfEventLog[i].infector_cell); + InfEventLog[i].type, InfEventLog[i].t, InfEventLog[i].thread, + InfEventLog[i].infectee_ind, InfEventLog[i].infectee_cell, InfEventLog[i].listpos, + InfEventLog[i].infectee_adunit, InfEventLog[i].infectee_x, InfEventLog[i].infectee_y, + InfEventLog[i].t_infector, InfEventLog[i].infector_ind, InfEventLog[i].infector_cell); } fclose(dat); } void LoadSnapshot(void) { - FILE* dat; - int i, j, * CellMemberArray, * CellSuscMemberArray; + FILE *dat; + int i, j, *CellMemberArray, *CellSuscMemberArray; int32_t l; long long CM_offset, CSM_offset; double t; - int** Array_InvCDF; - float* Array_tot_prob, ** Array_cum_trans, ** Array_max_trans; + int **Array_InvCDF; + float *Array_tot_prob, **Array_cum_trans, **Array_max_trans; - if (!(dat = fopen(SnapshotLoadFile, "rb"))) ERR_CRITICAL("Unable to open snapshot file\n"); + if (!(dat = fopen(SnapshotLoadFile, "rb"))) + ERR_CRITICAL("Unable to open snapshot file\n"); fprintf(stderr, "Loading snapshot."); - if (!(Array_InvCDF = (int**)malloc(P.NCP * sizeof(int*)))) ERR_CRITICAL("Unable to allocate temp cell storage\n"); - if (!(Array_max_trans = (float**)malloc(P.NCP * sizeof(float*)))) ERR_CRITICAL("Unable to temp allocate cell storage\n"); - if (!(Array_cum_trans = (float**)malloc(P.NCP * sizeof(float*)))) ERR_CRITICAL("Unable to temp allocate cell storage\n"); - if (!(Array_tot_prob = (float*)malloc(P.NCP * sizeof(float)))) ERR_CRITICAL("Unable to temp allocate cell storage\n"); + if (!(Array_InvCDF = (int **)malloc(P.NCP * sizeof(int *)))) + ERR_CRITICAL("Unable to allocate temp cell storage\n"); + if (!(Array_max_trans = (float **)malloc(P.NCP * sizeof(float *)))) + ERR_CRITICAL("Unable to temp allocate cell storage\n"); + if (!(Array_cum_trans = (float **)malloc(P.NCP * sizeof(float *)))) + ERR_CRITICAL("Unable to temp allocate cell storage\n"); + if (!(Array_tot_prob = (float *)malloc(P.NCP * sizeof(float)))) + ERR_CRITICAL("Unable to temp allocate cell storage\n"); for (i = 0; i < P.NCP; i++) { Array_InvCDF[i] = Cells[i].InvCDF; @@ -4290,36 +6286,54 @@ void LoadSnapshot(void) Array_tot_prob[i] = Cells[i].tot_prob; } - fread_big((void*)& i, sizeof(int), 1, dat); if (i != P.PopSize) ERR_CRITICAL_FMT("Incorrect N (%i %i) in snapshot file.\n", P.PopSize, i); - fread_big((void*)& i, sizeof(int), 1, dat); if (i != P.NH) ERR_CRITICAL("Incorrect NH in snapshot file.\n"); - fread_big((void*)&i, sizeof(int), 1, dat); if (i != P.NC) ERR_CRITICAL_FMT("## %i neq %i\nIncorrect NC in snapshot file.", i, P.NC); - fread_big((void*)& i, sizeof(int), 1, dat); if (i != P.NCP) ERR_CRITICAL("Incorrect NCP in snapshot file.\n"); - fread_big((void*)& i, sizeof(int), 1, dat); if (i != P.ncw) ERR_CRITICAL("Incorrect ncw in snapshot file.\n"); - fread_big((void*)& i, sizeof(int), 1, dat); if (i != P.nch) ERR_CRITICAL("Incorrect nch in snapshot file.\n"); - fread_big((void*)& l, sizeof(int32_t), 1, dat); if (l != P.setupSeed1) ERR_CRITICAL("Incorrect setupSeed1 in snapshot file.\n"); - fread_big((void*)& l, sizeof(int32_t), 1, dat); if (l != P.setupSeed2) ERR_CRITICAL("Incorrect setupSeed2 in snapshot file.\n"); - fread_big((void*)& t, sizeof(double), 1, dat); if (t != P.TimeStep) ERR_CRITICAL("Incorrect TimeStep in snapshot file.\n"); - fread_big((void*) & (P.SnapshotLoadTime), sizeof(double), 1, dat); + fread_big((void *)&i, sizeof(int), 1, dat); + if (i != P.PopSize) + ERR_CRITICAL_FMT("Incorrect N (%i %i) in snapshot file.\n", P.PopSize, i); + fread_big((void *)&i, sizeof(int), 1, dat); + if (i != P.NH) + ERR_CRITICAL("Incorrect NH in snapshot file.\n"); + fread_big((void *)&i, sizeof(int), 1, dat); + if (i != P.NC) + ERR_CRITICAL_FMT("## %i neq %i\nIncorrect NC in snapshot file.", i, P.NC); + fread_big((void *)&i, sizeof(int), 1, dat); + if (i != P.NCP) + ERR_CRITICAL("Incorrect NCP in snapshot file.\n"); + fread_big((void *)&i, sizeof(int), 1, dat); + if (i != P.ncw) + ERR_CRITICAL("Incorrect ncw in snapshot file.\n"); + fread_big((void *)&i, sizeof(int), 1, dat); + if (i != P.nch) + ERR_CRITICAL("Incorrect nch in snapshot file.\n"); + fread_big((void *)&l, sizeof(int32_t), 1, dat); + if (l != P.setupSeed1) + ERR_CRITICAL("Incorrect setupSeed1 in snapshot file.\n"); + fread_big((void *)&l, sizeof(int32_t), 1, dat); + if (l != P.setupSeed2) + ERR_CRITICAL("Incorrect setupSeed2 in snapshot file.\n"); + fread_big((void *)&t, sizeof(double), 1, dat); + if (t != P.TimeStep) + ERR_CRITICAL("Incorrect TimeStep in snapshot file.\n"); + fread_big((void *)&(P.SnapshotLoadTime), sizeof(double), 1, dat); P.NumSamples = 1 + (int)ceil((P.SampleTime - P.SnapshotLoadTime) / P.SampleStep); fprintf(stderr, "."); - fread_big((void*)& CellMemberArray, sizeof(int*), 1, dat); + fread_big((void *)&CellMemberArray, sizeof(int *), 1, dat); fprintf(stderr, "."); - fread_big((void*)& CellSuscMemberArray, sizeof(int*), 1, dat); + fread_big((void *)&CellSuscMemberArray, sizeof(int *), 1, dat); fprintf(stderr, "."); CM_offset = State.CellMemberArray - CellMemberArray; CSM_offset = State.CellSuscMemberArray - CellSuscMemberArray; - fread_big((void*)Hosts, sizeof(Person), (size_t)P.PopSize, dat); + fread_big((void *)Hosts, sizeof(Person), (size_t)P.PopSize, dat); fprintf(stderr, "."); - fread_big((void*)Households, sizeof(Household), (size_t)P.NH, dat); + fread_big((void *)Households, sizeof(Household), (size_t)P.NH, dat); fprintf(stderr, "."); - fread_big((void*)Cells, sizeof(Cell), (size_t)P.NC, dat); + fread_big((void *)Cells, sizeof(Cell), (size_t)P.NC, dat); fprintf(stderr, "."); - fread_big((void*)Mcells, sizeof(Microcell), (size_t)P.NMC, dat); + fread_big((void *)Mcells, sizeof(Microcell), (size_t)P.NMC, dat); fprintf(stderr, "."); - fread_big((void*)State.CellMemberArray, sizeof(int), (size_t)P.PopSize, dat); + fread_big((void *)State.CellMemberArray, sizeof(int), (size_t)P.PopSize, dat); fprintf(stderr, "."); - fread_big((void*)State.CellSuscMemberArray, sizeof(int), (size_t)P.PopSize, dat); + fread_big((void *)State.CellSuscMemberArray, sizeof(int), (size_t)P.PopSize, dat); fprintf(stderr, "."); for (i = 0; i < P.NC; i++) { @@ -4330,7 +6344,8 @@ void LoadSnapshot(void) Cells[i].latent += CSM_offset; Cells[i].infected += CSM_offset; } - for (j = 0; j < MAX_INTERVENTION_TYPES; j++) Cells[i].CurInterv[j] = -1; // turn interventions off in loaded image + for (j = 0; j < MAX_INTERVENTION_TYPES; j++) + Cells[i].CurInterv[j] = -1; // turn interventions off in loaded image } for (i = 0; i < P.NMC; i++) if (Mcells[i].n > 0) @@ -4353,49 +6368,50 @@ void LoadSnapshot(void) void SaveSnapshot(void) { - FILE* dat; + FILE *dat; int i = 1; - if (!(dat = fopen(SnapshotSaveFile, "wb"))) ERR_CRITICAL("Unable to open snapshot file\n"); + if (!(dat = fopen(SnapshotSaveFile, "wb"))) + ERR_CRITICAL("Unable to open snapshot file\n"); - fwrite_big((void*) & (P.PopSize), sizeof(int), 1, dat); + fwrite_big((void *)&(P.PopSize), sizeof(int), 1, dat); fprintf(stderr, "## %i\n", i++); - fwrite_big((void*) & (P.NH), sizeof(int), 1, dat); + fwrite_big((void *)&(P.NH), sizeof(int), 1, dat); fprintf(stderr, "## %i\n", i++); - fwrite_big((void*) & (P.NC), sizeof(int), 1, dat); + fwrite_big((void *)&(P.NC), sizeof(int), 1, dat); fprintf(stderr, "## %i\n", i++); - fwrite_big((void*) & (P.NCP), sizeof(int), 1, dat); + fwrite_big((void *)&(P.NCP), sizeof(int), 1, dat); fprintf(stderr, "## %i\n", i++); - fwrite_big((void*) & (P.ncw), sizeof(int), 1, dat); + fwrite_big((void *)&(P.ncw), sizeof(int), 1, dat); fprintf(stderr, "## %i\n", i++); - fwrite_big((void*) & (P.nch), sizeof(int), 1, dat); + fwrite_big((void *)&(P.nch), sizeof(int), 1, dat); fprintf(stderr, "## %i\n", i++); - fwrite_big((void*) & (P.setupSeed1), sizeof(int32_t), 1, dat); + fwrite_big((void *)&(P.setupSeed1), sizeof(int32_t), 1, dat); fprintf(stderr, "## %i\n", i++); - fwrite_big((void*) & (P.setupSeed2), sizeof(int32_t), 1, dat); + fwrite_big((void *)&(P.setupSeed2), sizeof(int32_t), 1, dat); fprintf(stderr, "## %i\n", i++); - fwrite_big((void*) & (P.TimeStep), sizeof(double), 1, dat); + fwrite_big((void *)&(P.TimeStep), sizeof(double), 1, dat); fprintf(stderr, "## %i\n", i++); - fwrite_big((void*) & (P.SnapshotSaveTime), sizeof(double), 1, dat); + fwrite_big((void *)&(P.SnapshotSaveTime), sizeof(double), 1, dat); fprintf(stderr, "## %i\n", i++); - fwrite_big((void*) & (State.CellMemberArray), sizeof(int*), 1, dat); + fwrite_big((void *)&(State.CellMemberArray), sizeof(int *), 1, dat); fprintf(stderr, "## %i\n", i++); - fwrite_big((void*) & (State.CellSuscMemberArray), sizeof(int*), 1, dat); + fwrite_big((void *)&(State.CellSuscMemberArray), sizeof(int *), 1, dat); fprintf(stderr, "## %i\n", i++); - fwrite_big((void*)Hosts, sizeof(Person), (size_t)P.PopSize, dat); + fwrite_big((void *)Hosts, sizeof(Person), (size_t)P.PopSize, dat); fprintf(stderr, "## %i\n", i++); - fwrite_big((void*)Households, sizeof(Household), (size_t)P.NH, dat); + fwrite_big((void *)Households, sizeof(Household), (size_t)P.NH, dat); fprintf(stderr, "## %i\n", i++); - fwrite_big((void*)Cells, sizeof(Cell), (size_t)P.NC, dat); + fwrite_big((void *)Cells, sizeof(Cell), (size_t)P.NC, dat); fprintf(stderr, "## %i\n", i++); - fwrite_big((void*)Mcells, sizeof(Microcell), (size_t)P.NMC, dat); + fwrite_big((void *)Mcells, sizeof(Microcell), (size_t)P.NMC, dat); fprintf(stderr, "## %i\n", i++); - fwrite_big((void*)State.CellMemberArray, sizeof(int), (size_t)P.PopSize, dat); + fwrite_big((void *)State.CellMemberArray, sizeof(int), (size_t)P.PopSize, dat); fprintf(stderr, "## %i\n", i++); - fwrite_big((void*)State.CellSuscMemberArray, sizeof(int), (size_t)P.PopSize, dat); + fwrite_big((void *)State.CellSuscMemberArray, sizeof(int), (size_t)P.PopSize, dat); fprintf(stderr, "## %i\n", i++); fclose(dat); @@ -4405,8 +6421,7 @@ void UpdateProbs(int DoPlace) { if (!DoPlace) { -#pragma omp parallel for schedule(static,500) default(none) \ - shared(P, CellLookup) +#pragma omp parallel for schedule(static, 500) default(none) shared(P, CellLookup) for (int j = 0; j < P.NCP; j++) { CellLookup[j]->tot_prob = 0; @@ -4414,22 +6429,21 @@ void UpdateProbs(int DoPlace) if (P.DoDeath) { CellLookup[j]->S0 += CellLookup[j]->n / 5; - if ((CellLookup[j]->n < 100) || (CellLookup[j]->S0 > CellLookup[j]->n)) CellLookup[j]->S0 = CellLookup[j]->n; + if ((CellLookup[j]->n < 100) || (CellLookup[j]->S0 > CellLookup[j]->n)) + CellLookup[j]->S0 = CellLookup[j]->n; } } } else { -#pragma omp parallel for schedule(static,500) default(none) \ - shared(P, CellLookup) +#pragma omp parallel for schedule(static, 500) default(none) shared(P, CellLookup) for (int j = 0; j < P.NCP; j++) { CellLookup[j]->S0 = CellLookup[j]->S; CellLookup[j]->tot_prob = 0; } } -#pragma omp parallel for schedule(static,500) default(none) \ - shared(P, CellLookup) +#pragma omp parallel for schedule(static, 500) default(none) shared(P, CellLookup) for (int j = 0; j < P.NCP; j++) { int m, k; @@ -4438,8 +6452,9 @@ void UpdateProbs(int DoPlace) t = ((float)CellLookup[0]->n) * CellLookup[j]->max_trans[0]; for (m = 1; m < P.NCP; m++) { - CellLookup[j]->cum_trans[m] = CellLookup[j]->cum_trans[m - 1] + ((float)(CellLookup[m]->S0)) * CellLookup[j]->max_trans[m]; - t += ((float)CellLookup[m]->n) * CellLookup[j]->max_trans[m]; + CellLookup[j]->cum_trans[m] = CellLookup[j]->cum_trans[m - 1] + + ((float)(CellLookup[m]->S0)) * CellLookup[j]->max_trans[m]; + t += ((float)CellLookup[m]->n) * CellLookup[j]->max_trans[m]; } CellLookup[j]->tot_prob = CellLookup[j]->cum_trans[P.NCP - 1]; for (m = 0; m < P.NCP; m++) @@ -4447,7 +6462,8 @@ void UpdateProbs(int DoPlace) CellLookup[j]->tot_prob /= t; for (k = m = 0; k <= 1024; k++) { - while (CellLookup[j]->cum_trans[m] * 1024 < ((float)k)) m++; + while (CellLookup[j]->cum_trans[m] * 1024 < ((float)k)) + m++; CellLookup[j]->InvCDF[k] = m; } } @@ -4459,19 +6475,28 @@ int ChooseTriggerVariableAndValue(int AdUnit) if (P.DoGlobalTriggers) { if (P.DoPerCapitaTriggers) - VariableAndValue = (int)floor(((double)State.trigDetectedCases) * P.GlobalIncThreshPop / ((double)P.PopSize)); + VariableAndValue = (int)floor(((double)State.trigDetectedCases) * P.GlobalIncThreshPop / + ((double)P.PopSize)); else VariableAndValue = State.trigDetectedCases; } - else if (P.DoAdminTriggers) VariableAndValue = State.trigDC_adunit[AdUnit]; - else VariableAndValue = INT_MAX; //// i.e. if not doing triggering (at either admin or global level) then set value to be arbitrarily large so that it will surpass any trigger threshold. Probably other ways around this if anybody wants to correct? + else if (P.DoAdminTriggers) + VariableAndValue = State.trigDC_adunit[AdUnit]; + else + VariableAndValue = + INT_MAX; //// i.e. if not doing triggering (at either admin or global level) then set value + /// to be arbitrarily large so that it will surpass any trigger threshold. Probably + /// other ways around this if anybody wants to correct? return VariableAndValue; } -double ChooseThreshold(int AdUnit, double WhichThreshold) //// point is that this threshold needs to be generalised, so this is likely insufficient. +double ChooseThreshold(int AdUnit, + double WhichThreshold) //// point is that this threshold needs to be + /// generalised, so this is likely insufficient. { double Threshold = 0; - if (P.DoGlobalTriggers) Threshold = WhichThreshold; + if (P.DoGlobalTriggers) + Threshold = WhichThreshold; else if (P.DoAdminTriggers) { if (P.DoPerCapitaTriggers) @@ -4482,7 +6507,6 @@ double ChooseThreshold(int AdUnit, double WhichThreshold) //// point is that thi return Threshold; } - void UpdateEfficaciesAndComplianceProportions(double t) { //// **** social distancing @@ -4490,29 +6514,36 @@ void UpdateEfficaciesAndComplianceProportions(double t) if (t == P.SD_ChangeTimes[ChangeTime]) { //// **** non-enhanced - P.SocDistHouseholdEffectCurrent = P.SD_HouseholdEffects_OverTime[ChangeTime]; //// household - P.SocDistSpatialEffectCurrent = P.SD_SpatialEffects_OverTime [ChangeTime]; //// spatial + P.SocDistHouseholdEffectCurrent = P.SD_HouseholdEffects_OverTime[ChangeTime]; //// household + P.SocDistSpatialEffectCurrent = P.SD_SpatialEffects_OverTime[ChangeTime]; //// spatial for (int PlaceType = 0; PlaceType < P.PlaceTypeNum; PlaceType++) - P.SocDistPlaceEffectCurrent[PlaceType] = P.SD_PlaceEffects_OverTime[ChangeTime][PlaceType]; ///// place + P.SocDistPlaceEffectCurrent[PlaceType] = + P.SD_PlaceEffects_OverTime[ChangeTime][PlaceType]; ///// place //// **** enhanced - P.EnhancedSocDistHouseholdEffectCurrent = P.Enhanced_SD_HouseholdEffects_OverTime [ChangeTime]; //// household - P.EnhancedSocDistSpatialEffectCurrent = P.Enhanced_SD_SpatialEffects_OverTime [ChangeTime]; //// spatial + P.EnhancedSocDistHouseholdEffectCurrent = + P.Enhanced_SD_HouseholdEffects_OverTime[ChangeTime]; //// household + P.EnhancedSocDistSpatialEffectCurrent = + P.Enhanced_SD_SpatialEffects_OverTime[ChangeTime]; //// spatial for (int PlaceType = 0; PlaceType < P.PlaceTypeNum; PlaceType++) - P.EnhancedSocDistPlaceEffectCurrent[PlaceType] = P.Enhanced_SD_PlaceEffects_OverTime[ChangeTime][PlaceType]; ///// place + P.EnhancedSocDistPlaceEffectCurrent[PlaceType] = + P.Enhanced_SD_PlaceEffects_OverTime[ChangeTime][PlaceType]; ///// place - P.SocDistCellIncThresh = P.SD_CellIncThresh_OverTime[ChangeTime]; //// cell incidence threshold + P.SocDistCellIncThresh = + P.SD_CellIncThresh_OverTime[ChangeTime]; //// cell incidence threshold } //// **** case isolation for (int ChangeTime = 0; ChangeTime < P.Num_CI_ChangeTimes; ChangeTime++) if (t == P.CI_ChangeTimes[ChangeTime]) { - P.CaseIsolationEffectiveness = P.CI_SpatialAndPlaceEffects_OverTime [ChangeTime]; //// spatial / place - P.CaseIsolationHouseEffectiveness = P.CI_HouseholdEffects_OverTime [ChangeTime]; //// household + P.CaseIsolationEffectiveness = + P.CI_SpatialAndPlaceEffects_OverTime[ChangeTime]; //// spatial / place + P.CaseIsolationHouseEffectiveness = P.CI_HouseholdEffects_OverTime[ChangeTime]; //// household - P.CaseIsolationProp = P.CI_Prop_OverTime [ChangeTime]; //// compliance - P.CaseIsolation_CellIncThresh = P.CI_CellIncThresh_OverTime [ChangeTime]; //// cell incidence threshold + P.CaseIsolationProp = P.CI_Prop_OverTime[ChangeTime]; //// compliance + P.CaseIsolation_CellIncThresh = + P.CI_CellIncThresh_OverTime[ChangeTime]; //// cell incidence threshold } ////// **** household quarantine @@ -4520,15 +6551,19 @@ void UpdateEfficaciesAndComplianceProportions(double t) for (int ChangeTime = 0; ChangeTime < P.Num_HQ_ChangeTimes; ChangeTime++) if (t == P.HQ_ChangeTimes[ChangeTime]) { - P.HQuarantineSpatialEffect = P.HQ_SpatialEffects_OverTime [ChangeTime]; //// spatial - P.HQuarantineHouseEffect = P.HQ_HouseholdEffects_OverTime [ChangeTime]; //// household + P.HQuarantineSpatialEffect = P.HQ_SpatialEffects_OverTime[ChangeTime]; //// spatial + P.HQuarantineHouseEffect = P.HQ_HouseholdEffects_OverTime[ChangeTime]; //// household for (int PlaceType = 0; PlaceType < P.PlaceTypeNum; PlaceType++) - P.HQuarantinePlaceEffect[PlaceType] = P.HQ_PlaceEffects_OverTime [ChangeTime][PlaceType]; //// place + P.HQuarantinePlaceEffect[PlaceType] = + P.HQ_PlaceEffects_OverTime[ChangeTime][PlaceType]; //// place - P.HQuarantinePropIndivCompliant = P.HQ_Individual_PropComply_OverTime [ChangeTime]; //// individual compliance - P.HQuarantinePropHouseCompliant = P.HQ_Household_PropComply_OverTime [ChangeTime]; //// household compliance + P.HQuarantinePropIndivCompliant = + P.HQ_Individual_PropComply_OverTime[ChangeTime]; //// individual compliance + P.HQuarantinePropHouseCompliant = + P.HQ_Household_PropComply_OverTime[ChangeTime]; //// household compliance - P.HHQuar_CellIncThresh = P.HQ_CellIncThresh_OverTime [ChangeTime]; //// cell incidence threshold + P.HHQuar_CellIncThresh = + P.HQ_CellIncThresh_OverTime[ChangeTime]; //// cell incidence threshold } //// **** place closure @@ -4537,34 +6572,44 @@ void UpdateEfficaciesAndComplianceProportions(double t) for (int ChangeTime = 0; ChangeTime < P.Num_PC_ChangeTimes; ChangeTime++) if (t == P.PC_ChangeTimes[ChangeTime]) { - //// First open all the places - keep commented out in case becomes necessary but avoid if possible to avoid runtime costs. -// unsigned short int ts = (unsigned short int) (P.TimeStepsPerDay * t); -// for (int PlaceType = 0; PlaceType < P.PlaceTypeNum; PlaceType++) -//#pragma omp parallel for schedule(static,1) -// for (int ThreadNum = 0; ThreadNum < P.NumThreads; ThreadNum++) -// for (int PlaceNum = ThreadNum; PlaceNum < P.Nplace[PlaceType]; PlaceNum += P.NumThreads) -// DoPlaceOpen(PlaceType, PlaceNum, ts, ThreadNum); - - P.PlaceCloseSpatialRelContact = P.PC_SpatialEffects_OverTime [ChangeTime]; //// spatial - P.PlaceCloseHouseholdRelContact = P.PC_HouseholdEffects_OverTime[ChangeTime]; //// household + //// First open all the places - keep commented out in case becomes necessary but avoid if + /// possible to avoid runtime costs. + // unsigned short int ts = (unsigned short int) (P.TimeStepsPerDay * t); + // for (int PlaceType = 0; PlaceType < P.PlaceTypeNum; PlaceType++) + //#pragma omp parallel for schedule(static,1) + // for (int ThreadNum = 0; ThreadNum < P.NumThreads; ThreadNum++) + // for (int PlaceNum = ThreadNum; PlaceNum < P.Nplace[PlaceType]; PlaceNum += + // P.NumThreads) DoPlaceOpen(PlaceType, PlaceNum, ts, ThreadNum); + + P.PlaceCloseSpatialRelContact = P.PC_SpatialEffects_OverTime[ChangeTime]; //// spatial + P.PlaceCloseHouseholdRelContact = P.PC_HouseholdEffects_OverTime[ChangeTime]; //// household for (int PlaceType = 0; PlaceType < P.PlaceTypeNum; PlaceType++) { - P.PlaceCloseEffect[PlaceType] = P.PC_PlaceEffects_OverTime[ChangeTime][PlaceType]; //// place - P.PlaceClosePropAttending[PlaceType] = P.PC_PropAttending_OverTime[ChangeTime][PlaceType]; //// place + P.PlaceCloseEffect[PlaceType] = + P.PC_PlaceEffects_OverTime[ChangeTime][PlaceType]; //// place + P.PlaceClosePropAttending[PlaceType] = + P.PC_PropAttending_OverTime[ChangeTime][PlaceType]; //// place } - P.PlaceCloseIncTrig = P.PC_IncThresh_OverTime [ChangeTime]; //// global incidence threshold - P.PlaceCloseFracIncTrig = P.PC_FracIncThresh_OverTime [ChangeTime]; //// fractional incidence threshold - P.PlaceCloseCellIncThresh = P.PC_CellIncThresh_OverTime [ChangeTime]; //// cell incidence threshold - P.PlaceCloseDuration = P.PC_Durs_OverTime [ChangeTime]; //// duration of place closure + P.PlaceCloseIncTrig = P.PC_IncThresh_OverTime[ChangeTime]; //// global incidence threshold + P.PlaceCloseFracIncTrig = + P.PC_FracIncThresh_OverTime[ChangeTime]; //// fractional incidence threshold + P.PlaceCloseCellIncThresh = + P.PC_CellIncThresh_OverTime[ChangeTime]; //// cell incidence threshold + P.PlaceCloseDuration = P.PC_Durs_OverTime[ChangeTime]; //// duration of place closure //// reset place close time start - has been set to 9e9 in event of no triggers. m - if(P.PlaceCloseTimeStart<1e10) P.PlaceCloseTimeStart = t; - - // ensure that new duration doesn't go over next change time. Judgement call here - talk to Neil if this is what he wants. - if ((ChangeTime < P.Num_PC_ChangeTimes - 1) && (P.PlaceCloseTimeStart + P.PlaceCloseDuration >= P.PC_ChangeTimes[ChangeTime + 1])) - P.PlaceCloseDuration = P.PC_ChangeTimes[ChangeTime + 1] - P.PC_ChangeTimes[ChangeTime]; // -1; - //fprintf(stderr, "\nt=%lf, n=%i (%i) PlaceCloseDuration = %lf (%lf) \n", t, ChangeTime, P.Num_PC_ChangeTimes, P.PlaceCloseDuration, P.PC_ChangeTimes[ChangeTime+1]); + if (P.PlaceCloseTimeStart < 1e10) + P.PlaceCloseTimeStart = t; + + // ensure that new duration doesn't go over next change time. Judgement call here - talk to + // Neil if this is what he wants. + if ((ChangeTime < P.Num_PC_ChangeTimes - 1) && + (P.PlaceCloseTimeStart + P.PlaceCloseDuration >= P.PC_ChangeTimes[ChangeTime + 1])) + P.PlaceCloseDuration = + P.PC_ChangeTimes[ChangeTime + 1] - P.PC_ChangeTimes[ChangeTime]; // -1; + // fprintf(stderr, "\nt=%lf, n=%i (%i) PlaceCloseDuration = %lf (%lf) \n", t, ChangeTime, + // P.Num_PC_ChangeTimes, P.PlaceCloseDuration, P.PC_ChangeTimes[ChangeTime+1]); } } @@ -4572,10 +6617,12 @@ void UpdateEfficaciesAndComplianceProportions(double t) for (int ChangeTime = 0; ChangeTime < P.Num_DCT_ChangeTimes; ChangeTime++) if (t == P.DCT_ChangeTimes[ChangeTime]) { - P.DCTCaseIsolationEffectiveness = P.DCT_SpatialAndPlaceEffects_OverTime [ChangeTime]; //// spatial / place - P.DCTCaseIsolationHouseEffectiveness = P.DCT_HouseholdEffects_OverTime [ChangeTime]; //// household - P.ProportionDigitalContactsIsolate = P.DCT_Prop_OverTime [ChangeTime]; //// compliance - P.MaxDigitalContactsToTrace = P.DCT_MaxToTrace_OverTime [ChangeTime]; + P.DCTCaseIsolationEffectiveness = + P.DCT_SpatialAndPlaceEffects_OverTime[ChangeTime]; //// spatial / place + P.DCTCaseIsolationHouseEffectiveness = + P.DCT_HouseholdEffects_OverTime[ChangeTime]; //// household + P.ProportionDigitalContactsIsolate = P.DCT_Prop_OverTime[ChangeTime]; //// compliance + P.MaxDigitalContactsToTrace = P.DCT_MaxToTrace_OverTime[ChangeTime]; } } @@ -4587,71 +6634,83 @@ void RecordAdminAgeBreakdowns(int t_int) { // Record incidence. Need new total minus old total (same as minus old total plus new total). // First subtract old total before reset, collated and updated. - TimeSeries[t_int].incInf_age_adunit[AgeGroup][AdUnit] = (double)(-State.cumInf_age_adunit[AgeGroup][AdUnit]); + TimeSeries[t_int].incInf_age_adunit[AgeGroup][AdUnit] = + (double)(-State.cumInf_age_adunit[AgeGroup][AdUnit]); // reset totals State.prevInf_age_adunit[AgeGroup][AdUnit] = 0; - State.cumInf_age_adunit [AgeGroup][AdUnit] = 0; + State.cumInf_age_adunit[AgeGroup][AdUnit] = 0; // sum totals for (int Thread = 0; Thread < P.NumThreads; Thread++) { - State.prevInf_age_adunit[AgeGroup][AdUnit] += StateT[Thread].prevInf_age_adunit[AgeGroup][AdUnit]; - State.cumInf_age_adunit [AgeGroup][AdUnit] += StateT[Thread].cumInf_age_adunit [AgeGroup][AdUnit]; + State.prevInf_age_adunit[AgeGroup][AdUnit] += + StateT[Thread].prevInf_age_adunit[AgeGroup][AdUnit]; + State.cumInf_age_adunit[AgeGroup][AdUnit] += + StateT[Thread].cumInf_age_adunit[AgeGroup][AdUnit]; } // record in time series. - TimeSeries[t_int].prevInf_age_adunit[AgeGroup][AdUnit] = State.prevInf_age_adunit[AgeGroup][AdUnit]; - TimeSeries[t_int].cumInf_age_adunit [AgeGroup][AdUnit] = State.cumInf_age_adunit [AgeGroup][AdUnit]; + TimeSeries[t_int].prevInf_age_adunit[AgeGroup][AdUnit] = + State.prevInf_age_adunit[AgeGroup][AdUnit]; + TimeSeries[t_int].cumInf_age_adunit[AgeGroup][AdUnit] = + State.cumInf_age_adunit[AgeGroup][AdUnit]; // Record incidence. Need new total minus old total. Add new total - TimeSeries[t_int].incInf_age_adunit[AgeGroup][AdUnit] += (double)(State.cumInf_age_adunit[AgeGroup][AdUnit]); + TimeSeries[t_int].incInf_age_adunit[AgeGroup][AdUnit] += + (double)(State.cumInf_age_adunit[AgeGroup][AdUnit]); } } void RecordQuarNotInfected(int n, unsigned short int ts) { int QuarNotInfected = 0, QuarNotSymptomatic = 0; -#pragma omp parallel for schedule(static,1) reduction(+:QuarNotInfected, QuarNotSymptomatic) +#pragma omp parallel for schedule(static, 1) reduction(+ : QuarNotInfected, QuarNotSymptomatic) for (int thread_no = 0; thread_no < P.NumThreads; thread_no++) for (int Person = thread_no; Person < P.PopSize; Person += P.NumThreads) if (HOST_QUARANTINED(Person)) { - if (Hosts[Person].inf == InfStat_Susceptible || abs(Hosts[Person].inf) == InfStat_Recovered) QuarNotInfected++; - if (Hosts[Person].inf > 0) QuarNotSymptomatic++; + if (Hosts[Person].inf == InfStat_Susceptible || abs(Hosts[Person].inf) == InfStat_Recovered) + QuarNotInfected++; + if (Hosts[Person].inf > 0) + QuarNotSymptomatic++; } - TimeSeries[n].prevQuarNotInfected = (double) QuarNotInfected; - TimeSeries[n].prevQuarNotSymptomatic = (double) QuarNotSymptomatic; + TimeSeries[n].prevQuarNotInfected = (double)QuarNotInfected; + TimeSeries[n].prevQuarNotSymptomatic = (double)QuarNotSymptomatic; } void RecordSample(double t, int n) { int j, k, S, L, I, R, D, N, cumC, cumTC, cumI, cumR, cumD, cumDC, cumFC, cumTG, cumSI, nTG; - int cumCT; //added cumulative number of contact traced: ggilani 15/06/17 - int cumCC; //added cumulative number of cases who are contacts: ggilani 28/05/2019 - int cumDCT; //added cumulative number of cases who are digitally contact traced: ggilani 11/03/20 - int cumHQ, cumAC, cumAH, cumAA, cumACS, cumAPC, cumAPA, cumAPCS, numPC, trigDetectedCases, trigAlert, trigAlertCases; - int cumC_country[MAX_COUNTRIES]; //add cumulative cases per country + int cumCT; // added cumulative number of contact traced: ggilani 15/06/17 + int cumCC; // added cumulative number of cases who are contacts: ggilani 28/05/2019 + int cumDCT; // added cumulative number of cases who are digitally contact traced: ggilani 11/03/20 + int cumHQ, cumAC, cumAH, cumAA, cumACS, cumAPC, cumAPA, cumAPCS, numPC, trigDetectedCases, + trigAlert, trigAlertCases; + int cumC_country[MAX_COUNTRIES]; // add cumulative cases per country unsigned short int ts; //// Severity quantities - int Mild, ILI, SARI, Critical, CritRecov, cumMild, cumILI, cumSARI, cumCritical, cumCritRecov, cumDeath_ILI, cumDeath_SARI, cumDeath_Critical; + int Mild, ILI, SARI, Critical, CritRecov, cumMild, cumILI, cumSARI, cumCritical, cumCritRecov, + cumDeath_ILI, cumDeath_SARI, cumDeath_Critical; - ts = (unsigned short int) (P.TimeStepsPerDay * t); + ts = (unsigned short int)(P.TimeStepsPerDay * t); //// initialize to zero - S = L = I = R = D = cumI = cumC = cumDC = cumTC = cumFC = cumHQ = cumAC = cumAA = cumAH = cumACS - = cumAPC = cumAPA = cumAPCS = cumD = cumCT = cumCC = cumDCT = cumTG = cumSI = nTG = 0; - for (int i = 0; i < MAX_COUNTRIES; i++) cumC_country[i] = 0; + S = L = I = R = D = cumI = cumC = cumDC = cumTC = cumFC = cumHQ = cumAC = cumAA = cumAH = cumACS = + cumAPC = cumAPA = cumAPCS = cumD = cumCT = cumCC = cumDCT = cumTG = cumSI = nTG = 0; + for (int i = 0; i < MAX_COUNTRIES; i++) + cumC_country[i] = 0; if (P.DoSeverity) - Mild = ILI = SARI = Critical = CritRecov = cumMild = cumILI = cumSARI = cumCritical = cumCritRecov = cumDeath_ILI = cumDeath_SARI = cumDeath_Critical = 0; + Mild = ILI = SARI = Critical = CritRecov = cumMild = cumILI = cumSARI = cumCritical = + cumCritRecov = cumDeath_ILI = cumDeath_SARI = cumDeath_Critical = 0; #pragma omp parallel for schedule(static,10000) reduction(+:S,L,I,R,D,cumTC) default(none) \ shared(P, CellLookup) for (int i = 0; i < P.NCP; i++) { - Cell* ct = CellLookup[i]; + Cell *ct = CellLookup[i]; S += (int)ct->S; L += (int)ct->L; I += (int)ct->I; @@ -4661,9 +6720,10 @@ void RecordSample(double t, int n) } cumR = R; cumD = D; - //cumD = 0; + // cumD = 0; N = S + L + I + R + D; - if (N != P.PopSize) fprintf(stderr, "## %i #\n", P.PopSize - N); + if (N != P.PopSize) + fprintf(stderr, "## %i #\n", P.PopSize - N); State.sumRad2 = 0; for (j = 0; j < P.NumThreads; j++) { @@ -4675,9 +6735,9 @@ void RecordSample(double t, int n) nTG += StateT[j].nTG; StateT[j].cumTG = StateT[j].cumSI = StateT[j].nTG = 0; cumFC += StateT[j].cumFC; - cumCT += StateT[j].cumCT; //added contact tracing - cumCC += StateT[j].cumCC; //added cases who are contacts - cumDCT += StateT[j].cumDCT; //added cases who are digitally contact traced + cumCT += StateT[j].cumCT; // added contact tracing + cumCC += StateT[j].cumCC; // added cases who are contacts + cumDCT += StateT[j].cumDCT; // added cases who are digitally contact traced State.sumRad2 += StateT[j].sumRad2; State.sumRad2 += StateT[j].sumRad2; cumHQ += StateT[j].cumHQ; @@ -4688,31 +6748,33 @@ void RecordSample(double t, int n) cumAPCS += StateT[j].cumAPCS; cumAH += StateT[j].cumAH; cumACS += StateT[j].cumACS; - //cumD += StateT[j].cumD; + // cumD += StateT[j].cumD; if (P.DoSeverity) { ///// severity states by thread - Mild += StateT[j].Mild ; - ILI += StateT[j].ILI ; - SARI += StateT[j].SARI ; - Critical += StateT[j].Critical ; - CritRecov += StateT[j].CritRecov ; + Mild += StateT[j].Mild; + ILI += StateT[j].ILI; + SARI += StateT[j].SARI; + Critical += StateT[j].Critical; + CritRecov += StateT[j].CritRecov; ///// cumulative severity states by thread - cumMild += StateT[j].cumMild ; - cumILI += StateT[j].cumILI ; - cumSARI += StateT[j].cumSARI ; - cumCritical += StateT[j].cumCritical ; - cumCritRecov += StateT[j].cumCritRecov ; - cumDeath_ILI += StateT[j].cumDeath_ILI ; - cumDeath_SARI += StateT[j].cumDeath_SARI ; - cumDeath_Critical += StateT[j].cumDeath_Critical ; - } - - //add up cumulative country counts: ggilani - 12/11/14 - for (int i = 0; i < MAX_COUNTRIES; i++) cumC_country[i] += StateT[j].cumC_country[i]; - if (State.maxRad2 < StateT[j].maxRad2) State.maxRad2 = StateT[j].maxRad2; + cumMild += StateT[j].cumMild; + cumILI += StateT[j].cumILI; + cumSARI += StateT[j].cumSARI; + cumCritical += StateT[j].cumCritical; + cumCritRecov += StateT[j].cumCritRecov; + cumDeath_ILI += StateT[j].cumDeath_ILI; + cumDeath_SARI += StateT[j].cumDeath_SARI; + cumDeath_Critical += StateT[j].cumDeath_Critical; + } + + // add up cumulative country counts: ggilani - 12/11/14 + for (int i = 0; i < MAX_COUNTRIES; i++) + cumC_country[i] += StateT[j].cumC_country[i]; + if (State.maxRad2 < StateT[j].maxRad2) + State.maxRad2 = StateT[j].maxRad2; } for (j = 0; j < P.NumThreads; j++) StateT[j].maxRad2 = State.maxRad2; @@ -4727,8 +6789,9 @@ void RecordSample(double t, int n) TimeSeries[n].incFC = (double)(cumFC - State.cumFC); TimeSeries[n].incCT = (double)(cumCT - State.cumCT); // added contact tracing TimeSeries[n].incCC = (double)(cumCC - State.cumCC); // added cases who are contacts - TimeSeries[n].incDCT = (double)(cumDCT - State.cumDCT); //added cases who are digitally contact traced - TimeSeries[n].incDC = (double)(cumDC - State.cumDC); //added incidence of detected cases + TimeSeries[n].incDCT = + (double)(cumDCT - State.cumDCT); // added cases who are digitally contact traced + TimeSeries[n].incDC = (double)(cumDC - State.cumDC); // added incidence of detected cases TimeSeries[n].incTC = (double)(cumTC - State.cumTC); TimeSeries[n].incR = (double)(cumR - State.cumR); TimeSeries[n].incD = (double)(cumD - State.cumD); @@ -4744,7 +6807,7 @@ void RecordSample(double t, int n) TimeSeries[n].cumUT = State.cumUT; TimeSeries[n].cumTP = State.cumTP; TimeSeries[n].cumV = State.cumV; - TimeSeries[n].cumVG = State.cumVG; //added VG; + TimeSeries[n].cumVG = State.cumVG; // added VG; TimeSeries[n].cumDC = cumDC; TimeSeries[n].meanTG = TimeSeries[n].meanSI = 0; if (nTG > 0) // record mean generation time and serial interval in timestep @@ -4752,18 +6815,21 @@ void RecordSample(double t, int n) TimeSeries[n].meanTG = P.TimeStep * ((double)cumTG) / ((double)nTG); TimeSeries[n].meanSI = P.TimeStep * ((double)cumSI) / ((double)nTG); } - //fprintf(stderr, "\ncumD=%i last_cumD=%i incD=%lg\n ", cumD, State.cumD, TimeSeries[n].incD); - //incidence per country - for (int i = 0; i < MAX_COUNTRIES; i++) TimeSeries[n].incC_country[i] = (double)(cumC_country[i] - State.cumC_country[i]); + // fprintf(stderr, "\ncumD=%i last_cumD=%i incD=%lg\n ", cumD, State.cumD, TimeSeries[n].incD); + // incidence per country + for (int i = 0; i < MAX_COUNTRIES; i++) + TimeSeries[n].incC_country[i] = (double)(cumC_country[i] - State.cumC_country[i]); if (P.DoICUTriggers) { trigDetectedCases = cumCritical; - if (n >= P.TriggersSamplingInterval) trigDetectedCases -= (int)TimeSeries[n - P.TriggersSamplingInterval].cumCritical; + if (n >= P.TriggersSamplingInterval) + trigDetectedCases -= (int)TimeSeries[n - P.TriggersSamplingInterval].cumCritical; } else { trigDetectedCases = cumDC; - if (n >= P.TriggersSamplingInterval) trigDetectedCases -= (int)TimeSeries[n - P.TriggersSamplingInterval].cumDC; + if (n >= P.TriggersSamplingInterval) + trigDetectedCases -= (int)TimeSeries[n - P.TriggersSamplingInterval].cumDC; } State.trigDetectedCases = trigDetectedCases; @@ -4777,9 +6843,9 @@ void RecordSample(double t, int n) State.cumDC = cumDC; State.cumTC = cumTC; State.cumFC = cumFC; - State.cumCT = cumCT; //added cumulative contact tracing - State.cumCC = cumCC; //added cumulative cases who are contacts - State.cumDCT = cumDCT; //added cumulative cases who are digitally contact traced + State.cumCT = cumCT; // added cumulative contact tracing + State.cumCC = cumCC; // added cumulative cases who are contacts + State.cumDCT = cumDCT; // added cumulative cases who are digitally contact traced State.cumC = cumC; State.cumR = cumR; State.cumD = cumD; @@ -4796,55 +6862,55 @@ void RecordSample(double t, int n) if (P.DoAdUnits && P.OutputAdUnitAge) RecordAdminAgeBreakdowns(n); - RecordQuarNotInfected(n, ts); + RecordQuarNotInfected(n, ts); if (P.DoSeverity) { //// Record incidence. (Must be done with old State totals) - TimeSeries[n].incMild = (double)(cumMild - State.cumMild ); - TimeSeries[n].incILI = (double)(cumILI - State.cumILI ); - TimeSeries[n].incSARI = (double)(cumSARI - State.cumSARI ); - TimeSeries[n].incCritical = (double)(cumCritical - State.cumCritical ); - TimeSeries[n].incCritRecov = (double)(cumCritRecov - State.cumCritRecov ); - TimeSeries[n].incDeath_ILI = (double)(cumDeath_ILI - State.cumDeath_ILI ); - TimeSeries[n].incDeath_SARI = (double)(cumDeath_SARI - State.cumDeath_SARI ); - TimeSeries[n].incDeath_Critical = (double)(cumDeath_Critical - State.cumDeath_Critical ); + TimeSeries[n].incMild = (double)(cumMild - State.cumMild); + TimeSeries[n].incILI = (double)(cumILI - State.cumILI); + TimeSeries[n].incSARI = (double)(cumSARI - State.cumSARI); + TimeSeries[n].incCritical = (double)(cumCritical - State.cumCritical); + TimeSeries[n].incCritRecov = (double)(cumCritRecov - State.cumCritRecov); + TimeSeries[n].incDeath_ILI = (double)(cumDeath_ILI - State.cumDeath_ILI); + TimeSeries[n].incDeath_SARI = (double)(cumDeath_SARI - State.cumDeath_SARI); + TimeSeries[n].incDeath_Critical = (double)(cumDeath_Critical - State.cumDeath_Critical); /////// update state with totals - State.Mild = Mild ; - State.ILI = ILI ; - State.SARI = SARI ; - State.Critical = Critical ; - State.CritRecov = CritRecov ; - State.cumMild = cumMild ; - State.cumILI = cumILI ; - State.cumSARI = cumSARI ; - State.cumCritical = cumCritical ; - State.cumCritRecov = cumCritRecov ; - State.cumDeath_ILI = cumDeath_ILI ; - State.cumDeath_SARI = cumDeath_SARI ; - State.cumDeath_Critical = cumDeath_Critical ; + State.Mild = Mild; + State.ILI = ILI; + State.SARI = SARI; + State.Critical = Critical; + State.CritRecov = CritRecov; + State.cumMild = cumMild; + State.cumILI = cumILI; + State.cumSARI = cumSARI; + State.cumCritical = cumCritical; + State.cumCritRecov = cumCritRecov; + State.cumDeath_ILI = cumDeath_ILI; + State.cumDeath_SARI = cumDeath_SARI; + State.cumDeath_Critical = cumDeath_Critical; //// Record new totals for time series. (Must be done with old State totals) - TimeSeries[n].Mild = Mild ; - TimeSeries[n].ILI = ILI ; - TimeSeries[n].SARI = SARI ; - TimeSeries[n].Critical = Critical ; - TimeSeries[n].CritRecov = CritRecov ; - TimeSeries[n].cumMild = cumMild ; - TimeSeries[n].cumILI = cumILI ; - TimeSeries[n].cumSARI = cumSARI ; - TimeSeries[n].cumCritical = cumCritical ; - TimeSeries[n].cumCritRecov = cumCritRecov ; - TimeSeries[n].cumDeath_ILI = cumDeath_ILI ; - TimeSeries[n].cumDeath_SARI = cumDeath_SARI ; - TimeSeries[n].cumDeath_Critical = cumDeath_Critical ; + TimeSeries[n].Mild = Mild; + TimeSeries[n].ILI = ILI; + TimeSeries[n].SARI = SARI; + TimeSeries[n].Critical = Critical; + TimeSeries[n].CritRecov = CritRecov; + TimeSeries[n].cumMild = cumMild; + TimeSeries[n].cumILI = cumILI; + TimeSeries[n].cumSARI = cumSARI; + TimeSeries[n].cumCritical = cumCritical; + TimeSeries[n].cumCritRecov = cumCritRecov; + TimeSeries[n].cumDeath_ILI = cumDeath_ILI; + TimeSeries[n].cumDeath_SARI = cumDeath_SARI; + TimeSeries[n].cumDeath_Critical = cumDeath_Critical; for (int i = 0; i < NUM_AGE_GROUPS; i++) { - //// Record incidence. Need new total minus old total (same as minus old total plus new total). - //// First subtract old total while unchanged. + //// Record incidence. Need new total minus old total (same as minus old total plus new + /// total). / First subtract old total while unchanged. TimeSeries[n].incMild_age[i] = (double)(-State.cumMild_age[i]); TimeSeries[n].incILI_age[i] = (double)(-State.cumILI_age[i]); TimeSeries[n].incSARI_age[i] = (double)(-State.cumSARI_age[i]); @@ -4914,89 +6980,96 @@ void RecordSample(double t, int n) if (P.DoAdUnits) for (int i = 0; i <= P.NumAdunits; i++) { - //// Record incidence. Need new total minus old total (same as minus old total plus new total). - //// First subtract old total while unchanged. - TimeSeries[n].incMild_adunit [i] = (double)(-State.cumMild_adunit [i]); - TimeSeries[n].incILI_adunit [i] = (double)(-State.cumILI_adunit [i]); - TimeSeries[n].incSARI_adunit [i] = (double)(-State.cumSARI_adunit [i]); - TimeSeries[n].incCritical_adunit [i] = (double)(-State.cumCritical_adunit [i]); - TimeSeries[n].incCritRecov_adunit [i] = (double)(-State.cumCritRecov_adunit [i]); - TimeSeries[n].incD_adunit [i] = (double)(-State.cumD_adunit [i]); - TimeSeries[n].incDeath_ILI_adunit [i] = (double)(-State.cumDeath_ILI_adunit [i]); - TimeSeries[n].incDeath_SARI_adunit [i] = (double)(-State.cumDeath_SARI_adunit [i]); - TimeSeries[n].incDeath_Critical_adunit [i] = (double)(-State.cumDeath_Critical_adunit [i]); - - //// reset State (not StateT) to zero. Don't need to do this with non-admin unit as local variables Mild, cumSARI etc. initialized to zero at beginning of function. Check with Gemma - State.Mild_adunit [i] = 0; - State.ILI_adunit [i] = 0; - State.SARI_adunit [i] = 0; - State.Critical_adunit [i] = 0; - State.CritRecov_adunit [i] = 0; - State.cumMild_adunit [i] = 0; - State.cumILI_adunit [i] = 0; - State.cumSARI_adunit [i] = 0; - State.cumCritical_adunit [i] = 0; - State.cumCritRecov_adunit [i] = 0; - State.cumD_adunit [i] = 0; - State.cumDeath_ILI_adunit [i] = 0; - State.cumDeath_SARI_adunit [i] = 0; - State.cumDeath_Critical_adunit [i] = 0; + //// Record incidence. Need new total minus old total (same as minus old total plus new + /// total). / First subtract old total while unchanged. + TimeSeries[n].incMild_adunit[i] = (double)(-State.cumMild_adunit[i]); + TimeSeries[n].incILI_adunit[i] = (double)(-State.cumILI_adunit[i]); + TimeSeries[n].incSARI_adunit[i] = (double)(-State.cumSARI_adunit[i]); + TimeSeries[n].incCritical_adunit[i] = (double)(-State.cumCritical_adunit[i]); + TimeSeries[n].incCritRecov_adunit[i] = (double)(-State.cumCritRecov_adunit[i]); + TimeSeries[n].incD_adunit[i] = (double)(-State.cumD_adunit[i]); + TimeSeries[n].incDeath_ILI_adunit[i] = (double)(-State.cumDeath_ILI_adunit[i]); + TimeSeries[n].incDeath_SARI_adunit[i] = (double)(-State.cumDeath_SARI_adunit[i]); + TimeSeries[n].incDeath_Critical_adunit[i] = (double)(-State.cumDeath_Critical_adunit[i]); + + //// reset State (not StateT) to zero. Don't need to do this with non-admin unit as local + /// variables Mild, cumSARI etc. initialized to zero at beginning of function. Check with + /// Gemma + State.Mild_adunit[i] = 0; + State.ILI_adunit[i] = 0; + State.SARI_adunit[i] = 0; + State.Critical_adunit[i] = 0; + State.CritRecov_adunit[i] = 0; + State.cumMild_adunit[i] = 0; + State.cumILI_adunit[i] = 0; + State.cumSARI_adunit[i] = 0; + State.cumCritical_adunit[i] = 0; + State.cumCritRecov_adunit[i] = 0; + State.cumD_adunit[i] = 0; + State.cumDeath_ILI_adunit[i] = 0; + State.cumDeath_SARI_adunit[i] = 0; + State.cumDeath_Critical_adunit[i] = 0; for (j = 0; j < P.NumThreads; j++) { //// collate from threads - State.Mild_adunit [i] += StateT[j].Mild_adunit [i]; - State.ILI_adunit [i] += StateT[j].ILI_adunit [i]; - State.SARI_adunit [i] += StateT[j].SARI_adunit [i]; - State.Critical_adunit [i] += StateT[j].Critical_adunit [i]; - State.CritRecov_adunit [i] += StateT[j].CritRecov_adunit [i]; - State.cumMild_adunit [i] += StateT[j].cumMild_adunit [i]; - State.cumILI_adunit [i] += StateT[j].cumILI_adunit [i]; - State.cumSARI_adunit [i] += StateT[j].cumSARI_adunit [i]; - State.cumCritical_adunit [i] += StateT[j].cumCritical_adunit [i]; - State.cumCritRecov_adunit [i] += StateT[j].cumCritRecov_adunit [i]; - State.cumD_adunit [i] += StateT[j].cumD_adunit [i]; - State.cumDeath_ILI_adunit [i] += StateT[j].cumDeath_ILI_adunit [i]; - State.cumDeath_SARI_adunit [i] += StateT[j].cumDeath_SARI_adunit [i]; - State.cumDeath_Critical_adunit [i] += StateT[j].cumDeath_Critical_adunit [i]; + State.Mild_adunit[i] += StateT[j].Mild_adunit[i]; + State.ILI_adunit[i] += StateT[j].ILI_adunit[i]; + State.SARI_adunit[i] += StateT[j].SARI_adunit[i]; + State.Critical_adunit[i] += StateT[j].Critical_adunit[i]; + State.CritRecov_adunit[i] += StateT[j].CritRecov_adunit[i]; + State.cumMild_adunit[i] += StateT[j].cumMild_adunit[i]; + State.cumILI_adunit[i] += StateT[j].cumILI_adunit[i]; + State.cumSARI_adunit[i] += StateT[j].cumSARI_adunit[i]; + State.cumCritical_adunit[i] += StateT[j].cumCritical_adunit[i]; + State.cumCritRecov_adunit[i] += StateT[j].cumCritRecov_adunit[i]; + State.cumD_adunit[i] += StateT[j].cumD_adunit[i]; + State.cumDeath_ILI_adunit[i] += StateT[j].cumDeath_ILI_adunit[i]; + State.cumDeath_SARI_adunit[i] += StateT[j].cumDeath_SARI_adunit[i]; + State.cumDeath_Critical_adunit[i] += StateT[j].cumDeath_Critical_adunit[i]; } //// Record incidence. Need new total minus old total. Add new total - TimeSeries[n].incMild_adunit [i] += (double)(State.cumMild_adunit [i]); - TimeSeries[n].incILI_adunit [i] += (double)(State.cumILI_adunit [i]); - TimeSeries[n].incSARI_adunit [i] += (double)(State.cumSARI_adunit [i]); - TimeSeries[n].incCritical_adunit [i] += (double)(State.cumCritical_adunit [i]); - TimeSeries[n].incCritRecov_adunit [i] += (double)(State.cumCritRecov_adunit [i]); - TimeSeries[n].incD_adunit [i] += (double)(State.cumD_adunit [i]); - TimeSeries[n].incDeath_ILI_adunit [i] += (double)(State.cumDeath_ILI_adunit [i]); - TimeSeries[n].incDeath_SARI_adunit [i] += (double)(State.cumDeath_SARI_adunit [i]); - TimeSeries[n].incDeath_Critical_adunit [i] += (double)(State.cumDeath_Critical_adunit [i]); + TimeSeries[n].incMild_adunit[i] += (double)(State.cumMild_adunit[i]); + TimeSeries[n].incILI_adunit[i] += (double)(State.cumILI_adunit[i]); + TimeSeries[n].incSARI_adunit[i] += (double)(State.cumSARI_adunit[i]); + TimeSeries[n].incCritical_adunit[i] += (double)(State.cumCritical_adunit[i]); + TimeSeries[n].incCritRecov_adunit[i] += (double)(State.cumCritRecov_adunit[i]); + TimeSeries[n].incD_adunit[i] += (double)(State.cumD_adunit[i]); + TimeSeries[n].incDeath_ILI_adunit[i] += (double)(State.cumDeath_ILI_adunit[i]); + TimeSeries[n].incDeath_SARI_adunit[i] += (double)(State.cumDeath_SARI_adunit[i]); + TimeSeries[n].incDeath_Critical_adunit[i] += (double)(State.cumDeath_Critical_adunit[i]); //// Record new totals for time series. (Must be done with old State totals) - TimeSeries[n].Mild_adunit [i] = State.Mild_adunit [i]; - TimeSeries[n].ILI_adunit [i] = State.ILI_adunit [i]; - TimeSeries[n].SARI_adunit [i] = State.SARI_adunit [i]; - TimeSeries[n].Critical_adunit [i] = State.Critical_adunit [i]; - TimeSeries[n].CritRecov_adunit [i] = State.CritRecov_adunit [i]; - TimeSeries[n].cumMild_adunit [i] = State.cumMild_adunit [i]; - TimeSeries[n].cumILI_adunit [i] = State.cumILI_adunit [i]; - TimeSeries[n].cumSARI_adunit [i] = State.cumSARI_adunit [i]; - TimeSeries[n].cumCritical_adunit [i] = State.cumCritical_adunit [i]; - TimeSeries[n].cumCritRecov_adunit [i] = State.cumCritRecov_adunit [i]; - TimeSeries[n].cumD_adunit [i] = State.cumD_adunit [i]; - TimeSeries[n].cumDeath_ILI_adunit [i] = State.cumDeath_ILI_adunit [i]; - TimeSeries[n].cumDeath_SARI_adunit [i] = State.cumDeath_SARI_adunit [i]; - TimeSeries[n].cumDeath_Critical_adunit [i] = State.cumDeath_Critical_adunit [i]; + TimeSeries[n].Mild_adunit[i] = State.Mild_adunit[i]; + TimeSeries[n].ILI_adunit[i] = State.ILI_adunit[i]; + TimeSeries[n].SARI_adunit[i] = State.SARI_adunit[i]; + TimeSeries[n].Critical_adunit[i] = State.Critical_adunit[i]; + TimeSeries[n].CritRecov_adunit[i] = State.CritRecov_adunit[i]; + TimeSeries[n].cumMild_adunit[i] = State.cumMild_adunit[i]; + TimeSeries[n].cumILI_adunit[i] = State.cumILI_adunit[i]; + TimeSeries[n].cumSARI_adunit[i] = State.cumSARI_adunit[i]; + TimeSeries[n].cumCritical_adunit[i] = State.cumCritical_adunit[i]; + TimeSeries[n].cumCritRecov_adunit[i] = State.cumCritRecov_adunit[i]; + TimeSeries[n].cumD_adunit[i] = State.cumD_adunit[i]; + TimeSeries[n].cumDeath_ILI_adunit[i] = State.cumDeath_ILI_adunit[i]; + TimeSeries[n].cumDeath_SARI_adunit[i] = State.cumDeath_SARI_adunit[i]; + TimeSeries[n].cumDeath_Critical_adunit[i] = State.cumDeath_Critical_adunit[i]; } } - //update cumulative cases per country - for (int i = 0; i < MAX_COUNTRIES; i++) State.cumC_country[i] = cumC_country[i]; - //update overall state variable for cumulative cases per adunit + // update cumulative cases per country + for (int i = 0; i < MAX_COUNTRIES; i++) + State.cumC_country[i] = cumC_country[i]; + // update overall state variable for cumulative cases per adunit TimeSeries[n].rmsRad = (State.cumI > 0) ? sqrt(State.sumRad2 / ((double)State.cumI)) : 0; TimeSeries[n].maxRad = sqrt(State.maxRad2); - TimeSeries[n].extinct = ((((P.SmallEpidemicCases >= 0) && (State.R <= P.SmallEpidemicCases)) || (P.SmallEpidemicCases < 0)) && (State.I + State.L == 0)) ? 1 : 0; + TimeSeries[n].extinct = ((((P.SmallEpidemicCases >= 0) && (State.R <= P.SmallEpidemicCases)) || + (P.SmallEpidemicCases < 0)) && + (State.I + State.L == 0)) + ? 1 + : 0; for (int i = 0; i < NUM_AGE_GROUPS; i++) { TimeSeries[n].incCa[i] = TimeSeries[n].incIa[i] = TimeSeries[n].incDa[i] = 0; @@ -5010,7 +7083,8 @@ void RecordSample(double t, int n) for (int i = 0; i < 2; i++) { - TimeSeries[n].incC_keyworker[i] = TimeSeries[n].incI_keyworker[i] = TimeSeries[n].cumT_keyworker[i] = 0; + TimeSeries[n].incC_keyworker[i] = TimeSeries[n].incI_keyworker[i] = + TimeSeries[n].cumT_keyworker[i] = 0; for (j = 0; j < P.NumThreads; j++) { TimeSeries[n].incC_keyworker[i] += (double)StateT[j].cumC_keyworker[i]; @@ -5032,49 +7106,68 @@ void RecordSample(double t, int n) if (P.DoAdUnits) for (int i = 0; i <= P.NumAdunits; i++) { - TimeSeries[n].incI_adunit[i] = TimeSeries[n].incC_adunit[i] = TimeSeries[n].cumT_adunit[i] = TimeSeries[n].incH_adunit[i] = TimeSeries[n].incDC_adunit[i] = TimeSeries[n].incCT_adunit[i] = TimeSeries[n].incDCT_adunit[i] = 0; //added detected cases: ggilani 03/02/15 + TimeSeries[n].incI_adunit[i] = TimeSeries[n].incC_adunit[i] = TimeSeries[n].cumT_adunit[i] = + TimeSeries[n].incH_adunit[i] = TimeSeries[n].incDC_adunit[i] = + TimeSeries[n].incCT_adunit[i] = TimeSeries[n].incDCT_adunit[i] = + 0; // added detected cases: ggilani 03/02/15 for (j = 0; j < P.NumThreads; j++) { TimeSeries[n].incI_adunit[i] += (double)StateT[j].cumI_adunit[i]; TimeSeries[n].incC_adunit[i] += (double)StateT[j].cumC_adunit[i]; - TimeSeries[n].incDC_adunit[i] += (double)StateT[j].cumDC_adunit[i]; //added detected cases: ggilani 03/02/15 - TimeSeries[n].incH_adunit[i] += (double)StateT[j].cumH_adunit[i]; //added hospitalisation - TimeSeries[n].incCT_adunit[i] += (double)StateT[j].cumCT_adunit[i]; //added contact tracing: ggilani 15/06/17 - TimeSeries[n].incCC_adunit[i] += (double)StateT[j].cumCC_adunit[i]; //added cases who are contacts: ggilani 28/05/2019 - TimeSeries[n].incDCT_adunit[i] += (double)StateT[j].cumDCT_adunit[i]; //added cases who are digitally contact traced: ggilani 11/03/20 + TimeSeries[n].incDC_adunit[i] += + (double)StateT[j].cumDC_adunit[i]; // added detected cases: ggilani 03/02/15 + TimeSeries[n].incH_adunit[i] += (double)StateT[j].cumH_adunit[i]; // added hospitalisation + TimeSeries[n].incCT_adunit[i] += + (double)StateT[j].cumCT_adunit[i]; // added contact tracing: ggilani 15/06/17 + TimeSeries[n].incCC_adunit[i] += + (double)StateT[j].cumCC_adunit[i]; // added cases who are contacts: ggilani 28/05/2019 + TimeSeries[n].incDCT_adunit[i] += + (double)StateT[j] + .cumDCT_adunit[i]; // added cases who are digitally contact traced: ggilani 11/03/20 TimeSeries[n].cumT_adunit[i] += (double)StateT[j].cumT_adunit[i]; State.cumC_adunit[i] += StateT[j].cumC_adunit[i]; State.cumDC_adunit[i] += StateT[j].cumDC_adunit[i]; - StateT[j].cumI_adunit[i] = StateT[j].cumC_adunit[i] = StateT[j].cumH_adunit[i] = StateT[j].cumDC_adunit[i] = StateT[j].cumCT_adunit[i] = StateT[j].cumCC_adunit[i] = StateT[j].cumDCT_adunit[i] = 0; //added hospitalisation, detected cases, contact tracing: ggilani 03/02/15, 15/06/17 + StateT[j].cumI_adunit[i] = StateT[j].cumC_adunit[i] = StateT[j].cumH_adunit[i] = + StateT[j].cumDC_adunit[i] = StateT[j].cumCT_adunit[i] = StateT[j].cumCC_adunit[i] = + StateT[j].cumDCT_adunit[i] = 0; // added hospitalisation, detected cases, contact + // tracing: ggilani 03/02/15, 15/06/17 } if (P.DoICUTriggers) { State.trigDC_adunit[i] += (int)TimeSeries[n].incCritical_adunit[i]; - if (n >= P.TriggersSamplingInterval) State.trigDC_adunit[i] -= (int)TimeSeries[n - P.TriggersSamplingInterval].incCritical_adunit[i]; + if (n >= P.TriggersSamplingInterval) + State.trigDC_adunit[i] -= + (int)TimeSeries[n - P.TriggersSamplingInterval].incCritical_adunit[i]; } else { State.trigDC_adunit[i] += (int)TimeSeries[n].incDC_adunit[i]; - if (n >= P.TriggersSamplingInterval) State.trigDC_adunit[i] -= (int)TimeSeries[n - P.TriggersSamplingInterval].incDC_adunit[i]; + if (n >= P.TriggersSamplingInterval) + State.trigDC_adunit[i] -= (int)TimeSeries[n - P.TriggersSamplingInterval].incDC_adunit[i]; } } if (P.DoDigitalContactTracing) for (int i = 0; i < P.NumAdunits; i++) - TimeSeries[n].DCT_adunit[i] = (double)AdUnits[i].ndct; //added total numbers of contacts currently isolated due to digital contact tracing: ggilani 11/03/20 + TimeSeries[n].DCT_adunit[i] = + (double)AdUnits[i].ndct; // added total numbers of contacts currently isolated due to + // digital contact tracing: ggilani 11/03/20 if (P.DoPlaces) for (int i = 0; i < NUM_PLACE_TYPES; i++) { numPC = 0; for (j = 0; j < P.Nplace[i]; j++) - if (PLACE_CLOSED(i, j)) numPC++; + if (PLACE_CLOSED(i, j)) + numPC++; State.NumPlacesClosed[i] = numPC; TimeSeries[n].PropPlacesClosed[i] = ((double)numPC) / ((double)P.Nplace[i]); } - for (int i = k = 0; i < P.NMC; i++) if (Mcells[i].socdist == 2) k++; - TimeSeries[n].PropSocDist=((double)k)/((double)P.NMC); + for (int i = k = 0; i < P.NMC; i++) + if (Mcells[i].socdist == 2) + k++; + TimeSeries[n].PropSocDist = ((double)k) / ((double)P.NMC); - //update contact number distribution in State - for (int i = 0; i < (MAX_CONTACTS+1); i++) + // update contact number distribution in State + for (int i = 0; i < (MAX_CONTACTS + 1); i++) { for (j = 0; j < P.NumThreads; j++) { @@ -5084,71 +7177,104 @@ void RecordSample(double t, int n) } trigAlertCases = State.cumDC; - if (n >= P.WindowToEvaluateTriggerAlert) trigAlertCases -= (int)TimeSeries[n - P.WindowToEvaluateTriggerAlert].cumDC; + if (n >= P.WindowToEvaluateTriggerAlert) + trigAlertCases -= (int)TimeSeries[n - P.WindowToEvaluateTriggerAlert].cumDC; - if (P.TriggerAlertOnDeaths) //// if using deaths as trigger (as opposed to detected cases) + if (P.TriggerAlertOnDeaths) //// if using deaths as trigger (as opposed to detected cases) { trigAlert = (int)TimeSeries[n].D; - if (n >= P.WindowToEvaluateTriggerAlert) trigAlert -= (int) TimeSeries[n - P.WindowToEvaluateTriggerAlert].D; + if (n >= P.WindowToEvaluateTriggerAlert) + trigAlert -= (int)TimeSeries[n - P.WindowToEvaluateTriggerAlert].D; } - else trigAlert = trigAlertCases; + else + trigAlert = trigAlertCases; double RatioPredictedObserved, DesiredAccuracy; // calibration variables. - if(((!P.DoAlertTriggerAfterInterv) && (trigAlert >= P.CaseOrDeathThresholdBeforeAlert)) || ((P.DoAlertTriggerAfterInterv) && - (((trigAlertCases >= P.CaseOrDeathThresholdBeforeAlert)&&(P.ModelCalibIteration<2)) || ((t>=P.Epidemic_StartDate_CalTime) && (P.ModelCalibIteration >= 2))))) + if (((!P.DoAlertTriggerAfterInterv) && (trigAlert >= P.CaseOrDeathThresholdBeforeAlert)) || + ((P.DoAlertTriggerAfterInterv) && + (((trigAlertCases >= P.CaseOrDeathThresholdBeforeAlert) && (P.ModelCalibIteration < 2)) || + ((t >= P.Epidemic_StartDate_CalTime) && (P.ModelCalibIteration >= 2))))) { - if((!P.StopCalibration)&&(!InterruptRun)) + if ((!P.StopCalibration) && (!InterruptRun)) { - if (P.DateTriggerReached_SimTime == 0) // i.e. if this is first time that calibration has been called for this realisation. + if (P.DateTriggerReached_SimTime == + 0) // i.e. if this is first time that calibration has been called for this realisation. { - P.Epidemic_StartDate_CalTime = P.DateTriggerReached_SimTime = t; // initialize Epidemic_StartDate_CalTime & DateTriggerReached_SimTime to now (i.e. simulation time that trigger was reached) + P.Epidemic_StartDate_CalTime = P.DateTriggerReached_SimTime = + t; // initialize Epidemic_StartDate_CalTime & DateTriggerReached_SimTime to now (i.e. + // simulation time that trigger was reached) if (P.DateTriggerReached_CalTime >= 0) - P.HolidaysStartDay_SimTime = P.DateTriggerReached_SimTime - P.Interventions_StartDate_CalTime; /// initialize holiday offset to time difference between DateTriggerReached_SimTime and day of year interventions start. + P.HolidaysStartDay_SimTime = + P.DateTriggerReached_SimTime - + P.Interventions_StartDate_CalTime; /// initialize holiday offset to time difference + /// between DateTriggerReached_SimTime and day of + /// year interventions start. } - if ((P.DateTriggerReached_CalTime >= 0)&& (!P.DoAlertTriggerAfterInterv)) + if ((P.DateTriggerReached_CalTime >= 0) && (!P.DoAlertTriggerAfterInterv)) { P.StopCalibration = 1; InterruptRun = 1; } - if ((P.DoAlertTriggerAfterInterv) && (t == P.DateTriggerReached_SimTime + P.DateTriggerReached_CalTime - P.Interventions_StartDate_CalTime)) + if ((P.DoAlertTriggerAfterInterv) && + (t == P.DateTriggerReached_SimTime + P.DateTriggerReached_CalTime - + P.Interventions_StartDate_CalTime)) { if ((trigAlert > 0) && (P.ModelCalibIteration < 20)) { - RatioPredictedObserved = ((double)trigAlert)/((double)P.AlertTriggerAfterIntervThreshold); + RatioPredictedObserved = + ((double)trigAlert) / ((double)P.AlertTriggerAfterIntervThreshold); DesiredAccuracy = 1.1 / sqrt((double)P.AlertTriggerAfterIntervThreshold); - if (DesiredAccuracy < 0.05) DesiredAccuracy = 0.05; - fprintf(stderr, "\n** %i %lf %lf | %lg / %lg \t", P.ModelCalibIteration, t, P.DateTriggerReached_SimTime + P.DateTriggerReached_CalTime - P.Interventions_StartDate_CalTime, P.HolidaysStartDay_SimTime,RatioPredictedObserved); - fprintf(stderr, "| %i %i %i %i -> ", trigAlert, trigAlertCases, P.AlertTriggerAfterIntervThreshold, P.CaseOrDeathThresholdBeforeAlert); - if ((P.ModelCalibIteration >= 2) && ((((RatioPredictedObserved - 1.0) <= DesiredAccuracy) && (RatioPredictedObserved >= 1)) || (((1.0 - RatioPredictedObserved) <= DesiredAccuracy) && (RatioPredictedObserved < 1)))) + if (DesiredAccuracy < 0.05) + DesiredAccuracy = 0.05; + fprintf(stderr, "\n** %i %lf %lf | %lg / %lg \t", P.ModelCalibIteration, t, + P.DateTriggerReached_SimTime + P.DateTriggerReached_CalTime - + P.Interventions_StartDate_CalTime, + P.HolidaysStartDay_SimTime, RatioPredictedObserved); + fprintf(stderr, "| %i %i %i %i -> ", trigAlert, trigAlertCases, + P.AlertTriggerAfterIntervThreshold, P.CaseOrDeathThresholdBeforeAlert); + if ((P.ModelCalibIteration >= 2) && + ((((RatioPredictedObserved - 1.0) <= DesiredAccuracy) && + (RatioPredictedObserved >= 1)) || + (((1.0 - RatioPredictedObserved) <= DesiredAccuracy) && + (RatioPredictedObserved < 1)))) P.StopCalibration = 1; else if (P.ModelCalibIteration == 0) { // rescale threshold k = (int)(((double)P.CaseOrDeathThresholdBeforeAlert) / RatioPredictedObserved); - if (k > 0) P.CaseOrDeathThresholdBeforeAlert = k; + if (k > 0) + P.CaseOrDeathThresholdBeforeAlert = k; } - else if ((P.ModelCalibIteration >= 2) && ((P.ModelCalibIteration) % 2 == 0)) // on even iterations, adjust timings + else if ((P.ModelCalibIteration >= 2) && + ((P.ModelCalibIteration) % 2 == 0)) // on even iterations, adjust timings { - if (RatioPredictedObserved > 1) // if too many predicted cases/deaths, make timings earlier... + if (RatioPredictedObserved > + 1) // if too many predicted cases/deaths, make timings earlier... { P.Epidemic_StartDate_CalTime--; P.HolidaysStartDay_SimTime--; } - else if (RatioPredictedObserved < 1) // ... otherwise if too few cases/deaths, make timings later + else if (RatioPredictedObserved < + 1) // ... otherwise if too few cases/deaths, make timings later { P.Epidemic_StartDate_CalTime++; P.HolidaysStartDay_SimTime++; } } - else if ((P.ModelCalibIteration >= 2) && ((P.ModelCalibIteration) % 2 == 1)) // on odd iterations, adjust seeding. - P.SeedingScaling /= pow(RatioPredictedObserved, 0.2 + 0.4 * ranf()); // include random number to prevent loops + else if ((P.ModelCalibIteration >= 2) && + ((P.ModelCalibIteration) % 2 == 1)) // on odd iterations, adjust seeding. + P.SeedingScaling /= pow(RatioPredictedObserved, + 0.2 + 0.4 * ranf()); // include random number to prevent loops P.ModelCalibIteration++; fprintf(stderr, "%i : %lg\n", P.CaseOrDeathThresholdBeforeAlert, P.SeedingScaling); - if(P.StopCalibration) fprintf(stderr, "Calibration ended.\n"); - else InterruptRun = 1; + if (P.StopCalibration) + fprintf(stderr, "Calibration ended.\n"); + else + InterruptRun = 1; } - else P.StopCalibration = 1; + else + P.StopCalibration = 1; } } P.ControlPropCasesId = P.PostAlertControlPropCasesId; @@ -5156,44 +7282,76 @@ void RecordSample(double t, int n) if (P.VaryEfficaciesOverTime) UpdateEfficaciesAndComplianceProportions(t - P.Epidemic_StartDate_CalTime); -// changed to a define for speed (though always likely inlined anyway) and to avoid clang compiler warnings re double alignment -#define DO_OR_DONT_AMEND_START_TIME(X,Y) if(X>=1e10) X=Y; +// changed to a define for speed (though always likely inlined anyway) and to avoid clang compiler +// warnings re double alignment +#define DO_OR_DONT_AMEND_START_TIME(X, Y) \ + if (X >= 1e10) \ + X = Y; //// Set Case isolation start time (by admin unit) for (int i = 0; i < P.NumAdunits; i++) - if (ChooseTriggerVariableAndValue(i) > ChooseThreshold(i, P.CaseIsolation_CellIncThresh)) //// a little wasteful if doing Global trigs as function called more times than necessary, but worth it for much simpler code. Also this function is small portion of runtime. - DO_OR_DONT_AMEND_START_TIME(AdUnits[i].CaseIsolationTimeStart, t + ((P.DoInterventionDelaysByAdUnit)?AdUnits[i].CaseIsolationDelay: P.CaseIsolationTimeStartBase)) + if (ChooseTriggerVariableAndValue(i) > + ChooseThreshold( + i, P.CaseIsolation_CellIncThresh)) //// a little wasteful if doing Global trigs as + /// function called more times than necessary, but + /// worth it for much simpler code. Also this + /// function is small portion of runtime. + DO_OR_DONT_AMEND_START_TIME(AdUnits[i].CaseIsolationTimeStart, + t + ((P.DoInterventionDelaysByAdUnit) + ? AdUnits[i].CaseIsolationDelay + : P.CaseIsolationTimeStartBase)) //// Set Household Quarantine start time (by admin unit) for (int i = 0; i < P.NumAdunits; i++) - if (ChooseTriggerVariableAndValue(i) > ChooseThreshold(i, P.HHQuar_CellIncThresh)) //// a little wasteful if doing Global trigs as function called more times than necessary, but worth it for much simpler code. Also this function is small portion of runtime. - DO_OR_DONT_AMEND_START_TIME(AdUnits[i].HQuarantineTimeStart, t + ((P.DoInterventionDelaysByAdUnit)?AdUnits[i].HQuarantineDelay: P.HQuarantineTimeStartBase)); + if (ChooseTriggerVariableAndValue(i) > + ChooseThreshold(i, + P.HHQuar_CellIncThresh)) //// a little wasteful if doing Global trigs as + /// function called more times than necessary, + /// but worth it for much simpler code. Also this + /// function is small portion of runtime. + DO_OR_DONT_AMEND_START_TIME(AdUnits[i].HQuarantineTimeStart, + t + ((P.DoInterventionDelaysByAdUnit) + ? AdUnits[i].HQuarantineDelay + : P.HQuarantineTimeStartBase)); //// Set DigitalContactTracingTimeStart if (P.DoDigitalContactTracing) for (int i = 0; i < P.NumAdunits; i++) - if (ChooseTriggerVariableAndValue(i) > ChooseThreshold(i, P.DigitalContactTracing_CellIncThresh)) //// a little wasteful if doing Global trigs as function called more times than necessary, but worth it for much simpler code. Also this function is small portion of runtime. - DO_OR_DONT_AMEND_START_TIME(AdUnits[i].DigitalContactTracingTimeStart, t + ((P.DoInterventionDelaysByAdUnit)?AdUnits[i].DCTDelay: P.DigitalContactTracingTimeStartBase)); + if (ChooseTriggerVariableAndValue(i) > + ChooseThreshold( + i, P.DigitalContactTracing_CellIncThresh)) //// a little wasteful if doing Global + /// trigs as function called more times + /// than necessary, but worth it for much + /// simpler code. Also this function is + /// small portion of runtime. + DO_OR_DONT_AMEND_START_TIME(AdUnits[i].DigitalContactTracingTimeStart, + t + ((P.DoInterventionDelaysByAdUnit) + ? AdUnits[i].DCTDelay + : P.DigitalContactTracingTimeStartBase)); if (P.DoGlobalTriggers) { int TriggerValue = ChooseTriggerVariableAndValue(0); if (TriggerValue >= ChooseThreshold(0, P.TreatCellIncThresh)) DO_OR_DONT_AMEND_START_TIME((P.TreatTimeStart), t + P.TreatTimeStartBase); - if (TriggerValue >= P.VaccCellIncThresh) DO_OR_DONT_AMEND_START_TIME(P.VaccTimeStart, t + P.VaccTimeStartBase); + if (TriggerValue >= P.VaccCellIncThresh) + DO_OR_DONT_AMEND_START_TIME(P.VaccTimeStart, t + P.VaccTimeStartBase); if (TriggerValue >= P.SocDistCellIncThresh) { DO_OR_DONT_AMEND_START_TIME(P.SocDistTimeStart, t + P.SocDistTimeStartBase); - //added this for admin unit based intervention delays based on a global trigger: ggilani 17/03/20 + // added this for admin unit based intervention delays based on a global trigger: ggilani + // 17/03/20 if (P.DoInterventionDelaysByAdUnit) for (int i = 0; i < P.NumAdunits; i++) - DO_OR_DONT_AMEND_START_TIME(AdUnits[i].SocialDistanceTimeStart, t + AdUnits[i].SocialDistanceDelay); + DO_OR_DONT_AMEND_START_TIME(AdUnits[i].SocialDistanceTimeStart, + t + AdUnits[i].SocialDistanceDelay); } if (TriggerValue >= P.PlaceCloseCellIncThresh) { DO_OR_DONT_AMEND_START_TIME(P.PlaceCloseTimeStart, t + P.PlaceCloseTimeStartBase); if (P.DoInterventionDelaysByAdUnit) for (int i = 0; i < P.NumAdunits; i++) - DO_OR_DONT_AMEND_START_TIME(AdUnits[i].PlaceCloseTimeStart, t + AdUnits[i].PlaceCloseDelay); + DO_OR_DONT_AMEND_START_TIME(AdUnits[i].PlaceCloseTimeStart, + t + AdUnits[i].PlaceCloseDelay); } if (TriggerValue >= P.MoveRestrCellIncThresh) DO_OR_DONT_AMEND_START_TIME(P.MoveRestrTimeStart, t + P.MoveRestrTimeStartBase); @@ -5202,8 +7360,8 @@ void RecordSample(double t, int n) } else { - DO_OR_DONT_AMEND_START_TIME(P.TreatTimeStart, t + P.TreatTimeStartBase); - DO_OR_DONT_AMEND_START_TIME(P.VaccTimeStart , t + P.VaccTimeStartBase); + DO_OR_DONT_AMEND_START_TIME(P.TreatTimeStart, t + P.TreatTimeStartBase); + DO_OR_DONT_AMEND_START_TIME(P.VaccTimeStart, t + P.VaccTimeStartBase); DO_OR_DONT_AMEND_START_TIME(P.SocDistTimeStart, t + P.SocDistTimeStartBase); DO_OR_DONT_AMEND_START_TIME(P.PlaceCloseTimeStart, t + P.PlaceCloseTimeStartBase); DO_OR_DONT_AMEND_START_TIME(P.MoveRestrTimeStart, t + P.MoveRestrTimeStartBase); @@ -5227,18 +7385,27 @@ void RecordSample(double t, int n) P.EnhancedSocDistPlaceEffectCurrent[i] = P.EnhancedSocDistPlaceEffect2[i]; } } - //fix to switch off first place closure after P.PlaceCloseDuration has elapsed, if there are no school or cell-based triggers set + // fix to switch off first place closure after P.PlaceCloseDuration has elapsed, if there are no + // school or cell-based triggers set if (t == P.PlaceCloseTimeStart + P.PlaceCloseDuration) { P.PlaceCloseTimeStartPrevious = P.PlaceCloseTimeStart; - if ((P.PlaceCloseIncTrig == 0) && (P.PlaceCloseFracIncTrig == 0) && (P.PlaceCloseCellIncThresh == 0)) P.PlaceCloseTimeStart = 9e9; + if ((P.PlaceCloseIncTrig == 0) && (P.PlaceCloseFracIncTrig == 0) && + (P.PlaceCloseCellIncThresh == 0)) + P.PlaceCloseTimeStart = 9e9; } if (!P.VaryEfficaciesOverTime) { - if ((P.PlaceCloseTimeStart2 > P.PlaceCloseTimeStartPrevious) && //// if second place closure start time after previous start time AND - (t >= P.PlaceCloseTimeStartPrevious + P.PlaceCloseDuration) && //// if now after previous place closure period has finished AND - (t >= P.PlaceCloseTimeStartPrevious + P.PlaceCloseTimeStartBase2 - P.PlaceCloseTimeStartBase)) //// if now after previous start time + plus difference between 1st and 2nd base start times + if ((P.PlaceCloseTimeStart2 > + P.PlaceCloseTimeStartPrevious) && //// if second place closure start time after previous + /// start time AND + (t >= P.PlaceCloseTimeStartPrevious + + P.PlaceCloseDuration) && //// if now after previous place + /// closure period has finished AND + (t >= P.PlaceCloseTimeStartPrevious + P.PlaceCloseTimeStartBase2 - + P.PlaceCloseTimeStartBase)) //// if now after previous start time + plus + /// difference between 1st and 2nd base start times { fprintf(stderr, "\nSecond place closure period (t=%lg)\n", t); P.PlaceCloseTimeStartPrevious = P.PlaceCloseTimeStart2 = P.PlaceCloseTimeStart = t; @@ -5250,25 +7417,30 @@ void RecordSample(double t, int n) if (P.OutputBitmap >= 1) { - TSMean = TSMeanNE; TSVar = TSVarNE; - CaptureBitmap (); - OutputBitmap (0); + TSMean = TSMeanNE; + TSVar = TSVarNE; + CaptureBitmap(); + OutputBitmap(0); } } void RecordInfTypes(void) { int i, j, k, l, lc, lc2, b, c, n, nf, i2; - double* res, * res_av, * res_var, t, s; + double *res, *res_av, *res_var, t, s; for (n = 0; n < P.NumSamples; n++) { - for (i = 0; i < INFECT_TYPE_MASK; i++) TimeSeries[n].Rtype[i] = 0; - for (i = 0; i < NUM_AGE_GROUPS; i++) TimeSeries[n].Rage[i] = 0; + for (i = 0; i < INFECT_TYPE_MASK; i++) + TimeSeries[n].Rtype[i] = 0; + for (i = 0; i < NUM_AGE_GROUPS; i++) + TimeSeries[n].Rage[i] = 0; TimeSeries[n].Rdenom = 0; } - for (i = 0; i < INFECT_TYPE_MASK; i++) inftype[i] = 0; - for (i = 0; i < MAX_COUNTRIES; i++) infcountry[i] = 0; + for (i = 0; i < INFECT_TYPE_MASK; i++) + inftype[i] = 0; + for (i = 0; i < MAX_COUNTRIES; i++) + infcountry[i] = 0; for (i = 0; i < MAX_SEC_REC; i++) for (j = 0; j < MAX_GEN_REC; j++) indivR0[i][j] = 0; @@ -5282,12 +7454,14 @@ void RecordInfTypes(void) // for(b=0;b0)) { - j = k = l = lc = lc2 = 0; t = 1e10; + j = k = l = lc = lc2 = 0; + t = 1e10; // for(c=0;c= 0) l++; - if ((l >= 0) && ((Hosts[i].inf == InfStat_RecoveredFromSymp) || (Hosts[i].inf == InfStat_Dead_WasSymp))) + if ((l >= 0) && + ((Hosts[i].inf == InfStat_RecoveredFromSymp) || (Hosts[i].inf == InfStat_Dead_WasSymp))) { lc2++; - if (Hosts[i].latent_time * P.TimeStep <= t) // This convoluted logic is to pick up households where the index is symptomatic + if (Hosts[i].latent_time * P.TimeStep <= + t) // This convoluted logic is to pick up households where the index is symptomatic { - lc = 1; t = Hosts[i].latent_time * P.TimeStep; + lc = 1; + t = Hosts[i].latent_time * P.TimeStep; } } else if ((l > 0) && (Hosts[i].latent_time * P.TimeStep < t)) { - lc = 0; t = Hosts[i].latent_time * P.TimeStep; + lc = 0; + t = Hosts[i].latent_time * P.TimeStep; } i2 = Hosts[i].infector; if (i2 >= 0) @@ -5315,8 +7493,10 @@ void RecordInfTypes(void) Hosts[i2].listpos++; if (Hosts[i2].latent_time * P.TimeStep <= P.SampleTime) { - TimeSeries[(int)(Hosts[i2].latent_time * P.TimeStep / P.SampleStep)].Rtype[Hosts[i].infect_type % INFECT_TYPE_MASK]++; - TimeSeries[(int)(Hosts[i2].latent_time * P.TimeStep / P.SampleStep)].Rage[HOST_AGE_GROUP(i)]++; + TimeSeries[(int)(Hosts[i2].latent_time * P.TimeStep / P.SampleStep)] + .Rtype[Hosts[i].infect_type % INFECT_TYPE_MASK]++; + TimeSeries[(int)(Hosts[i2].latent_time * P.TimeStep / P.SampleStep)] + .Rage[HOST_AGE_GROUP(i)]++; } } } @@ -5324,10 +7504,13 @@ void RecordInfTypes(void) j--; if (j == 0) { - if (l < 0) l = 0; + if (l < 0) + l = 0; inf_household[k][l]++; - case_household[k][lc2]++; //now recording total symptomatic cases, rather than infections conditional on symptomatic index - l = lc = lc2 = 0; t = 1e10; + case_household[k][lc2]++; // now recording total symptomatic cases, rather than infections + // conditional on symptomatic index + l = lc = lc2 = 0; + t = 1e10; } } } @@ -5339,16 +7522,19 @@ void RecordInfTypes(void) if ((abs(Hosts[i].inf) == InfStat_Recovered) || (abs(Hosts[i].inf) == InfStat_Dead)) { l = Hosts[i].infect_type / INFECT_TYPE_MASK; - if ((l < MAX_GEN_REC) && (Hosts[i].listpos < MAX_SEC_REC)) indivR0[Hosts[i].listpos][l]++; + if ((l < MAX_GEN_REC) && (Hosts[i].listpos < MAX_SEC_REC)) + indivR0[Hosts[i].listpos][l]++; } } /* if(!TimeSeries[P.NumSamples-1].extinct) */ { - for (i = 0; i < INFECT_TYPE_MASK; i++) inftype_av[i] += inftype[i]; + for (i = 0; i < INFECT_TYPE_MASK; i++) + inftype_av[i] += inftype[i]; for (i = 0; i < MAX_COUNTRIES; i++) { infcountry_av[i] += infcountry[i]; - if (infcountry[i] > 0) infcountry_num[i]++; + if (infcountry[i] > 0) + infcountry_num[i]++; } for (i = 0; i < MAX_SEC_REC; i++) for (j = 0; j < MAX_GEN_REC; j++) @@ -5360,12 +7546,15 @@ void RecordInfTypes(void) case_household_av[i][j] += case_household[i][j]; } } - k = (P.Interventions_StartDate_CalTime > 0) ? ((int)(P.Interventions_StartDate_CalTime - P.DateTriggerReached_SimTime)) : 0; + k = (P.Interventions_StartDate_CalTime > 0) + ? ((int)(P.Interventions_StartDate_CalTime - P.DateTriggerReached_SimTime)) + : 0; for (n = 0; n < P.NumSamples; n++) { TimeSeries[n].t += k; s = 0; - if (TimeSeries[n].Rdenom == 0) TimeSeries[n].Rdenom = 1e-10; + if (TimeSeries[n].Rdenom == 0) + TimeSeries[n].Rdenom = 1e-10; for (i = 0; i < NUM_AGE_GROUPS; i++) TimeSeries[n].Rage[i] /= TimeSeries[n].Rdenom; for (i = 0; i < INFECT_TYPE_MASK; i++) @@ -5373,15 +7562,21 @@ void RecordInfTypes(void) TimeSeries[n].Rdenom = s; } nf = sizeof(Results) / sizeof(double); - if (!P.DoAdUnits) nf -= MAX_ADUNITS; // TODO: This still processes most of the AdUnit arrays; just not the last one - fprintf(stderr, "extinct=%i (%i)\n", (int) TimeSeries[P.NumSamples - 1].extinct, P.NumSamples - 1); + if (!P.DoAdUnits) + nf -= + MAX_ADUNITS; // TODO: This still processes most of the AdUnit arrays; just not the last one + fprintf(stderr, "extinct=%i (%i)\n", (int)TimeSeries[P.NumSamples - 1].extinct, P.NumSamples - 1); if (TimeSeries[P.NumSamples - 1].extinct) { - TSMean = TSMeanE; TSVar = TSVarE; P.NRactE++; + TSMean = TSMeanE; + TSVar = TSVarE; + P.NRactE++; } else { - TSMean = TSMeanNE; TSVar = TSVarNE; P.NRactNE++; + TSMean = TSMeanNE; + TSVar = TSVarNE; + P.NRactNE++; } lc = -k; @@ -5390,10 +7585,14 @@ void RecordInfTypes(void) { if ((n + lc >= 0) && (n + lc < P.NumSamples)) { - if (s < TimeSeries[n + lc].incC) { s = TimeSeries[n + lc].incC; t = P.SampleStep * ((double)(n + lc)); } - res = (double*)&TimeSeries[n + lc]; - res_av = (double*)&TSMean[n]; - res_var = (double*)&TSVar[n]; + if (s < TimeSeries[n + lc].incC) + { + s = TimeSeries[n + lc].incC; + t = P.SampleStep * ((double)(n + lc)); + } + res = (double *)&TimeSeries[n + lc]; + res_av = (double *)&TSMean[n]; + res_var = (double *)&TSVar[n]; for (std::size_t i = ResultsDoubleOffsetStart /* skip over initial fields */; i < nf; i++) { res_av[i] += res[i]; @@ -5403,15 +7602,20 @@ void RecordInfTypes(void) for (std::size_t age = 0; age < NUM_AGE_GROUPS; ++age) for (std::size_t adunit = 0; adunit < P.NumAdunits; ++adunit) { - TSMean[n].prevInf_age_adunit[age][adunit] = TimeSeries[n + lc].prevInf_age_adunit[age][adunit]; - TSMean[n].cumInf_age_adunit [age][adunit] = TimeSeries[n + lc].cumInf_age_adunit [age][adunit]; - TSMean[n].incInf_age_adunit [age][adunit] = TimeSeries[n + lc].incInf_age_adunit [age][adunit]; + TSMean[n].prevInf_age_adunit[age][adunit] = + TimeSeries[n + lc].prevInf_age_adunit[age][adunit]; + TSMean[n].cumInf_age_adunit[age][adunit] = + TimeSeries[n + lc].cumInf_age_adunit[age][adunit]; + TSMean[n].incInf_age_adunit[age][adunit] = + TimeSeries[n + lc].incInf_age_adunit[age][adunit]; } - if (TSMean[n].cumTmax < TimeSeries[n + lc].cumT) TSMean[n].cumTmax = TimeSeries[n + lc].cumT; - if (TSMean[n].cumVmax < TimeSeries[n + lc].cumV) TSMean[n].cumVmax = TimeSeries[n + lc].cumV; + if (TSMean[n].cumTmax < TimeSeries[n + lc].cumT) + TSMean[n].cumTmax = TimeSeries[n + lc].cumT; + if (TSMean[n].cumVmax < TimeSeries[n + lc].cumV) + TSMean[n].cumVmax = TimeSeries[n + lc].cumV; } - TSMean[n].t += ((double) n )* P.SampleStep; + TSMean[n].t += ((double)n) * P.SampleStep; } PeakHeightSum += s; PeakHeightSS += s * s; @@ -5419,7 +7623,6 @@ void RecordInfTypes(void) PeakTimeSS += t * t; } - void CalcOriginDestMatrix_adunit() { /** function: CalcOriginDestMatrix_adunit() @@ -5433,44 +7636,46 @@ void CalcOriginDestMatrix_adunit() * author: ggilani, date: 28/01/15 */ -#pragma omp parallel for schedule(static) default(none) \ - shared(P, Cells, CellLookup, Mcells, StateT) +#pragma omp parallel for schedule(static) default(none) shared(P, Cells, CellLookup, Mcells, StateT) for (int tn = 0; tn < P.NumThreads; tn++) { for (int i = tn; i < P.NCP; i += P.NumThreads) { - //reset pop density matrix to zero + // reset pop density matrix to zero double pop_dens_from[MAX_ADUNITS] = {}; - //find index of cell from which flow travels + // find index of cell from which flow travels ptrdiff_t cl_from = CellLookup[i] - Cells; - ptrdiff_t cl_from_mcl = (cl_from / P.nch) * P.NMCL * P.get_number_of_micro_cells_high() + (cl_from % P.nch) * P.NMCL; + ptrdiff_t cl_from_mcl = (cl_from / P.nch) * P.NMCL * P.get_number_of_micro_cells_high() + + (cl_from % P.nch) * P.NMCL; - //loop over microcells in these cells to find populations in each admin unit and so flows + // loop over microcells in these cells to find populations in each admin unit and so flows for (int k = 0; k < P.NMCL; k++) { for (int l = 0; l < P.NMCL; l++) { - //get index of microcell + // get index of microcell ptrdiff_t mcl_from = cl_from_mcl + l + k * P.get_number_of_micro_cells_high(); if (Mcells[mcl_from].n > 0) { - //get proportion of each population of cell that exists in each admin unit - pop_dens_from[Mcells[mcl_from].adunit] += (((double)Mcells[mcl_from].n) / ((double)Cells[cl_from].n)); + // get proportion of each population of cell that exists in each admin unit + pop_dens_from[Mcells[mcl_from].adunit] += + (((double)Mcells[mcl_from].n) / ((double)Cells[cl_from].n)); } } } for (int j = i; j < P.NCP; j++) { - //reset pop density matrix to zero + // reset pop density matrix to zero double pop_dens_to[MAX_ADUNITS] = {}; - //find index of cell which flow travels to + // find index of cell which flow travels to ptrdiff_t cl_to = CellLookup[j] - Cells; - ptrdiff_t cl_to_mcl = (cl_to / P.nch) * P.NMCL * P.get_number_of_micro_cells_high() + (cl_to % P.nch) * P.NMCL; - //calculate distance and kernel between the cells - //total_flow=Cells[cl_from].max_trans[j]*Cells[cl_from].n*Cells[cl_to].n; + ptrdiff_t cl_to_mcl = (cl_to / P.nch) * P.NMCL * P.get_number_of_micro_cells_high() + + (cl_to % P.nch) * P.NMCL; + // calculate distance and kernel between the cells + // total_flow=Cells[cl_from].max_trans[j]*Cells[cl_from].n*Cells[cl_to].n; double total_flow; if (j == 0) { @@ -5478,20 +7683,22 @@ void CalcOriginDestMatrix_adunit() } else { - total_flow = (Cells[cl_from].cum_trans[j] - Cells[cl_from].cum_trans[j - 1]) * Cells[cl_from].n; + total_flow = + (Cells[cl_from].cum_trans[j] - Cells[cl_from].cum_trans[j - 1]) * Cells[cl_from].n; } - //loop over microcells within destination cell + // loop over microcells within destination cell for (int m = 0; m < P.NMCL; m++) { for (int p = 0; p < P.NMCL; p++) { - //get index of microcell + // get index of microcell ptrdiff_t mcl_to = cl_to_mcl + p + m * P.get_number_of_micro_cells_high(); if (Mcells[mcl_to].n > 0) { - //get proportion of each population of cell that exists in each admin unit - pop_dens_to[Mcells[mcl_to].adunit] += (((double)Mcells[mcl_to].n) / ((double)Cells[cl_to].n)); + // get proportion of each population of cell that exists in each admin unit + pop_dens_to[Mcells[mcl_to].adunit] += + (((double)Mcells[mcl_to].n) / ((double)Cells[cl_to].n)); } } } @@ -5502,7 +7709,9 @@ void CalcOriginDestMatrix_adunit() { if (m != p) { - double flow = total_flow * pop_dens_from[m] * pop_dens_to[p]; //updated to remove reference to cross-border flows: ggilani 26/03/20 + double flow = total_flow * pop_dens_from[m] * + pop_dens_to[p]; // updated to remove reference to cross-border flows: + // ggilani 26/03/20 StateT[tn].origin_dest[m][p] += flow; StateT[tn].origin_dest[p][m] += flow; } @@ -5512,7 +7721,7 @@ void CalcOriginDestMatrix_adunit() } } - //Sum up flow between adunits across threads + // Sum up flow between adunits across threads for (int i = 0; i < P.NumAdunits; i++) { for (int j = 0; j < P.NumAdunits; j++) @@ -5526,59 +7735,76 @@ void CalcOriginDestMatrix_adunit() } //// Get parameters code (called by ReadParams function) -int GetInputParameter(FILE* dat, FILE* dat2, const char* SItemName, const char* ItemType, void* ItemPtr, int NumItem, int NumItem2, int Offset) +int GetInputParameter(FILE *dat, FILE *dat2, const char *SItemName, const char *ItemType, + void *ItemPtr, int NumItem, int NumItem2, int Offset) { int FindFlag; FindFlag = GetInputParameter2(dat, dat2, SItemName, ItemType, ItemPtr, NumItem, NumItem2, Offset); if (!FindFlag) { - ERR_CRITICAL_FMT("\nUnable to find parameter `%s' in input file. Aborting program...\n", SItemName); + ERR_CRITICAL_FMT("\nUnable to find parameter `%s' in input file. Aborting program...\n", + SItemName); } return FindFlag; } -int GetInputParameter2(FILE* dat, FILE* dat2, const char* SItemName, const char* ItemType, void* ItemPtr, int NumItem, int NumItem2, int Offset) +int GetInputParameter2(FILE *dat, FILE *dat2, const char *SItemName, const char *ItemType, + void *ItemPtr, int NumItem, int NumItem2, int Offset) { int FindFlag = 0; - if (dat2) FindFlag = GetInputParameter3(dat2, SItemName, ItemType, ItemPtr, NumItem, NumItem2, Offset); + if (dat2) + FindFlag = GetInputParameter3(dat2, SItemName, ItemType, ItemPtr, NumItem, NumItem2, Offset); if (!FindFlag) FindFlag = GetInputParameter3(dat, SItemName, ItemType, ItemPtr, NumItem, NumItem2, Offset); return FindFlag; } -int GetInputParameter2all(FILE* dat, FILE* dat2, FILE* dat3, const char* SItemName, const char* ItemType, void* ItemPtr, int NumItem, int NumItem2, int Offset) +int GetInputParameter2all(FILE *dat, FILE *dat2, FILE *dat3, const char *SItemName, + const char *ItemType, void *ItemPtr, int NumItem, int NumItem2, + int Offset) { int FindFlag = 0; - if (dat3) FindFlag = GetInputParameter3(dat3, SItemName, ItemType, ItemPtr, NumItem, NumItem2, Offset); + if (dat3) + FindFlag = GetInputParameter3(dat3, SItemName, ItemType, ItemPtr, NumItem, NumItem2, Offset); if (!FindFlag) { - if (dat2) FindFlag = GetInputParameter3(dat2, SItemName, ItemType, ItemPtr, NumItem, NumItem2, Offset); - if ((!FindFlag)&&(dat)) + if (dat2) + FindFlag = GetInputParameter3(dat2, SItemName, ItemType, ItemPtr, NumItem, NumItem2, Offset); + if ((!FindFlag) && (dat)) FindFlag = GetInputParameter3(dat, SItemName, ItemType, ItemPtr, NumItem, NumItem2, Offset); } return FindFlag; } /* - Reads a string (as per fscanf %s). - Returns true if it succeeds, false on EOF, and does not return on error. + Reads a string (as per fscanf %s). + Returns true if it succeeds, false on EOF, and does not return on error. */ -bool readString(const char* SItemName, FILE* dat, char *buf) { - int r = fscanf(dat, "%s", buf); - if(r == 1) { - return true; - } else if (r == EOF) { - if(ferror(dat)) { - ERR_CRITICAL_FMT("fscanf failed for %s: %s.\n", SItemName, strerror(errno)); - } else { - // EOF - return false; - } - } else { - ERR_CRITICAL_FMT("Unexpected fscanf result %d for %s.\n", r, SItemName); - } +bool readString(const char *SItemName, FILE *dat, char *buf) +{ + int r = fscanf(dat, "%s", buf); + if (r == 1) + { + return true; + } + else if (r == EOF) + { + if (ferror(dat)) + { + ERR_CRITICAL_FMT("fscanf failed for %s: %s.\n", SItemName, strerror(errno)); + } + else + { + // EOF + return false; + } + } + else + { + ERR_CRITICAL_FMT("Unexpected fscanf result %d for %s.\n", r, SItemName); + } } // #define to map *nix strncasecmp to windows equivalent @@ -5586,7 +7812,8 @@ bool readString(const char* SItemName, FILE* dat, char *buf) { #define strncasecmp _strnicmp #endif -int GetInputParameter3(FILE* dat, const char* SItemName, const char* ItemType, void* ItemPtr, int NumItem, int NumItem2, int Offset) +int GetInputParameter3(FILE *dat, const char *SItemName, const char *ItemType, void *ItemPtr, + int NumItem, int NumItem2, int Offset) { char match[10000] = "", ReadItemName[10000] = "", ItemName[10000]; int FindFlag = 0, EndString, CurPos, i, j, n; @@ -5596,7 +7823,8 @@ int GetInputParameter3(FILE* dat, const char* SItemName, const char* ItemType, v sprintf(ItemName, "[%s]", SItemName); while (!FindFlag) { - if(!readString(SItemName, dat, match)) return 0; + if (!readString(SItemName, dat, match)) + return 0; FindFlag = (!strncasecmp(match, ItemName, strlen(match))); if (FindFlag) { @@ -5605,7 +7833,8 @@ int GetInputParameter3(FILE* dat, const char* SItemName, const char* ItemType, v EndString = (match[strlen(match) - 1] == ']'); while ((!EndString) && (FindFlag)) { - if(!readString(SItemName, dat, match)) return 0; + if (!readString(SItemName, dat, match)) + return 0; strcat(ReadItemName, " "); strcat(ReadItemName, match); FindFlag = (!strncmp(ReadItemName, ItemName, strlen(ReadItemName))); @@ -5621,99 +7850,108 @@ int GetInputParameter3(FILE* dat, const char* SItemName, const char* ItemType, v if (FindFlag) { FindFlag = 0; - if (!strcmp(ItemType, "%lf")) n = 1; - else if (!strcmp(ItemType, "%i")) n = 2; - else if (!strcmp(ItemType, "%s")) n = 3; + if (!strcmp(ItemType, "%lf")) + n = 1; + else if (!strcmp(ItemType, "%i")) + n = 2; + else if (!strcmp(ItemType, "%s")) + n = 3; if (NumItem2 < 2) { if (NumItem == 1) { - if(fscanf(dat, "%s", match) != 1) { ERR_CRITICAL_FMT("fscanf failed for %s\n", SItemName); } + if (fscanf(dat, "%s", match) != 1) + { + ERR_CRITICAL_FMT("fscanf failed for %s\n", SItemName); + } if ((match[0] == '#') && (match[1] == '1')) { FindFlag++; if (n == 1) - * ((double*)ItemPtr) = P.clP1; + *((double *)ItemPtr) = P.clP1; else if (n == 2) - * ((int*)ItemPtr) = (int)P.clP1; + *((int *)ItemPtr) = (int)P.clP1; else if (n == 3) - sscanf(match, "%s", (char*)ItemPtr); + sscanf(match, "%s", (char *)ItemPtr); } else if ((match[0] == '#') && (match[1] == '2')) { FindFlag++; if (n == 1) - * ((double*)ItemPtr) = P.clP2; + *((double *)ItemPtr) = P.clP2; else if (n == 2) - * ((int*)ItemPtr) = (int)P.clP2; + *((int *)ItemPtr) = (int)P.clP2; else if (n == 3) - sscanf(match, "%s", (char*)ItemPtr); + sscanf(match, "%s", (char *)ItemPtr); } - else if((match[0] == '#') && (match[1] == '3')) - { + else if ((match[0] == '#') && (match[1] == '3')) + { FindFlag++; - if(n == 1) - * ((double*)ItemPtr) = P.clP3; - else if(n == 2) - * ((int*)ItemPtr) = (int)P.clP3; - else if(n == 3) - sscanf(match, "%s", (char*)ItemPtr); - } - else if((match[0] == '#') && (match[1] == '4')) - { + if (n == 1) + *((double *)ItemPtr) = P.clP3; + else if (n == 2) + *((int *)ItemPtr) = (int)P.clP3; + else if (n == 3) + sscanf(match, "%s", (char *)ItemPtr); + } + else if ((match[0] == '#') && (match[1] == '4')) + { FindFlag++; - if(n == 1) - * ((double*)ItemPtr) = P.clP4; - else if(n == 2) - * ((int*)ItemPtr) = (int)P.clP4; - else if(n == 3) - sscanf(match, "%s", (char*)ItemPtr); - } - else if((match[0] == '#') && (match[1] == '5')) - { + if (n == 1) + *((double *)ItemPtr) = P.clP4; + else if (n == 2) + *((int *)ItemPtr) = (int)P.clP4; + else if (n == 3) + sscanf(match, "%s", (char *)ItemPtr); + } + else if ((match[0] == '#') && (match[1] == '5')) + { FindFlag++; - if(n == 1) - * ((double*)ItemPtr) = P.clP5; - else if(n == 2) - * ((int*)ItemPtr) = (int)P.clP5; - else if(n == 3) - sscanf(match, "%s", (char*)ItemPtr); - } - else if((match[0] == '#') && (match[1] == '6')) - { + if (n == 1) + *((double *)ItemPtr) = P.clP5; + else if (n == 2) + *((int *)ItemPtr) = (int)P.clP5; + else if (n == 3) + sscanf(match, "%s", (char *)ItemPtr); + } + else if ((match[0] == '#') && (match[1] == '6')) + { FindFlag++; - if(n == 1) - * ((double*)ItemPtr) = P.clP6; - else if(n == 2) - * ((int*)ItemPtr) = (int)P.clP6; - else if(n == 3) - sscanf(match, "%s", (char*)ItemPtr); - } + if (n == 1) + *((double *)ItemPtr) = P.clP6; + else if (n == 2) + *((int *)ItemPtr) = (int)P.clP6; + else if (n == 3) + sscanf(match, "%s", (char *)ItemPtr); + } else if ((match[0] != '[') && (!feof(dat))) { FindFlag++; if (n == 1) - sscanf(match, "%lf", (double*)ItemPtr); + sscanf(match, "%lf", (double *)ItemPtr); else if (n == 2) - sscanf(match, "%i", (int*)ItemPtr); + sscanf(match, "%i", (int *)ItemPtr); else if (n == 3) - sscanf(match, "%s", (char*)ItemPtr); + sscanf(match, "%s", (char *)ItemPtr); } } else { for (CurPos = 0; CurPos < NumItem; CurPos++) { - if(fscanf(dat, "%s", match) != 1) { ERR_CRITICAL_FMT("fscanf failed for %s\n", SItemName); } + if (fscanf(dat, "%s", match) != 1) + { + ERR_CRITICAL_FMT("fscanf failed for %s\n", SItemName); + } if ((match[0] != '[') && (!feof(dat))) { FindFlag++; if (n == 1) - sscanf(match, "%lf", ((double*)ItemPtr) + CurPos + Offset); + sscanf(match, "%lf", ((double *)ItemPtr) + CurPos + Offset); else if (n == 2) - sscanf(match, "%i", ((int*)ItemPtr) + CurPos + Offset); + sscanf(match, "%i", ((int *)ItemPtr) + CurPos + Offset); else if (n == 3) - sscanf(match, "%s", *(((char**)ItemPtr) + CurPos + Offset)); + sscanf(match, "%s", *(((char **)ItemPtr) + CurPos + Offset)); } else CurPos = NumItem; @@ -5723,17 +7961,23 @@ int GetInputParameter3(FILE* dat, const char* SItemName, const char* ItemType, v else { for (j = 0; j < NumItem; j++) - { //added these braces + { // added these braces for (i = 0; i < NumItem2; i++) { - if(fscanf(dat, "%s", match) != 1) { ERR_CRITICAL_FMT("fscanf failed for %s\n", SItemName); } + if (fscanf(dat, "%s", match) != 1) + { + ERR_CRITICAL_FMT("fscanf failed for %s\n", SItemName); + } if ((match[0] != '[') && (!feof(dat))) { FindFlag++; if (n == 1) - sscanf(match, "%lf", ((double**)ItemPtr)[j + Offset] + i + Offset); //changed from [j+Offset]+i+Offset to +j+Offset+i, as ItemPtr isn't an array - 01/10: changed it back + sscanf(match, "%lf", + ((double **)ItemPtr)[j + Offset] + i + + Offset); // changed from [j+Offset]+i+Offset to +j+Offset+i, as ItemPtr + // isn't an array - 01/10: changed it back else - sscanf(match, "%i", ((int**)ItemPtr)[j + Offset] + i + Offset); + sscanf(match, "%i", ((int **)ItemPtr)[j + Offset] + i + Offset); } else { @@ -5741,8 +7985,9 @@ int GetInputParameter3(FILE* dat, const char* SItemName, const char* ItemType, v j = NumItem; } } - //Offset=Offset+(NumItem2-1); //added this line to get the correct offset in address position when incrementing j - } //added these braces + // Offset=Offset+(NumItem2-1); //added this line to get the correct offset in address + // position when incrementing j + } // added these braces } } // fprintf(stderr,"%s\n",SItemName); @@ -5750,13 +7995,9 @@ int GetInputParameter3(FILE* dat, const char* SItemName, const char* ItemType, v } /* helper function to set icdf arrays */ -void SetICDF(double* icdf, double startValue) +void SetICDF(double *icdf, double startValue) { icdf[CDF_RES] = startValue; for (int i = 0; i < CDF_RES; i++) icdf[i] = -log(1 - ((double)i) / CDF_RES); } - - - - diff --git a/src/CovidSim.h b/src/CovidSim.h index 9be937a80..74347fd22 100644 --- a/src/CovidSim.h +++ b/src/CovidSim.h @@ -7,22 +7,22 @@ // not found. The following should include the lib file only on Clang. #ifdef _WIN32 - #ifdef __clang__ +#ifdef __clang__ #pragma comment(lib, "libomp.lib") - #endif +#endif #endif #include +#include #include #include -#include #include -#include #include +#include #include -#include "Country.h" #include "Constants.h" +#include "Country.h" #endif // COVIDSIM_COVIDSIM_H_INCLUDED_ diff --git a/src/Direction.cpp b/src/Direction.cpp index 52fbaf6ad..addb1f5eb 100644 --- a/src/Direction.cpp +++ b/src/Direction.cpp @@ -1,12 +1,18 @@ #include "Direction.hpp" #include -Direction rotate_left(Direction direction) { - switch (direction) { - case Right: return Up; - case Up: return Left; - case Left: return Down; - case Down: return Right; +Direction rotate_left(Direction direction) +{ + switch (direction) + { + case Right: + return Up; + case Up: + return Left; + case Left: + return Down; + case Down: + return Right; } throw std::out_of_range("direction"); } diff --git a/src/Direction.hpp b/src/Direction.hpp index 82fad2443..23291cbf8 100644 --- a/src/Direction.hpp +++ b/src/Direction.hpp @@ -1,10 +1,11 @@ #pragma once -enum Direction { +enum Direction +{ Right = 0, - Up = 1, - Left = 2, - Down = 3 + Up = 1, + Left = 2, + Down = 3 }; Direction rotate_left(Direction direction); \ No newline at end of file diff --git a/src/Dist.cpp b/src/Dist.cpp index 1c27fb340..723cdcfc8 100644 --- a/src/Dist.cpp +++ b/src/Dist.cpp @@ -1,5 +1,5 @@ -#include #include +#include #include "Constants.h" #include "Dist.h" @@ -9,15 +9,20 @@ double sinx[361], cosx[361], asin2sqx[1001]; -//// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** -//// **** DISTANCE FUNCTIONS (return distance-squared, which is input for every Kernel function) -//// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** +//// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** +/////// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** / **** DISTANCE +/// FUNCTIONS (return distance-squared, which is input for every Kernel function) / **** //// **** +/////// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// +///**** //// **** //// **** //// **** //// **** //// **** //// **** -double periodic_xy(double x, double y) { +double periodic_xy(double x, double y) +{ if (P.DoPeriodicBoundaries) { - if (x > P.in_degrees_.width * 0.5) x = P.in_degrees_.width - x; - if (y > P.in_degrees_.height * 0.5) y = P.in_degrees_.height - y; + if (x > P.in_degrees_.width * 0.5) + x = P.in_degrees_.width - x; + if (y > P.in_degrees_.height * 0.5) + y = P.in_degrees_.height - y; } return x * x + y * y; } @@ -48,12 +53,13 @@ double dist2UTM(double x1, double y1, double x2, double y2) y = (1 - x) * asin2sqx[((int)xi)] + x * asin2sqx[((int)xi) + 1]; return 4 * EARTHRADIUS * EARTHRADIUS * y; } -double dist2(Person* a, Person* b) +double dist2(Person *a, Person *b) { double x, y; if (P.DoUTM_coords) - return dist2UTM(Households[a->hh].loc.x, Households[a->hh].loc.y, Households[b->hh].loc.x, Households[b->hh].loc.y); + return dist2UTM(Households[a->hh].loc.x, Households[a->hh].loc.y, Households[b->hh].loc.x, + Households[b->hh].loc.y); else { x = fabs(Households[a->hh].loc.x - Households[b->hh].loc.x); @@ -61,7 +67,7 @@ double dist2(Person* a, Person* b) return periodic_xy(x, y); } } -double dist2_cc(Cell* a, Cell* b) +double dist2_cc(Cell *a, Cell *b) { double x, y; int l, m; @@ -69,8 +75,10 @@ double dist2_cc(Cell* a, Cell* b) l = (int)(a - Cells); m = (int)(b - Cells); if (P.DoUTM_coords) - return dist2UTM(P.in_cells_.width * fabs((double)(l / P.nch)), P.in_cells_.height * fabs((double)(l % P.nch)), - P.in_cells_.width * fabs((double)(m / P.nch)), P.in_cells_.height * fabs((double)(m % P.nch))); + return dist2UTM(P.in_cells_.width * fabs((double)(l / P.nch)), + P.in_cells_.height * fabs((double)(l % P.nch)), + P.in_cells_.width * fabs((double)(m / P.nch)), + P.in_cells_.height * fabs((double)(m % P.nch))); else { x = P.in_cells_.width * fabs((double)(l / P.nch - m / P.nch)); @@ -78,14 +86,15 @@ double dist2_cc(Cell* a, Cell* b) return periodic_xy(x, y); } } -double dist2_cc_min(Cell* a, Cell* b) +double dist2_cc_min(Cell *a, Cell *b) { double x, y; int l, m, i, j; l = (int)(a - Cells); m = (int)(b - Cells); - i = l; j = m; + i = l; + j = m; if (P.DoUTM_coords) { if (P.in_cells_.width * ((double)abs(m / P.nch - l / P.nch)) > PI) @@ -106,12 +115,15 @@ double dist2_cc_min(Cell* a, Cell* b) i++; else if (m % P.nch < l % P.nch) j++; - return dist2UTM(P.in_cells_.width * fabs((double)(i / P.nch)), P.in_cells_.height * fabs((double)(i % P.nch)), - P.in_cells_.width * fabs((double)(j / P.nch)), P.in_cells_.height * fabs((double)(j % P.nch))); + return dist2UTM(P.in_cells_.width * fabs((double)(i / P.nch)), + P.in_cells_.height * fabs((double)(i % P.nch)), + P.in_cells_.width * fabs((double)(j / P.nch)), + P.in_cells_.height * fabs((double)(j % P.nch))); } else { - if ((P.DoPeriodicBoundaries) && (P.in_cells_.width * ((double)abs(m / P.nch - l / P.nch)) > P.in_degrees_.width * 0.5)) + if ((P.DoPeriodicBoundaries) && + (P.in_cells_.width * ((double)abs(m / P.nch - l / P.nch)) > P.in_degrees_.width * 0.5)) { if (m / P.nch > l / P.nch) j += P.nch; @@ -125,7 +137,8 @@ double dist2_cc_min(Cell* a, Cell* b) else if (m / P.nch < l / P.nch) j += P.nch; } - if ((P.DoPeriodicBoundaries) && (P.in_degrees_.height * ((double)abs(m % P.nch - l % P.nch)) > P.in_degrees_.height * 0.5)) + if ((P.DoPeriodicBoundaries) && + (P.in_degrees_.height * ((double)abs(m % P.nch - l % P.nch)) > P.in_degrees_.height * 0.5)) { if (m % P.nch > l % P.nch) j++; @@ -144,7 +157,7 @@ double dist2_cc_min(Cell* a, Cell* b) return periodic_xy(x, y); } } -double dist2_mm(Microcell* a, Microcell* b) +double dist2_mm(Microcell *a, Microcell *b) { double x, y; int l, m; @@ -152,12 +165,17 @@ double dist2_mm(Microcell* a, Microcell* b) l = (int)(a - Mcells); m = (int)(b - Mcells); if (P.DoUTM_coords) - return dist2UTM(P.in_microcells_.width * fabs((double)(l / P.get_number_of_micro_cells_high())), P.in_microcells_.height * fabs((double)(l % P.get_number_of_micro_cells_high())), - P.in_microcells_.width * fabs((double)(m / P.get_number_of_micro_cells_high())), P.in_microcells_.height * fabs((double)(m % P.get_number_of_micro_cells_high()))); + return dist2UTM( + P.in_microcells_.width * fabs((double)(l / P.get_number_of_micro_cells_high())), + P.in_microcells_.height * fabs((double)(l % P.get_number_of_micro_cells_high())), + P.in_microcells_.width * fabs((double)(m / P.get_number_of_micro_cells_high())), + P.in_microcells_.height * fabs((double)(m % P.get_number_of_micro_cells_high()))); else { - x = P.in_microcells_.width * fabs((double)(l / P.get_number_of_micro_cells_high() - m / P.get_number_of_micro_cells_high())); - y = P.in_microcells_.height * fabs((double)(l % P.get_number_of_micro_cells_high() - m % P.get_number_of_micro_cells_high())); + x = P.in_microcells_.width * fabs((double)(l / P.get_number_of_micro_cells_high() - + m / P.get_number_of_micro_cells_high())); + y = P.in_microcells_.height * fabs((double)(l % P.get_number_of_micro_cells_high() - + m % P.get_number_of_micro_cells_high())); return periodic_xy(x, y); } } diff --git a/src/Dist.h b/src/Dist.h index 9c2968e7b..7340f2609 100644 --- a/src/Dist.h +++ b/src/Dist.h @@ -1,16 +1,16 @@ #ifndef COVIDSIM_DIST_H_INCLUDED_ #define COVIDSIM_DIST_H_INCLUDED_ -#include "Models/Person.h" #include "Models/Cell.h" #include "Models/Microcell.h" +#include "Models/Person.h" extern double sinx[361], cosx[361], asin2sqx[1001]; double dist2UTM(double, double, double, double); -double dist2(Person*, Person*); -double dist2_cc(Cell*, Cell*); -double dist2_cc_min(Cell*, Cell*); -double dist2_mm(Microcell*, Microcell*); +double dist2(Person *, Person *); +double dist2_cc(Cell *, Cell *); +double dist2_cc_min(Cell *, Cell *); +double dist2_mm(Microcell *, Microcell *); double dist2_raw(double, double, double, double); #endif // COVIDSIM_DIST_H_INCLUDED_ diff --git a/src/Error.cpp b/src/Error.cpp index cb7353cd0..fbb321b36 100644 --- a/src/Error.cpp +++ b/src/Error.cpp @@ -1,14 +1,14 @@ #include "Error.h" -#include #include #include +#include -void ErrorCritical(const char* fmt, const char* file, int line, ...) +void ErrorCritical(const char *fmt, const char *file, int line, ...) { - va_list args; - va_start(args, line); - fprintf(stderr, "[%s line %i] ", file, line); - vfprintf(stderr, fmt, args); - va_end(args); - exit(1); + va_list args; + va_start(args, line); + fprintf(stderr, "[%s line %i] ", file, line); + vfprintf(stderr, fmt, args); + va_end(args); + exit(1); } diff --git a/src/Error.h b/src/Error.h index 4d6ba630d..12b165fd3 100644 --- a/src/Error.h +++ b/src/Error.h @@ -7,10 +7,10 @@ #ifdef _MSC_VER __declspec(noreturn) #endif -void ErrorCritical(const char* msg, const char* file, int line, ...) + void ErrorCritical(const char *msg, const char *file, int line, ...) #ifdef __GNUC__ - __attribute__ ((noreturn)) __attribute__ ((format (printf, 1, 4))) + __attribute__((noreturn)) __attribute__((format(printf, 1, 4))) #endif -; + ; #endif // COVIDSIM_ERROR_H_INCLUDED_ diff --git a/src/Geometry/BoundingBox.h b/src/Geometry/BoundingBox.h index c121b6b61..495395f76 100644 --- a/src/Geometry/BoundingBox.h +++ b/src/Geometry/BoundingBox.h @@ -1,43 +1,41 @@ #pragma once -#include "Vector2.h" #include "Size.h" +#include "Vector2.h" -namespace Geometry { - template - struct BoundingBox { - Vector2 start; - Vector2 end; +namespace Geometry +{ +template struct BoundingBox +{ + Vector2 start; + Vector2 end; - T width() const; + T width() const; - T height() const; + T height() const; - Size size() const; + Size size() const; - bool contains(const Vector2 &point) const; - }; + bool contains(const Vector2 &point) const; +}; - template - T BoundingBox::width() const { - return end.x - start.x; - } +template T BoundingBox::width() const +{ + return end.x - start.x; +} - template - T BoundingBox::height() const { - return end.y - start.y; - } +template T BoundingBox::height() const +{ + return end.y - start.y; +} - template - bool BoundingBox::contains(const Vector2 &point) const { - return point.x >= start.x - && point.x < end.x - && point.y >= start.y - && point.y < end.y; - } +template bool BoundingBox::contains(const Vector2 &point) const +{ + return point.x >= start.x && point.x < end.x && point.y >= start.y && point.y < end.y; +} - template - Size BoundingBox::size() const { - return Size(this->width(), this->height()); - } +template Size BoundingBox::size() const +{ + return Size(this->width(), this->height()); } +} // namespace Geometry diff --git a/src/Geometry/Size.h b/src/Geometry/Size.h index 0873ddcfc..a1d97b7ec 100644 --- a/src/Geometry/Size.h +++ b/src/Geometry/Size.h @@ -1,112 +1,109 @@ #pragma once -#include #include "Vector2.h" +#include -namespace Geometry { - template - struct Size { - T width; - T height; +namespace Geometry +{ +template struct Size +{ + T width; + T height; - Size(); + Size(); - explicit Size(const Vector2 &dimensions); + explicit Size(const Vector2 &dimensions); - Size(T width, T height); + Size(T width, T height); - T area() const; + T area() const; - bool contains(const Vector2 &point) const; + bool contains(const Vector2 &point) const; - Size floor() const; + Size floor() const; - Size ceil() const; + Size ceil() const; - Size operator*(const Size &other) const; + Size operator*(const Size &other) const; - Size operator/(const Size &other) const; + Size operator/(const Size &other) const; - Size operator*(const T &other) const; + Size operator*(const T &other) const; - template - friend Size operator*(const U &other, const Size &self); + template friend Size operator*(const U &other, const Size &self); - Size operator/(const T &other) const; + Size operator/(const T &other) const; - template - explicit operator Size() const; + template explicit operator Size() const; - template - explicit operator Vector2() const; - }; + template explicit operator Vector2() const; +}; - template - Size::Size() : width(), height() {} +template Size::Size() : width(), height() +{ +} - template - Size::Size(const Vector2 &dimensions) : width(dimensions.x), height(dimensions.y) {} +template +Size::Size(const Vector2 &dimensions) : width(dimensions.x), height(dimensions.y) +{ +} - template - Size::Size(T width, T height) : width(width), height(height) {} +template Size::Size(T width, T height) : width(width), height(height) +{ +} - template - T Size::area() const { - return this->width * this->height; - } +template T Size::area() const +{ + return this->width * this->height; +} - template - bool Size::contains(const Vector2 &point) const { - return point.x >= 0 - && point.y >= 0 - && point.x < this->width - && point.y < this->height; - } +template bool Size::contains(const Vector2 &point) const +{ + return point.x >= 0 && point.y >= 0 && point.x < this->width && point.y < this->height; +} - template - Size Size::floor() const { - return Size(std::floor(this->width), std::floor(this->height)); - } +template Size Size::floor() const +{ + return Size(std::floor(this->width), std::floor(this->height)); +} - template - Size Size::ceil() const { - return Size(std::ceil(this->width), std::ceil(this->height)); - } +template Size Size::ceil() const +{ + return Size(std::ceil(this->width), std::ceil(this->height)); +} - template - Size Size::operator*(const Size &other) const { - return Size(this->width * other.width, this->height * other.height); - } +template Size Size::operator*(const Size &other) const +{ + return Size(this->width * other.width, this->height * other.height); +} - template - Size Size::operator/(const Size &other) const { - return Size(this->width / other.width, this->height / other.height); - } +template Size Size::operator/(const Size &other) const +{ + return Size(this->width / other.width, this->height / other.height); +} - template - Size Size::operator*(const T &other) const { - return Size(this->width * other, this->height * other); - } +template Size Size::operator*(const T &other) const +{ + return Size(this->width * other, this->height * other); +} - template - Size operator*(const U &other, const Size &self) { - return Size(other * self.width, other * self.height); - } +template Size operator*(const U &other, const Size &self) +{ + return Size(other * self.width, other * self.height); +} - template - Size Size::operator/(const T &other) const { - return Size(this->width / other, this->height / other); - } +template Size Size::operator/(const T &other) const +{ + return Size(this->width / other, this->height / other); +} - template - template - Size::operator Size() const { - return Size((U)this->width, (U)this->height); - } +template template Size::operator Size() const +{ + return Size((U)this->width, (U)this->height); +} - template - template - Size::operator Vector2() const { - return Vector2((U)this->width, (U)this->height); - } +template template Size::operator Vector2() const +{ + return Vector2((U)this->width, (U)this->height); } +} // namespace Geometry diff --git a/src/Geometry/Vector2.cpp b/src/Geometry/Vector2.cpp index 57930ed20..13c73a738 100644 --- a/src/Geometry/Vector2.cpp +++ b/src/Geometry/Vector2.cpp @@ -2,16 +2,20 @@ using namespace Geometry; -Vector2 Geometry::operator*(const Vector2 &left, const Vector2 &right){ +Vector2 Geometry::operator*(const Vector2 &left, const Vector2 &right) +{ return left * Vector2(right); } -Vector2 Geometry::operator*(const Vector2 &left, const Vector2 &right){ +Vector2 Geometry::operator*(const Vector2 &left, const Vector2 &right) +{ return Vector2(left) * right; } -Vector2 Geometry::operator-(const Vector2 &left, const Vector2 &right){ +Vector2 Geometry::operator-(const Vector2 &left, const Vector2 &right) +{ return left - Vector2(right); } -Vector2 Geometry::operator-(const Vector2 &left, const Vector2 &right){ +Vector2 Geometry::operator-(const Vector2 &left, const Vector2 &right) +{ return Vector2(left) - right; } diff --git a/src/Geometry/Vector2.h b/src/Geometry/Vector2.h index 5fb4a54d0..169441bd2 100644 --- a/src/Geometry/Vector2.h +++ b/src/Geometry/Vector2.h @@ -1,157 +1,157 @@ #pragma once -#include #include "../Dist.h" +#include -namespace Geometry { - template - struct Vector2 { - T x; - T y; +namespace Geometry +{ +template struct Vector2 +{ + T x; + T y; - Vector2(); + Vector2(); - Vector2(T x, T y); + Vector2(T x, T y); - T length() const; + T length() const; - T length_squared() const; + T length_squared() const; - T distance_to(const Vector2 &other) const; + T distance_to(const Vector2 &other) const; - T distance_to_squared(const Vector2 &other) const; + T distance_to_squared(const Vector2 &other) const; - Vector2 abs() const; + Vector2 abs() const; - Vector2 floor() const; + Vector2 floor() const; - Vector2 ceil() const; + Vector2 ceil() const; - Vector2 operator+(const Vector2 &other) const; + Vector2 operator+(const Vector2 &other) const; - Vector2 &operator+=(const Vector2 &other); + Vector2 &operator+=(const Vector2 &other); - Vector2 operator-(const Vector2 &other) const; + Vector2 operator-(const Vector2 &other) const; - Vector2 &operator-=(const Vector2 &other); + Vector2 &operator-=(const Vector2 &other); - Vector2 operator*(const Vector2 &other) const; + Vector2 operator*(const Vector2 &other) const; - Vector2 operator/(const Vector2 &other) const; + Vector2 operator/(const Vector2 &other) const; - Vector2 operator+(const T &other) const; + Vector2 operator+(const T &other) const; - Vector2 operator-(const T &other) const; + Vector2 operator-(const T &other) const; - Vector2 operator*(const T &other) const; + Vector2 operator*(const T &other) const; - Vector2 operator/(const T &other) const; + Vector2 operator/(const T &other) const; - template - explicit operator Vector2() const; - }; + template explicit operator Vector2() const; +}; +template Vector2::Vector2() : x(), y() +{ +} - template - Vector2::Vector2() : x(), y() {} +template Vector2::Vector2(T x, T y) : x(x), y(y) +{ +} - template - Vector2::Vector2(T x, T y) : x(x), y(y) {} +template T Vector2::length() const +{ + return sqrt(this->length_squared()); +} - template - T Vector2::length() const { - return sqrt(this->length_squared()); - } +template T Vector2::length_squared() const +{ + return this->x * this->x + this->y * this->y; +} - template - T Vector2::length_squared() const { - return this->x * this->x + this->y * this->y; - } +template T Vector2::distance_to(const Vector2 &other) const +{ + return (T)std::sqrt(this->distance_to_squared(other)); +} - template - T Vector2::distance_to(const Vector2 &other) const { - return (T) std::sqrt(this->distance_to_squared(other)); - } +template T Vector2::distance_to_squared(const Vector2 &other) const +{ + return (T)dist2_raw(this->x, this->y, other.x, other.y); +} - template - T Vector2::distance_to_squared(const Vector2 &other) const { - return (T) dist2_raw(this->x, this->y, other.x, other.y); - } +template Vector2 Vector2::abs() const +{ + return Vector2(std::abs(this->x), std::abs(this->y)); +} - template - Vector2 Vector2::abs() const { - return Vector2(std::abs(this->x), std::abs(this->y)); - } +template Vector2 Vector2::floor() const +{ + return Vector2(std::floor(this->x), std::floor(this->y)); +} - template - Vector2 Vector2::floor() const { - return Vector2(std::floor(this->x), std::floor(this->y)); - } +template Vector2 Vector2::ceil() const +{ + return Vector2(std::ceil(this->x), std::ceil(this->y)); +} - template - Vector2 Vector2::ceil() const { - return Vector2(std::ceil(this->x), std::ceil(this->y)); - } +template Vector2 Vector2::operator+(const Vector2 &other) const +{ + return Vector2(this->x + other.x, this->y + other.y); +} - template - Vector2 Vector2::operator+(const Vector2 &other) const { - return Vector2(this->x + other.x, this->y + other.y); - } +template Vector2 &Vector2::operator+=(const Vector2 &other) +{ + return *this = *this + other; +} - template - Vector2 &Vector2::operator+=(const Vector2 &other) { - return *this = *this + other; - } +template Vector2 Vector2::operator-(const Vector2 &other) const +{ + return Vector2(this->x - other.x, this->y - other.y); +} - template - Vector2 Vector2::operator-(const Vector2 &other) const { - return Vector2(this->x - other.x, this->y - other.y); - } +template Vector2 &Vector2::operator-=(const Vector2 &other) +{ + return *this = *this - other; +} - template - Vector2 &Vector2::operator-=(const Vector2 &other) { - return *this = *this - other; - } +template Vector2 Vector2::operator*(const Vector2 &other) const +{ + return Vector2(this->x * other.x, this->y * other.y); +} - template - Vector2 Vector2::operator*(const Vector2 &other) const { - return Vector2(this->x * other.x, this->y * other.y); - } +template Vector2 Vector2::operator/(const Vector2 &other) const +{ + return Vector2(this->x / other.x, this->y / other.y); +} - template - Vector2 Vector2::operator/(const Vector2 &other) const { - return Vector2(this->x / other.x, this->y / other.y); - } +template Vector2 Vector2::operator+(const T &other) const +{ + return Vector2(this->x + other, this->y + other); +} - template - Vector2 Vector2::operator+(const T &other) const { - return Vector2(this->x + other, this->y + other); - } +template Vector2 Vector2::operator-(const T &other) const +{ + return Vector2(this->x - other, this->y - other); +} - template - Vector2 Vector2::operator-(const T &other) const { - return Vector2(this->x - other, this->y - other); - } +template Vector2 Vector2::operator*(const T &other) const +{ + return Vector2(this->x * other, this->y * other); +} - template - Vector2 Vector2::operator*(const T &other) const { - return Vector2(this->x * other, this->y * other); - } +template Vector2 Vector2::operator/(const T &other) const +{ + return Vector2(this->x / other, this->y / other); +} - template - Vector2 Vector2::operator/(const T &other) const { - return Vector2(this->x / other, this->y / other); - } - - template - template - Vector2::operator Vector2() const { - return Vector2((U)this->x, (U)this->y); - } - - Vector2 operator*(const Vector2 &left, const Vector2 &right); - Vector2 operator*(const Vector2 &left, const Vector2 &right); - - Vector2 operator-(const Vector2 &left, const Vector2 &right); - Vector2 operator-(const Vector2 &left, const Vector2 &right); +template template Vector2::operator Vector2() const +{ + return Vector2((U)this->x, (U)this->y); } + +Vector2 operator*(const Vector2 &left, const Vector2 &right); +Vector2 operator*(const Vector2 &left, const Vector2 &right); + +Vector2 operator-(const Vector2 &left, const Vector2 &right); +Vector2 operator-(const Vector2 &left, const Vector2 &right); +} // namespace Geometry diff --git a/src/InfStat.h b/src/InfStat.h index f2c61f9c2..5db03e3dc 100644 --- a/src/InfStat.h +++ b/src/InfStat.h @@ -1,13 +1,15 @@ #ifndef COVIDSIM_INFSTAT_H_INCLUDED_ #define COVIDSIM_INFSTAT_H_INCLUDED_ -//// Infection Status definitions / labels (generally positive value indicates asymptomatic infection, -//// negative value indicates symptomatic infection). +//// Infection Status definitions / labels (generally positive value indicates asymptomatic +/// infection, / negative value indicates symptomatic infection). -enum InfStat { +enum InfStat +{ -//// Note - DO NOT CHANGE these definitions without accounting for "Quarantined not Infected" / -//// "Quarantined not symptomatic" calculation: relies on value below being negative for symptomatic people. + //// Note - DO NOT CHANGE these definitions without accounting for "Quarantined not Infected" / + //// "Quarantined not symptomatic" calculation: relies on value below being negative for + /// symptomatic people. //// Susceptible InfStat_Susceptible = 0, @@ -25,7 +27,8 @@ enum InfStat { InfStat_RecoveredFromSymp = -3, //// InfStat_Recovered (will use this for abs() values) so code reads correctly InfStat_Recovered = 3, - //// Immune at start of epidemic - used to model partially immune population. Distinct from recovered, who recovered during runtime. Doesn't take negative values. + //// Immune at start of epidemic - used to model partially immune population. Distinct from + /// recovered, who recovered during runtime. Doesn't take negative values. InfStat_ImmuneAtStart = 4, //// Dead was asymptomatic InfStat_Dead_WasAsymp = 5, @@ -36,7 +39,8 @@ enum InfStat { }; //// SeverityClass definitions / labels (numbers arbitrary but must be different to each other). -enum Severity { +enum Severity +{ //// Flag value. Severity_Asymptomatic = -1, Severity_Mild = 0, diff --git a/src/Kernels.cpp b/src/Kernels.cpp index 13f88e329..d7c9d59e6 100644 --- a/src/Kernels.cpp +++ b/src/Kernels.cpp @@ -1,9 +1,9 @@ -#include -#include #include "Kernels.h" -#include "Error.h" #include "Dist.h" +#include "Error.h" #include "Param.h" +#include +#include #include "Model.h" @@ -27,7 +27,7 @@ double *nKernel, *nKernelHR; void InitKernel(double norm) { - double(*Kernel)(double); + double (*Kernel)(double); if (P.KernelType == 1) Kernel = ExpKernel; @@ -46,7 +46,7 @@ void InitKernel(double norm) else ERR_CRITICAL_FMT("Unknown kernel type %d.\n", P.KernelType); -#pragma omp parallel for schedule(static,500) default(none) \ +#pragma omp parallel for schedule(static, 500) default(none) \ shared(P, Kernel, nKernel, nKernelHR, norm) for (int i = 0; i <= P.NKR; i++) { @@ -54,8 +54,7 @@ void InitKernel(double norm) nKernelHR[i] = (*Kernel)(((double)i) * P.KernelDelta / P.NK_HR) / norm; } -#pragma omp parallel for schedule(static,500) default(none) \ - shared(P, CellLookup) +#pragma omp parallel for schedule(static, 500) default(none) shared(P, CellLookup) for (int i = 0; i < P.NCP; i++) { Cell *l = CellLookup[i]; @@ -69,8 +68,9 @@ void InitKernel(double norm) } } -//// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** -//// **** KERNEL DEFINITIONS +//// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** +/////// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** / **** KERNEL +/// DEFINITIONS double ExpKernel(double r2) { @@ -92,7 +92,9 @@ double PowerKernelB(double r2) double PowerKernelUS(double r2) { double t = log(sqrt(r2) / P.KernelScale + 1); - return (t < -690) ? 0 : (exp(-P.KernelShape * t) + P.KernelP3 * exp(-P.KernelP4 * t)) / (1 + P.KernelP3); + return (t < -690) + ? 0 + : (exp(-P.KernelShape * t) + P.KernelP3 * exp(-P.KernelP4 * t)) / (1 + P.KernelP3); } double GaussianKernel(double r2) diff --git a/src/MicroCellPosition.cpp b/src/MicroCellPosition.cpp index 247bdb27d..acd137ad7 100644 --- a/src/MicroCellPosition.cpp +++ b/src/MicroCellPosition.cpp @@ -1,16 +1,23 @@ #include "MicroCellPosition.hpp" #include -MicroCellPosition MicroCellPosition::operator+(Direction direction) const { - switch (direction) { - case Right: return {this->x + 1, this->y}; - case Up: return {this->x, this->y - 1}; - case Left: return {this->x - 1, this->y}; - case Down: return {this->x, this->y + 1}; +MicroCellPosition MicroCellPosition::operator+(Direction direction) const +{ + switch (direction) + { + case Right: + return {this->x + 1, this->y}; + case Up: + return {this->x, this->y - 1}; + case Left: + return {this->x - 1, this->y}; + case Down: + return {this->x, this->y + 1}; } throw std::out_of_range("direction"); } -MicroCellPosition &MicroCellPosition::operator+=(Direction direction) { +MicroCellPosition &MicroCellPosition::operator+=(Direction direction) +{ return *this = *this + direction; } diff --git a/src/MicroCellPosition.hpp b/src/MicroCellPosition.hpp index 4f05bee3e..f58816971 100644 --- a/src/MicroCellPosition.hpp +++ b/src/MicroCellPosition.hpp @@ -2,12 +2,12 @@ #include "Direction.hpp" -class MicroCellPosition { +class MicroCellPosition +{ public: int x; int y; MicroCellPosition operator+(Direction direction) const; - MicroCellPosition& operator+=(Direction direction); + MicroCellPosition &operator+=(Direction direction); }; - diff --git a/src/Model.h b/src/Model.h index 5f321c237..84441ee55 100644 --- a/src/Model.h +++ b/src/Model.h @@ -3,10 +3,10 @@ #include -#include "Country.h" #include "Constants.h" -#include "InfStat.h" +#include "Country.h" #include "IndexList.h" +#include "InfStat.h" #include "Geometry/Vector2.h" @@ -15,13 +15,11 @@ #include "Models/Microcell.h" #include "Models/Person.h" -//// need to test that inequalities in IncubRecoverySweep can be replaced if you initialize to USHRT_MAX, rather than zero. -//// need to output quantities by admin unit +//// need to test that inequalities in IncubRecoverySweep can be replaced if you initialize to +/// USHRT_MAX, rather than zero. / need to output quantities by admin unit #pragma pack(push, 2) - - /* In the main InfectSweep loop, we cannot safely set Hosts[infectee].infector and Hosts[infectee].infect_type, as concurrent @@ -56,47 +54,71 @@ struct ContactEvent */ struct PopVar { - int S, L, I, R, D, cumI, cumR, cumD, cumC, cumTC, cumFC, cumDC, trigDetectedCases, cumTG, cumSI, nTG; - int cumH; //Added cumulative hospitalisation: ggilani 28/10/14 - int cumCT, cumCC, DCT, cumDCT; //Added total and cumulative contact tracing: ggilani 15/06/17, and equivalents for digital contact tracing: ggilani 11/03/20 - int cumC_country[MAX_COUNTRIES]; //added cumulative cases by country: ggilani 12/11/14 + int S, L, I, R, D, cumI, cumR, cumD, cumC, cumTC, cumFC, cumDC, trigDetectedCases, cumTG, cumSI, + nTG; + int cumH; // Added cumulative hospitalisation: ggilani 28/10/14 + int cumCT, cumCC, DCT, cumDCT; // Added total and cumulative contact tracing: ggilani 15/06/17, + // and equivalents for digital contact tracing: ggilani 11/03/20 + int cumC_country[MAX_COUNTRIES]; // added cumulative cases by country: ggilani 12/11/14 int cumHQ, cumAC, cumAA, cumAH, cumACS, cumAPC, cumAPA, cumAPCS; - //// age specific versions of above variables. e.g. cumI is cumulative infections. cumIa is cumulative infections by age group. + //// age specific versions of above variables. e.g. cumI is cumulative infections. cumIa is + /// cumulative infections by age group. int cumIa[NUM_AGE_GROUPS], cumCa[NUM_AGE_GROUPS], cumDa[NUM_AGE_GROUPS]; - int cumI_adunit[MAX_ADUNITS], cumC_adunit[MAX_ADUNITS], cumD_adunit[MAX_ADUNITS], cumT_adunit[MAX_ADUNITS], cumH_adunit[MAX_ADUNITS], cumDC_adunit[MAX_ADUNITS]; //added cumulative hospitalisation per admin unit: ggilani 28/10/14, cumulative detected cases per adunit: ggilani 03/02/15 - int cumCT_adunit[MAX_ADUNITS], cumCC_adunit[MAX_ADUNITS], trigDC_adunit[MAX_ADUNITS]; //added cumulative CT per admin unit: ggilani 15/06/17 - int cumDCT_adunit[MAX_ADUNITS], DCT_adunit[MAX_ADUNITS]; //added cumulative and overall digital contact tracing per adunit: ggilani 11/03/20 + int cumI_adunit[MAX_ADUNITS], cumC_adunit[MAX_ADUNITS], cumD_adunit[MAX_ADUNITS], + cumT_adunit[MAX_ADUNITS], cumH_adunit[MAX_ADUNITS], + cumDC_adunit[MAX_ADUNITS]; // added cumulative hospitalisation per admin unit: ggilani + // 28/10/14, cumulative detected cases per adunit: ggilani 03/02/15 + int cumCT_adunit[MAX_ADUNITS], cumCC_adunit[MAX_ADUNITS], + trigDC_adunit[MAX_ADUNITS]; // added cumulative CT per admin unit: ggilani 15/06/17 + int cumDCT_adunit[MAX_ADUNITS], + DCT_adunit[MAX_ADUNITS]; // added cumulative and overall digital contact tracing per adunit: + // ggilani 11/03/20 int cumItype[INFECT_TYPE_MASK], cumI_keyworker[2], cumC_keyworker[2], cumT_keyworker[2]; - Infection *inf_queue[MAX_NUM_THREADS]; // the queue (i.e. list) of infections. 1st index is thread, 2nd is person. - int n_queue[MAX_NUM_THREADS]; // number of infections in inf_queue - int* p_queue[NUM_PLACE_TYPES], *pg_queue[NUM_PLACE_TYPES], np_queue[NUM_PLACE_TYPES]; // np_queue is number of places in place queue (by place type), p_queue, and pg_queue is the actual place and place-group queue (i.e. list) of places. 1st index is place type, 2nd is place. + Infection *inf_queue[MAX_NUM_THREADS]; // the queue (i.e. list) of infections. 1st index is + // thread, 2nd is person. + int n_queue[MAX_NUM_THREADS]; // number of infections in inf_queue + int *p_queue[NUM_PLACE_TYPES], *pg_queue[NUM_PLACE_TYPES], + np_queue[NUM_PLACE_TYPES]; // np_queue is number of places in place queue (by place type), + // p_queue, and pg_queue is the actual place and place-group queue + // (i.e. list) of places. 1st index is place type, 2nd is place. int NumPlacesClosed[NUM_PLACE_TYPES], n_mvacc, mvacc_cum; - float* cell_inf; //// List of spatial infectiousnesses by person within cell. - double sumRad2, maxRad2, cumT, cumV, cumVG, cumUT, cumTP, cumV_daily, cumVG_daily; //added cumVG, cumVG_daily - int* CellMemberArray, *CellSuscMemberArray; - int** InvAgeDist; - int* mvacc_queue; - int nct_queue[MAX_ADUNITS]; // queue for contact tracing: ggilani 12/06/17 - ContactEvent* dct_queue[MAX_ADUNITS]; //queues for digital contact tracing: ggilani 14/04/20 - int ndct_queue[MAX_ADUNITS]; //queues for digital contact tracing: ggilani 10/03/20 - int contact_dist[MAX_CONTACTS+1]; //added this to store contact distribution: ggilani 13/04/20 - double* origin_dest[MAX_ADUNITS]; //added intermediate storage for calculation of origin-destination matrix: ggilani 02/02/15 + float *cell_inf; //// List of spatial infectiousnesses by person within cell. + double sumRad2, maxRad2, cumT, cumV, cumVG, cumUT, cumTP, cumV_daily, + cumVG_daily; // added cumVG, cumVG_daily + int *CellMemberArray, *CellSuscMemberArray; + int **InvAgeDist; + int *mvacc_queue; + int nct_queue[MAX_ADUNITS]; // queue for contact tracing: ggilani 12/06/17 + ContactEvent *dct_queue[MAX_ADUNITS]; // queues for digital contact tracing: ggilani 14/04/20 + int ndct_queue[MAX_ADUNITS]; // queues for digital contact tracing: ggilani 10/03/20 + int contact_dist[MAX_CONTACTS + 1]; // added this to store contact distribution: ggilani 13/04/20 + double *origin_dest[MAX_ADUNITS]; // added intermediate storage for calculation of + // origin-destination matrix: ggilani 02/02/15 ///// Prevalence quantities (+ by admin unit) - int Mild, ILI, SARI, Critical, CritRecov, /*cumulative incidence*/ cumMild, cumILI, cumSARI, cumCritical, cumCritRecov; - int Mild_adunit[MAX_ADUNITS], ILI_adunit[MAX_ADUNITS], SARI_adunit[MAX_ADUNITS], Critical_adunit[MAX_ADUNITS], CritRecov_adunit[MAX_ADUNITS]; + int Mild, ILI, SARI, Critical, CritRecov, /*cumulative incidence*/ cumMild, cumILI, cumSARI, + cumCritical, cumCritRecov; + int Mild_adunit[MAX_ADUNITS], ILI_adunit[MAX_ADUNITS], SARI_adunit[MAX_ADUNITS], + Critical_adunit[MAX_ADUNITS], CritRecov_adunit[MAX_ADUNITS]; /// cum incidence quantities. (+ by admin unit) - int cumMild_adunit[MAX_ADUNITS], cumILI_adunit[MAX_ADUNITS], cumSARI_adunit[MAX_ADUNITS], cumCritical_adunit[MAX_ADUNITS], cumCritRecov_adunit[MAX_ADUNITS]; - int Mild_age[NUM_AGE_GROUPS], ILI_age[NUM_AGE_GROUPS], SARI_age[NUM_AGE_GROUPS], Critical_age[NUM_AGE_GROUPS], CritRecov_age[NUM_AGE_GROUPS]; + int cumMild_adunit[MAX_ADUNITS], cumILI_adunit[MAX_ADUNITS], cumSARI_adunit[MAX_ADUNITS], + cumCritical_adunit[MAX_ADUNITS], cumCritRecov_adunit[MAX_ADUNITS]; + int Mild_age[NUM_AGE_GROUPS], ILI_age[NUM_AGE_GROUPS], SARI_age[NUM_AGE_GROUPS], + Critical_age[NUM_AGE_GROUPS], CritRecov_age[NUM_AGE_GROUPS]; /// cum incidence quantities. (+ by age group) - int cumMild_age[NUM_AGE_GROUPS], cumILI_age[NUM_AGE_GROUPS], cumSARI_age[NUM_AGE_GROUPS], cumCritical_age[NUM_AGE_GROUPS], cumCritRecov_age[NUM_AGE_GROUPS]; + int cumMild_age[NUM_AGE_GROUPS], cumILI_age[NUM_AGE_GROUPS], cumSARI_age[NUM_AGE_GROUPS], + cumCritical_age[NUM_AGE_GROUPS], cumCritRecov_age[NUM_AGE_GROUPS]; - int cumDeath_ILI, cumDeath_SARI, cumDeath_Critical; // tracks cumulative deaths from ILI, SARI & Critical severities - int cumDeath_ILI_adunit[MAX_ADUNITS], cumDeath_SARI_adunit[MAX_ADUNITS], cumDeath_Critical_adunit[MAX_ADUNITS]; // tracks cumulative deaths from ILI, SARI & Critical severities - int cumDeath_ILI_age[NUM_AGE_GROUPS], cumDeath_SARI_age[NUM_AGE_GROUPS], cumDeath_Critical_age[NUM_AGE_GROUPS]; - - int ** prevInf_age_adunit, ** cumInf_age_adunit; // prevalence, incidence, and cumulative incidence of infection by age and admin unit. + int cumDeath_ILI, cumDeath_SARI, + cumDeath_Critical; // tracks cumulative deaths from ILI, SARI & Critical severities + int cumDeath_ILI_adunit[MAX_ADUNITS], cumDeath_SARI_adunit[MAX_ADUNITS], + cumDeath_Critical_adunit[MAX_ADUNITS]; // tracks cumulative deaths from ILI, SARI & Critical + // severities + int cumDeath_ILI_age[NUM_AGE_GROUPS], cumDeath_SARI_age[NUM_AGE_GROUPS], + cumDeath_Critical_age[NUM_AGE_GROUPS]; + int **prevInf_age_adunit, **cumInf_age_adunit; // prevalence, incidence, and cumulative incidence + // of infection by age and admin unit. //// above quantities need to be amended in following parts of code: //// i) InitModel (set to zero); @@ -105,7 +127,6 @@ struct PopVar //// iv) SaveResults //// v) SaveSummaryResults ///// And various parts of Update.cpp where variables need must be incremented, decremented. - }; /** @@ -121,57 +142,92 @@ struct Results { // Initial values should not be touched by mean/var calculation double t; - double ** prevInf_age_adunit, ** incInf_age_adunit, ** cumInf_age_adunit; // prevalence, incidence, and cumulative incidence of infection by age and admin unit. + double **prevInf_age_adunit, **incInf_age_adunit, + **cumInf_age_adunit; // prevalence, incidence, and cumulative incidence of infection by age + // and admin unit. // The following values must all be doubles or inline arrays of doubles // The first variable must be S. If that changes change the definition of // ResultsDoubleOffsetStart below. - double S, L, I, R, D, incC, incTC, incFC, incI, incR, incD, incDC, meanTG, meanSI ; - double CT, incCT, incCC, DCT, incDCT; //added total numbers being contact traced and incidence of contact tracing: ggilani 15/06/17, and for digital contact tracing: ggilani 11/03/20 - double incC_country[MAX_COUNTRIES]; //added incidence of cases - double cumT, cumUT, cumTP, cumV, cumTmax, cumVmax, cumDC, extinct, cumVG; //added cumVG + double S, L, I, R, D, incC, incTC, incFC, incI, incR, incD, incDC, meanTG, meanSI; + double CT, incCT, incCC, DCT, + incDCT; // added total numbers being contact traced and incidence of contact tracing: ggilani + // 15/06/17, and for digital contact tracing: ggilani 11/03/20 + double incC_country[MAX_COUNTRIES]; // added incidence of cases + double cumT, cumUT, cumTP, cumV, cumTmax, cumVmax, cumDC, extinct, cumVG; // added cumVG double incHQ, incAC, incAH, incAA, incACS, incAPC, incAPA, incAPCS; double incIa[NUM_AGE_GROUPS], incCa[NUM_AGE_GROUPS], incDa[NUM_AGE_GROUPS]; double incItype[INFECT_TYPE_MASK], Rtype[INFECT_TYPE_MASK], Rage[NUM_AGE_GROUPS], Rdenom; double rmsRad, maxRad, PropPlacesClosed[NUM_PLACE_TYPES], PropSocDist; - double incI_adunit[MAX_ADUNITS], incC_adunit[MAX_ADUNITS], cumT_adunit[MAX_ADUNITS], incD_adunit[MAX_ADUNITS], cumD_adunit[MAX_ADUNITS], incH_adunit[MAX_ADUNITS], incDC_adunit[MAX_ADUNITS]; //added incidence of hospitalisation per day: ggilani 28/10/14, incidence of detected cases per adunit,: ggilani 03/02/15 - double incCT_adunit[MAX_ADUNITS], incCC_adunit[MAX_ADUNITS], incDCT_adunit[MAX_ADUNITS], DCT_adunit[MAX_ADUNITS]; //added incidence of contact tracing and number of people being contact traced per admin unit: ggilani 15/06/17 + double incI_adunit[MAX_ADUNITS], incC_adunit[MAX_ADUNITS], cumT_adunit[MAX_ADUNITS], + incD_adunit[MAX_ADUNITS], cumD_adunit[MAX_ADUNITS], incH_adunit[MAX_ADUNITS], + incDC_adunit[MAX_ADUNITS]; // added incidence of hospitalisation per day: ggilani 28/10/14, + // incidence of detected cases per adunit,: ggilani 03/02/15 + double incCT_adunit[MAX_ADUNITS], incCC_adunit[MAX_ADUNITS], incDCT_adunit[MAX_ADUNITS], + DCT_adunit[MAX_ADUNITS]; // added incidence of contact tracing and number of people being + // contact traced per admin unit: ggilani 15/06/17 double incI_keyworker[2], incC_keyworker[2], cumT_keyworker[2]; ///@{ /** Severity States track the COVID-19 states (e.g., mild, critical, etc.) */ - double Mild, ILI, SARI, Critical, CritRecov; // Prevalence //// Must be: i) initialised to zero in SetUpModel. ii) outputted in SaveResults iii) outputted in SaveSummaryResults - double incMild, incILI, incSARI, incCritical, incCritRecov; // Incidence //// Must be: i) initialised to zero in SetUpModel. ii) calculated in RecordSample iii) outputted in SaveResults. - double cumMild, cumILI, cumSARI, cumCritical, cumCritRecov; // cumulative incidence //// Must be: i) initialised to zero in SetUpModel. ii) outputted in SaveResults - double incDeath_ILI, incDeath_SARI, incDeath_Critical; // tracks incidence of death from ILI, SARI & Critical severities - double cumDeath_ILI, cumDeath_SARI, cumDeath_Critical; // tracks cumulative deaths from ILI, SARI & Critical severities + double Mild, ILI, SARI, Critical, + CritRecov; // Prevalence //// Must be: i) initialised to zero in SetUpModel. ii) + // outputted in SaveResults iii) outputted in SaveSummaryResults + double incMild, incILI, incSARI, incCritical, + incCritRecov; // Incidence //// Must be: i) initialised to zero in SetUpModel. ii) + // calculated in RecordSample iii) outputted in SaveResults. + double cumMild, cumILI, cumSARI, cumCritical, + cumCritRecov; // cumulative incidence //// Must be: i) initialised to zero in SetUpModel. + // ii) outputted in SaveResults + double incDeath_ILI, incDeath_SARI, + incDeath_Critical; // tracks incidence of death from ILI, SARI & Critical severities + double cumDeath_ILI, cumDeath_SARI, + cumDeath_Critical; // tracks cumulative deaths from ILI, SARI & Critical severities ///@} /////// Severity States by admin unit - double Mild_adunit[MAX_ADUNITS], ILI_adunit[MAX_ADUNITS], SARI_adunit[MAX_ADUNITS], Critical_adunit[MAX_ADUNITS], CritRecov_adunit[MAX_ADUNITS]; // Prevalence by admin unit - double incMild_adunit[MAX_ADUNITS], incILI_adunit[MAX_ADUNITS], incSARI_adunit[MAX_ADUNITS], incCritical_adunit[MAX_ADUNITS], incCritRecov_adunit[MAX_ADUNITS]; // incidence by admin unit - double cumMild_adunit[MAX_ADUNITS], cumILI_adunit[MAX_ADUNITS], cumSARI_adunit[MAX_ADUNITS], cumCritical_adunit[MAX_ADUNITS], cumCritRecov_adunit[MAX_ADUNITS]; // cumulative incidence by admin unit - double incDeath_ILI_adunit[MAX_ADUNITS], incDeath_SARI_adunit[MAX_ADUNITS], incDeath_Critical_adunit[MAX_ADUNITS]; // tracks incidence of death from ILI, SARI & Critical severities - double cumDeath_ILI_adunit[MAX_ADUNITS], cumDeath_SARI_adunit[MAX_ADUNITS], cumDeath_Critical_adunit[MAX_ADUNITS]; // tracks cumulative deaths from ILI, SARI & Critical severities + double Mild_adunit[MAX_ADUNITS], ILI_adunit[MAX_ADUNITS], SARI_adunit[MAX_ADUNITS], + Critical_adunit[MAX_ADUNITS], CritRecov_adunit[MAX_ADUNITS]; // Prevalence by admin unit + double incMild_adunit[MAX_ADUNITS], incILI_adunit[MAX_ADUNITS], incSARI_adunit[MAX_ADUNITS], + incCritical_adunit[MAX_ADUNITS], incCritRecov_adunit[MAX_ADUNITS]; // incidence by admin unit + double cumMild_adunit[MAX_ADUNITS], cumILI_adunit[MAX_ADUNITS], cumSARI_adunit[MAX_ADUNITS], + cumCritical_adunit[MAX_ADUNITS], + cumCritRecov_adunit[MAX_ADUNITS]; // cumulative incidence by admin unit + double incDeath_ILI_adunit[MAX_ADUNITS], incDeath_SARI_adunit[MAX_ADUNITS], + incDeath_Critical_adunit[MAX_ADUNITS]; // tracks incidence of death from ILI, SARI & Critical + // severities + double cumDeath_ILI_adunit[MAX_ADUNITS], cumDeath_SARI_adunit[MAX_ADUNITS], + cumDeath_Critical_adunit[MAX_ADUNITS]; // tracks cumulative deaths from ILI, SARI & Critical + // severities /////// Severity States by age group - double Mild_age[NUM_AGE_GROUPS], ILI_age[NUM_AGE_GROUPS], SARI_age[NUM_AGE_GROUPS], Critical_age[NUM_AGE_GROUPS], CritRecov_age[NUM_AGE_GROUPS]; // Prevalence by admin unit - double incMild_age[NUM_AGE_GROUPS], incILI_age[NUM_AGE_GROUPS], incSARI_age[NUM_AGE_GROUPS], incCritical_age[NUM_AGE_GROUPS], incCritRecov_age[NUM_AGE_GROUPS]; // incidence by admin unit - double cumMild_age[NUM_AGE_GROUPS], cumILI_age[NUM_AGE_GROUPS], cumSARI_age[NUM_AGE_GROUPS], cumCritical_age[NUM_AGE_GROUPS], cumCritRecov_age[NUM_AGE_GROUPS]; // cumulative incidence by admin unit - double incDeath_ILI_age[NUM_AGE_GROUPS], incDeath_SARI_age[NUM_AGE_GROUPS], incDeath_Critical_age[NUM_AGE_GROUPS]; // tracks incidence of death from ILI, SARI & Critical severities - double cumDeath_ILI_age[NUM_AGE_GROUPS], cumDeath_SARI_age[NUM_AGE_GROUPS], cumDeath_Critical_age[NUM_AGE_GROUPS]; // tracks cumulative deaths from ILI, SARI & Critical severities - - double prevQuarNotInfected, prevQuarNotSymptomatic; // Which people are under quarantine but not themselves infected/sypmtomatic? + double Mild_age[NUM_AGE_GROUPS], ILI_age[NUM_AGE_GROUPS], SARI_age[NUM_AGE_GROUPS], + Critical_age[NUM_AGE_GROUPS], CritRecov_age[NUM_AGE_GROUPS]; // Prevalence by admin unit + double incMild_age[NUM_AGE_GROUPS], incILI_age[NUM_AGE_GROUPS], incSARI_age[NUM_AGE_GROUPS], + incCritical_age[NUM_AGE_GROUPS], incCritRecov_age[NUM_AGE_GROUPS]; // incidence by admin unit + double cumMild_age[NUM_AGE_GROUPS], cumILI_age[NUM_AGE_GROUPS], cumSARI_age[NUM_AGE_GROUPS], + cumCritical_age[NUM_AGE_GROUPS], + cumCritRecov_age[NUM_AGE_GROUPS]; // cumulative incidence by admin unit + double incDeath_ILI_age[NUM_AGE_GROUPS], incDeath_SARI_age[NUM_AGE_GROUPS], + incDeath_Critical_age[NUM_AGE_GROUPS]; // tracks incidence of death from ILI, SARI & Critical + // severities + double cumDeath_ILI_age[NUM_AGE_GROUPS], cumDeath_SARI_age[NUM_AGE_GROUPS], + cumDeath_Critical_age[NUM_AGE_GROUPS]; // tracks cumulative deaths from ILI, SARI & Critical + // severities + + double prevQuarNotInfected, prevQuarNotSymptomatic; // Which people are under quarantine but not + // themselves infected/sypmtomatic? /////// possibly need quantities by age (later) - //// state variables (S, L, I, R) and therefore (Mild, ILI) etc. changed in i) SetUpModel (initialised to zero); ii) + //// state variables (S, L, I, R) and therefore (Mild, ILI) etc. changed in i) SetUpModel + ///(initialised to zero); ii) //// above quantities need to be amended in following parts of code: //// i) SetUpModel (set to zero); //// ii) RecordSample: add to incidence / Timeseries). //// iii) SaveResults and SaveSummary results. - ///// need to update these quantities in InitModel (DONE), Record Sample (DONE) (and of course places where you need to increment, decrement). - + ///// need to update these quantities in InitModel (DONE), Record Sample (DONE) (and of course + /// places where you need to increment, decrement). }; // The offset (in number of doubles) of the first double field in Results. @@ -186,24 +242,27 @@ const std::size_t ResultsDoubleOffsetStart = offsetof(Results, S) / sizeof(doubl struct Events { double infectee_x, infectee_y, t, t_infector; - int run, infectee_ind, infector_ind, type, infectee_adunit, listpos, infectee_cell, infector_cell, thread; + int run, infectee_ind, infector_ind, type, infectee_adunit, listpos, infectee_cell, infector_cell, + thread; }; /* - HQ - quarantined households - AH - Quarantined (and perhaps sick) working adults - AC - Non-quarantined working adult cases absent thru sickness. - AA - Absent working adults who are caring for sick children (only assigned if no non-working, quarantine or sick adults available). - ACS - Children below care requirement cut-off age who are absent (sick or quarantined) - - APC - Non-quarantined working adult cases absent due to closure of their workplace (excl teachers). - APA - Absent working adults who are caring for children at home due to school closure (only assigned if no non-working, quarantine or sick adults available). - ACS - Children below care requirement cut-off age who are absent due to school closure - - - AH x rq + AC + AA +(APC+APA) x rc = total adult absence - rq=ratio of quarantine time to duration of absence due to illness - rc=ratio of school/workplace closure duration of absence due to illness + HQ - quarantined households + AH - Quarantined (and perhaps sick) working adults + AC - Non-quarantined working adult cases absent thru sickness. + AA - Absent working adults who are caring for sick children (only assigned if no non-working, + quarantine or sick adults available). ACS - Children below care requirement cut-off age who are + absent (sick or quarantined) + + APC - Non-quarantined working adult cases absent due to closure of their workplace (excl + teachers). APA - Absent working adults who are caring for children at home due to school closure + (only assigned if no non-working, quarantine or sick adults available). ACS - Children below care + requirement cut-off age who are absent due to school closure + + + AH x rq + AC + AA +(APC+APA) x rc = total adult absence + rq=ratio of quarantine time to duration of absence due to illness + rc=ratio of school/workplace closure duration of absence due to illness */ /** @@ -218,8 +277,8 @@ struct Airport unsigned short int num_connected, *conn_airports; float total_traffic; Geometry::Vector2 loc; - float* prop_traffic; - IndexList* DestMcells, *DestPlaces; + float *prop_traffic; + IndexList *DestMcells, *DestPlaces; }; /** @@ -237,11 +296,11 @@ struct Place int n, mcell; unsigned short int ng, treat, control_trig, country; unsigned short int close_start_time, close_end_time, treat_end_time; - unsigned short int* AvailByAge; + unsigned short int *AvailByAge; unsigned short int Absent[MAX_ABSENT_TIME], AbsentLastUpdateTime; Geometry::Vector2 loc; float ProbClose; - int* group_start, *group_size, *members; + int *group_start, *group_size, *members; }; /** @@ -251,9 +310,10 @@ struct Place */ struct Intervention { - int InterventionType, DoAUThresh, NoStartAfterMin,dummy; //dummy for 8 byte alignment + int InterventionType, DoAUThresh, NoStartAfterMin, dummy; // dummy for 8 byte alignment double StartTime, StopTime, MinDuration, RepeatInterval, TimeOffset; - double StartThresholdHigh, StartThresholdLow, StopThreshold, Level, LevelCellVar, LevelAUVar, LevelCountryVar, ControlParam, LevelClustering; + double StartThresholdHigh, StartThresholdLow, StopThreshold, Level, LevelCellVar, LevelAUVar, + LevelCountryVar, ControlParam, LevelClustering; unsigned int MaxRounds, MaxResource; }; @@ -262,46 +322,57 @@ struct Intervention */ struct AdminUnit { - int id, cnt_id, NI, n; //added n - number of people in admin unit: ggilani 05/01/15 + int id, cnt_id, NI, n; // added n - number of people in admin unit: ggilani 05/01/15 Intervention InterventionList[MAX_INTERVENTIONS_PER_ADUNIT]; char cnt_name[96], ad_name[200]; int NP, place_close_trig; double CaseIsolationTimeStart, HQuarantineTimeStart, DigitalContactTracingTimeStart; - double SocialDistanceTimeStart, PlaceCloseTimeStart; //added these to admin unit in the hope of getting specific start times for Italy: ggilani 16/03/20 - //adding in admin level delays and durations for admin units: ggilani 17/03/20 + double SocialDistanceTimeStart, + PlaceCloseTimeStart; // added these to admin unit in the hope of getting specific start times + // for Italy: ggilani 16/03/20 + // adding in admin level delays and durations for admin units: ggilani 17/03/20 double SocialDistanceDelay, HQuarantineDelay, CaseIsolationDelay, PlaceCloseDelay, DCTDelay; - double SocialDistanceDuration, HQuarantineDuration, CaseIsolationPolicyDuration, PlaceCloseDuration, DCTDuration; - int* dct, ndct; //arrays for admin unit based digital contact tracing: ggilani 10/03/20 - double* origin_dest; //storage for origin-destination matrix between admin units: ggilani 28/01/15 + double SocialDistanceDuration, HQuarantineDuration, CaseIsolationPolicyDuration, + PlaceCloseDuration, DCTDuration; + int *dct, ndct; // arrays for admin unit based digital contact tracing: ggilani 10/03/20 + double *origin_dest; // storage for origin-destination matrix between admin units: ggilani + // 28/01/15 }; #pragma pack(pop) -extern Person* Hosts; -extern Household* Households; +extern Person *Hosts; +extern Household *Households; extern PopVar State, StateT[MAX_NUM_THREADS]; -extern Cell* Cells, ** CellLookup; -extern Microcell* Mcells, ** McellLookup; -extern Place** Places; +extern Cell *Cells, **CellLookup; +extern Microcell *Mcells, **McellLookup; +extern Place **Places; extern AdminUnit AdUnits[MAX_ADUNITS]; //// Time Series defs: -//// TimeSeries is an array of type results, used to store (unsurprisingly) a time series of every quantity in results. Mostly used in RecordSample. -//// TSMeanNE and TSVarNE are the mean and variance of non-extinct time series. TSMeanE and TSVarE are the mean and variance of extinct time series. TSMean and TSVar are pointers that point to either extinct or non-extinct. -extern Results* TimeSeries, *TSMean, *TSVar, *TSMeanNE, *TSVarNE, *TSMeanE, *TSVarE; //// TimeSeries used in RecordSample, RecordInfTypes, SaveResults. TSMean and TSVar - -extern Airport* Airports; -extern Events* InfEventLog; +//// TimeSeries is an array of type results, used to store (unsurprisingly) a time series of every +/// quantity in results. Mostly used in RecordSample. / TSMeanNE and TSVarNE are the mean and +/// variance of non-extinct time series. TSMeanE and TSVarE are the mean and variance of extinct +/// time series. TSMean and TSVar are pointers that point to either extinct or non-extinct. +extern Results *TimeSeries, *TSMean, *TSVar, *TSMeanNE, *TSVarNE, *TSMeanE, + *TSVarE; //// TimeSeries used in RecordSample, RecordInfTypes, SaveResults. TSMean and TSVar + +extern Airport *Airports; +extern Events *InfEventLog; extern int nEvents; - -extern double inftype[INFECT_TYPE_MASK], inftype_av[INFECT_TYPE_MASK], infcountry[MAX_COUNTRIES], infcountry_av[MAX_COUNTRIES], infcountry_num[MAX_COUNTRIES]; +extern double inftype[INFECT_TYPE_MASK], inftype_av[INFECT_TYPE_MASK], infcountry[MAX_COUNTRIES], + infcountry_av[MAX_COUNTRIES], infcountry_num[MAX_COUNTRIES]; extern double indivR0[MAX_SEC_REC][MAX_GEN_REC], indivR0_av[MAX_SEC_REC][MAX_GEN_REC]; -extern double inf_household[MAX_HOUSEHOLD_SIZE + 1][MAX_HOUSEHOLD_SIZE + 1], denom_household[MAX_HOUSEHOLD_SIZE + 1]; -extern double inf_household_av[MAX_HOUSEHOLD_SIZE + 1][MAX_HOUSEHOLD_SIZE + 1], AgeDist[NUM_AGE_GROUPS], AgeDist2[NUM_AGE_GROUPS]; -extern double case_household[MAX_HOUSEHOLD_SIZE + 1][MAX_HOUSEHOLD_SIZE + 1], case_household_av[MAX_HOUSEHOLD_SIZE + 1][MAX_HOUSEHOLD_SIZE + 1]; +extern double inf_household[MAX_HOUSEHOLD_SIZE + 1][MAX_HOUSEHOLD_SIZE + 1], + denom_household[MAX_HOUSEHOLD_SIZE + 1]; +extern double inf_household_av[MAX_HOUSEHOLD_SIZE + 1][MAX_HOUSEHOLD_SIZE + 1], + AgeDist[NUM_AGE_GROUPS], AgeDist2[NUM_AGE_GROUPS]; +extern double case_household[MAX_HOUSEHOLD_SIZE + 1][MAX_HOUSEHOLD_SIZE + 1], + case_household_av[MAX_HOUSEHOLD_SIZE + 1][MAX_HOUSEHOLD_SIZE + 1]; extern double PropPlaces[NUM_AGE_GROUPS * AGE_GROUP_WIDTH][NUM_PLACE_TYPES]; -extern double PropPlacesC[NUM_AGE_GROUPS * AGE_GROUP_WIDTH][NUM_PLACE_TYPES], AirTravelDist[MAX_DIST]; +extern double PropPlacesC[NUM_AGE_GROUPS * AGE_GROUP_WIDTH][NUM_PLACE_TYPES], + AirTravelDist[MAX_DIST]; extern double PeakHeightSum, PeakHeightSS, PeakTimeSum, PeakTimeSS; extern int DoInitUpdateProbs; diff --git a/src/ModelMacros.h b/src/ModelMacros.h index 19f446607..9f7218863 100644 --- a/src/ModelMacros.h +++ b/src/ModelMacros.h @@ -6,17 +6,24 @@ #define HOST_TREATED(x) ((Hosts[x].treat_stop_time > ts) && (Hosts[x].treat_start_time <= ts)) #define HOST_TO_BE_TREATED(x) (Hosts[x].treat_stop_time > ts) #define PLACE_TREATED(x, y) (Places[x][y].treat_end_time > ts) -#define PLACE_CLOSED(x, y) ((Places[x][y].close_start_time <= ts) && (Places[x][y].close_end_time > ts)) +#define PLACE_CLOSED(x, y) \ + ((Places[x][y].close_start_time <= ts) && (Places[x][y].close_end_time > ts)) #define HOST_TO_BE_VACCED(x) (Hosts[x].vacc_start_time < USHRT_MAX - 1) -#define HOST_VACCED(x) (Hosts[x].vacc_start_time+P.usVaccTimeToEfficacy<=ts) +#define HOST_VACCED(x) (Hosts[x].vacc_start_time + P.usVaccTimeToEfficacy <= ts) #define HOST_VACCED_SWITCH(x) (Hosts[x].vacc_start_time >= P.usVaccTimeEfficacySwitch) -#define HOST_QUARANTINED(x) ((Hosts[x].quar_comply == 1) && (Hosts[x].quar_start_time + P.usHQuarantineHouseDuration > ts) && (Hosts[x].quar_start_time <= ts)) -#define HOST_TO_BE_QUARANTINED(x) ((Hosts[x].quar_start_time + P.usHQuarantineHouseDuration > ts) && (Hosts[x].quar_comply < 2)) -#define HOST_ISOLATED(x) ((Hosts[x].isolation_start_time + P.usCaseIsolationDelay <= ts) && (Hosts[x].isolation_start_time + P.usCaseIsolationDelay + P.usCaseIsolationDuration > ts)) +#define HOST_QUARANTINED(x) \ + ((Hosts[x].quar_comply == 1) && \ + (Hosts[x].quar_start_time + P.usHQuarantineHouseDuration > ts) && \ + (Hosts[x].quar_start_time <= ts)) +#define HOST_TO_BE_QUARANTINED(x) \ + ((Hosts[x].quar_start_time + P.usHQuarantineHouseDuration > ts) && (Hosts[x].quar_comply < 2)) +#define HOST_ISOLATED(x) \ + ((Hosts[x].isolation_start_time + P.usCaseIsolationDelay <= ts) && \ + (Hosts[x].isolation_start_time + P.usCaseIsolationDelay + P.usCaseIsolationDuration > ts)) #define HOST_ABSENT(x) ((Hosts[x].absent_start_time <= ts) && (Hosts[x].absent_stop_time > ts)) /* - #define NO_TREAT_PROPH_CASES + #define NO_TREAT_PROPH_CASES */ #define HOST_AGE_YEAR(x) (Hosts[x].age) diff --git a/src/Models/Cell.h b/src/Models/Cell.h index f46bcdab6..0ebb0be9e 100644 --- a/src/Models/Cell.h +++ b/src/Models/Cell.h @@ -6,12 +6,14 @@ * Keeps track of susceptible, latent and infected people (in addition to details like who * is vaccinated, treated etc.) Also contains data for the spatial gravity model for social * interactions (probability distributions). -*/ + */ struct Cell { int n, S, L, I, R, D, cumTC, S0, tot_treat, tot_vacc; - int* members, *susceptible, *latent, *infected; //// pointers to people in cell. e.g. *susceptible identifies where the final susceptible member of cel is. - int* InvCDF; + int *members, *susceptible, *latent, + *infected; //// pointers to people in cell. e.g. *susceptible identifies where the final + /// susceptible member of cel is. + int *InvCDF; float tot_prob, *cum_trans, *max_trans; short int CurInterv[MAX_INTERVENTION_TYPES]; }; diff --git a/src/Models/Microcell.h b/src/Models/Microcell.h index bf0614b80..bd179c7f2 100644 --- a/src/Models/Microcell.h +++ b/src/Models/Microcell.h @@ -11,20 +11,22 @@ */ struct Microcell { - /* Note use of short int here limits max run time to USHRT_MAX*TimeStep - e.g. 65536*0.25=16384 days=44 yrs. - Global search and replace of 'unsigned short int' with 'int' would remove this limit, but use more memory. + /* Note use of short int here limits max run time to USHRT_MAX*TimeStep - e.g. 65536*0.25=16384 + days=44 yrs. Global search and replace of 'unsigned short int' with 'int' would remove this + limit, but use more memory. */ int n /*Number of people in microcell*/, adunit; - int* members; + int *members; unsigned short int country; - int* places[NUM_PLACE_TYPES]; + int *places[NUM_PLACE_TYPES]; unsigned short int np[NUM_PLACE_TYPES]; - unsigned short int moverest, placeclose, socdist, keyworkerproph, move_trig, place_trig, socdist_trig, keyworkerproph_trig; + unsigned short int moverest, placeclose, socdist, keyworkerproph, move_trig, place_trig, + socdist_trig, keyworkerproph_trig; unsigned short int move_start_time, move_end_time; unsigned short int place_end_time, socdist_end_time, keyworkerproph_end_time; unsigned short int treat, vacc, treat_trig, vacc_trig; unsigned short int treat_start_time, treat_end_time; unsigned short int vacc_start_time; - IndexList* AirportList; + IndexList *AirportList; }; diff --git a/src/Models/Person.h b/src/Models/Person.h index d7f8f3725..82a5e4495 100644 --- a/src/Models/Person.h +++ b/src/Models/Person.h @@ -5,41 +5,57 @@ struct Person { - int pcell; // place cell, Cells[person->pcell] holds this person - int mcell; // microcell, Mcells[person->mcell] holds this person + int pcell; // place cell, Cells[person->pcell] holds this person + int mcell; // microcell, Mcells[person->mcell] holds this person int hh; // Household[person->hh] holds this person - int infector; // If >=0, Hosts[person->infector] was who infected this person - int listpos; // Goes up to at least MAX_SEC_REC, also used as a temp variable? + int infector; // If >=0, Hosts[person->infector] was who infected this person + int listpos; // Goes up to at least MAX_SEC_REC, also used as a temp variable? - int PlaceLinks[NUM_PLACE_TYPES]; //// indexed by i) place type. Value is the number of that place type (e.g. school no. 17; office no. 310 etc.) Place[i][person->PlaceLinks[i]], can be up to P.Nplace[i] - float infectiousness, susc,ProbAbsent,ProbCare; + int PlaceLinks[NUM_PLACE_TYPES]; //// indexed by i) place type. Value is the number of that place + /// type (e.g. school no. 17; office no. 310 etc.) + /// Place[i][person->PlaceLinks[i]], can be up to P.Nplace[i] + float infectiousness, susc, ProbAbsent, ProbCare; unsigned int esocdist_comply : 1; - unsigned int keyworker : 1; // also used to binary index cumI_keyworker[] and related arrays + unsigned int keyworker : 1; // also used to binary index cumI_keyworker[] and related arrays unsigned int to_die : 1; - unsigned int detected : 1; //added hospitalisation flag: ggilani 28/10/2014, added flag to determined whether this person's infection is detected or not + unsigned int detected : 1; // added hospitalisation flag: ggilani 28/10/2014, added flag to + // determined whether this person's infection is detected or not - unsigned char Travelling; // Range up to MAX_TRAVEL_TIME + unsigned char Travelling; // Range up to MAX_TRAVEL_TIME unsigned char age; - unsigned char quar_comply; // can be 0, 1, or 2 - unsigned char num_treats; // set to 0 and tested < 2. but never modified? - Severity Severity_Current, Severity_Final; //// Note we allow Severity_Final to take values: Severity_Mild, Severity_ILI, Severity_SARI, Severity_Critical (not e.g. Severity_Dead or Severity_RecoveringFromCritical) - - unsigned short int PlaceGroupLinks[NUM_PLACE_TYPES]; // These can definitely get > 255 - short int infect_type; // INFECT_TYPE_MASK + unsigned char quar_comply; // can be 0, 1, or 2 + unsigned char num_treats; // set to 0 and tested < 2. but never modified? + Severity Severity_Current, + Severity_Final; //// Note we allow Severity_Final to take values: Severity_Mild, Severity_ILI, + /// Severity_SARI, Severity_Critical (not e.g. Severity_Dead or + /// Severity_RecoveringFromCritical) + + unsigned short int PlaceGroupLinks[NUM_PLACE_TYPES]; // These can definitely get > 255 + short int infect_type; // INFECT_TYPE_MASK InfStat inf; - unsigned short int detected_time; //added hospitalisation flag: ggilani 28/10/2014, added flag to determined whether this person's infection is detected or not + unsigned short int detected_time; // added hospitalisation flag: ggilani 28/10/2014, added flag to + // determined whether this person's infection is detected or not unsigned short int absent_start_time, absent_stop_time; unsigned short int quar_start_time, isolation_start_time; - unsigned short int infection_time, latent_time; // Set in DoInfect function. infection time is time of infection; latent_time is a misnomer - it is the time at which person become infectious (i.e. infection time + latent period for this person). latent_time will also refer to time of onset with ILI or Mild symptomatic disease. - unsigned short int recovery_or_death_time; // set in DoIncub function - unsigned short int SARI_time, Critical_time, RecoveringFromCritical_time; //// /*mild_time, ILI_time,*/ Time of infectiousness onset same for asymptomatic, Mild, and ILI infection so don't need mild_time etc. - unsigned short int treat_start_time, treat_stop_time, vacc_start_time; //// set in TreatSweep function. + unsigned short int infection_time, + latent_time; // Set in DoInfect function. infection time is time of infection; latent_time is + // a misnomer - it is the time at which person become infectious (i.e. infection + // time + latent period for this person). latent_time will also refer to time of + // onset with ILI or Mild symptomatic disease. + unsigned short int recovery_or_death_time; // set in DoIncub function + unsigned short int SARI_time, Critical_time, + RecoveringFromCritical_time; //// /*mild_time, ILI_time,*/ Time of infectiousness onset same + /// for asymptomatic, Mild, and ILI infection so don't need + /// mild_time etc. + unsigned short int treat_start_time, treat_stop_time, + vacc_start_time; //// set in TreatSweep function. unsigned int digitalContactTraced : 1; unsigned int index_case_dct : 2; unsigned int digitalContactTracingUser : 1; - unsigned short int dct_start_time, dct_end_time, dct_trigger_time, dct_test_time; //digital contact tracing start and end time: ggilani 10/03/20 - int ncontacts; //added this in to record total number of contacts each index case records: ggilani 13/04/20 - + unsigned short int dct_start_time, dct_end_time, dct_trigger_time, + dct_test_time; // digital contact tracing start and end time: ggilani 10/03/20 + int ncontacts; // added this in to record total number of contacts each index case records: + // ggilani 13/04/20 }; diff --git a/src/Param.cpp b/src/Param.cpp index 4eb8a869e..108030b2c 100644 --- a/src/Param.cpp +++ b/src/Param.cpp @@ -1,28 +1,34 @@ #include "Param.h" -int Param::get_number_of_micro_cells_wide() const { +int Param::get_number_of_micro_cells_wide() const +{ return this->ncw * this->NMCL; } -int Param::get_number_of_micro_cells_high() const { +int Param::get_number_of_micro_cells_high() const +{ return this->nch * this->NMCL; } -MicroCellPosition Param::get_micro_cell_position_from_cell_index(int cell_index) const { +MicroCellPosition Param::get_micro_cell_position_from_cell_index(int cell_index) const +{ int x = cell_index / this->get_number_of_micro_cells_high(); int y = cell_index % this->get_number_of_micro_cells_high(); return {x, y}; } -bool Param::is_in_bounds(MicroCellPosition position) const { - return position.x >= 0 - && position.y >= 0 - && position.x < this->get_number_of_micro_cells_wide() - && position.y < this->get_number_of_micro_cells_high(); +bool Param::is_in_bounds(MicroCellPosition position) const +{ + return position.x >= 0 && position.y >= 0 && + position.x < this->get_number_of_micro_cells_wide() && + position.y < this->get_number_of_micro_cells_high(); } -int Param::get_micro_cell_index_from_position(MicroCellPosition position) const { - int x = (position.x + this->get_number_of_micro_cells_wide()) % this->get_number_of_micro_cells_wide(); - int y = (position.y + this->get_number_of_micro_cells_high()) % this->get_number_of_micro_cells_high(); +int Param::get_micro_cell_index_from_position(MicroCellPosition position) const +{ + int x = (position.x + this->get_number_of_micro_cells_wide()) % + this->get_number_of_micro_cells_wide(); + int y = (position.y + this->get_number_of_micro_cells_high()) % + this->get_number_of_micro_cells_high(); return x * this->get_number_of_micro_cells_high() + y; } diff --git a/src/Param.h b/src/Param.h index 88b3895b5..67753f4db 100644 --- a/src/Param.h +++ b/src/Param.h @@ -3,8 +3,8 @@ #include -#include "Country.h" #include "Constants.h" +#include "Country.h" #include "MicroCellPosition.hpp" #include "Geometry/Size.h" @@ -12,8 +12,8 @@ /** @brief Enumeration of bitmap formats. */ enum struct BitmapFormats { - PNG, // PNG - default if IMAGE_MAGICK or _WIN32 defined - BMP // BMP - fall-back + PNG, // PNG - default if IMAGE_MAGICK or _WIN32 defined + BMP // BMP - fall-back }; /** @@ -22,27 +22,27 @@ enum struct BitmapFormats */ struct Param { - int PopSize; /**< Population size */ - int NH; // Number of households - int NumRealisations; /**< Number of Realisations */ + int PopSize; /**< Population size */ + int NH; // Number of households + int NumRealisations; /**< Number of Realisations */ int NumNonExtinctRealisations; /**< Number of non-extinct realisations */ int NRactual; int NRactE; int NRactNE; int UpdatesPerSample; // Number of time steps between samples - int NumSamples; // Total number of samples that will be made + int NumSamples; // Total number of samples that will be made int KernelType; - int NKR; // Size of kernel lookup table + int NKR; // Size of kernel lookup table int NK_HR; // Factor to expand hi-res kernel lookup table by int MoveKernelType; int AirportKernelType; unsigned int BinFileLen; int DoBin, DoSaveSnapshot, DoLoadSnapshot; double SnapshotSaveTime, SnapshotLoadTime, clP1, clP2, clP3, clP4, clP5, clP6; - int NC; // Number of cells - int NMC; // Number of microcells + int NC; // Number of cells + int NMC; // Number of microcells int NMCL; // Number of microcells wide/high a cell is; i.e. NMC = NC * NMCL * NMCL - int NCP; /**< Number of populated cells */ + int NCP; /**< Number of populated cells */ int NMCP, ncw, nch, DoUTM_coords, nsp, DoSeasonality, DoCorrectAgeDist, DoPartialImmunity; int get_number_of_micro_cells_wide() const; @@ -51,51 +51,84 @@ struct Param int get_micro_cell_index_from_position(MicroCellPosition position) const; bool is_in_bounds(MicroCellPosition position) const; - int DoAdUnits, NumAdunits, DoAdunitBoundaries, AdunitLevel1Divisor, AdunitLevel1Mask, AdunitBitmapDivisor, CountryDivisor; - int DoAdunitOutput, DoAdunitBoundaryOutput, DoAdunitDemog, DoCorrectAdunitPop, DoSpecifyPop, AdunitLevel1Lookup[ADUNIT_LOOKUP_SIZE]; + int DoAdUnits, NumAdunits, DoAdunitBoundaries, AdunitLevel1Divisor, AdunitLevel1Mask, + AdunitBitmapDivisor, CountryDivisor; + int DoAdunitOutput, DoAdunitBoundaryOutput, DoAdunitDemog, DoCorrectAdunitPop, DoSpecifyPop, + AdunitLevel1Lookup[ADUNIT_LOOKUP_SIZE]; int DoOutputPlaceDistForOneAdunit, OutputPlaceDistAdunit, OutputDensFile; - int DoOneGen, OutputEveryRealisation, BitmapMovieFrame, MaxCorrSample, DoLatent, InfQueuePeakLength, NumThreads, MaxNumThreads; + int DoOneGen, OutputEveryRealisation, BitmapMovieFrame, MaxCorrSample, DoLatent, + InfQueuePeakLength, NumThreads, MaxNumThreads; /// Size in pixels of the map area in the bitmap output Geometry::Size b; - /// Height in pixels of the entire bitmap output, including both the spectrum at the top and the map area + /// Height in pixels of the entire bitmap output, including both the spectrum at the top and the + /// map area int bheight2; Geometry::Vector2 bmin; - BitmapFormats BitmapFormat; // Format of bitmap (platform dependent and command-line /BM: specified). - int DoSI, DoHeteroDensity, DoPeriodicBoundaries, DoImmuneBitmap, OutputBitmapDetected; //added OutputBitmapDetected - ggilani 04/08/15 - int DoHouseholds, DoPlaces, PlaceTypeNum, Nplace[NUM_PLACE_TYPES], SmallEpidemicCases, DoPlaceGroupTreat; - int NumInitialInfections[MAX_NUM_SEED_LOCATIONS], DoRandomInitialInfectionLoc, DoAllInitialInfectioninSameLoc; - int MinPopDensForInitialInfection, NumSeedLocations,InitialInfectionsAdminUnitId[MAX_NUM_SEED_LOCATIONS],InitialInfectionsAdminUnit[MAX_NUM_SEED_LOCATIONS], MaxPopDensForInitialInfection; + BitmapFormats + BitmapFormat; // Format of bitmap (platform dependent and command-line /BM: specified). + int DoSI, DoHeteroDensity, DoPeriodicBoundaries, DoImmuneBitmap, + OutputBitmapDetected; // added OutputBitmapDetected - ggilani 04/08/15 + int DoHouseholds, DoPlaces, PlaceTypeNum, Nplace[NUM_PLACE_TYPES], SmallEpidemicCases, + DoPlaceGroupTreat; + int NumInitialInfections[MAX_NUM_SEED_LOCATIONS], DoRandomInitialInfectionLoc, + DoAllInitialInfectioninSameLoc; + int MinPopDensForInitialInfection, NumSeedLocations, + InitialInfectionsAdminUnitId[MAX_NUM_SEED_LOCATIONS], + InitialInfectionsAdminUnit[MAX_NUM_SEED_LOCATIONS], MaxPopDensForInitialInfection; int DoAge, DoSymptoms, LoadSaveNetwork, IncThreshPop, GlobalIncThreshPop; - int OutputOnlyNonExtinct, DoInfectiousnessProfile, DoInfectionTree, DoWholeHouseholdImmunity, DoSpatial, DoDeath; - int DoAirports, Nairports, Air_popscale, DoSchoolFile, DoRealSymptWithdrawal, CaseAbsentChildAgeCutoff, DoEarlyCaseDiagnosis, DoInterventionFile; - int PlaceTypeNoAirNum; // If DoAirports then this is the number of non-airport place types (< PlaceTypeNum), else == PlaceTypeNum (~ no airport places). - int HotelPlaceType; // If DoAirports then this is place type for hotel (>= PlaceTypeNoAirNum, < PlaceTypeNum), else == PlaceTypeNum (~ unused). - int32_t setupSeed1, setupSeed2; // RNG seeds from the command line, used to initialise the RNG for setup - int32_t runSeed1, runSeed2; // RNG seeds from the command line, used to initialise the RNG for running the model - int32_t nextSetupSeed1, nextSetupSeed2; // The next RNG seeds to use when we need to reinitialise the RNG for setup - int32_t nextRunSeed1, nextRunSeed2; // The next RNG seeds to use when we need to reinitialise the RNG for the model - int ResetSeeds,KeepSameSeeds, ResetSeedsPostIntervention, ResetSeedsFlag, TimeToResetSeeds; - int OutputBitmap; // Whether to output a bitmap - double LongitudeCutLine; // Longitude to image earth is cut at to produce a flat map. Default -360 degrees (effectively -180). Use to ensure countries have a contiguous boundary - double SpatialBoundingBox[4], LocationInitialInfection[MAX_NUM_SEED_LOCATIONS][2], InitialInfectionsAdminUnitWeight[MAX_NUM_SEED_LOCATIONS], TimeStepsPerDay; + int OutputOnlyNonExtinct, DoInfectiousnessProfile, DoInfectionTree, DoWholeHouseholdImmunity, + DoSpatial, DoDeath; + int DoAirports, Nairports, Air_popscale, DoSchoolFile, DoRealSymptWithdrawal, + CaseAbsentChildAgeCutoff, DoEarlyCaseDiagnosis, DoInterventionFile; + int PlaceTypeNoAirNum; // If DoAirports then this is the number of non-airport place types (< + // PlaceTypeNum), else == PlaceTypeNum (~ no airport places). + int HotelPlaceType; // If DoAirports then this is place type for hotel (>= PlaceTypeNoAirNum, < + // PlaceTypeNum), else == PlaceTypeNum (~ unused). + int32_t setupSeed1, + setupSeed2; // RNG seeds from the command line, used to initialise the RNG for setup + int32_t runSeed1, + runSeed2; // RNG seeds from the command line, used to initialise the RNG for running the model + int32_t nextSetupSeed1, + nextSetupSeed2; // The next RNG seeds to use when we need to reinitialise the RNG for setup + int32_t nextRunSeed1, + nextRunSeed2; // The next RNG seeds to use when we need to reinitialise the RNG for the model + int ResetSeeds, KeepSameSeeds, ResetSeedsPostIntervention, ResetSeedsFlag, TimeToResetSeeds; + int OutputBitmap; // Whether to output a bitmap + double LongitudeCutLine; // Longitude to image earth is cut at to produce a flat map. Default + // -360 degrees (effectively -180). Use to ensure countries have a + // contiguous boundary + double SpatialBoundingBox[4], LocationInitialInfection[MAX_NUM_SEED_LOCATIONS][2], + InitialInfectionsAdminUnitWeight[MAX_NUM_SEED_LOCATIONS], TimeStepsPerDay; double FalsePositiveRate, FalsePositivePerCapitaIncidence, FalsePositiveAgeRate[NUM_AGE_GROUPS]; - double latent_icdf[CDF_RES + 1], infectious_icdf[CDF_RES + 1], infectious_prof[INFPROF_RES + 1], infectiousness[MAX_INFECTIOUS_STEPS]; - - double MildToRecovery_icdf[CDF_RES + 1], ILIToRecovery_icdf[CDF_RES + 1], SARIToRecovery_icdf[CDF_RES + 1], CriticalToCritRecov_icdf[CDF_RES + 1], CritRecovToRecov_icdf[CDF_RES + 1]; - double ILIToSARI_icdf[CDF_RES + 1], SARIToCritical_icdf[CDF_RES + 1], ILIToDeath_icdf[CDF_RES + 1], SARIToDeath_icdf[CDF_RES + 1], CriticalToDeath_icdf[CDF_RES + 1]; + double latent_icdf[CDF_RES + 1], infectious_icdf[CDF_RES + 1], infectious_prof[INFPROF_RES + 1], + infectiousness[MAX_INFECTIOUS_STEPS]; + + double MildToRecovery_icdf[CDF_RES + 1], ILIToRecovery_icdf[CDF_RES + 1], + SARIToRecovery_icdf[CDF_RES + 1], CriticalToCritRecov_icdf[CDF_RES + 1], + CritRecovToRecov_icdf[CDF_RES + 1]; + double ILIToSARI_icdf[CDF_RES + 1], SARIToCritical_icdf[CDF_RES + 1], + ILIToDeath_icdf[CDF_RES + 1], SARIToDeath_icdf[CDF_RES + 1], + CriticalToDeath_icdf[CDF_RES + 1]; /// means for above icdf's. - double Mean_MildToRecovery[NUM_AGE_GROUPS], Mean_ILIToRecovery[NUM_AGE_GROUPS], Mean_SARIToRecovery[NUM_AGE_GROUPS], Mean_CriticalToCritRecov[NUM_AGE_GROUPS], Mean_CritRecovToRecov[NUM_AGE_GROUPS]; - double Mean_TimeToTest, Mean_TimeToTestOffset, Mean_TimeToTestCriticalOffset, Mean_TimeToTestCritRecovOffset; - double Mean_ILIToSARI[NUM_AGE_GROUPS], Mean_SARIToCritical[NUM_AGE_GROUPS], Mean_CriticalToDeath[NUM_AGE_GROUPS], Mean_SARIToDeath[NUM_AGE_GROUPS], Mean_ILIToDeath[NUM_AGE_GROUPS]; - double Prop_Mild_ByAge[NUM_AGE_GROUPS], Prop_ILI_ByAge[NUM_AGE_GROUPS], Prop_SARI_ByAge[NUM_AGE_GROUPS], Prop_Critical_ByAge[NUM_AGE_GROUPS]; - double CFR_SARI_ByAge[NUM_AGE_GROUPS], CFR_Critical_ByAge[NUM_AGE_GROUPS], CFR_ILI_ByAge[NUM_AGE_GROUPS]; - - double TimeStep; // The length of a time step, in days - double SampleTime; // The number of days to run for - double SampleStep; // The length of a sampling step, in days + double Mean_MildToRecovery[NUM_AGE_GROUPS], Mean_ILIToRecovery[NUM_AGE_GROUPS], + Mean_SARIToRecovery[NUM_AGE_GROUPS], Mean_CriticalToCritRecov[NUM_AGE_GROUPS], + Mean_CritRecovToRecov[NUM_AGE_GROUPS]; + double Mean_TimeToTest, Mean_TimeToTestOffset, Mean_TimeToTestCriticalOffset, + Mean_TimeToTestCritRecovOffset; + double Mean_ILIToSARI[NUM_AGE_GROUPS], Mean_SARIToCritical[NUM_AGE_GROUPS], + Mean_CriticalToDeath[NUM_AGE_GROUPS], Mean_SARIToDeath[NUM_AGE_GROUPS], + Mean_ILIToDeath[NUM_AGE_GROUPS]; + double Prop_Mild_ByAge[NUM_AGE_GROUPS], Prop_ILI_ByAge[NUM_AGE_GROUPS], + Prop_SARI_ByAge[NUM_AGE_GROUPS], Prop_Critical_ByAge[NUM_AGE_GROUPS]; + double CFR_SARI_ByAge[NUM_AGE_GROUPS], CFR_Critical_ByAge[NUM_AGE_GROUPS], + CFR_ILI_ByAge[NUM_AGE_GROUPS]; + + double TimeStep; // The length of a time step, in days + double SampleTime; // The number of days to run for + double SampleStep; // The length of a sampling step, in days double BitmapAspectScale; // Height of bitmap / Width of bitmap int ts_age; int DoSeverity; // Non-zero (true) if severity analysis should be done @@ -111,57 +144,81 @@ struct Param /// Size of spatial domain in microcells Geometry::Size in_microcells_; - double KernelShape, KernelScale, KernelP3, KernelP4, KernelDelta, MoveKernelShape, MoveKernelScale, MoveKernelP3, MoveKernelP4; - double AirportKernelShape, AirportKernelScale, AirportKernelP3, AirportKernelP4, AirportTrafficScale; + double KernelShape, KernelScale, KernelP3, KernelP4, KernelDelta, MoveKernelShape, + MoveKernelScale, MoveKernelP3, MoveKernelP4; + double AirportKernelShape, AirportKernelScale, AirportKernelP3, AirportKernelP4, + AirportTrafficScale; double R0, R0scale, LocalBeta; - double LatentPeriod; // In days. Mean of icdf (inverse cumulative distribution function). + double LatentPeriod; // In days. Mean of icdf (inverse cumulative distribution function). double InfectiousPeriod; // In days. Mean of icdf (inverse cumulative distribution function). double R0household, R0places, R0spatial; double Seasonality[DAYS_PER_YEAR]; - double SusceptibilitySD,InfectiousnessSD, R0DensityScalePower; + double SusceptibilitySD, InfectiousnessSD, R0DensityScalePower; double ProportionSymptomatic[NUM_AGE_GROUPS], LatentToSymptDelay, SymptInfectiousness; - double SymptSpatialContactRate, SymptPlaceTypeContactRate[NUM_PLACE_TYPES], InhibitInterAdunitPlaceAssignment[NUM_PLACE_TYPES]; - double SymptPlaceTypeWithdrawalProp[NUM_PLACE_TYPES], CaseAbsenteeismDuration, CaseAbsenteeismDelay; + double SymptSpatialContactRate, SymptPlaceTypeContactRate[NUM_PLACE_TYPES], + InhibitInterAdunitPlaceAssignment[NUM_PLACE_TYPES]; + double SymptPlaceTypeWithdrawalProp[NUM_PLACE_TYPES], CaseAbsenteeismDuration, + CaseAbsenteeismDelay; double CaseAbsentChildPropAdultCarers; double RelativeTravelRate[NUM_AGE_GROUPS], RelativeSpatialContact[NUM_AGE_GROUPS]; - double AgeSusceptibility[NUM_AGE_GROUPS], AgeInfectiousness[NUM_AGE_GROUPS], InitialImmunity[NUM_AGE_GROUPS]; + double AgeSusceptibility[NUM_AGE_GROUPS], AgeInfectiousness[NUM_AGE_GROUPS], + InitialImmunity[NUM_AGE_GROUPS]; double WAIFW_Matrix[NUM_AGE_GROUPS][NUM_AGE_GROUPS]; - double HotelPropLocal, JourneyDurationDistrib[MAX_TRAVEL_TIME], LocalJourneyDurationDistrib[MAX_TRAVEL_TIME]; + double HotelPropLocal, JourneyDurationDistrib[MAX_TRAVEL_TIME], + LocalJourneyDurationDistrib[MAX_TRAVEL_TIME]; double MeanJourneyTime, MeanLocalJourneyTime; int PlaceCloseRoundHousehold; // Default 1 (close places around a household), 0 (off) - int AbsenteeismPlaceClosure; // Default 0 (off), 1 (on) track place closures in more detail - int MaxAbsentTime; // In days. Max number of days absent, range [0, MAX_ABSENT_TIME]. Default 0 if !P.AbsenteeismPlaceClosure, otherwise MAX_ABSENT_TIME + int AbsenteeismPlaceClosure; // Default 0 (off), 1 (on) track place closures in more detail + int MaxAbsentTime; // In days. Max number of days absent, range [0, MAX_ABSENT_TIME]. Default 0 + // if !P.AbsenteeismPlaceClosure, otherwise MAX_ABSENT_TIME int InvJourneyDurationDistrib[1025], InvLocalJourneyDurationDistrib[1026]; double HouseholdTrans, HouseholdSizeDistrib[MAX_ADUNITS][MAX_HOUSEHOLD_SIZE], HouseholdTransPow; double HouseholdDenomLookup[MAX_HOUSEHOLD_SIZE]; - int PlaceTypeAgeMin[NUM_PLACE_TYPES], PlaceTypeAgeMax[NUM_PLACE_TYPES], PlaceTypeMaxAgeRead[NUM_PLACE_TYPES]; + int PlaceTypeAgeMin[NUM_PLACE_TYPES], PlaceTypeAgeMax[NUM_PLACE_TYPES], + PlaceTypeMaxAgeRead[NUM_PLACE_TYPES]; int PlaceTypeAgeMin2[NUM_PLACE_TYPES], PlaceTypeAgeMax2[NUM_PLACE_TYPES]; int PlaceTypeAgeMin3[NUM_PLACE_TYPES], PlaceTypeAgeMax3[NUM_PLACE_TYPES]; int PlaceTypeNearestNeighb[NUM_PLACE_TYPES], PlaceTypeKernelType[NUM_PLACE_TYPES]; double PlaceTypePropAgeGroup[NUM_PLACE_TYPES], PlaceTypePropAgeGroup2[NUM_PLACE_TYPES]; - double PlaceTypePropAgeGroup3[NUM_PLACE_TYPES], PlaceTypeKernelShape[NUM_PLACE_TYPES], PlaceTypeKernelScale[NUM_PLACE_TYPES]; - double PlaceTypeKernelP3[NUM_PLACE_TYPES], PlaceTypeKernelP4[NUM_PLACE_TYPES], PlaceTypeTrans[NUM_PLACE_TYPES]; - double PlaceTypeMeanSize[NUM_PLACE_TYPES], PlaceTypePropBetweenGroupLinks[NUM_PLACE_TYPES], PlaceTypeSizeSD[NUM_PLACE_TYPES]; //added PlaceTypeSizeSD for lognormal distribution - ggilani 09/02/17 - double PlaceTypeSizePower[NUM_PLACE_TYPES], PlaceTypeSizeOffset[NUM_PLACE_TYPES], PlaceTypeSizeMax[NUM_PLACE_TYPES]; - double PlaceTypeGroupSizeParam1[NUM_PLACE_TYPES], PlaceExclusivityMatrix[NUM_PLACE_TYPES * NUM_PLACE_TYPES]; //changed PlaceExclusivityMatrix from [NUM_PLACE_TYPES][NUM_PLACE_TYPES] + double PlaceTypePropAgeGroup3[NUM_PLACE_TYPES], PlaceTypeKernelShape[NUM_PLACE_TYPES], + PlaceTypeKernelScale[NUM_PLACE_TYPES]; + double PlaceTypeKernelP3[NUM_PLACE_TYPES], PlaceTypeKernelP4[NUM_PLACE_TYPES], + PlaceTypeTrans[NUM_PLACE_TYPES]; + double PlaceTypeMeanSize[NUM_PLACE_TYPES], PlaceTypePropBetweenGroupLinks[NUM_PLACE_TYPES], + PlaceTypeSizeSD[NUM_PLACE_TYPES]; // added PlaceTypeSizeSD for lognormal distribution - + // ggilani 09/02/17 + double PlaceTypeSizePower[NUM_PLACE_TYPES], PlaceTypeSizeOffset[NUM_PLACE_TYPES], + PlaceTypeSizeMax[NUM_PLACE_TYPES]; + double PlaceTypeGroupSizeParam1[NUM_PLACE_TYPES], + PlaceExclusivityMatrix[NUM_PLACE_TYPES * + NUM_PLACE_TYPES]; // changed PlaceExclusivityMatrix from + // [NUM_PLACE_TYPES][NUM_PLACE_TYPES] double PropAgeGroup[MAX_ADUNITS][NUM_AGE_GROUPS], PopByAdunit[MAX_ADUNITS][2]; double InvLifeExpecDist[MAX_ADUNITS][1001]; - double PlaceCloseTimeStart, PlaceCloseTimeStart2, PlaceCloseDurationBase, PlaceCloseDuration, PlaceCloseDuration2, PlaceCloseDelayMean, PlaceCloseRadius, PlaceCloseRadius2; - double PlaceCloseEffect[NUM_PLACE_TYPES], PlaceClosePropAttending[NUM_PLACE_TYPES], PlaceCloseSpatialRelContact, PlaceCloseHouseholdRelContact; + double PlaceCloseTimeStart, PlaceCloseTimeStart2, PlaceCloseDurationBase, PlaceCloseDuration, + PlaceCloseDuration2, PlaceCloseDelayMean, PlaceCloseRadius, PlaceCloseRadius2; + double PlaceCloseEffect[NUM_PLACE_TYPES], PlaceClosePropAttending[NUM_PLACE_TYPES], + PlaceCloseSpatialRelContact, PlaceCloseHouseholdRelContact; double PlaceCloseCasePropThresh, PlaceCloseAdunitPropThresh, PlaceCloseFracIncTrig; int DoHolidays, NumHolidays; - double HolidayEffect[NUM_PLACE_TYPES], HolidayStartTime[DAYS_PER_YEAR], HolidayDuration[DAYS_PER_YEAR]; + double HolidayEffect[NUM_PLACE_TYPES], HolidayStartTime[DAYS_PER_YEAR], + HolidayDuration[DAYS_PER_YEAR]; double ColourPeriod, BoundingBox[4], BitmapScale; - double TreatSuscDrop, TreatInfDrop, TreatDeathDrop, TreatSympDrop, TreatDelayMean, TreatTimeStart, TreatPlaceGeogDuration; - double TreatProphCourseLength, TreatCaseCourseLength, TreatPropRadial, TreatRadius, TreatRadius2, TreatCellIncThresh; + double TreatSuscDrop, TreatInfDrop, TreatDeathDrop, TreatSympDrop, TreatDelayMean, TreatTimeStart, + TreatPlaceGeogDuration; + double TreatProphCourseLength, TreatCaseCourseLength, TreatPropRadial, TreatRadius, TreatRadius2, + TreatCellIncThresh; double CaseIsolation_CellIncThresh, HHQuar_CellIncThresh, DigitalContactTracing_CellIncThresh; double TreatPropCases, TreatPropCaseHouseholds, TreatHouseholdsDuration; double TreatPlaceProbCaseId[NUM_PLACE_TYPES], TreatPlaceTotalProp[NUM_PLACE_TYPES]; double TreatMaxCoursesBase, TreatNewCoursesRate, TreatNewCoursesStartTime, TreatMaxCourses; - double VaccSuscDrop, VaccSuscDrop2, VaccInfDrop, VaccMortDrop, VaccSympDrop, VaccDelayMean, VaccTimeStart, VaccTimeEfficacySwitch, VaccTimeStartGeo; - double VaccTimeToEfficacy, VaccProp, VaccRadius, VaccRadius2, VaccMinRadius, VaccMinRadius2, VaccPropCaseHouseholds, VaccHouseholdsDuration, VaccMaxCoursesBase; - double VaccNewCoursesRate, VaccNewCoursesStartTime, VaccMaxCourses, VaccNewCoursesEndTime, VaccEfficacyDecay, VaccCellIncThresh, VaccCampaignInterval, VaccCoverageIncreasePeriod; + double VaccSuscDrop, VaccSuscDrop2, VaccInfDrop, VaccMortDrop, VaccSympDrop, VaccDelayMean, + VaccTimeStart, VaccTimeEfficacySwitch, VaccTimeStartGeo; + double VaccTimeToEfficacy, VaccProp, VaccRadius, VaccRadius2, VaccMinRadius, VaccMinRadius2, + VaccPropCaseHouseholds, VaccHouseholdsDuration, VaccMaxCoursesBase; + double VaccNewCoursesRate, VaccNewCoursesStartTime, VaccMaxCourses, VaccNewCoursesEndTime, + VaccEfficacyDecay, VaccCellIncThresh, VaccCampaignInterval, VaccCoverageIncreasePeriod; int VaccDosePerDay; int EnhancedSocDistClusterByHousehold; @@ -173,158 +230,273 @@ struct Param double CaseIsolationDuration, CaseIsolationEffectiveness, CaseIsolationHouseEffectiveness; double CaseIsolationDelay, CaseIsolationPolicyDuration, CaseIsolationProp; - double HQuarantineTimeStart, HQuarantineDelay, HQuarantineHouseDuration, HQuarantinePolicyDuration, HQuarantinePropIndivCompliant; - double HQuarantinePropHouseCompliant, HQuarantinePlaceEffect[NUM_PLACE_TYPES], HQuarantineSpatialEffect, HQuarantineHouseEffect; + double HQuarantineTimeStart, HQuarantineDelay, HQuarantineHouseDuration, + HQuarantinePolicyDuration, HQuarantinePropIndivCompliant; + double HQuarantinePropHouseCompliant, HQuarantinePlaceEffect[NUM_PLACE_TYPES], + HQuarantineSpatialEffect, HQuarantineHouseEffect; - double SocDistTimeStart, SocDistDuration, SocDistHouseholdEffect, SocDistPlaceEffect[NUM_PLACE_TYPES], SocDistSpatialEffect; - double EnhancedSocDistHouseholdEffect, EnhancedSocDistPlaceEffect[NUM_PLACE_TYPES], EnhancedSocDistSpatialEffect, EnhancedSocDistProportionCompliant[NUM_AGE_GROUPS]; + double SocDistTimeStart, SocDistDuration, SocDistHouseholdEffect, + SocDistPlaceEffect[NUM_PLACE_TYPES], SocDistSpatialEffect; + double EnhancedSocDistHouseholdEffect, EnhancedSocDistPlaceEffect[NUM_PLACE_TYPES], + EnhancedSocDistSpatialEffect, EnhancedSocDistProportionCompliant[NUM_AGE_GROUPS]; - double SocDistChangeDelay, SocDistDuration2, SocDistHouseholdEffect2, SocDistPlaceEffect2[NUM_PLACE_TYPES], SocDistSpatialEffect2; - double EnhancedSocDistHouseholdEffect2, EnhancedSocDistPlaceEffect2[NUM_PLACE_TYPES], EnhancedSocDistSpatialEffect2; + double SocDistChangeDelay, SocDistDuration2, SocDistHouseholdEffect2, + SocDistPlaceEffect2[NUM_PLACE_TYPES], SocDistSpatialEffect2; + double EnhancedSocDistHouseholdEffect2, EnhancedSocDistPlaceEffect2[NUM_PLACE_TYPES], + EnhancedSocDistSpatialEffect2; - double SocDistDurationCurrent, SocDistHouseholdEffectCurrent, SocDistPlaceEffectCurrent[NUM_PLACE_TYPES], SocDistSpatialEffectCurrent; - double EnhancedSocDistHouseholdEffectCurrent, EnhancedSocDistPlaceEffectCurrent[NUM_PLACE_TYPES], EnhancedSocDistSpatialEffectCurrent; + double SocDistDurationCurrent, SocDistHouseholdEffectCurrent, + SocDistPlaceEffectCurrent[NUM_PLACE_TYPES], SocDistSpatialEffectCurrent; + double EnhancedSocDistHouseholdEffectCurrent, EnhancedSocDistPlaceEffectCurrent[NUM_PLACE_TYPES], + EnhancedSocDistSpatialEffectCurrent; double SocDistRadius, SocDistRadius2; - ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** + ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** + //////// **** ///// **** ///// **** ///// **** VARIABLE EFFICACIES OVER TIME - ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** + ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** + //////// **** ///// **** ///// **** int VaryEfficaciesOverTime; /**< SOCIAL DISTANCING */ /**< non-enhanced */ int Num_SD_ChangeTimes; //// must be at most MAX_NUM_INTERVENTION_CHANGE_TIMES - double SD_ChangeTimes [MAX_NUM_INTERVENTION_CHANGE_TIMES]; /**< change times for intensity of (enhanced) social distancing */ - double SD_SpatialEffects_OverTime [MAX_NUM_INTERVENTION_CHANGE_TIMES]; //// time-varying equivalent of SocDistSpatialEffectCurrent - double SD_HouseholdEffects_OverTime [MAX_NUM_INTERVENTION_CHANGE_TIMES]; //// time-varying equivalent of SocDistHouseholdEffectCurrent - double SD_PlaceEffects_OverTime [MAX_NUM_INTERVENTION_CHANGE_TIMES][NUM_PLACE_TYPES]; //// indexed by i) change time; ii) place type; //// time-varying equivalent of SocDistPlaceEffectCurrent - int SD_CellIncThresh_OverTime [MAX_NUM_INTERVENTION_CHANGE_TIMES]; //// time-varying equivalent of SocDistCellIncThresh + double SD_ChangeTimes[MAX_NUM_INTERVENTION_CHANGE_TIMES]; /**< change times for intensity of + (enhanced) social distancing */ + double + SD_SpatialEffects_OverTime[MAX_NUM_INTERVENTION_CHANGE_TIMES]; //// time-varying equivalent of + /// SocDistSpatialEffectCurrent + double SD_HouseholdEffects_OverTime + [MAX_NUM_INTERVENTION_CHANGE_TIMES]; //// time-varying equivalent of + /// SocDistHouseholdEffectCurrent + double SD_PlaceEffects_OverTime[MAX_NUM_INTERVENTION_CHANGE_TIMES] + [NUM_PLACE_TYPES]; //// indexed by i) change time; ii) place type; + /////// time-varying equivalent of + /// SocDistPlaceEffectCurrent + int SD_CellIncThresh_OverTime[MAX_NUM_INTERVENTION_CHANGE_TIMES]; //// time-varying equivalent of + /// SocDistCellIncThresh /**< enhanced */ - double Enhanced_SD_SpatialEffects_OverTime [MAX_NUM_INTERVENTION_CHANGE_TIMES]; //// time-varying equivalent of EnhancedSocDistSpatialEffectCurrent - double Enhanced_SD_HouseholdEffects_OverTime [MAX_NUM_INTERVENTION_CHANGE_TIMES]; //// time-varying equivalent of EnhancedSocDistHouseholdEffectCurrent - double Enhanced_SD_PlaceEffects_OverTime [MAX_NUM_INTERVENTION_CHANGE_TIMES][NUM_PLACE_TYPES]; //// indexed by i) change time; ii) place type; time-varying equivalent of EnhancedSocDistPlaceEffectCurrent - - int Num_CI_ChangeTimes; //// must be at most MAX_NUM_INTERVENTION_CHANGE_TIMES - int Num_HQ_ChangeTimes; //// must be at most MAX_NUM_INTERVENTION_CHANGE_TIMES - int Num_PC_ChangeTimes; //// must be at most MAX_NUM_INTERVENTION_CHANGE_TIMES + double Enhanced_SD_SpatialEffects_OverTime + [MAX_NUM_INTERVENTION_CHANGE_TIMES]; //// time-varying equivalent of + /// EnhancedSocDistSpatialEffectCurrent + double Enhanced_SD_HouseholdEffects_OverTime + [MAX_NUM_INTERVENTION_CHANGE_TIMES]; //// time-varying equivalent of + /// EnhancedSocDistHouseholdEffectCurrent + double + Enhanced_SD_PlaceEffects_OverTime[MAX_NUM_INTERVENTION_CHANGE_TIMES] + [NUM_PLACE_TYPES]; //// indexed by i) change time; ii) + /// place type; time-varying equivalent + /// of EnhancedSocDistPlaceEffectCurrent + + int Num_CI_ChangeTimes; //// must be at most MAX_NUM_INTERVENTION_CHANGE_TIMES + int Num_HQ_ChangeTimes; //// must be at most MAX_NUM_INTERVENTION_CHANGE_TIMES + int Num_PC_ChangeTimes; //// must be at most MAX_NUM_INTERVENTION_CHANGE_TIMES int Num_DCT_ChangeTimes; //// must be at most MAX_NUM_INTERVENTION_CHANGE_TIMES /**< CASE ISOLATION */ - double CI_ChangeTimes [MAX_NUM_INTERVENTION_CHANGE_TIMES]; /**< change times for intensity of case isolation */ - double CI_SpatialAndPlaceEffects_OverTime [MAX_NUM_INTERVENTION_CHANGE_TIMES]; //// time-varying equivalent of CaseIsolationEffectiveness - double CI_HouseholdEffects_OverTime [MAX_NUM_INTERVENTION_CHANGE_TIMES]; //// time-varying equivalent of CaseIsolationHouseEffectiveness - double CI_Prop_OverTime [MAX_NUM_INTERVENTION_CHANGE_TIMES]; //// time-varying equivalent of CaseIsolationProp - double CI_CellIncThresh_OverTime [MAX_NUM_INTERVENTION_CHANGE_TIMES]; //// time-varying equivalent of CaseIsolation_CellIncThresh + double CI_ChangeTimes[MAX_NUM_INTERVENTION_CHANGE_TIMES]; /**< change times for intensity of case + isolation */ + double CI_SpatialAndPlaceEffects_OverTime + [MAX_NUM_INTERVENTION_CHANGE_TIMES]; //// time-varying equivalent of + /// CaseIsolationEffectiveness + double CI_HouseholdEffects_OverTime + [MAX_NUM_INTERVENTION_CHANGE_TIMES]; //// time-varying equivalent of + /// CaseIsolationHouseEffectiveness + double CI_Prop_OverTime[MAX_NUM_INTERVENTION_CHANGE_TIMES]; //// time-varying equivalent of + /// CaseIsolationProp + double + CI_CellIncThresh_OverTime[MAX_NUM_INTERVENTION_CHANGE_TIMES]; //// time-varying equivalent of + /// CaseIsolation_CellIncThresh /**< HOUSEHOLD QUARANTINE */ - double HQ_ChangeTimes [MAX_NUM_INTERVENTION_CHANGE_TIMES]; /**< change times for intensity of household quarantine */ - double HQ_SpatialEffects_OverTime [MAX_NUM_INTERVENTION_CHANGE_TIMES]; //// time-varying equivalent of HQuarantineSpatialEffect - double HQ_HouseholdEffects_OverTime [MAX_NUM_INTERVENTION_CHANGE_TIMES]; //// time-varying equivalent of HQuarantineHouseEffect - double HQ_PlaceEffects_OverTime [MAX_NUM_INTERVENTION_CHANGE_TIMES][NUM_PLACE_TYPES]; //// indexed by i) change time; ii) place type; time-varying equivalent of HQuarantinePlaceEffect - double HQ_Individual_PropComply_OverTime [MAX_NUM_INTERVENTION_CHANGE_TIMES]; //// time-varying equivalent of HQuarantinePropIndivCompliant - double HQ_Household_PropComply_OverTime [MAX_NUM_INTERVENTION_CHANGE_TIMES]; //// time-varying equivalent of HQuarantinePropHouseCompliant - double HQ_CellIncThresh_OverTime [MAX_NUM_INTERVENTION_CHANGE_TIMES]; //// time-varying equivalent of HHQuar_CellIncThresh + double HQ_ChangeTimes[MAX_NUM_INTERVENTION_CHANGE_TIMES]; /**< change times for intensity of + household quarantine */ + double + HQ_SpatialEffects_OverTime[MAX_NUM_INTERVENTION_CHANGE_TIMES]; //// time-varying equivalent of + /// HQuarantineSpatialEffect + double + HQ_HouseholdEffects_OverTime[MAX_NUM_INTERVENTION_CHANGE_TIMES]; //// time-varying equivalent + /// of HQuarantineHouseEffect + double HQ_PlaceEffects_OverTime[MAX_NUM_INTERVENTION_CHANGE_TIMES] + [NUM_PLACE_TYPES]; //// indexed by i) change time; ii) place type; + /// time-varying equivalent of + /// HQuarantinePlaceEffect + double HQ_Individual_PropComply_OverTime + [MAX_NUM_INTERVENTION_CHANGE_TIMES]; //// time-varying equivalent of + /// HQuarantinePropIndivCompliant + double HQ_Household_PropComply_OverTime + [MAX_NUM_INTERVENTION_CHANGE_TIMES]; //// time-varying equivalent of + /// HQuarantinePropHouseCompliant + double HQ_CellIncThresh_OverTime[MAX_NUM_INTERVENTION_CHANGE_TIMES]; //// time-varying equivalent + /// of HHQuar_CellIncThresh /**< PLACE CLOSURE */ - double PC_ChangeTimes [MAX_NUM_INTERVENTION_CHANGE_TIMES]; /**< change times for intensity of place closure */ - double PC_SpatialEffects_OverTime [MAX_NUM_INTERVENTION_CHANGE_TIMES]; //// time-varying equivalent of PlaceCloseSpatialRelContact - double PC_HouseholdEffects_OverTime [MAX_NUM_INTERVENTION_CHANGE_TIMES]; //// time-varying equivalent of PlaceCloseHouseholdRelContact - double PC_PlaceEffects_OverTime [MAX_NUM_INTERVENTION_CHANGE_TIMES][NUM_PLACE_TYPES]; //// indexed by i) change time; ii) place type; //// time-varying equivalent of PlaceCloseEffect - double PC_PropAttending_OverTime [MAX_NUM_INTERVENTION_CHANGE_TIMES][NUM_PLACE_TYPES]; - int PC_IncThresh_OverTime [MAX_NUM_INTERVENTION_CHANGE_TIMES]; //// time-varying equivalent of PlaceCloseIncTrig / PlaceCloseIncTrig1 - double PC_FracIncThresh_OverTime [MAX_NUM_INTERVENTION_CHANGE_TIMES]; //// time-varying equivalent of PlaceCloseFracIncTrig - int PC_CellIncThresh_OverTime [MAX_NUM_INTERVENTION_CHANGE_TIMES]; //// time-varying equivalent of PlaceCloseCellIncThresh - double PC_Durs_OverTime [MAX_NUM_INTERVENTION_CHANGE_TIMES]; //// time-varying equivalent of PlaceCloseDuration + double PC_ChangeTimes[MAX_NUM_INTERVENTION_CHANGE_TIMES]; /**< change times for intensity of place + closure */ + double + PC_SpatialEffects_OverTime[MAX_NUM_INTERVENTION_CHANGE_TIMES]; //// time-varying equivalent of + /// PlaceCloseSpatialRelContact + double PC_HouseholdEffects_OverTime + [MAX_NUM_INTERVENTION_CHANGE_TIMES]; //// time-varying equivalent of + /// PlaceCloseHouseholdRelContact + double + PC_PlaceEffects_OverTime[MAX_NUM_INTERVENTION_CHANGE_TIMES] + [NUM_PLACE_TYPES]; //// indexed by i) change time; ii) place type; + /////// time-varying equivalent of PlaceCloseEffect + double PC_PropAttending_OverTime[MAX_NUM_INTERVENTION_CHANGE_TIMES][NUM_PLACE_TYPES]; + int PC_IncThresh_OverTime[MAX_NUM_INTERVENTION_CHANGE_TIMES]; //// time-varying equivalent of + /// PlaceCloseIncTrig / + /// PlaceCloseIncTrig1 + double PC_FracIncThresh_OverTime[MAX_NUM_INTERVENTION_CHANGE_TIMES]; //// time-varying equivalent + /// of PlaceCloseFracIncTrig + int PC_CellIncThresh_OverTime[MAX_NUM_INTERVENTION_CHANGE_TIMES]; //// time-varying equivalent of + /// PlaceCloseCellIncThresh + double PC_Durs_OverTime[MAX_NUM_INTERVENTION_CHANGE_TIMES]; //// time-varying equivalent of + /// PlaceCloseDuration /**< DIGITAL CONTACT TRACING */ - double DCT_ChangeTimes [MAX_NUM_INTERVENTION_CHANGE_TIMES]; /**< change times for intensity of digital contact tracing */ - double DCT_SpatialAndPlaceEffects_OverTime [MAX_NUM_INTERVENTION_CHANGE_TIMES]; //// time-varying equivalent of DCTCaseIsolationEffectiveness - double DCT_HouseholdEffects_OverTime [MAX_NUM_INTERVENTION_CHANGE_TIMES]; //// time-varying equivalent of DCTCaseIsolationHouseEffectiveness - double DCT_Prop_OverTime [MAX_NUM_INTERVENTION_CHANGE_TIMES]; //// time-varying equivalent of ProportionDigitalContactsIsolate - int DCT_MaxToTrace_OverTime [MAX_NUM_INTERVENTION_CHANGE_TIMES]; - - double KeyWorkerProphTimeStart, KeyWorkerProphDuration, KeyWorkerPropInKeyPlaces[NUM_PLACE_TYPES], KeyWorkerHouseProp; + double DCT_ChangeTimes[MAX_NUM_INTERVENTION_CHANGE_TIMES]; /**< change times for intensity of + digital contact tracing */ + double DCT_SpatialAndPlaceEffects_OverTime + [MAX_NUM_INTERVENTION_CHANGE_TIMES]; //// time-varying equivalent of + /// DCTCaseIsolationEffectiveness + double DCT_HouseholdEffects_OverTime + [MAX_NUM_INTERVENTION_CHANGE_TIMES]; //// time-varying equivalent of + /// DCTCaseIsolationHouseEffectiveness + double DCT_Prop_OverTime[MAX_NUM_INTERVENTION_CHANGE_TIMES]; //// time-varying equivalent of + /// ProportionDigitalContactsIsolate + int DCT_MaxToTrace_OverTime[MAX_NUM_INTERVENTION_CHANGE_TIMES]; + + double KeyWorkerProphTimeStart, KeyWorkerProphDuration, KeyWorkerPropInKeyPlaces[NUM_PLACE_TYPES], + KeyWorkerHouseProp; double KeyWorkerProphRenewalDuration, KeyWorkerProphRadius, KeyWorkerProphRadius2; - double TreatTimeStartBase, VaccTimeStartBase, MoveRestrTimeStartBase, PlaceCloseTimeStartBase, PlaceCloseTimeStartBase2,PlaceCloseTimeStartPrevious; - double AirportCloseTimeStartBase, HQuarantineTimeStartBase, CaseIsolationTimeStartBase, SocDistTimeStartBase, KeyWorkerProphTimeStartBase, DigitalContactTracingTimeStartBase; - double InfectionImportRate1, InfectionImportRate2, InfectionImportChangeTime, ImportInfectionTimeProfile[MAX_DUR_IMPORT_PROFILE]; + double TreatTimeStartBase, VaccTimeStartBase, MoveRestrTimeStartBase, PlaceCloseTimeStartBase, + PlaceCloseTimeStartBase2, PlaceCloseTimeStartPrevious; + double AirportCloseTimeStartBase, HQuarantineTimeStartBase, CaseIsolationTimeStartBase, + SocDistTimeStartBase, KeyWorkerProphTimeStartBase, DigitalContactTracingTimeStartBase; + double InfectionImportRate1, InfectionImportRate2, InfectionImportChangeTime, + ImportInfectionTimeProfile[MAX_DUR_IMPORT_PROFILE]; /**< CALIBRATION PARAMETERS Params below govern how epidemic is calibrated. - Calibration relates simulation time to calendar time (e.g. which day of year corresponds to first day of epidemic / simulation?), and adjusts seeding of infection. - Important distinction between Day 0 in calendar time, and Day 0 in simulation time. - Calendar time Day 0 is taken to be 31 Dec 2019, so e.g Day 1 is 1st Jan 2020. and Day 76 is 16th March 2020. - Simulation time day 0 (i.e. t = 0 in runtime) is recorded as Epidemic_StartDate_CalTime. - Variables with _CalTime suffix refer to calendar time (relative to Calendar time Day 0). Variables with _SimTime suffix refer to simulation time. - Model estimates start date of epidemic with reference to either cumulative deaths or cumulative Critical/ICU admissions - Calibration parameters specified in pre-parameter file. + Calibration relates simulation time to calendar time (e.g. which day of year corresponds to + first day of epidemic / simulation?), and adjusts seeding of infection. Important distinction + between Day 0 in calendar time, and Day 0 in simulation time. Calendar time Day 0 is taken to be + 31 Dec 2019, so e.g Day 1 is 1st Jan 2020. and Day 76 is 16th March 2020. Simulation time day 0 + (i.e. t = 0 in runtime) is recorded as Epidemic_StartDate_CalTime. Variables with _CalTime + suffix refer to calendar time (relative to Calendar time Day 0). Variables with _SimTime suffix + refer to simulation time. Model estimates start date of epidemic with reference to either + cumulative deaths or cumulative Critical/ICU admissions Calibration parameters specified in + pre-parameter file. */ - double DateTriggerReached_SimTime; // Day of simulation that trigger is reached. (internal parameter not specified by user/command line/(pre-parameter files. Value determined through calibration.) - double DateTriggerReached_CalTime; // Day of year trigger is reached (where trigger refers to either cumulative deaths or cumulative ICU admissions, absolute or per-capita etc.) - double HolidaysStartDay_SimTime; // Number of days between school holiday start date and start date of epidemic. Is set during calibration as start date of epidemic unknown before calibration. - double Interventions_StartDate_CalTime; // Number of days between school holiday start date and start date of epidemic. Is set during calibration as start date of epidemic unknown before calibration. - double Epidemic_StartDate_CalTime; // First day of epidemic relative to Calendar time Day 0. (internal parameter not specified by user/command line/(pre-parameter files. Value determined through calibration.) - double SeedingScaling; // Scaling of number of seeding infections by location. (internal parameter not specified by user/command line/(pre-parameter files. Value determined through calibration.) - int CaseOrDeathThresholdBeforeAlert; // Number of deaths accummulated before alert (if TriggerAlertOnDeaths == 1) OR "Number of detected cases needed before outbreak alert triggered" (if TriggerAlertOnDeaths == 0) - int CaseOrDeathThresholdBeforeAlert_Fixed; // CaseOrDeathThresholdBeforeAlert adjusted during calibration. Need to record fixed version in order to reset so that calibration works for multiple realisations - int TriggerAlertOnDeaths; // Trigger alert on deaths (if true then cumulative deaths used for calibration, if false then cumulative ICU cases used for calibration). - int WindowToEvaluateTriggerAlert; // Number of days to accummulate cases/deaths before alert - int DoAlertTriggerAfterInterv; // Alert trigger starts after interventions, i.e. were there interventions before date specified in DateTriggerReached_CalTime / "Day of year trigger is reached"? - int AlertTriggerAfterIntervThreshold; // initialized to CaseOrDeathThresholdBeforeAlert (i.e. number cases or deaths accumulated before alert). - + double DateTriggerReached_SimTime; // Day of simulation that trigger is reached. (internal + // parameter not specified by user/command line/(pre-parameter + // files. Value determined through calibration.) + double DateTriggerReached_CalTime; // Day of year trigger is reached (where trigger refers to + // either cumulative deaths or cumulative ICU admissions, + // absolute or per-capita etc.) + double HolidaysStartDay_SimTime; // Number of days between school holiday start date and start + // date of epidemic. Is set during calibration as start date of + // epidemic unknown before calibration. + double Interventions_StartDate_CalTime; // Number of days between school holiday start date and + // start date of epidemic. Is set during calibration as + // start date of epidemic unknown before calibration. + double Epidemic_StartDate_CalTime; // First day of epidemic relative to Calendar time Day 0. + // (internal parameter not specified by user/command + // line/(pre-parameter files. Value determined through + // calibration.) + double SeedingScaling; // Scaling of number of seeding infections by location. (internal + // parameter not specified by user/command line/(pre-parameter files. Value + // determined through calibration.) + int CaseOrDeathThresholdBeforeAlert; // Number of deaths accummulated before alert (if + // TriggerAlertOnDeaths == 1) OR "Number of detected cases + // needed before outbreak alert triggered" (if + // TriggerAlertOnDeaths == 0) + int CaseOrDeathThresholdBeforeAlert_Fixed; // CaseOrDeathThresholdBeforeAlert adjusted during + // calibration. Need to record fixed version in order + // to reset so that calibration works for multiple + // realisations + int TriggerAlertOnDeaths; // Trigger alert on deaths (if true then cumulative deaths used for + // calibration, if false then cumulative ICU cases used for + // calibration). + int WindowToEvaluateTriggerAlert; // Number of days to accummulate cases/deaths before alert + int DoAlertTriggerAfterInterv; // Alert trigger starts after interventions, i.e. were there + // interventions before date specified in + // DateTriggerReached_CalTime / "Day of year trigger is reached"? + int AlertTriggerAfterIntervThreshold; // initialized to CaseOrDeathThresholdBeforeAlert (i.e. + // number cases or deaths accumulated before alert). + int StopCalibration; int ModelCalibIteration; /**< Trigger parameters */ int DoPerCapitaTriggers; // Use cases per thousand threshold for area controls - int DoGlobalTriggers; // Use global triggers for interventions - int DoAdminTriggers; // Use admin unit triggers for interventions - int DoICUTriggers; // Use ICU case triggers for interventions - int TriggersSamplingInterval; // Number of sampling intervals over which cumulative incidence measured for global trigger + int DoGlobalTriggers; // Use global triggers for interventions + int DoAdminTriggers; // Use admin unit triggers for interventions + int DoICUTriggers; // Use ICU case triggers for interventions + int TriggersSamplingInterval; // Number of sampling intervals over which cumulative incidence + // measured for global trigger int MoveRestrCellIncThresh, DoHQretrigger; - int PlaceCloseCellIncThresh, PlaceCloseCellIncThresh1, PlaceCloseCellIncThresh2, PlaceCloseIndepThresh, SocDistCellIncThresh, VaccPriorityGroupAge[2]; + int PlaceCloseCellIncThresh, PlaceCloseCellIncThresh1, PlaceCloseCellIncThresh2, + PlaceCloseIndepThresh, SocDistCellIncThresh, VaccPriorityGroupAge[2]; int PlaceCloseCellIncStopThresh, SocDistCellIncStopThresh; int PlaceCloseAdunitPlaceTypes[NUM_PLACE_TYPES]; int DoPlaceCloseOnceOnly, DoSocDistOnceOnly, DoMoveRestrOnceOnly, DoKeyWorkerProphOnceOnly; - int VaccMaxRounds, VaccByAdminUnit, VaccAdminUnitDivisor, TreatByAdminUnit, TreatAdminUnitDivisor, MoveRestrByAdminUnit, MoveRestrAdminUnitDivisor, PlaceCloseByAdminUnit, PlaceCloseAdminUnitDivisor; - int KeyWorkerProphCellIncThresh, KeyWorkerPlaceNum[NUM_PLACE_TYPES], KeyWorkerPopNum, KeyWorkerNum, KeyWorkerIncHouseNum; - int DoBlanketMoveRestr, PlaceCloseIncTrig, PlaceCloseIncTrig1, PlaceCloseIncTrig2, TreatMaxCoursesPerCase, DoImportsViaAirports, DoMassVacc, DurImportTimeProfile; + int VaccMaxRounds, VaccByAdminUnit, VaccAdminUnitDivisor, TreatByAdminUnit, TreatAdminUnitDivisor, + MoveRestrByAdminUnit, MoveRestrAdminUnitDivisor, PlaceCloseByAdminUnit, + PlaceCloseAdminUnitDivisor; + int KeyWorkerProphCellIncThresh, KeyWorkerPlaceNum[NUM_PLACE_TYPES], KeyWorkerPopNum, + KeyWorkerNum, KeyWorkerIncHouseNum; + int DoBlanketMoveRestr, PlaceCloseIncTrig, PlaceCloseIncTrig1, PlaceCloseIncTrig2, + TreatMaxCoursesPerCase, DoImportsViaAirports, DoMassVacc, DurImportTimeProfile; int DoRecordInfEvents, MaxInfEvents, RecordInfEventsPerRun; - unsigned short int usHQuarantineHouseDuration, usVaccTimeToEfficacy, usVaccTimeEfficacySwitch; //// us = unsigned short versions of their namesakes, multiplied by P.TimeStepsPerDay - unsigned short int usCaseIsolationDuration, usCaseIsolationDelay, usCaseAbsenteeismDuration, usCaseAbsenteeismDelay,usAlignDum; // last is for 8 byte alignment + unsigned short int usHQuarantineHouseDuration, usVaccTimeToEfficacy, + usVaccTimeEfficacySwitch; //// us = unsigned short versions of their namesakes, multiplied by + /// P.TimeStepsPerDay + unsigned short int usCaseIsolationDuration, usCaseIsolationDelay, usCaseAbsenteeismDuration, + usCaseAbsenteeismDelay, usAlignDum; // last is for 8 byte alignment double KernelPowerScale, KernelOffsetScale; int LimitNumInfections, MaxNumInfections; - //Added parameters to deal with digital contact tracing - ggilani 09/03/2020 - int DoDigitalContactTracing, ClusterDigitalContactUsers, NDigitalContactUsers, NDigitalHouseholdUsers, FindContactsOfDCTContacts, DoDCTTest; - int OutputDigitalContactTracing, OutputDigitalContactDist, DCTIsolateIndexCases, RemoveContactsOfNegativeIndexCase, MaxDigitalContactsToTrace; - double PropPopUsingDigitalContactTracing, ScalingFactorSpatialDigitalContacts, ScalingFactorPlaceDigitalContacts, DigitalContactTracingDelay, LengthDigitalContactIsolation, ProportionDigitalContactsIsolate, ProportionSmartphoneUsersByAge[NUM_AGE_GROUPS]; - double DelayFromIndexCaseDetectionToDCTIsolation, DelayToTestIndexCase, DelayToTestDCTContacts, SpecificityDCT, SensitivityDCT; - double DigitalContactTracingPolicyDuration, DCTCaseIsolationHouseEffectiveness, DCTCaseIsolationEffectiveness; - - int DoOriginDestinationMatrix; //added: ggilani 28/01/15 + // Added parameters to deal with digital contact tracing - ggilani 09/03/2020 + int DoDigitalContactTracing, ClusterDigitalContactUsers, NDigitalContactUsers, + NDigitalHouseholdUsers, FindContactsOfDCTContacts, DoDCTTest; + int OutputDigitalContactTracing, OutputDigitalContactDist, DCTIsolateIndexCases, + RemoveContactsOfNegativeIndexCase, MaxDigitalContactsToTrace; + double PropPopUsingDigitalContactTracing, ScalingFactorSpatialDigitalContacts, + ScalingFactorPlaceDigitalContacts, DigitalContactTracingDelay, LengthDigitalContactIsolation, + ProportionDigitalContactsIsolate, ProportionSmartphoneUsersByAge[NUM_AGE_GROUPS]; + double DelayFromIndexCaseDetectionToDCTIsolation, DelayToTestIndexCase, DelayToTestDCTContacts, + SpecificityDCT, SensitivityDCT; + double DigitalContactTracingPolicyDuration, DCTCaseIsolationHouseEffectiveness, + DCTCaseIsolationEffectiveness; + + int DoOriginDestinationMatrix; // added: ggilani 28/01/15 int DoInterventionDelaysByAdUnit; - - int OutputAge, OutputR0, OutputControls, OutputCountry, OutputAdUnitVar, OutputHousehold, OutputInfType, OutputNonSeverity, OutputSeverityAdminUnit, OutputSeverityAge, OutputNonSummaryResults, OutputAdUnitAge; + int OutputAge, OutputR0, OutputControls, OutputCountry, OutputAdUnitVar, OutputHousehold, + OutputInfType, OutputNonSeverity, OutputSeverityAdminUnit, OutputSeverityAge, + OutputNonSummaryResults, OutputAdUnitAge; int MeanChildAgeGap; // Average gap between ages of children in a household, in years - int MinAdultAge; // The youngest age, in years, at which someone is considered to be an adult - int MaxMFPartnerAgeGap; // The largest number of years older than a female partner that a male partner can be - int MaxFMPartnerAgeGap; // The largest number of years older than a male partner that a female partner can be - int MinParentAgeGap; // The minimum number of years older than a child that a parent must be - int MaxParentAgeGap; // The maximum number of years older than a child that a parent can be - int MaxChildAge; // The maximum age, in years, of a child + int MinAdultAge; // The youngest age, in years, at which someone is considered to be an adult + int MaxMFPartnerAgeGap; // The largest number of years older than a female partner that a male + // partner can be + int MaxFMPartnerAgeGap; // The largest number of years older than a male partner that a female + // partner can be + int MinParentAgeGap; // The minimum number of years older than a child that a parent must be + int MaxParentAgeGap; // The maximum number of years older than a child that a parent can be + int MaxChildAge; // The maximum age, in years, of a child int YoungAndSingle; int NoChildPersAge; int OldPersAge; diff --git a/src/Rand.cpp b/src/Rand.cpp index d7a44e9e3..26a3b0cf0 100644 --- a/src/Rand.cpp +++ b/src/Rand.cpp @@ -1,9 +1,9 @@ -#include -#include -#include #include "Rand.h" #include "Constants.h" #include "Error.h" +#include +#include +#include #ifdef _OPENMP #include @@ -13,12 +13,14 @@ #endif /* RANDLIB static variables */ -int32_t* Xcg1, *Xcg2; +int32_t *Xcg1, *Xcg2; int **SamplingQueue = nullptr; -///////////// ********* ///////////// ********* ///////////// ********* ///////////// ********* ///////////// ********* ///////////// ********* +///////////// ********* ///////////// ********* ///////////// ********* ///////////// ********* +//////////////// ********* ///////////// ********* /////////////////////// NEIL rand_lib code (with some Gemma rand lib also) -///////////// ********* ///////////// ********* ///////////// ********* ///////////// ********* ///////////// ********* ///////////// ********* +///////////// ********* ///////////// ********* ///////////// ********* ///////////// ********* +//////////////// ********* ///////////// ********* double ranf(void) { @@ -35,14 +37,17 @@ double ranf_mt(int tn) s2 = Xcg2[curntg]; k = s1 / 53668; s1 = Xa1 * (s1 - k * 53668) - k * 12211; - if (s1 < 0) s1 += Xm1; + if (s1 < 0) + s1 += Xm1; k = s2 / 52774; s2 = Xa2 * (s2 - k * 52774) - k * 3791; - if (s2 < 0) s2 += Xm2; + if (s2 < 0) + s2 += Xm2; Xcg1[curntg] = s1; Xcg2[curntg] = s2; z = s1 - s2; - if (z < 1) z += (Xm1 - 1); + if (z < 1) + z += (Xm1 - 1); return ((double)z) / Xm1; } @@ -50,7 +55,7 @@ void setall(int32_t *pseed1, int32_t *pseed2) /* ********************************************************************** void setall(int32_t iseed1,int32_t iseed2) - SET ALL random number generators + SET ALL random number generators Sets the initial seed of generator 1 to ISEED1 and ISEED2. The initial seeds of the other generators are set accordingly, and all generators states are set to these seeds. @@ -60,7 +65,7 @@ void setall(int32_t *pseed1, int32_t *pseed2) with Splitting Facilities." ACM Transactions on Mathematical Software, 17:98-111 (1991) https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.149.9439 - Arguments + Arguments iseed1 -> First of two integer seeds iseed2 -> Second of two integer seeds ********************************************************************** @@ -71,7 +76,8 @@ void setall(int32_t *pseed1, int32_t *pseed2) int32_t iseed1 = *pseed1; int32_t iseed2 = *pseed2; - for (g = 0; g < MAX_NUM_THREADS; g++) { + for (g = 0; g < MAX_NUM_THREADS; g++) + { *(Xcg1 + g * CACHE_LINE_SIZE) = iseed1 = mltmod(Xa1vw, iseed1, Xm1); *(Xcg2 + g * CACHE_LINE_SIZE) = iseed2 = mltmod(Xa2vw, iseed2, Xm2); } @@ -98,59 +104,74 @@ int32_t mltmod(int32_t a, int32_t s, int32_t m) int32_t a0, a1, k, p, q, qh, rh; /* H = 2**((b-2)/2) where b = 32 because we are using a 32 bit - machine. On a different machine recompute H + machine. On a different machine recompute H */ - if (a <= 0 || a >= m || s <= 0 || s >= m) { + if (a <= 0 || a >= m || s <= 0 || s >= m) + { fputs(" a, m, s out of order in mltmod - ABORT!\n", stderr); fprintf(stderr, " a = %12d s = %12d m = %12d\n", a, s, m); fputs(" mltmod requires: 0 < a < m; 0 < s < m\n", stderr); exit(1); } - if (a < h) { + if (a < h) + { a0 = a; p = 0; - } else { + } + else + { a1 = a / h; a0 = a - h * a1; qh = m / h; rh = m - h * qh; - if (a1 >= h) { // a2 == 1 + if (a1 >= h) + { // a2 == 1 a1 -= h; k = s / qh; p = h * (s - k * qh) - k * rh; - while (p < 0) { + while (p < 0) + { p += m; } - } else { + } + else + { p = 0; } // p == (a2 * s * h) MOD m - if (a1 != 0) { + if (a1 != 0) + { q = m / a1; k = s / q; p -= (k * (m - a1 * q)); - if (p > 0) p -= m; + if (p > 0) + p -= m; p += (a1 * (s - k * q)); - while (p < 0) { + while (p < 0) + { p += m; } } // p == ((a2 * h + a1) * s) MOD m k = p / qh; p = h * (p - k * qh) - k * rh; - while (p < 0) { + while (p < 0) + { p += m; } } // p == ((a2 * h + a1) * h * s) MOD m - if (a0 != 0) { + if (a0 != 0) + { q = m / a0; k = s / q; p -= (k * (m - a0 * q)); - if (p > 0) p -= m; + if (p > 0) + p -= m; p += (a0 * (s - k * q)); - while (p < 0) { + while (p < 0) + { p += m; } } @@ -229,14 +250,14 @@ SEPARATION OF CASES A AND B double a6 = -0.1384794; double a7 = 0.125006; /* JJV changed the initial values of MUPREV and MUOLD */ - double fact[10] = { - 1.0,1.0,2.0,6.0,24.0,120.0,720.0,5040.0,40320.0,362880.0 - }; + double fact[10] = {1.0, 1.0, 2.0, 6.0, 24.0, 120.0, 720.0, 5040.0, 40320.0, 362880.0}; /* JJV added ll to the list, for Case A */ int32_t ignpoi_mt, j, k, kflag, l, ll, m; - double b1, b2, c, c0, c1, c2, c3, d, del, difmuk, e, fk, fx, fy, g, omega, p, p0, px, py, q, s, t, u, v, x, xx, pp[35]; + double b1, b2, c, c0, c1, c2, c3, d, del, difmuk, e, fk, fx, fy, g, omega, p, p0, px, py, q, s, t, + u, v, x, xx, pp[35]; - if (mu < 10.0) goto S120; + if (mu < 10.0) + goto S120; /* C A S E A. (RECALCULATION OF S,D,LL IF MU HAS CHANGED) JJV changed l in Case A to ll @@ -254,19 +275,22 @@ SEPARATION OF CASES A AND B STEP N. NORMAL SAMPLE - SNORM(IR) FOR STANDARD NORMAL DEVIATE */ g = mu + s * snorm_mt(tn); - if (g < 0.0) goto S20; + if (g < 0.0) + goto S20; ignpoi_mt = (int32_t)(g); /* STEP I. IMMEDIATE ACCEPTANCE IF IGNPOI IS LARGE ENOUGH */ - if (ignpoi_mt >= ll) return ignpoi_mt; + if (ignpoi_mt >= ll) + return ignpoi_mt; /* STEP S. SQUEEZE ACCEPTANCE - SUNIF(IR) FOR (0,1)-SAMPLE U */ fk = (double)ignpoi_mt; difmuk = mu - fk; u = ranf_mt(tn); - if (d * u >= difmuk * difmuk * difmuk) return ignpoi_mt; + if (d * u >= difmuk * difmuk * difmuk) + return ignpoi_mt; S20: /* STEP P. PREPARATIONS FOR STEPS Q AND H. @@ -285,7 +309,8 @@ SEPARATION OF CASES A AND B c0 = 1.0 - b1 + 3.0 * b2 - 15.0 * c3; c = 0.1069 / mu; - if (g < 0.0) goto S50; + if (g < 0.0) + goto S50; /* 'SUBROUTINE' F IS CALLED (KFLAG=0 FOR CORRECT RETURN) */ @@ -295,7 +320,8 @@ SEPARATION OF CASES A AND B /* STEP Q. QUOTIENT ACCEPTANCE (RARE CASE) */ - if (fy - u * fy <= py * exp(px - fx)) return ignpoi_mt; + if (fy - u * fy <= py * exp(px - fx)) + return ignpoi_mt; S50: /* STEP E. EXPONENTIAL SAMPLE - SEXPO(IR) FOR STANDARD EXPONENTIAL @@ -306,7 +332,8 @@ SEPARATION OF CASES A AND B u = ranf_mt(tn); u += (u - 1.0); t = 1.8 + fsign(e, u); - if (t <= -0.6744) goto S50; + if (t <= -0.6744) + goto S50; ignpoi_mt = (int32_t)(mu + s * t); fk = (double)ignpoi_mt; difmuk = mu - fk; @@ -319,14 +346,16 @@ SEPARATION OF CASES A AND B /* STEP H. HAT ACCEPTANCE (E IS REPEATED ON REJECTION) */ - if (c * fabs(u) > py * exp(px + e) - fy * exp(fx + e)) goto S50; + if (c * fabs(u) > py * exp(px + e) - fy * exp(fx + e)) + goto S50; return ignpoi_mt; S70: /* STEP F. 'SUBROUTINE' F. CALCULATION OF PX,PY,FX,FY. CASE IGNPOI .LT. 10 USES FACTORIALS FROM TABLE FACT */ - if (ignpoi_mt >= 10) goto S80; + if (ignpoi_mt >= 10) + goto S80; px = -mu; py = pow(mu, (double)ignpoi_mt) / *(fact + ignpoi_mt); goto S110; @@ -339,11 +368,14 @@ SEPARATION OF CASES A AND B del = 8.333333E-2 / fk; del -= (4.8 * del * del * del); v = difmuk / fk; - if (fabs(v) <= 0.25) goto S90; + if (fabs(v) <= 0.25) + goto S90; px = fk * log(1.0 + v) - difmuk - del; goto S100; S90: - px = fk * v * v * (((((((a7 * v + a6) * v + a5) * v + a4) * v + a3) * v + a2) * v + a1) * v + a0) - del; + px = + fk * v * v * (((((((a7 * v + a6) * v + a5) * v + a4) * v + a3) * v + a2) * v + a1) * v + a0) - + del; S100: py = 0.3989423 / sqrt(fk); S110: @@ -351,7 +383,8 @@ SEPARATION OF CASES A AND B xx = x * x; fx = -0.5 * xx; fy = omega * (((c3 * xx + c2) * xx + c1) * xx + c0); - if (kflag <= 0) goto S40; + if (kflag <= 0) + goto S40; goto S60; S120: /* @@ -368,30 +401,38 @@ SEPARATION OF CASES A AND B */ u = ranf_mt(tn); ignpoi_mt = 0; - if (u <= p0) return ignpoi_mt; + if (u <= p0) + return ignpoi_mt; /* STEP T. TABLE COMPARISON UNTIL THE END PP(L) OF THE PP-TABLE OF CUMULATIVE POISSON PROBABILITIES (0.458=PP(9) FOR MU=10) */ - if (l == 0) goto S150; + if (l == 0) + goto S150; j = 1; - if (u > 0.458) j = std::min(l, m); - for (k = j; k <= l; k++) { - if (u <= *(pp + k - 1)) goto S180; + if (u > 0.458) + j = std::min(l, m); + for (k = j; k <= l; k++) + { + if (u <= *(pp + k - 1)) + goto S180; } - if (l == 35) goto S130; + if (l == 35) + goto S130; S150: /* STEP C. CREATION OF NEW POISSON PROBABILITIES P AND THEIR CUMULATIVES Q=PP(K) */ l += 1; - for (k = l; k <= 35; k++) { + for (k = l; k <= 35; k++) + { p = p * mu / (double)k; q += p; *(pp + k - 1) = q; - if (u <= q) goto S170; + if (u <= q) + goto S170; } l = 35; goto S130; @@ -509,19 +550,21 @@ TYPE OF ISEED SHOULD BE DICTATED BY THE UNIFORM GENERATOR ********************************************************************** *****DETERMINE APPROPRIATE ALGORITHM AND WHETHER SETUP IS NECESSARY */ -/* JJV changed initial values to ridiculous values */ + /* JJV changed initial values to ridiculous values */ double psave = -1.0E37; int32_t nsave = -214748365; int32_t ignbin_mt, i, ix, ix1, k, m, mp, T1; double al, alv, amaxp, c, f, f1, f2, ffm, fm, g, p, p1, p2, p3, p4, q, qn, r, u, v, w, w2, x, x1, - x2, xl, xll, xlr, xm, xnp, xnpq, xr, ynorm, z, z2; + x2, xl, xll, xlr, xm, xnp, xnpq, xr, ynorm, z, z2; /* *****SETUP, PERFORM ONLY WHEN PARAMETERS CHANGE JJV added checks to ensure 0.0 <= PP <= 1.0 */ - if (pp < 0.0) ERR_CRITICAL("PP < 0.0 in IGNBIN"); - if (pp > 1.0) ERR_CRITICAL("PP > 1.0 in IGNBIN"); + if (pp < 0.0) + ERR_CRITICAL("PP < 0.0 in IGNBIN"); + if (pp > 1.0) + ERR_CRITICAL("PP > 1.0 in IGNBIN"); psave = pp; p = std::min(psave, 1.0 - psave); q = 1.0 - p; @@ -529,10 +572,12 @@ TYPE OF ISEED SHOULD BE DICTATED BY THE UNIFORM GENERATOR /* JJV added check to ensure N >= 0 */ - if (n < 0) ERR_CRITICAL("N < 0 in IGNBIN"); + if (n < 0) + ERR_CRITICAL("N < 0 in IGNBIN"); xnp = n * p; nsave = n; - if (xnp < 30.0) goto S140; + if (xnp < 30.0) + goto S140; ffm = xnp + p; m = (int32_t)ffm; fm = m; @@ -558,26 +603,31 @@ TYPE OF ISEED SHOULD BE DICTATED BY THE UNIFORM GENERATOR /* TRIANGULAR REGION */ - if (u > p1) goto S40; + if (u > p1) + goto S40; ix = (int32_t)(xm - p1 * v + u); goto S170; S40: /* PARALLELOGRAM REGION */ - if (u > p2) goto S50; + if (u > p2) + goto S50; x = xl + (u - p1) / c; v = v * c + 1.0 - std::abs(xm - x) / p1; - if (v > 1.0 || v <= 0.0) goto S30; + if (v > 1.0 || v <= 0.0) + goto S30; ix = (int32_t)x; goto S70; S50: /* LEFT TAIL */ - if (u > p3) goto S60; + if (u > p3) + goto S60; ix = (int32_t)(xl + log(v) / xll); - if (ix < 0) goto S30; + if (ix < 0) + goto S30; v *= ((u - p2) * xll); goto S70; S60: @@ -585,14 +635,16 @@ TYPE OF ISEED SHOULD BE DICTATED BY THE UNIFORM GENERATOR RIGHT TAIL */ ix = (int32_t)(xr - log(v) / xlr); - if (ix > n) goto S30; + if (ix > n) + goto S30; v *= ((u - p3) * xlr); S70: /* *****DETERMINE APPROPRIATE WAY TO PERFORM ACCEPT/REJECT TEST */ k = std::abs(ix - m); - if (k > 20 && k < xnpq / 2 - 1) goto S130; + if (k > 20 && k < xnpq / 2 - 1) + goto S130; /* EXPLICIT EVALUATION */ @@ -600,18 +652,24 @@ TYPE OF ISEED SHOULD BE DICTATED BY THE UNIFORM GENERATOR r = p / q; g = (n + 1) * r; T1 = m - ix; - if (T1 < 0) goto S80; - else if (T1 == 0) goto S120; - else goto S100; + if (T1 < 0) + goto S80; + else if (T1 == 0) + goto S120; + else + goto S100; S80: mp = m + 1; - for (i = mp; i <= ix; i++) f *= (g / i - r); + for (i = mp; i <= ix; i++) + f *= (g / i - r); goto S120; S100: ix1 = ix + 1; - for (i = ix1; i <= m; i++) f /= (g / i - r); + for (i = ix1; i <= m; i++) + f /= (g / i - r); S120: - if (v <= f) goto S170; + if (v <= f) + goto S170; goto S30; S130: /* @@ -620,8 +678,10 @@ TYPE OF ISEED SHOULD BE DICTATED BY THE UNIFORM GENERATOR amaxp = k / xnpq * ((k * (k / 3.0 + 0.625) + 0.1666666666666) / xnpq + 0.5); ynorm = -(k * k / (2.0 * xnpq)); alv = log(v); - if (alv < ynorm - amaxp) goto S170; - if (alv > ynorm + amaxp) goto S30; + if (alv < ynorm - amaxp) + goto S170; + if (alv > ynorm + amaxp) + goto S30; /* STIRLING'S FORMULA TO MACHINE ACCURACY FOR THE FINAL ACCEPTANCE/REJECTION TEST @@ -634,11 +694,13 @@ TYPE OF ISEED SHOULD BE DICTATED BY THE UNIFORM GENERATOR x2 = x1 * x1; f2 = f1 * f1; w2 = w * w; - if (alv <= xm * log(f1 / x1) + (n - m + 0.5) * log(z / w) + (ix - m) * log(w * p / (x1 * q)) + (13860.0 - - (462.0 - (132.0 - (99.0 - 140.0 / f2) / f2) / f2) / f2) / f1 / 166320.0 + (13860.0 - (462.0 - - (132.0 - (99.0 - 140.0 / z2) / z2) / z2) / z2) / z / 166320.0 + (13860.0 - (462.0 - (132.0 - - (99.0 - 140.0 / x2) / x2) / x2) / x2) / x1 / 166320.0 + (13860.0 - (462.0 - (132.0 - (99.0 - - 140.0 / w2) / w2) / w2) / w2) / w / 166320.0) goto S170; + if (alv <= + xm * log(f1 / x1) + (n - m + 0.5) * log(z / w) + (ix - m) * log(w * p / (x1 * q)) + + (13860.0 - (462.0 - (132.0 - (99.0 - 140.0 / f2) / f2) / f2) / f2) / f1 / 166320.0 + + (13860.0 - (462.0 - (132.0 - (99.0 - 140.0 / z2) / z2) / z2) / z2) / z / 166320.0 + + (13860.0 - (462.0 - (132.0 - (99.0 - 140.0 / x2) / x2) / x2) / x2) / x1 / 166320.0 + + (13860.0 - (462.0 - (132.0 - (99.0 - 140.0 / w2) / w2) / w2) / w2) / w / 166320.0) + goto S170; goto S30; S140: /* @@ -652,14 +714,17 @@ TYPE OF ISEED SHOULD BE DICTATED BY THE UNIFORM GENERATOR f = qn; u = ranf_mt(tn); S160: - if (u < f) goto S170; - if (ix > 110) goto S150; + if (u < f) + goto S170; + if (ix > 110) + goto S150; u -= f; ix += 1; f *= (g / ix - r); goto S160; S170: - if (psave > 0.5) ix = n - ix; + if (psave > 0.5) + ix = n - ix; ignbin_mt = ix; return ignbin_mt; } @@ -698,9 +763,10 @@ Q(N) = SUM(ALOG(2.0)**K/K!) K=1,..,N , THE HIGHEST N (HERE 8) IS DETERMINED BY Q(N)=1.0 WITHIN STANDARD PRECISION */ { -// return -log(1 - ranf_mt(tn)); // a much simpler exponential generator! + // return -log(1 - ranf_mt(tn)); // a much simpler exponential generator! - double q[8] = {0.6931472,0.9333737,0.9888778,0.9984959,0.9998293,0.9999833,0.9999986,0.99999999999999989}; + double q[8] = {0.6931472, 0.9333737, 0.9888778, 0.9984959, + 0.9998293, 0.9999833, 0.9999986, 0.99999999999999989}; int32_t i; double sexpo_mt, a, u, ustar, umin; @@ -712,9 +778,11 @@ Q(N) = SUM(ALOG(2.0)**K/K!) K=1,..,N , THE HIGHEST N S30: u += u; - if (u < 1.0) goto S20; + if (u < 1.0) + goto S20; u -= 1.0; - if (u > q[0]) goto S60; + if (u > q[0]) + goto S60; sexpo_mt = a + u; return sexpo_mt; S60: @@ -723,11 +791,12 @@ Q(N) = SUM(ALOG(2.0)**K/K!) K=1,..,N , THE HIGHEST N umin = ustar; S70: ustar = ranf_mt(tn); - if (ustar < umin) umin = ustar; + if (ustar < umin) + umin = ustar; i += 1; - if (u > q[i - 1]) goto S70; - return a + umin * q[0]; - + if (u > q[i - 1]) + goto S70; + return a + umin * q[0]; } double snorm(void) @@ -743,10 +812,10 @@ double snorm(void) FOR DETAILS SEE: - AHRENS, J.H. AND DIETER, U. - EXTENSIONS OF FORSYTHE'S METHOD FOR RANDOM - SAMPLING FROM THE NORMAL DISTRIBUTION. - MATH. COMPUT., 27,124 (OCT. 1973), 927 - 937. + AHRENS, J.H. AND DIETER, U. + EXTENSIONS OF FORSYTHE'S METHOD FOR RANDOM + SAMPLING FROM THE NORMAL DISTRIBUTION. + MATH. COMPUT., 27,124 (OCT. 1973), 927 - 937. ALL STATEMENT NUMBERS CORRESPOND TO THE STEPS OF ALGORITHM 'FL' (M=5) IN THE ABOVE PAPER (SLIGHTLY MODIFIED IMPLEMENTATION) @@ -760,49 +829,48 @@ double snorm(void) */ { static double a[32] = { - 0.0,3.917609E-2,7.841241E-2,0.11777,0.1573107,0.1970991,0.2372021,0.2776904, - 0.3186394,0.36013,0.4022501,0.4450965,0.4887764,0.5334097,0.5791322, - 0.626099,0.6744898,0.7245144,0.7764218,0.8305109,0.8871466,0.9467818, - 1.00999,1.077516,1.150349,1.229859,1.318011,1.417797,1.534121,1.67594, - 1.862732,2.153875 - }; + 0.0, 3.917609E-2, 7.841241E-2, 0.11777, 0.1573107, 0.1970991, 0.2372021, 0.2776904, + 0.3186394, 0.36013, 0.4022501, 0.4450965, 0.4887764, 0.5334097, 0.5791322, 0.626099, + 0.6744898, 0.7245144, 0.7764218, 0.8305109, 0.8871466, 0.9467818, 1.00999, 1.077516, + 1.150349, 1.229859, 1.318011, 1.417797, 1.534121, 1.67594, 1.862732, 2.153875}; static double d[31] = { - 0.0,0.0,0.0,0.0,0.0,0.2636843,0.2425085,0.2255674,0.2116342,0.1999243, - 0.1899108,0.1812252,0.1736014,0.1668419,0.1607967,0.1553497,0.1504094, - 0.1459026,0.14177,0.1379632,0.1344418,0.1311722,0.128126,0.1252791, - 0.1226109,0.1201036,0.1177417,0.1155119,0.1134023,0.1114027,0.1095039 - }; + 0.0, 0.0, 0.0, 0.0, 0.0, 0.2636843, 0.2425085, 0.2255674, + 0.2116342, 0.1999243, 0.1899108, 0.1812252, 0.1736014, 0.1668419, 0.1607967, 0.1553497, + 0.1504094, 0.1459026, 0.14177, 0.1379632, 0.1344418, 0.1311722, 0.128126, 0.1252791, + 0.1226109, 0.1201036, 0.1177417, 0.1155119, 0.1134023, 0.1114027, 0.1095039}; static double t[31] = { - 7.673828E-4,2.30687E-3,3.860618E-3,5.438454E-3,7.0507E-3,8.708396E-3, - 1.042357E-2,1.220953E-2,1.408125E-2,1.605579E-2,1.81529E-2,2.039573E-2, - 2.281177E-2,2.543407E-2,2.830296E-2,3.146822E-2,3.499233E-2,3.895483E-2, - 4.345878E-2,4.864035E-2,5.468334E-2,6.184222E-2,7.047983E-2,8.113195E-2, - 9.462444E-2,0.1123001,0.136498,0.1716886,0.2276241,0.330498,0.5847031 - }; + 7.673828E-4, 2.30687E-3, 3.860618E-3, 5.438454E-3, 7.0507E-3, 8.708396E-3, 1.042357E-2, + 1.220953E-2, 1.408125E-2, 1.605579E-2, 1.81529E-2, 2.039573E-2, 2.281177E-2, 2.543407E-2, + 2.830296E-2, 3.146822E-2, 3.499233E-2, 3.895483E-2, 4.345878E-2, 4.864035E-2, 5.468334E-2, + 6.184222E-2, 7.047983E-2, 8.113195E-2, 9.462444E-2, 0.1123001, 0.136498, 0.1716886, + 0.2276241, 0.330498, 0.5847031}; static double h[31] = { - 3.920617E-2,3.932705E-2,3.951E-2,3.975703E-2,4.007093E-2,4.045533E-2, - 4.091481E-2,4.145507E-2,4.208311E-2,4.280748E-2,4.363863E-2,4.458932E-2, - 4.567523E-2,4.691571E-2,4.833487E-2,4.996298E-2,5.183859E-2,5.401138E-2, - 5.654656E-2,5.95313E-2,6.308489E-2,6.737503E-2,7.264544E-2,7.926471E-2, - 8.781922E-2,9.930398E-2,0.11556,0.1404344,0.1836142,0.2790016,0.7010474 - }; - int32_t i; //made this non-static: ggilani 27/11/14 - double snorm, u, s, ustar, aa, w, y, tt; //made this non-static: ggilani 27/11/14 + 3.920617E-2, 3.932705E-2, 3.951E-2, 3.975703E-2, 4.007093E-2, 4.045533E-2, 4.091481E-2, + 4.145507E-2, 4.208311E-2, 4.280748E-2, 4.363863E-2, 4.458932E-2, 4.567523E-2, 4.691571E-2, + 4.833487E-2, 4.996298E-2, 5.183859E-2, 5.401138E-2, 5.654656E-2, 5.95313E-2, 6.308489E-2, + 6.737503E-2, 7.264544E-2, 7.926471E-2, 8.781922E-2, 9.930398E-2, 0.11556, 0.1404344, + 0.1836142, 0.2790016, 0.7010474}; + int32_t i; // made this non-static: ggilani 27/11/14 + double snorm, u, s, ustar, aa, w, y, tt; // made this non-static: ggilani 27/11/14 u = ranf(); s = 0.0; - if (u > 0.5) s = 1.0; + if (u > 0.5) + s = 1.0; u += (u - s); u = 32.0 * u; i = (int32_t)(u); - if (i == 32) i = 31; - if (i == 0) goto S100; + if (i == 32) + i = 31; + if (i == 0) + goto S100; /* START CENTER */ ustar = u - (double)i; aa = *(a + i - 1); S40: - if (ustar <= *(t + i - 1)) goto S60; + if (ustar <= *(t + i - 1)) + goto S60; w = (ustar - *(t + i - 1)) * *(h + i - 1); S50: /* @@ -810,7 +878,8 @@ double snorm(void) */ y = aa + w; snorm = y; - if (s == 1.0) snorm = -y; + if (s == 1.0) + snorm = -y; return snorm; S60: /* @@ -824,9 +893,11 @@ double snorm(void) tt = u; ustar = ranf(); S80: - if (ustar > tt) goto S50; + if (ustar > tt) + goto S50; u = ranf(); - if (ustar >= u) goto S70; + if (ustar >= u) + goto S70; ustar = ranf(); goto S40; S100: @@ -841,7 +912,8 @@ double snorm(void) i += 1; S120: u += u; - if (u < 1.0) goto S110; + if (u < 1.0) + goto S110; u -= 1.0; S140: w = u * *(d + i - 1); @@ -851,9 +923,11 @@ double snorm(void) tt = u; S160: ustar = ranf(); - if (ustar > tt) goto S50; + if (ustar > tt) + goto S50; u = ranf(); - if (ustar >= u) goto S150; + if (ustar >= u) + goto S150; u = ranf(); goto S140; } @@ -887,49 +961,48 @@ H(K) ARE ACCORDING TO THE ABOVEMENTIONED ARTICLE */ { static double a[32] = { - 0.0,3.917609E-2,7.841241E-2,0.11777,0.1573107,0.1970991,0.2372021,0.2776904, - 0.3186394,0.36013,0.4022501,0.4450965,0.4887764,0.5334097,0.5791322, - 0.626099,0.6744898,0.7245144,0.7764218,0.8305109,0.8871466,0.9467818, - 1.00999,1.077516,1.150349,1.229859,1.318011,1.417797,1.534121,1.67594, - 1.862732,2.153875 - }; + 0.0, 3.917609E-2, 7.841241E-2, 0.11777, 0.1573107, 0.1970991, 0.2372021, 0.2776904, + 0.3186394, 0.36013, 0.4022501, 0.4450965, 0.4887764, 0.5334097, 0.5791322, 0.626099, + 0.6744898, 0.7245144, 0.7764218, 0.8305109, 0.8871466, 0.9467818, 1.00999, 1.077516, + 1.150349, 1.229859, 1.318011, 1.417797, 1.534121, 1.67594, 1.862732, 2.153875}; static double d[31] = { - 0.0,0.0,0.0,0.0,0.0,0.2636843,0.2425085,0.2255674,0.2116342,0.1999243, - 0.1899108,0.1812252,0.1736014,0.1668419,0.1607967,0.1553497,0.1504094, - 0.1459026,0.14177,0.1379632,0.1344418,0.1311722,0.128126,0.1252791, - 0.1226109,0.1201036,0.1177417,0.1155119,0.1134023,0.1114027,0.1095039 - }; + 0.0, 0.0, 0.0, 0.0, 0.0, 0.2636843, 0.2425085, 0.2255674, + 0.2116342, 0.1999243, 0.1899108, 0.1812252, 0.1736014, 0.1668419, 0.1607967, 0.1553497, + 0.1504094, 0.1459026, 0.14177, 0.1379632, 0.1344418, 0.1311722, 0.128126, 0.1252791, + 0.1226109, 0.1201036, 0.1177417, 0.1155119, 0.1134023, 0.1114027, 0.1095039}; static double t[31] = { - 7.673828E-4,2.30687E-3,3.860618E-3,5.438454E-3,7.0507E-3,8.708396E-3, - 1.042357E-2,1.220953E-2,1.408125E-2,1.605579E-2,1.81529E-2,2.039573E-2, - 2.281177E-2,2.543407E-2,2.830296E-2,3.146822E-2,3.499233E-2,3.895483E-2, - 4.345878E-2,4.864035E-2,5.468334E-2,6.184222E-2,7.047983E-2,8.113195E-2, - 9.462444E-2,0.1123001,0.136498,0.1716886,0.2276241,0.330498,0.5847031 - }; + 7.673828E-4, 2.30687E-3, 3.860618E-3, 5.438454E-3, 7.0507E-3, 8.708396E-3, 1.042357E-2, + 1.220953E-2, 1.408125E-2, 1.605579E-2, 1.81529E-2, 2.039573E-2, 2.281177E-2, 2.543407E-2, + 2.830296E-2, 3.146822E-2, 3.499233E-2, 3.895483E-2, 4.345878E-2, 4.864035E-2, 5.468334E-2, + 6.184222E-2, 7.047983E-2, 8.113195E-2, 9.462444E-2, 0.1123001, 0.136498, 0.1716886, + 0.2276241, 0.330498, 0.5847031}; static double h[31] = { - 3.920617E-2,3.932705E-2,3.951E-2,3.975703E-2,4.007093E-2,4.045533E-2, - 4.091481E-2,4.145507E-2,4.208311E-2,4.280748E-2,4.363863E-2,4.458932E-2, - 4.567523E-2,4.691571E-2,4.833487E-2,4.996298E-2,5.183859E-2,5.401138E-2, - 5.654656E-2,5.95313E-2,6.308489E-2,6.737503E-2,7.264544E-2,7.926471E-2, - 8.781922E-2,9.930398E-2,0.11556,0.1404344,0.1836142,0.2790016,0.7010474 - }; + 3.920617E-2, 3.932705E-2, 3.951E-2, 3.975703E-2, 4.007093E-2, 4.045533E-2, 4.091481E-2, + 4.145507E-2, 4.208311E-2, 4.280748E-2, 4.363863E-2, 4.458932E-2, 4.567523E-2, 4.691571E-2, + 4.833487E-2, 4.996298E-2, 5.183859E-2, 5.401138E-2, 5.654656E-2, 5.95313E-2, 6.308489E-2, + 6.737503E-2, 7.264544E-2, 7.926471E-2, 8.781922E-2, 9.930398E-2, 0.11556, 0.1404344, + 0.1836142, 0.2790016, 0.7010474}; int32_t i; double snorm_mt, u, s, ustar, aa, w, y, tt; u = ranf_mt(tn); s = 0.0; - if (u > 0.5) s = 1.0; + if (u > 0.5) + s = 1.0; u += (u - s); u = 32.0 * u; i = (int32_t)(u); - if (i == 32) i = 31; - if (i == 0) goto S100; + if (i == 32) + i = 31; + if (i == 0) + goto S100; /* START CENTER */ ustar = u - (double)i; aa = *(a + i - 1); S40: - if (ustar <= *(t + i - 1)) goto S60; + if (ustar <= *(t + i - 1)) + goto S60; w = (ustar - *(t + i - 1)) * *(h + i - 1); S50: /* @@ -937,7 +1010,8 @@ H(K) ARE ACCORDING TO THE ABOVEMENTIONED ARTICLE */ y = aa + w; snorm_mt = y; - if (s == 1.0) snorm_mt = -y; + if (s == 1.0) + snorm_mt = -y; return snorm_mt; S60: /* @@ -951,9 +1025,11 @@ H(K) ARE ACCORDING TO THE ABOVEMENTIONED ARTICLE tt = u; ustar = ranf_mt(tn); S80: - if (ustar > tt) goto S50; + if (ustar > tt) + goto S50; u = ranf_mt(tn); - if (ustar >= u) goto S70; + if (ustar >= u) + goto S70; ustar = ranf_mt(tn); goto S40; S100: @@ -968,7 +1044,8 @@ H(K) ARE ACCORDING TO THE ABOVEMENTIONED ARTICLE i += 1; S120: u += u; - if (u < 1.0) goto S110; + if (u < 1.0) + goto S110; u -= 1.0; S140: w = u * *(d + i - 1); @@ -978,21 +1055,25 @@ H(K) ARE ACCORDING TO THE ABOVEMENTIONED ARTICLE tt = u; S160: ustar = ranf_mt(tn); - if (ustar > tt) goto S50; + if (ustar > tt) + goto S50; u = ranf_mt(tn); - if (ustar >= u) goto S150; + if (ustar >= u) + goto S150; u = ranf_mt(tn); goto S140; } double fsign(double num, double sign) /* Transfers sign of argument sign to argument num */ { - if ((sign > 0.0f && num < 0.0f) || (sign < 0.0f && num>0.0f)) + if ((sign > 0.0f && num < 0.0f) || (sign < 0.0f && num > 0.0f)) return -num; - else return num; + else + return num; } /*function gen_snorm - * purpose: my own implementation of sampling from a uniform distribution, using Marsaglia polar method, but for multi-threading + * purpose: my own implementation of sampling from a uniform distribution, using Marsaglia polar + * method, but for multi-threading * * author: ggilani, date: 28/11/14 */ @@ -1002,26 +1083,27 @@ double gen_norm_mt(double mu, double sd, int tn) do { - u = 2 * ranf_mt(tn) - 1; //u and v are uniform random numbers on the interval [-1,1] + u = 2 * ranf_mt(tn) - 1; // u and v are uniform random numbers on the interval [-1,1] v = 2 * ranf_mt(tn) - 1; - //calculate S=U^2+V^2 + // calculate S=U^2+V^2 S = u * u + v * v; } while (S >= 1 || S == 0); - //calculate x,y - both of which are normally distributed + // calculate x,y - both of which are normally distributed x = u * sqrt((-2 * log(S)) / S); // This routine can be accelerated by storing the second normal value // and using it for the next call. // y = v * sqrt((-2 * log(S)) / S); - //return x + // return x return x * sd + mu; } /*function gen_gamma_mt - * purpose: my own implementation of sampling from a gamma distribution, using Marsaglia-Tsang method, but for multi-threading + * purpose: my own implementation of sampling from a gamma distribution, using Marsaglia-Tsang + * method, but for multi-threading * * author: ggilani, date: 01/12/14 */ @@ -1029,26 +1111,28 @@ double gen_gamma_mt(double beta, double alpha, int tn) { double d, c, u, v, z, f, alpha2, gamma; - //error statment if either beta or alpha are <=0, as gamma distribution is undefined in this case + // error statment if either beta or alpha are <=0, as gamma distribution is undefined in this case if ((beta <= 0) || (alpha <= 0)) { ERR_CRITICAL("Gamma distribution parameters in undefined range!\n"); } - //method is slightly different depending on whether alpha is greater than or equal to 1, or less than 1 + // method is slightly different depending on whether alpha is greater than or equal to 1, or less + // than 1 if (alpha >= 1) { d = alpha - (1.0 / 3.0); c = 1.0 / (3.0 * sqrt(d)); do { - //sample one random number from uniform distribution and one from standard normal distribution + // sample one random number from uniform distribution and one from standard normal + // distribution u = ranf_mt(tn); z = gen_norm_mt(0, 1, tn); v = 1 + z * c; v = v * v * v; } while ((z <= (-1.0 / c)) || (log(u) >= (0.5 * z * z + d - d * v + d * log(v)))); - //if beta is equal to 1, there is no scale. If beta is not equal to one, return scaled value + // if beta is equal to 1, there is no scale. If beta is not equal to one, return scaled value if (beta != 1) { return (d * v) / beta; @@ -1060,19 +1144,20 @@ double gen_gamma_mt(double beta, double alpha, int tn) } else { - //if alpha is less than 1, initially sample from gamma(beta,alpha+1) + // if alpha is less than 1, initially sample from gamma(beta,alpha+1) alpha2 = alpha + 1; d = alpha2 - (1.0 / 3.0); c = 1.0 / (3.0 * sqrt(d)); do { - //sample one random number from uniform distribution and one from standard normal distribution + // sample one random number from uniform distribution and one from standard normal + // distribution u = ranf_mt(tn); z = gen_norm_mt(0, 1, tn); v = 1 + z * c; v = v * v * v; } while ((z <= (-1.0 / c)) || (log(u) >= (0.5 * z * z + d - d * v + d * log(v)))); - //if beta is equal to 1, there is no scale. If beta is not equal to one, return scaled value + // if beta is equal to 1, there is no scale. If beta is not equal to one, return scaled value if (beta != 1) { gamma = (d * v) / beta; @@ -1081,9 +1166,9 @@ double gen_gamma_mt(double beta, double alpha, int tn) { gamma = d * v; } - //now rescale again to take into account that alpha is less than 1 + // now rescale again to take into account that alpha is less than 1 f = pow(ranf_mt(tn), (1.0 / alpha)); - //return gamma scaled by f + // return gamma scaled by f return gamma * f; } } @@ -1129,11 +1214,12 @@ void SampleWithoutReplacement(int tn, int k, int n) do { SamplingQueue[tn][i] = (int)(ranf_mt(tn) * ((double)n)); -// This original formulation is completely valid, but the PVS Studio analyzer -// notes this, so I am changing it just to get report-clean. -// "V1008 Consider inspecting the 'for' operator. No more than one iteration of the loop will be performed. Rand.cpp 2450" -// for (j = q = 0; (j < i) && (!q); j++) -// q = (SamplingQueue[tn][i] == SamplingQueue[tn][j]); + // This original formulation is completely valid, but the PVS Studio analyzer + // notes this, so I am changing it just to get report-clean. + // "V1008 Consider inspecting the 'for' operator. No more than one iteration of the loop + // will be performed. Rand.cpp 2450" + // for (j = q = 0; (j < i) && (!q); j++) + // q = (SamplingQueue[tn][i] == SamplingQueue[tn][j]); j = q = 0; if (i == 1) q = (SamplingQueue[tn][i] == SamplingQueue[tn][j]); @@ -1191,7 +1277,8 @@ void SampleWithoutReplacement(int tn, int k, int n) { SamplingQueue[tn][q] = i - 1; q++; - if (q >= b) i = q = 0; + if (q >= b) + i = q = 0; } else if (q < k) i = q = 0; @@ -1236,12 +1323,12 @@ void SampleWithoutReplacement(int tn, int k, int n) for(i=0;i k) + */ + while (q > k) { i = (int)(ranf_mt(tn) * ((double)q)); - if (i < q - 1) SamplingQueue[tn][i] = SamplingQueue[tn][q - 1]; + if (i < q - 1) + SamplingQueue[tn][i] = SamplingQueue[tn][q - 1]; q--; } - } - diff --git a/src/Rand.h b/src/Rand.h index 6be2e8f16..c6ae4d95f 100644 --- a/src/Rand.h +++ b/src/Rand.h @@ -13,7 +13,7 @@ const int32_t Xa2vw = 784306273; /* RANDLIB global variables */ extern int **SamplingQueue; -extern int32_t* Xcg1, *Xcg2; +extern int32_t *Xcg1, *Xcg2; /* RANDLIB functions */ int32_t ignbin(int32_t, double); int32_t ignpoi(double); @@ -28,10 +28,10 @@ int32_t mltmod(int32_t, int32_t, int32_t); double snorm(void); double snorm_mt(int); double fsign(double, double); -//added some new beta, gamma generating functions: ggilani 27/11/14 +// added some new beta, gamma generating functions: ggilani 27/11/14 double gen_norm_mt(double, double, int); double gen_gamma_mt(double, double, int); -//added some new lognormal sampling functions: ggilani 09/02/17 +// added some new lognormal sampling functions: ggilani 09/02/17 double gen_lognormal(double, double); void SampleWithoutReplacement(int, int, int); diff --git a/src/SetupModel.cpp b/src/SetupModel.cpp index e0e858102..ce5b269a5 100644 --- a/src/SetupModel.cpp +++ b/src/SetupModel.cpp @@ -1,38 +1,38 @@ #include +#include +#include #include #include -#include -#include #include "BinIO.h" -#include "Error.h" -#include "Rand.h" -#include "Kernels.h" +#include "Bitmap.h" #include "Constants.h" #include "Dist.h" -#include "Param.h" -#include "SetupModel.h" +#include "Error.h" +#include "InfStat.h" +#include "Kernels.h" #include "Model.h" #include "ModelMacros.h" -#include "InfStat.h" -#include "Bitmap.h" +#include "Param.h" +#include "Rand.h" +#include "SetupModel.h" -void* BinFileBuf; -BinFile* BF; +void *BinFileBuf; +BinFile *BF; int netbuf[NUM_PLACE_TYPES * 1000000]; - ///// INITIALIZE / SET UP FUNCTIONS -void SetupModel(char* DensityFile, char* NetworkFile, char* SchoolFile, char* RegDemogFile) +void SetupModel(char *DensityFile, char *NetworkFile, char *SchoolFile, char *RegDemogFile) { int l, m, j2, l2, m2; unsigned int rn; double t, s, s2, s3, t2, t3, d, q; char buf[2048]; - FILE* dat; + FILE *dat; - if (!(Xcg1 = (int32_t*)malloc(MAX_NUM_THREADS * CACHE_LINE_SIZE * sizeof(int32_t))) || - !(Xcg2 = (int32_t*)malloc(MAX_NUM_THREADS * CACHE_LINE_SIZE * sizeof(int32_t)))) ERR_CRITICAL("Unable to allocate ranf storage\n"); + if (!(Xcg1 = (int32_t *)malloc(MAX_NUM_THREADS * CACHE_LINE_SIZE * sizeof(int32_t))) || + !(Xcg2 = (int32_t *)malloc(MAX_NUM_THREADS * CACHE_LINE_SIZE * sizeof(int32_t)))) + ERR_CRITICAL("Unable to allocate ranf storage\n"); P.nextSetupSeed1 = P.setupSeed1; P.nextSetupSeed2 = P.setupSeed2; setall(&P.nextSetupSeed1, &P.nextSetupSeed2); @@ -41,16 +41,19 @@ void SetupModel(char* DensityFile, char* NetworkFile, char* SchoolFile, char* Re if (P.DoHeteroDensity) { fprintf(stderr, "Scanning population density file\n"); - if (!(dat = fopen(DensityFile, "rb"))) ERR_CRITICAL("Unable to open density file\n"); + if (!(dat = fopen(DensityFile, "rb"))) + ERR_CRITICAL("Unable to open density file\n"); unsigned int density_file_header; fread_big(&density_file_header, sizeof(unsigned int), 1, dat); - if (density_file_header == 0xf0f0f0f0) //code for first 4 bytes of binary file ## NOTE - SHOULD BE LONG LONG TO COPE WITH BIGGER POPULATIONS + if (density_file_header == 0xf0f0f0f0) // code for first 4 bytes of binary file ## NOTE - SHOULD + // BE LONG LONG TO COPE WITH BIGGER POPULATIONS { P.DoBin = 1; fread_big(&(P.BinFileLen), sizeof(unsigned int), 1, dat); - if (!(BinFileBuf = (void*)malloc(P.BinFileLen * sizeof(BinFile)))) ERR_CRITICAL("Unable to allocate binary file buffer\n"); + if (!(BinFileBuf = (void *)malloc(P.BinFileLen * sizeof(BinFile)))) + ERR_CRITICAL("Unable to allocate binary file buffer\n"); fread_big(BinFileBuf, sizeof(BinFile), (size_t)P.BinFileLen, dat); - BF = (BinFile*)BinFileBuf; + BF = (BinFile *)BinFileBuf; fclose(dat); } else @@ -59,37 +62,44 @@ void SetupModel(char* DensityFile, char* NetworkFile, char* SchoolFile, char* Re // Count the number of lines in the density file rewind(dat); P.BinFileLen = 0; - while(fgets(buf, sizeof(buf), dat) != NULL) P.BinFileLen++; - if(ferror(dat)) ERR_CRITICAL("Error while reading density file\n"); + while (fgets(buf, sizeof(buf), dat) != NULL) + P.BinFileLen++; + if (ferror(dat)) + ERR_CRITICAL("Error while reading density file\n"); // Read each line, and build the binary structure that corresponds to it rewind(dat); - if (!(BinFileBuf = (void*)malloc(P.BinFileLen * sizeof(BinFile)))) ERR_CRITICAL("Unable to allocate binary file buffer\n"); - BF = (BinFile*)BinFileBuf; + if (!(BinFileBuf = (void *)malloc(P.BinFileLen * sizeof(BinFile)))) + ERR_CRITICAL("Unable to allocate binary file buffer\n"); + BF = (BinFile *)BinFileBuf; int index = 0; - while(fgets(buf, sizeof(buf), dat) != NULL) + while (fgets(buf, sizeof(buf), dat) != NULL) { int i2; double x, y; // This shouldn't be able to happen, as we just counted the number of lines: - if (index == P.BinFileLen) ERR_CRITICAL("Too many input lines while reading density file\n"); + if (index == P.BinFileLen) + ERR_CRITICAL("Too many input lines while reading density file\n"); if (P.DoAdUnits) { sscanf(buf, "%lg %lg %lg %i %i", &x, &y, &t, &i2, &l); if (l / P.CountryDivisor != i2) { - //fprintf(stderr,"# %lg %lg %lg %i %i\n",x,y,t,i2,l); + // fprintf(stderr,"# %lg %lg %lg %i %i\n",x,y,t,i2,l); } } - else { + else + { sscanf(buf, "%lg %lg %lg %i", &x, &y, &t, &i2); l = 0; } // Ensure we use an x which gives us a contiguous whole for the // geography. - if (x >= P.LongitudeCutLine) { + if (x >= P.LongitudeCutLine) + { BF[index].x = x; } - else { + else + { BF[index].x = x + 360; } BF[index].y = y; @@ -98,9 +108,11 @@ void SetupModel(char* DensityFile, char* NetworkFile, char* SchoolFile, char* Re BF[index].ad = l; index++; } - if(ferror(dat)) ERR_CRITICAL("Error while reading density file\n"); + if (ferror(dat)) + ERR_CRITICAL("Error while reading density file\n"); // This shouldn't be able to happen, as we just counted the number of lines: - if (index != P.BinFileLen) ERR_CRITICAL("Too few input lines while reading density file\n"); + if (index != P.BinFileLen) + ERR_CRITICAL("Too few input lines while reading density file\n"); fclose(dat); } @@ -129,20 +141,28 @@ void SetupModel(char* DensityFile, char* NetworkFile, char* SchoolFile, char* Re s2 += t; // Adjust the bounds of the spatial bounding box so that they include the location // for this block of population. - if (x < P.SpatialBoundingBox[0]) P.SpatialBoundingBox[0] = x; - if (x >= P.SpatialBoundingBox[2]) P.SpatialBoundingBox[2] = x + 1e-6; - if (y < P.SpatialBoundingBox[1]) P.SpatialBoundingBox[1] = y; - if (y >= P.SpatialBoundingBox[3]) P.SpatialBoundingBox[3] = y + 1e-6; + if (x < P.SpatialBoundingBox[0]) + P.SpatialBoundingBox[0] = x; + if (x >= P.SpatialBoundingBox[2]) + P.SpatialBoundingBox[2] = x + 1e-6; + if (y < P.SpatialBoundingBox[1]) + P.SpatialBoundingBox[1] = y; + if (y >= P.SpatialBoundingBox[3]) + P.SpatialBoundingBox[3] = y + 1e-6; } } - if (!P.DoSpecifyPop) P.PopSize = (int)s2; + if (!P.DoSpecifyPop) + P.PopSize = (int)s2; } P.in_cells_.height = P.in_cells_.width; - P.SpatialBoundingBox[0] = floor(P.SpatialBoundingBox[0] / P.in_cells_.width) * P.in_cells_.width; - P.SpatialBoundingBox[1] = floor(P.SpatialBoundingBox[1] / P.in_cells_.height) * P.in_cells_.height; + P.SpatialBoundingBox[0] = + floor(P.SpatialBoundingBox[0] / P.in_cells_.width) * P.in_cells_.width; + P.SpatialBoundingBox[1] = + floor(P.SpatialBoundingBox[1] / P.in_cells_.height) * P.in_cells_.height; P.SpatialBoundingBox[2] = ceil(P.SpatialBoundingBox[2] / P.in_cells_.width) * P.in_cells_.width; - P.SpatialBoundingBox[3] = ceil(P.SpatialBoundingBox[3] / P.in_cells_.height) * P.in_cells_.height; + P.SpatialBoundingBox[3] = + ceil(P.SpatialBoundingBox[3] / P.in_cells_.height) * P.in_cells_.height; P.in_degrees_.width = P.SpatialBoundingBox[2] - P.SpatialBoundingBox[0]; P.in_degrees_.height = P.SpatialBoundingBox[3] - P.SpatialBoundingBox[1]; P.ncw = 4 * ((int)ceil(P.in_degrees_.width / P.in_cells_.width / 4)); @@ -152,14 +172,19 @@ void SetupModel(char* DensityFile, char* NetworkFile, char* SchoolFile, char* Re P.SpatialBoundingBox[2] = P.SpatialBoundingBox[0] + P.in_degrees_.width; P.SpatialBoundingBox[3] = P.SpatialBoundingBox[1] + P.in_degrees_.height; P.NC = P.ncw * P.nch; - fprintf(stderr, "Adjusted bounding box = (%lg, %lg)- (%lg, %lg)\n", P.SpatialBoundingBox[0], P.SpatialBoundingBox[1], P.SpatialBoundingBox[2], P.SpatialBoundingBox[3]); + fprintf(stderr, "Adjusted bounding box = (%lg, %lg)- (%lg, %lg)\n", P.SpatialBoundingBox[0], + P.SpatialBoundingBox[1], P.SpatialBoundingBox[2], P.SpatialBoundingBox[3]); fprintf(stderr, "Number of cells = %i (%i x %i)\n", P.NC, P.ncw, P.nch); fprintf(stderr, "Population size = %i \n", P.PopSize); - if (P.in_degrees_.width > 180) { - fprintf(stderr, "WARNING: Width of bounding box > 180 degrees. Results may be inaccurate.\n"); + if (P.in_degrees_.width > 180) + { + fprintf(stderr, + "WARNING: Width of bounding box > 180 degrees. Results may be inaccurate.\n"); } - if (P.in_degrees_.height > 90) { - fprintf(stderr, "WARNING: Height of bounding box > 90 degrees. Results may be inaccurate.\n"); + if (P.in_degrees_.height > 90) + { + fprintf(stderr, + "WARNING: Height of bounding box > 90 degrees. Results may be inaccurate.\n"); } s = 1; P.DoPeriodicBoundaries = 0; @@ -202,27 +227,38 @@ void SetupModel(char* DensityFile, char* NetworkFile, char* SchoolFile, char* Re t = dist2_raw(0, 0, P.in_degrees_.width, P.in_degrees_.height); double tw = dist2_raw(0, 0, P.in_degrees_.width, 0); double th = dist2_raw(0, 0, 0, P.in_degrees_.height); - if (tw > t) t = tw; - if (th > t) t = th; - if (P.DoPeriodicBoundaries) t *= 0.25; - if (!(nKernel = (double*)calloc(P.NKR + 1, sizeof(double))) || - !(nKernelHR = (double*)calloc(P.NKR + 1, sizeof(double)))) ERR_CRITICAL("Unable to allocate kernel storage\n"); + if (tw > t) + t = tw; + if (th > t) + t = th; + if (P.DoPeriodicBoundaries) + t *= 0.25; + if (!(nKernel = (double *)calloc(P.NKR + 1, sizeof(double))) || + !(nKernelHR = (double *)calloc(P.NKR + 1, sizeof(double)))) + ERR_CRITICAL("Unable to allocate kernel storage\n"); P.KernelDelta = t / P.NKR; - // fprintf(stderr,"** %i %lg %lg %lg %lg | %lg %lg %lg %lg \n",P.DoUTM_coords,P.SpatialBoundingBox[0],P.SpatialBoundingBox[1],P.SpatialBoundingBox[2],P.SpatialBoundingBox[3],P.width,P.height,t,P.KernelDelta); - fprintf(stderr, "Coords xmcell=%lg m ymcell = %lg m\n", - sqrt(dist2_raw(P.in_degrees_.width / 2, P.in_degrees_.height / 2, P.in_degrees_.width / 2 + P.in_microcells_.width, P.in_degrees_.height / 2)), - sqrt(dist2_raw(P.in_degrees_.width / 2, P.in_degrees_.height / 2, P.in_degrees_.width / 2, P.in_degrees_.height / 2 + P.in_microcells_.height))); + // fprintf(stderr,"** %i %lg %lg %lg %lg | %lg %lg %lg %lg + //\n",P.DoUTM_coords,P.SpatialBoundingBox[0],P.SpatialBoundingBox[1],P.SpatialBoundingBox[2],P.SpatialBoundingBox[3],P.width,P.height,t,P.KernelDelta); + fprintf( + stderr, "Coords xmcell=%lg m ymcell = %lg m\n", + sqrt(dist2_raw(P.in_degrees_.width / 2, P.in_degrees_.height / 2, + P.in_degrees_.width / 2 + P.in_microcells_.width, P.in_degrees_.height / 2)), + sqrt(dist2_raw(P.in_degrees_.width / 2, P.in_degrees_.height / 2, P.in_degrees_.width / 2, + P.in_degrees_.height / 2 + P.in_microcells_.height))); t2 = 0.0; SetupPopulation(SchoolFile, RegDemogFile); - if (!(TimeSeries = (Results*)calloc(P.NumSamples, sizeof(Results))) || - !(TSMeanE = (Results*)calloc(P.NumSamples, sizeof(Results))) || - !(TSVarE = (Results*)calloc(P.NumSamples, sizeof(Results))) || - !(TSMeanNE = (Results*)calloc(P.NumSamples, sizeof(Results))) || - !(TSVarNE = (Results*)calloc(P.NumSamples, sizeof(Results)))) ERR_CRITICAL("Unable to allocate results storage\n"); - TSMean = TSMeanE; TSVar = TSVarE; - ///// This loops over index l twice just to reset the pointer TSMean from TSMeanE to TSMeanNE (same for TSVar). + if (!(TimeSeries = (Results *)calloc(P.NumSamples, sizeof(Results))) || + !(TSMeanE = (Results *)calloc(P.NumSamples, sizeof(Results))) || + !(TSVarE = (Results *)calloc(P.NumSamples, sizeof(Results))) || + !(TSMeanNE = (Results *)calloc(P.NumSamples, sizeof(Results))) || + !(TSVarNE = (Results *)calloc(P.NumSamples, sizeof(Results)))) + ERR_CRITICAL("Unable to allocate results storage\n"); + TSMean = TSMeanE; + TSVar = TSVarE; + ///// This loops over index l twice just to reset the pointer TSMean from TSMeanE to TSMeanNE + ///(same for TSVar). int num_in_results = sizeof(Results) / sizeof(double); for (l = 0; l < 2; l++) { @@ -230,46 +266,48 @@ void SetupModel(char* DensityFile, char* NetworkFile, char* SchoolFile, char* Re { double *ts_mean = (double *)&TSMean[i]; double *ts_var = (double *)&TSVar[i]; - for (int j = 0; j < num_in_results; j++) ts_mean[j] = ts_var[j] = 0.0; + for (int j = 0; j < num_in_results; j++) + ts_mean[j] = ts_var[j] = 0.0; } - TSMean = TSMeanNE; TSVar = TSVarNE; + TSMean = TSMeanNE; + TSVar = TSVarNE; } if (P.DoAdUnits && P.OutputAdUnitAge) { // initialize State age and admin unit breakdowns - State.prevInf_age_adunit = new int* [NUM_AGE_GROUPS](); - State.cumInf_age_adunit = new int* [NUM_AGE_GROUPS](); + State.prevInf_age_adunit = new int *[NUM_AGE_GROUPS](); + State.cumInf_age_adunit = new int *[NUM_AGE_GROUPS](); for (int AgeGroup = 0; AgeGroup < NUM_AGE_GROUPS; AgeGroup++) { State.prevInf_age_adunit[AgeGroup] = new int[P.NumAdunits](); - State.cumInf_age_adunit [AgeGroup] = new int[P.NumAdunits](); + State.cumInf_age_adunit[AgeGroup] = new int[P.NumAdunits](); } // initialize threaded State age and admin unit breakdowns for (int Thread = 0; Thread < P.NumThreads; Thread++) { - StateT[Thread].prevInf_age_adunit = new int* [NUM_AGE_GROUPS](); - StateT[Thread].cumInf_age_adunit = new int* [NUM_AGE_GROUPS](); + StateT[Thread].prevInf_age_adunit = new int *[NUM_AGE_GROUPS](); + StateT[Thread].cumInf_age_adunit = new int *[NUM_AGE_GROUPS](); for (int AgeGroup = 0; AgeGroup < NUM_AGE_GROUPS; AgeGroup++) { StateT[Thread].prevInf_age_adunit[AgeGroup] = new int[P.NumAdunits](); - StateT[Thread].cumInf_age_adunit [AgeGroup] = new int[P.NumAdunits](); + StateT[Thread].cumInf_age_adunit[AgeGroup] = new int[P.NumAdunits](); } } // initialize TimeSeries age and admin unit breakdowns for (int Time = 0; Time < P.NumSamples; Time++) { - TimeSeries[Time].prevInf_age_adunit = new double* [NUM_AGE_GROUPS](); - TimeSeries[Time].incInf_age_adunit = new double* [NUM_AGE_GROUPS](); - TimeSeries[Time].cumInf_age_adunit = new double* [NUM_AGE_GROUPS](); - TSMeanE [Time].prevInf_age_adunit = new double* [NUM_AGE_GROUPS](); - TSMeanE [Time].incInf_age_adunit = new double* [NUM_AGE_GROUPS](); - TSMeanE [Time].cumInf_age_adunit = new double* [NUM_AGE_GROUPS](); - TSMeanNE[Time].prevInf_age_adunit = new double* [NUM_AGE_GROUPS](); - TSMeanNE[Time].incInf_age_adunit = new double* [NUM_AGE_GROUPS](); - TSMeanNE[Time].cumInf_age_adunit = new double* [NUM_AGE_GROUPS](); + TimeSeries[Time].prevInf_age_adunit = new double *[NUM_AGE_GROUPS](); + TimeSeries[Time].incInf_age_adunit = new double *[NUM_AGE_GROUPS](); + TimeSeries[Time].cumInf_age_adunit = new double *[NUM_AGE_GROUPS](); + TSMeanE[Time].prevInf_age_adunit = new double *[NUM_AGE_GROUPS](); + TSMeanE[Time].incInf_age_adunit = new double *[NUM_AGE_GROUPS](); + TSMeanE[Time].cumInf_age_adunit = new double *[NUM_AGE_GROUPS](); + TSMeanNE[Time].prevInf_age_adunit = new double *[NUM_AGE_GROUPS](); + TSMeanNE[Time].incInf_age_adunit = new double *[NUM_AGE_GROUPS](); + TSMeanNE[Time].cumInf_age_adunit = new double *[NUM_AGE_GROUPS](); for (int AgeGroup = 0; AgeGroup < NUM_AGE_GROUPS; AgeGroup++) { @@ -286,14 +324,16 @@ void SetupModel(char* DensityFile, char* NetworkFile, char* SchoolFile, char* Re } } - //added memory allocation and initialisation of infection event log, if DoRecordInfEvents is set to 1: ggilani - 10/10/2014 + // added memory allocation and initialisation of infection event log, if DoRecordInfEvents is set + // to 1: ggilani - 10/10/2014 if (P.DoRecordInfEvents) { - if (!(InfEventLog = (Events*)calloc(P.MaxInfEvents, sizeof(Events)))) ERR_CRITICAL("Unable to allocate events storage\n"); + if (!(InfEventLog = (Events *)calloc(P.MaxInfEvents, sizeof(Events)))) + ERR_CRITICAL("Unable to allocate events storage\n"); } - - if(P.OutputNonSeverity) SaveAgeDistrib(); + if (P.OutputNonSeverity) + SaveAgeDistrib(); fprintf(stderr, "Initialising places...\n"); if (P.DoPlaces) @@ -306,10 +346,10 @@ void SetupModel(char* DensityFile, char* NetworkFile, char* SchoolFile, char* Re if ((P.DoPlaces) && (P.LoadSaveNetwork == 2)) SavePeopleToPlaces(NetworkFile); - //SaveDistribs(); + // SaveDistribs(); - // From here on, we want the same random numbers regardless of whether we used the RNG to make the network, - // or loaded the network from a file. Therefore we need to reseed the RNG. + // From here on, we want the same random numbers regardless of whether we used the RNG to make the + // network, or loaded the network from a file. Therefore we need to reseed the RNG. setall(&P.nextSetupSeed1, &P.nextSetupSeed2); StratifyPlaces(); @@ -317,9 +357,10 @@ void SetupModel(char* DensityFile, char* NetworkFile, char* SchoolFile, char* Re { Cells[i].S = Cells[i].n; Cells[i].L = Cells[i].I = Cells[i].R = 0; - //Cells[i].susceptible=Cells[i].members; //added this line + // Cells[i].susceptible=Cells[i].members; //added this line } - for (int i = 0; i < P.PopSize; i++) Hosts[i].keyworker = 0; + for (int i = 0; i < P.PopSize; i++) + Hosts[i].keyworker = 0; P.KeyWorkerNum = P.KeyWorkerIncHouseNum = m = l = 0; fprintf(stderr, "Initialising kernel...\n"); @@ -366,7 +407,8 @@ void SetupModel(char* DensityFile, char* NetworkFile, char* SchoolFile, char* Re for (int i2 = 0; (m < P.KeyWorkerPlaceNum[j]) && (i2 < Places[j][k].n); i2++) { int i = Places[j][k].members[i2]; - if ((i < 0) || (i >= P.PopSize)) fprintf(stderr, "## %i # ", i); + if ((i < 0) || (i >= P.PopSize)) + fprintf(stderr, "## %i # ", i); if ((Hosts[i].keyworker) || (ranf_mt(0) >= P.KeyWorkerPropInKeyPlaces[j])) l++; else @@ -388,10 +430,12 @@ void SetupModel(char* DensityFile, char* NetworkFile, char* SchoolFile, char* Re } } } - if (P.KeyWorkerNum > 0) fprintf(stderr, "%i key workers selected in total\n", P.KeyWorkerNum); + if (P.KeyWorkerNum > 0) + fprintf(stderr, "%i key workers selected in total\n", P.KeyWorkerNum); if (P.DoAdUnits) { - for (int i = 0; i < P.NumAdunits; i++) AdUnits[i].NP = 0; + for (int i = 0; i < P.NumAdunits; i++) + AdUnits[i].NP = 0; for (int j = 0; j < P.PlaceTypeNum; j++) if (P.PlaceCloseAdunitPlaceTypes[j] > 0) { @@ -402,17 +446,18 @@ void SetupModel(char* DensityFile, char* NetworkFile, char* SchoolFile, char* Re } fprintf(stderr, "Places intialised.\n"); - //Set up the population for digital contact tracing here... - ggilani 09/03/20 + // Set up the population for digital contact tracing here... - ggilani 09/03/20 if (P.DoDigitalContactTracing) { P.NDigitalContactUsers = 0; - l = m=0; - //if clustering by Households + l = m = 0; + // if clustering by Households if (P.DoHouseholds && P.ClusterDigitalContactUsers) { - //Loop through households + // Loop through households - //NOTE: Are we still okay with this kind of openmp parallelisation. I know there have been some discussions re:openmp, but not followed them completely + // NOTE: Are we still okay with this kind of openmp parallelisation. I know there have been + // some discussions re:openmp, but not followed them completely l = m = 0; #pragma omp parallel for schedule(static,1) reduction(+:l,m) default(none) \ shared(P, Households, Hosts) @@ -422,16 +467,17 @@ void SetupModel(char* DensityFile, char* NetworkFile, char* SchoolFile, char* Re { if (ranf_mt(tn) < P.PropPopUsingDigitalContactTracing) { - //select this household for digital contact app use - //loop through household members and check whether they will be selected for use + // select this household for digital contact app use + // loop through household members and check whether they will be selected for use int i1 = Households[i].FirstPerson; int i2 = i1 + Households[i].nh; for (int j = i1; j < i2; j++) { - //get age of host + // get age of host int age = HOST_AGE_GROUP(j); - if (age >= NUM_AGE_GROUPS) age = NUM_AGE_GROUPS - 1; - //check to see if host will be a user based on age group + if (age >= NUM_AGE_GROUPS) + age = NUM_AGE_GROUPS - 1; + // check to see if host will be a user based on age group if (ranf_mt(tn) < P.ProportionSmartphoneUsersByAge[age]) { Hosts[j].digitalContactTracingUser = 1; @@ -444,23 +490,29 @@ void SetupModel(char* DensityFile, char* NetworkFile, char* SchoolFile, char* Re } P.NDigitalContactUsers = l; P.NDigitalHouseholdUsers = m; - fprintf(stderr, "Number of digital contact tracing households: %i, out of total number of households: %i\n", P.NDigitalHouseholdUsers, P.NH); - fprintf(stderr, "Number of digital contact tracing users: %i, out of population size: %i\n", P.NDigitalContactUsers, P.PopSize); - } - else // Just go through the population and assign people to the digital contact tracing app based on probability by age. + fprintf(stderr, + "Number of digital contact tracing households: %i, out of total number of " + "households: %i\n", + P.NDigitalHouseholdUsers, P.NH); + fprintf(stderr, "Number of digital contact tracing users: %i, out of population size: %i\n", + P.NDigitalContactUsers, P.PopSize); + } + else // Just go through the population and assign people to the digital contact tracing app + // based on probability by age. { - //for use with non-clustered + // for use with non-clustered l = 0; -#pragma omp parallel for schedule(static,1) reduction(+:l) default(none) \ - shared(P, Hosts) +#pragma omp parallel for schedule(static, 1) reduction(+ : l) default(none) shared(P, Hosts) for (int tn = 0; tn < P.NumThreads; tn++) { for (int i = tn; i < P.PopSize; i += P.NumThreads) { int age = HOST_AGE_GROUP(i); - if (age >= NUM_AGE_GROUPS) age = NUM_AGE_GROUPS - 1; + if (age >= NUM_AGE_GROUPS) + age = NUM_AGE_GROUPS - 1; - if (ranf_mt(tn) < (P.ProportionSmartphoneUsersByAge[age] * P.PropPopUsingDigitalContactTracing)) + if (ranf_mt(tn) < + (P.ProportionSmartphoneUsersByAge[age] * P.PropPopUsingDigitalContactTracing)) { Hosts[i].digitalContactTracingUser = 1; l++; @@ -468,12 +520,14 @@ void SetupModel(char* DensityFile, char* NetworkFile, char* SchoolFile, char* Re } } P.NDigitalContactUsers = l; - fprintf(stderr, "Number of digital contact tracing users: %i, out of population size: %i\n", P.NDigitalContactUsers, P.PopSize); + fprintf(stderr, "Number of digital contact tracing users: %i, out of population size: %i\n", + P.NDigitalContactUsers, P.PopSize); } } UpdateProbs(0); - if (P.DoAirports) SetupAirports(); + if (P.DoAirports) + SetupAirports(); if (P.R0scale != 1.0) { P.HouseholdTrans *= P.R0scale; @@ -498,41 +552,60 @@ void SetupModel(char* DensityFile, char* NetworkFile, char* SchoolFile, char* Re for (int i = tn; i < P.PopSize; i += P.NumThreads) { if (P.SusceptibilitySD == 0) - Hosts[i].susc = (float)((P.DoPartialImmunity) ? (1.0 - P.InitialImmunity[HOST_AGE_GROUP(i)]) : 1.0); + Hosts[i].susc = + (float)((P.DoPartialImmunity) ? (1.0 - P.InitialImmunity[HOST_AGE_GROUP(i)]) : 1.0); else - Hosts[i].susc = (float) (((P.DoPartialImmunity) ? (1.0 - P.InitialImmunity[HOST_AGE_GROUP(i)]) : 1.0) * gen_gamma_mt(1 / (P.SusceptibilitySD * P.SusceptibilitySD), 1 / (P.SusceptibilitySD * P.SusceptibilitySD), tn)); + Hosts[i].susc = + (float)(((P.DoPartialImmunity) ? (1.0 - P.InitialImmunity[HOST_AGE_GROUP(i)]) : 1.0) * + gen_gamma_mt(1 / (P.SusceptibilitySD * P.SusceptibilitySD), + 1 / (P.SusceptibilitySD * P.SusceptibilitySD), tn)); if (P.InfectiousnessSD == 0) Hosts[i].infectiousness = (float)P.AgeInfectiousness[HOST_AGE_GROUP(i)]; else - Hosts[i].infectiousness = (float)(P.AgeInfectiousness[HOST_AGE_GROUP(i)] * gen_gamma_mt(1 / (P.InfectiousnessSD * P.InfectiousnessSD), 1 / (P.InfectiousnessSD * P.InfectiousnessSD), tn)); + Hosts[i].infectiousness = + (float)(P.AgeInfectiousness[HOST_AGE_GROUP(i)] * + gen_gamma_mt(1 / (P.InfectiousnessSD * P.InfectiousnessSD), + 1 / (P.InfectiousnessSD * P.InfectiousnessSD), tn)); q = P.ProportionSymptomatic[HOST_AGE_GROUP(i)]; if (ranf_mt(tn) < q) Hosts[i].infectiousness = (float)(-P.SymptInfectiousness * Hosts[i].infectiousness); int j = (int)floor((q = ranf_mt(tn) * CDF_RES)); q -= ((double)j); - Hosts[i].recovery_or_death_time = (unsigned short int) floor(0.5 - (P.InfectiousPeriod * log(q * P.infectious_icdf[j + 1] + (1.0 - q) * P.infectious_icdf[j]) / P.TimeStep)); + Hosts[i].recovery_or_death_time = (unsigned short int)floor( + 0.5 - + (P.InfectiousPeriod * + log(q * P.infectious_icdf[j + 1] + (1.0 - q) * P.infectious_icdf[j]) / P.TimeStep)); if (P.DoHouseholds) { - s2 = P.TimeStep * P.HouseholdTrans * fabs(Hosts[i].infectiousness) * P.HouseholdDenomLookup[Households[Hosts[i].hh].nhr - 1]; - d = 1.0; l = (int)Hosts[i].recovery_or_death_time; - for (int k = 0; k < l; k++) { + s2 = P.TimeStep * P.HouseholdTrans * fabs(Hosts[i].infectiousness) * + P.HouseholdDenomLookup[Households[Hosts[i].hh].nhr - 1]; + d = 1.0; + l = (int)Hosts[i].recovery_or_death_time; + for (int k = 0; k < l; k++) + { double y = 1.0 - s2 * P.infectiousness[k]; d *= ((y < 0) ? 0 : y); } l = Households[Hosts[i].hh].FirstPerson; m = l + Households[Hosts[i].hh].nh; - for (int k = l; k < m; k++) if ((Hosts[k].inf == InfStat_Susceptible) && (k != i)) s += (1 - d) * P.AgeSusceptibility[HOST_AGE_GROUP(i)]; + for (int k = l; k < m; k++) + if ((Hosts[k].inf == InfStat_Susceptible) && (k != i)) + s += (1 - d) * P.AgeSusceptibility[HOST_AGE_GROUP(i)]; } - q = (P.LatentToSymptDelay > Hosts[i].recovery_or_death_time * P.TimeStep) ? Hosts[i].recovery_or_death_time * P.TimeStep : P.LatentToSymptDelay; + q = (P.LatentToSymptDelay > Hosts[i].recovery_or_death_time * P.TimeStep) + ? Hosts[i].recovery_or_death_time * P.TimeStep + : P.LatentToSymptDelay; s2 = fabs(Hosts[i].infectiousness) * P.RelativeSpatialContact[HOST_AGE_GROUP(i)] * P.TimeStep; l = (int)(q / P.TimeStep); int k; - for (k = 0; k < l; k++) t2 += s2 * P.infectiousness[k]; + for (k = 0; k < l; k++) + t2 += s2 * P.infectiousness[k]; s2 *= ((Hosts[i].infectiousness < 0) ? P.SymptSpatialContactRate : 1); l = (int)Hosts[i].recovery_or_death_time; - for (; k < l; k++) t2 += s2 * P.infectiousness[k]; + for (; k < l; k++) + t2 += s2 * P.infectiousness[k]; } } t2 *= (s3 / ((double)P.PopSize)); @@ -550,32 +623,44 @@ void SetupModel(char* DensityFile, char* NetworkFile, char* SchoolFile, char* Re int k = Hosts[i].PlaceLinks[j]; if (k >= 0) { - q = (P.LatentToSymptDelay > Hosts[i].recovery_or_death_time * P.TimeStep) ? Hosts[i].recovery_or_death_time * P.TimeStep : P.LatentToSymptDelay; + q = (P.LatentToSymptDelay > Hosts[i].recovery_or_death_time * P.TimeStep) + ? Hosts[i].recovery_or_death_time * P.TimeStep + : P.LatentToSymptDelay; s2 = fabs(Hosts[i].infectiousness) * P.TimeStep * P.PlaceTypeTrans[j]; double x = s2 / P.PlaceTypeGroupSizeParam1[j]; - d = 1.0; l = (int)(q / P.TimeStep); - for (m = 0; m < l; m++) { + d = 1.0; + l = (int)(q / P.TimeStep); + for (m = 0; m < l; m++) + { double y = 1.0 - x * P.infectiousness[m]; d *= ((y < 0) ? 0 : y); } s3 = ((double)(Places[j][k].group_size[Hosts[i].PlaceGroupLinks[j]] - 1)); - x *= ((Hosts[i].infectiousness < 0) ? (P.SymptPlaceTypeContactRate[j] * (1 - P.SymptPlaceTypeWithdrawalProp[j])) : 1); + x *= ((Hosts[i].infectiousness < 0) + ? (P.SymptPlaceTypeContactRate[j] * (1 - P.SymptPlaceTypeWithdrawalProp[j])) + : 1); l = (int)Hosts[i].recovery_or_death_time; - for (; m < l; m++) { + for (; m < l; m++) + { double y = 1.0 - x * P.infectiousness[m]; d *= ((y < 0) ? 0 : y); } t3 = d; x = P.PlaceTypePropBetweenGroupLinks[j] * s2 / ((double)Places[j][k].n); - d = 1.0; l = (int)(q / P.TimeStep); - for (m = 0; m < l; m++) { + d = 1.0; + l = (int)(q / P.TimeStep); + for (m = 0; m < l; m++) + { double y = 1.0 - x * P.infectiousness[m]; d *= ((y < 0) ? 0 : y); } - x *= ((Hosts[i].infectiousness < 0) ? (P.SymptPlaceTypeContactRate[j] * (1 - P.SymptPlaceTypeWithdrawalProp[j])) : 1); + x *= ((Hosts[i].infectiousness < 0) + ? (P.SymptPlaceTypeContactRate[j] * (1 - P.SymptPlaceTypeWithdrawalProp[j])) + : 1); l = (int)Hosts[i].recovery_or_death_time; - for (; m < l; m++) { + for (; m < l; m++) + { double y = 1.0 - x * P.infectiousness[m]; d *= ((y < 0) ? 0 : y); } @@ -598,8 +683,10 @@ void SetupModel(char* DensityFile, char* NetworkFile, char* SchoolFile, char* Re t /= ((double)P.PopSize); recovery_time_days /= ((double)P.PopSize); recovery_time_timesteps /= ((double)P.PopSize); - fprintf(stderr, "R0 for places = %lg\nR0 for random spatial = %lg\nOverall R0=%lg\n", P.R0places = t, P.R0spatial = P.R0 - s - t, P.R0); - fprintf(stderr, "Mean infectious period (sampled) = %lg (%lg)\n", recovery_time_days, recovery_time_timesteps); + fprintf(stderr, "R0 for places = %lg\nR0 for random spatial = %lg\nOverall R0=%lg\n", + P.R0places = t, P.R0spatial = P.R0 - s - t, P.R0); + fprintf(stderr, "Mean infectious period (sampled) = %lg (%lg)\n", recovery_time_days, + recovery_time_timesteps); } if (P.DoSI) P.LocalBeta = (P.R0 / t2 - s - t); @@ -611,10 +698,13 @@ void SetupModel(char* DensityFile, char* NetworkFile, char* SchoolFile, char* Re fprintf(stderr, "Reset spatial R0 to 0\n"); } fprintf(stderr, "LocalBeta = %lg\n", P.LocalBeta); - TSMean = TSMeanNE; TSVar = TSVarNE; + TSMean = TSMeanNE; + TSVar = TSVarNE; fprintf(stderr, "Calculated approx cell probabilities\n"); - for (int i = 0; i < INFECT_TYPE_MASK; i++) inftype_av[i] = 0; - for (int i = 0; i < MAX_COUNTRIES; i++) infcountry_av[i] = infcountry_num[i] = 0; + for (int i = 0; i < INFECT_TYPE_MASK; i++) + inftype_av[i] = 0; + for (int i = 0; i < MAX_COUNTRIES; i++) + infcountry_av[i] = infcountry_num[i] = 0; for (int i = 0; i < MAX_SEC_REC; i++) for (int j = 0; j < MAX_GEN_REC; j++) indivR0_av[i][j] = 0; @@ -622,19 +712,25 @@ void SetupModel(char* DensityFile, char* NetworkFile, char* SchoolFile, char* Re for (int j = 0; j <= MAX_HOUSEHOLD_SIZE; j++) inf_household_av[i][j] = case_household_av[i][j] = 0; DoInitUpdateProbs = 1; - for (int i = 0; i < P.NC; i++) Cells[i].tot_treat = 1; //This makes sure InitModel intialises the cells. + for (int i = 0; i < P.NC; i++) + Cells[i].tot_treat = 1; // This makes sure InitModel intialises the cells. P.NRactE = P.NRactNE = 0; - for (int i = 0; i < P.PopSize; i++) Hosts[i].esocdist_comply = (ranf() < P.EnhancedSocDistProportionCompliant[HOST_AGE_GROUP(i)]) ? 1 : 0; + for (int i = 0; i < P.PopSize; i++) + Hosts[i].esocdist_comply = + (ranf() < P.EnhancedSocDistProportionCompliant[HOST_AGE_GROUP(i)]) ? 1 : 0; if (P.EnhancedSocDistClusterByHousehold) { - for (int i = 0; i < P.NH;i++) + for (int i = 0; i < P.NH; i++) { l = Households[i].FirstPerson; m = l + Households[i].nh; int i2 = 0; - for (int k = l; k < m; k++) if (Hosts[k].esocdist_comply) i2=1; + for (int k = l; k < m; k++) + if (Hosts[k].esocdist_comply) + i2 = 1; if (i2) - for (int k = l; k < m; k++) Hosts[k].esocdist_comply = 1; + for (int k = l; k < m; k++) + Hosts[k].esocdist_comply = 1; } } @@ -644,11 +740,13 @@ void SetupModel(char* DensityFile, char* NetworkFile, char* SchoolFile, char* Re } if (P.DoMassVacc) { - if (!(State.mvacc_queue = (int*)calloc(P.PopSize, sizeof(int)))) ERR_CRITICAL("Unable to allocate host storage\n"); + if (!(State.mvacc_queue = (int *)calloc(P.PopSize, sizeof(int)))) + ERR_CRITICAL("Unable to allocate host storage\n"); int queueIndex = 0; for (int i = 0; i < P.PopSize; i++) { - if ((HOST_AGE_YEAR(i) >= P.VaccPriorityGroupAge[0]) && (HOST_AGE_YEAR(i) <= P.VaccPriorityGroupAge[1])) + if ((HOST_AGE_YEAR(i) >= P.VaccPriorityGroupAge[0]) && + (HOST_AGE_YEAR(i) <= P.VaccPriorityGroupAge[1])) { if (ranf() < P.VaccProp) State.mvacc_queue[queueIndex++] = i; @@ -657,7 +755,8 @@ void SetupModel(char* DensityFile, char* NetworkFile, char* SchoolFile, char* Re int vaccineCount = queueIndex; for (int i = 0; i < P.PopSize; i++) { - if ((HOST_AGE_YEAR(i) < P.VaccPriorityGroupAge[0]) || (HOST_AGE_YEAR(i) > P.VaccPriorityGroupAge[1])) + if ((HOST_AGE_YEAR(i) < P.VaccPriorityGroupAge[0]) || + (HOST_AGE_YEAR(i) > P.VaccPriorityGroupAge[1])) { if (ranf() < P.VaccProp) State.mvacc_queue[queueIndex++] = i; @@ -687,13 +786,16 @@ void SetupModel(char* DensityFile, char* NetworkFile, char* SchoolFile, char* Re PeakHeightSum = PeakHeightSS = PeakTimeSum = PeakTimeSS = 0; int i = (P.ncw / 2) * P.nch + P.nch / 2; int j = (P.ncw / 2 + 2) * P.nch + P.nch / 2; - fprintf(stderr, "UTM dist horiz=%lg %lg\n", sqrt(dist2_cc(Cells + i, Cells + j)), sqrt(dist2_cc(Cells + j, Cells + i))); + fprintf(stderr, "UTM dist horiz=%lg %lg\n", sqrt(dist2_cc(Cells + i, Cells + j)), + sqrt(dist2_cc(Cells + j, Cells + i))); j = (P.ncw / 2) * P.nch + P.nch / 2 + 2; - fprintf(stderr, "UTM dist vert=%lg %lg\n", sqrt(dist2_cc(Cells + i, Cells + j)), sqrt(dist2_cc(Cells + j, Cells + i))); + fprintf(stderr, "UTM dist vert=%lg %lg\n", sqrt(dist2_cc(Cells + i, Cells + j)), + sqrt(dist2_cc(Cells + j, Cells + i))); j = (P.ncw / 2 + 2) * P.nch + P.nch / 2 + 2; - fprintf(stderr, "UTM dist diag=%lg %lg\n", sqrt(dist2_cc(Cells + i, Cells + j)), sqrt(dist2_cc(Cells + j, Cells + i))); + fprintf(stderr, "UTM dist diag=%lg %lg\n", sqrt(dist2_cc(Cells + i, Cells + j)), + sqrt(dist2_cc(Cells + j, Cells + i))); - //if(P.OutputBitmap) + // if(P.OutputBitmap) //{ // CaptureBitmap(); // OutputBitmap(0); @@ -701,24 +803,26 @@ void SetupModel(char* DensityFile, char* NetworkFile, char* SchoolFile, char* Re fprintf(stderr, "Model configuration complete.\n"); } -void SetupPopulation(char* SchoolFile, char* RegDemogFile) +void SetupPopulation(char *SchoolFile, char *RegDemogFile) { int j, l, m, i2, j2, last_i, mr, ad, country; unsigned int rn, rn2; double t, s, x, y, xh, yh, maxd, CumAgeDist[NUM_AGE_GROUPS + 1]; char buf[4096], *col; const char delimiters[] = " \t,"; - FILE* dat = NULL, *dat2; + FILE *dat = NULL, *dat2; BinFile rec; double *mcell_dens; int *mcell_adunits, *mcell_num, *mcell_country; - if (!(Cells = (Cell*)calloc(P.NC, sizeof(Cell)))) ERR_CRITICAL("Unable to allocate cell storage\n"); - if (!(Mcells = (Microcell*)calloc(P.NMC, sizeof(Microcell))) || - !(mcell_num = (int*)malloc(P.NMC * sizeof(int))) || - !(mcell_dens = (double*)malloc(P.NMC * sizeof(double))) || - !(mcell_country = (int*)malloc(P.NMC * sizeof(int))) || - !(mcell_adunits = (int*)malloc(P.NMC * sizeof(int)))) ERR_CRITICAL("Unable to allocate microcell storage\n"); + if (!(Cells = (Cell *)calloc(P.NC, sizeof(Cell)))) + ERR_CRITICAL("Unable to allocate cell storage\n"); + if (!(Mcells = (Microcell *)calloc(P.NMC, sizeof(Microcell))) || + !(mcell_num = (int *)malloc(P.NMC * sizeof(int))) || + !(mcell_dens = (double *)malloc(P.NMC * sizeof(double))) || + !(mcell_country = (int *)malloc(P.NMC * sizeof(int))) || + !(mcell_adunits = (int *)malloc(P.NMC * sizeof(int)))) + ERR_CRITICAL("Unable to allocate microcell storage\n"); for (j = 0; j < P.NMC; j++) { @@ -732,13 +836,18 @@ void SetupPopulation(char* SchoolFile, char* RegDemogFile) P.PopByAdunit[i][0] = P.PopByAdunit[i][1] = 0; if (P.DoHeteroDensity) { - if (!P.DoAdunitBoundaries) P.NumAdunits = 0; + if (!P.DoAdunitBoundaries) + P.NumAdunits = 0; // if(!(dat2=fopen("EnvTest.txt","w"))) ERR_CRITICAL("Unable to open test file\n"); fprintf(stderr, "Density file contains %i datapoints.\n", (int)P.BinFileLen); for (rn = rn2 = mr = 0; rn < P.BinFileLen; rn++) { int k; - x = BF[rn].x; y = BF[rn].y; t = BF[rn].pop; country = BF[rn].cnt; j2 = BF[rn].ad; + x = BF[rn].x; + y = BF[rn].y; + t = BF[rn].pop; + country = BF[rn].cnt; + j2 = BF[rn].ad; rec = BF[rn]; if (P.DoAdUnits) { @@ -767,7 +876,8 @@ void SetupPopulation(char* SchoolFile, char* RegDemogFile) AdUnits[P.NumAdunits].id = j2; AdUnits[P.NumAdunits].cnt_id = country; P.NumAdunits++; - if (P.NumAdunits >= MAX_ADUNITS) ERR_CRITICAL("Total number of administrative units exceeds MAX_ADUNITS\n"); + if (P.NumAdunits >= MAX_ADUNITS) + ERR_CRITICAL("Total number of administrative units exceeds MAX_ADUNITS\n"); } else { @@ -779,7 +889,8 @@ void SetupPopulation(char* SchoolFile, char* RegDemogFile) { k = 1; } - if ((k) && (x >= P.SpatialBoundingBox[0]) && (y >= P.SpatialBoundingBox[1]) && (x < P.SpatialBoundingBox[2]) && (y < P.SpatialBoundingBox[3])) + if ((k) && (x >= P.SpatialBoundingBox[0]) && (y >= P.SpatialBoundingBox[1]) && + (x < P.SpatialBoundingBox[2]) && (y < P.SpatialBoundingBox[3])) { j = (int)floor((x - P.SpatialBoundingBox[0]) / P.in_microcells_.width + 0.1); k = (int)floor((y - P.SpatialBoundingBox[1]) / P.in_microcells_.height + 0.1); @@ -789,19 +900,21 @@ void SetupPopulation(char* SchoolFile, char* RegDemogFile) mr++; mcell_dens[l] += t; mcell_country[l] = country; - //fprintf(stderr,"mcell %i, country %i, pop %lg\n",l,country,t); + // fprintf(stderr,"mcell %i, country %i, pop %lg\n",l,country,t); mcell_num[l]++; if (P.DoAdUnits) { mcell_adunits[l] = P.AdunitLevel1Lookup[m]; - if (mcell_adunits[l] < 0) fprintf(stderr, "Microcell %i has adunits<0\n", l); + if (mcell_adunits[l] < 0) + fprintf(stderr, "Microcell %i has adunits<0\n", l); P.PopByAdunit[P.AdunitLevel1Lookup[m]][0] += t; } else mcell_adunits[l] = 0; if ((P.OutputDensFile) && (P.DoBin) && (mcell_adunits[l] >= 0)) { - if (rn2 < rn) BF[rn2] = rec; + if (rn2 < rn) + BF[rn2] = rec; rn2++; } } @@ -809,7 +922,8 @@ void SetupPopulation(char* SchoolFile, char* RegDemogFile) } // fclose(dat2); fprintf(stderr, "%i valid microcells read from density file.\n", mr); - if ((P.OutputDensFile) && (P.DoBin)) P.BinFileLen = rn2; + if ((P.OutputDensFile) && (P.DoBin)) + P.BinFileLen = rn2; if (P.DoBin == 0) { if (P.OutputDensFile) @@ -818,16 +932,22 @@ void SetupPopulation(char* SchoolFile, char* RegDemogFile) P.DoBin = 1; P.BinFileLen = 0; for (l = 0; l < P.NMC; l++) - if (mcell_adunits[l] >= 0) P.BinFileLen++; - if (!(BinFileBuf = (void*)malloc(P.BinFileLen * sizeof(BinFile)))) ERR_CRITICAL("Unable to allocate binary file buffer\n"); - BF = (BinFile*)BinFileBuf; + if (mcell_adunits[l] >= 0) + P.BinFileLen++; + if (!(BinFileBuf = (void *)malloc(P.BinFileLen * sizeof(BinFile)))) + ERR_CRITICAL("Unable to allocate binary file buffer\n"); + BF = (BinFile *)BinFileBuf; fprintf(stderr, "Binary density file should contain %i microcells.\n", (int)P.BinFileLen); rn = 0; for (l = 0; l < P.NMC; l++) if (mcell_adunits[l] >= 0) { - BF[rn].x = (double)(P.in_microcells_.width * (((double)(l / P.get_number_of_micro_cells_high())) + 0.5)) + P.SpatialBoundingBox[0]; //x - BF[rn].y = (double)(P.in_microcells_.height * (((double)(l % P.get_number_of_micro_cells_high())) + 0.5)) + P.SpatialBoundingBox[1]; //y + BF[rn].x = (double)(P.in_microcells_.width * + (((double)(l / P.get_number_of_micro_cells_high())) + 0.5)) + + P.SpatialBoundingBox[0]; // x + BF[rn].y = (double)(P.in_microcells_.height * + (((double)(l % P.get_number_of_micro_cells_high())) + 0.5)) + + P.SpatialBoundingBox[1]; // y BF[rn].ad = (P.DoAdUnits) ? (AdUnits[mcell_adunits[l]].id) : 0; BF[rn].pop = mcell_dens[l]; BF[rn].cnt = mcell_country[l]; @@ -838,11 +958,12 @@ void SetupPopulation(char* SchoolFile, char* RegDemogFile) if (P.OutputDensFile) { - if (!(dat2 = fopen(OutDensFile, "wb"))) ERR_CRITICAL("Unable to open output density file\n"); + if (!(dat2 = fopen(OutDensFile, "wb"))) + ERR_CRITICAL("Unable to open output density file\n"); rn = 0xf0f0f0f0; - fwrite_big((void*)& rn, sizeof(unsigned int), 1, dat2); + fwrite_big((void *)&rn, sizeof(unsigned int), 1, dat2); fprintf(stderr, "Saving population density file with NC=%i...\n", (int)P.BinFileLen); - fwrite_big((void*) & (P.BinFileLen), sizeof(unsigned int), 1, dat2); + fwrite_big((void *)&(P.BinFileLen), sizeof(unsigned int), 1, dat2); fwrite_big(BinFileBuf, sizeof(BinFile), (size_t)P.BinFileLen, dat2); fclose(dat2); } @@ -874,13 +995,17 @@ void SetupPopulation(char* SchoolFile, char* RegDemogFile) } maxd = ((double)P.NMC); } - if (!P.DoAdUnits) P.NumAdunits = 1; + if (!P.DoAdUnits) + P.NumAdunits = 1; if ((P.DoAdUnits) && (P.DoAdunitDemog)) { - if (!(State.InvAgeDist = (int**)malloc(P.NumAdunits * sizeof(int*)))) ERR_CRITICAL("Unable to allocate InvAgeDist storage\n"); + if (!(State.InvAgeDist = (int **)malloc(P.NumAdunits * sizeof(int *)))) + ERR_CRITICAL("Unable to allocate InvAgeDist storage\n"); for (int i = 0; i < P.NumAdunits; i++) - if (!(State.InvAgeDist[i] = (int*)malloc(1000 * sizeof(int)))) ERR_CRITICAL("Unable to allocate InvAgeDist storage\n"); - if (!(dat = fopen(RegDemogFile, "rb"))) ERR_CRITICAL("Unable to open regional demography file\n"); + if (!(State.InvAgeDist[i] = (int *)malloc(1000 * sizeof(int)))) + ERR_CRITICAL("Unable to allocate InvAgeDist storage\n"); + if (!(dat = fopen(RegDemogFile, "rb"))) + ERR_CRITICAL("Unable to open regional demography file\n"); for (int k = 0; k < P.NumAdunits; k++) { for (int i = 0; i < NUM_AGE_GROUPS; i++) @@ -937,8 +1062,10 @@ void SetupPopulation(char* SchoolFile, char* RegDemogFile) for (int i = j = 0; i < 1000; i++) { t = ((double)i) / 1000; - while (t >= CumAgeDist[j + 1]) j++; - t = AGE_GROUP_WIDTH * (((double)j) + (t - CumAgeDist[j]) / (CumAgeDist[j + 1] - CumAgeDist[j])); + while (t >= CumAgeDist[j + 1]) + j++; + t = AGE_GROUP_WIDTH * + (((double)j) + (t - CumAgeDist[j]) / (CumAgeDist[j + 1] - CumAgeDist[j])); State.InvAgeDist[k][i] = (int)t; } State.InvAgeDist[k][1000 - 1] = NUM_AGE_GROUPS * AGE_GROUP_WIDTH - 1; @@ -949,7 +1076,8 @@ void SetupPopulation(char* SchoolFile, char* RegDemogFile) t += P.HouseholdSizeDistrib[k][i]; P.HouseholdSizeDistrib[k][0] /= t; for (int i = 1; i < MAX_HOUSEHOLD_SIZE - 1; i++) - P.HouseholdSizeDistrib[k][i] = P.HouseholdSizeDistrib[k][i] / t + P.HouseholdSizeDistrib[k][i - 1]; + P.HouseholdSizeDistrib[k][i] = + P.HouseholdSizeDistrib[k][i] / t + P.HouseholdSizeDistrib[k][i - 1]; P.HouseholdSizeDistrib[k][MAX_HOUSEHOLD_SIZE - 1] = 1.0; } else @@ -961,34 +1089,42 @@ void SetupPopulation(char* SchoolFile, char* RegDemogFile) } else { - if (!(State.InvAgeDist = (int**)malloc(sizeof(int*))) || - !(State.InvAgeDist[0] = (int*)malloc(1000 * sizeof(int)))) ERR_CRITICAL("Unable to allocate InvAgeDist storage\n"); + if (!(State.InvAgeDist = (int **)malloc(sizeof(int *))) || + !(State.InvAgeDist[0] = (int *)malloc(1000 * sizeof(int)))) + ERR_CRITICAL("Unable to allocate InvAgeDist storage\n"); CumAgeDist[0] = 0; for (int i = 1; i <= NUM_AGE_GROUPS; i++) CumAgeDist[i] = CumAgeDist[i - 1] + P.PropAgeGroup[0][i - 1]; for (int i = j = 0; i < 1000; i++) { t = ((double)i) / 1000; - if (t >= CumAgeDist[j + 1]) j++; - t = AGE_GROUP_WIDTH * (((double)j) + (t - CumAgeDist[j]) / (CumAgeDist[j + 1] - CumAgeDist[j])); + if (t >= CumAgeDist[j + 1]) + j++; + t = AGE_GROUP_WIDTH * + (((double)j) + (t - CumAgeDist[j]) / (CumAgeDist[j + 1] - CumAgeDist[j])); State.InvAgeDist[0][i] = (int)t; } State.InvAgeDist[0][1000 - 1] = NUM_AGE_GROUPS * AGE_GROUP_WIDTH - 1; } if (P.DoAdUnits) - for (int i = 0; i < P.NumAdunits; i++) AdUnits[i].n = 0; + for (int i = 0; i < P.NumAdunits; i++) + AdUnits[i].n = 0; if ((P.DoAdUnits) && (P.DoAdunitDemog) && (P.DoCorrectAdunitPop)) { for (int i = 0; i < P.NumAdunits; i++) - fprintf(stderr, "%i\t%i\t%lg\t%lg\n", i, (AdUnits[i].id % P.AdunitLevel1Mask) / P.AdunitLevel1Divisor, P.PropAgeGroup[i][0], P.HouseholdSizeDistrib[i][0]); + fprintf(stderr, "%i\t%i\t%lg\t%lg\n", i, + (AdUnits[i].id % P.AdunitLevel1Mask) / P.AdunitLevel1Divisor, P.PropAgeGroup[i][0], + P.HouseholdSizeDistrib[i][0]); maxd = 0; for (int i = 0; i < P.NMC; i++) { if (mcell_num[i] > 0) - { - if (mcell_adunits[i] < 0) ERR_CRITICAL_FMT("Cell %i has adunits < 0 (indexing PopByAdunit)\n", i); - mcell_dens[i] *= P.PopByAdunit[mcell_adunits[i]][1] / (1e-10 + P.PopByAdunit[mcell_adunits[i]][0]); - } + { + if (mcell_adunits[i] < 0) + ERR_CRITICAL_FMT("Cell %i has adunits < 0 (indexing PopByAdunit)\n", i); + mcell_dens[i] *= + P.PopByAdunit[mcell_adunits[i]][1] / (1e-10 + P.PopByAdunit[mcell_adunits[i]][0]); + } maxd += mcell_dens[i]; } t = 0; @@ -1002,12 +1138,15 @@ void SetupPopulation(char* SchoolFile, char* RegDemogFile) for (int i = m = 0; i < (P.NMC - 1); i++) { s = mcell_dens[i] / maxd / t; - if (s > 1.0) s = 1.0; + if (s > 1.0) + s = 1.0; m += (Mcells[i].n = (int)ignbin_mt((int32_t)(P.PopSize - m), s, 0)); t -= mcell_dens[i] / maxd; - if (Mcells[i].n > 0) { + if (Mcells[i].n > 0) + { P.NMCP++; - if (mcell_adunits[i] < 0) ERR_CRITICAL_FMT("Cell %i has adunits < 0 (indexing AdUnits)\n", i); + if (mcell_adunits[i] < 0) + ERR_CRITICAL_FMT("Cell %i has adunits < 0 (indexing AdUnits)\n", i); AdUnits[mcell_adunits[i]].n += Mcells[i].n; } } @@ -1024,8 +1163,10 @@ void SetupPopulation(char* SchoolFile, char* RegDemogFile) free(mcell_adunits); t = 0.0; - if (!(McellLookup = (Microcell * *)malloc(P.NMCP * sizeof(Microcell*)))) ERR_CRITICAL("Unable to allocate microcell storage\n"); - if (!(State.CellMemberArray = (int*)malloc(P.PopSize * sizeof(int)))) ERR_CRITICAL("Unable to allocate cell storage\n"); + if (!(McellLookup = (Microcell **)malloc(P.NMCP * sizeof(Microcell *)))) + ERR_CRITICAL("Unable to allocate microcell storage\n"); + if (!(State.CellMemberArray = (int *)malloc(P.PopSize * sizeof(int)))) + ERR_CRITICAL("Unable to allocate cell storage\n"); P.NCP = 0; for (int i = i2 = j2 = 0; i < P.NC; i++) { @@ -1039,21 +1180,26 @@ void SetupPopulation(char* SchoolFile, char* RegDemogFile) if (Mcells[j].n > 0) { Mcells[j].members = State.CellMemberArray + j2; - //if(!(Mcells[j].members=(int *) calloc(Mcells[j].n,sizeof(int)))) ERR_CRITICAL("Unable to allocate cell storage\n"); //replaced line above with this to ensure members don't get mixed across microcells + // if(!(Mcells[j].members=(int *) calloc(Mcells[j].n,sizeof(int)))) ERR_CRITICAL("Unable + // to allocate cell storage\n"); //replaced line above with this to ensure members don't + // get mixed across microcells McellLookup[i2++] = Mcells + j; Cells[i].n += Mcells[j].n; j2 += Mcells[j].n; } } - if (Cells[i].n > 0) P.NCP++; + if (Cells[i].n > 0) + P.NCP++; } fprintf(stderr, "Number of hosts assigned = %i\n", j2); - if (!P.DoAdUnits) P.AdunitLevel1Lookup[0] = 0; + if (!P.DoAdUnits) + P.AdunitLevel1Lookup[0] = 0; fprintf(stderr, "Number of cells with non-zero population = %i\n", P.NCP); fprintf(stderr, "Number of microcells with non-zero population = %i\n", P.NMCP); - if (!(CellLookup = (Cell * *)malloc(P.NCP * sizeof(Cell*))) || - !(State.CellSuscMemberArray = (int*)malloc(P.PopSize * sizeof(int)))) ERR_CRITICAL("Unable to allocate cell storage\n"); + if (!(CellLookup = (Cell **)malloc(P.NCP * sizeof(Cell *))) || + !(State.CellSuscMemberArray = (int *)malloc(P.PopSize * sizeof(int)))) + ERR_CRITICAL("Unable to allocate cell storage\n"); int susceptibleAccumulator = 0; i2 = 0; for (j = 0; j < P.NC; j++) @@ -1063,34 +1209,40 @@ void SetupPopulation(char* SchoolFile, char* RegDemogFile) Cells[j].susceptible = State.CellSuscMemberArray + susceptibleAccumulator; susceptibleAccumulator += Cells[j].n; } - if (i2 > P.NCP) fprintf(stderr, "######## Over-run on CellLookup array NCP=%i i2=%i ###########\n", P.NCP, i2); + if (i2 > P.NCP) + fprintf(stderr, "######## Over-run on CellLookup array NCP=%i i2=%i ###########\n", P.NCP, i2); i2 = 0; - if (!(Hosts = (Person*)calloc(P.PopSize, sizeof(Person)))) ERR_CRITICAL("Unable to allocate host storage\n"); - fprintf(stderr, "sizeof(Person)=%i\n", (int) sizeof(Person)); + if (!(Hosts = (Person *)calloc(P.PopSize, sizeof(Person)))) + ERR_CRITICAL("Unable to allocate host storage\n"); + fprintf(stderr, "sizeof(Person)=%i\n", (int)sizeof(Person)); for (int i = 0; i < P.NCP; i++) { Cell *c = CellLookup[i]; if (c->n > 0) { - if (!(c->InvCDF = (int*)malloc(1025 * sizeof(int))) || - !(c->max_trans = (float*)malloc(P.NCP * sizeof(float))) || - !(c->cum_trans = (float*)malloc(P.NCP * sizeof(float)))) ERR_CRITICAL("Unable to allocate cell storage\n"); + if (!(c->InvCDF = (int *)malloc(1025 * sizeof(int))) || + !(c->max_trans = (float *)malloc(P.NCP * sizeof(float))) || + !(c->cum_trans = (float *)malloc(P.NCP * sizeof(float)))) + ERR_CRITICAL("Unable to allocate cell storage\n"); } } for (int i = 0; i < P.NC; i++) { Cells[i].cumTC = 0; - for (j = 0; j < Cells[i].n; j++) Cells[i].members[j] = -1; + for (j = 0; j < Cells[i].n; j++) + Cells[i].members[j] = -1; } fprintf(stderr, "Cells assigned\n"); - for (int i = 0; i <= MAX_HOUSEHOLD_SIZE; i++) denom_household[i] = 0; + for (int i = 0; i <= MAX_HOUSEHOLD_SIZE; i++) + denom_household[i] = 0; P.NH = 0; int numberOfPeople = 0; for (j2 = 0; j2 < P.NMCP; j2++) { j = (int)(McellLookup[j2] - Mcells); - l = ((j / P.get_number_of_micro_cells_high()) / P.NMCL) * P.nch + ((j % P.get_number_of_micro_cells_high()) / P.NMCL); + l = ((j / P.get_number_of_micro_cells_high()) / P.NMCL) * P.nch + + ((j % P.get_number_of_micro_cells_high()) / P.NMCL); ad = ((P.DoAdunitDemog) && (P.DoAdUnits)) ? Mcells[j].adunit : 0; for (int k = 0; k < Mcells[j].n;) { @@ -1098,13 +1250,15 @@ void SetupPopulation(char* SchoolFile, char* RegDemogFile) if (P.DoHouseholds) { s = ranf_mt(0); - while ((s > P.HouseholdSizeDistrib[ad][m - 1]) && (k + m < Mcells[j].n) && (m < MAX_HOUSEHOLD_SIZE)) m++; + while ((s > P.HouseholdSizeDistrib[ad][m - 1]) && (k + m < Mcells[j].n) && + (m < MAX_HOUSEHOLD_SIZE)) + m++; } denom_household[m]++; for (i2 = 0; i2 < m; i2++) { // fprintf(stderr,"%i ",i+i2); - Hosts[numberOfPeople + i2].listpos = m; //used temporarily to store household size + Hosts[numberOfPeople + i2].listpos = m; // used temporarily to store household size Mcells[j].members[k + i2] = numberOfPeople + i2; Cells[l].susceptible[Cells[l].cumTC] = numberOfPeople + i2; Cells[l].members[Cells[l].cumTC++] = numberOfPeople + i2; @@ -1117,12 +1271,15 @@ void SetupPopulation(char* SchoolFile, char* RegDemogFile) k += m; } } - if (!(Households = (Household*)malloc(P.NH * sizeof(Household)))) ERR_CRITICAL("Unable to allocate household storage\n"); - for (j = 0; j < NUM_AGE_GROUPS; j++) AgeDist[j] = AgeDist2[j] = 0; - if (P.DoHouseholds) fprintf(stderr, "Household sizes assigned to %i people\n", numberOfPeople); - - FILE* stderr_shared = stderr; -#pragma omp parallel for private(j2,j,x,y,xh,yh,i2,m) schedule(static,1) default(none) \ + if (!(Households = (Household *)malloc(P.NH * sizeof(Household)))) + ERR_CRITICAL("Unable to allocate household storage\n"); + for (j = 0; j < NUM_AGE_GROUPS; j++) + AgeDist[j] = AgeDist2[j] = 0; + if (P.DoHouseholds) + fprintf(stderr, "Household sizes assigned to %i people\n", numberOfPeople); + + FILE *stderr_shared = stderr; +#pragma omp parallel for private(j2, j, x, y, xh, yh, i2, m) schedule(static, 1) default(none) \ shared(P, Households, Hosts, Mcells, McellLookup, AdUnits, stderr_shared) for (int tn = 0; tn < P.NumThreads; tn++) for (j2 = tn; j2 < P.NMCP; j2 += P.NumThreads) @@ -1132,18 +1289,23 @@ void SetupPopulation(char* SchoolFile, char* RegDemogFile) y = (double)(j % P.get_number_of_micro_cells_high()); int i = Mcells[j].members[0]; if (j % 100 == 0) - fprintf(stderr_shared, "%i=%i (%i %i) \r", j, Mcells[j].n, Mcells[j].adunit, (AdUnits[Mcells[j].adunit].id % P.AdunitLevel1Mask) / P.AdunitLevel1Divisor); + fprintf(stderr_shared, "%i=%i (%i %i) \r", j, Mcells[j].n, Mcells[j].adunit, + (AdUnits[Mcells[j].adunit].id % P.AdunitLevel1Mask) / P.AdunitLevel1Divisor); for (int k = 0; k < Mcells[j].n;) { m = Hosts[i].listpos; xh = P.in_microcells_.width * (ranf_mt(tn) + x); yh = P.in_microcells_.height * (ranf_mt(tn) + y); AssignHouseholdAges(m, i, tn); - for (i2 = 0; i2 < m; i2++) Hosts[i + i2].listpos = 0; + for (i2 = 0; i2 < m; i2++) + Hosts[i + i2].listpos = 0; if (P.DoHouseholds) { - for (i2 = 0; i2 < m; i2++) { - Hosts[i + i2].inf = InfStat_Susceptible; //added this so that infection status is set to zero and household r0 is correctly calculated + for (i2 = 0; i2 < m; i2++) + { + Hosts[i + i2].inf = + InfStat_Susceptible; // added this so that infection status is set to zero and + // household r0 is correctly calculated } } Households[Hosts[i].hh].FirstPerson = i; @@ -1157,15 +1319,17 @@ void SetupPopulation(char* SchoolFile, char* RegDemogFile) } if (P.DoCorrectAgeDist) { - double** AgeDistAd, ** AgeDistCorrF, ** AgeDistCorrB; - if (!(AgeDistAd = (double**)malloc(MAX_ADUNITS * sizeof(double*))) || - !(AgeDistCorrF = (double**)malloc(MAX_ADUNITS * sizeof(double*))) || - !(AgeDistCorrB = (double**)malloc(MAX_ADUNITS * sizeof(double*)))) ERR_CRITICAL("Unable to allocate temp storage\n"); + double **AgeDistAd, **AgeDistCorrF, **AgeDistCorrB; + if (!(AgeDistAd = (double **)malloc(MAX_ADUNITS * sizeof(double *))) || + !(AgeDistCorrF = (double **)malloc(MAX_ADUNITS * sizeof(double *))) || + !(AgeDistCorrB = (double **)malloc(MAX_ADUNITS * sizeof(double *)))) + ERR_CRITICAL("Unable to allocate temp storage\n"); for (int i = 0; i < P.NumAdunits; i++) { - if (!(AgeDistAd[i] = (double*)malloc((NUM_AGE_GROUPS + 1) * sizeof(double))) || - !(AgeDistCorrF[i] = (double*)malloc((NUM_AGE_GROUPS + 1) * sizeof(double))) || - !(AgeDistCorrB[i] = (double*)malloc((NUM_AGE_GROUPS + 1) * sizeof(double)))) ERR_CRITICAL("Unable to allocate temp storage\n"); + if (!(AgeDistAd[i] = (double *)malloc((NUM_AGE_GROUPS + 1) * sizeof(double))) || + !(AgeDistCorrF[i] = (double *)malloc((NUM_AGE_GROUPS + 1) * sizeof(double))) || + !(AgeDistCorrB[i] = (double *)malloc((NUM_AGE_GROUPS + 1) * sizeof(double)))) + ERR_CRITICAL("Unable to allocate temp storage\n"); } // compute AgeDistAd[i][j] = total number of people in adunit i, age group j @@ -1177,7 +1341,8 @@ void SetupPopulation(char* SchoolFile, char* RegDemogFile) int k = (P.DoAdunitDemog) ? Mcells[Hosts[i].mcell].adunit : 0; AgeDistAd[k][HOST_AGE_GROUP(i)]++; } - // normalize AgeDistAd[i][j], so it's the proportion of people in adunit i that are in age group j + // normalize AgeDistAd[i][j], so it's the proportion of people in adunit i that are in age group + // j int k = (P.DoAdunitDemog) ? P.NumAdunits : 1; for (int i = 0; i < k; i++) { @@ -1194,7 +1359,8 @@ void SetupPopulation(char* SchoolFile, char* RegDemogFile) AgeDistCorrB[i][0] = 0; for (j = 0; j < NUM_AGE_GROUPS; j++) { - // compute s = the proportion of people that need removing from adunit i, age group j to match age data in parameters + // compute s = the proportion of people that need removing from adunit i, age group j to + // match age data in parameters s = t + AgeDistAd[i][j] - P.PropAgeGroup[i][j] - AgeDistCorrB[i][j]; if (s > 0) { @@ -1206,18 +1372,21 @@ void SetupPopulation(char* SchoolFile, char* RegDemogFile) t = AgeDistCorrF[i][j] = 0; AgeDistCorrB[i][j + 1] = fabs(s); // people to pull down from next age group } - AgeDistCorrF[i][j] /= AgeDistAd[i][j]; // convert from proportion of people in the adunit to proportion of people in the adunit and age group + AgeDistCorrF[i][j] /= AgeDistAd[i][j]; // convert from proportion of people in the adunit to + // proportion of people in the adunit and age group AgeDistCorrB[i][j] /= AgeDistAd[i][j]; } // output problematic adjustments (these should be 0.0f) - //fprintf(stderr, "AgeDistCorrB[%i][0] = %f\n", i, AgeDistCorrB[i][0]); // push down from youngest age group - //fprintf(stderr, "AgeDistCorrF[%i][NUM_AGE_GROUPS - 1] = %f\n", i, AgeDistCorrF[i][NUM_AGE_GROUPS - 1]); // push up from oldest age group - //fprintf(stderr, "AgeDistCorrB[%i][NUM_AGE_GROUPS] = %f\n", i, AgeDistCorrB[i][NUM_AGE_GROUPS]); // push down from oldest age group + 1 + // fprintf(stderr, "AgeDistCorrB[%i][0] = %f\n", i, AgeDistCorrB[i][0]); // push down from + // youngest age group fprintf(stderr, "AgeDistCorrF[%i][NUM_AGE_GROUPS - 1] = %f\n", i, + // AgeDistCorrF[i][NUM_AGE_GROUPS - 1]); // push up from oldest age group fprintf(stderr, + // "AgeDistCorrB[%i][NUM_AGE_GROUPS] = %f\n", i, AgeDistCorrB[i][NUM_AGE_GROUPS]); // push + // down from oldest age group + 1 } // make age adjustments to population -#pragma omp parallel for private(j,k,m,s) schedule(static,1) default(none) \ - shared(P, Hosts, AgeDistCorrF, AgeDistCorrB, Mcells) +#pragma omp parallel for private(j, k, m, s) schedule(static, 1) default(none) \ + shared(P, Hosts, AgeDistCorrF, AgeDistCorrB, Mcells) for (int tn = 0; tn < P.NumThreads; tn++) for (int i = tn; i < P.PopSize; i += P.NumThreads) { @@ -1256,34 +1425,45 @@ void SetupPopulation(char* SchoolFile, char* RegDemogFile) l = (int)(P.LocationInitialInfection[0][1] / P.in_microcells_.height); j = k * P.get_number_of_micro_cells_high() + l; - double rand_r = 0.0; //added these variables so that if initial infection location is empty we can search the 10km neighbourhood to find a suitable cell + double rand_r = 0.0; // added these variables so that if initial infection location is empty we + // can search the 10km neighbourhood to find a suitable cell double rand_theta = 0.0; int counter = 0; if (Mcells[j].n < P.NumInitialInfections[0]) { while (Mcells[j].n < P.NumInitialInfections[0] && counter < 100) { - rand_r = ranf(); rand_theta = ranf(); - rand_r = 0.083 * sqrt(rand_r); rand_theta = 2 * PI * rand_theta; //rand_r is multiplied by 0.083 as this is roughly equal to 10km in decimal degrees - k = (int)((P.LocationInitialInfection[0][0] + rand_r * cos(rand_theta)) / P.in_microcells_.width); - l = (int)((P.LocationInitialInfection[0][1] + rand_r * sin(rand_theta)) / P.in_microcells_.height); + rand_r = ranf(); + rand_theta = ranf(); + rand_r = 0.083 * sqrt(rand_r); + rand_theta = 2 * PI * rand_theta; // rand_r is multiplied by 0.083 as this is roughly equal + // to 10km in decimal degrees + k = (int)((P.LocationInitialInfection[0][0] + rand_r * cos(rand_theta)) / + P.in_microcells_.width); + l = (int)((P.LocationInitialInfection[0][1] + rand_r * sin(rand_theta)) / + P.in_microcells_.height); j = k * P.get_number_of_micro_cells_high() + l; counter++; } if (counter < 100) { - P.LocationInitialInfection[0][0] = P.LocationInitialInfection[0][0] + rand_r * cos(rand_theta); //set LocationInitialInfection to actual one used - P.LocationInitialInfection[0][1] = P.LocationInitialInfection[0][1] + rand_r * sin(rand_theta); + P.LocationInitialInfection[0][0] = + P.LocationInitialInfection[0][0] + + rand_r * cos(rand_theta); // set LocationInitialInfection to actual one used + P.LocationInitialInfection[0][1] = + P.LocationInitialInfection[0][1] + rand_r * sin(rand_theta); } } if (Mcells[j].n < P.NumInitialInfections[0]) - ERR_CRITICAL("Too few people in seed microcell to start epidemic with required number of initial infectionz.\n"); + ERR_CRITICAL("Too few people in seed microcell to start epidemic with required number of " + "initial infectionz.\n"); } fprintf(stderr, "Checking cells...\n"); maxd = ((double)P.PopSize); last_i = 0; for (int i = 0; i < P.NMC; i++) - if (Mcells[i].n > 0) last_i = i; + if (Mcells[i].n > 0) + last_i = i; fprintf(stderr, "Allocating place/age groups...\n"); for (int k = 0; k < NUM_AGE_GROUPS * AGE_GROUP_WIDTH; k++) { @@ -1315,34 +1495,45 @@ void SetupPopulation(char* SchoolFile, char* RegDemogFile) else free(State.InvAgeDist[0]); free(State.InvAgeDist); - */ P.nsp = 0; + */ + P.nsp = 0; if (P.DoPlaces) - if (!(Places = (Place * *)malloc(P.PlaceTypeNum * sizeof(Place*)))) ERR_CRITICAL("Unable to allocate place storage\n"); + if (!(Places = (Place **)malloc(P.PlaceTypeNum * sizeof(Place *)))) + ERR_CRITICAL("Unable to allocate place storage\n"); if ((P.DoSchoolFile) && (P.DoPlaces)) { fprintf(stderr, "Reading school file\n"); - if (!(dat = fopen(SchoolFile, "rb"))) ERR_CRITICAL("Unable to open school file\n"); + if (!(dat = fopen(SchoolFile, "rb"))) + ERR_CRITICAL("Unable to open school file\n"); fscanf(dat, "%i", &P.nsp); for (j = 0; j < P.nsp; j++) { fscanf(dat, "%i %i", &m, &(P.PlaceTypeMaxAgeRead[j])); - if (!(Places[j] = (Place*)calloc(m, sizeof(Place)))) ERR_CRITICAL("Unable to allocate place storage\n"); + if (!(Places[j] = (Place *)calloc(m, sizeof(Place)))) + ERR_CRITICAL("Unable to allocate place storage\n"); for (int i = 0; i < m; i++) - if (!(Places[j][i].AvailByAge = (unsigned short int*) malloc(P.PlaceTypeMaxAgeRead[j] * sizeof(unsigned short int)))) ERR_CRITICAL("Unable to allocate place storage\n"); + if (!(Places[j][i].AvailByAge = (unsigned short int *)malloc(P.PlaceTypeMaxAgeRead[j] * + sizeof(unsigned short int)))) + ERR_CRITICAL("Unable to allocate place storage\n"); P.Nplace[j] = 0; - for (int i = 0; i < P.NMC; i++) Mcells[i].np[j] = 0; + for (int i = 0; i < P.NMC; i++) + Mcells[i].np[j] = 0; } mr = 0; while (!feof(dat)) { fscanf(dat, "%lg %lg %i %i", &x, &y, &j, &m); - for (int i = 0; i < P.PlaceTypeMaxAgeRead[j]; i++) fscanf(dat, "%hu", &(Places[j][P.Nplace[j]].AvailByAge[i])); + for (int i = 0; i < P.PlaceTypeMaxAgeRead[j]; i++) + fscanf(dat, "%hu", &(Places[j][P.Nplace[j]].AvailByAge[i])); Places[j][P.Nplace[j]].loc.x = (float)(x - P.SpatialBoundingBox[0]); Places[j][P.Nplace[j]].loc.y = (float)(y - P.SpatialBoundingBox[1]); - if ((x >= P.SpatialBoundingBox[0]) && (x < P.SpatialBoundingBox[2]) && (y >= P.SpatialBoundingBox[1]) && (y < P.SpatialBoundingBox[3])) + if ((x >= P.SpatialBoundingBox[0]) && (x < P.SpatialBoundingBox[2]) && + (y >= P.SpatialBoundingBox[1]) && (y < P.SpatialBoundingBox[3])) { - int i = P.nch * ((int)(Places[j][P.Nplace[j]].loc.x / P.in_cells_.width)) + ((int)(Places[j][P.Nplace[j]].loc.y / P.in_cells_.height)); - if (Cells[i].n == 0) mr++; + int i = P.nch * ((int)(Places[j][P.Nplace[j]].loc.x / P.in_cells_.width)) + + ((int)(Places[j][P.Nplace[j]].loc.y / P.in_cells_.height)); + if (Cells[i].n == 0) + mr++; Places[j][P.Nplace[j]].n = m; i = (int)(Places[j][P.Nplace[j]].loc.x / P.in_microcells_.width); int k = (int)(Places[j][P.Nplace[j]].loc.y / P.in_microcells_.height); @@ -1350,7 +1541,8 @@ void SetupPopulation(char* SchoolFile, char* RegDemogFile) Mcells[j2].np[j]++; Places[j][P.Nplace[j]].mcell = j2; P.Nplace[j]++; - if (P.Nplace[j] % 1000 == 0) fprintf(stderr, "%i read \r", P.Nplace[j]); + if (P.Nplace[j] % 1000 == 0) + fprintf(stderr, "%i read \r", P.Nplace[j]); } } fclose(dat); @@ -1359,7 +1551,8 @@ void SetupPopulation(char* SchoolFile, char* RegDemogFile) for (j = 0; j < P.nsp; j++) if (Mcells[i].np[j] > 0) { - if (!(Mcells[i].places[j] = (int*)malloc(Mcells[i].np[j] * sizeof(int)))) ERR_CRITICAL("Unable to allocate place storage\n"); + if (!(Mcells[i].places[j] = (int *)malloc(Mcells[i].np[j] * sizeof(int)))) + ERR_CRITICAL("Unable to allocate place storage\n"); Mcells[i].np[j] = 0; } for (j = 0; j < P.nsp; j++) @@ -1383,9 +1576,9 @@ void SetupPopulation(char* SchoolFile, char* RegDemogFile) { fprintf(stderr, "Configuring places...\n"); - FILE* stderr_shared = stderr; -#pragma omp parallel for private(j2,j,t,m,s,x,y,xh,yh) schedule(static,1) default(none) \ - shared(P, Hosts, Places, PropPlaces, Mcells, maxd, last_i, stderr_shared) + FILE *stderr_shared = stderr; +#pragma omp parallel for private(j2, j, t, m, s, x, y, xh, yh) schedule(static, 1) default(none) \ + shared(P, Hosts, Places, PropPlaces, Mcells, maxd, last_i, stderr_shared) for (int tn = 0; tn < P.NumThreads; tn++) for (j2 = P.nsp + tn; j2 < P.PlaceTypeNum; j2 += P.NumThreads) { @@ -1395,13 +1588,15 @@ void SetupPopulation(char* SchoolFile, char* RegDemogFile) t += PropPlaces[HOST_AGE_YEAR(i)][j2]; P.Nplace[j2] = (int)ceil(t / P.PlaceTypeMeanSize[j2]); fprintf(stderr_shared, "[%i:%i %g] ", j2, P.Nplace[j2], t); - if (!(Places[j2] = (Place*)calloc(P.Nplace[j2], sizeof(Place)))) ERR_CRITICAL("Unable to allocate place storage\n"); + if (!(Places[j2] = (Place *)calloc(P.Nplace[j2], sizeof(Place)))) + ERR_CRITICAL("Unable to allocate place storage\n"); t = 1.0; int k; for (int i = m = k = 0; i < P.NMC; i++) { - s = ((double) Mcells[i].n) / maxd / t; - if (s > 1.0) s = 1.0; + s = ((double)Mcells[i].n) / maxd / t; + if (s > 1.0) + s = 1.0; if (i == last_i) m += (Mcells[last_i].np[j2] = P.Nplace[j2] - m); else @@ -1409,7 +1604,8 @@ void SetupPopulation(char* SchoolFile, char* RegDemogFile) t -= ((double)Mcells[i].n) / maxd; if (Mcells[i].np[j2] > 0) { - if (!(Mcells[i].places[j2] = (int*)malloc(Mcells[i].np[j2] * sizeof(int)))) ERR_CRITICAL("Unable to allocate place storage\n"); + if (!(Mcells[i].places[j2] = (int *)malloc(Mcells[i].np[j2] * sizeof(int)))) + ERR_CRITICAL("Unable to allocate place storage\n"); x = (double)(i / P.get_number_of_micro_cells_high()); y = (double)(i % P.get_number_of_micro_cells_high()); for (j = 0; j < Mcells[i].np[j2]; j++) @@ -1436,55 +1632,64 @@ void SetupPopulation(char* SchoolFile, char* RegDemogFile) else if (PropPlaces[k][l] != 0) PropPlaces[k][l] = 1.0; } -/* for (j2 = 0; j2 < P.PlaceTypeNum; j2++) - for (i =0; i < P.NMC; i++) - if ((Mcells[i].np[j2]>0) && (Mcells[i].n == 0)) - fprintf(stderr, "\n##~ %i %i %i \n", i, j2, Mcells[i].np[j2]); -*/ fprintf(stderr, "Places assigned\n"); + /* for (j2 = 0; j2 < P.PlaceTypeNum; j2++) + for (i =0; i < P.NMC; i++) + if ((Mcells[i].np[j2]>0) && (Mcells[i].n == 0)) + fprintf(stderr, "\n##~ %i %i %i \n", i, j2, Mcells[i].np[j2]); + */ + fprintf(stderr, "Places assigned\n"); } l = 0; for (j = 0; j < P.NC; j++) - if (l < Cells[j].n) l = Cells[j].n; - if (!(SamplingQueue = (int**)malloc(P.NumThreads * sizeof(int*)))) ERR_CRITICAL("Unable to allocate state storage\n"); + if (l < Cells[j].n) + l = Cells[j].n; + if (!(SamplingQueue = (int **)malloc(P.NumThreads * sizeof(int *)))) + ERR_CRITICAL("Unable to allocate state storage\n"); P.InfQueuePeakLength = P.PopSize / P.NumThreads / INF_QUEUE_SCALE; -#pragma omp parallel for schedule(static,1) default(none) \ - shared(P, SamplingQueue, StateT, l) +#pragma omp parallel for schedule(static, 1) default(none) shared(P, SamplingQueue, StateT, l) for (int i = 0; i < P.NumThreads; i++) { - if (!(SamplingQueue[i] = (int*)malloc(2 * (MAX_PLACE_SIZE + CACHE_LINE_SIZE) * sizeof(int)))) ERR_CRITICAL("Unable to allocate state storage\n"); + if (!(SamplingQueue[i] = (int *)malloc(2 * (MAX_PLACE_SIZE + CACHE_LINE_SIZE) * sizeof(int)))) + ERR_CRITICAL("Unable to allocate state storage\n"); for (int k = 0; k < P.NumThreads; k++) - if (!(StateT[i].inf_queue[k] = (Infection*)malloc(P.InfQueuePeakLength * sizeof(Infection)))) ERR_CRITICAL("Unable to allocate state storage\n"); - if (!(StateT[i].cell_inf = (float*)malloc((l + 1) * sizeof(float)))) ERR_CRITICAL("Unable to allocate state storage\n"); + if (!(StateT[i].inf_queue[k] = (Infection *)malloc(P.InfQueuePeakLength * sizeof(Infection)))) + ERR_CRITICAL("Unable to allocate state storage\n"); + if (!(StateT[i].cell_inf = (float *)malloc((l + 1) * sizeof(float)))) + ERR_CRITICAL("Unable to allocate state storage\n"); } - //set up queues and storage for digital contact tracing + // set up queues and storage for digital contact tracing if ((P.DoAdUnits) && (P.DoDigitalContactTracing)) { for (int i = 0; i < P.NumAdunits; i++) { - //malloc or calloc for these? - if (!(AdUnits[i].dct = (int*)malloc(AdUnits[i].n * sizeof(int)))) ERR_CRITICAL("Unable to allocate state storage\n"); + // malloc or calloc for these? + if (!(AdUnits[i].dct = (int *)malloc(AdUnits[i].n * sizeof(int)))) + ERR_CRITICAL("Unable to allocate state storage\n"); } for (int i = 0; i < P.NumThreads; i++) { for (j = 0; j < P.NumAdunits; j++) { - if (!(StateT[i].dct_queue[j] = (ContactEvent*)malloc(AdUnits[j].n * sizeof(ContactEvent)))) ERR_CRITICAL("Unable to allocate state storage\n"); + if (!(StateT[i].dct_queue[j] = (ContactEvent *)malloc(AdUnits[j].n * sizeof(ContactEvent)))) + ERR_CRITICAL("Unable to allocate state storage\n"); } } } - //If outputting origin-destination matrix, set up storage for flow between admin units + // If outputting origin-destination matrix, set up storage for flow between admin units if ((P.DoAdUnits) && (P.DoOriginDestinationMatrix)) { for (int i = 0; i < P.NumAdunits; i++) { - if (!(AdUnits[i].origin_dest = (double*)malloc(MAX_ADUNITS * sizeof(double)))) ERR_CRITICAL("Unable to allocate storage for origin destination matrix\n"); + if (!(AdUnits[i].origin_dest = (double *)malloc(MAX_ADUNITS * sizeof(double)))) + ERR_CRITICAL("Unable to allocate storage for origin destination matrix\n"); for (j = 0; j < P.NumThreads; j++) { - if (!(StateT[j].origin_dest[i] = (double*)calloc(MAX_ADUNITS, sizeof(double)))) ERR_CRITICAL("Unable to allocate state origin destination matrix storage\n"); + if (!(StateT[j].origin_dest[i] = (double *)calloc(MAX_ADUNITS, sizeof(double)))) + ERR_CRITICAL("Unable to allocate state origin destination matrix storage\n"); } - //initialise to zero + // initialise to zero for (j = 0; j < P.NumAdunits; j++) { AdUnits[i].origin_dest[j] = 0.0; @@ -1500,17 +1705,17 @@ void SetupPopulation(char* SchoolFile, char* RegDemogFile) } fprintf(stderr, "Allocated cell and host memory\n"); fprintf(stderr, "Assigned hosts to cells\n"); - } void SetupAirports(void) { int k, l, m; double x, y, t, tmin; - IndexList* base, *cur; + IndexList *base, *cur; fprintf(stderr, "Assigning airports to microcells\n"); // Convince static analysers that values are set correctly: - if (!(P.DoAirports && P.HotelPlaceType < P.PlaceTypeNum)) ERR_CRITICAL("DoAirports || HotelPlaceType not set\n"); + if (!(P.DoAirports && P.HotelPlaceType < P.PlaceTypeNum)) + ERR_CRITICAL("DoAirports || HotelPlaceType not set\n"); P.KernelType = P.AirportKernelType; P.KernelScale = P.AirportKernelScale; @@ -1518,9 +1723,11 @@ void SetupAirports(void) P.KernelP3 = P.AirportKernelP3; P.KernelP4 = P.AirportKernelP4; InitKernel(1.0); - if (!(Airports[0].DestMcells = (IndexList*)calloc(P.NMCP * NNA, sizeof(IndexList))) || - !(base = (IndexList*)calloc(P.NMCP * NNA, sizeof(IndexList)))) ERR_CRITICAL("Unable to allocate airport storage\n"); - for (int i = 0; i < P.Nairports; i++) Airports[i].num_mcell = 0; + if (!(Airports[0].DestMcells = (IndexList *)calloc(P.NMCP * NNA, sizeof(IndexList))) || + !(base = (IndexList *)calloc(P.NMCP * NNA, sizeof(IndexList)))) + ERR_CRITICAL("Unable to allocate airport storage\n"); + for (int i = 0; i < P.Nairports; i++) + Airports[i].num_mcell = 0; cur = base; for (int i = 0; i < P.NMC; i++) if (Mcells[i].n > 0) @@ -1529,13 +1736,14 @@ void SetupAirports(void) cur += NNA; } - FILE* stderr_shared = stderr; -#pragma omp parallel for private(k,l,x,y,t,tmin) schedule(static,10000) default(none) \ + FILE *stderr_shared = stderr; +#pragma omp parallel for private(k, l, x, y, t, tmin) schedule(static, 10000) default(none) \ shared(P, Airports, Mcells, stderr_shared) for (int i = 0; i < P.NMC; i++) if (Mcells[i].n > 0) { - if (i % 10000 == 0) fprintf(stderr_shared, "\n%i ", i); + if (i % 10000 == 0) + fprintf(stderr_shared, "\n%i ", i); x = (((double)(i / P.get_number_of_micro_cells_high())) + 0.5) * P.in_microcells_.width; y = (((double)(i % P.get_number_of_micro_cells_high())) + 0.5) * P.in_microcells_.height; k = l = 0; @@ -1543,12 +1751,17 @@ void SetupAirports(void) for (int j = 0; j < P.Nairports; j++) if (Airports[j].total_traffic > 0) { - t = numKernel(dist2_raw(x, y, Airports[j].loc.x, Airports[j].loc.y)) * Airports[j].total_traffic; + t = numKernel(dist2_raw(x, y, Airports[j].loc.x, Airports[j].loc.y)) * + Airports[j].total_traffic; if (k < NNA) { Mcells[i].AirportList[k].id = j; Mcells[i].AirportList[k].prob = (float)t; - if (t < tmin) { tmin = t; l = k; } + if (t < tmin) + { + tmin = t; + l = k; + } k++; } else if (t > tmin) @@ -1575,18 +1788,19 @@ void SetupAirports(void) cur += Airports[i].num_mcell; Airports[i].num_mcell = 0; } -#pragma omp parallel for private(k,l,t,tmin) schedule(static,10000) default(none) \ +#pragma omp parallel for private(k, l, t, tmin) schedule(static, 10000) default(none) \ shared(P, Airports, Mcells, stderr_shared) for (int i = 0; i < P.NMC; i++) if (Mcells[i].n > 0) { - if (i % 10000 == 0) fprintf(stderr_shared, "\n%i ", i); + if (i % 10000 == 0) + fprintf(stderr_shared, "\n%i ", i); t = 0; for (int j = 0; j < NNA; j++) { t += Mcells[i].AirportList[j].prob; k = Mcells[i].AirportList[j].id; -#pragma omp critical (airport) +#pragma omp critical(airport) l = (Airports[k].num_mcell++); Airports[k].DestMcells[l].id = i; Airports[k].DestMcells[l].prob = Mcells[i].AirportList[j].prob * ((float)Mcells[i].n); @@ -1605,14 +1819,17 @@ void SetupAirports(void) for (int j = 1; j < Airports[i].num_mcell; j++) Airports[i].DestMcells[j].prob += Airports[i].DestMcells[j - 1].prob; t = Airports[i].DestMcells[Airports[i].num_mcell - 1].prob; - if (t == 0) t = 1.0; + if (t == 0) + t = 1.0; for (int j = 0; j < Airports[i].num_mcell - 1; j++) Airports[i].DestMcells[j].prob = (float)(Airports[i].DestMcells[j].prob / t); - if (Airports[i].num_mcell > 0) Airports[i].DestMcells[Airports[i].num_mcell - 1].prob = 1.0; + if (Airports[i].num_mcell > 0) + Airports[i].DestMcells[Airports[i].num_mcell - 1].prob = 1.0; for (int j = l = 0; l <= 1024; l++) { t = ((double)l) / 1024.0; - while (Airports[i].DestMcells[j].prob < t) j++; + while (Airports[i].DestMcells[j].prob < t) + j++; Airports[i].Inv_DestMcells[l] = j; } l = 0; @@ -1629,12 +1846,14 @@ void SetupAirports(void) } fprintf(stderr, "\nInitialising hotel to airport lookup tables\n"); free(base); -#pragma omp parallel for private(l,m,t,tmin) schedule(static,1) default(none) shared(P, Airports, Places, stderr_shared) +#pragma omp parallel for private(l, m, t, tmin) schedule(static, 1) default(none) \ + shared(P, Airports, Places, stderr_shared) for (int i = 0; i < P.Nairports; i++) if (Airports[i].total_traffic > 0) { m = (int)(Airports[i].total_traffic / HOTELS_PER_1000PASSENGER / 1000); - if (m < MIN_HOTELS_PER_AIRPORT) m = MIN_HOTELS_PER_AIRPORT; + if (m < MIN_HOTELS_PER_AIRPORT) + m = MIN_HOTELS_PER_AIRPORT; fprintf(stderr_shared, "\n%i ", i); tmin = MAX_DIST_AIRPORT_TO_HOTEL * MAX_DIST_AIRPORT_TO_HOTEL * 0.75; do @@ -1642,16 +1861,18 @@ void SetupAirports(void) tmin += 0.25 * MAX_DIST_AIRPORT_TO_HOTEL * MAX_DIST_AIRPORT_TO_HOTEL; Airports[i].num_place = 0; for (int j = 0; j < P.Nplace[P.HotelPlaceType]; j++) - if (dist2_raw(Airports[i].loc.x, Airports[i].loc.y, - Places[P.HotelPlaceType][j].loc.x, Places[P.HotelPlaceType][j].loc.y) < tmin) + if (dist2_raw(Airports[i].loc.x, Airports[i].loc.y, Places[P.HotelPlaceType][j].loc.x, + Places[P.HotelPlaceType][j].loc.y) < tmin) Airports[i].num_place++; } while (Airports[i].num_place < m); - if (tmin > MAX_DIST_AIRPORT_TO_HOTEL * MAX_DIST_AIRPORT_TO_HOTEL) fprintf(stderr_shared, "*** %i : %lg %i ***\n", i, sqrt(tmin), Airports[i].num_place); - if (!(Airports[i].DestPlaces = (IndexList*)calloc(Airports[i].num_place, sizeof(IndexList)))) ERR_CRITICAL("Unable to allocate airport storage\n"); + if (tmin > MAX_DIST_AIRPORT_TO_HOTEL * MAX_DIST_AIRPORT_TO_HOTEL) + fprintf(stderr_shared, "*** %i : %lg %i ***\n", i, sqrt(tmin), Airports[i].num_place); + if (!(Airports[i].DestPlaces = (IndexList *)calloc(Airports[i].num_place, sizeof(IndexList)))) + ERR_CRITICAL("Unable to allocate airport storage\n"); Airports[i].num_place = 0; for (int j = 0; j < P.Nplace[P.HotelPlaceType]; j++) - if ((t = dist2_raw(Airports[i].loc.x, Airports[i].loc.y, - Places[P.HotelPlaceType][j].loc.x, Places[P.HotelPlaceType][j].loc.y)) < tmin) + if ((t = dist2_raw(Airports[i].loc.x, Airports[i].loc.y, Places[P.HotelPlaceType][j].loc.x, + Places[P.HotelPlaceType][j].loc.y)) < tmin) { Airports[i].DestPlaces[Airports[i].num_place].prob = (float)numKernel(t); Airports[i].DestPlaces[Airports[i].num_place].id = j; @@ -1665,15 +1886,18 @@ void SetupAirports(void) } for (int j = 0; j < Airports[i].num_place - 1; j++) Airports[i].DestPlaces[j].prob = (float)(Airports[i].DestPlaces[j].prob / t); - if (Airports[i].num_place > 0) Airports[i].DestPlaces[Airports[i].num_place - 1].prob = 1.0; + if (Airports[i].num_place > 0) + Airports[i].DestPlaces[Airports[i].num_place - 1].prob = 1.0; for (int j = l = 0; l <= 1024; l++) { t = ((double)l) / 1024.0; - while (Airports[i].DestPlaces[j].prob < t) j++; + while (Airports[i].DestPlaces[j].prob < t) + j++; Airports[i].Inv_DestPlaces[l] = j; } } - for (int i = 0; i < P.Nplace[P.HotelPlaceType]; i++) Places[P.HotelPlaceType][i].n = 0; + for (int i = 0; i < P.Nplace[P.HotelPlaceType]; i++) + Places[P.HotelPlaceType][i].n = 0; P.KernelType = P.MoveKernelType; P.KernelScale = P.MoveKernelScale; P.KernelShape = P.MoveKernelShape; @@ -1685,7 +1909,6 @@ void SetupAirports(void) const double PROP_OTHER_PARENT_AWAY = 0.0; - void AssignHouseholdAges(int n, int pers, int tn) { /* Complex household age distribution model @@ -1713,20 +1936,23 @@ void AssignHouseholdAges(int n, int pers, int tn) do { a[0] = State.InvAgeDist[ad][(int)(1000.0 * ranf_mt(tn))]; - } - while ((a[0] < P.NoChildPersAge) - || (ranf_mt(tn) > (((double)a[0]) - P.NoChildPersAge + 1) / (P.OldPersAge - P.NoChildPersAge + 1))); + } while ((a[0] < P.NoChildPersAge) || + (ranf_mt(tn) > + (((double)a[0]) - P.NoChildPersAge + 1) / (P.OldPersAge - P.NoChildPersAge + 1))); } - else if ((P.OnePersHouseProbYoung > 0) && (ranf_mt(tn) < P.OnePersHouseProbYoung / (1 - P.OnePersHouseProbOld))) + else if ((P.OnePersHouseProbYoung > 0) && + (ranf_mt(tn) < P.OnePersHouseProbYoung / (1 - P.OnePersHouseProbOld))) { do { a[0] = State.InvAgeDist[ad][(int)(1000.0 * ranf_mt(tn))]; - } while ((a[0] > P.YoungAndSingle) || (a[0] < P.MinAdultAge) - || (ranf_mt(tn) > 1 - P.YoungAndSingleSlope * (((double)a[0]) - P.MinAdultAge) / (P.YoungAndSingle - P.MinAdultAge))); + } while ((a[0] > P.YoungAndSingle) || (a[0] < P.MinAdultAge) || + (ranf_mt(tn) > 1 - P.YoungAndSingleSlope * (((double)a[0]) - P.MinAdultAge) / + (P.YoungAndSingle - P.MinAdultAge))); } else - while ((a[0] = State.InvAgeDist[ad][(int)(1000.0 * ranf_mt(tn))]) < P.MinAdultAge); + while ((a[0] = State.InvAgeDist[ad][(int)(1000.0 * ranf_mt(tn))]) < P.MinAdultAge) + ; } else if (n == 2) { @@ -1735,37 +1961,42 @@ void AssignHouseholdAges(int n, int pers, int tn) do { a[0] = State.InvAgeDist[ad][(int)(1000.0 * ranf_mt(tn))]; - } - while ((a[0] < P.NoChildPersAge) - || (ranf_mt(tn) > (((double)a[0]) - P.NoChildPersAge + 1) / (P.OldPersAge - P.NoChildPersAge + 1))); + } while ((a[0] < P.NoChildPersAge) || + (ranf_mt(tn) > + (((double)a[0]) - P.NoChildPersAge + 1) / (P.OldPersAge - P.NoChildPersAge + 1))); do { a[1] = State.InvAgeDist[ad][(int)(1000.0 * ranf_mt(tn))]; - } - while ((a[1] > a[0] + P.MaxMFPartnerAgeGap) || (a[1] < a[0] - P.MaxFMPartnerAgeGap) || (a[1] < P.NoChildPersAge) - || (ranf_mt(tn) > (((double)a[1]) - P.NoChildPersAge + 1) / (P.OldPersAge - P.NoChildPersAge + 1))); + } while ((a[1] > a[0] + P.MaxMFPartnerAgeGap) || (a[1] < a[0] - P.MaxFMPartnerAgeGap) || + (a[1] < P.NoChildPersAge) || + (ranf_mt(tn) > + (((double)a[1]) - P.NoChildPersAge + 1) / (P.OldPersAge - P.NoChildPersAge + 1))); } else if (ranf_mt(tn) < P.OneChildTwoPersProb / (1 - P.TwoPersHouseProbOld)) { - while ((a[0] = State.InvAgeDist[ad][(int)(1000.0 * ranf_mt(tn))]) > P.MaxChildAge); + while ((a[0] = State.InvAgeDist[ad][(int)(1000.0 * ranf_mt(tn))]) > P.MaxChildAge) + ; do { a[1] = State.InvAgeDist[ad][(int)(1000.0 * ranf_mt(tn))]; - } - while ((a[1] > a[0] + P.MaxParentAgeGap) || (a[1] < a[0] + P.MinParentAgeGap) || (a[1] < P.MinAdultAge)); + } while ((a[1] > a[0] + P.MaxParentAgeGap) || (a[1] < a[0] + P.MinParentAgeGap) || + (a[1] < P.MinAdultAge)); } - else if ((P.TwoPersHouseProbYoung > 0) && (ranf_mt(tn) < P.TwoPersHouseProbYoung / (1 - P.TwoPersHouseProbOld - P.OneChildTwoPersProb))) + else if ((P.TwoPersHouseProbYoung > 0) && + (ranf_mt(tn) < + P.TwoPersHouseProbYoung / (1 - P.TwoPersHouseProbOld - P.OneChildTwoPersProb))) { do { a[0] = State.InvAgeDist[ad][(int)(1000.0 * ranf_mt(tn))]; - } while ((a[0] < P.MinAdultAge) || (a[0] > P.YoungAndSingle) - || (ranf_mt(tn) > 1 - P.YoungAndSingleSlope * (((double)a[0]) - P.MinAdultAge) / (P.YoungAndSingle - P.MinAdultAge))); + } while ((a[0] < P.MinAdultAge) || (a[0] > P.YoungAndSingle) || + (ranf_mt(tn) > 1 - P.YoungAndSingleSlope * (((double)a[0]) - P.MinAdultAge) / + (P.YoungAndSingle - P.MinAdultAge))); do { a[1] = State.InvAgeDist[ad][(int)(1000.0 * ranf_mt(tn))]; - } - while ((a[1] > a[0] + P.MaxMFPartnerAgeGap) || (a[1] < a[0] - P.MaxFMPartnerAgeGap) || (a[1] < P.MinAdultAge)); + } while ((a[1] > a[0] + P.MaxMFPartnerAgeGap) || (a[1] < a[0] - P.MaxFMPartnerAgeGap) || + (a[1] < P.MinAdultAge)); } else { @@ -1776,17 +2007,18 @@ void AssignHouseholdAges(int n, int pers, int tn) do { a[1] = State.InvAgeDist[ad][(int)(1000.0 * ranf_mt(tn))]; - } - while ((a[1] > a[0] + P.MaxMFPartnerAgeGap) || (a[1] < a[0] - P.MaxFMPartnerAgeGap) || (a[1] < P.MinAdultAge)); + } while ((a[1] > a[0] + P.MaxMFPartnerAgeGap) || (a[1] < a[0] - P.MaxFMPartnerAgeGap) || + (a[1] < P.MinAdultAge)); } - } else { if (n == 3) { if ((P.ZeroChildThreePersProb > 0) || (P.TwoChildThreePersProb > 0)) - nc = (ranf_mt(tn) < P.ZeroChildThreePersProb) ? 0 : ((ranf_mt(tn) < P.TwoChildThreePersProb) ? 2 : 1); + nc = (ranf_mt(tn) < P.ZeroChildThreePersProb) + ? 0 + : ((ranf_mt(tn) < P.TwoChildThreePersProb) ? 2 : 1); else nc = 1; } @@ -1802,13 +2034,11 @@ void AssignHouseholdAges(int n, int pers, int tn) { a[0] = State.InvAgeDist[ad][(int)(1000.0 * ranf_mt(tn))]; a[1] = State.InvAgeDist[ad][(int)(1000.0 * ranf_mt(tn))]; - } - while ((a[1] < P.MinAdultAge) || (a[0] < P.MinAdultAge)); + } while ((a[1] < P.MinAdultAge) || (a[0] < P.MinAdultAge)); do { a[2] = State.InvAgeDist[ad][(int)(1000.0 * ranf_mt(tn))]; - } - while ((a[2] >= a[1] + P.MaxMFPartnerAgeGap) || (a[2] < a[1] - P.MaxFMPartnerAgeGap)); + } while ((a[2] >= a[1] + P.MaxMFPartnerAgeGap) || (a[2] < a[1] - P.MaxFMPartnerAgeGap)); } else { @@ -1817,10 +2047,15 @@ void AssignHouseholdAges(int n, int pers, int tn) a[0] = 0; for (i = 1; i < nc; i++) a[i] = a[i - 1] + 1 + ((int)ignpoi_mt(P.MeanChildAgeGap - 1, tn)); - a[0] = State.InvAgeDist[ad][(int)(1000.0 * ranf_mt(tn))] - a[(int)(ranf_mt(tn) * ((double)nc))]; - for (i = 1; i < nc; i++) a[i] += a[0]; - k = (((nc == 1) && (ranf_mt(tn) < P.OneChildProbYoungestChildUnderFive)) || ((nc == 2) && (ranf_mt(tn) < P.TwoChildrenProbYoungestUnderFive)) - || ((nc > 2) && (ranf_mt(tn) < P.ProbYoungestChildUnderFive))) ? 5 : P.MaxChildAge; + a[0] = State.InvAgeDist[ad][(int)(1000.0 * ranf_mt(tn))] - + a[(int)(ranf_mt(tn) * ((double)nc))]; + for (i = 1; i < nc; i++) + a[i] += a[0]; + k = (((nc == 1) && (ranf_mt(tn) < P.OneChildProbYoungestChildUnderFive)) || + ((nc == 2) && (ranf_mt(tn) < P.TwoChildrenProbYoungestUnderFive)) || + ((nc > 2) && (ranf_mt(tn) < P.ProbYoungestChildUnderFive))) + ? 5 + : P.MaxChildAge; } while ((a[0] < 0) || (a[0] > k) || (a[nc - 1] > P.MaxChildAge)); j = a[nc - 1] - a[0] - (P.MaxParentAgeGap - P.MinParentAgeGap); if (j > 0) @@ -1837,31 +2072,36 @@ void AssignHouseholdAges(int n, int pers, int tn) do { a[nc + 1] = State.InvAgeDist[ad][(int)(1000.0 * ranf_mt(tn))]; - } while ((a[nc + 1] > a[nc] + P.MaxMFPartnerAgeGap) || (a[nc + 1] < a[nc] - P.MaxFMPartnerAgeGap) - || (a[nc + 1] > a[0] + j) || (a[nc + 1] < k + P.MinParentAgeGap) || (a[nc + 1] < P.MinAdultAge)); + } while ((a[nc + 1] > a[nc] + P.MaxMFPartnerAgeGap) || + (a[nc + 1] < a[nc] - P.MaxFMPartnerAgeGap) || (a[nc + 1] > a[0] + j) || + (a[nc + 1] < k + P.MinParentAgeGap) || (a[nc + 1] < P.MinAdultAge)); } if (n > nc + 2) { j = ((a[nc + 1] > a[nc]) ? a[nc + 1] : a[nc]) + P.OlderGenGap; - if (j >= NUM_AGE_GROUPS * AGE_GROUP_WIDTH) j = NUM_AGE_GROUPS * AGE_GROUP_WIDTH - 1; - if (j < P.NoChildPersAge) j = P.NoChildPersAge; + if (j >= NUM_AGE_GROUPS * AGE_GROUP_WIDTH) + j = NUM_AGE_GROUPS * AGE_GROUP_WIDTH - 1; + if (j < P.NoChildPersAge) + j = P.NoChildPersAge; for (i = nc + 2; i < n; i++) - while ((a[i] = State.InvAgeDist[ad][(int)(1000.0 * ranf_mt(tn))]) < j); + while ((a[i] = State.InvAgeDist[ad][(int)(1000.0 * ranf_mt(tn))]) < j) + ; } } } } - for (i = 0; i < n; i++) Hosts[pers + i].age = (unsigned char) a[i]; + for (i = 0; i < n; i++) + Hosts[pers + i].age = (unsigned char)a[i]; } void AssignPeopleToPlaces() { int i2, j, j2, k, k2, l, m, tp, f, f2, f3, f4, ic, a, cnt, ca, nt, nn; - int* PeopleArray; - int* NearestPlaces[MAX_NUM_THREADS]; + int *PeopleArray; + int *NearestPlaces[MAX_NUM_THREADS]; double s, t, *NearestPlacesProb[MAX_NUM_THREADS]; - Cell* ct; + Cell *ct; int npt; npt = NUM_PLACE_TYPES; @@ -1872,14 +2112,17 @@ void AssignPeopleToPlaces() for (int i = 0; i < P.NC; i++) { Cells[i].infected = Cells[i].susceptible; - if (!(Cells[i].susceptible = (int*)calloc(Cells[i].n, sizeof(int)))) ERR_CRITICAL("Unable to allocate state storage\n"); + if (!(Cells[i].susceptible = (int *)calloc(Cells[i].n, sizeof(int)))) + ERR_CRITICAL("Unable to allocate state storage\n"); Cells[i].cumTC = Cells[i].n; } - //PropPlaces initialisation is only valid for non-overlapping places. + // PropPlaces initialisation is only valid for non-overlapping places. for (int i = 0; i < P.PopSize; i++) { - for (tp = 0; tp < npt; tp++) //Changed from 'for(tp=0;tp 0) && (ranf() < PropPlaces[k][tp])); if (f) for (k = 0; (k < tp) && (f); k++) - if (Hosts[c->members[j]].PlaceLinks[k] >= 0) f = 0; //(ranf()members[j]].PlaceLinks[k] >= 0) + f = 0; //(ranf()S = c->n; c->I = 0; } - if (!(PeopleArray = (int*)calloc(cnt, sizeof(int)))) ERR_CRITICAL("Unable to allocate cell storage\n"); + if (!(PeopleArray = (int *)calloc(cnt, sizeof(int)))) + ERR_CRITICAL("Unable to allocate cell storage\n"); j2 = 0; for (a = 0; a < P.NCP; a++) { @@ -1946,28 +2191,36 @@ void AssignPeopleToPlaces() { Places[tp][i].n = 0; j = 1 + ((int)ignpoi(P.PlaceTypeMeanSize[tp] - 1)); - if (j > USHRT_MAX - 1) j = USHRT_MAX - 1; + if (j > USHRT_MAX - 1) + j = USHRT_MAX - 1; m += (int)(Places[tp][i].treat_end_time = (unsigned short)j); } } - //added this code to allow a place size to be specified according to a lognormal distribution - ggilani 09/02/17 + // added this code to allow a place size to be specified according to a lognormal + // distribution - ggilani 09/02/17 else if (P.PlaceTypeSizePower[tp] == 0 && P.PlaceTypeSizeSD[tp] > 0) { for (int i = 0; i < P.Nplace[tp]; i++) { Places[tp][i].n = 0; j = (int)gen_lognormal(P.PlaceTypeMeanSize[tp], P.PlaceTypeSizeSD[tp]); - if (j > USHRT_MAX - 1) j = USHRT_MAX - 1; + if (j > USHRT_MAX - 1) + j = USHRT_MAX - 1; m += (int)(Places[tp][i].treat_end_time = (unsigned short)j); } } else { - s = pow(P.PlaceTypeSizeOffset[tp] / (P.PlaceTypeSizeOffset[tp] + P.PlaceTypeSizeMax[tp] - 1), P.PlaceTypeSizePower[tp]); + s = pow(P.PlaceTypeSizeOffset[tp] / + (P.PlaceTypeSizeOffset[tp] + P.PlaceTypeSizeMax[tp] - 1), + P.PlaceTypeSizePower[tp]); for (int i = 0; i < P.Nplace[tp]; i++) { - j = (int)floor(P.PlaceTypeSizeOffset[tp] * pow((1 - s) * ranf() + s, -1 / P.PlaceTypeSizePower[tp]) + 1 - P.PlaceTypeSizeOffset[tp]); - if (j > USHRT_MAX - 1) j = USHRT_MAX - 1; + j = (int)floor(P.PlaceTypeSizeOffset[tp] * + pow((1 - s) * ranf() + s, -1 / P.PlaceTypeSizePower[tp]) + + 1 - P.PlaceTypeSizeOffset[tp]); + if (j > USHRT_MAX - 1) + j = USHRT_MAX - 1; m += (int)(Places[tp][i].treat_end_time = (unsigned short)j); Places[tp][i].n = 0; } @@ -1975,7 +2228,9 @@ void AssignPeopleToPlaces() if (tp < P.nsp) { t = ((double)m) / ((double)P.Nplace[tp]); - fprintf(stderr, "Adjusting place weights by cell (Capacity=%i Demand=%i Av place size=%lg)\n", m, cnt, t); + fprintf(stderr, + "Adjusting place weights by cell (Capacity=%i Demand=%i Av place size=%lg)\n", m, + cnt, t); for (int i = 0; i < P.Nplace[tp]; i++) if (Places[tp][i].treat_end_time > 0) { @@ -1987,49 +2242,64 @@ void AssignPeopleToPlaces() { int i = k % P.nch; j = k / P.nch; - f2 = Cells[k].I; f3 = Cells[k].S; + f2 = Cells[k].I; + f3 = Cells[k].S; if ((i > 0) && (j > 0)) { - f2 += Cells[(j - 1) * P.nch + (i - 1)].I; f3 += Cells[(j - 1) * P.nch + (i - 1)].S; + f2 += Cells[(j - 1) * P.nch + (i - 1)].I; + f3 += Cells[(j - 1) * P.nch + (i - 1)].S; } if (i > 0) { - f2 += Cells[j * P.nch + (i - 1)].I; f3 += Cells[j * P.nch + (i - 1)].S; + f2 += Cells[j * P.nch + (i - 1)].I; + f3 += Cells[j * P.nch + (i - 1)].S; } if ((i > 0) && (j < P.ncw - 1)) { - f2 += Cells[(j + 1) * P.nch + (i - 1)].I; f3 += Cells[(j + 1) * P.nch + (i - 1)].S; + f2 += Cells[(j + 1) * P.nch + (i - 1)].I; + f3 += Cells[(j + 1) * P.nch + (i - 1)].S; } if (j > 0) { - f2 += Cells[(j - 1) * P.nch + i].I; f3 += Cells[(j - 1) * P.nch + i].S; + f2 += Cells[(j - 1) * P.nch + i].I; + f3 += Cells[(j - 1) * P.nch + i].S; } if (j < P.ncw - 1) { - f2 += Cells[(j + 1) * P.nch + i].I; f3 += Cells[(j + 1) * P.nch + i].S; + f2 += Cells[(j + 1) * P.nch + i].I; + f3 += Cells[(j + 1) * P.nch + i].S; } if ((i < P.nch - 1) && (j > 0)) { - f2 += Cells[(j - 1) * P.nch + (i + 1)].I; f3 += Cells[(j - 1) * P.nch + (i + 1)].S; + f2 += Cells[(j - 1) * P.nch + (i + 1)].I; + f3 += Cells[(j - 1) * P.nch + (i + 1)].S; } if (i < P.nch - 1) { - f2 += Cells[j * P.nch + (i + 1)].I; f3 += Cells[j * P.nch + (i + 1)].S; + f2 += Cells[j * P.nch + (i + 1)].I; + f3 += Cells[j * P.nch + (i + 1)].S; } if ((i < P.nch - 1) && (j < P.ncw - 1)) { - f2 += Cells[(j + 1) * P.nch + (i + 1)].I; f3 += Cells[(j + 1) * P.nch + (i + 1)].S; + f2 += Cells[(j + 1) * P.nch + (i + 1)].I; + f3 += Cells[(j + 1) * P.nch + (i + 1)].S; } - Cells[k].L = f3; Cells[k].R = f2; + Cells[k].L = f3; + Cells[k].R = f2; } m = f2 = f3 = f4 = 0; for (k = 0; k < P.NC; k++) if ((Cells[k].S > 0) && (Cells[k].I == 0)) { - f2 += Cells[k].S; f3++; - if (Cells[k].R == 0) f4 += Cells[k].S; + f2 += Cells[k].S; + f3++; + if (Cells[k].R == 0) + f4 += Cells[k].S; } - fprintf(stderr, "Demand in cells with no places=%i in %i cells\nDemand in cells with no places <=1 cell away=%i\n", f2, f3, f4); + fprintf(stderr, + "Demand in cells with no places=%i in %i cells\nDemand in cells with no places " + "<=1 cell away=%i\n", + f2, f3, f4); for (int i = 0; i < P.Nplace[tp]; i++) if (Places[tp][i].treat_end_time > 0) { @@ -2038,14 +2308,17 @@ void AssignPeopleToPlaces() if ((Cells[k].L > 0) && (Cells[k].R > 0)) { s = ((double)Cells[k].L) / ((double)Cells[k].R); - Places[tp][i].treat_end_time = (unsigned short)ceil(Places[tp][i].treat_end_time * s); + Places[tp][i].treat_end_time = + (unsigned short)ceil(Places[tp][i].treat_end_time * s); } m += ((int)Places[tp][i].treat_end_time); } - for (int i = 0; i < P.NC; i++) Cells[i].L = Cells[i].I = Cells[i].R = 0; + for (int i = 0; i < P.NC; i++) + Cells[i].L = Cells[i].I = Cells[i].R = 0; } t = ((double)m) / ((double)P.Nplace[tp]); - fprintf(stderr, "Adjusting place weights (Capacity=%i Demand=%i Av place size=%lg)\n", m, cnt, t); + fprintf(stderr, "Adjusting place weights (Capacity=%i Demand=%i Av place size=%lg)\n", m, + cnt, t); for (int i = m = 0; i < P.Nplace[tp]; i++) { s = ((double)Places[tp][i].treat_end_time) * 43 / 40 - 1; @@ -2063,15 +2336,18 @@ void AssignPeopleToPlaces() j2 = -j2; for (int i = 0; i < j2; i++) { - while (Places[tp][j = (int)(((double)P.Nplace[tp]) * ranf())].treat_end_time < 2); + while (Places[tp][j = (int)(((double)P.Nplace[tp]) * ranf())].treat_end_time < 2) + ; Places[tp][j].treat_end_time--; } if (P.PlaceTypeNearestNeighb[tp] == 0) { - for (int i = 0; i < P.NC; i++) Cells[i].S = 0; + for (int i = 0; i < P.NC; i++) + Cells[i].S = 0; for (j = 0; j < P.Nplace[tp]; j++) { - int i = P.nch * ((int)(Places[tp][j].loc.x / P.in_cells_.width)) + ((int)(Places[tp][j].loc.y / P.in_cells_.height)); + int i = P.nch * ((int)(Places[tp][j].loc.x / P.in_cells_.width)) + + ((int)(Places[tp][j].loc.y / P.in_cells_.height)); Cells[i].S += (int)Places[tp][j].treat_end_time; } for (int i = 0; i < P.NC; i++) @@ -2079,13 +2355,15 @@ void AssignPeopleToPlaces() if (Cells[i].S > Cells[i].cumTC) { free(Cells[i].susceptible); - if (!(Cells[i].susceptible = (int*)calloc(Cells[i].S, sizeof(int)))) ERR_CRITICAL("Unable to allocate cell storage\n"); + if (!(Cells[i].susceptible = (int *)calloc(Cells[i].S, sizeof(int)))) + ERR_CRITICAL("Unable to allocate cell storage\n"); } Cells[i].S = 0; } for (j = 0; j < P.Nplace[tp]; j++) { - int i = P.nch * ((int)(Places[tp][j].loc.x / P.in_cells_.width)) + ((int)(Places[tp][j].loc.y / P.in_cells_.height)); + int i = P.nch * ((int)(Places[tp][j].loc.x / P.in_cells_.width)) + + ((int)(Places[tp][j].loc.y / P.in_cells_.height)); k = (int)Places[tp][j].treat_end_time; for (j2 = 0; j2 < k; j2++) { @@ -2096,8 +2374,11 @@ void AssignPeopleToPlaces() } for (int i = 0; i < P.NumThreads; i++) { - if (!(NearestPlaces[i] = (int*)calloc(P.PlaceTypeNearestNeighb[tp] + CACHE_LINE_SIZE, sizeof(int))) || - !(NearestPlacesProb[i] = (double*)calloc(P.PlaceTypeNearestNeighb[tp] + CACHE_LINE_SIZE, sizeof(double)))) ERR_CRITICAL("Unable to allocate cell storage\n"); + if (!(NearestPlaces[i] = + (int *)calloc(P.PlaceTypeNearestNeighb[tp] + CACHE_LINE_SIZE, sizeof(int))) || + !(NearestPlacesProb[i] = (double *)calloc( + P.PlaceTypeNearestNeighb[tp] + CACHE_LINE_SIZE, sizeof(double)))) + ERR_CRITICAL("Unable to allocate cell storage\n"); } P.KernelType = P.PlaceTypeKernelType[tp]; P.KernelScale = P.PlaceTypeKernelScale[tp]; @@ -2116,15 +2397,20 @@ void AssignPeopleToPlaces() int tn = 0; for (j = 0; j < a; j++) { - if (j % 1000 == 0) fprintf(stderr, "(%i) %i \r", tp, j); - for (i2 = 0; i2 < nn; i2++) NearestPlacesProb[tn][i2] = 0; - l = 1; k = m = f2 = 0; + if (j % 1000 == 0) + fprintf(stderr, "(%i) %i \r", tp, j); + for (i2 = 0; i2 < nn; i2++) + NearestPlacesProb[tn][i2] = 0; + l = 1; + k = m = f2 = 0; int i = PeopleArray[j]; ic = Hosts[i].mcell; MicroCellPosition mc_position = P.get_micro_cell_position_from_cell_index(ic); Direction m2 = Right; - if (Hosts[i].PlaceLinks[tp] < 0) //added this so that if any hosts have already be assigned due to their household membership, they will not be reassigned + if (Hosts[i].PlaceLinks[tp] < + 0) // added this so that if any hosts have already be assigned due to their + // household membership, they will not be reassigned { while (((k < nn) || (l < 4)) && (l < P.get_number_of_micro_cells_wide())) { @@ -2135,16 +2421,20 @@ void AssignPeopleToPlaces() { for (cnt = 0; cnt < Mcells[ic].np[tp]; cnt++) { - if (Mcells[ic].places[tp][cnt] >= P.Nplace[tp]) fprintf(stderr, "#%i %i %i ", tp, ic, cnt); + if (Mcells[ic].places[tp][cnt] >= P.Nplace[tp]) + fprintf(stderr, "#%i %i %i ", tp, ic, cnt); t = dist2_raw(Households[Hosts[i].hh].loc.x, Households[Hosts[i].hh].loc.y, - Places[tp][Mcells[ic].places[tp][cnt]].loc.x, Places[tp][Mcells[ic].places[tp][cnt]].loc.y); + Places[tp][Mcells[ic].places[tp][cnt]].loc.x, + Places[tp][Mcells[ic].places[tp][cnt]].loc.y); s = numKernel(t); if (tp < P.nsp) { t = ((double)Places[tp][Mcells[ic].places[tp][cnt]].treat_end_time); if (HOST_AGE_YEAR(i) < P.PlaceTypeMaxAgeRead[tp]) { - if ((t > 0) && (Places[tp][Mcells[ic].places[tp][cnt]].AvailByAge[HOST_AGE_YEAR(i)] > 0)) + if ((t > 0) && + (Places[tp][Mcells[ic].places[tp][cnt]].AvailByAge[HOST_AGE_YEAR(i)] > + 0)) s *= t; else s = 0; @@ -2169,7 +2459,8 @@ void AssignPeopleToPlaces() { if (NearestPlacesProb[tn][i2] < t) { - t = NearestPlacesProb[tn][i2]; j2 = i2; + t = NearestPlacesProb[tn][i2]; + j2 = i2; } } if (s > t) @@ -2188,12 +2479,14 @@ void AssignPeopleToPlaces() { m2 = rotate_left(m2); m = (m + 1) % 2; - if (m == 0) l++; + if (m == 0) + l++; } } s = 0; - if (k > nn) fprintf(stderr, "*** k>P.PlaceTypeNearestNeighb[tp] ***\n"); + if (k > nn) + fprintf(stderr, "*** k>P.PlaceTypeNearestNeighb[tp] ***\n"); if (k == 0) { fprintf(stderr, "# %i %i \r", i, j); @@ -2215,8 +2508,10 @@ void AssignPeopleToPlaces() if (tp < P.nsp) Places[tp][Hosts[i].PlaceLinks[tp]].treat_end_time--; } - if (!f) Hosts[i].PlaceLinks[tp] = -1; - if (NearestPlaces[tn][i2] >= P.Nplace[tp]) fprintf(stderr, "@%i %i %i ", tp, i, j); + if (!f) + Hosts[i].PlaceLinks[tp] = -1; + if (NearestPlaces[tn][i2] >= P.Nplace[tp]) + fprintf(stderr, "@%i %i %i ", tp, i, j); } } } @@ -2260,7 +2555,8 @@ void AssignPeopleToPlaces() { s = ranf_mt(tn); l = Cells[i].InvCDF[(int)floor(s * 1024)]; - while (Cells[i].cum_trans[l] < s) l++; + while (Cells[i].cum_trans[l] < s) + l++; ct = CellLookup[l]; m = (int)(ranf_mt(tn) * ((double)ct->S)); j = -1; @@ -2276,16 +2572,19 @@ void AssignPeopleToPlaces() fprintf(stderr, "*%i %i: %i %i\n", k, tp, j, P.Nplace[tp]); ERR_CRITICAL("Out of bounds place link\n"); } - t = dist2_raw(Households[Hosts[k].hh].loc.x, Households[Hosts[k].hh].loc.y, Places[tp][j].loc.x, Places[tp][j].loc.y); + t = dist2_raw(Households[Hosts[k].hh].loc.x, Households[Hosts[k].hh].loc.y, + Places[tp][j].loc.x, Places[tp][j].loc.y); s = ((double)ct->S) / ((double)ct->S0) * numKernel(t) / Cells[i].max_trans[l]; if ((P.DoAdUnits) && (P.InhibitInterAdunitPlaceAssignment[tp] > 0)) { - if (Mcells[Hosts[k].mcell].adunit != Mcells[Places[tp][j].mcell].adunit) s *= (1 - P.InhibitInterAdunitPlaceAssignment[tp]); + if (Mcells[Hosts[k].mcell].adunit != Mcells[Places[tp][j].mcell].adunit) + s *= (1 - P.InhibitInterAdunitPlaceAssignment[tp]); } if (ranf_mt(tn) < s) { l = (--ct->S); - if (m < l) ct->susceptible[m] = ct->susceptible[l]; + if (m < l) + ct->susceptible[m] = ct->susceptible[l]; Places[tp][j].treat_end_time--; ca++; Hosts[k].PlaceLinks[tp] = j; @@ -2330,16 +2629,14 @@ void StratifyPlaces(void) if (P.DoPlaces) { fprintf(stderr, "Initialising groups in places\n"); -#pragma omp parallel for schedule(static,500) default(none) \ - shared(P, Hosts) +#pragma omp parallel for schedule(static, 500) default(none) shared(P, Hosts) for (int i = 0; i < P.PopSize; i++) for (int j = 0; j < NUM_PLACE_TYPES; j++) Hosts[i].PlaceGroupLinks[j] = 0; for (int j = 0; j < P.PlaceTypeNum; j++) for (int i = 0; i < P.Nplace[j]; i++) Places[j][i].n = 0; -#pragma omp parallel for schedule(static,1) default(none) \ - shared(P, Places, Hosts) +#pragma omp parallel for schedule(static, 1) default(none) shared(P, Places, Hosts) for (int tn = 0; tn < P.NumThreads; tn++) for (int j = tn; j < P.PlaceTypeNum; j += P.NumThreads) { @@ -2348,7 +2645,8 @@ void StratifyPlaces(void) int l = 2 * ((int)P.PlaceTypeMeanSize[j]); for (int i = 0; i < P.Nplace[j]; i++) { - if (!(Places[j][i].members = (int*)calloc(l, sizeof(int)))) ERR_CRITICAL("Unable to allocate place storage\n"); + if (!(Places[j][i].members = (int *)calloc(l, sizeof(int)))) + ERR_CRITICAL("Unable to allocate place storage\n"); Places[j][i].n = 0; } } @@ -2363,7 +2661,8 @@ void StratifyPlaces(void) { if (Places[j][i].n > 0) { - if (!(Places[j][i].members = (int*)calloc(Places[j][i].n, sizeof(int)))) ERR_CRITICAL("Unable to allocate place storage\n"); + if (!(Places[j][i].members = (int *)calloc(Places[j][i].n, sizeof(int)))) + ERR_CRITICAL("Unable to allocate place storage\n"); } Places[j][i].n = 0; } @@ -2384,8 +2683,9 @@ void StratifyPlaces(void) Places[j][i].ng = 1; else Places[j][i].ng = 1 + (int)ignpoi_mt(t, tn); - if (!(Places[j][i].group_start = (int*)calloc(Places[j][i].ng, sizeof(int))) || - !(Places[j][i].group_size = (int*)calloc(Places[j][i].ng, sizeof(int)))) ERR_CRITICAL("Unable to allocate place storage\n"); + if (!(Places[j][i].group_start = (int *)calloc(Places[j][i].ng, sizeof(int))) || + !(Places[j][i].group_size = (int *)calloc(Places[j][i].ng, sizeof(int)))) + ERR_CRITICAL("Unable to allocate place storage\n"); int m = Places[j][i].n - Places[j][i].ng; int l; for (int k = l = 0; k < Places[j][i].ng; k++) @@ -2413,8 +2713,7 @@ void StratifyPlaces(void) } } -#pragma omp parallel for schedule(static,1) default (none) \ - shared(P, Places, StateT) +#pragma omp parallel for schedule(static, 1) default(none) shared(P, Places, StateT) for (int i = 0; i < P.NumThreads; i++) { for (int k = 0; k < P.PlaceTypeNum; k++) @@ -2424,13 +2723,15 @@ void StratifyPlaces(void) int l = 0; for (int j = 0; j < P.Nplace[k]; j++) l += (int)Places[k][j].ng; - if (!(StateT[i].p_queue[k] = (int*)calloc(l, sizeof(int))) || - !(StateT[i].pg_queue[k] = (int*)calloc(l, sizeof(int)))) ERR_CRITICAL("Unable to allocate state storage\n"); + if (!(StateT[i].p_queue[k] = (int *)calloc(l, sizeof(int))) || + !(StateT[i].pg_queue[k] = (int *)calloc(l, sizeof(int)))) + ERR_CRITICAL("Unable to allocate state storage\n"); } else { - if (!(StateT[i].p_queue[k] = (int*)calloc(P.Nplace[k], sizeof(int))) || - !(StateT[i].pg_queue[k] = (int*)calloc(P.Nplace[k], sizeof(int)))) ERR_CRITICAL("Unable to allocate state storage\n"); + if (!(StateT[i].p_queue[k] = (int *)calloc(P.Nplace[k], sizeof(int))) || + !(StateT[i].pg_queue[k] = (int *)calloc(P.Nplace[k], sizeof(int)))) + ERR_CRITICAL("Unable to allocate state storage\n"); } } } @@ -2460,14 +2761,15 @@ void StratifyPlaces(void) } } -void LoadPeopleToPlaces(char* NetworkFile) +void LoadPeopleToPlaces(char *NetworkFile) { int i, j, k, l, m, n, npt, i2; int32_t s1, s2; - FILE* dat; + FILE *dat; int fileversion; - if (!(dat = fopen(NetworkFile, "rb"))) ERR_CRITICAL("Unable to open network file for loading\n"); + if (!(dat = fopen(NetworkFile, "rb"))) + ERR_CRITICAL("Unable to open network file for loading\n"); fread_big(&fileversion, sizeof(fileversion), 1, dat); if (fileversion != NETWORK_FILE_VERSION) { @@ -2479,11 +2781,16 @@ void LoadPeopleToPlaces(char* NetworkFile) fread_big(&j, sizeof(int), 1, dat); fread_big(&s1, sizeof(int32_t), 1, dat); fread_big(&s2, sizeof(int32_t), 1, dat); - if (i != npt) ERR_CRITICAL("Number of place types does not match saved value\n"); - if (j != P.PopSize) ERR_CRITICAL("Population size does not match saved value\n"); - if ((s1 != P.setupSeed1) || (s2 != P.setupSeed2)) { - ERR_CRITICAL_FMT("Random number seeds do not match saved values: %" PRId32 " != %" PRId32 " || %" PRId32 " != %" PRId32 "\n", s1, P.setupSeed1, s2, P.setupSeed2); - } + if (i != npt) + ERR_CRITICAL("Number of place types does not match saved value\n"); + if (j != P.PopSize) + ERR_CRITICAL("Population size does not match saved value\n"); + if ((s1 != P.setupSeed1) || (s2 != P.setupSeed2)) + { + ERR_CRITICAL_FMT("Random number seeds do not match saved values: %" PRId32 " != %" PRId32 + " || %" PRId32 " != %" PRId32 "\n", + s1, P.setupSeed1, s2, P.setupSeed2); + } k = (P.PopSize + 999999) / 1000000; for (i = 0; i < P.PopSize; i++) for (j = 0; j < P.PlaceTypeNum; j++) @@ -2514,17 +2821,19 @@ void LoadPeopleToPlaces(char* NetworkFile) if((i+1)%100000==0) fprintf(stderr,"%i loaded \r",i+1); fread_big(&(Hosts[i].PlaceLinks[0]),sizeof(int),P.PlaceTypeNum,dat); } - */ fprintf(stderr, "\n"); + */ + fprintf(stderr, "\n"); fclose(dat); } -void SavePeopleToPlaces(char* NetworkFile) +void SavePeopleToPlaces(char *NetworkFile) { int i, j, npt; - FILE* dat; + FILE *dat; int fileversion = NETWORK_FILE_VERSION; npt = P.PlaceTypeNoAirNum; - if (!(dat = fopen(NetworkFile, "wb"))) ERR_CRITICAL("Unable to open network file for saving\n"); + if (!(dat = fopen(NetworkFile, "wb"))) + ERR_CRITICAL("Unable to open network file for saving\n"); fwrite_big(&fileversion, sizeof(fileversion), 1, dat); if (P.PlaceTypeNum > 0) @@ -2535,9 +2844,11 @@ void SavePeopleToPlaces(char* NetworkFile) fwrite_big(&P.setupSeed2, sizeof(int32_t), 1, dat); for (i = 0; i < P.PopSize; i++) { - if ((i + 1) % 100000 == 0) fprintf(stderr, "%i saved \r", i + 1); + if ((i + 1) % 100000 == 0) + fprintf(stderr, "%i saved \r", i + 1); /* fwrite_big(&(Hosts[i].spatial_norm),sizeof(float),1,dat); - */ fwrite_big(&(Hosts[i].PlaceLinks[0]), sizeof(int), npt, dat); + */ + fwrite_big(&(Hosts[i].PlaceLinks[0]), sizeof(int), npt, dat); for (j = 0; j < npt; j++) if (Hosts[i].PlaceLinks[j] >= P.Nplace[j]) { @@ -2555,11 +2866,12 @@ void SavePeopleToPlaces(char* NetworkFile) void SaveAgeDistrib(void) { int i; - FILE* dat; + FILE *dat; char outname[1024]; sprintf(outname, "%s.agedist.xls", OutFile); - if (!(dat = fopen(outname, "wb"))) ERR_CRITICAL("Unable to open output file\n"); + if (!(dat = fopen(outname, "wb"))) + ERR_CRITICAL("Unable to open output file\n"); if (P.DoDeath) { fprintf(dat, "age\tfreq\tlifeexpect\n"); @@ -2567,7 +2879,8 @@ void SaveAgeDistrib(void) fprintf(dat, "%i\ta%.10f\t%.10f\n", i, AgeDist[i], AgeDist2[i]); fprintf(dat, "\np\tlife_expec\tage\n"); for (i = 0; i <= 1000; i++) - fprintf(dat, "%.10f\t%.10f\t%i\n", ((double)i) / 1000, P.InvLifeExpecDist[0][i], State.InvAgeDist[0][i]); + fprintf(dat, "%.10f\t%.10f\t%i\n", ((double)i) / 1000, P.InvLifeExpecDist[0][i], + State.InvAgeDist[0][i]); } else { diff --git a/src/SetupModel.h b/src/SetupModel.h index 63b88cd73..918cbe1a1 100644 --- a/src/SetupModel.h +++ b/src/SetupModel.h @@ -1,14 +1,14 @@ #ifndef COVIDSIM_SETUPMODEL_H_INCLUDED_ #define COVIDSIM_SETUPMODEL_H_INCLUDED_ -void SetupModel(char*, char*, char*, char*); -void SetupPopulation(char*, char*); +void SetupModel(char *, char *, char *, char *); +void SetupPopulation(char *, char *); void SetupAirports(void); void AssignHouseholdAges(int, int, int); void AssignPeopleToPlaces(void); void StratifyPlaces(void); -void LoadPeopleToPlaces(char*); -void SavePeopleToPlaces(char*); +void LoadPeopleToPlaces(char *); +void SavePeopleToPlaces(char *); void SaveAgeDistrib(void); void UpdateProbs(int); @@ -22,6 +22,6 @@ struct BinFile int cnt, ad; }; -extern char OutFile[1024],OutDensFile[1024]; +extern char OutFile[1024], OutDensFile[1024]; #endif // COVIDSIM_SETUPMODEL_H_INCLUDED_ diff --git a/src/Sweep.cpp b/src/Sweep.cpp index 0e057d9cb..c08b965e9 100644 --- a/src/Sweep.cpp +++ b/src/Sweep.cpp @@ -1,34 +1,34 @@ #include #include -#include #include +#include #include "CalcInfSusc.h" #include "Dist.h" #include "Error.h" #include "InfStat.h" #include "Kernels.h" -#include "Rand.h" #include "Model.h" #include "ModelMacros.h" #include "Param.h" +#include "Rand.h" #include "Sweep.h" #include "Update.h" - void TravelReturnSweep(double t) { int l, nr, ner; // Convince static analysers that values are set correctly: - if (!(P.DoAirports && P.HotelPlaceType < P.PlaceTypeNum)) ERR_CRITICAL("DoAirports || HotelPlaceType not set\n"); + if (!(P.DoAirports && P.HotelPlaceType < P.PlaceTypeNum)) + ERR_CRITICAL("DoAirports || HotelPlaceType not set\n"); if (floor(1 + t + P.TimeStep) != floor(1 + t)) { nr = ner = 0; int floorOfTime = (int)floor(t); l = 1 + floorOfTime % MAX_TRAVEL_TIME; - FILE* stderr_shared = stderr; + FILE *stderr_shared = stderr; #pragma omp parallel for reduction(+:nr, ner) schedule(static, 1) default(none) \ shared(P, Places, Hosts, l, stderr_shared) for (int tn = 0; tn < P.NumThreads; tn++) @@ -43,10 +43,10 @@ void TravelReturnSweep(double t) { n--; /* if((n<0)||(Places[P.HotelPlaceType][j].members[n]<0)||(Places[P.HotelPlaceType][j].members[n]>=P.PopSize)) - {fprintf(stderr,"### %i %i %i %i\n",j,k,n,Places[P.HotelPlaceType][j].members[n]);ner++;} - else if((k<0)||(k>n)) - {fprintf(stderr,"@ %i %i %i %i\n",j,k,n,Places[P.HotelPlaceType][j].members[n]);ner++;} - else + {fprintf(stderr,"### %i %i %i + %i\n",j,k,n,Places[P.HotelPlaceType][j].members[n]);ner++;} else if((k<0)||(k>n)) + {fprintf(stderr,"@ %i %i %i + %i\n",j,k,n,Places[P.HotelPlaceType][j].members[n]);ner++;} else */ if (k != n) { @@ -55,7 +55,8 @@ void TravelReturnSweep(double t) nr++; if (Hosts[i].PlaceLinks[P.HotelPlaceType] != j) { - ner++; fprintf(stderr_shared, "(%i %i) ", j, Hosts[i].PlaceLinks[P.HotelPlaceType]); + ner++; + fprintf(stderr_shared, "(%i %i) ", j, Hosts[i].PlaceLinks[P.HotelPlaceType]); } Hosts[i].PlaceLinks[P.HotelPlaceType] = -1; Hosts[i].Travelling = 0; @@ -74,11 +75,13 @@ void TravelDepartSweep(double t) double nl; // Convince static analysers that values are set correctly: - if (!(P.DoAirports && P.HotelPlaceType < P.PlaceTypeNum)) ERR_CRITICAL("DoAirports || HotelPlaceType not set\n"); + if (!(P.DoAirports && P.HotelPlaceType < P.PlaceTypeNum)) + ERR_CRITICAL("DoAirports || HotelPlaceType not set\n"); if (floor(1 + t - P.TimeStep) != floor(1 + t)) { - bm = ((P.DoBlanketMoveRestr) && (t >= P.MoveRestrTimeStart) && (t < P.MoveRestrTimeStart + P.MoveRestrDuration)); + bm = ((P.DoBlanketMoveRestr) && (t >= P.MoveRestrTimeStart) && + (t < P.MoveRestrTimeStart + P.MoveRestrDuration)); mps = 2 * ((int)P.PlaceTypeMeanSize[P.HotelPlaceType]) - P.NumThreads - 1; int floorOfTime = (int)floor(t); d = floorOfTime % MAX_TRAVEL_TIME; @@ -90,7 +93,8 @@ void TravelDepartSweep(double t) if ((Airports[i].total_traffic > 0) && (Airports[i].num_mcell > 0)) { double s = Airports[i].total_traffic; - if ((t > P.AirportCloseTimeStart) && (t < P.AirportCloseTimeStart + P.AirportCloseTimeStartBase)) + if ((t > P.AirportCloseTimeStart) && + (t < P.AirportCloseTimeStart + P.AirportCloseTimeStartBase)) s *= P.AirportCloseEffectiveness; int n = (s > 0) ? ((int)ignpoi_mt((double)s, tn)) : 0; int f3 = 0; @@ -99,11 +103,13 @@ void TravelDepartSweep(double t) { s = ranf_mt(tn); int l = Airports[i].Inv_DestMcells[(int)floor(s * 1024)]; - while (Airports[i].DestMcells[l].prob < s) l++; + while (Airports[i].DestMcells[l].prob < s) + l++; l = Airports[i].DestMcells[l].id; int k = (int)(ranf_mt(tn) * ((double)Mcells[l].n)); int i2 = Mcells[l].members[k]; - if ((abs(Hosts[i2].inf) < InfStat_InfectiousAsymptomaticNotCase) && (Hosts[i2].inf != InfStat_Case)) + if ((abs(Hosts[i2].inf) < InfStat_InfectiousAsymptomaticNotCase) && + (Hosts[i2].inf != InfStat_Case)) { int d2 = HOST_AGE_GROUP(i2); if ((P.RelativeTravelRate[d2] == 1) || (ranf_mt(tn) < P.RelativeTravelRate[d2])) @@ -121,11 +127,13 @@ void TravelDepartSweep(double t) { s = ranf_mt(tn); l = Airports[i].Inv_prop_traffic[(int)floor(s * 128)]; - while (Airports[i].prop_traffic[l] < s) l++; + while (Airports[i].prop_traffic[l] < s) + l++; k = Airports[i].conn_airports[l]; if (bm) { - if (dist2_raw(Airports[i].loc.x, Airports[i].loc.y, Airports[k].loc.x, Airports[k].loc.y) > P.MoveRestrRadius2) + if (dist2_raw(Airports[i].loc.x, Airports[i].loc.y, Airports[k].loc.x, + Airports[k].loc.y) > P.MoveRestrRadius2) { if (ranf_mt(tn) > P.MoveRestrEffect) { @@ -144,7 +152,8 @@ void TravelDepartSweep(double t) { s = ranf_mt(tn); int m = Airports[k].Inv_DestPlaces[(int)floor(s * 1024)]; - while (Airports[k].DestPlaces[m].prob < s) m++; + while (Airports[k].DestPlaces[m].prob < s) + m++; l = Airports[k].DestPlaces[m].id; int hp; #pragma omp critical @@ -159,7 +168,8 @@ void TravelDepartSweep(double t) { f3 = 0; Places[P.HotelPlaceType][l].members[hp] = i2; - d2 = (d + P.InvJourneyDurationDistrib[(int)(ranf_mt(tn) * 1024.0)]) % MAX_TRAVEL_TIME; + d2 = (d + P.InvJourneyDurationDistrib[(int)(ranf_mt(tn) * 1024.0)]) % + MAX_TRAVEL_TIME; Hosts[i2].PlaceLinks[P.HotelPlaceType] = l; Hosts[i2].Travelling = 1 + d2; nad++; @@ -173,7 +183,8 @@ void TravelDepartSweep(double t) Hosts[i2].PlaceLinks[P.HotelPlaceType] = -1; if (++f3 > 100) { - j++; nsk++; + j++; + nsk++; } } } @@ -185,14 +196,16 @@ void TravelDepartSweep(double t) } } fprintf(stderr, " mps) { @@ -207,22 +220,32 @@ void TravelDepartSweep(double t) f = 0; double s = ranf_mt(tn); int l = Cells[c].InvCDF[(int)floor(s * 1024)]; - while (Cells[c].cum_trans[l] < s) l++; - Cell* ct = CellLookup[l]; + while (Cells[c].cum_trans[l] < s) + l++; + Cell *ct = CellLookup[l]; int m = (int)(ranf_mt(tn) * ((double)ct->S0)); if (m < (ct->S + ct->L)) { int i2 = ct->susceptible[m]; int d2 = HOST_AGE_GROUP(i2); int f3 = 0; - if ((Hosts[i2].Travelling == 0) && ((P.RelativeTravelRate[d2] == 1) || (ranf_mt(tn) < P.RelativeTravelRate[d2]))) + if ((Hosts[i2].Travelling == 0) && + ((P.RelativeTravelRate[d2] == 1) || (ranf_mt(tn) < P.RelativeTravelRate[d2]))) { #pragma omp critical - {if (Hosts[i2].PlaceLinks[P.HotelPlaceType] == -1) { Hosts[i2].PlaceLinks[P.HotelPlaceType] = -2; f3 = 1; }} + { + if (Hosts[i2].PlaceLinks[P.HotelPlaceType] == -1) + { + Hosts[i2].PlaceLinks[P.HotelPlaceType] = -2; + f3 = 1; + } + } } if (f3) { - double s2 = dist2_raw(Households[Hosts[i2].hh].loc.x, Households[Hosts[i2].hh].loc.y, Places[P.HotelPlaceType][i].loc.x, Places[P.HotelPlaceType][i].loc.y); + double s2 = + dist2_raw(Households[Hosts[i2].hh].loc.x, Households[Hosts[i2].hh].loc.y, + Places[P.HotelPlaceType][i].loc.x, Places[P.HotelPlaceType][i].loc.y); int f2 = 1; if ((bm) && (s2 > P.MoveRestrRadius2)) { @@ -245,7 +268,8 @@ void TravelDepartSweep(double t) } else { - d2 = (d + P.InvLocalJourneyDurationDistrib[(int)(ranf_mt(tn) * 1024.0)]) % MAX_TRAVEL_TIME; + d2 = (d + P.InvLocalJourneyDurationDistrib[(int)(ranf_mt(tn) * 1024.0)]) % + MAX_TRAVEL_TIME; int hp = Places[P.HotelPlaceType][i].n; Places[P.HotelPlaceType][i].n++; Places[P.HotelPlaceType][i].members[hp] = i2; @@ -268,92 +292,111 @@ void TravelDepartSweep(double t) } } -void InfectSweep(double t, int run) //added run number as argument in order to record it in event log +void InfectSweep(double t, + int run) // added run number as argument in order to record it in event log { - //// This function takes the day number (t) and run number (run) as inputs. It loops over infected people, and decides whom to infect. Structure is 1) #pragma loop over all cells then 1a) infectious people, which chooses who they will infect, adds them to a queue - //// Next 2) #pragma loop infects those people from queue (using DoInfect function). This is to avoid race conditions. - //// Loop 1a) calculates the force of infection exerted by each infected person on (and therefore number of new infections to) i) their house; ii) their place(s); iii) other spatial cells. - //// Each force of infection includes infectiousness and susceptibility components. - //// Infectiousness is (broadly) a function of 1 person (their age, treatment status, places, no. people in their household etc.) - //// Susceptibility is (broadly) a function of 2 people (a person's susceptibility TO ANOTHER PERSON / potential infector) - //// After loop 1a) over infectious people, spatial infections are doled out. - - int n; //// number of people you could potentially infect in your place group, then number of potential spatial infections doled out by cell on other cells. - int f, f2, cq /*cell queue*/, bm/*movement restrictions in place*/, ci /*person index*/; + //// This function takes the day number (t) and run number (run) as inputs. It loops over infected + /// people, and decides whom to infect. Structure is 1) #pragma loop over all cells then 1a) + /// infectious people, which chooses who they will infect, adds them to a queue / Next 2) #pragma + /// loop infects those people from queue (using DoInfect function). This is to avoid race + /// conditions. / Loop 1a) calculates the force of infection exerted by each infected person on + ///(and therefore number of new infections to) i) their house; ii) their place(s); iii) other + /// spatial cells. / Each force of infection includes infectiousness and susceptibility + /// components. / Infectiousness is (broadly) a function of 1 person (their age, treatment status, + ///places, no. people in their household etc.) / Susceptibility is (broadly) a function of 2 + /// people (a person's susceptibility TO ANOTHER PERSON / potential infector) / After loop 1a) over + /// infectious people, spatial infections are doled out. + + int n; //// number of people you could potentially infect in your place group, then number of + /// potential spatial infections doled out by cell on other cells. + int f, f2, cq /*cell queue*/, bm /*movement restrictions in place*/, ci /*person index*/; double seasonality, sbeta, hbeta; - //// various quantities of force of infection, including "infectiousness" and "susceptibility" components - double s; // household Force Of Infection (FOI) on fellow household member, then place susceptibility, then random number for spatial infections allocation* / ; - double s2; // spatial infectiousness, then distance in spatial infections allocation + //// various quantities of force of infection, including "infectiousness" and "susceptibility" + /// components + double s; // household Force Of Infection (FOI) on fellow household member, then place + // susceptibility, then random number for spatial infections allocation* / ; + double s2; // spatial infectiousness, then distance in spatial infections allocation double s3, s3_scaled; // household, then place infectiousness double s4, s4_scaled; // place infectiousness (copy of s3 as some code commented out - double s5; //// total spatial infectiousness summed over all infectious people in cell. + double s5; //// total spatial infectiousness summed over all infectious people in cell. double s6; double fp; //// false positive unsigned short int ts; // if not doing seasonality if (!P.DoSeasonality) - { + { // set seasonality to 1 seasonality = 1.0; } - else{ + else + { // otherwise pick seasonality from P.Seasonality array using day number in year seasonality = P.Seasonality[((int)t) % DAYS_PER_YEAR]; } - + // ts = the timestep number of the start of the current day - ts = (unsigned short int) (P.TimeStepsPerDay * t); + ts = (unsigned short int)(P.TimeStepsPerDay * t); // fp = false positive fp = P.TimeStep / (1 - P.FalsePositiveRate); // sbeta seasonality beta sbeta = seasonality * fp * P.LocalBeta; - + // hbeta = household beta // if doing households, hbeta = seasonality * fp * P.HouseholdTrans, else hbeta = 0 hbeta = (P.DoHouseholds) ? (seasonality * fp * P.HouseholdTrans) : 0; - - // Establish if movement restrictions are in place on current day - store in bm, 0:false, 1:true - bm = ((P.DoBlanketMoveRestr) && (t >= P.MoveRestrTimeStart) && (t < P.MoveRestrTimeStart + P.MoveRestrDuration)); + + // Establish if movement restrictions are in place on current day - store in bm, 0:false, 1:true + bm = ((P.DoBlanketMoveRestr) && (t >= P.MoveRestrTimeStart) && + (t < P.MoveRestrTimeStart + P.MoveRestrDuration)); // File for storing error reports - FILE* stderr_shared = stderr; - -#pragma omp parallel for private(n,f,f2,s,s2,s3,s4,s5,s6,cq,ci,s3_scaled,s4_scaled) schedule(static,1) default(none) \ - shared(t, P, CellLookup, Hosts, AdUnits, Households, Places, SamplingQueue, Cells, Mcells, StateT, hbeta, sbeta, seasonality, ts, fp, bm, stderr_shared) + FILE *stderr_shared = stderr; + +#pragma omp parallel for private(n, f, f2, s, s2, s3, s4, s5, s6, cq, ci, s3_scaled, s4_scaled) \ + schedule(static, 1) default(none) \ + shared(t, P, CellLookup, Hosts, AdUnits, Households, Places, SamplingQueue, Cells, Mcells, \ + StateT, hbeta, sbeta, seasonality, ts, fp, bm, stderr_shared) for (int tn = 0; tn < P.NumThreads; tn++) - for (int b = tn; b < P.NCP; b += P.NumThreads) //// loop over (in parallel) all populated cells. Loop 1) + for (int b = tn; b < P.NCP; + b += P.NumThreads) //// loop over (in parallel) all populated cells. Loop 1) { - Cell* c = CellLookup[b]; // select Cell given by index b + Cell *c = CellLookup[b]; // select Cell given by index b s5 = 0; ///// spatial infectiousness summed over all infectious people in loop below - + //// Loop over array of indices of infectious people c->I in cell c. Loop 1a) - for (int j = 0; j < c->I; j++) + for (int j = 0; j < c->I; j++) { //// get person index ci of j'th infected person in cell ci = c->infected[j]; - //// get person si from Hosts (array of people) corresponding to ci, using pointer arithmetic. - Person* si = Hosts + ci; + //// get person si from Hosts (array of people) corresponding to ci, using pointer + /// arithmetic. + Person *si = Hosts + ci; - //evaluate flag for digital contact tracing (fct) here at the beginning for each individual + // evaluate flag for digital contact tracing (fct) here at the beginning for each individual // fct = 1 if: // P.DoDigitalContactTracing = 1 (ie. digital contact tracing functionlity is switched on) - // AND Day number (t) is greater than the start day for contact tracing in this administrative unit (ie. contact tracing has started) - // AND Day number (t) is less than the end day for contact tracing in this administrative unit (ie. contact tracing has not ended) - // AND the selected host is a digital contact tracing user - // otherwise fct = 0 - int fct = ((P.DoDigitalContactTracing) && (t >= AdUnits[Mcells[si->mcell].adunit].DigitalContactTracingTimeStart) - && (t < AdUnits[Mcells[si->mcell].adunit].DigitalContactTracingTimeStart + P.DigitalContactTracingPolicyDuration) && (Hosts[ci].digitalContactTracingUser == 1)); // && (ts <= (Hosts[ci].detected_time + P.usCaseIsolationDelay))); + // AND Day number (t) is greater than the start day for contact tracing in this + // administrative unit (ie. contact tracing has started) AND Day number (t) is less than the + // end day for contact tracing in this administrative unit (ie. contact tracing has not + // ended) AND the selected host is a digital contact tracing user otherwise fct = 0 + int fct = ((P.DoDigitalContactTracing) && + (t >= AdUnits[Mcells[si->mcell].adunit].DigitalContactTracingTimeStart) && + (t < AdUnits[Mcells[si->mcell].adunit].DigitalContactTracingTimeStart + + P.DigitalContactTracingPolicyDuration) && + (Hosts[ci].digitalContactTracingUser == + 1)); // && (ts <= (Hosts[ci].detected_time + P.usCaseIsolationDelay))); // BEGIN HOUSEHOLD INFECTIONS - + //// Household Force Of Infection (FOI) component - - // hbeta = seasonality * fp * P.HouseholdTrans or 0 depending on whether households functionality is on or off - see start of function - - // if household beta (hbeta) > 0 + + // hbeta = seasonality * fp * P.HouseholdTrans or 0 depending on whether households + // functionality is on or off - see start of function + + // if household beta (hbeta) > 0 if (hbeta > 0) { - // For selected host si's household (si->hh), + // For selected host si's household (si->hh), // if the number of hosts (nh) in that Household is greater than 1 // AND the selected host is not travelling if ((Households[si->hh].nh > 1) && (!si->Travelling)) @@ -361,37 +404,50 @@ void InfectSweep(double t, int run) //added run number as argument in order to r int l = Households[si->hh].FirstPerson; int m = l + Households[si->hh].nh; // calculate infectiousness of selected household (s3) - // using the CalcHouseInf function on the selected cell and timestamp at start of current day - // then scaling by hbeta - s3 = hbeta * CalcHouseInf(ci, ts); + // using the CalcHouseInf function on the selected cell and timestamp at start of + // current day then scaling by hbeta + s3 = hbeta * CalcHouseInf(ci, ts); - // Test if any of the individuals in the selected persons household are absent from places - // f=0 means noone absent, f=1 means at least one absent + // Test if any of the individuals in the selected persons household are absent from + // places f=0 means noone absent, f=1 means at least one absent f = 0; // initialise f to be 0 - for (int i3 = l; (i3 < m) && (!f); i3++){ //// loop over people in household - for (int i2 = 0; (i2 < P.PlaceTypeNum) && (!f); i2++){ //// loop over place types - if (Hosts[i3].PlaceLinks[i2] >= 0){ //// if person in household has any sort of link to place type + for (int i3 = l; (i3 < m) && (!f); i3++) + { //// loop over people in household + for (int i2 = 0; (i2 < P.PlaceTypeNum) && (!f); i2++) + { //// loop over place types + if (Hosts[i3].PlaceLinks[i2] >= 0) + { //// if person in household has any sort of link to place type // if person is absent set f=1 - f = ((PLACE_CLOSED(i2, Hosts[i3].PlaceLinks[i2]))&&(HOST_ABSENT(i3))); + f = ((PLACE_CLOSED(i2, Hosts[i3].PlaceLinks[i2])) && (HOST_ABSENT(i3))); } } } - // if individuals in the household are absent from places (ie. f==1 from test immediately above), scale up the infectiousness (s3) of the household - if (f) { s3 *= P.PlaceCloseHouseholdRelContact; }/* NumPCD++;}*/ //// if people in your household are absent from places, person si/ci is more infectious to them, as they spend more time at home. - - // Loop from l (the index of the first person in the household) to m-1 (the index of the last person in the household) - // ie. loop over everyone in the household - for (int i3 = l; i3 < m; i3++) //// loop over all people in household (note goes from l to m - 1) + // if individuals in the household are absent from places (ie. f==1 from test + // immediately above), scale up the infectiousness (s3) of the household + if (f) + { + s3 *= P.PlaceCloseHouseholdRelContact; + } /* NumPCD++;}*/ //// if people in your household are absent from places, person si/ci + /// is more infectious to them, as they spend more time at home. + + // Loop from l (the index of the first person in the household) to m-1 (the index of the + // last person in the household) ie. loop over everyone in the household + for (int i3 = l; i3 < m; + i3++) //// loop over all people in household (note goes from l to m - 1) { - if ((Hosts[i3].inf == InfStat_Susceptible) && (!Hosts[i3].Travelling)) //// if people in household uninfected/susceptible and not travelling + if ((Hosts[i3].inf == InfStat_Susceptible) && + (!Hosts[i3].Travelling)) //// if people in household uninfected/susceptible and + /// not travelling { - s = s3 * CalcHouseSusc(i3, ts, ci, tn); //// FOI ( = infectiousness x susceptibility) from person ci/si on fellow household member i3 - + s = s3 * CalcHouseSusc(i3, ts, ci, + tn); //// FOI ( = infectiousness x susceptibility) from + /// person ci/si on fellow household member i3 + // Force of Infection (s) > random value between 0 and 1 - if (ranf_mt(tn) < s) + if (ranf_mt(tn) < s) { - // identify which cell queue (index cq) to add infection to + // identify which cell queue (index cq) to add infection to cq = Hosts[i3].pcell % P.NumThreads; if ((StateT[tn].n_queue[cq] < P.InfQueuePeakLength)) //(Hosts[i3].infector==-1)&& { @@ -402,27 +458,29 @@ void InfectSweep(double t, int run) //added run number as argument in order to r // ** infect household member i3 ** Hosts[i3].infector = ci; //// assign person ci as infector of person i3 - //infect_type: first 4 bits store type of infection + // infect_type: first 4 bits store type of infection // 1= household - // 2..NUM_PLACE_TYPES+1 = within-class/work-group place based transmission - // NUM_PLACE_TYPES+2..2*NUM_PLACE_TYPES+1 = between-class/work-group place based transmission - // 2*NUM_PLACE_TYPES+2 = "spatial" transmission (spatially local random mixing) + // 2..NUM_PLACE_TYPES+1 = within-class/work-group place based + // transmission NUM_PLACE_TYPES+2..2*NUM_PLACE_TYPES+1 = + // between-class/work-group place based transmission 2*NUM_PLACE_TYPES+2 + // = "spatial" transmission (spatially local random mixing) // bits >4 store the generation of infection - short int infect_type = 1 + INFECT_TYPE_MASK * (1 + si->infect_type / INFECT_TYPE_MASK); + short int infect_type = + 1 + INFECT_TYPE_MASK * (1 + si->infect_type / INFECT_TYPE_MASK); StateT[tn].inf_queue[cq][StateT[tn].n_queue[cq]++] = {ci, i3, infect_type}; } } - }// if FOI > s - } // if person in household uninfected/susceptible and not travelling - }// loop over people in household - } // if more than one person in household - }// if hbeta > 0 - + } // if FOI > s + } // if person in household uninfected/susceptible and not travelling + } // loop over people in household + } // if more than one person in household + } // if hbeta > 0 + // END HOUSHOLD INFECTIONS - + // BEGIN PLACE INFECTIONS - + // Still with infected person (si) = Hosts[ci] // if places functionality is enabled if (P.DoPlaces) @@ -431,69 +489,76 @@ void InfectSweep(double t, int run) //added run number as argument in order to r if (!HOST_ABSENT(ci)) { // select microcell (mi) corresponding to selected host (si) - Microcell* mi = Mcells + si->mcell; + Microcell *mi = Mcells + si->mcell; for (int k = 0; k < P.PlaceTypeNum; k++) //// loop over all place types { - // select link (l) between selected host (si) and place from si's placelinks to place type k + // select link (l) between selected host (si) and place from si's placelinks to place + // type k int l = si->PlaceLinks[k]; - if (l >= 0) //// l>=0 means if place type k is relevant to person si. (Now allowing for partial attendance). + if (l >= 0) //// l>=0 means if place type k is relevant to person si. (Now allowing + /// for partial attendance). { // infectiousness of place (s3) // = false positive rate * seasonality * place infectiousness s3 = fp * seasonality * CalcPlaceInf(ci, k, ts); // select microcell of the place linked to host si with link l - Microcell* mp = Mcells + Places[k][l].mcell; + Microcell *mp = Mcells + Places[k][l].mcell; // if blanket movement restrictions are in place on current day if (bm) { // if distance between si's household and linked place // is greater than movement restriction radius if ((dist2_raw(Households[si->hh].loc.x, Households[si->hh].loc.y, - Places[k][l].loc.x, Places[k][l].loc.y) > P.MoveRestrRadius2)) + Places[k][l].loc.x, Places[k][l].loc.y) > P.MoveRestrRadius2)) { // multiply infectiousness of place by movement restriction effect s3 *= P.MoveRestrEffect; } } - // else if movement restrictions in effect in either household microcell or place microcell - else if ((mi->moverest != mp->moverest) && ((mi->moverest == 2) || (mp->moverest == 2))) + // else if movement restrictions in effect in either household microcell or place + // microcell + else if ((mi->moverest != mp->moverest) && + ((mi->moverest == 2) || (mp->moverest == 2))) { // multiply infectiousness of place by movement restriction effect s3 *= P.MoveRestrEffect; } - + // BEGIN NON-HOTEL INFECTIONS - + // if linked place isn't a hotel and selected host isn't travelling if ((k != P.HotelPlaceType) && (!si->Travelling)) { - // i2 is index of group (of place type k) that selected host is linked to + // i2 is index of group (of place type k) that selected host is linked to int i2 = (si->PlaceGroupLinks[k]); - - // calculate infectiousness (s4_scaled) + + // calculate infectiousness (s4_scaled) // which varies if contact tracing is in place - // if contact tracing isn't in place s4_scaled is a copy of s3 - // if contact tracing is in place, s4_scaled is s3 * P.ScalingFactorPlaceDigitalContacts - // in either case s4_scaled is capped at 1 - + // if contact tracing isn't in place s4_scaled is a copy of s3 + // if contact tracing is in place, s4_scaled is s3 * + // P.ScalingFactorPlaceDigitalContacts in either case s4_scaled is capped at 1 + // if contact tracing if (fct) { // copy s3 s4 = s3; - // multiply s4 by P.ScalingFactorPlaceDigitalContacts - s4_scaled = s4 *P.ScalingFactorPlaceDigitalContacts; + // multiply s4 by P.ScalingFactorPlaceDigitalContacts + s4_scaled = s4 * P.ScalingFactorPlaceDigitalContacts; // cap s4 at 1 - if (s4 > 1) s4 = 1; + if (s4 > 1) + s4 = 1; // cap at 1 - if (s4_scaled > 1) s4_scaled = 1; + if (s4_scaled > 1) + s4_scaled = 1; } else { // copy s3 to s4 s4 = s3; // cap s4 at 1 - if (s4 > 1) s4 = 1; + if (s4 > 1) + s4 = 1; s4_scaled = s4; } @@ -504,77 +569,89 @@ void InfectSweep(double t, int run) //added run number as argument in order to r exit(1); } // else if infectiousness == 1 (should never be more than 1 due to capping above) - else if (s4_scaled >= 1) //// if place infectiousness above threshold, consider everyone in group a potential infectee... + else if (s4_scaled >= 1) //// if place infectiousness above threshold, consider + /// everyone in group a potential infectee... { // set n to be number of people in group in place k,l n = Places[k][l].group_size[i2]; } - else //// ... otherwise randomly sample (from binomial distribution) number of potential infectees in this place. + else //// ... otherwise randomly sample (from binomial distribution) number of + /// potential infectees in this place. { n = (int)ignbin_mt((int32_t)Places[k][l].group_size[i2], s4_scaled, tn); } - - // if potential infectees > 0 - if (n > 0) + + // if potential infectees > 0 + if (n > 0) { // pick n members of place k,l and add them to sampling queue for thread tn - SampleWithoutReplacement(tn, n, Places[k][l].group_size[i2]); //// changes thread-specific SamplingQueue. + SampleWithoutReplacement( + tn, n, + Places[k][l].group_size[i2]); //// changes thread-specific SamplingQueue. } - + // loop over sampling queue of potential infectees for (int m = 0; m < n; m++) { // pick potential infectee index i3 - int i3 = Places[k][l].members[Places[k][l].group_start[i2] + SamplingQueue[tn][m]]; - // calculate place susceptbility based on infectee (i3), place type (k), timestep (ts) - // cell (ci) and thread number (tn) + int i3 = + Places[k][l].members[Places[k][l].group_start[i2] + SamplingQueue[tn][m]]; + // calculate place susceptbility based on infectee (i3), place type (k), + // timestep (ts) cell (ci) and thread number (tn) s = CalcPlaceSusc(i3, k, ts, ci, tn); - + // ** add potential infectees to digital contact tracing queue** - // if contact tracing in place (fct) AND potential infectee (i3) is a contact tracing user - // AND potential infectee != infectionus person ci - // AND potential infectee (i3) isn't absent - if ((fct) && (Hosts[i3].digitalContactTracingUser) && (ci != i3) && (!HOST_ABSENT(i3))) + // if contact tracing in place (fct) AND potential infectee (i3) is a contact + // tracing user AND potential infectee != infectionus person ci AND potential + // infectee (i3) isn't absent + if ((fct) && (Hosts[i3].digitalContactTracingUser) && (ci != i3) && + (!HOST_ABSENT(i3))) { // scale place susceptibility by proportion who self isolate and store as s6 s6 = P.ProportionDigitalContactsIsolate * s; // if random number < s6 - // AND number of contacts of ci(!) is less than maximum digital contact to trace - if ((Hosts[ci].ncontacts < P.MaxDigitalContactsToTrace) && (ranf_mt(tn) P.MoveRestrRadius2)) + if ((dist2_raw(Households[Hosts[i3].hh].loc.x, + Households[Hosts[i3].hh].loc.y, Places[k][l].loc.x, + Places[k][l].loc.y) > P.MoveRestrRadius2)) { // multiply susceptibility by movement restriction effect s *= P.MoveRestrEffect; } } // else if movement restrictions are in place in either cell - else if ((mt->moverest != mp->moverest) && ((mt->moverest == 2) || (mp->moverest == 2))) + else if ((mt->moverest != mp->moverest) && + ((mt->moverest == 2) || (mp->moverest == 2))) { // multiply susceptibility by movement restriction effect s *= P.MoveRestrEffect; @@ -586,7 +663,8 @@ void InfectSweep(double t, int run) //added run number as argument in order to r // select cell containing potential infectee cq = Hosts[i3].pcell % P.NumThreads; // if infection queue for selected call < maximum length - if ((StateT[tn].n_queue[cq] < P.InfQueuePeakLength)) //(Hosts[i3].infector==-1)&& + if ((StateT[tn].n_queue[cq] < + P.InfQueuePeakLength)) //(Hosts[i3].infector==-1)&& { // false positive if ((P.FalsePositiveRate > 0) && (ranf_mt(tn) < P.FalsePositiveRate)) @@ -594,25 +672,30 @@ void InfectSweep(double t, int run) //added run number as argument in order to r else { // infect i3 - add if to infection queue for selected cell - short int infect_type = 2 + k + INFECT_TYPE_MASK * (1 + si->infect_type / INFECT_TYPE_MASK); - StateT[tn].inf_queue[cq][StateT[tn].n_queue[cq]++] = {ci, i3, infect_type}; + short int infect_type = + 2 + k + INFECT_TYPE_MASK * (1 + si->infect_type / INFECT_TYPE_MASK); + StateT[tn].inf_queue[cq][StateT[tn].n_queue[cq]++] = {ci, i3, + infect_type}; } } } } } } - + // END NON-HOTEL INFECTIONS - + // BEGIN HOTEL INFECTIONS - + // if selected host si is not travelling or selected link is to a hotel if ((k == P.HotelPlaceType) || (!si->Travelling)) { - s3 *= P.PlaceTypePropBetweenGroupLinks[k] * P.PlaceTypeGroupSizeParam1[k] / ((double)Places[k][l].n); - if (s3 > 1) s3 = 1; - // if contact tracing in place, multiply s3_scaled = s3*scalingfactor, otherwise s3_scaled = s3 + s3 *= P.PlaceTypePropBetweenGroupLinks[k] * P.PlaceTypeGroupSizeParam1[k] / + ((double)Places[k][l].n); + if (s3 > 1) + s3 = 1; + // if contact tracing in place, multiply s3_scaled = s3*scalingfactor, otherwise + // s3_scaled = s3 s3_scaled = (fct) ? (s3 * P.ScalingFactorPlaceDigitalContacts) : s3; // s3_scales shouldn't be less than 0 so generate error if it is if (s3_scaled < 0) @@ -626,8 +709,10 @@ void InfectSweep(double t, int run) //added run number as argument in order to r // using ignbin_mt function else n = (int)ignbin_mt((int32_t)Places[k][l].n, s3_scaled, tn); - // if more than 0 potential infectees, pick n hosts from the hotel and add to sampling queue - if (n > 0) SampleWithoutReplacement(tn, n, Places[k][l].n); + // if more than 0 potential infectees, pick n hosts from the hotel and add to + // sampling queue + if (n > 0) + SampleWithoutReplacement(tn, n, Places[k][l].n); // loop over the sampling queue for (int m = 0; m < n; m++) { @@ -635,30 +720,35 @@ void InfectSweep(double t, int run) //added run number as argument in order to r int i3 = Places[k][l].members[SamplingQueue[tn][m]]; // calculate place susceptibility s s = CalcPlaceSusc(i3, k, ts, ci, tn); - + // ** Do contact tracing in hotels ** - - //these are all place group contacts to be tracked for digital contact tracing - add to StateT queue for contact tracing - //if infectee is also a user, add them as a contact - - // if contact tracing in place AND potential infectee i3 is a contact tracing user AND i3 isn't absent AND i3 isn't ci (suspect this should be si) - if ((fct) && (Hosts[i3].digitalContactTracingUser) && (ci != i3) && (!HOST_ABSENT(i3))) + + // these are all place group contacts to be tracked for digital contact tracing + // - add to StateT queue for contact tracing if infectee is also a user, add + // them as a contact + + // if contact tracing in place AND potential infectee i3 is a contact tracing + // user AND i3 isn't absent AND i3 isn't ci (suspect this should be si) + if ((fct) && (Hosts[i3].digitalContactTracingUser) && (ci != i3) && + (!HOST_ABSENT(i3))) { // s6 = place susceptibility * proportion of digital contacts who self isolate s6 = P.ProportionDigitalContactsIsolate * s; // if number of contacts of infectious person < maximum and random number < s6 if ((Hosts[ci].ncontacts < P.MaxDigitalContactsToTrace) && (ranf_mt(tn) < s6)) { - Hosts[ci].ncontacts++; //add to number of contacts made + Hosts[ci].ncontacts++; // add to number of contacts made int ad = Mcells[Hosts[i3].mcell].adunit; if ((StateT[tn].ndct_queue[ad] < AdUnits[ad].n)) { - //find adunit for contact and add both contact and infectious host to lists - storing both so I can set times later. - StateT[tn].dct_queue[ad][StateT[tn].ndct_queue[ad]++] = { i3,ci,ts }; + // find adunit for contact and add both contact and infectious host to + // lists - storing both so I can set times later. + StateT[tn].dct_queue[ad][StateT[tn].ndct_queue[ad]++] = {i3, ci, ts}; } else { - fprintf(stderr_shared, "No more space in queue! Thread: %i, AdUnit: %i\n", tn, ad); + fprintf(stderr_shared, "No more space in queue! Thread: %i, AdUnit: %i\n", + tn, ad); } } } @@ -667,37 +757,43 @@ void InfectSweep(double t, int run) //added run number as argument in order to r if ((Hosts[i3].inf == InfStat_Susceptible) && (!HOST_ABSENT(i3))) { // mt = microcell of potential infectee - Microcell* mt = Mcells + Hosts[i3].mcell; + Microcell *mt = Mcells + Hosts[i3].mcell; - //if doing digital contact tracing, scale down susceptibility here - s*= CalcPersonSusc(i3, ts, ci, tn)*s3/s3_scaled; + // if doing digital contact tracing, scale down susceptibility here + s *= CalcPersonSusc(i3, ts, ci, tn) * s3 / s3_scaled; // if blanket movement restrictions are in place if (bm) { - // if potential infectees household is farther away from hotel than restriction radius - if ((dist2_raw(Households[Hosts[i3].hh].loc.x, Households[Hosts[i3].hh].loc.y, - Places[k][l].loc.x, Places[k][l].loc.y) > P.MoveRestrRadius2)) + // if potential infectees household is farther away from hotel than + // restriction radius + if ((dist2_raw(Households[Hosts[i3].hh].loc.x, + Households[Hosts[i3].hh].loc.y, Places[k][l].loc.x, + Places[k][l].loc.y) > P.MoveRestrRadius2)) { // multiply susceptibility by movement restriction effect s *= P.MoveRestrEffect; } } - // else if movement restrictions are in place in potential infectee's cell or hotel's cell - else if ((mt->moverest != mp->moverest) && ((mt->moverest == 2) || (mp->moverest == 2))) + // else if movement restrictions are in place in potential infectee's cell or + // hotel's cell + else if ((mt->moverest != mp->moverest) && + ((mt->moverest == 2) || (mp->moverest == 2))) { // multiply susceptibility by movement restriction effect s *= P.MoveRestrEffect; } - + // ** do infections ** - - // is susceptibility is 1 (ie infect everyone) or random number is less than susceptibility + + // is susceptibility is 1 (ie infect everyone) or random number is less than + // susceptibility if ((s == 1) || (ranf_mt(tn) < s)) { // store cell number of potential infectee i3 as cq cq = Hosts[i3].pcell % P.NumThreads; // if there is space in queue for this thread - if ((StateT[tn].n_queue[cq] < P.InfQueuePeakLength))//(Hosts[i3].infector==-1)&& + if ((StateT[tn].n_queue[cq] < + P.InfQueuePeakLength)) //(Hosts[i3].infector==-1)&& { // if random number < false positive rate if ((P.FalsePositiveRate > 0) && (ranf_mt(tn) < P.FalsePositiveRate)) @@ -705,50 +801,57 @@ void InfectSweep(double t, int run) //added run number as argument in order to r StateT[tn].inf_queue[cq][StateT[tn].n_queue[cq]++] = {-1, i3, -1}; else { - short int infect_type = 2 + k + NUM_PLACE_TYPES + INFECT_TYPE_MASK * (1 + si->infect_type / INFECT_TYPE_MASK); + short int infect_type = + 2 + k + NUM_PLACE_TYPES + + INFECT_TYPE_MASK * (1 + si->infect_type / INFECT_TYPE_MASK); // add infection of i3 by ci to infection queue - StateT[tn].inf_queue[cq][StateT[tn].n_queue[cq]++] = {ci, i3, infect_type}; + StateT[tn].inf_queue[cq][StateT[tn].n_queue[cq]++] = {ci, i3, + infect_type}; } - }// space in queue - }// susceptibility test - }// potential infectee i3 uninfected and not absent. - }// loop over sampling queue - }// selected host si is not travelling or selected link is to a hotel - - // ** END HOTEL INFECTIONS ** - - }// if place link relevant - }// loop over place types - }// if host isn't absent - }// if places functionality enabled - + } // space in queue + } // susceptibility test + } // potential infectee i3 uninfected and not absent. + } // loop over sampling queue + } // selected host si is not travelling or selected link is to a hotel + + // ** END HOTEL INFECTIONS ** + + } // if place link relevant + } // loop over place types + } // if host isn't absent + } // if places functionality enabled + // END PLACE INFECTIONS - + // BEGIN SPATIAL INFECTIONS - + //// First determine spatial FOI component (s5) - + // if seasonality beta > 0 - // do spatial infections - //// ie sum spatial infectiousness over all infected people, the infections from which are allocated after loop over infected people. - if (sbeta > 0) + // do spatial infections + //// ie sum spatial infectiousness over all infected people, the infections from which are + /// allocated after loop over infected people. + if (sbeta > 0) { - if (si->Travelling) //// if host currently away from their cell, they cannot add to their cell's spatial infectiousness. + if (si->Travelling) //// if host currently away from their cell, they cannot add to their + /// cell's spatial infectiousness. { - s2 = 0; + s2 = 0; f = 0; } else { // calculate spatial infectiousness (s2) based on host and timestep s2 = CalcSpatialInf(ci, ts); - //if do digital contact tracing, scale up spatial infectiousness of infectives who are using the app and will be detected + // if do digital contact tracing, scale up spatial infectiousness of infectives who are + // using the app and will be detected if (fct) { s2 *= P.ScalingFactorSpatialDigitalContacts; } } - // test if selected person si is linked to a place that is closed, f=0 means no links to closed places, otherwise f=1 + // test if selected person si is linked to a place that is closed, f=0 means no links to + // closed places, otherwise f=1 f = 0; // initialise f as 0 // If place functionality switched on if (P.DoPlaces) @@ -759,12 +862,16 @@ void InfectSweep(double t, int run) //added run number as argument in order to r if (si->PlaceLinks[i3] >= 0) //// if person has a link to place of type i3... { // if place is closed set f=1 - f = PLACE_CLOSED(i3, si->PlaceLinks[i3]); //// find out if that place of type i3 is closed. + f = PLACE_CLOSED( + i3, si->PlaceLinks[i3]); //// find out if that place of type i3 is closed. } } - }// if doing places + } // if doing places - if((f) && (HOST_ABSENT(ci))) //// if place is closed and person is absent then adjust the spatial infectiousness (similar logic to household infectiousness: place closure affects spatial infectiousness + if ((f) && + (HOST_ABSENT(ci))) //// if place is closed and person is absent then adjust the + /// spatial infectiousness (similar logic to household + /// infectiousness: place closure affects spatial infectiousness { s2 *= P.PlaceCloseSpatialRelContact; /* NumPCD++; */ @@ -778,27 +885,35 @@ void InfectSweep(double t, int run) //added run number as argument in order to r } } } // loop over infectious people in cell - - + //// Now allocate spatial infections using Force Of Infection (s5) calculated above if (s5 > 0) //// if spatial infectiousness positive { - - // decide how many potential cell to cell infections this cell could cause - n = (int)ignpoi_mt(s5 * sbeta * ((double)c->tot_prob), tn); //// number people this cell's population might infect elsewhere. poisson random number based on spatial infectiousness s5, sbeta (seasonality) and this cell's "probability" (guessing this is a function of its population and geographical size). + + // decide how many potential cell to cell infections this cell could cause + n = (int)ignpoi_mt(s5 * sbeta * ((double)c->tot_prob), + tn); //// number people this cell's population might infect elsewhere. + /// poisson random number based on spatial infectiousness s5, sbeta + ///(seasonality) and this cell's "probability" (guessing this is a + /// function of its population and geographical size). // i2 = number of infectious people in cell c int i2 = c->I; - - if (n > 0) //// this block normalises cumulative infectiousness cell_inf by person. s5 is the total cumulative spatial infectiousness. Reason is so that infector can be chosen using ranf_mt, which returns random number between 0 and 1. + + if (n > 0) //// this block normalises cumulative infectiousness cell_inf by person. s5 is + /// the total cumulative spatial infectiousness. Reason is so that infector can + /// be chosen using ranf_mt, which returns random number between 0 and 1. { //// normalise by cumulative spatial infectiousness. - for (int j = 0; j < i2 - 1; j++) StateT[tn].cell_inf[j] /= ((float) s5); - //// does same as the above loop just a slightly faster calculation. i.e. StateT[tn].cell_inf[i2 - 1] / s5 would equal 1 or -1 anyway. + for (int j = 0; j < i2 - 1; j++) + StateT[tn].cell_inf[j] /= ((float)s5); + //// does same as the above loop just a slightly faster calculation. i.e. + /// StateT[tn].cell_inf[i2 - 1] / s5 would equal 1 or -1 anyway. StateT[tn].cell_inf[i2 - 1] = (StateT[tn].cell_inf[i2 - 1] < 0) ? -1.0f : 1.0f; } - - //// loop over infections to dole out. roughly speaking, this determines which infectious person in cell c infects which person elsewhere. - for (int k = 0; k < n; k++) + + //// loop over infections to dole out. roughly speaking, this determines which infectious + /// person in cell c infects which person elsewhere. + for (int k = 0; k < n; k++) { //// decide on infector ci/si from cell c. int j; // j = index of infector @@ -808,43 +923,59 @@ void InfectSweep(double t, int run) //added run number as argument in order to r j = 0; // infector index is first in cell (person 0) } // if more than one infectious person in cell pick an infectious person (given by index j) - //// roughly speaking, this determines which infectious person in cell c infects which person elsewhere - else + //// roughly speaking, this determines which infectious person in cell c infects which + /// person elsewhere + else { int m; - s = ranf_mt(tn); ///// choose random number between 0 and 1 - j = m = i2 / 2; ///// assign j and m to be halfway between zero and number of infected people i2 = c->I. + s = ranf_mt(tn); ///// choose random number between 0 and 1 + j = m = i2 / 2; ///// assign j and m to be halfway between zero and number of infected + /// people i2 = c->I. f = 1; do { - if (m > 1) m /= 2; //// amount m to change j by reduced by half. Looks like a binary search. Basically saying, keep amending potential infector j until either j less than zero or more than number of infected people until you find j s.t. spatial infectiousness "matches" s. + if (m > 1) + m /= 2; //// amount m to change j by reduced by half. Looks like a binary search. + /// Basically saying, keep amending potential infector j until either j less + /// than zero or more than number of infected people until you find j s.t. + /// spatial infectiousness "matches" s. if ((j > 0) && (fabs(StateT[tn].cell_inf[j - 1]) >= s)) { j -= m; - if (j == 0) f = 0; + if (j == 0) + f = 0; } else if ((j < i2 - 1) && (fabs(StateT[tn].cell_inf[j]) < s)) { j += m; - if (j == i2 - 1) f = 0; + if (j == i2 - 1) + f = 0; } - else f = 0; + else + f = 0; } while (f); } - f = (StateT[tn].cell_inf[j] < 0); //// flag for whether infector j had their place(s) closed. <0 (true) = place closed / >=0 (false) = place not closed. Set in if (sbeta > 0) part of loop over infectious people. + f = (StateT[tn].cell_inf[j] < + 0); //// flag for whether infector j had their place(s) closed. <0 (true) = place + /// closed / >=0 (false) = place not closed. Set in if (sbeta > 0) part of loop + /// over infectious people. // ci is the index of the jth infectious person in the cell ci = c->infected[j]; // si is the jth selected person in the cell - Person* si = Hosts + ci; - - //calculate flag (fct) for digital contact tracing here at the beginning for each individual infector - int fct = ((P.DoDigitalContactTracing) && (t >= AdUnits[Mcells[si->mcell].adunit].DigitalContactTracingTimeStart) - && (t < AdUnits[Mcells[si->mcell].adunit].DigitalContactTracingTimeStart + P.DigitalContactTracingPolicyDuration) && (Hosts[ci].digitalContactTracingUser == 1)); // && (ts <= (Hosts[ci].detected_time + P.usCaseIsolationDelay))); + Person *si = Hosts + ci; + // calculate flag (fct) for digital contact tracing here at the beginning for each + // individual infector + int fct = ((P.DoDigitalContactTracing) && + (t >= AdUnits[Mcells[si->mcell].adunit].DigitalContactTracingTimeStart) && + (t < AdUnits[Mcells[si->mcell].adunit].DigitalContactTracingTimeStart + + P.DigitalContactTracingPolicyDuration) && + (Hosts[ci].digitalContactTracingUser == + 1)); // && (ts <= (Hosts[ci].detected_time + P.usCaseIsolationDelay))); //// decide on infectee - - // do the following while f2=0 + + // do the following while f2=0 do { //// chooses which cell person will infect @@ -853,106 +984,129 @@ void InfectSweep(double t, int run) //added run number as argument in order to r // generate l using InvCDF of selected cell and random integer between 0 and 1024 int l = c->InvCDF[(int)floor(s * 1024)]; // loop over c->cum_trans array until find a value >= random number s - while (c->cum_trans[l] < s) l++; + while (c->cum_trans[l] < s) + l++; // selecte the cell corresponding to l - Cell* ct = CellLookup[l]; + Cell *ct = CellLookup[l]; - ///// pick random person m within susceptibles of cell ct (S0 initial number susceptibles within cell). + ///// pick random person m within susceptibles of cell ct (S0 initial number + /// susceptibles within cell). int m = (int)(ranf_mt(tn) * ((double)ct->S0)); int i3 = ct->susceptible[m]; - - s2 = dist2(Hosts + i3, Hosts + ci); /// calculate distance squared between this susceptible person and person ci/si identified earlier + + s2 = dist2(Hosts + i3, + Hosts + ci); /// calculate distance squared between this susceptible person + /// and person ci/si identified earlier s = numKernel(s2) / c->max_trans[l]; //// acceptance probability - + // initialise f2=0 (f2=1 is the while condition for this loop) f2 = 0; // if random number greater than acceptance probablility or infectee is dead - if ((ranf_mt(tn) >= s) || (abs(Hosts[i3].inf) == InfStat_Dead)) //// if rejected, or infectee i3/m already dead, ensure do-while evaluated again (i.e. choose a new infectee). + if ((ranf_mt(tn) >= s) || + (abs(Hosts[i3].inf) == + InfStat_Dead)) //// if rejected, or infectee i3/m already dead, ensure do-while + /// evaluated again (i.e. choose a new infectee). { - // set f2=1 so loop continues + // set f2=1 so loop continues f2 = 1; } else { - //// if potential infectee not travelling, and either is not part of cell c or doesn't share a household with infector. - if ((!Hosts[i3].Travelling) && ((c != ct) || (Hosts[i3].hh != si->hh))) + //// if potential infectee not travelling, and either is not part of cell c or doesn't + /// share a household with infector. + if ((!Hosts[i3].Travelling) && ((c != ct) || (Hosts[i3].hh != si->hh))) { // pick microcell of infector (mi) - Microcell* mi = Mcells + si->mcell; + Microcell *mi = Mcells + si->mcell; // pick microcell of infectee (mt) - Microcell* mt = Mcells + Hosts[i3].mcell; + Microcell *mt = Mcells + Hosts[i3].mcell; s = CalcSpatialSusc(i3, ts, ci, tn); - //so this person is a contact - but might not be infected. if we are doing digital contact tracing, we want to add the person to the contacts list, if both are users + // so this person is a contact - but might not be infected. if we are doing digital + // contact tracing, we want to add the person to the contacts list, if both are + // users if (fct) { - //if infectee is also a user, add them as a contact + // if infectee is also a user, add them as a contact if (Hosts[i3].digitalContactTracingUser && (ci != i3)) { - if ((Hosts[ci].ncontactsS) // only bother trying to infect susceptible people + if (m < ct->S) // only bother trying to infect susceptible people { s *= CalcPersonSusc(i3, ts, ci, tn); if (bm) { if ((dist2_raw(Households[si->hh].loc.x, Households[si->hh].loc.y, - Households[Hosts[i3].hh].loc.x, Households[Hosts[i3].hh].loc.y) > P.MoveRestrRadius2)) + Households[Hosts[i3].hh].loc.x, + Households[Hosts[i3].hh].loc.y) > P.MoveRestrRadius2)) s *= P.MoveRestrEffect; } - else if ((mt->moverest != mi->moverest) && ((mt->moverest == 2) || (mi->moverest == 2))) + else if ((mt->moverest != mi->moverest) && + ((mt->moverest == 2) || (mi->moverest == 2))) s *= P.MoveRestrEffect; - if ((!f)&& (HOST_ABSENT(i3))) //// if infector did not have place closed, loop over place types of infectee i3 to see if their places had closed. If they had, amend their susceptibility. + if ((!f) && + (HOST_ABSENT(i3))) //// if infector did not have place closed, loop over place + /// types of infectee i3 to see if their places had closed. + /// If they had, amend their susceptibility. { for (m = f2 = 0; (m < P.PlaceTypeNum) && (!f2); m++) if (Hosts[i3].PlaceLinks[m] >= 0) { f2 = PLACE_CLOSED(m, Hosts[i3].PlaceLinks[m]); } - if (f2) { s *= P.PlaceCloseSpatialRelContact; }/* NumPCD++;} */ + if (f2) + { + s *= P.PlaceCloseSpatialRelContact; + } /* NumPCD++;} */ f2 = 0; } if ((s == 1) || (ranf_mt(tn) < s)) //// accept/reject { cq = ((int)(ct - Cells)) % P.NumThreads; - if ((Hosts[i3].inf == InfStat_Susceptible) && (StateT[tn].n_queue[cq] < P.InfQueuePeakLength)) //Hosts[i3].infector==-1 + if ((Hosts[i3].inf == InfStat_Susceptible) && + (StateT[tn].n_queue[cq] < P.InfQueuePeakLength)) // Hosts[i3].infector==-1 { if ((P.FalsePositiveRate > 0) && (ranf_mt(tn) < P.FalsePositiveRate)) - StateT[tn].inf_queue[cq][StateT[tn].n_queue[cq]++] = { -1, i3, -1 }; + StateT[tn].inf_queue[cq][StateT[tn].n_queue[cq]++] = {-1, i3, -1}; else { - short int infect_type = 2 + 2 * NUM_PLACE_TYPES + INFECT_TYPE_MASK * (1 + si->infect_type / INFECT_TYPE_MASK); - StateT[tn].inf_queue[cq][StateT[tn].n_queue[cq]++] = { ci, i3, infect_type }; + short int infect_type = + 2 + 2 * NUM_PLACE_TYPES + + INFECT_TYPE_MASK * (1 + si->infect_type / INFECT_TYPE_MASK); + StateT[tn].inf_queue[cq][StateT[tn].n_queue[cq]++] = {ci, i3, infect_type}; } } } - }// m < susceptible people in target cell - }// //// if potential infectee not travelling, and either is not part of cell c or doesn't share a household with infector - }// infectee isn't dead + } // m < susceptible people in target cell + } // //// if potential infectee not travelling, and either is not part of cell c or + // doesn't share a household with infector + } // infectee isn't dead } while (f2); - }// loop over infections doled out by cell - }// s5 > 0 + } // loop over infections doled out by cell + } // s5 > 0 } - -#pragma omp parallel for schedule(static,1) default(none) \ - shared(t, run, P, StateT, Hosts, ts) +#pragma omp parallel for schedule(static, 1) default(none) shared(t, run, P, StateT, Hosts, ts) for (int j = 0; j < P.NumThreads; j++) { for (int k = 0; k < P.NumThreads; k++) @@ -978,7 +1132,7 @@ void IncubRecoverySweep(double t, int run) { double ht; unsigned short int ts; //// this timestep - ts = (unsigned short int) (P.TimeStepsPerDay * t); + ts = (unsigned short int)(P.TimeStepsPerDay * t); if (P.DoPlaces) for (int i = 0; i < P.NumHolidays; i++) @@ -986,23 +1140,28 @@ void IncubRecoverySweep(double t, int run) ht = P.HolidayStartTime[i] + P.HolidaysStartDay_SimTime; if ((t + P.TimeStep >= ht) && (t < ht)) { -// fprintf(stderr, "Holiday %i t=%lg\n", i, t); + // fprintf(stderr, "Holiday %i t=%lg\n", i, t); for (int j = 0; j < P.PlaceTypeNum; j++) { -#pragma omp parallel for schedule(static,1) default(none) shared(P, Places, Hosts, i, j, ht) - for(int tn=0;tn= P.HolidayEffect[j]))) + if ((P.HolidayEffect[j] < 1) && + ((P.HolidayEffect[j] == 0) || (ranf_mt(tn) >= P.HolidayEffect[j]))) { int l = (int)(ht * P.TimeStepsPerDay); - if (Places[j][k].close_start_time > l) Places[j][k].close_start_time = (unsigned short) l; + if (Places[j][k].close_start_time > l) + Places[j][k].close_start_time = (unsigned short)l; int b = (int)((ht + P.HolidayDuration[i]) * P.TimeStepsPerDay); - if (Places[j][k].close_end_time < b) Places[j][k].close_end_time = (unsigned short) b; + if (Places[j][k].close_end_time < b) + Places[j][k].close_end_time = (unsigned short)b; for (int ci = 0; ci < Places[j][k].n; ci++) { - if (Hosts[Places[j][k].members[ci]].absent_start_time > l) Hosts[Places[j][k].members[ci]].absent_start_time = (unsigned short)l; - if (Hosts[Places[j][k].members[ci]].absent_stop_time < b) Hosts[Places[j][k].members[ci]].absent_stop_time = (unsigned short)b; + if (Hosts[Places[j][k].members[ci]].absent_start_time > l) + Hosts[Places[j][k].members[ci]].absent_start_time = (unsigned short)l; + if (Hosts[Places[j][k].members[ci]].absent_stop_time < b) + Hosts[Places[j][k].members[ci]].absent_stop_time = (unsigned short)b; } } } @@ -1010,31 +1169,48 @@ void IncubRecoverySweep(double t, int run) } } -#pragma omp parallel for schedule(static,1) default(none) shared(t, run, P, CellLookup, Hosts, AdUnits, Mcells, StateT, ts) - for (int tn = 0; tn < P.NumThreads; tn++) //// loop over threads - for (int b = tn; b < P.NCP; b += P.NumThreads) //// loop/step over populated cells +#pragma omp parallel for schedule(static, 1) default(none) \ + shared(t, run, P, CellLookup, Hosts, AdUnits, Mcells, StateT, ts) + for (int tn = 0; tn < P.NumThreads; tn++) //// loop over threads + for (int b = tn; b < P.NCP; b += P.NumThreads) //// loop/step over populated cells { - Cell* c = CellLookup[b]; //// find (pointer-to) cell. - for (int j = ((int)c->L - 1); j >= 0; j--) //// loop backwards over latently infected people, hence it starts from L - 1 and goes to zero. Runs backwards because of pointer swapping? - if (ts >= Hosts[c->latent[j]].latent_time) //// if now after time at which person became infectious (latent_time a slight misnomer). - DoIncub(c->latent[j], ts, tn, run); //// move infected person from latently infected (L) to infectious (I), but not symptomatic - //StateT[tn].n_queue[0] = StateT[tn].n_queue[1] = 0; - for (int j = c->I - 1; j >= 0; j--) ///// loop backwards over Infectious people. Runs backwards because of pointer swapping? + Cell *c = CellLookup[b]; //// find (pointer-to) cell. + for (int j = ((int)c->L - 1); j >= 0; + j--) //// loop backwards over latently infected people, hence it starts from L - 1 and + /// goes to zero. Runs backwards because of pointer swapping? + if (ts >= Hosts[c->latent[j]].latent_time) //// if now after time at which person became + /// infectious (latent_time a slight misnomer). + DoIncub(c->latent[j], ts, tn, run); //// move infected person from latently infected (L) + /// to infectious (I), but not symptomatic + // StateT[tn].n_queue[0] = StateT[tn].n_queue[1] = 0; + for (int j = c->I - 1; j >= 0; j--) ///// loop backwards over Infectious people. Runs + /// backwards because of pointer swapping? { - int ci = c->infected[j]; //// person index - Person* si = Hosts + ci; //// person - - unsigned short int tc; //// time at which person becomes case (i.e. moves from infectious and asymptomatic to infectious and symptomatic). - /* Following line not 100% consistent with DoIncub. All severity time points (e.g. SARI time) are added to latent_time, not latent_time + ((int)(P.LatentToSymptDelay / P.TimeStep))*/ - tc = si->latent_time + ((int)(P.LatentToSymptDelay / P.TimeStep)); //// time that person si/ci becomes case (symptomatic)... + int ci = c->infected[j]; //// person index + Person *si = Hosts + ci; //// person + + unsigned short int tc; //// time at which person becomes case (i.e. moves from infectious + /// and asymptomatic to infectious and symptomatic). + /* Following line not 100% consistent with DoIncub. All severity time points (e.g. SARI + * time) are added to latent_time, not latent_time + ((int)(P.LatentToSymptDelay / + * P.TimeStep))*/ + tc = si->latent_time + + ((int)(P.LatentToSymptDelay / + P.TimeStep)); //// time that person si/ci becomes case (symptomatic)... if ((P.DoSymptoms) && (ts == tc)) //// ... if now is that time... - DoCase(ci, t, ts, tn); //// ... change infectious (but asymptomatic) person to infectious and symptomatic. If doing severity, this contains DoMild and DoILI. + DoCase(ci, t, ts, + tn); //// ... change infectious (but asymptomatic) person to infectious and + /// symptomatic. If doing severity, this contains DoMild and DoILI. if (P.DoSeverity) { - if (ts >= si->SARI_time) DoSARI(ci, tn); //// see if you can dispense with inequalities by initializing SARI_time, Critical_time etc. to USHRT_MAX - if (ts >= si->Critical_time) DoCritical(ci, tn); - if (ts >= si->RecoveringFromCritical_time) DoRecoveringFromCritical(ci, tn); + if (ts >= si->SARI_time) + DoSARI(ci, tn); //// see if you can dispense with inequalities by initializing + /// SARI_time, Critical_time etc. to USHRT_MAX + if (ts >= si->Critical_time) + DoCritical(ci, tn); + if (ts >= si->RecoveringFromCritical_time) + DoRecoveringFromCritical(ci, tn); if (ts >= si->recovery_or_death_time) { if (si->to_die) @@ -1044,13 +1220,15 @@ void IncubRecoverySweep(double t, int run) } } - //Adding code to assign recovery or death when leaving the infectious class: ggilani - 22/10/14 + // Adding code to assign recovery or death when leaving the infectious class: ggilani - + // 22/10/14 if (ts >= si->recovery_or_death_time) { if (!si->to_die) //// if person si recovers and this timestep is after they've recovered { DoRecover(ci, tn, run); - //StateT[tn].inf_queue[0][StateT[tn].n_queue[0]++] = ci; //// add them to end of 0th thread of inf queue. Don't get why 0 here. + // StateT[tn].inf_queue[0][StateT[tn].n_queue[0]++] = ci; //// add them to end of 0th + // thread of inf queue. Don't get why 0 here. } else /// if they die and this timestep is after they've died. { @@ -1060,11 +1238,20 @@ void IncubRecoverySweep(double t, int run) DoDeath(ci, tn, run); } - //once host recovers, will no longer make contacts for contact tracing - if we are doing contact tracing and case was infectious when contact tracing was active, increment state vector - if ((P.DoDigitalContactTracing) && (Hosts[ci].latent_time>= AdUnits[Mcells[Hosts[ci].mcell].adunit].DigitalContactTracingTimeStart) && (Hosts[ci].recovery_or_death_time < AdUnits[Mcells[Hosts[ci].mcell].adunit].DigitalContactTracingTimeStart + P.DigitalContactTracingPolicyDuration) && (Hosts[ci].digitalContactTracingUser == 1) && (P.OutputDigitalContactDist)) + // once host recovers, will no longer make contacts for contact tracing - if we are doing + // contact tracing and case was infectious when contact tracing was active, increment + // state vector + if ((P.DoDigitalContactTracing) && + (Hosts[ci].latent_time >= + AdUnits[Mcells[Hosts[ci].mcell].adunit].DigitalContactTracingTimeStart) && + (Hosts[ci].recovery_or_death_time < + AdUnits[Mcells[Hosts[ci].mcell].adunit].DigitalContactTracingTimeStart + + P.DigitalContactTracingPolicyDuration) && + (Hosts[ci].digitalContactTracingUser == 1) && (P.OutputDigitalContactDist)) { - if (Hosts[ci].ncontacts > MAX_CONTACTS) Hosts[ci].ncontacts = MAX_CONTACTS; - //increment bin in State corresponding to this number of contacts + if (Hosts[ci].ncontacts > MAX_CONTACTS) + Hosts[ci].ncontacts = MAX_CONTACTS; + // increment bin in State corresponding to this number of contacts StateT[tn].contact_dist[Hosts[ci].ncontacts]++; } } @@ -1072,13 +1259,13 @@ void IncubRecoverySweep(double t, int run) } } - void DigitalContactTracingSweep(double t) { /** * Function: DigitalContactTracingSweep * - * Purpose: to update and count the number of people in each admin unit who are being digitally contact traced each day and remove those who no longer need to be traced + * Purpose: to update and count the number of people in each admin unit who are being digitally + * contact traced each day and remove those who no longer need to be traced * @param t is a double representing the actual simulation time (not the integer timestep) * @return void * @@ -1086,11 +1273,11 @@ void DigitalContactTracingSweep(double t) */ unsigned short int ts; - //find current time step - ts = (unsigned short int) (P.TimeStepsPerDay * t); + // find current time step + ts = (unsigned short int)(P.TimeStepsPerDay * t); - FILE* stderr_shared = stderr; -#pragma omp parallel for schedule(static,1) default(none) \ + FILE *stderr_shared = stderr; +#pragma omp parallel for schedule(static, 1) default(none) \ shared(t, P, AdUnits, StateT, Hosts, ts, stderr_shared) for (int tn = 0; tn < P.NumThreads; tn++) { @@ -1102,218 +1289,292 @@ void DigitalContactTracingSweep(double t) { for (int k = 0; k < StateT[j].ndct_queue[i];) { - //start by finding theoretical start and end isolation times for each contact; - //these are calculated here for each time step instead of InfectSweep when contact event is added as trigger times will be updated for asymptomatic cases detected by testing. + // start by finding theoretical start and end isolation times for each contact; + // these are calculated here for each time step instead of InfectSweep when contact + // event is added as trigger times will be updated for asymptomatic cases detected by + // testing. int infector = StateT[j].dct_queue[i][k].index; int contact = StateT[j].dct_queue[i][k].contact; unsigned short int contact_time = StateT[j].dct_queue[i][k].contact_time; unsigned short int dct_start_time, dct_end_time; - //this condition is only ever met when a symptomatic case is detected in DoDetectedCase and is not already an index case. If they have already - //been made an index case due to testing, then this won't occur again for them. - if (infector==-1) + // this condition is only ever met when a symptomatic case is detected in DoDetectedCase + // and is not already an index case. If they have already been made an index case due to + // testing, then this won't occur again for them. + if (infector == -1) { - //i.e. this is an index case that has been detected by becoming symptomatic and added to the digital contact tracing queue - dct_start_time = Hosts[contact].dct_trigger_time; //trigger time for these cases is set in DoIncub and already accounts for delay between onset and isolation - dct_end_time = dct_start_time + (unsigned short int)(P.LengthDigitalContactIsolation * P.TimeStepsPerDay); - + // i.e. this is an index case that has been detected by becoming symptomatic and added + // to the digital contact tracing queue + dct_start_time = + Hosts[contact] + .dct_trigger_time; // trigger time for these cases is set in DoIncub and + // already accounts for delay between onset and isolation + dct_end_time = dct_start_time + (unsigned short int)(P.LengthDigitalContactIsolation * + P.TimeStepsPerDay); } - else //We are looking at actual contact events between infectious hosts and their contacts. + else // We are looking at actual contact events between infectious hosts and their + // contacts. { - //trigger times are either set in DoDetectedCase or in the loop below (for asymptomatic and presymptomatic cases that are picked up via testing - //If the contact's index case has a trigger time that means that they have been detected, and we can calculate start and end isolation times for the contact. + // trigger times are either set in DoDetectedCase or in the loop below (for + // asymptomatic and presymptomatic cases that are picked up via testing If the + // contact's index case has a trigger time that means that they have been detected, + // and we can calculate start and end isolation times for the contact. if (Hosts[infector].dct_trigger_time < (USHRT_MAX - 1)) { if (contact_time > Hosts[infector].dct_trigger_time) { - //if the contact time was made after host detected, we should use the later time - dct_start_time = contact_time + (unsigned short int) (P.DigitalContactTracingDelay * P.TimeStepsPerDay); + // if the contact time was made after host detected, we should use the later time + dct_start_time = + contact_time + + (unsigned short int)(P.DigitalContactTracingDelay * P.TimeStepsPerDay); } else { - //if the contact time was made before or at the same time as detection, use the trigger time instead - dct_start_time = Hosts[infector].dct_trigger_time + (unsigned short int) (P.DigitalContactTracingDelay * P.TimeStepsPerDay); + // if the contact time was made before or at the same time as detection, use the + // trigger time instead + dct_start_time = + Hosts[infector].dct_trigger_time + + (unsigned short int)(P.DigitalContactTracingDelay * P.TimeStepsPerDay); } - dct_end_time = dct_start_time + (unsigned short int)(P.LengthDigitalContactIsolation * P.TimeStepsPerDay); + dct_end_time = + dct_start_time + + (unsigned short int)(P.LengthDigitalContactIsolation * P.TimeStepsPerDay); } else { - dct_start_time = USHRT_MAX - 1; //for contacts of asymptomatic or presymptomatic cases - they won't get added as their index case won't know that they are infected (unless explicitly tested) - //but we keep them in the queue in case their index case is detected as the contact of someone else and gets their trigger time set - //set dct_end_time to recovery time of infector, in order to remove from queue if their infector isn't detected before they recover. + dct_start_time = + USHRT_MAX - 1; // for contacts of asymptomatic or presymptomatic cases - they + // won't get added as their index case won't know that they are + // infected (unless explicitly tested) + // but we keep them in the queue in case their index case is detected as the contact + // of someone else and gets their trigger time set set dct_end_time to recovery time + // of infector, in order to remove from queue if their infector isn't detected + // before they recover. dct_end_time = Hosts[infector].recovery_or_death_time; } } - //if we've reached the start time for isolation + // if we've reached the start time for isolation if (dct_start_time == ts) { - //if the host has been detected due to being symptomatic, they are now an index case - set this variable now. For index cases detected by testing, this will be set on testing - if ((infector==-1) && (Hosts[contact].index_case_dct == 0)) //don't really need the second condition as the first should only be true when the second isn't (due to how this contact is logged in DoDetectedCase) + // if the host has been detected due to being symptomatic, they are now an index case + // - set this variable now. For index cases detected by testing, this will be set on + // testing + if ((infector == -1) && (Hosts[contact].index_case_dct == + 0)) // don't really need the second condition as the first + // should only be true when the second isn't (due to how + // this contact is logged in DoDetectedCase) { - Hosts[contact].index_case_dct = 1; //assign them as an index case + Hosts[contact].index_case_dct = 1; // assign them as an index case } - //if contact is not being traced at all + // if contact is not being traced at all if (Hosts[contact].digitalContactTraced == 0) { - //move into the contact tracing list for that admin unit, set start and end times, update flag and remove from queue - if (AdUnits[i].ndct < AdUnits[i].n) //AdUnits[i].n is length of queue + // move into the contact tracing list for that admin unit, set start and end times, + // update flag and remove from queue + if (AdUnits[i].ndct < AdUnits[i].n) // AdUnits[i].n is length of queue { Hosts[contact].dct_start_time = dct_start_time; Hosts[contact].dct_end_time = dct_end_time; Hosts[contact].digitalContactTraced = 1; - //At this point, we do testing on index cases who have been picked up on symptoms alone, in order to figure out whether and when - //to remove their contacts (if P.RemoveContactsOfNegativeIndexCase). It's much harder to do it in the next loop as we don't have all - //the information about the contact event there and would need to loop over all contacts again to look for their index case - //This would cause race conditions due to having a loop over adunits within threaded loop over admin units - //Only set test times if P.DoDCTTest. If P.DoDCTTest==0, but we are finding contacts of contacts, we check to see if contacts should become index cases every day they are in isolation. + // At this point, we do testing on index cases who have been picked up on symptoms + // alone, in order to figure out whether and when to remove their contacts (if + // P.RemoveContactsOfNegativeIndexCase). It's much harder to do it in the next + // loop as we don't have all the information about the contact event there and + // would need to loop over all contacts again to look for their index case This + // would cause race conditions due to having a loop over adunits within threaded + // loop over admin units Only set test times if P.DoDCTTest. If P.DoDCTTest==0, + // but we are finding contacts of contacts, we check to see if contacts should + // become index cases every day they are in isolation. if (P.DoDCTTest) { if (Hosts[contact].index_case_dct == 1) { - //set testing time (which has a different delay to contact testing delay), but no need to set index_case link - Hosts[contact].dct_test_time = dct_start_time + (unsigned short int)(P.DelayToTestIndexCase * P.TimeStepsPerDay); - //if host is infectious at test time - if ((Hosts[contact].dct_test_time >= Hosts[contact].latent_time) && (Hosts[contact].dct_test_time < Hosts[contact].recovery_or_death_time)) + // set testing time (which has a different delay to contact testing delay), + // but no need to set index_case link + Hosts[contact].dct_test_time = + dct_start_time + + (unsigned short int)(P.DelayToTestIndexCase * P.TimeStepsPerDay); + // if host is infectious at test time + if ((Hosts[contact].dct_test_time >= Hosts[contact].latent_time) && + (Hosts[contact].dct_test_time < Hosts[contact].recovery_or_death_time)) { - //if false negative, remove from queue by setting the end time to the test time - if ((P.SensitivityDCT == 0) || ((P.SensitivityDCT < 1) && (ranf_mt(tn) >= P.SensitivityDCT))) + // if false negative, remove from queue by setting the end time to the test + // time + if ((P.SensitivityDCT == 0) || + ((P.SensitivityDCT < 1) && (ranf_mt(tn) >= P.SensitivityDCT))) { Hosts[contact].dct_end_time = Hosts[contact].dct_test_time; - //set index_dct_flag to 2 to indicate that contacts should be removed, if we are removing based on negative test result of index case - if (P.RemoveContactsOfNegativeIndexCase) Hosts[contact].index_case_dct = 2; + // set index_dct_flag to 2 to indicate that contacts should be removed, if + // we are removing based on negative test result of index case + if (P.RemoveContactsOfNegativeIndexCase) + Hosts[contact].index_case_dct = 2; } } - //if host is non-infectious) + // if host is non-infectious) else { - //if true negative, remove from list - if ((P.SpecificityDCT == 1) || ((P.SpecificityDCT > 0) && (ranf_mt(tn) < P.SpecificityDCT))) + // if true negative, remove from list + if ((P.SpecificityDCT == 1) || + ((P.SpecificityDCT > 0) && (ranf_mt(tn) < P.SpecificityDCT))) { - //again mark them to be removed from list at test time rather than end_time, and change index_case_dct flag + // again mark them to be removed from list at test time rather than + // end_time, and change index_case_dct flag Hosts[contact].dct_end_time = Hosts[contact].dct_test_time; - if (P.RemoveContactsOfNegativeIndexCase) Hosts[contact].index_case_dct = 2; + if (P.RemoveContactsOfNegativeIndexCase) + Hosts[contact].index_case_dct = 2; } } } else if (Hosts[contact].index_case_dct == 0) { - //if their infector is set to be removed from the list at test time, and their contacts will also be removed at this stage - if ((Hosts[infector].index_case_dct == 2) && (P.RemoveContactsOfNegativeIndexCase)) + // if their infector is set to be removed from the list at test time, and + // their contacts will also be removed at this stage + if ((Hosts[infector].index_case_dct == 2) && + (P.RemoveContactsOfNegativeIndexCase)) { - //set end time to match end time of infector + // set end time to match end time of infector Hosts[contact].dct_end_time = Hosts[infector].dct_end_time; } else { - //set testing time - Hosts[contact].dct_test_time = dct_start_time + (unsigned short int)(P.DelayToTestDCTContacts * P.TimeStepsPerDay); + // set testing time + Hosts[contact].dct_test_time = + dct_start_time + + (unsigned short int)(P.DelayToTestDCTContacts * P.TimeStepsPerDay); } } } - //actually put them in the queue + // actually put them in the queue AdUnits[i].dct[AdUnits[i].ndct] = contact; - //update number of people in queue + // update number of people in queue AdUnits[i].ndct++; - //increment state variables + // increment state variables StateT[tn].cumDCT_adunit[i]++; StateT[tn].cumDCT++; - //now remove this case from the queues + // now remove this case from the queues StateT[j].dct_queue[i][k] = StateT[j].dct_queue[i][StateT[j].ndct_queue[i] - 1]; - StateT[j].dct_queue[i][StateT[j].ndct_queue[i] - 1] = { contact,infector,contact_time }; + StateT[j].dct_queue[i][StateT[j].ndct_queue[i] - 1] = {contact, infector, + contact_time}; StateT[j].ndct_queue[i]--; } else { - fprintf(stderr_shared, "No more space in queue! AdUnit: %i, ndct=%i, max queue length: %i\n", i, AdUnits[i].ndct, AdUnits[i].n); + fprintf(stderr_shared, + "No more space in queue! AdUnit: %i, ndct=%i, max queue length: %i\n", i, + AdUnits[i].ndct, AdUnits[i].n); fprintf(stderr_shared, "Error!\n"); k++; } } - //else if contact is already being contact traced + // else if contact is already being contact traced else if (Hosts[contact].digitalContactTraced == 1) { if (P.DoDCTTest) { - //if case has been detected due to being symptomatic, then we will update their testing time if they would be tested earlier based on being an index case as opposed to being a contact of another case - //If they are already being contact traced and testing is on, they should have been set a test_time - if ((Hosts[contact].index_case_dct == 1) && (Hosts[contact].dct_test_time > (dct_start_time + (unsigned short int)(P.DelayToTestIndexCase * P.TimeStepsPerDay)))) + // if case has been detected due to being symptomatic, then we will update their + // testing time if they would be tested earlier based on being an index case as + // opposed to being a contact of another case If they are already being contact + // traced and testing is on, they should have been set a test_time + if ((Hosts[contact].index_case_dct == 1) && + (Hosts[contact].dct_test_time > + (dct_start_time + + (unsigned short int)(P.DelayToTestIndexCase * P.TimeStepsPerDay)))) { - Hosts[contact].dct_test_time = dct_start_time + (unsigned short int)(P.DelayToTestIndexCase * P.TimeStepsPerDay); - //update end time (which is always at least equal to, but may be later that the current one) + Hosts[contact].dct_test_time = + dct_start_time + + (unsigned short int)(P.DelayToTestIndexCase * P.TimeStepsPerDay); + // update end time (which is always at least equal to, but may be later that the + // current one) Hosts[contact].dct_end_time = dct_end_time; - //check to see if test will be negative, if so, tag them for early removal and update index_dct_flag - if ((Hosts[contact].dct_test_time >= Hosts[contact].latent_time) && (Hosts[contact].dct_test_time < Hosts[contact].recovery_or_death_time)) + // check to see if test will be negative, if so, tag them for early removal and + // update index_dct_flag + if ((Hosts[contact].dct_test_time >= Hosts[contact].latent_time) && + (Hosts[contact].dct_test_time < Hosts[contact].recovery_or_death_time)) { - //if false negative, remove from - if ((P.SensitivityDCT == 0) || ((P.SensitivityDCT < 1) && (ranf_mt(tn) >= P.SensitivityDCT))) + // if false negative, remove from + if ((P.SensitivityDCT == 0) || + ((P.SensitivityDCT < 1) && (ranf_mt(tn) >= P.SensitivityDCT))) { Hosts[contact].dct_end_time = Hosts[contact].dct_test_time; - //set index_dct_flag to 2 to indicate that contacts should be removed - if (P.RemoveContactsOfNegativeIndexCase) Hosts[contact].index_case_dct = 2; + // set index_dct_flag to 2 to indicate that contacts should be removed + if (P.RemoveContactsOfNegativeIndexCase) + Hosts[contact].index_case_dct = 2; } } - //if host is non-infectious + // if host is non-infectious else { - //if true negative, remove from list - if ((P.SpecificityDCT == 1) || ((P.SpecificityDCT > 0) && (ranf_mt(tn) < P.SpecificityDCT))) + // if true negative, remove from list + if ((P.SpecificityDCT == 1) || + ((P.SpecificityDCT > 0) && (ranf_mt(tn) < P.SpecificityDCT))) { - //again mark them to be removed from list at test time rather than end_time, and change index_case_dct flag + // again mark them to be removed from list at test time rather than + // end_time, and change index_case_dct flag Hosts[contact].dct_end_time = Hosts[contact].dct_test_time; - if (P.RemoveContactsOfNegativeIndexCase) Hosts[contact].index_case_dct = 2; + if (P.RemoveContactsOfNegativeIndexCase) + Hosts[contact].index_case_dct = 2; } } } else { - //we don't want to remove this contact if they are also linked to another case - their testing time shouldn't change. - //but we'll only extend their end time if they wouldn't potentially be removed by having a negative contact - if ((!P.RemoveContactsOfNegativeIndexCase) || ((P.RemoveContactsOfNegativeIndexCase) && (Hosts[infector].index_case_dct == 1))) + // we don't want to remove this contact if they are also linked to another case + // - their testing time shouldn't change. but we'll only extend their end time + // if they wouldn't potentially be removed by having a negative contact + if ((!P.RemoveContactsOfNegativeIndexCase) || + ((P.RemoveContactsOfNegativeIndexCase) && + (Hosts[infector].index_case_dct == 1))) { - //extend end time + // extend end time Hosts[contact].dct_end_time = dct_end_time; } - //otherwise if contact would have been removed if they didn't have another contact, we keep their original end time + // otherwise if contact would have been removed if they didn't have another + // contact, we keep their original end time } - } else { - //just extend the isolation end time, but we're not going to update testing time or as we still want the testing time to be dependent on the earlier contact. - Hosts[contact].dct_end_time = dct_end_time; //we could choose to not extend the time for cases who are index cases. If they are tested and are negative, they'd be removed earlier anyway. If positive, they will stay isolated for a bit longer - + // just extend the isolation end time, but we're not going to update testing time + // or as we still want the testing time to be dependent on the earlier contact. + Hosts[contact].dct_end_time = + dct_end_time; // we could choose to not extend the time for cases who are + // index cases. If they are tested and are negative, they'd be + // removed earlier anyway. If positive, they will stay isolated + // for a bit longer } - //now remove this case from the queue + // now remove this case from the queue StateT[j].dct_queue[i][k] = StateT[j].dct_queue[i][StateT[j].ndct_queue[i] - 1]; - StateT[j].dct_queue[i][StateT[j].ndct_queue[i] - 1] = { contact,infector,contact_time }; + StateT[j].dct_queue[i][StateT[j].ndct_queue[i] - 1] = {contact, infector, + contact_time}; StateT[j].ndct_queue[i]--; } } - //if contact of an asymptomatic host has passed the recovery time of their asymptomatic index, they would no longer be identified by testing of their index case - remove from the queue so they don't stay here forever + // if contact of an asymptomatic host has passed the recovery time of their asymptomatic + // index, they would no longer be identified by testing of their index case - remove + // from the queue so they don't stay here forever else if ((dct_start_time == (USHRT_MAX - 1)) && (dct_end_time == ts)) { - //now remove this case from the queue + // now remove this case from the queue StateT[j].dct_queue[i][k] = StateT[j].dct_queue[i][StateT[j].ndct_queue[i] - 1]; - StateT[j].dct_queue[i][StateT[j].ndct_queue[i] - 1] = { contact,infector,contact_time }; + StateT[j].dct_queue[i][StateT[j].ndct_queue[i] - 1] = {contact, infector, + contact_time}; StateT[j].ndct_queue[i]--; } else { k++; } - } } } } } -#pragma omp parallel for schedule(static,1) default(none) \ - shared(t, P, AdUnits, Hosts, ts) +#pragma omp parallel for schedule(static, 1) default(none) shared(t, P, AdUnits, Hosts, ts) for (int tn = 0; tn < P.NumThreads; tn++) { for (int i = tn; i < P.NumAdunits; i += P.NumThreads) @@ -1324,79 +1585,96 @@ void DigitalContactTracingSweep(double t) { int contact = AdUnits[i].dct[j]; - //first do testing of index cases and their contacts + // first do testing of index cases and their contacts if (P.DoDCTTest) { if ((Hosts[contact].dct_test_time == ts) && (Hosts[contact].index_case_dct == 0)) { - //if host is positive - if ((abs(Hosts[contact].inf) == 2) || (Hosts[contact].inf == -1)) //either asymptomatic infectious, symptomatic infectious or presymptomatic infectious + // if host is positive + if ((abs(Hosts[contact].inf) == 2) || + (Hosts[contact].inf == -1)) // either asymptomatic infectious, symptomatic + // infectious or presymptomatic infectious { - //if the test is a false negative - if ((P.SensitivityDCT == 0) || ((P.SensitivityDCT < 1) && (ranf_mt(tn) >= P.SensitivityDCT))) + // if the test is a false negative + if ((P.SensitivityDCT == 0) || + ((P.SensitivityDCT < 1) && (ranf_mt(tn) >= P.SensitivityDCT))) { Hosts[contact].dct_end_time = ts; } - //else if a true positive + // else if a true positive else if (P.FindContactsOfDCTContacts) { - //set them to be an index case + // set them to be an index case Hosts[contact].index_case_dct = 1; - //set trigger time to pick up their contacts in the next time step - Hosts[contact].dct_trigger_time = ts + 1; //added the +1 here so that if there are no delays, the contacts will still get picked up correctly - //if they are asymptomatic, i.e. specifically if they have inf flag 2, call DoDetectedCase in order to trigger HQ and PC too. + // set trigger time to pick up their contacts in the next time step + Hosts[contact].dct_trigger_time = + ts + 1; // added the +1 here so that if there are no delays, the contacts will + // still get picked up correctly + // if they are asymptomatic, i.e. specifically if they have inf flag 2, call + // DoDetectedCase in order to trigger HQ and PC too. if (Hosts[contact].inf == 2) { DoDetectedCase(contact, t, ts, tn); - Hosts[contact].detected = 1; Hosts[contact].detected_time = ts; + Hosts[contact].detected = 1; + Hosts[contact].detected_time = ts; } } } - //or if host is negative + // or if host is negative else { - //and is a true negative - if ((P.SpecificityDCT == 1) || ((P.SpecificityDCT > 0) && (ranf_mt(tn) < P.SpecificityDCT))) + // and is a true negative + if ((P.SpecificityDCT == 1) || + ((P.SpecificityDCT > 0) && (ranf_mt(tn) < P.SpecificityDCT))) { Hosts[contact].dct_end_time = ts; } - //can't track contacts of false positives as they don't make any contacts in InfectSweep + // can't track contacts of false positives as they don't make any contacts in + // InfectSweep } } } else if (P.FindContactsOfDCTContacts) { - //check every day to see if contacts become index cases - but they have to be infectious. Otherwise we could set the trigger time and cause their contacts to be traced when they are not being traced themselves. - if ((Hosts[contact].index_case_dct == 0) && ((abs(Hosts[contact].inf) == 2) || (Hosts[contact].inf == -1))) - //if ((Hosts[contact].dct_test_time == ts) && (Hosts[contact].index_case_dct == 0) && ((abs(Hosts[contact].inf) == 2) || (Hosts[contact].inf == -1))) + // check every day to see if contacts become index cases - but they have to be + // infectious. Otherwise we could set the trigger time and cause their contacts to be + // traced when they are not being traced themselves. + if ((Hosts[contact].index_case_dct == 0) && + ((abs(Hosts[contact].inf) == 2) || (Hosts[contact].inf == -1))) + // if ((Hosts[contact].dct_test_time == ts) && (Hosts[contact].index_case_dct == 0) && + // ((abs(Hosts[contact].inf) == 2) || (Hosts[contact].inf == -1))) { - //set them to be an index case + // set them to be an index case Hosts[contact].index_case_dct = 1; - //set trigger time to pick up their contacts in the next time step - Hosts[contact].dct_trigger_time = ts + 1; //added the +1 here so that if there are no delays, the contacts will still get picked up correctly - //if they are asymptomatic, i.e. specifically if they have inf flag 2, call DoDetectedCase in order to trigger HQ and PC too. + // set trigger time to pick up their contacts in the next time step + Hosts[contact].dct_trigger_time = + ts + 1; // added the +1 here so that if there are no delays, the contacts will + // still get picked up correctly + // if they are asymptomatic, i.e. specifically if they have inf flag 2, call + // DoDetectedCase in order to trigger HQ and PC too. if (Hosts[contact].inf == 2) { DoDetectedCase(contact, t, ts, tn); - Hosts[contact].detected = 1; Hosts[contact].detected_time = ts; + Hosts[contact].detected = 1; + Hosts[contact].detected_time = ts; } } } - //now remove hosts who have reached the end of their isolation time + // now remove hosts who have reached the end of their isolation time if (Hosts[contact].dct_end_time == ts) { - //stop contact tracing this host + // stop contact tracing this host Hosts[contact].digitalContactTraced = 0; - //remove index_case_dct flag to 0; + // remove index_case_dct flag to 0; if (Hosts[contact].index_case_dct) { Hosts[contact].index_case_dct = 0; - //Hosts[contact].dct_trigger_time = USHRT_MAX - 1; + // Hosts[contact].dct_trigger_time = USHRT_MAX - 1; } - //remove from list - //k = contact; + // remove from list + // k = contact; AdUnits[i].dct[j] = AdUnits[i].dct[AdUnits[i].ndct - 1]; AdUnits[i].dct[AdUnits[i].ndct - 1] = contact; AdUnits[i].ndct--; @@ -1413,30 +1691,32 @@ void DigitalContactTracingSweep(double t) int TreatSweep(double t) { - ///// function loops over microcells to decide which cells are treated (either with treatment, vaccine, social distancing, movement restrictions etc.) + ///// function loops over microcells to decide which cells are treated (either with treatment, + /// vaccine, social distancing, movement restrictions etc.) int f, f1, f2, f3, f4; //// various fail conditions. Used for other things int nckwp; //// time steps - unsigned short int ts; //// time-step now. - unsigned short int tstf; //// time-step treatment finish - unsigned short int tstb; //// time-step treatment begin - unsigned short int tsvb; //// time-step vaccination begin - unsigned short int tspf; //// time-step place closure finish - unsigned short int tsmb; //// time-step movement restriction begin - unsigned short int tsmf; //// time-step movement restriction finish - unsigned short int tssdf; //// time-step social distancing finish - unsigned short int tskwpf; //// time-step key worker place closure finish + unsigned short int ts; //// time-step now. + unsigned short int tstf; //// time-step treatment finish + unsigned short int tstb; //// time-step treatment begin + unsigned short int tsvb; //// time-step vaccination begin + unsigned short int tspf; //// time-step place closure finish + unsigned short int tsmb; //// time-step movement restriction begin + unsigned short int tsmf; //// time-step movement restriction finish + unsigned short int tssdf; //// time-step social distancing finish + unsigned short int tskwpf; //// time-step key worker place closure finish int global_trig; double r; - ts = (unsigned short int) (P.TimeStepsPerDay * t); + ts = (unsigned short int)(P.TimeStepsPerDay * t); f = f1 = 0; if (P.DoGlobalTriggers) { if (P.DoPerCapitaTriggers) - global_trig = (int)floor(((double)State.trigDetectedCases) * P.GlobalIncThreshPop / ((double)P.PopSize)); + global_trig = (int)floor(((double)State.trigDetectedCases) * P.GlobalIncThreshPop / + ((double)P.PopSize)); else global_trig = State.trigDetectedCases; } @@ -1444,9 +1724,11 @@ int TreatSweep(double t) global_trig = 0; ///// block loops over places and determines whom to prophylactically treat - if ((P.DoPlaces) && (t >= P.TreatTimeStart) && (t < P.TreatTimeStart + P.TreatPlaceGeogDuration) && (State.cumT < P.TreatMaxCourses)) + if ((P.DoPlaces) && (t >= P.TreatTimeStart) && + (t < P.TreatTimeStart + P.TreatPlaceGeogDuration) && (State.cumT < P.TreatMaxCourses)) { - tstf = (unsigned short int) (P.TimeStepsPerDay * (t + P.TreatDelayMean + P.TreatProphCourseLength)); + tstf = + (unsigned short int)(P.TimeStepsPerDay * (t + P.TreatDelayMean + P.TreatProphCourseLength)); #pragma omp parallel for private(f) reduction(+:f1) schedule(static,1) default(none) \ shared(P, StateT, Places, Hosts, ts, tstf) @@ -1459,19 +1741,18 @@ int TreatSweep(double t) if (P.DoPlaceGroupTreat) { f = StateT[i].pg_queue[j][k]; - for (int m = ((int)Places[j][l].group_start[f]); m < ((int)(Places[j][l].group_start[f] + Places[j][l].group_size[f])); m++) + for (int m = ((int)Places[j][l].group_start[f]); + m < ((int)(Places[j][l].group_start[f] + Places[j][l].group_size[f])); m++) { /* if((Places[j][l].members[m]<0)||(Places[j][l].members[m]>P.PopSize-1)) - fprintf(stderr,"\n*** npq=%i gn=%i h=%i m=%i j=%i l=%i f=%i s=%i n=%i ***\n", - StateT[i].np_queue[j], - Places[j][l].n, - Places[j][l].members[m], - m,j,l,f, + fprintf(stderr,"\n*** npq=%i gn=%i h=%i m=%i j=%i l=%i f=%i s=%i n=%i + ***\n", StateT[i].np_queue[j], Places[j][l].n, Places[j][l].members[m], m,j,l,f, (int) Places[j][l].group_start[f], (int) Places[j][l].group_size[f]); else */ - if ((!HOST_TO_BE_TREATED(Places[j][l].members[m])) && ((P.TreatPlaceTotalProp[j] == 1) || (ranf_mt(i) < P.TreatPlaceTotalProp[j]))) + if ((!HOST_TO_BE_TREATED(Places[j][l].members[m])) && + ((P.TreatPlaceTotalProp[j] == 1) || (ranf_mt(i) < P.TreatPlaceTotalProp[j]))) DoProph(Places[j][l].members[m], ts, i); } } @@ -1495,28 +1776,32 @@ int TreatSweep(double t) } } - ///// block vaccinates everyone in mass vaccination queue. Don't know why loop is done twice (although State.mvacc_cum is reset at end so will relate to that) + ///// block vaccinates everyone in mass vaccination queue. Don't know why loop is done twice + ///(although State.mvacc_cum is reset at end so will relate to that) if ((P.DoMassVacc) && (t >= P.VaccTimeStart)) for (int j = 0; j < 2; j++) { int m = (int)P.VaccMaxCourses; - if (m > State.n_mvacc) m = State.n_mvacc; -#pragma omp parallel for schedule(static,1000) default(none) \ - shared(State, m, ts) + if (m > State.n_mvacc) + m = State.n_mvacc; +#pragma omp parallel for schedule(static, 1000) default(none) shared(State, m, ts) for (int i = State.mvacc_cum; i < m; i++) DoVacc(State.mvacc_queue[i], ts); State.mvacc_cum = m; } - if ((t >= P.TreatTimeStart) || (t >= P.VaccTimeStartGeo) || (t >= P.PlaceCloseTimeStart) || (t >= P.MoveRestrTimeStart) || (t >= P.SocDistTimeStart) || (t >= P.KeyWorkerProphTimeStart)) //changed this to start time geo + if ((t >= P.TreatTimeStart) || (t >= P.VaccTimeStartGeo) || (t >= P.PlaceCloseTimeStart) || + (t >= P.MoveRestrTimeStart) || (t >= P.SocDistTimeStart) || + (t >= P.KeyWorkerProphTimeStart)) // changed this to start time geo { - tstf = (unsigned short int) (P.TimeStepsPerDay * (t + P.TreatProphCourseLength) - 1); - tstb = (unsigned short int) (P.TimeStepsPerDay * (t + P.TreatDelayMean)); - tsvb = (unsigned short int) (P.TimeStepsPerDay * (t + P.VaccDelayMean)); - tspf = (unsigned short int) ceil(P.TimeStepsPerDay * (t + P.PlaceCloseDelayMean + P.PlaceCloseDuration)); - tsmf = (unsigned short int) ceil(P.TimeStepsPerDay * (t + P.MoveRestrDuration)); - tsmb = (unsigned short int) floor(P.TimeStepsPerDay * (t + P.MoveDelayMean)); - tssdf = (unsigned short int) ceil(P.TimeStepsPerDay * (t + P.SocDistDurationCurrent)); - tskwpf = (unsigned short int) ceil(P.TimeStepsPerDay * (t + P.KeyWorkerProphRenewalDuration)); + tstf = (unsigned short int)(P.TimeStepsPerDay * (t + P.TreatProphCourseLength) - 1); + tstb = (unsigned short int)(P.TimeStepsPerDay * (t + P.TreatDelayMean)); + tsvb = (unsigned short int)(P.TimeStepsPerDay * (t + P.VaccDelayMean)); + tspf = (unsigned short int)ceil(P.TimeStepsPerDay * + (t + P.PlaceCloseDelayMean + P.PlaceCloseDuration)); + tsmf = (unsigned short int)ceil(P.TimeStepsPerDay * (t + P.MoveRestrDuration)); + tsmb = (unsigned short int)floor(P.TimeStepsPerDay * (t + P.MoveDelayMean)); + tssdf = (unsigned short int)ceil(P.TimeStepsPerDay * (t + P.SocDistDurationCurrent)); + tskwpf = (unsigned short int)ceil(P.TimeStepsPerDay * (t + P.KeyWorkerProphRenewalDuration)); nckwp = (int)ceil(P.KeyWorkerProphDuration / P.TreatProphCourseLength); #pragma omp parallel for private(f2,f3,f4,r) reduction(+:f) schedule(static,1) default(none) \ @@ -1528,460 +1813,390 @@ int TreatSweep(double t) int adi = (P.DoAdUnits) ? Mcells[b].adunit : -1; int ad = (P.DoAdUnits) ? AdUnits[adi].id : 0; - //// Code block goes through various types of treatments/interventions (vaccination/movement restrictions etc.), - //// assesses whether various triggers (counts) are over a certain threshold, (specified in ReadParams) - //// and then implements those treatments by setting various flags (i.e. .treat/ .vacc etc.) by microcell. - //// Further, this block assigns all microcells that are within this admin unit (and around this microcell) to be treated, using the flags set to avoid duplication. - - + //// Code block goes through various types of treatments/interventions (vaccination/movement + /// restrictions etc.), / assesses whether various triggers (counts) are over a certain + /// threshold, (specified in ReadParams) / and then implements those treatments by setting + /// various flags (i.e. .treat/ .vacc etc.) by microcell. / Further, this block assigns all + /// microcells that are within this admin unit (and around this microcell) to be treated, + /// using the flags set to avoid duplication. - //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** - //// **** //// **** //// **** //// **** TREATMENT - //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** + //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** + /////// **** //// **** //// **** / **** //// **** //// **** //// **** TREATMENT / **** //// + ///**** //// **** //// **** //// **** //// **** //// **** //// **** - if ((Mcells[b].treat == 2) && (ts >= Mcells[b].treat_end_time)) - { - f = 1; - Mcells[b].treat = 0; - } - if ((Mcells[b].treat == 1) && (ts >= Mcells[b].treat_start_time)) - { - f = 1; - Mcells[b].treat = 2; - Mcells[b].treat_trig = 0; - Mcells[b].treat_end_time = tstf; - for (int i = 0; i < Mcells[b].n; i++) - { - int l = Mcells[b].members[i]; - if ((!HOST_TO_BE_TREATED(l)) && ((P.TreatPropRadial == 1) || (ranf_mt(tn) < P.TreatPropRadial))) - DoProphNoDelay(l, ts, tn, 1); - } - } - if (P.DoGlobalTriggers) - f2 = (global_trig >= P.TreatCellIncThresh); - else if (P.DoAdminTriggers) - { - int trig_thresh = (P.DoPerCapitaTriggers) ? ((int)ceil(((double)(AdUnits[adi].n * P.TreatCellIncThresh)) / P.IncThreshPop)) : (int)P.TreatCellIncThresh; - f2 = (State.trigDC_adunit[adi] > trig_thresh); - } - else + if ((Mcells[b].treat == 2) && (ts >= Mcells[b].treat_end_time)) + { + f = 1; + Mcells[b].treat = 0; + } + if ((Mcells[b].treat == 1) && (ts >= Mcells[b].treat_start_time)) + { + f = 1; + Mcells[b].treat = 2; + Mcells[b].treat_trig = 0; + Mcells[b].treat_end_time = tstf; + for (int i = 0; i < Mcells[b].n; i++) { - int trig_thresh = (P.DoPerCapitaTriggers) ? ((int)ceil(((double)(Mcells[b].n * P.TreatCellIncThresh)) / P.IncThreshPop)) : (int)P.TreatCellIncThresh; - f2 = (Mcells[b].treat_trig >= trig_thresh); + int l = Mcells[b].members[i]; + if ((!HOST_TO_BE_TREATED(l)) && + ((P.TreatPropRadial == 1) || (ranf_mt(tn) < P.TreatPropRadial))) + DoProphNoDelay(l, ts, tn, 1); } - if ((t >= P.TreatTimeStart) && (Mcells[b].treat == 0) && (f2) && (P.TreatRadius2 > 0)) + } + if (P.DoGlobalTriggers) + f2 = (global_trig >= P.TreatCellIncThresh); + else if (P.DoAdminTriggers) + { + int trig_thresh = + (P.DoPerCapitaTriggers) + ? ((int)ceil(((double)(AdUnits[adi].n * P.TreatCellIncThresh)) / P.IncThreshPop)) + : (int)P.TreatCellIncThresh; + f2 = (State.trigDC_adunit[adi] > trig_thresh); + } + else + { + int trig_thresh = + (P.DoPerCapitaTriggers) + ? ((int)ceil(((double)(Mcells[b].n * P.TreatCellIncThresh)) / P.IncThreshPop)) + : (int)P.TreatCellIncThresh; + f2 = (Mcells[b].treat_trig >= trig_thresh); + } + if ((t >= P.TreatTimeStart) && (Mcells[b].treat == 0) && (f2) && (P.TreatRadius2 > 0)) + { + MicroCellPosition min = P.get_micro_cell_position_from_cell_index(b); + Direction j = Right; + int k = b; + int maxx = 0; + int i, m, l; + i = m = f2 = 0; + l = f3 = 1; + if ((!P.TreatByAdminUnit) || (ad > 0)) { - MicroCellPosition min = P.get_micro_cell_position_from_cell_index(b); - Direction j = Right; - int k = b; - int maxx = 0; - int i, m, l; - i = m = f2 = 0; - l = f3 = 1; - if ((!P.TreatByAdminUnit) || (ad > 0)) + int ad2 = ad / P.TreatAdminUnitDivisor; + do { - int ad2 = ad / P.TreatAdminUnitDivisor; - do + if (P.is_in_bounds(min)) { - if (P.is_in_bounds(min)) + if (P.TreatByAdminUnit) + f4 = (AdUnits[Mcells[k].adunit].id / P.TreatAdminUnitDivisor == ad2); + else + f4 = ((r = dist2_mm(Mcells + b, Mcells + k)) < P.TreatRadius2); + if (f4) { - if (P.TreatByAdminUnit) - f4 = (AdUnits[Mcells[k].adunit].id / P.TreatAdminUnitDivisor == ad2); - else - f4 = ((r = dist2_mm(Mcells + b, Mcells + k)) < P.TreatRadius2); - if (f4) + f = f2 = 1; + if ((Mcells[k].n > 0) && (Mcells[k].treat == 0)) { - f = f2 = 1; - if ((Mcells[k].n > 0) && (Mcells[k].treat == 0)) - { - Mcells[k].treat_start_time = tstb; - Mcells[k].treat = 1; - maxx += Mcells[k].n; - } + Mcells[k].treat_start_time = tstb; + Mcells[k].treat = 1; + maxx += Mcells[k].n; } } - min += j; - m = (m + 1) % l; - if (m == 0) + } + min += j; + m = (m + 1) % l; + if (m == 0) + { + j = rotate_left(j); + i = (i + 1) % 2; + if (i == 0) + l++; + if (j == Up) { - j = rotate_left(j); - i = (i + 1) % 2; - if (i == 0) l++; - if (j == Up) - { - f3 = f2; - f2 = 0; - } + f3 = f2; + f2 = 0; } - k = P.get_micro_cell_index_from_position(min); - } while ((f3) && (maxx < P.TreatMaxCoursesPerCase)); - } + } + k = P.get_micro_cell_index_from_position(min); + } while ((f3) && (maxx < P.TreatMaxCoursesPerCase)); } + } + //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** + /////// **** //// **** //// **** / **** //// **** //// **** //// **** VACCINATION / **** + /////// **** //// **** //// **** //// **** //// **** //// **** //// **** - //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** - //// **** //// **** //// **** //// **** VACCINATION - //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** - - - //// vaccinates proportion VaccProp of people in microcell (or at least adds them to geovacc_queue). - if ((Mcells[b].vacc == 1) && (ts >= Mcells[b].vacc_start_time)) + //// vaccinates proportion VaccProp of people in microcell (or at least adds them to + /// geovacc_queue). + if ((Mcells[b].vacc == 1) && (ts >= Mcells[b].vacc_start_time)) + { + f = 1; + Mcells[b].vacc_trig = 0; + // if(State.cumVG+P.NumThreads*Mcells[b].n= P.VaccCellIncThresh); - else if (P.DoAdminTriggers) - { - int trig_thresh = (P.DoPerCapitaTriggers) ? ((int)ceil(((double)(AdUnits[adi].n * P.VaccCellIncThresh)) / P.IncThreshPop)) : (int)P.VaccCellIncThresh; - f2 = (State.trigDC_adunit[adi] > trig_thresh); - } - else - { - int trig_thresh = (P.DoPerCapitaTriggers) ? ((int)ceil(((double)(Mcells[b].n * P.VaccCellIncThresh)) / P.IncThreshPop)) : (int)P.VaccCellIncThresh; - f2 = (Mcells[b].treat_trig >= trig_thresh); - } - if ((!P.DoMassVacc) && (P.VaccRadius2 > 0) && (t >= P.VaccTimeStartGeo) && (Mcells[b].vacc == 0) && (f2)) //changed from VaccTimeStart to VaccTimeStarGeo + } + if (P.DoGlobalTriggers) + f2 = (global_trig >= P.VaccCellIncThresh); + else if (P.DoAdminTriggers) + { + int trig_thresh = + (P.DoPerCapitaTriggers) + ? ((int)ceil(((double)(AdUnits[adi].n * P.VaccCellIncThresh)) / P.IncThreshPop)) + : (int)P.VaccCellIncThresh; + f2 = (State.trigDC_adunit[adi] > trig_thresh); + } + else + { + int trig_thresh = + (P.DoPerCapitaTriggers) + ? ((int)ceil(((double)(Mcells[b].n * P.VaccCellIncThresh)) / P.IncThreshPop)) + : (int)P.VaccCellIncThresh; + f2 = (Mcells[b].treat_trig >= trig_thresh); + } + if ((!P.DoMassVacc) && (P.VaccRadius2 > 0) && (t >= P.VaccTimeStartGeo) && + (Mcells[b].vacc == 0) && (f2)) // changed from VaccTimeStart to VaccTimeStarGeo + { + MicroCellPosition min = P.get_micro_cell_position_from_cell_index(b); + Direction j = Right; + int k = b; + int i, l, m; + i = m = f2 = 0; + l = f3 = 1; + if ((!P.VaccByAdminUnit) || (ad > 0)) { - MicroCellPosition min = P.get_micro_cell_position_from_cell_index(b); - Direction j = Right; - int k = b; - int i, l, m; - i = m = f2 = 0; - l = f3 = 1; - if ((!P.VaccByAdminUnit) || (ad > 0)) + int ad2 = ad / P.VaccAdminUnitDivisor; + do { - int ad2 = ad / P.VaccAdminUnitDivisor; - do + if (P.is_in_bounds(min)) { - if (P.is_in_bounds(min)) + if (P.VaccByAdminUnit) { - if (P.VaccByAdminUnit) - { - f4 = (AdUnits[Mcells[k].adunit].id / P.VaccAdminUnitDivisor == ad2); - r = 1e20; - } - else - f4 = ((r = dist2_mm(Mcells + b, Mcells + k)) < P.VaccRadius2); - if (f4) - { - f = f2 = 1; - if (r < P.VaccMinRadius2) - Mcells[k].vacc = 3; - else if ((Mcells[k].n > 0) && (Mcells[k].vacc == 0)) - { - Mcells[k].vacc_start_time = tsvb; - Mcells[k].vacc = 1; - } - } + f4 = (AdUnits[Mcells[k].adunit].id / P.VaccAdminUnitDivisor == ad2); + r = 1e20; } - min += j; - m = (m + 1) % l; - if (m == 0) + else + f4 = ((r = dist2_mm(Mcells + b, Mcells + k)) < P.VaccRadius2); + if (f4) { - j = rotate_left(j); - i = (i + 1) % 2; - if (i == 0) l++; - if (j == Up) + f = f2 = 1; + if (r < P.VaccMinRadius2) + Mcells[k].vacc = 3; + else if ((Mcells[k].n > 0) && (Mcells[k].vacc == 0)) { - f3 = f2; - f2 = 0; + Mcells[k].vacc_start_time = tsvb; + Mcells[k].vacc = 1; } } - k = P.get_micro_cell_index_from_position(min); - } while (f3); - } - } - - //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** - //// **** //// **** //// **** //// **** PLACE CLOSURE - //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** - - - ///// note that here f2 bool asks whether trigger lower than stop threshold. A few blocks down meaning changes to almost the opposite: asking whether trigger has exceeded threshold in order to close places for first time. - if (P.DoGlobalTriggers) - f2 = (global_trig < P.PlaceCloseCellIncStopThresh); - else if (P.DoAdminTriggers) - { - int trig_thresh = (P.DoPerCapitaTriggers) ? ((int)ceil(((double)(AdUnits[adi].n * P.PlaceCloseCellIncStopThresh)) / P.IncThreshPop)) : P.PlaceCloseCellIncStopThresh; - f2 = (State.trigDC_adunit[adi] < trig_thresh); - } - else - { - int trig_thresh = (P.DoPerCapitaTriggers) ? ((int)ceil(((double)(Mcells[b].n * P.PlaceCloseCellIncStopThresh)) / P.IncThreshPop)) : P.PlaceCloseCellIncStopThresh; - f2 = (Mcells[b].treat_trig < trig_thresh); - } - if ((Mcells[b].placeclose == 2) && ((f2) || (ts >= Mcells[b].place_end_time))) //// if place closure has started, the places in this microcell are closed, and either stop threshold has been reached or place_end_time has passed, go through block - { - f = 1; - Mcells[b].placeclose = P.DoPlaceCloseOnceOnly; - Mcells[b].place_end_time = ts; - Mcells[b].place_trig = 0; - if (f2) - { - for (int j2 = 0; j2 < P.PlaceTypeNum; j2++) - if (j2 != P.HotelPlaceType) - for (int i2 = 0; i2 < Mcells[b].np[j2]; i2++) - DoPlaceOpen(j2, Mcells[b].places[j2][i2], ts, tn); - } - } - - - if ((P.DoPlaces) && (t >= P.PlaceCloseTimeStart) && (Mcells[b].placeclose == 0)) - { - ///// note that here f2 bool asks whether trigger has exceeded threshold in order to close places for first time.A few blocks up meaning was almost the opposite: asking whether trigger lower than stop threshold. - - if (P.DoGlobalTriggers) - { - f2 = (global_trig >= P.PlaceCloseCellIncThresh); - } - else if (P.DoAdminTriggers) - { - int trig_thresh = (P.DoPerCapitaTriggers) ? ((int)ceil(((double)(AdUnits[adi].n * P.PlaceCloseCellIncThresh)) / P.IncThreshPop)) : P.PlaceCloseCellIncThresh; - f2 = (State.trigDC_adunit[adi] > trig_thresh); - } - else - { - int trig_thresh = (P.DoPerCapitaTriggers) ? ((int)ceil(((double)(Mcells[b].n * P.PlaceCloseCellIncThresh)) / P.IncThreshPop)) : P.PlaceCloseCellIncThresh; - f2 = (Mcells[b].treat_trig >= trig_thresh); - } - if (((P.PlaceCloseByAdminUnit) && (AdUnits[Mcells[b].adunit].place_close_trig < USHRT_MAX - 1) - && (((double)AdUnits[Mcells[b].adunit].place_close_trig) / ((double)AdUnits[Mcells[b].adunit].NP) > P.PlaceCloseAdunitPropThresh)) - || ((!P.PlaceCloseByAdminUnit) && (f2))) - { - // if(P.PlaceCloseByAdminUnit) AdUnits[Mcells[b].adunit].place_close_trig=USHRT_MAX-1; // This means schools only close once - int interventionFlag; //added this as a way to help filter out when interventions start - interventionFlag = 1; - if ((P.DoInterventionDelaysByAdUnit)&&((t <= AdUnits[Mcells[b].adunit].PlaceCloseTimeStart) || (t >= (AdUnits[Mcells[b].adunit].PlaceCloseTimeStart + AdUnits[Mcells[b].adunit].PlaceCloseDuration)))) - interventionFlag = 0; - - if ((interventionFlag == 1)&&((!P.PlaceCloseByAdminUnit) || (ad > 0))) + } + min += j; + m = (m + 1) % l; + if (m == 0) { - if ((Mcells[b].n > 0) && (Mcells[b].placeclose == 0)) + j = rotate_left(j); + i = (i + 1) % 2; + if (i == 0) + l++; + if (j == Up) { - //if doing intervention delays and durations by admin unit based on global triggers - if (P.DoInterventionDelaysByAdUnit) - Mcells[b].place_end_time = (unsigned short int) ceil(P.TimeStepsPerDay * (t + P.PlaceCloseDelayMean + AdUnits[Mcells[b].adunit].PlaceCloseDuration)); - else - Mcells[b].place_end_time = tspf; - Mcells[b].place_trig = 0; - Mcells[b].placeclose = 2; - for (int j2 = 0; j2 < P.PlaceTypeNum; j2++) - if (j2 != P.HotelPlaceType) - for (int i2 = 0; i2 < Mcells[b].np[j2]; i2++) - DoPlaceClose(j2, Mcells[b].places[j2][i2], ts, tn, 1); + f3 = f2; + f2 = 0; } } - } + k = P.get_micro_cell_index_from_position(min); + } while (f3); } + } + //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** + /////// **** //// **** //// **** / **** //// **** //// **** //// **** PLACE CLOSURE / **** + /////// **** //// **** //// **** //// **** //// **** //// **** //// **** - //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** - //// **** //// **** //// **** //// **** MOVEMENT RESTRICTIONS - //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** - - if ((Mcells[b].moverest == 2) && (ts >= Mcells[b].move_end_time)) - { - f = 1; - Mcells[b].moverest = P.DoMoveRestrOnceOnly; - } - if ((Mcells[b].moverest == 1) && (ts >= Mcells[b].move_start_time)) - { - f = 1; - Mcells[b].moverest = 2; - Mcells[b].move_trig = 0; - Mcells[b].move_end_time = tsmf; - } - if (P.DoGlobalTriggers) - f2 = (global_trig >= P.MoveRestrCellIncThresh); - else if (P.DoAdminTriggers) - { - int trig_thresh = (P.DoPerCapitaTriggers) ? ((int)ceil(((double)(AdUnits[adi].n * P.MoveRestrCellIncThresh)) / P.IncThreshPop)) : P.MoveRestrCellIncThresh; - f2 = (State.trigDC_adunit[adi] > trig_thresh); - } - else - { - int trig_thresh = (P.DoPerCapitaTriggers) ? ((int)ceil(((double)(Mcells[b].n * P.MoveRestrCellIncThresh)) / P.IncThreshPop)) : P.MoveRestrCellIncThresh; - f2 = (Mcells[b].treat_trig >= trig_thresh); - } - - if ((t >= P.MoveRestrTimeStart) && (Mcells[b].moverest == 0) && (f2)) + ///// note that here f2 bool asks whether trigger lower than stop threshold. A few blocks + /// down meaning changes to almost the opposite: asking whether trigger has exceeded + /// threshold in order to close places for first time. + if (P.DoGlobalTriggers) + f2 = (global_trig < P.PlaceCloseCellIncStopThresh); + else if (P.DoAdminTriggers) + { + int trig_thresh = + (P.DoPerCapitaTriggers) + ? ((int)ceil(((double)(AdUnits[adi].n * P.PlaceCloseCellIncStopThresh)) / + P.IncThreshPop)) + : P.PlaceCloseCellIncStopThresh; + f2 = (State.trigDC_adunit[adi] < trig_thresh); + } + else + { + int trig_thresh = + (P.DoPerCapitaTriggers) + ? ((int)ceil(((double)(Mcells[b].n * P.PlaceCloseCellIncStopThresh)) / + P.IncThreshPop)) + : P.PlaceCloseCellIncStopThresh; + f2 = (Mcells[b].treat_trig < trig_thresh); + } + if ((Mcells[b].placeclose == 2) && + ((f2) || + (ts >= Mcells[b].place_end_time))) //// if place closure has started, the places in + /// this microcell are closed, and either stop + /// threshold has been reached or place_end_time has + /// passed, go through block + { + f = 1; + Mcells[b].placeclose = P.DoPlaceCloseOnceOnly; + Mcells[b].place_end_time = ts; + Mcells[b].place_trig = 0; + if (f2) { - MicroCellPosition min = P.get_micro_cell_position_from_cell_index(b); - Direction j = Direction::Right; - int k = b; - int i, l, m; - i = m = f2 = 0; - l = f3 = 1; - if ((!P.MoveRestrByAdminUnit) || (ad > 0)) - { - int ad2 = ad / P.MoveRestrAdminUnitDivisor; - do - { - if (P.is_in_bounds(min)) - { - if (P.MoveRestrByAdminUnit) - f4 = (AdUnits[Mcells[k].adunit].id / P.MoveRestrAdminUnitDivisor == ad2); - else - f4 = ((r = dist2_mm(Mcells + b, Mcells + k)) < P.MoveRestrRadius2); - if (f4) - { - f = f2 = 1; - if ((Mcells[k].n > 0) && (Mcells[k].moverest == 0)) - { - Mcells[k].move_start_time = tsmb; - Mcells[k].moverest = 1; - } - } - } - min += j; - m = (m + 1) % l; - if (m == 0) - { - j = rotate_left(j); - i = (i + 1) % 2; - if (i == 0) l++; - if (j == 1) { f3 = f2; f2 = 0; } - } - k = P.get_micro_cell_index_from_position(min); - } while (f3); - } + for (int j2 = 0; j2 < P.PlaceTypeNum; j2++) + if (j2 != P.HotelPlaceType) + for (int i2 = 0; i2 < Mcells[b].np[j2]; i2++) + DoPlaceOpen(j2, Mcells[b].places[j2][i2], ts, tn); } + } - //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** - //// **** //// **** //// **** //// **** SOCIAL DISTANCING - //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** - + if ((P.DoPlaces) && (t >= P.PlaceCloseTimeStart) && (Mcells[b].placeclose == 0)) + { + ///// note that here f2 bool asks whether trigger has exceeded threshold in order to close + /// places for first time.A few blocks up meaning was almost the opposite: asking whether + /// trigger lower than stop threshold. if (P.DoGlobalTriggers) - f2 = (global_trig < P.SocDistCellIncStopThresh); - else if (P.DoAdminTriggers) { - int trig_thresh = (P.DoPerCapitaTriggers) ? ((int)ceil(((double)(AdUnits[adi].n * P.SocDistCellIncStopThresh)) / P.IncThreshPop)) : P.SocDistCellIncStopThresh; - f2 = (State.trigDC_adunit[adi] < trig_thresh); + f2 = (global_trig >= P.PlaceCloseCellIncThresh); } - else - { - int trig_thresh = (P.DoPerCapitaTriggers) ? ((int)ceil(((double)(Mcells[b].n * P.SocDistCellIncStopThresh)) / P.IncThreshPop)) : P.SocDistCellIncStopThresh; - f2 = (Mcells[b].treat_trig < trig_thresh); - } - - //// if: policy of social distancing has started AND this microcell cell has been labelled to as undergoing social distancing, AND either trigger not reached (note definition of f2 changes in next few lines) or end time has passed. - if ((t >= P.SocDistTimeStart) && (Mcells[b].socdist == 2) && ((f2) || (ts >= Mcells[b].socdist_end_time))) - { - f = 1; - Mcells[b].socdist = P.DoSocDistOnceOnly; //// i.e. if P.DoSocDistOnceOnly set to false, socdist set to 0 here, hence will be picked up upon some subsequent call to TreatSweep if required trigger passes threshold. - Mcells[b].socdist_trig = 0; //// reset trigger - Mcells[b].socdist_end_time = ts; //// record end time. - } - if (P.DoGlobalTriggers) - f2 = (global_trig >= P.SocDistCellIncThresh); else if (P.DoAdminTriggers) { - int trig_thresh = (P.DoPerCapitaTriggers) ? ((int)ceil(((double)(AdUnits[adi].n * P.SocDistCellIncThresh)) / P.IncThreshPop)) : P.SocDistCellIncThresh; - f2 = (State.trigDC_adunit[adi] >= trig_thresh); + int trig_thresh = + (P.DoPerCapitaTriggers) + ? ((int)ceil(((double)(AdUnits[adi].n * P.PlaceCloseCellIncThresh)) / + P.IncThreshPop)) + : P.PlaceCloseCellIncThresh; + f2 = (State.trigDC_adunit[adi] > trig_thresh); } else { - int trig_thresh = (P.DoPerCapitaTriggers) ? ((int)ceil(((double)(Mcells[b].n * P.SocDistCellIncThresh)) / P.IncThreshPop)) : P.SocDistCellIncThresh; + int trig_thresh = (P.DoPerCapitaTriggers) + ? ((int)ceil(((double)(Mcells[b].n * P.PlaceCloseCellIncThresh)) / + P.IncThreshPop)) + : P.PlaceCloseCellIncThresh; f2 = (Mcells[b].treat_trig >= trig_thresh); } - if ((t >= P.SocDistTimeStart) && (Mcells[b].socdist == 0) && (f2)) + if (((P.PlaceCloseByAdminUnit) && + (AdUnits[Mcells[b].adunit].place_close_trig < USHRT_MAX - 1) && + (((double)AdUnits[Mcells[b].adunit].place_close_trig) / + ((double)AdUnits[Mcells[b].adunit].NP) > + P.PlaceCloseAdunitPropThresh)) || + ((!P.PlaceCloseByAdminUnit) && (f2))) { - //some code to try and deal with intervention delays and durations by admin unit based on global triggers - int interventionFlag; //added this as a way to help filter out when interventions start + // if(P.PlaceCloseByAdminUnit) + // AdUnits[Mcells[b].adunit].place_close_trig=USHRT_MAX-1; // This means schools only + // close once + int interventionFlag; // added this as a way to help filter out when interventions start interventionFlag = 1; + if ((P.DoInterventionDelaysByAdUnit) && + ((t <= AdUnits[Mcells[b].adunit].PlaceCloseTimeStart) || + (t >= (AdUnits[Mcells[b].adunit].PlaceCloseTimeStart + + AdUnits[Mcells[b].adunit].PlaceCloseDuration)))) + interventionFlag = 0; - if (P.DoInterventionDelaysByAdUnit) - if ((t <= AdUnits[Mcells[b].adunit].SocialDistanceTimeStart) || - (t >= (AdUnits[Mcells[b].adunit].SocialDistanceTimeStart + AdUnits[Mcells[b].adunit].SocialDistanceDuration))) //// i.e. if outside window of social distancing for this admin unit. - interventionFlag = 0; - - if (interventionFlag == 1) - if ((Mcells[b].n > 0) && (Mcells[b].socdist == 0)) //// if microcell populated and not currently undergoing social distancing + if ((interventionFlag == 1) && ((!P.PlaceCloseByAdminUnit) || (ad > 0))) + { + if ((Mcells[b].n > 0) && (Mcells[b].placeclose == 0)) { - Mcells[b].socdist = 2; //// update flag to denote that cell is undergoing social distancing - Mcells[b].socdist_trig = 0; /// reset trigger - //// set (admin-specific) social distancing end time. + // if doing intervention delays and durations by admin unit based on global triggers if (P.DoInterventionDelaysByAdUnit) - Mcells[b].socdist_end_time = (unsigned short int) ceil(P.TimeStepsPerDay * (t + AdUnits[Mcells[b].adunit].SocialDistanceDuration)); + Mcells[b].place_end_time = (unsigned short int)ceil( + P.TimeStepsPerDay * + (t + P.PlaceCloseDelayMean + AdUnits[Mcells[b].adunit].PlaceCloseDuration)); else - Mcells[b].socdist_end_time = tssdf; + Mcells[b].place_end_time = tspf; + Mcells[b].place_trig = 0; + Mcells[b].placeclose = 2; + for (int j2 = 0; j2 < P.PlaceTypeNum; j2++) + if (j2 != P.HotelPlaceType) + for (int i2 = 0; i2 < Mcells[b].np[j2]; i2++) + DoPlaceClose(j2, Mcells[b].places[j2][i2], ts, tn, 1); } + } } + } + //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** + /////// **** //// **** //// **** / **** //// **** //// **** //// **** MOVEMENT RESTRICTIONS + //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** - //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** - //// **** //// **** //// **** //// **** KEY-WORKER PROPHYLAXIS - //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** + if ((Mcells[b].moverest == 2) && (ts >= Mcells[b].move_end_time)) + { + f = 1; + Mcells[b].moverest = P.DoMoveRestrOnceOnly; + } + if ((Mcells[b].moverest == 1) && (ts >= Mcells[b].move_start_time)) + { + f = 1; + Mcells[b].moverest = 2; + Mcells[b].move_trig = 0; + Mcells[b].move_end_time = tsmf; + } + if (P.DoGlobalTriggers) + f2 = (global_trig >= P.MoveRestrCellIncThresh); + else if (P.DoAdminTriggers) + { + int trig_thresh = (P.DoPerCapitaTriggers) + ? ((int)ceil(((double)(AdUnits[adi].n * P.MoveRestrCellIncThresh)) / + P.IncThreshPop)) + : P.MoveRestrCellIncThresh; + f2 = (State.trigDC_adunit[adi] > trig_thresh); + } + else + { + int trig_thresh = + (P.DoPerCapitaTriggers) + ? ((int)ceil(((double)(Mcells[b].n * P.MoveRestrCellIncThresh)) / P.IncThreshPop)) + : P.MoveRestrCellIncThresh; + f2 = (Mcells[b].treat_trig >= trig_thresh); + } - if ((Mcells[b].keyworkerproph == 2) && (ts >= Mcells[b].keyworkerproph_end_time)) - { - f = 1; - Mcells[b].keyworkerproph = P.DoKeyWorkerProphOnceOnly; - } - if (P.DoGlobalTriggers) - f2 = (global_trig >= P.KeyWorkerProphCellIncThresh); - else if (P.DoAdminTriggers) - { - int trig_thresh = (P.DoPerCapitaTriggers) ? ((int)ceil(((double)(AdUnits[adi].n * P.KeyWorkerProphCellIncThresh)) / P.IncThreshPop)) : P.KeyWorkerProphCellIncThresh; - f2 = (State.trigDC_adunit[adi] > trig_thresh); - } - else - { - int trig_thresh = (P.DoPerCapitaTriggers) ? ((int)ceil(((double)(Mcells[b].n * P.KeyWorkerProphCellIncThresh)) / P.IncThreshPop)) : P.KeyWorkerProphCellIncThresh; - f2 = (Mcells[b].treat_trig >= trig_thresh); - } - if ((P.DoPlaces) && (t >= P.KeyWorkerProphTimeStart) && (Mcells[b].keyworkerproph == 0) && (f2)) + if ((t >= P.MoveRestrTimeStart) && (Mcells[b].moverest == 0) && (f2)) + { + MicroCellPosition min = P.get_micro_cell_position_from_cell_index(b); + Direction j = Direction::Right; + int k = b; + int i, l, m; + i = m = f2 = 0; + l = f3 = 1; + if ((!P.MoveRestrByAdminUnit) || (ad > 0)) { - MicroCellPosition min = P.get_micro_cell_position_from_cell_index(b); - Direction j = Right; - int k = b; - int i, l, m; - i = m = f2 = 0; - l = f3 = 1; + int ad2 = ad / P.MoveRestrAdminUnitDivisor; do { if (P.is_in_bounds(min)) - if (dist2_mm(Mcells + b, Mcells + k) < P.KeyWorkerProphRadius2) + { + if (P.MoveRestrByAdminUnit) + f4 = (AdUnits[Mcells[k].adunit].id / P.MoveRestrAdminUnitDivisor == ad2); + else + f4 = ((r = dist2_mm(Mcells + b, Mcells + k)) < P.MoveRestrRadius2); + if (f4) { f = f2 = 1; - if ((Mcells[k].n > 0) && (Mcells[k].keyworkerproph == 0)) + if ((Mcells[k].n > 0) && (Mcells[k].moverest == 0)) { - Mcells[k].keyworkerproph = 2; - Mcells[k].keyworkerproph_trig = 0; - Mcells[k].keyworkerproph_end_time = tskwpf; - for (int i2 = 0; i2 < Mcells[k].n; i2++) - { - int j2 = Mcells[k].members[i2]; - if ((Hosts[j2].keyworker) && (!HOST_TO_BE_TREATED(j2))) - DoProphNoDelay(j2, ts, tn, nckwp); - } + Mcells[k].move_start_time = tsmb; + Mcells[k].moverest = 1; } } + } min += j; m = (m + 1) % l; if (m == 0) { j = rotate_left(j); i = (i + 1) % 2; - if (i == 0) l++; - if (j == Up) + if (i == 0) + l++; + if (j == 1) { f3 = f2; f2 = 0; @@ -1990,19 +2205,181 @@ int TreatSweep(double t) k = P.get_micro_cell_index_from_position(min); } while (f3); } + } + + //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** + /////// **** //// **** //// **** / **** //// **** //// **** //// **** SOCIAL DISTANCING / + ///**** //// **** //// **** //// **** //// **** //// **** //// **** //// **** + if (P.DoGlobalTriggers) + f2 = (global_trig < P.SocDistCellIncStopThresh); + else if (P.DoAdminTriggers) + { + int trig_thresh = + (P.DoPerCapitaTriggers) + ? ((int)ceil(((double)(AdUnits[adi].n * P.SocDistCellIncStopThresh)) / + P.IncThreshPop)) + : P.SocDistCellIncStopThresh; + f2 = (State.trigDC_adunit[adi] < trig_thresh); + } + else + { + int trig_thresh = (P.DoPerCapitaTriggers) + ? ((int)ceil(((double)(Mcells[b].n * P.SocDistCellIncStopThresh)) / + P.IncThreshPop)) + : P.SocDistCellIncStopThresh; + f2 = (Mcells[b].treat_trig < trig_thresh); + } + + //// if: policy of social distancing has started AND this microcell cell has been labelled + /// to as undergoing social distancing, AND either trigger not reached (note definition of + /// f2 changes in next few lines) or end time has passed. + if ((t >= P.SocDistTimeStart) && (Mcells[b].socdist == 2) && + ((f2) || (ts >= Mcells[b].socdist_end_time))) + { + f = 1; + Mcells[b].socdist = + P.DoSocDistOnceOnly; //// i.e. if P.DoSocDistOnceOnly set to false, socdist set to 0 + /// here, hence will be picked up upon some subsequent call to + /// TreatSweep if required trigger passes threshold. + Mcells[b].socdist_trig = 0; //// reset trigger + Mcells[b].socdist_end_time = ts; //// record end time. + } + if (P.DoGlobalTriggers) + f2 = (global_trig >= P.SocDistCellIncThresh); + else if (P.DoAdminTriggers) + { + int trig_thresh = (P.DoPerCapitaTriggers) + ? ((int)ceil(((double)(AdUnits[adi].n * P.SocDistCellIncThresh)) / + P.IncThreshPop)) + : P.SocDistCellIncThresh; + f2 = (State.trigDC_adunit[adi] >= trig_thresh); + } + else + { + int trig_thresh = + (P.DoPerCapitaTriggers) + ? ((int)ceil(((double)(Mcells[b].n * P.SocDistCellIncThresh)) / P.IncThreshPop)) + : P.SocDistCellIncThresh; + f2 = (Mcells[b].treat_trig >= trig_thresh); + } + if ((t >= P.SocDistTimeStart) && (Mcells[b].socdist == 0) && (f2)) + { + // some code to try and deal with intervention delays and durations by admin unit based on + // global triggers + int interventionFlag; // added this as a way to help filter out when interventions start + interventionFlag = 1; + + if (P.DoInterventionDelaysByAdUnit) + if ((t <= AdUnits[Mcells[b].adunit].SocialDistanceTimeStart) || + (t >= (AdUnits[Mcells[b].adunit].SocialDistanceTimeStart + + AdUnits[Mcells[b].adunit] + .SocialDistanceDuration))) //// i.e. if outside window of social + /// distancing for this admin unit. + interventionFlag = 0; + + if (interventionFlag == 1) + if ((Mcells[b].n > 0) && + (Mcells[b].socdist == + 0)) //// if microcell populated and not currently undergoing social distancing + { + Mcells[b].socdist = + 2; //// update flag to denote that cell is undergoing social distancing + Mcells[b].socdist_trig = 0; /// reset trigger + //// set (admin-specific) social distancing end time. + if (P.DoInterventionDelaysByAdUnit) + Mcells[b].socdist_end_time = (unsigned short int)ceil( + P.TimeStepsPerDay * (t + AdUnits[Mcells[b].adunit].SocialDistanceDuration)); + else + Mcells[b].socdist_end_time = tssdf; + } + } + + //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** + /////// **** //// **** //// **** / **** //// **** //// **** //// **** KEY-WORKER PROPHYLAXIS + //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** + + if ((Mcells[b].keyworkerproph == 2) && (ts >= Mcells[b].keyworkerproph_end_time)) + { + f = 1; + Mcells[b].keyworkerproph = P.DoKeyWorkerProphOnceOnly; + } + if (P.DoGlobalTriggers) + f2 = (global_trig >= P.KeyWorkerProphCellIncThresh); + else if (P.DoAdminTriggers) + { + int trig_thresh = + (P.DoPerCapitaTriggers) + ? ((int)ceil(((double)(AdUnits[adi].n * P.KeyWorkerProphCellIncThresh)) / + P.IncThreshPop)) + : P.KeyWorkerProphCellIncThresh; + f2 = (State.trigDC_adunit[adi] > trig_thresh); + } + else + { + int trig_thresh = + (P.DoPerCapitaTriggers) + ? ((int)ceil(((double)(Mcells[b].n * P.KeyWorkerProphCellIncThresh)) / + P.IncThreshPop)) + : P.KeyWorkerProphCellIncThresh; + f2 = (Mcells[b].treat_trig >= trig_thresh); + } + if ((P.DoPlaces) && (t >= P.KeyWorkerProphTimeStart) && (Mcells[b].keyworkerproph == 0) && + (f2)) + { + MicroCellPosition min = P.get_micro_cell_position_from_cell_index(b); + Direction j = Right; + int k = b; + int i, l, m; + i = m = f2 = 0; + l = f3 = 1; + do + { + if (P.is_in_bounds(min)) + if (dist2_mm(Mcells + b, Mcells + k) < P.KeyWorkerProphRadius2) + { + f = f2 = 1; + if ((Mcells[k].n > 0) && (Mcells[k].keyworkerproph == 0)) + { + Mcells[k].keyworkerproph = 2; + Mcells[k].keyworkerproph_trig = 0; + Mcells[k].keyworkerproph_end_time = tskwpf; + for (int i2 = 0; i2 < Mcells[k].n; i2++) + { + int j2 = Mcells[k].members[i2]; + if ((Hosts[j2].keyworker) && (!HOST_TO_BE_TREATED(j2))) + DoProphNoDelay(j2, ts, tn, nckwp); + } + } + } + min += j; + m = (m + 1) % l; + if (m == 0) + { + j = rotate_left(j); + i = (i + 1) % 2; + if (i == 0) + l++; + if (j == Up) + { + f3 = f2; + f2 = 0; + } + } + k = P.get_micro_cell_index_from_position(min); + } while (f3); + } } for (int i = 0; i < P.NumThreads; i++) { State.cumT += StateT[i].cumT; State.cumTP += StateT[i].cumTP; State.cumUT += StateT[i].cumUT; - //State.cumV+=StateT[i].cumV; - StateT[i].cumT = StateT[i].cumUT = StateT[i].cumTP = 0; //StateT[i].cumV=0; + // State.cumV+=StateT[i].cumV; + StateT[i].cumT = StateT[i].cumUT = StateT[i].cumTP = 0; // StateT[i].cumV=0; } } f += f1; - return (f > 0); } diff --git a/src/Sweep.h b/src/Sweep.h index 88d76ddf5..5a9912c74 100644 --- a/src/Sweep.h +++ b/src/Sweep.h @@ -3,10 +3,12 @@ void TravelReturnSweep(double); void TravelDepartSweep(double); -void InfectSweep(double, int); //added int as argument to InfectSweep to record run number: ggilani - 15/10/14 -void IncubRecoverySweep(double, int); //added int as argument to record run number: ggilani - 15/10/14 +void InfectSweep( + double, int); // added int as argument to InfectSweep to record run number: ggilani - 15/10/14 +void IncubRecoverySweep(double, + int); // added int as argument to record run number: ggilani - 15/10/14 int TreatSweep(double); -//void HospitalSweep(double); //added hospital sweep function: ggilani - 10/11/14 +// void HospitalSweep(double); //added hospital sweep function: ggilani - 10/11/14 void DigitalContactTracingSweep(double); // added function to update contact tracing number #endif // COVIDSIM_SWEEP_H_INCLUDED_ diff --git a/src/Update.cpp b/src/Update.cpp index e23a7f748..75dd56942 100644 --- a/src/Update.cpp +++ b/src/Update.cpp @@ -1,19 +1,21 @@ #include -#include #include +#include -#include "Update.h" +#include "Bitmap.h" +#include "InfStat.h" #include "Model.h" #include "ModelMacros.h" #include "Param.h" -#include "InfStat.h" -#include "Bitmap.h" #include "Rand.h" +#include "Update.h" using namespace Geometry; -//adding function to record an event: ggilani - 10/10/2014 -void RecordEvent(double, int, int, int, int); //added int as argument to InfectSweep to record run number: ggilani - 15/10/14 +// adding function to record an event: ggilani - 10/10/2014 +void RecordEvent( + double, int, int, int, + int); // added int as argument to InfectSweep to record run number: ggilani - 15/10/14 unsigned short int ChooseFromICDF(double *, double, int); Severity ChooseFinalDiseaseSeverity(int, int); @@ -27,8 +29,9 @@ void InfectiousToDeath(int cellIndex); void DoImmune(int ai) { - // This transfers a person straight from susceptible to immune. Used to start a run with a partially immune population. - Person* a; + // This transfers a person straight from susceptible to immune. Used to start a run with a + // partially immune population. + Person *a; int c; a = Hosts + ai; @@ -51,7 +54,8 @@ void DoImmune(int ai) } if (Cells[c].I > 0) { - Cells[c].susceptible[Cells[c].S + Cells[c].L] = Cells[c].susceptible[Cells[c].S + Cells[c].L + Cells[c].I]; + Cells[c].susceptible[Cells[c].S + Cells[c].L] = + Cells[c].susceptible[Cells[c].S + Cells[c].L + Cells[c].I]; Hosts[Cells[c].susceptible[Cells[c].S + Cells[c].L]].listpos = Cells[c].S + Cells[c].L; } if (a->listpos < Cells[c].S + Cells[c].L + Cells[c].I) @@ -59,7 +63,6 @@ void DoImmune(int ai) Cells[c].susceptible[Cells[c].S + Cells[c].L + Cells[c].I] = ai; a->listpos = Cells[c].S + Cells[c].L + Cells[c].I; } - if (P.OutputBitmap) { @@ -76,21 +79,26 @@ void DoImmune(int ai) } } } -void DoInfect(int ai, double t, int tn, int run) // Change person from susceptible to latently infected. added int as argument to DoInfect to record run number: ggilani - 15/10/14 +void DoInfect(int ai, double t, int tn, + int run) // Change person from susceptible to latently infected. added int as + // argument to DoInfect to record run number: ggilani - 15/10/14 { - ///// This updates a number of things concerning person ai (and their contacts/infectors/places etc.) at time t in thread tn for this run. + ///// This updates a number of things concerning person ai (and their contacts/infectors/places + /// etc.) at time t in thread tn for this run. int i; unsigned short int ts; //// time step - double q, x, y; //// q radius squared, x and y coords. q later changed to be quantile of inverse CDF to choose latent period. - Person* a; + double q, x, y; //// q radius squared, x and y coords. q later changed to be quantile of inverse + /// CDF to choose latent period. + Person *a; a = Hosts + ai; //// pointer arithmetic. a = pointer to person. ai = int person index. - if (a->inf == InfStat_Susceptible) //// Only change anything if person a/ai uninfected at start of this function. + if (a->inf == InfStat_Susceptible) //// Only change anything if person a/ai uninfected at start of + /// this function. { - ts = (unsigned short int) (P.TimeStepsPerDay * t); - a->inf = InfStat_Latent; //// set person a to be infected - a->infection_time = (unsigned short int) ts; //// record their infection time + ts = (unsigned short int)(P.TimeStepsPerDay * t); + a->inf = InfStat_Latent; //// set person a to be infected + a->infection_time = (unsigned short int)ts; //// record their infection time ///// Change threaded state variables to reflect new infection status of person a. StateT[tn].cumI++; StateT[tn].cumItype[a->infect_type % INFECT_TYPE_MASK]++; @@ -101,7 +109,8 @@ void DoInfect(int ai, double t, int tn, int run) // Change person from susceptib q = x * x + y * y; StateT[tn].sumRad2 += q; - if (q > StateT[tn].maxRad2) StateT[tn].maxRad2 = q; //// update maximum radius squared from seeding infection + if (q > StateT[tn].maxRad2) + StateT[tn].maxRad2 = q; //// update maximum radius squared from seeding infection { SusceptibleToLatent(a->pcell); @@ -109,7 +118,8 @@ void DoInfect(int ai, double t, int tn, int run) // Change person from susceptib { Cells[a->pcell].susceptible[a->listpos] = Cells[a->pcell].susceptible[Cells[a->pcell].S]; Hosts[Cells[a->pcell].susceptible[a->listpos]].listpos = a->listpos; - a->listpos = Cells[a->pcell].S; //// person a's position with cell.members now equal to number of susceptibles in cell. + a->listpos = Cells[a->pcell].S; //// person a's position with cell.members now equal to + /// number of susceptibles in cell. Cells[a->pcell].latent[0] = ai; //// person ai joins front of latent queue. } } @@ -119,10 +129,13 @@ void DoInfect(int ai, double t, int tn, int run) // Change person from susceptib { i = (int)floor((q = ranf_mt(tn) * CDF_RES)); q -= ((double)i); - a->latent_time = (unsigned short int) floor(0.5 + (t - P.LatentPeriod * log(q * P.latent_icdf[i + 1] + (1.0 - q) * P.latent_icdf[i])) * P.TimeStepsPerDay); + a->latent_time = (unsigned short int)floor( + 0.5 + + (t - P.LatentPeriod * log(q * P.latent_icdf[i + 1] + (1.0 - q) * P.latent_icdf[i])) * + P.TimeStepsPerDay); } else - a->latent_time = (unsigned short int) (t * P.TimeStepsPerDay); + a->latent_time = (unsigned short int)(t * P.TimeStepsPerDay); if (a->infector >= 0) // record generation times and serial intervals { StateT[tn].cumTG += (((int)a->infection_time) - ((int)Hosts[a->infector].infection_time)); @@ -130,8 +143,8 @@ void DoInfect(int ai, double t, int tn, int run) // Change person from susceptib StateT[tn].nTG++; } - //if (P.DoLatent) a->latent_time = a->infection_time + ChooseFromICDF(P.latent_icdf, P.LatentPeriod, tn); - //else a->latent_time = (unsigned short int) (t * P.TimeStepsPerDay); + // if (P.DoLatent) a->latent_time = a->infection_time + ChooseFromICDF(P.latent_icdf, + // P.LatentPeriod, tn); else a->latent_time = (unsigned short int) (t * P.TimeStepsPerDay); if (P.DoAdUnits) { @@ -140,12 +153,13 @@ void DoInfect(int ai, double t, int tn, int run) // Change person from susceptib if (P.OutputAdUnitAge) { StateT[tn].prevInf_age_adunit[HOST_AGE_GROUP(ai)][Mcells[a->mcell].adunit]++; - StateT[tn].cumInf_age_adunit [HOST_AGE_GROUP(ai)][Mcells[a->mcell].adunit]++; + StateT[tn].cumInf_age_adunit[HOST_AGE_GROUP(ai)][Mcells[a->mcell].adunit]++; } } if (P.OutputBitmap) { - if ((P.OutputBitmapDetected == 0) || ((P.OutputBitmapDetected == 1) && (Hosts[ai].detected == 1))) + if ((P.OutputBitmapDetected == 0) || + ((P.OutputBitmapDetected == 1) && (Hosts[ai].detected == 1))) { Vector2 pixel((Households[a->hh].loc * P.scale) - P.bmin); if (P.b.contains(pixel)) @@ -159,10 +173,12 @@ void DoInfect(int ai, double t, int tn, int run) // Change person from susceptib } } } - //added this to record event if flag is set to 1 : ggilani - 10/10/2014 + // added this to record event if flag is set to 1 : ggilani - 10/10/2014 if (P.DoRecordInfEvents) { - RecordEvent(t, ai, run, 0, tn); //added int as argument to RecordEvent to record run number: ggilani - 15/10/14 + RecordEvent( + t, ai, run, 0, + tn); // added int as argument to RecordEvent to record run number: ggilani - 15/10/14 } if ((t > 0) && (P.DoOneGen)) { @@ -173,7 +189,9 @@ void DoInfect(int ai, double t, int tn, int run) // Change person from susceptib } } -void RecordEvent(double t, int ai, int run, int type, int tn) //added int as argument to RecordEvent to record run number: ggilani - 15/10/14 +void RecordEvent( + double t, int ai, int run, int type, + int tn) // added int as argument to RecordEvent to record run number: ggilani - 15/10/14 { /* Function: RecordEvent(t, ai) * Records an infection event in the event log @@ -186,13 +204,13 @@ void RecordEvent(double t, int ai, int run, int type, int tn) //added int as arg * * Author: ggilani, Date: 10/10/2014 */ - //Declare int to store infector's index + // Declare int to store infector's index int bi; bi = Hosts[ai].infector; - //Save information to event -#pragma omp critical (inf_event) + // Save information to event +#pragma omp critical(inf_event) if (nEvents < P.MaxInfEvents) { InfEventLog[nEvents].run = run; @@ -205,7 +223,7 @@ void RecordEvent(double t, int ai, int run, int type, int tn) //added int as arg InfEventLog[nEvents].listpos = Hosts[ai].listpos; InfEventLog[nEvents].infectee_cell = Hosts[ai].pcell; InfEventLog[nEvents].thread = tn; - if (type == 0) //infection event - record time of onset of infector and infector + if (type == 0) // infection event - record time of onset of infector and infector { InfEventLog[nEvents].infector_ind = bi; if (bi < 0) @@ -219,26 +237,25 @@ void RecordEvent(double t, int ai, int run, int type, int tn) //added int as arg InfEventLog[nEvents].infector_cell = Hosts[bi].pcell; } } - else if (type == 1) //onset event - record infectee's onset time + else if (type == 1) // onset event - record infectee's onset time { InfEventLog[nEvents].t_infector = (int)(Hosts[ai].infection_time / P.TimeStepsPerDay); } - else if ((type == 2) || (type == 3)) //recovery or death event - record infectee's onset time + else if ((type == 2) || (type == 3)) // recovery or death event - record infectee's onset time { InfEventLog[nEvents].t_infector = (int)(Hosts[ai].latent_time / P.TimeStepsPerDay); } - //increment the index of the infection event + // increment the index of the infection event nEvents++; } - } void DoMild(int ai, int tn) { if (P.DoSeverity) //// shouldn't need this but best be careful. { - Person* a = Hosts + ai; + Person *a = Hosts + ai; if (a->Severity_Current == Severity_Asymptomatic) { a->Severity_Current = Severity_Mild; @@ -258,7 +275,7 @@ void DoILI(int ai, int tn) { if (P.DoSeverity) //// shouldn't need this but best be careful. { - Person* a = Hosts + ai; + Person *a = Hosts + ai; if (a->Severity_Current == Severity_Asymptomatic) { a->Severity_Current = Severity_ILI; @@ -268,7 +285,7 @@ void DoILI(int ai, int tn) StateT[tn].cumILI_age[HOST_AGE_GROUP(ai)]++; if (P.DoAdUnits) { - StateT[tn].ILI_adunit [Mcells[a->mcell].adunit]++; + StateT[tn].ILI_adunit[Mcells[a->mcell].adunit]++; StateT[tn].cumILI_adunit[Mcells[a->mcell].adunit]++; } } @@ -278,7 +295,7 @@ void DoSARI(int ai, int tn) { if (P.DoSeverity) //// shouldn't need this but best be careful. { - Person* a = Hosts + ai; + Person *a = Hosts + ai; if (a->Severity_Current == Severity_ILI) { a->Severity_Current = Severity_SARI; @@ -290,9 +307,9 @@ void DoSARI(int ai, int tn) StateT[tn].cumSARI_age[HOST_AGE_GROUP(ai)]++; if (P.DoAdUnits) { - StateT[tn].ILI_adunit [Mcells[a->mcell].adunit]--; - StateT[tn].SARI_adunit [Mcells[a->mcell].adunit]++; - StateT[tn].cumSARI_adunit [Mcells[a->mcell].adunit]++; + StateT[tn].ILI_adunit[Mcells[a->mcell].adunit]--; + StateT[tn].SARI_adunit[Mcells[a->mcell].adunit]++; + StateT[tn].cumSARI_adunit[Mcells[a->mcell].adunit]++; } } } @@ -301,7 +318,7 @@ void DoCritical(int ai, int tn) { if (P.DoSeverity) //// shouldn't need this but best be careful. { - Person* a = Hosts + ai; + Person *a = Hosts + ai; if (a->Severity_Current == Severity_SARI) { a->Severity_Current = Severity_Critical; @@ -313,9 +330,9 @@ void DoCritical(int ai, int tn) StateT[tn].cumCritical_age[HOST_AGE_GROUP(ai)]++; if (P.DoAdUnits) { - StateT[tn].SARI_adunit [Mcells[a->mcell].adunit]--; - StateT[tn].Critical_adunit [Mcells[a->mcell].adunit]++; - StateT[tn].cumCritical_adunit [Mcells[a->mcell].adunit]++; + StateT[tn].SARI_adunit[Mcells[a->mcell].adunit]--; + StateT[tn].Critical_adunit[Mcells[a->mcell].adunit]++; + StateT[tn].cumCritical_adunit[Mcells[a->mcell].adunit]++; } } } @@ -324,11 +341,13 @@ void DoRecoveringFromCritical(int ai, int tn) { //// note function different from DoRecover_FromSeverity. //// DoRecover_FromSeverity assigns people to state Recovered (and bookkeeps accordingly). - //// DoRecoveringFromCritical assigns people to intermediate state "recovering from critical condition" (and bookkeeps accordingly). + //// DoRecoveringFromCritical assigns people to intermediate state "recovering from critical + /// condition" (and bookkeeps accordingly). if (P.DoSeverity) //// shouldn't need this but best be careful. { - Person* a = Hosts + ai; - if (a->Severity_Current == Severity_Critical && (!a->to_die)) //// second condition should be unnecessary but leave in for now. + Person *a = Hosts + ai; + if (a->Severity_Current == Severity_Critical && + (!a->to_die)) //// second condition should be unnecessary but leave in for now. { a->Severity_Current = Severity_RecoveringFromCritical; StateT[tn].Critical--; @@ -348,7 +367,7 @@ void DoRecoveringFromCritical(int ai, int tn) } void DoDeath_FromCriticalorSARIorILI(int ai, int tn) { - Person* a = Hosts + ai; + Person *a = Hosts + ai; if (P.DoSeverity) { if (a->Severity_Current == Severity_Critical) @@ -359,10 +378,12 @@ void DoDeath_FromCriticalorSARIorILI(int ai, int tn) StateT[tn].cumDeath_Critical_age[HOST_AGE_GROUP(ai)]++; if (P.DoAdUnits) { - StateT[tn].Critical_adunit [Mcells[a->mcell].adunit]--; - StateT[tn].cumDeath_Critical_adunit [Mcells[a->mcell].adunit]++; + StateT[tn].Critical_adunit[Mcells[a->mcell].adunit]--; + StateT[tn].cumDeath_Critical_adunit[Mcells[a->mcell].adunit]++; } - //// change current status (so that flags work if function called again for same person). Don't move this outside of this if statement, even though it looks like it can be moved safely. It can't. + //// change current status (so that flags work if function called again for same person). + /// Don't move this outside of this if statement, even though it looks like it can be moved + /// safely. It can't. a->Severity_Current = Severity_Dead; } else if (a->Severity_Current == Severity_SARI) @@ -373,10 +394,12 @@ void DoDeath_FromCriticalorSARIorILI(int ai, int tn) StateT[tn].cumDeath_SARI_age[HOST_AGE_GROUP(ai)]++; if (P.DoAdUnits) { - StateT[tn].SARI_adunit [Mcells[a->mcell].adunit]--; - StateT[tn].cumDeath_SARI_adunit [Mcells[a->mcell].adunit]++; + StateT[tn].SARI_adunit[Mcells[a->mcell].adunit]--; + StateT[tn].cumDeath_SARI_adunit[Mcells[a->mcell].adunit]++; } - //// change current status (so that flags work if function called again for same person). Don't move this outside of this if statement, even though it looks like it can be moved safely. It can't. + //// change current status (so that flags work if function called again for same person). + /// Don't move this outside of this if statement, even though it looks like it can be moved + /// safely. It can't. a->Severity_Current = Severity_Dead; } else if (a->Severity_Current == Severity_ILI) @@ -387,10 +410,12 @@ void DoDeath_FromCriticalorSARIorILI(int ai, int tn) StateT[tn].cumDeath_ILI_age[HOST_AGE_GROUP(ai)]++; if (P.DoAdUnits) { - StateT[tn].ILI_adunit [Mcells[a->mcell].adunit]--; - StateT[tn].cumDeath_ILI_adunit [Mcells[a->mcell].adunit]++; + StateT[tn].ILI_adunit[Mcells[a->mcell].adunit]--; + StateT[tn].cumDeath_ILI_adunit[Mcells[a->mcell].adunit]++; } - //// change current status (so that flags work if function called again for same person). Don't move this outside of this if statement, even though it looks like it can be moved safely. It can't. + //// change current status (so that flags work if function called again for same person). + /// Don't move this outside of this if statement, even though it looks like it can be moved + /// safely. It can't. a->Severity_Current = Severity_Dead; } } @@ -399,44 +424,59 @@ void DoRecover_FromSeverity(int ai, int tn) { //// note function different from DoRecoveringFromCritical. //// DoRecover_FromSeverity assigns people to state Recovered (and bookkeeps accordingly). - //// DoRecoveringFromCritical assigns people to intermediate state "recovering from critical condition" (and bookkeeps accordingly). + //// DoRecoveringFromCritical assigns people to intermediate state "recovering from critical + /// condition" (and bookkeeps accordingly). //// moved this from DoRecover - Person* a = Hosts + ai; + Person *a = Hosts + ai; if (P.DoSeverity) - if (a->inf == InfStat_InfectiousAsymptomaticNotCase || a->inf == InfStat_Case) ///// i.e same condition in DoRecover (make sure you don't recover people twice). + if (a->inf == InfStat_InfectiousAsymptomaticNotCase || + a->inf == InfStat_Case) ///// i.e same condition in DoRecover (make sure you don't recover + /// people twice). { if (a->Severity_Current == Severity_Mild) { StateT[tn].Mild--; StateT[tn].Mild_age[HOST_AGE_GROUP(ai)]--; - if (P.DoAdUnits) StateT[tn].Mild_adunit[Mcells[a->mcell].adunit]--; - //// change current status (so that flags work if function called again for same person). Don't move this outside of this if statement, even though it looks like it can be moved safely. It can't. + if (P.DoAdUnits) + StateT[tn].Mild_adunit[Mcells[a->mcell].adunit]--; + //// change current status (so that flags work if function called again for same person). + /// Don't move this outside of this if statement, even though it looks like it can be moved + /// safely. It can't. a->Severity_Current = Severity_Recovered; } else if (a->Severity_Current == Severity_ILI) { StateT[tn].ILI--; StateT[tn].ILI_age[HOST_AGE_GROUP(ai)]--; - if (P.DoAdUnits) StateT[tn].ILI_adunit[Mcells[a->mcell].adunit]--; - //// change current status (so that flags work if function called again for same person). Don't move this outside of this if statement, even though it looks like it can be moved safely. It can't. + if (P.DoAdUnits) + StateT[tn].ILI_adunit[Mcells[a->mcell].adunit]--; + //// change current status (so that flags work if function called again for same person). + /// Don't move this outside of this if statement, even though it looks like it can be moved + /// safely. It can't. a->Severity_Current = Severity_Recovered; } else if (a->Severity_Current == Severity_SARI) { StateT[tn].SARI--; StateT[tn].SARI_age[HOST_AGE_GROUP(ai)]--; - if (P.DoAdUnits) StateT[tn].SARI_adunit[Mcells[a->mcell].adunit]--; - //// change current status (so that flags work if function called again for same person). Don't move this outside of this if statement, even though it looks like it can be moved safely. It can't. + if (P.DoAdUnits) + StateT[tn].SARI_adunit[Mcells[a->mcell].adunit]--; + //// change current status (so that flags work if function called again for same person). + /// Don't move this outside of this if statement, even though it looks like it can be moved + /// safely. It can't. a->Severity_Current = Severity_Recovered; } else if (a->Severity_Current == Severity_RecoveringFromCritical) { StateT[tn].CritRecov--; //// decrement CritRecov, not critical. StateT[tn].CritRecov_age[HOST_AGE_GROUP(ai)]--; - if (P.DoAdUnits) StateT[tn].CritRecov_adunit[Mcells[a->mcell].adunit]--; - //// change current status (so that flags work if function called again for same person). Don't move this outside of this if statement, even though it looks like it can be moved safely. It can't. + if (P.DoAdUnits) + StateT[tn].CritRecov_adunit[Mcells[a->mcell].adunit]--; + //// change current status (so that flags work if function called again for same person). + /// Don't move this outside of this if statement, even though it looks like it can be moved + /// safely. It can't. a->Severity_Current = Severity_Recovered; } } @@ -444,21 +484,23 @@ void DoRecover_FromSeverity(int ai, int tn) void DoIncub(int ai, unsigned short int ts, int tn, int run) { - Person* a; + Person *a; double q; int age; age = HOST_AGE_GROUP(ai); - if (age >= NUM_AGE_GROUPS) age = NUM_AGE_GROUPS - 1; + if (age >= NUM_AGE_GROUPS) + age = NUM_AGE_GROUPS - 1; a = Hosts + ai; if (a->inf == InfStat_Latent) { a->infectiousness = (float)P.AgeInfectiousness[age]; - if (P.InfectiousnessSD > 0) a->infectiousness *= (float) gen_gamma_mt(1 / (P.InfectiousnessSD * P.InfectiousnessSD), 1 / (P.InfectiousnessSD * P.InfectiousnessSD), tn); - q = P.ProportionSymptomatic[age] - * (HOST_TREATED(ai) ? (1 - P.TreatSympDrop) : 1) - * (HOST_VACCED(ai) ? (1 - P.VaccSympDrop) : 1); + if (P.InfectiousnessSD > 0) + a->infectiousness *= (float)gen_gamma_mt(1 / (P.InfectiousnessSD * P.InfectiousnessSD), + 1 / (P.InfectiousnessSD * P.InfectiousnessSD), tn); + q = P.ProportionSymptomatic[age] * (HOST_TREATED(ai) ? (1 - P.TreatSympDrop) : 1) * + (HOST_VACCED(ai) ? (1 - P.VaccSympDrop) : 1); if (ranf_mt(tn) < q) { @@ -468,82 +510,125 @@ void DoIncub(int ai, unsigned short int ts, int tn, int run) else a->inf = InfStat_InfectiousAsymptomaticNotCase; - if (!P.DoSeverity || a->inf == InfStat_InfectiousAsymptomaticNotCase) //// if not doing severity or if person asymptomatic. + if (!P.DoSeverity || + a->inf == InfStat_InfectiousAsymptomaticNotCase) //// if not doing severity or if person + /// asymptomatic. { - if (P.DoInfectiousnessProfile) a->recovery_or_death_time = a->latent_time + (unsigned short int) (P.InfectiousPeriod * P.TimeStepsPerDay); - else a->recovery_or_death_time = a->latent_time + ChooseFromICDF(P.infectious_icdf, P.InfectiousPeriod, tn); + if (P.DoInfectiousnessProfile) + a->recovery_or_death_time = + a->latent_time + (unsigned short int)(P.InfectiousPeriod * P.TimeStepsPerDay); + else + a->recovery_or_death_time = + a->latent_time + ChooseFromICDF(P.infectious_icdf, P.InfectiousPeriod, tn); } else { - int CaseTime = a->latent_time + ((int)(P.LatentToSymptDelay / P.TimeStep)); //// base severity times on CaseTime, not latent time. Otherwise there are edge cases where recovery time is zero days after latent_time and therefore before DoCase called in IncubRecoverySweep (i.e. people can recover before they've become a case!). - - //// choose final disease severity (either mild, ILI, SARI, Critical, not asymptomatic as covered above) by age + int CaseTime = a->latent_time + + ((int)(P.LatentToSymptDelay / + P.TimeStep)); //// base severity times on CaseTime, not latent time. + /// Otherwise there are edge cases where recovery time is + /// zero days after latent_time and therefore before + /// DoCase called in IncubRecoverySweep (i.e. people can + /// recover before they've become a case!). + + //// choose final disease severity (either mild, ILI, SARI, Critical, not asymptomatic as + /// covered above) by age a->Severity_Final = ChooseFinalDiseaseSeverity(age, tn); /// choose outcome recovery or death - if ( ((a->Severity_Final == Severity_Critical) && (ranf_mt(tn) < P.CFR_Critical_ByAge [age])) || - ((a->Severity_Final == Severity_SARI ) && (ranf_mt(tn) < P.CFR_SARI_ByAge [age])) || - ((a->Severity_Final == Severity_ILI ) && (ranf_mt(tn) < P.CFR_ILI_ByAge [age])) ) + if (((a->Severity_Final == Severity_Critical) && (ranf_mt(tn) < P.CFR_Critical_ByAge[age])) || + ((a->Severity_Final == Severity_SARI) && (ranf_mt(tn) < P.CFR_SARI_ByAge[age])) || + ((a->Severity_Final == Severity_ILI) && (ranf_mt(tn) < P.CFR_ILI_ByAge[age]))) a->to_die = 1; //// choose events and event times if (a->Severity_Final == Severity_Mild) - a->recovery_or_death_time = CaseTime + ChooseFromICDF(P.MildToRecovery_icdf, P.Mean_MildToRecovery[age], tn); + a->recovery_or_death_time = + CaseTime + ChooseFromICDF(P.MildToRecovery_icdf, P.Mean_MildToRecovery[age], tn); else if (a->Severity_Final == Severity_Critical) { - a->SARI_time = CaseTime + ChooseFromICDF(P.ILIToSARI_icdf , P.Mean_ILIToSARI[age], tn); - a->Critical_time = a->SARI_time + ChooseFromICDF(P.SARIToCritical_icdf , P.Mean_SARIToCritical[age], tn); + a->SARI_time = CaseTime + ChooseFromICDF(P.ILIToSARI_icdf, P.Mean_ILIToSARI[age], tn); + a->Critical_time = + a->SARI_time + ChooseFromICDF(P.SARIToCritical_icdf, P.Mean_SARIToCritical[age], tn); if (a->to_die) - a->recovery_or_death_time = a->Critical_time + ChooseFromICDF(P.CriticalToDeath_icdf , P.Mean_CriticalToDeath[age], tn); + a->recovery_or_death_time = + a->Critical_time + + ChooseFromICDF(P.CriticalToDeath_icdf, P.Mean_CriticalToDeath[age], tn); else { - a->RecoveringFromCritical_time = a->Critical_time + ChooseFromICDF(P.CriticalToCritRecov_icdf , P.Mean_CriticalToCritRecov[age], tn); - a->recovery_or_death_time = a->RecoveringFromCritical_time + ChooseFromICDF(P.CritRecovToRecov_icdf , P.Mean_CritRecovToRecov[age], tn); + a->RecoveringFromCritical_time = + a->Critical_time + + ChooseFromICDF(P.CriticalToCritRecov_icdf, P.Mean_CriticalToCritRecov[age], tn); + a->recovery_or_death_time = + a->RecoveringFromCritical_time + + ChooseFromICDF(P.CritRecovToRecov_icdf, P.Mean_CritRecovToRecov[age], tn); } } else if (a->Severity_Final == Severity_SARI) { a->SARI_time = CaseTime + ChooseFromICDF(P.ILIToSARI_icdf, P.Mean_ILIToSARI[age], tn); if (a->to_die) - a->recovery_or_death_time = a->SARI_time + ChooseFromICDF(P.SARIToDeath_icdf , P.Mean_SARIToDeath[age], tn); + a->recovery_or_death_time = + a->SARI_time + ChooseFromICDF(P.SARIToDeath_icdf, P.Mean_SARIToDeath[age], tn); else - a->recovery_or_death_time = a->SARI_time + ChooseFromICDF(P.SARIToRecovery_icdf , P.Mean_SARIToRecovery[age], tn); + a->recovery_or_death_time = + a->SARI_time + ChooseFromICDF(P.SARIToRecovery_icdf, P.Mean_SARIToRecovery[age], tn); } else /*i.e. if Severity_Final == Severity_ILI*/ { if (a->to_die) - a->recovery_or_death_time = CaseTime + ChooseFromICDF(P.ILIToDeath_icdf , P.Mean_ILIToDeath[age], tn); + a->recovery_or_death_time = + CaseTime + ChooseFromICDF(P.ILIToDeath_icdf, P.Mean_ILIToDeath[age], tn); else - a->recovery_or_death_time = CaseTime + ChooseFromICDF(P.ILIToRecovery_icdf , P.Mean_ILIToRecovery[age], tn); + a->recovery_or_death_time = + CaseTime + ChooseFromICDF(P.ILIToRecovery_icdf, P.Mean_ILIToRecovery[age], tn); } } - if ((a->inf== InfStat_InfectiousAlmostSymptomatic) && ((P.ControlPropCasesId == 1) || (ranf_mt(tn) < P.ControlPropCasesId))) + if ((a->inf == InfStat_InfectiousAlmostSymptomatic) && + ((P.ControlPropCasesId == 1) || (ranf_mt(tn) < P.ControlPropCasesId))) { Hosts[ai].detected = 1; Hosts[ai].detected_time = ts + (unsigned short int)(P.LatentToSymptDelay * P.TimeStepsPerDay); - - if ((P.DoDigitalContactTracing) && (Hosts[ai].detected_time >= (unsigned short int)(AdUnits[Mcells[Hosts[ai].mcell].adunit].DigitalContactTracingTimeStart * P.TimeStepsPerDay)) && (Hosts[ai].detected_time < (unsigned short int)((AdUnits[Mcells[Hosts[ai].mcell].adunit].DigitalContactTracingTimeStart + P.DigitalContactTracingPolicyDuration)*P.TimeStepsPerDay)) && (Hosts[ai].digitalContactTracingUser)) + if ((P.DoDigitalContactTracing) && + (Hosts[ai].detected_time >= (unsigned short int)(AdUnits[Mcells[Hosts[ai].mcell].adunit] + .DigitalContactTracingTimeStart * + P.TimeStepsPerDay)) && + (Hosts[ai].detected_time < (unsigned short int)((AdUnits[Mcells[Hosts[ai].mcell].adunit] + .DigitalContactTracingTimeStart + + P.DigitalContactTracingPolicyDuration) * + P.TimeStepsPerDay)) && + (Hosts[ai].digitalContactTracingUser)) { - //set dct_trigger_time for index case - if (P.DoDigitalContactTracing) //set dct_trigger_time for index case - if (Hosts[ai].dct_trigger_time == (USHRT_MAX - 1)) //if this hasn't been set in DigitalContactTracingSweep due to detection of contact of contacts, set it here - Hosts[ai].dct_trigger_time = Hosts[ai].detected_time + (unsigned short int) (P.DelayFromIndexCaseDetectionToDCTIsolation * P.TimeStepsPerDay); + // set dct_trigger_time for index case + if (P.DoDigitalContactTracing) // set dct_trigger_time for index case + if (Hosts[ai].dct_trigger_time == + (USHRT_MAX - 1)) // if this hasn't been set in DigitalContactTracingSweep due to + // detection of contact of contacts, set it here + Hosts[ai].dct_trigger_time = + Hosts[ai].detected_time + + (unsigned short int)(P.DelayFromIndexCaseDetectionToDCTIsolation * + P.TimeStepsPerDay); } } //// update pointers - LatentToInfectious(a->pcell); if (Cells[a->pcell].L > 0) { - Cells[a->pcell].susceptible[a->listpos] = Cells[a->pcell].latent[Cells[a->pcell].L]; //// reset pointers. + Cells[a->pcell].susceptible[a->listpos] = + Cells[a->pcell].latent[Cells[a->pcell].L]; //// reset pointers. Hosts[Cells[a->pcell].susceptible[a->listpos]].listpos = a->listpos; - a->listpos = Cells[a->pcell].S + Cells[a->pcell].L; //// change person a's listpos, which will now refer to their position among infectious people, not latent. - Cells[a->pcell].infected[0] = ai; //// this person is now first infectious person in the array. Pointer was moved back one so now that memory address refers to person ai. Alternative would be to move everyone back one which would take longer. + a->listpos = Cells[a->pcell].S + + Cells[a->pcell].L; //// change person a's listpos, which will now refer to their + /// position among infectious people, not latent. + Cells[a->pcell].infected[0] = + ai; //// this person is now first infectious person in the array. Pointer was moved back + /// one so now that memory address refers to person ai. Alternative would be to move + /// everyone back one which would take longer. } } } @@ -552,22 +637,31 @@ void DoDetectedCase(int ai, double t, unsigned short int ts, int tn) { //// Function DoDetectedCase does many things associated with various interventions. //// Enacts Household quarantine, case isolation, place closure. - //// and therefore changes lots of quantities (e.g. quar_comply and isolation_start_time) associated with model macros e.g. HOST_ABSENT / HOST_ISOLATED + //// and therefore changes lots of quantities (e.g. quar_comply and isolation_start_time) + /// associated with model macros e.g. HOST_ABSENT / HOST_ISOLATED int j, k, f, j1, j2, ad; // m, h, ad; - Person* a = Hosts + ai; - - //// Increment triggers (Based on numbers of detected cases) for interventions. Used in TreatSweep function when not doing Global or Admin triggers. And not when doing ICU triggers. - if (Mcells[a->mcell].treat_trig < USHRT_MAX - 1) Mcells[a->mcell].treat_trig++; - if (Mcells[a->mcell].vacc_trig < USHRT_MAX - 1) Mcells[a->mcell].vacc_trig++; - if (Mcells[a->mcell].move_trig < USHRT_MAX - 1) Mcells[a->mcell].move_trig++; - if (Mcells[a->mcell].socdist_trig < USHRT_MAX - 1) Mcells[a->mcell].socdist_trig++; - if (Mcells[a->mcell].keyworkerproph_trig < USHRT_MAX - 1) Mcells[a->mcell].keyworkerproph_trig++; + Person *a = Hosts + ai; + + //// Increment triggers (Based on numbers of detected cases) for interventions. Used in TreatSweep + /// function when not doing Global or Admin triggers. And not when doing ICU triggers. + if (Mcells[a->mcell].treat_trig < USHRT_MAX - 1) + Mcells[a->mcell].treat_trig++; + if (Mcells[a->mcell].vacc_trig < USHRT_MAX - 1) + Mcells[a->mcell].vacc_trig++; + if (Mcells[a->mcell].move_trig < USHRT_MAX - 1) + Mcells[a->mcell].move_trig++; + if (Mcells[a->mcell].socdist_trig < USHRT_MAX - 1) + Mcells[a->mcell].socdist_trig++; + if (Mcells[a->mcell].keyworkerproph_trig < USHRT_MAX - 1) + Mcells[a->mcell].keyworkerproph_trig++; if (!P.AbsenteeismPlaceClosure) { - if ((P.PlaceCloseRoundHousehold)&& (Mcells[a->mcell].place_trig < USHRT_MAX - 1)) Mcells[a->mcell].place_trig++; - if ((t >= P.PlaceCloseTimeStart) && (!P.DoAdminTriggers) && (!((P.DoGlobalTriggers)&&(P.PlaceCloseCellIncThresh<1000000000)))) + if ((P.PlaceCloseRoundHousehold) && (Mcells[a->mcell].place_trig < USHRT_MAX - 1)) + Mcells[a->mcell].place_trig++; + if ((t >= P.PlaceCloseTimeStart) && (!P.DoAdminTriggers) && + (!((P.DoGlobalTriggers) && (P.PlaceCloseCellIncThresh < 1000000000)))) for (j = 0; j < P.PlaceTypeNum; j++) if ((j != P.HotelPlaceType) && (a->PlaceLinks[j] >= 0)) { @@ -576,7 +670,7 @@ void DoDetectedCase(int ai, double t, unsigned short int ts, int tn) { if (Mcells[Places[j][a->PlaceLinks[j]].mcell].place_trig < USHRT_MAX - 1) { -#pragma omp critical (place_trig) +#pragma omp critical(place_trig) Mcells[Places[j][a->PlaceLinks[j]].mcell].place_trig++; } } @@ -589,11 +683,14 @@ void DoDetectedCase(int ai, double t, unsigned short int ts, int tn) DoTreatCase(ai, ts, tn); if (P.DoHouseholds) { - if ((t < P.TreatTimeStart + P.TreatHouseholdsDuration) && ((P.TreatPropCaseHouseholds == 1) || (ranf_mt(tn) < P.TreatPropCaseHouseholds))) + if ((t < P.TreatTimeStart + P.TreatHouseholdsDuration) && + ((P.TreatPropCaseHouseholds == 1) || (ranf_mt(tn) < P.TreatPropCaseHouseholds))) { - j1 = Households[Hosts[ai].hh].FirstPerson; j2 = j1 + Households[Hosts[ai].hh].nh; + j1 = Households[Hosts[ai].hh].FirstPerson; + j2 = j1 + Households[Hosts[ai].hh].nh; for (j = j1; j < j2; j++) - if (!HOST_TO_BE_TREATED(j)) DoProph(j, ts, tn); + if (!HOST_TO_BE_TREATED(j)) + DoProph(j, ts, tn); } } if (P.DoPlaces) @@ -613,8 +710,9 @@ void DoDetectedCase(int ai, double t, unsigned short int ts, int tn) else { f = 0; -#pragma omp critical (starttreat) - if (!Places[j][a->PlaceLinks[j]].treat) f = Places[j][a->PlaceLinks[j]].treat = 1; +#pragma omp critical(starttreat) + if (!Places[j][a->PlaceLinks[j]].treat) + f = Places[j][a->PlaceLinks[j]].treat = 1; if (f) { if ((P.TreatPlaceProbCaseId[j] == 1) || (ranf_mt(tn) < P.TreatPlaceProbCaseId[j])) @@ -634,86 +732,138 @@ void DoDetectedCase(int ai, double t, unsigned short int ts, int tn) // incrementing State.cumV, but by checking here too we can avoid a lot of // wasted effort bool cumV_OK; -#pragma omp critical (state_cumV) +#pragma omp critical(state_cumV) { cumV_OK = State.cumV < P.VaccMaxCourses; } - if (cumV_OK && (t < P.VaccTimeStart + P.VaccHouseholdsDuration) && ((P.VaccPropCaseHouseholds == 1) || (ranf_mt(tn) < P.VaccPropCaseHouseholds))) + if (cumV_OK && (t < P.VaccTimeStart + P.VaccHouseholdsDuration) && + ((P.VaccPropCaseHouseholds == 1) || (ranf_mt(tn) < P.VaccPropCaseHouseholds))) { - j1 = Households[Hosts[ai].hh].FirstPerson; j2 = j1 + Households[Hosts[ai].hh].nh; - for (j = j1; j < j2; j++) DoVacc(j, ts); + j1 = Households[Hosts[ai].hh].FirstPerson; + j2 = j1 + Households[Hosts[ai].hh].nh; + for (j = j1; j < j2; j++) + DoVacc(j, ts); } } - //// Giant compound if statement. If doing delays by admin unit, then window of HQuarantine dependent on admin unit-specific duration. This if statement ensures that this timepoint within window, regardless of how window defined. + //// Giant compound if statement. If doing delays by admin unit, then window of HQuarantine + /// dependent on admin unit-specific duration. This if statement ensures that this timepoint + /// within window, regardless of how window defined. if ((P.DoInterventionDelaysByAdUnit && - (t >= AdUnits[Mcells[a->mcell].adunit].HQuarantineTimeStart && (t < AdUnits[Mcells[a->mcell].adunit].HQuarantineTimeStart + AdUnits[Mcells[a->mcell].adunit].HQuarantineDuration))) || - (t >= AdUnits[Mcells[a->mcell].adunit].HQuarantineTimeStart && (t < AdUnits[Mcells[a->mcell].adunit].HQuarantineTimeStart + P.HQuarantinePolicyDuration)) ) + (t >= AdUnits[Mcells[a->mcell].adunit].HQuarantineTimeStart && + (t < AdUnits[Mcells[a->mcell].adunit].HQuarantineTimeStart + + AdUnits[Mcells[a->mcell].adunit].HQuarantineDuration))) || + (t >= AdUnits[Mcells[a->mcell].adunit].HQuarantineTimeStart && + (t < AdUnits[Mcells[a->mcell].adunit].HQuarantineTimeStart + P.HQuarantinePolicyDuration))) { - j1 = Households[Hosts[ai].hh].FirstPerson; j2 = j1 + Households[Hosts[ai].hh].nh; + j1 = Households[Hosts[ai].hh].FirstPerson; + j2 = j1 + Households[Hosts[ai].hh].nh; if ((!HOST_TO_BE_QUARANTINED(j1)) || (P.DoHQretrigger)) { - Hosts[j1].quar_start_time = ts + ((unsigned short int) (P.TimeStepsPerDay * P.HQuarantineDelay)); - k = (ranf_mt(tn) < P.HQuarantinePropHouseCompliant) ? 1 : 0; //// Is household compliant? True or false - if (k) StateT[tn].cumHQ++; //// if compliant, increment cumulative numbers of households under quarantine. - //// if household not compliant then neither is first person. Otheswise ask whether first person is compliant? + Hosts[j1].quar_start_time = + ts + ((unsigned short int)(P.TimeStepsPerDay * P.HQuarantineDelay)); + k = (ranf_mt(tn) < P.HQuarantinePropHouseCompliant) + ? 1 + : 0; //// Is household compliant? True or false + if (k) + StateT[tn].cumHQ++; //// if compliant, increment cumulative numbers of households under + /// quarantine. + //// if household not compliant then neither is first person. Otheswise ask whether first + /// person is compliant? ///// cycle through remaining household members and repeat the above steps for (j = j1; j < j2; j++) { - if(j>j1) Hosts[j].quar_start_time = Hosts[j1].quar_start_time; - Hosts[j].quar_comply = ((k == 0) ? 0 : ((ranf_mt(tn) < P.HQuarantinePropIndivCompliant) ? 1 : 0)); + if (j > j1) + Hosts[j].quar_start_time = Hosts[j1].quar_start_time; + Hosts[j].quar_comply = + ((k == 0) ? 0 : ((ranf_mt(tn) < P.HQuarantinePropIndivCompliant) ? 1 : 0)); if ((Hosts[j].quar_comply) && (!HOST_ABSENT(j))) { if (HOST_AGE_YEAR(j) >= P.CaseAbsentChildAgeCutoff) { - if (Hosts[j].PlaceLinks[P.PlaceTypeNoAirNum - 1] >= 0) StateT[tn].cumAH++; + if (Hosts[j].PlaceLinks[P.PlaceTypeNoAirNum - 1] >= 0) + StateT[tn].cumAH++; } - else StateT[tn].cumACS++; + else + StateT[tn].cumACS++; } } } } } - //// Giant compound if statement. If doing delays by admin unit, then window of case isolation dependent on admin unit-specific duration. This if statement ensures that this timepoint within window, regardless of how window defined. + //// Giant compound if statement. If doing delays by admin unit, then window of case isolation + /// dependent on admin unit-specific duration. This if statement ensures that this timepoint + /// within window, regardless of how window defined. if ((P.DoInterventionDelaysByAdUnit && - (t >= AdUnits[Mcells[a->mcell].adunit].CaseIsolationTimeStart && (t < AdUnits[Mcells[a->mcell].adunit].CaseIsolationTimeStart + AdUnits[Mcells[a->mcell].adunit].CaseIsolationPolicyDuration))) || - (t >= AdUnits[Mcells[a->mcell].adunit].CaseIsolationTimeStart && (t < AdUnits[Mcells[a->mcell].adunit].CaseIsolationTimeStart + P.CaseIsolationPolicyDuration)) ) + (t >= AdUnits[Mcells[a->mcell].adunit].CaseIsolationTimeStart && + (t < AdUnits[Mcells[a->mcell].adunit].CaseIsolationTimeStart + + AdUnits[Mcells[a->mcell].adunit].CaseIsolationPolicyDuration))) || + (t >= AdUnits[Mcells[a->mcell].adunit].CaseIsolationTimeStart && + (t < + AdUnits[Mcells[a->mcell].adunit].CaseIsolationTimeStart + P.CaseIsolationPolicyDuration))) if ((P.CaseIsolationProp == 1) || (ranf_mt(tn) < P.CaseIsolationProp)) { Hosts[ai].isolation_start_time = ts; //// set isolation start time. if (HOST_ABSENT(ai)) { - if (a->absent_stop_time < ts + P.usCaseAbsenteeismDelay + P.usCaseIsolationDuration) //// ensure that absent_stop_time is at least now + CaseIsolationDuraton + if (a->absent_stop_time < + ts + P.usCaseAbsenteeismDelay + + P.usCaseIsolationDuration) //// ensure that absent_stop_time is at least now + + /// CaseIsolationDuraton a->absent_stop_time = ts + P.usCaseAbsenteeismDelay + P.usCaseIsolationDuration; } - else if (P.DoRealSymptWithdrawal) /* This calculates adult absenteeism from work due to care of isolated children. */ + else if (P.DoRealSymptWithdrawal) /* This calculates adult absenteeism from work due to care + of isolated children. */ { Hosts[ai].absent_start_time = ts + P.usCaseIsolationDelay; - Hosts[ai].absent_stop_time = ts + P.usCaseIsolationDelay + P.usCaseIsolationDuration; + Hosts[ai].absent_stop_time = ts + P.usCaseIsolationDelay + P.usCaseIsolationDuration; if (P.DoPlaces) { - if ((!HOST_QUARANTINED(ai)) && (Hosts[ai].PlaceLinks[P.PlaceTypeNoAirNum - 1] >= 0) && (HOST_AGE_YEAR(ai) >= P.CaseAbsentChildAgeCutoff)) + if ((!HOST_QUARANTINED(ai)) && (Hosts[ai].PlaceLinks[P.PlaceTypeNoAirNum - 1] >= 0) && + (HOST_AGE_YEAR(ai) >= P.CaseAbsentChildAgeCutoff)) StateT[tn].cumAC++; } - if ((P.DoHouseholds) && (P.DoPlaces) && (HOST_AGE_YEAR(ai) < P.CaseAbsentChildAgeCutoff)) //// if host is a child who requires adult to stay at home. + if ((P.DoHouseholds) && (P.DoPlaces) && + (HOST_AGE_YEAR(ai) < P.CaseAbsentChildAgeCutoff)) //// if host is a child who requires + /// adult to stay at home. { - if (!HOST_QUARANTINED(ai)) StateT[tn].cumACS++; - if (Hosts[ai].ProbCare < P.CaseAbsentChildPropAdultCarers) //// if adult needs to stay at home (i.e. if Proportion of children at home for whom one adult also stays at home = 1 or coinflip satisfied.) + if (!HOST_QUARANTINED(ai)) + StateT[tn].cumACS++; + if (Hosts[ai].ProbCare < + P.CaseAbsentChildPropAdultCarers) //// if adult needs to stay at home (i.e. if + /// Proportion of children at home for whom one + /// adult also stays at home = 1 or coinflip + /// satisfied.) { - j1 = Households[Hosts[ai].hh].FirstPerson; j2 = j1 + Households[Hosts[ai].hh].nh; + j1 = Households[Hosts[ai].hh].FirstPerson; + j2 = j1 + Households[Hosts[ai].hh].nh; f = 0; - //// in loop below, f true if any household member a) alive AND b) not a child AND c) has no links to workplace (or is absent from work or quarantined). + //// in loop below, f true if any household member a) alive AND b) not a child AND c) + /// has no links to workplace (or is absent from work or quarantined). for (j = j1; (j < j2) && (!f); j++) - f = ((abs(Hosts[j].inf) != InfStat_Dead) && (HOST_AGE_YEAR(j) >= P.CaseAbsentChildAgeCutoff) && ((Hosts[j].PlaceLinks[P.PlaceTypeNoAirNum - 1] < 0) || (HOST_ABSENT(j)) || (HOST_QUARANTINED(j)))); - - //// so !f true if any household member EITHER: a) dead; b) a child; c) has a link to an office and not currently absent or quarantined. - if (!f) //// so if either a) a household member is dead; b) a household member is a child requiring adult to stay home; c) a household member has links to office. + f = ((abs(Hosts[j].inf) != InfStat_Dead) && + (HOST_AGE_YEAR(j) >= P.CaseAbsentChildAgeCutoff) && + ((Hosts[j].PlaceLinks[P.PlaceTypeNoAirNum - 1] < 0) || (HOST_ABSENT(j)) || + (HOST_QUARANTINED(j)))); + + //// so !f true if any household member EITHER: a) dead; b) a child; c) has a link to an + /// office and not currently absent or quarantined. + if (!f) //// so if either a) a household member is dead; b) a household member is a + /// child requiring adult to stay home; c) a household member has links to + /// office. { - for (j = j1; (j < j2) & (!f); j++) /// loop again, checking whether household members not children needing supervision and are alive. - if ((HOST_AGE_YEAR(j) >= P.CaseAbsentChildAgeCutoff) && (abs(Hosts[j].inf) != InfStat_Dead)) { k = j; f = 1; } - if (f) //// so finally, if at least one member of household is alive and does not need supervision by an adult, amend absent start and stop times + for (j = j1; (j < j2) & (!f); j++) /// loop again, checking whether household members + /// not children needing supervision and are alive. + if ((HOST_AGE_YEAR(j) >= P.CaseAbsentChildAgeCutoff) && + (abs(Hosts[j].inf) != InfStat_Dead)) + { + k = j; + f = 1; + } + if (f) //// so finally, if at least one member of household is alive and does not need + /// supervision by an adult, amend absent start and stop times { Hosts[k].absent_start_time = ts + P.usCaseIsolationDelay; Hosts[k].absent_stop_time = ts + P.usCaseIsolationDelay + P.usCaseIsolationDuration; @@ -725,38 +875,52 @@ void DoDetectedCase(int ai, double t, unsigned short int ts, int tn) } } - //add contacts to digital contact tracing, but only if considering contact tracing, we are within the window of the policy and the detected case is a user - if ((P.DoDigitalContactTracing) && (t >= AdUnits[Mcells[Hosts[ai].mcell].adunit].DigitalContactTracingTimeStart) && (t < AdUnits[Mcells[Hosts[ai].mcell].adunit].DigitalContactTracingTimeStart + P.DigitalContactTracingPolicyDuration) && (Hosts[ai].digitalContactTracingUser)) + // add contacts to digital contact tracing, but only if considering contact tracing, we are within + // the window of the policy and the detected case is a user + if ((P.DoDigitalContactTracing) && + (t >= AdUnits[Mcells[Hosts[ai].mcell].adunit].DigitalContactTracingTimeStart) && + (t < AdUnits[Mcells[Hosts[ai].mcell].adunit].DigitalContactTracingTimeStart + + P.DigitalContactTracingPolicyDuration) && + (Hosts[ai].digitalContactTracingUser)) { // allow for DCT to isolate index cases - if ((P.DCTIsolateIndexCases) && (Hosts[ai].index_case_dct==0))//(Hosts[ai].digitalContactTraced == 0)&& - currently removed this condition as it would mean that someone already under isolation wouldn't have their isolation extended + if ((P.DCTIsolateIndexCases) && + (Hosts[ai].index_case_dct == + 0)) //(Hosts[ai].digitalContactTraced == 0)&& - currently removed this condition as it + // would mean that someone already under isolation wouldn't have their isolation + // extended { ad = Mcells[Hosts[ai].mcell].adunit; - //if (AdUnits[j].ndct < AdUnits[j].n) - if(StateT[tn].ndct_queue[ad] < AdUnits[ad].n) + // if (AdUnits[j].ndct < AdUnits[j].n) + if (StateT[tn].ndct_queue[ad] < AdUnits[ad].n) { - //if we are isolating an index case, we set their infector as -1 in order to get the timings consistent. - StateT[tn].dct_queue[ad][StateT[tn].ndct_queue[ad]++] = { ai,-1,ts }; + // if we are isolating an index case, we set their infector as -1 in order to get the + // timings consistent. + StateT[tn].dct_queue[ad][StateT[tn].ndct_queue[ad]++] = {ai, -1, ts}; } else { - fprintf(stderr, "No more space in queue! AdUnit: %i, ndct=%i, max queue length: %i\n", ad, AdUnits[j].ndct, AdUnits[ad].n); + fprintf(stderr, "No more space in queue! AdUnit: %i, ndct=%i, max queue length: %i\n", ad, + AdUnits[j].ndct, AdUnits[ad].n); fprintf(stderr, "Error!\n"); } } - //currently commenting this out as household members will likely be picked up by household quarantine. - //can add back in if needed, but would need to re-add a couple more local variables. + // currently commenting this out as household members will likely be picked up by household + // quarantine. can add back in if needed, but would need to re-add a couple more local + // variables. - //if(P.IncludeHouseholdDigitalContactTracing) + // if(P.IncludeHouseholdDigitalContactTracing) //{ - // //Then we want to find all their household and place group contacts to add to the contact tracing queue + // //Then we want to find all their household and place group contacts to add to the contact + // tracing queue // //Start with household contacts // j1 = Households[Hosts[ai].hh].FirstPerson; j2 = j1 + Households[Hosts[ai].hh].nh; // for (j = j1; j < j2; j++) // { - // //if host is dead or the detected case, no need to add them to the list. They also need to be a user themselves - // if ((abs(Hosts[j].inf) != 5) && (j != ai) && (Hosts[j].digitalContactTracingUser) && (ranf_mt(tn)= NUM_AGE_GROUPS) age = NUM_AGE_GROUPS - 1; + if (age >= NUM_AGE_GROUPS) + age = NUM_AGE_GROUPS - 1; a = Hosts + ai; - if (a->inf == InfStat_InfectiousAlmostSymptomatic) //// if person latent/asymptomatically infected, but infectious + if (a->inf == InfStat_InfectiousAlmostSymptomatic) //// if person latent/asymptomatically + /// infected, but infectious { a->inf = InfStat_Case; //// make person symptomatic and infectious (i.e. a case) if (HOST_ABSENT(ai)) @@ -830,13 +998,15 @@ void DoCase(int ai, double t, unsigned short int ts, int tn) //// makes an infec if (a->absent_stop_time < ts + P.usCaseAbsenteeismDelay + P.usCaseAbsenteeismDuration) a->absent_stop_time = ts + P.usCaseAbsenteeismDelay + P.usCaseAbsenteeismDuration; } - else if((P.DoRealSymptWithdrawal)&&(P.DoPlaces)) + else if ((P.DoRealSymptWithdrawal) && (P.DoPlaces)) { a->absent_start_time = USHRT_MAX - 1; for (j = 0; j < P.PlaceTypeNum; j++) - if ((a->PlaceLinks[j] >= 0) && (j != P.HotelPlaceType) && (!HOST_ABSENT(ai)) && (P.SymptPlaceTypeWithdrawalProp[j] > 0)) + if ((a->PlaceLinks[j] >= 0) && (j != P.HotelPlaceType) && (!HOST_ABSENT(ai)) && + (P.SymptPlaceTypeWithdrawalProp[j] > 0)) { - if ((P.SymptPlaceTypeWithdrawalProp[j] == 1) || (ranf_mt(tn) < P.SymptPlaceTypeWithdrawalProp[j])) + if ((P.SymptPlaceTypeWithdrawalProp[j] == 1) || + (ranf_mt(tn) < P.SymptPlaceTypeWithdrawalProp[j])) { a->absent_start_time = ts + P.usCaseAbsenteeismDelay; a->absent_stop_time = ts + P.usCaseAbsenteeismDelay + P.usCaseAbsenteeismDuration; @@ -851,28 +1021,41 @@ void DoCase(int ai, double t, unsigned short int ts, int tn) //// makes an infec j = P.PlaceTypeNum; } } - if ((!HOST_QUARANTINED(ai)) && (Hosts[ai].PlaceLinks[P.PlaceTypeNoAirNum - 1] >= 0) && (HOST_AGE_YEAR(ai) >= P.CaseAbsentChildAgeCutoff)) + if ((!HOST_QUARANTINED(ai)) && (Hosts[ai].PlaceLinks[P.PlaceTypeNoAirNum - 1] >= 0) && + (HOST_AGE_YEAR(ai) >= P.CaseAbsentChildAgeCutoff)) StateT[tn].cumAC++; - /* This calculates adult absenteeism from work due to care of sick children. Note, children not at school not counted (really this should - be fixed in population setup by having adult at home all the time for such kids. */ + /* This calculates adult absenteeism from work due to care of sick children. Note, + children not at school not counted (really this should be fixed in population setup by + having adult at home all the time for such kids. */ if ((P.DoHouseholds) && (HOST_AGE_YEAR(ai) < P.CaseAbsentChildAgeCutoff)) { - if (!HOST_QUARANTINED(ai)) StateT[tn].cumACS++; + if (!HOST_QUARANTINED(ai)) + StateT[tn].cumACS++; if (Hosts[ai].ProbCare < P.CaseAbsentChildPropAdultCarers) { - j1 = Households[Hosts[ai].hh].FirstPerson; j2 = j1 + Households[Hosts[ai].hh].nh; + j1 = Households[Hosts[ai].hh].FirstPerson; + j2 = j1 + Households[Hosts[ai].hh].nh; f = 0; for (int j3 = j1; (j3 < j2) && (!f); j3++) - f = ((abs(Hosts[j3].inf) != InfStat_Dead) && (HOST_AGE_YEAR(j3) >= P.CaseAbsentChildAgeCutoff) - && ((Hosts[j3].PlaceLinks[P.PlaceTypeNoAirNum - 1] < 0)|| (HOST_ABSENT(j3)) || (HOST_QUARANTINED(j3)))); + f = ((abs(Hosts[j3].inf) != InfStat_Dead) && + (HOST_AGE_YEAR(j3) >= P.CaseAbsentChildAgeCutoff) && + ((Hosts[j3].PlaceLinks[P.PlaceTypeNoAirNum - 1] < 0) || (HOST_ABSENT(j3)) || + (HOST_QUARANTINED(j3)))); if (!f) { for (int j3 = j1; (j3 < j2) && (!f); j3++) - if ((HOST_AGE_YEAR(j3) >= P.CaseAbsentChildAgeCutoff) && (abs(Hosts[j3].inf) != InfStat_Dead)) { k = j3; f = 1; } + if ((HOST_AGE_YEAR(j3) >= P.CaseAbsentChildAgeCutoff) && + (abs(Hosts[j3].inf) != InfStat_Dead)) + { + k = j3; + f = 1; + } if (f) { - if (!HOST_ABSENT(k)) Hosts[k].absent_start_time = ts + P.usCaseIsolationDelay; - Hosts[k].absent_stop_time = ts + P.usCaseIsolationDelay + P.usCaseIsolationDuration; + if (!HOST_ABSENT(k)) + Hosts[k].absent_start_time = ts + P.usCaseIsolationDelay; + Hosts[k].absent_stop_time = + ts + P.usCaseIsolationDelay + P.usCaseIsolationDuration; StateT[tn].cumAA++; } } @@ -882,41 +1065,46 @@ void DoCase(int ai, double t, unsigned short int ts, int tn) //// makes an infec } // End of if, and for(j) } - //added some case detection code here: ggilani - 03/02/15 + // added some case detection code here: ggilani - 03/02/15 if (Hosts[ai].detected == 1) - //if ((P.ControlPropCasesId == 1) || (ranf_mt(tn) < P.ControlPropCasesId)) + // if ((P.ControlPropCasesId == 1) || (ranf_mt(tn) < P.ControlPropCasesId)) { StateT[tn].cumDC++; StateT[tn].cumDC_adunit[Mcells[a->mcell].adunit]++; DoDetectedCase(ai, t, ts, tn); - //add detection time - + // add detection time } - if (HOST_TREATED(ai)) Cells[Hosts[ai].pcell].cumTC++; + if (HOST_TREATED(ai)) + Cells[Hosts[ai].pcell].cumTC++; StateT[tn].cumC++; StateT[tn].cumCa[age]++; - StateT[tn].cumC_country[Mcells[Hosts[ai].mcell].country]++; //add to cumulative count of cases in that country: ggilani - 12/11/14 + StateT[tn] + .cumC_country[Mcells[Hosts[ai].mcell].country]++; // add to cumulative count of cases in + // that country: ggilani - 12/11/14 StateT[tn].cumC_keyworker[a->keyworker]++; - if (P.DoSeverity) { if (a->Severity_Final == Severity_Mild) DoMild(ai, tn); else - DoILI(ai, tn); //// symptomatic cases either mild or ILI at symptom onset. SARI and Critical cases still onset with ILI. + DoILI(ai, tn); //// symptomatic cases either mild or ILI at symptom onset. SARI and Critical + /// cases still onset with ILI. } - if (P.DoAdUnits) StateT[tn].cumC_adunit[Mcells[a->mcell].adunit]++; + if (P.DoAdUnits) + StateT[tn].cumC_adunit[Mcells[a->mcell].adunit]++; } } void DoFalseCase(int ai, double t, unsigned short int ts, int tn) { - /* Arguably adult absenteeism to take care of sick kids could be included here, but then output absenteeism would not be 'excess' absenteeism */ + /* Arguably adult absenteeism to take care of sick kids could be included here, but then output + * absenteeism would not be 'excess' absenteeism */ if ((P.ControlPropCasesId == 1) || (ranf_mt(tn) < P.ControlPropCasesId)) { - if ((!P.DoEarlyCaseDiagnosis) || (State.cumDC >= P.CaseOrDeathThresholdBeforeAlert)) StateT[tn].cumDC++; + if ((!P.DoEarlyCaseDiagnosis) || (State.cumDC >= P.CaseOrDeathThresholdBeforeAlert)) + StateT[tn].cumDC++; DoDetectedCase(ai, t, ts, tn); } StateT[tn].cumFC++; @@ -925,7 +1113,7 @@ void DoFalseCase(int ai, double t, unsigned short int ts, int tn) void DoRecover(int ai, int tn, int run) { int i, j; - Person* a; + Person *a; a = Hosts + ai; if (a->inf == InfStat_InfectiousAsymptomaticNotCase || a->inf == InfStat_Case) @@ -946,7 +1134,8 @@ void DoRecover(int ai, int tn, int run) if (P.OutputBitmap) { - if ((P.OutputBitmapDetected == 0) || ((P.OutputBitmapDetected == 1) && (Hosts[ai].detected == 1))) + if ((P.OutputBitmapDetected == 0) || + ((P.OutputBitmapDetected == 1) && (Hosts[ai].detected == 1))) { Vector2 pixel((Households[a->hh].loc * P.scale) - P.bmin); if (P.b.contains(pixel)) @@ -963,14 +1152,14 @@ void DoRecover(int ai, int tn, int run) } } } - //else - //fprintf(stderr, "\n ### %i %i \n", ai, a->inf); + // else + // fprintf(stderr, "\n ### %i %i \n", ai, a->inf); } void DoDeath(int ai, int tn, int run) { int i; - Person* a = Hosts + ai; + Person *a = Hosts + ai; if ((a->inf == InfStat_InfectiousAsymptomaticNotCase || a->inf == InfStat_Case)) { @@ -991,11 +1180,13 @@ void DoDeath(int ai, int tn, int run) if (P.DoAdUnits) { StateT[tn].cumD_adunit[Mcells[a->mcell].adunit]++; - if (P.OutputAdUnitAge) StateT[tn].prevInf_age_adunit[HOST_AGE_GROUP(ai)][Mcells[a->mcell].adunit]--; + if (P.OutputAdUnitAge) + StateT[tn].prevInf_age_adunit[HOST_AGE_GROUP(ai)][Mcells[a->mcell].adunit]--; } if (P.OutputBitmap) { - if ((P.OutputBitmapDetected == 0) || ((P.OutputBitmapDetected == 1) && (Hosts[ai].detected == 1))) + if ((P.OutputBitmapDetected == 0) || + ((P.OutputBitmapDetected == 1) && (Hosts[ai].detected == 1))) { Vector2 pixel((Households[a->hh].loc * P.scale) - P.bmin); if (P.b.contains(pixel)) @@ -1022,14 +1213,20 @@ void DoTreatCase(int ai, unsigned short int ts, int tn) if (!HOST_TO_BE_TREATED(ai)) #endif { - Hosts[ai].treat_start_time = ts + ((unsigned short int) (P.TimeStepsPerDay * P.TreatDelayMean)); - Hosts[ai].treat_stop_time = ts + ((unsigned short int) (P.TimeStepsPerDay * (P.TreatDelayMean + P.TreatCaseCourseLength))); + Hosts[ai].treat_start_time = + ts + ((unsigned short int)(P.TimeStepsPerDay * P.TreatDelayMean)); + Hosts[ai].treat_stop_time = + ts + + ((unsigned short int)(P.TimeStepsPerDay * (P.TreatDelayMean + P.TreatCaseCourseLength))); StateT[tn].cumT++; - if ((abs(Hosts[ai].inf) > InfStat_Susceptible) && (Hosts[ai].inf != InfStat_Dead_WasAsymp)) Cells[Hosts[ai].pcell].cumTC++; + if ((abs(Hosts[ai].inf) > InfStat_Susceptible) && (Hosts[ai].inf != InfStat_Dead_WasAsymp)) + Cells[Hosts[ai].pcell].cumTC++; StateT[tn].cumT_keyworker[Hosts[ai].keyworker]++; - if ((++Hosts[ai].num_treats) < 2) StateT[tn].cumUT++; + if ((++Hosts[ai].num_treats) < 2) + StateT[tn].cumUT++; Cells[Hosts[ai].pcell].tot_treat++; - if (P.DoAdUnits) StateT[tn].cumT_adunit[Mcells[Hosts[ai].mcell].adunit]++; + if (P.DoAdUnits) + StateT[tn].cumT_adunit[Mcells[Hosts[ai].mcell].adunit]++; if (P.OutputBitmap) { Vector2 pixel((Households[Hosts[ai].hh].loc * P.scale) - P.bmin); @@ -1049,17 +1246,23 @@ void DoTreatCase(int ai, unsigned short int ts, int tn) void DoProph(int ai, unsigned short int ts, int tn) { - //// almost identical to DoProphNoDelay, except unsurprisingly this function includes delay between timestep and start of treatment. Also increments StateT[tn].cumT_keyworker by 1 every time. + //// almost identical to DoProphNoDelay, except unsurprisingly this function includes delay + /// between timestep and start of treatment. Also increments StateT[tn].cumT_keyworker by 1 every + /// time. if (State.cumT < P.TreatMaxCourses) { - Hosts[ai].treat_start_time = ts + ((unsigned short int) (P.TimeStepsPerDay * P.TreatDelayMean)); - Hosts[ai].treat_stop_time = ts + ((unsigned short int) (P.TimeStepsPerDay * (P.TreatDelayMean + P.TreatProphCourseLength))); + Hosts[ai].treat_start_time = ts + ((unsigned short int)(P.TimeStepsPerDay * P.TreatDelayMean)); + Hosts[ai].treat_stop_time = + ts + + ((unsigned short int)(P.TimeStepsPerDay * (P.TreatDelayMean + P.TreatProphCourseLength))); StateT[tn].cumT++; StateT[tn].cumT_keyworker[Hosts[ai].keyworker]++; - if ((++Hosts[ai].num_treats) < 2) StateT[tn].cumUT++; - if (P.DoAdUnits) StateT[tn].cumT_adunit[Mcells[Hosts[ai].mcell].adunit]++; -#pragma omp critical (tot_treat) + if ((++Hosts[ai].num_treats) < 2) + StateT[tn].cumUT++; + if (P.DoAdUnits) + StateT[tn].cumT_adunit[Mcells[Hosts[ai].mcell].adunit]++; +#pragma omp critical(tot_treat) Cells[Hosts[ai].pcell].tot_treat++; if (P.OutputBitmap) { @@ -1082,12 +1285,15 @@ void DoProphNoDelay(int ai, unsigned short int ts, int tn, int nc) if (State.cumT < P.TreatMaxCourses) { Hosts[ai].treat_start_time = ts; - Hosts[ai].treat_stop_time = ts + ((unsigned short int) (P.TimeStepsPerDay * P.TreatProphCourseLength * nc)); + Hosts[ai].treat_stop_time = + ts + ((unsigned short int)(P.TimeStepsPerDay * P.TreatProphCourseLength * nc)); StateT[tn].cumT += nc; StateT[tn].cumT_keyworker[Hosts[ai].keyworker] += nc; - if ((++Hosts[ai].num_treats) < 2) StateT[tn].cumUT++; - if (P.DoAdUnits) StateT[tn].cumT_adunit[Mcells[Hosts[ai].mcell].adunit] += nc; -#pragma omp critical (tot_treat) + if ((++Hosts[ai].num_treats) < 2) + StateT[tn].cumUT++; + if (P.DoAdUnits) + StateT[tn].cumT_adunit[Mcells[Hosts[ai].mcell].adunit] += nc; +#pragma omp critical(tot_treat) Cells[Hosts[ai].pcell].tot_treat++; if (P.OutputBitmap) { @@ -1107,9 +1313,11 @@ void DoProphNoDelay(int ai, unsigned short int ts, int tn, int nc) void DoPlaceClose(int i, int j, unsigned short int ts, int tn, int DoAnyway) { - //// DoPlaceClose function called in TreatSweep (with arg DoAnyway = 1) and DoDetectedCase (with arg DoAnyway = 0). - //// Basic pupose of this function is to change Places[i][j].close_start_time and Places[i][j].close_end_time, so that macro PLACE_CLOSED will return true. - //// This will then scale peoples household, place, and spatial infectiousness and susceptibilities in function InfectSweep (but not in functions ini CalcInfSusc.cpp) + //// DoPlaceClose function called in TreatSweep (with arg DoAnyway = 1) and DoDetectedCase (with + /// arg DoAnyway = 0). / Basic pupose of this function is to change Places[i][j].close_start_time + /// and Places[i][j].close_end_time, so that macro PLACE_CLOSED will return true. / This will then + /// scale peoples household, place, and spatial infectiousness and susceptibilities in function + /// InfectSweep (but not in functions ini CalcInfSusc.cpp) int k, ai, j1, j2, l, f, f2; unsigned short trig; @@ -1123,20 +1331,24 @@ void DoPlaceClose(int i, int j, unsigned short int ts, int tn, int DoAnyway) */ t_new = (unsigned short)(((double)ts) / P.TimeStepsPerDay); trig = 0; - t_start = ts + ((unsigned short int) (P.TimeStepsPerDay * P.PlaceCloseDelayMean)); + t_start = ts + ((unsigned short int)(P.TimeStepsPerDay * P.PlaceCloseDelayMean)); if (P.DoInterventionDelaysByAdUnit) { k = Mcells[Places[i][j].mcell].adunit; - t_stop = ts + ((unsigned short int) (P.TimeStepsPerDay * (P.PlaceCloseDelayMean + AdUnits[k].PlaceCloseDuration))); + t_stop = ts + ((unsigned short int)(P.TimeStepsPerDay * + (P.PlaceCloseDelayMean + AdUnits[k].PlaceCloseDuration))); } else { - t_stop = ts + ((unsigned short int) (P.TimeStepsPerDay * (P.PlaceCloseDelayMean + P.PlaceCloseDuration))); + t_stop = + ts + + ((unsigned short int)(P.TimeStepsPerDay * (P.PlaceCloseDelayMean + P.PlaceCloseDuration))); } -#pragma omp critical (closeplace) +#pragma omp critical(closeplace) { //// close_start_time initialized to USHRT_MAX - 1. - //// close_end_time initialized to zero in InitModel (so will pass this check on at least first call of this function). + //// close_end_time initialized to zero in InitModel (so will pass this check on at least first + /// call of this function). if (Places[i][j].close_end_time < t_stop) { @@ -1147,33 +1359,42 @@ void DoPlaceClose(int i, int j, unsigned short int ts, int tn, int DoAnyway) { t_old = Places[i][j].AbsentLastUpdateTime; if (t_new >= t_old + P.MaxAbsentTime) - for (l = 0; l < P.MaxAbsentTime; l++) Places[i][j].Absent[l] = 0; + for (l = 0; l < P.MaxAbsentTime; l++) + Places[i][j].Absent[l] = 0; else - for (l = t_old; l < t_new; l++) Places[i][j].Absent[l % P.MaxAbsentTime] = 0; - for (l = t_new; l < t_new + P.usCaseAbsenteeismDuration / P.TimeStepsPerDay; l++) Places[i][j].Absent[l % P.MaxAbsentTime]++; + for (l = t_old; l < t_new; l++) + Places[i][j].Absent[l % P.MaxAbsentTime] = 0; + for (l = t_new; l < t_new + P.usCaseAbsenteeismDuration / P.TimeStepsPerDay; l++) + Places[i][j].Absent[l % P.MaxAbsentTime]++; trig = Places[i][j].Absent[t_new % P.MaxAbsentTime]; Places[i][j].AbsentLastUpdateTime = t_new; - if ((P.PlaceCloseByAdminUnit) && (P.PlaceCloseAdunitPlaceTypes[i] > 0) - && (((double)trig) / ((double)Places[i][j].n) > P.PlaceCloseCasePropThresh)) + if ((P.PlaceCloseByAdminUnit) && (P.PlaceCloseAdunitPlaceTypes[i] > 0) && + (((double)trig) / ((double)Places[i][j].n) > P.PlaceCloseCasePropThresh)) { - //fprintf(stderr,"** %i %i %i %i %lg ## ",i,j,(int) Places[i][j].control_trig, (int) Places[i][j].n,P.PlaceCloseCasePropThresh); + // fprintf(stderr,"** %i %i %i %i %lg ## ",i,j,(int) Places[i][j].control_trig, (int) + // Places[i][j].n,P.PlaceCloseCasePropThresh); k = Mcells[Places[i][j].mcell].adunit; - if (AdUnits[k].place_close_trig < USHRT_MAX - 1) AdUnits[k].place_close_trig++; + if (AdUnits[k].place_close_trig < USHRT_MAX - 1) + AdUnits[k].place_close_trig++; } } else { trig = Places[i][j].control_trig; - if ((P.PlaceCloseByAdminUnit) && (P.PlaceCloseAdunitPlaceTypes[i] > 0) - && (((double)Places[i][j].control_trig) / ((double)Places[i][j].n) > P.PlaceCloseCasePropThresh)) + if ((P.PlaceCloseByAdminUnit) && (P.PlaceCloseAdunitPlaceTypes[i] > 0) && + (((double)Places[i][j].control_trig) / ((double)Places[i][j].n) > + P.PlaceCloseCasePropThresh)) { - //fprintf(stderr,"** %i %i %i %i %lg ## ",i,j,(int) Places[i][j].control_trig, (int) Places[i][j].n,P.PlaceCloseCasePropThresh); + // fprintf(stderr,"** %i %i %i %i %lg ## ",i,j,(int) Places[i][j].control_trig, (int) + // Places[i][j].n,P.PlaceCloseCasePropThresh); k = Mcells[Places[i][j].mcell].adunit; - if (AdUnits[k].place_close_trig < USHRT_MAX - 1) AdUnits[k].place_close_trig++; + if (AdUnits[k].place_close_trig < USHRT_MAX - 1) + AdUnits[k].place_close_trig++; } } } - if (Places[i][j].control_trig < USHRT_MAX - 1) //// control_trig initialized to zero so this check will pass at least once + if (Places[i][j].control_trig < + USHRT_MAX - 1) //// control_trig initialized to zero so this check will pass at least once { if (P.PlaceCloseFracIncTrig > 0) k = (((double)trig) / ((double)Places[i][j].n) > P.PlaceCloseFracIncTrig); @@ -1182,20 +1403,27 @@ void DoPlaceClose(int i, int j, unsigned short int ts, int tn, int DoAnyway) if (((!P.PlaceCloseByAdminUnit) && (k)) || (DoAnyway)) { if (P.DoPlaceCloseOnceOnly) - Places[i][j].control_trig = USHRT_MAX - 1; //// Places only close once, and so this code block would not be entered again. + Places[i][j].control_trig = + USHRT_MAX - + 1; //// Places only close once, and so this code block would not be entered again. else - Places[i][j].control_trig = 0; //// otherwise reset the trigger. + Places[i][j].control_trig = 0; //// otherwise reset the trigger. //// set close_start_time and close_end_time - if (Places[i][j].ProbClose >= P.PlaceCloseEffect[i]) //// if proportion of places of type i remaining open is 0 or if place is closed with prob 1 - PlaceCloseEffect[i]... + if (Places[i][j].ProbClose >= + P.PlaceCloseEffect[i]) //// if proportion of places of type i remaining open is 0 or + /// if place is closed with prob 1 - PlaceCloseEffect[i]... { - if (Places[i][j].close_start_time > t_start) Places[i][j].close_start_time = t_start; + if (Places[i][j].close_start_time > t_start) + Places[i][j].close_start_time = t_start; Places[i][j].close_end_time = t_stop; f2 = 1; /// /set flag to true so next part of function used. } else - Places[i][j].close_start_time = Places[i][j].close_end_time = t_stop; //// ... otherwise set start and end of closure to be the same, which will cause macro PLACE_CLOSED to always return false. + Places[i][j].close_start_time = Places[i][j].close_end_time = + t_stop; //// ... otherwise set start and end of closure to be the same, which will + /// cause macro PLACE_CLOSED to always return false. } } } @@ -1207,27 +1435,42 @@ void DoPlaceClose(int i, int j, unsigned short int ts, int tn, int DoAnyway) for (k = 0; k < Places[i][j].n; k++) //// loop over all people in place. { ai = Places[i][j].members[k]; - if (((P.PlaceClosePropAttending[i] == 0) || (Hosts[ai].ProbAbsent >= P.PlaceClosePropAttending[i]))) + if (((P.PlaceClosePropAttending[i] == 0) || + (Hosts[ai].ProbAbsent >= P.PlaceClosePropAttending[i]))) { - if ((!HOST_ABSENT(ai)) && (!HOST_QUARANTINED(ai)) && (HOST_AGE_YEAR(ai) < P.CaseAbsentChildAgeCutoff)) //// if person is a child and neither absent nor quarantined + if ((!HOST_ABSENT(ai)) && (!HOST_QUARANTINED(ai)) && + (HOST_AGE_YEAR(ai) < P.CaseAbsentChildAgeCutoff)) //// if person is a child and + /// neither absent nor quarantined { StateT[tn].cumAPCS++; - if (Hosts[ai].ProbCare < P.CaseAbsentChildPropAdultCarers) //// if child needs adult supervision + if (Hosts[ai].ProbCare < + P.CaseAbsentChildPropAdultCarers) //// if child needs adult supervision { - j1 = Households[Hosts[ai].hh].FirstPerson; j2 = j1 + Households[Hosts[ai].hh].nh; - if ((j1 < 0) || (j2 > P.PopSize)) fprintf(stderr, "++ %i %i %i (%i %i %i)## ", ai, j1, j2, i, j, k); + j1 = Households[Hosts[ai].hh].FirstPerson; + j2 = j1 + Households[Hosts[ai].hh].nh; + if ((j1 < 0) || (j2 > P.PopSize)) + fprintf(stderr, "++ %i %i %i (%i %i %i)## ", ai, j1, j2, i, j, k); f = 0; - //// in loop below, f true if any household member a) alive AND b) not a child AND c) has no links to workplace (or is absent from work or quarantined). + //// in loop below, f true if any household member a) alive AND b) not a child AND c) + /// has no links to workplace (or is absent from work or quarantined). for (l = j1; (l < j2) && (!f); l++) - f = ((abs(Hosts[l].inf) != InfStat_Dead) && (HOST_AGE_YEAR(l) >= P.CaseAbsentChildAgeCutoff) && ((Hosts[l].PlaceLinks[P.PlaceTypeNoAirNum - 1] < 0) || (HOST_QUARANTINED(l)))); - if (!f) //// so !f true if there's no living adult household member who is not quarantined already or isn't a home-worker. + f = ((abs(Hosts[l].inf) != InfStat_Dead) && + (HOST_AGE_YEAR(l) >= P.CaseAbsentChildAgeCutoff) && + ((Hosts[l].PlaceLinks[P.PlaceTypeNoAirNum - 1] < 0) || (HOST_QUARANTINED(l)))); + if (!f) //// so !f true if there's no living adult household member who is not + /// quarantined already or isn't a home-worker. { - for (l = j1; (l < j2) && (!f); l++) //// loop over all household members of child this place: find the adults and ensure they're not dead... - if ((HOST_AGE_YEAR(l) >= P.CaseAbsentChildAgeCutoff) && (abs(Hosts[l].inf) != InfStat_Dead)) + for (l = j1; (l < j2) && (!f); + l++) //// loop over all household members of child this place: find the adults + /// and ensure they're not dead... + if ((HOST_AGE_YEAR(l) >= P.CaseAbsentChildAgeCutoff) && + (abs(Hosts[l].inf) != InfStat_Dead)) { - if (Hosts[l].absent_start_time > t_start) Hosts[l].absent_start_time = t_start; - if (Hosts[l].absent_stop_time < t_stop) Hosts[l].absent_stop_time = t_stop; + if (Hosts[l].absent_start_time > t_start) + Hosts[l].absent_start_time = t_start; + if (Hosts[l].absent_stop_time < t_stop) + Hosts[l].absent_stop_time = t_stop; StateT[tn].cumAPA++; f = 1; } @@ -1236,22 +1479,26 @@ void DoPlaceClose(int i, int j, unsigned short int ts, int tn, int DoAnyway) } //#pragma omp critical (closeplace3) { - ///// finally amend absent start and stop times if they contradict place start and stop times. - if (Hosts[ai].absent_start_time > t_start) Hosts[ai].absent_start_time = t_start; - if (Hosts[ai].absent_stop_time < t_stop) Hosts[ai].absent_stop_time = t_stop; + ///// finally amend absent start and stop times if they contradict place start and stop + /// times. + if (Hosts[ai].absent_start_time > t_start) + Hosts[ai].absent_start_time = t_start; + if (Hosts[ai].absent_stop_time < t_stop) + Hosts[ai].absent_stop_time = t_stop; } - if ((HOST_AGE_YEAR(ai) >= P.CaseAbsentChildAgeCutoff) && (Hosts[ai].PlaceLinks[P.PlaceTypeNoAirNum - 1] >= 0)) StateT[tn].cumAPC++; + if ((HOST_AGE_YEAR(ai) >= P.CaseAbsentChildAgeCutoff) && + (Hosts[ai].PlaceLinks[P.PlaceTypeNoAirNum - 1] >= 0)) + StateT[tn].cumAPC++; } } } } - void DoPlaceOpen(int i, int j, unsigned short int ts, int tn) { int k, ai, j1, j2, l, f; -#pragma omp critical (openplace) +#pragma omp critical(openplace) { if (ts < Places[i][j].close_end_time) { @@ -1259,21 +1506,28 @@ void DoPlaceOpen(int i, int j, unsigned short int ts, int tn) for (k = 0; k < Places[i][j].n; k++) { ai = Places[i][j].members[k]; - if (Hosts[ai].absent_stop_time == Places[i][j].close_end_time) Hosts[ai].absent_stop_time = ts; - if (Hosts[ai].ProbCare < P.CaseAbsentChildPropAdultCarers) //// if child needs adult supervision + if (Hosts[ai].absent_stop_time == Places[i][j].close_end_time) + Hosts[ai].absent_stop_time = ts; + if (Hosts[ai].ProbCare < + P.CaseAbsentChildPropAdultCarers) //// if child needs adult supervision { if ((HOST_AGE_YEAR(ai) < P.CaseAbsentChildAgeCutoff) && (!HOST_QUARANTINED(ai))) { - j1 = Households[Hosts[ai].hh].FirstPerson; j2 = j1 + Households[Hosts[ai].hh].nh; + j1 = Households[Hosts[ai].hh].FirstPerson; + j2 = j1 + Households[Hosts[ai].hh].nh; f = 0; for (l = j1; (l < j2) && (!f); l++) - f = ((abs(Hosts[l].inf) != InfStat_Dead) && (HOST_AGE_YEAR(l) >= P.CaseAbsentChildAgeCutoff) && ((Hosts[l].PlaceLinks[P.PlaceTypeNoAirNum - 1] < 0) || (HOST_QUARANTINED(l)))); + f = ((abs(Hosts[l].inf) != InfStat_Dead) && + (HOST_AGE_YEAR(l) >= P.CaseAbsentChildAgeCutoff) && + ((Hosts[l].PlaceLinks[P.PlaceTypeNoAirNum - 1] < 0) || (HOST_QUARANTINED(l)))); if (!f) { for (l = j1; (l < j2) && (!f); l++) - if ((HOST_AGE_YEAR(l) >= P.CaseAbsentChildAgeCutoff) && (abs(Hosts[l].inf) != InfStat_Dead) && (HOST_ABSENT(l))) + if ((HOST_AGE_YEAR(l) >= P.CaseAbsentChildAgeCutoff) && + (abs(Hosts[l].inf) != InfStat_Dead) && (HOST_ABSENT(l))) { - if (Hosts[l].absent_stop_time == Places[i][j].close_end_time) Hosts[l].absent_stop_time = ts; + if (Hosts[l].absent_stop_time == Places[i][j].close_end_time) + Hosts[l].absent_stop_time = ts; } } } @@ -1288,9 +1542,10 @@ void DoVacc(int ai, unsigned short int ts) { bool cumV_OK = false; - if ((HOST_TO_BE_VACCED(ai)) || (Hosts[ai].inf < InfStat_InfectiousAlmostSymptomatic) || (Hosts[ai].inf >= InfStat_Dead_WasAsymp)) + if ((HOST_TO_BE_VACCED(ai)) || (Hosts[ai].inf < InfStat_InfectiousAlmostSymptomatic) || + (Hosts[ai].inf >= InfStat_Dead_WasAsymp)) return; -#pragma omp critical (state_cumV) +#pragma omp critical(state_cumV) if (State.cumV < P.VaccMaxCourses) { cumV_OK = true; @@ -1298,14 +1553,14 @@ void DoVacc(int ai, unsigned short int ts) } if (cumV_OK) { - Hosts[ai].vacc_start_time = ts + ((unsigned short int) (P.TimeStepsPerDay * P.VaccDelayMean)); + Hosts[ai].vacc_start_time = ts + ((unsigned short int)(P.TimeStepsPerDay * P.VaccDelayMean)); if (P.VaccDosePerDay >= 0) { -#pragma omp critical (state_cumV_daily) +#pragma omp critical(state_cumV_daily) State.cumV_daily++; } -#pragma omp critical (tot_vacc) +#pragma omp critical(tot_vacc) Cells[Hosts[ai].pcell].tot_vacc++; if (P.OutputBitmap) { @@ -1327,9 +1582,10 @@ void DoVaccNoDelay(int ai, unsigned short int ts) { bool cumVG_OK = false; - if ((HOST_TO_BE_VACCED(ai)) || (Hosts[ai].inf < InfStat_InfectiousAlmostSymptomatic) || (Hosts[ai].inf >= InfStat_Dead_WasAsymp)) + if ((HOST_TO_BE_VACCED(ai)) || (Hosts[ai].inf < InfStat_InfectiousAlmostSymptomatic) || + (Hosts[ai].inf >= InfStat_Dead_WasAsymp)) return; -#pragma omp critical (state_cumVG) +#pragma omp critical(state_cumVG) if (State.cumVG < P.VaccMaxCourses) { cumVG_OK = true; @@ -1340,10 +1596,10 @@ void DoVaccNoDelay(int ai, unsigned short int ts) Hosts[ai].vacc_start_time = ts; if (P.VaccDosePerDay >= 0) { -#pragma omp critical (state_cumV_daily) +#pragma omp critical(state_cumV_daily) State.cumVG_daily++; } -#pragma omp critical (tot_vacc) +#pragma omp critical(tot_vacc) Cells[Hosts[ai].pcell].tot_vacc++; if (P.OutputBitmap) { @@ -1370,10 +1626,15 @@ Severity ChooseFinalDiseaseSeverity(int AgeGroup, int tn) // assume normalised props x = ranf_mt(tn); - if (x < P.Prop_ILI_ByAge[AgeGroup]) DiseaseSeverity = Severity_ILI; - else if (x < P.Prop_ILI_ByAge[AgeGroup] + P.Prop_SARI_ByAge[AgeGroup]) DiseaseSeverity = Severity_SARI; - else if (x < P.Prop_ILI_ByAge[AgeGroup] + P.Prop_SARI_ByAge[AgeGroup] + P.Prop_Critical_ByAge[AgeGroup]) DiseaseSeverity = Severity_Critical; - else DiseaseSeverity = Severity_Mild; + if (x < P.Prop_ILI_ByAge[AgeGroup]) + DiseaseSeverity = Severity_ILI; + else if (x < P.Prop_ILI_ByAge[AgeGroup] + P.Prop_SARI_ByAge[AgeGroup]) + DiseaseSeverity = Severity_SARI; + else if (x < P.Prop_ILI_ByAge[AgeGroup] + P.Prop_SARI_ByAge[AgeGroup] + + P.Prop_Critical_ByAge[AgeGroup]) + DiseaseSeverity = Severity_Critical; + else + DiseaseSeverity = Severity_Mild; return DiseaseSeverity; } @@ -1384,9 +1645,13 @@ unsigned short int ChooseFromICDF(double *ICDF, double Mean, int tn) double q, ti; i = (int)floor(q = ranf_mt(tn) * CDF_RES); //// note q defined here as well as i. - q -= ((double)i); //// remainder - ti = -Mean * log(q * ICDF[i + 1] + (1.0 - q) * ICDF[i]); //// weighted average (sort of) between quartile values from CDF_RES. logged as it was previously exponentiated in ReadParams. Minus as exp(-cdf) was done in ReadParaams. Sort of - Value = (unsigned short int) floor(0.5 + (ti * P.TimeStepsPerDay)); + q -= ((double)i); //// remainder + ti = -Mean * + log(q * ICDF[i + 1] + + (1.0 - q) * ICDF[i]); //// weighted average (sort of) between quartile values from + /// CDF_RES. logged as it was previously exponentiated in + /// ReadParams. Minus as exp(-cdf) was done in ReadParaams. Sort of + Value = (unsigned short int)floor(0.5 + (ti * P.TimeStepsPerDay)); return Value; } @@ -1401,16 +1666,15 @@ void SusceptibleToRecovered(int cellIndex) void SusceptibleToLatent(int cellIndex) { - Cells[cellIndex].S--; - Cells[cellIndex].L++; //// number of latently infected people increases by one. - Cells[cellIndex].latent--; //// pointer to latent in that cell decreased. + Cells[cellIndex].S--; + Cells[cellIndex].L++; //// number of latently infected people increases by one. + Cells[cellIndex].latent--; //// pointer to latent in that cell decreased. } - void LatentToInfectious(int cellIndex) { - Cells[cellIndex].L--; //// one fewer person latently infected. - Cells[cellIndex].I++; //// one more infectious person. + Cells[cellIndex].L--; //// one fewer person latently infected. + Cells[cellIndex].I++; //// one more infectious person. Cells[cellIndex].infected--; //// first infected person is now one index earlier in array. } @@ -1420,10 +1684,8 @@ void InfectiousToRecovered(int cellIndex) Cells[cellIndex].R++; //// one more recovered person } - void InfectiousToDeath(int cellIndex) { Cells[cellIndex].I--; //// one less infectious person Cells[cellIndex].D++; //// one more dead person } - diff --git a/src/Update.h b/src/Update.h index d285c1e2d..7d6631a24 100644 --- a/src/Update.h +++ b/src/Update.h @@ -2,13 +2,16 @@ #define COVIDSIM_UPDATE_H_INCLUDED_ void DoImmune(int); -void DoInfect(int, double, int, int); //added int as argument to InfectSweep to record run number: ggilani - 15/10/14 -void DoIncub(int, unsigned short int, int, int); //added int as argument to record run number: ggilani - 23/10/14 +void DoInfect(int, double, int, + int); // added int as argument to InfectSweep to record run number: ggilani - 15/10/14 +void DoIncub(int, unsigned short int, int, + int); // added int as argument to record run number: ggilani - 23/10/14 void DoDetectedCase(int, double, unsigned short int, int); void DoCase(int, double, unsigned short int, int); void DoFalseCase(int, double, unsigned short int, int); -void DoRecover(int, int, int); //added int as argument to record run number: ggilani - 23/10/14. Added thread number to record Severity categories in StateT. -void DoDeath(int, int, int); //added int as argument to record run number: ggilani - 23/10/14 +void DoRecover(int, int, int); // added int as argument to record run number: ggilani - 23/10/14. + // Added thread number to record Severity categories in StateT. +void DoDeath(int, int, int); // added int as argument to record run number: ggilani - 23/10/14 void DoPlaceClose(int, int, unsigned short int, int, int); void DoPlaceOpen(int, int, unsigned short int, int); void DoTreatCase(int, unsigned short int, int); @@ -16,7 +19,7 @@ void DoProph(int, unsigned short int, int); void DoProphNoDelay(int, unsigned short int, int, int); void DoVacc(int, unsigned short int); void DoVaccNoDelay(int, unsigned short int); -//SEVERITY ANALYSIS +// SEVERITY ANALYSIS void DoMild(int, int); void DoSARI(int, int); void DoCritical(int, int); From e69bc90fac6acefbe9b4296572308e0af00aeb61 Mon Sep 17 00:00:00 2001 From: Matthew Gretton-Dann Date: Thu, 18 Jun 2020 14:44:45 +0100 Subject: [PATCH 5/6] Fix includes so build works Clang format rearranged some of the header includes which highlighted some build issues. --- src/BinIO.h | 3 +++ src/Bitmap.h | 7 +++++-- src/CovidSim.cpp | 1 + src/Models/Cell.h | 2 ++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/BinIO.h b/src/BinIO.h index 6859a5e6d..5823816d9 100644 --- a/src/BinIO.h +++ b/src/BinIO.h @@ -1,2 +1,5 @@ +#include +#include + size_t fwrite_big(void *, size_t, size_t, FILE *); size_t fread_big(void *, size_t, size_t, FILE *); diff --git a/src/Bitmap.h b/src/Bitmap.h index 31b85ef2f..b3c290b58 100644 --- a/src/Bitmap.h +++ b/src/Bitmap.h @@ -13,9 +13,12 @@ #ifdef _WIN32 #define _WIN32_WINNT 0x0400 #define WIN32_LEAN_AND_MEAN -#include -#include +// order is important, so disable clang-format +// clang-format off #include +#include +#include +// clang-format on #endif #ifdef IMAGE_MAGICK #include "Magick++.h" diff --git a/src/CovidSim.cpp b/src/CovidSim.cpp index 0a6f1b90d..67e2bb492 100644 --- a/src/CovidSim.cpp +++ b/src/CovidSim.cpp @@ -4,6 +4,7 @@ #include #include +#include #include "BinIO.h" #include "Bitmap.h" diff --git a/src/Models/Cell.h b/src/Models/Cell.h index 0ebb0be9e..65a290d31 100644 --- a/src/Models/Cell.h +++ b/src/Models/Cell.h @@ -1,5 +1,7 @@ #pragma once +#include "Country.h" + /** * @brief Holds microcells. * From 564889852328cc07d9ac8cdf0781b74000e0b040 Mon Sep 17 00:00:00 2001 From: Matthew Gretton-Dann Date: Thu, 18 Jun 2020 14:57:15 +0100 Subject: [PATCH 6/6] Tidy up some comments The clangformat auto-applied patch produced some untidily formatted comments. This commit tidies up the ones I spotted. --- src/Bitmap.cpp | 4 +-- src/CovidSim.cpp | 70 ++++++++++++------------------------------------ src/Dist.cpp | 6 +---- src/Kernels.cpp | 4 +-- src/Rand.cpp | 6 +---- src/Sweep.cpp | 36 +++++++++---------------- 6 files changed, 33 insertions(+), 93 deletions(-) diff --git a/src/Bitmap.cpp b/src/Bitmap.cpp index 8dd59fb43..bd583c0c8 100644 --- a/src/Bitmap.cpp +++ b/src/Bitmap.cpp @@ -10,9 +10,7 @@ #include "Model.h" #include "Param.h" -//// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** -/////// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** / **** BITMAP -/// stuff. +//// **** BITMAP stuff. #ifdef _WIN32 // HAVI avi; diff --git a/src/CovidSim.cpp b/src/CovidSim.cpp index 67e2bb492..561ac3465 100644 --- a/src/CovidSim.cpp +++ b/src/CovidSim.cpp @@ -69,12 +69,8 @@ int GetInputParameter3(FILE *, const char *, const char *, void *, int, int, int void SetICDF(double *icdf, double startValue); -///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** -//////// ***** ///// ***** ///// ***** ///// ***** ///// -///// ***** ///// ***** ///// ***** ///// ***** ///// ***** GLOBAL VARIABLES (some structures in -/// CovidSim.h file and some containers) - memory allocated later. -///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** -//////// ***** ///// ***** ///// ***** ///// ***** ///// +//// **** GLOBAL VARIABLES (some structures in CovidSim.h file and some containers) +//// **** - memory allocated later. Param P; Person *Hosts; @@ -374,10 +370,7 @@ int main(int argc, char *argv[]) "[/R:R0scaling] SetupSeed1 SetupSeed2 RunSeed1 RunSeed2\n", argv[0]); - //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// - ///**** //// **** //// **** //// **** //// **** / **** SET UP OMP / THREADS / **** //// **** - /////// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** - /////// **** //// **** //// **** + //// **** SET UP OMP / THREADS #ifdef _OPENMP P.NumThreads = omp_get_max_threads(); @@ -406,10 +399,7 @@ int main(int argc, char *argv[]) sprintf(PreParamFile, ".." DIRECTORY_SEPARATOR "Pre_%s", ParamFile); } - //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// - ///**** //// **** //// **** //// **** //// **** / **** READ IN PARAMETERS, DATA ETC. / **** //// - ///**** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** - /////// **** //// **** //// **** + //// **** READ IN PARAMETERS, DATA ETC. P.NumRealisations = GotNR; ReadParams(ParamFile, PreParamFile); @@ -425,10 +415,7 @@ int main(int argc, char *argv[]) ReadAirTravel(AirTravelFile); } - //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// - ///**** //// **** //// **** //// **** //// **** / **** INITIALIZE / **** //// **** //// **** //// - ///**** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** - /////// **** + //// **** INITIALIZE ///// initialize model (for all realisations). SetupModel(DensityFile, NetworkFile, SchoolFile, RegDemogFile); @@ -443,10 +430,7 @@ int main(int argc, char *argv[]) // print out number of calls to random number generator - //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// - ///**** //// **** //// **** //// **** //// **** / **** RUN MODEL / **** //// **** //// **** //// - ///**** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** - /////// **** + //// **** RUN MODEL P.NRactE = P.NRactNE = 0; for (i = 0; (i < P.NumRealisations) && (P.NRactNE < P.NumNonExtinctRealisations); i++) @@ -2237,11 +2221,7 @@ void ReadParams(char *ParamFile, char *PreParamFile) } } - ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** - //////// **** ///// **** ///// **** - ///// **** DIGITAL CONTACT TRACING - ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** - //////// **** ///// **** ///// **** + //// **** DIGITAL CONTACT TRACING // New code for digital contact tracing - ggilani: 09/03/20 if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Include digital contact tracing", "%i", @@ -2400,11 +2380,7 @@ void ReadParams(char *ParamFile, char *PreParamFile) P.ScalingFactorPlaceDigitalContacts = 1; } - ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** - //////// **** ///// **** ///// **** - ///// **** PLACE CLOSURE - ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** - //////// **** ///// **** ///// **** + //// **** PLACE CLOSURE if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Trigger incidence per cell for place closure", "%i", @@ -2538,11 +2514,7 @@ void ReadParams(char *ParamFile, char *PreParamFile) P.PlaceCloseByAdminUnit = 0; } - ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** - //////// **** ///// **** ///// **** - ///// **** SOCIAL DISTANCING - ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** - //////// **** ///// **** ///// **** + //// **** SOCIAL DISTANCING if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Trigger incidence per cell for social distancing", "%i", @@ -2668,11 +2640,7 @@ void ReadParams(char *ParamFile, char *PreParamFile) (void *)&(P.AirportCloseDuration), 1, 1, 0)) P.AirportCloseDuration = USHRT_MAX / P.TimeStepsPerDay; - ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** - //////// **** ///// **** ///// **** - ///// **** HOUSEHOLD QUARANTINE - ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** - //////// **** ///// **** ///// **** + //// **** HOUSEHOLD QUARANTINE if (P.DoHouseholds) { @@ -2748,11 +2716,7 @@ void ReadParams(char *ParamFile, char *PreParamFile) P.CaseIsolationHouseEffectiveness = P.CaseIsolationEffectiveness; } - ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** - //////// **** ///// **** ///// **** - ///// **** VARIABLE EFFICACIES OVER TIME - ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** ///// **** - //////// **** ///// **** ///// **** + //// **** VARIABLE EFFICACIES OVER TIME if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Vary efficacies over time", "%i", (void *)&(P.VaryEfficaciesOverTime), 1, 1, 0)) @@ -5104,7 +5068,7 @@ void SaveResults(void) ERR_CRITICAL("Unable to open output file\n"); fprintf(dat, "t"); - /////// ****** /////// ****** /////// ****** COLNAMES + //// **** COLNAMES //// prevalence for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tMild_%s", AdUnits[i].ad_name); @@ -5161,7 +5125,7 @@ void SaveResults(void) fprintf(dat, "\n"); - /////// ****** /////// ****** /////// ****** Populate table. + //// **** Populate table. for (i = 0; i < P.NumSamples; i++) { fprintf(dat, "%.10f", TimeSeries[i].t); @@ -5785,7 +5749,7 @@ void SaveSummaryResults(void) //// calculates and saves summary results (called ERR_CRITICAL("Unable to open output file\n"); fprintf(dat, "t"); - /////// ****** /////// ****** /////// ****** COLNAMES + //// **** COLNAMES //// prevalance for (i = 0; i < NUM_AGE_GROUPS; i++) fprintf(dat, "\tMild_%i", i); @@ -5854,7 +5818,7 @@ void SaveSummaryResults(void) //// calculates and saves summary results (called fprintf(dat, "\n"); - /////// ****** /////// ****** /////// ****** Populate table. + //// **** Populate table. for (i = 0; i < P.NumSamples; i++) { for (j = 0; j < NUM_AGE_GROUPS; j++) @@ -5990,7 +5954,7 @@ void SaveSummaryResults(void) //// calculates and saves summary results (called ERR_CRITICAL("Unable to open output file\n"); fprintf(dat, "t"); - /////// ****** /////// ****** /////// ****** COLNAMES + //// **** COLNAMES //// prevalance for (i = 0; i < P.NumAdunits; i++) fprintf(dat, "\tMild_%s", AdUnits[i].ad_name); @@ -6059,7 +6023,7 @@ void SaveSummaryResults(void) //// calculates and saves summary results (called fprintf(dat, "\n"); - /////// ****** /////// ****** /////// ****** Populate table. + //// **** Populate table. for (i = 0; i < P.NumSamples; i++) { for (j = 0; j < P.NumAdunits; j++) diff --git a/src/Dist.cpp b/src/Dist.cpp index 723cdcfc8..090e94d83 100644 --- a/src/Dist.cpp +++ b/src/Dist.cpp @@ -9,11 +9,7 @@ double sinx[361], cosx[361], asin2sqx[1001]; -//// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** -/////// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** / **** DISTANCE -/// FUNCTIONS (return distance-squared, which is input for every Kernel function) / **** //// **** -/////// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// -///**** //// **** //// **** //// **** //// **** //// **** //// **** +//// **** DISTANC FUNCTIONS (return distance-squared, which is input for every Kernel function) double periodic_xy(double x, double y) { diff --git a/src/Kernels.cpp b/src/Kernels.cpp index d7c9d59e6..f69468c82 100644 --- a/src/Kernels.cpp +++ b/src/Kernels.cpp @@ -68,9 +68,7 @@ void InitKernel(double norm) } } -//// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** -/////// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** / **** KERNEL -/// DEFINITIONS +//// **** KERNEL DEFINITIONS double ExpKernel(double r2) { diff --git a/src/Rand.cpp b/src/Rand.cpp index 26a3b0cf0..be86314d4 100644 --- a/src/Rand.cpp +++ b/src/Rand.cpp @@ -16,11 +16,7 @@ int32_t *Xcg1, *Xcg2; int **SamplingQueue = nullptr; -///////////// ********* ///////////// ********* ///////////// ********* ///////////// ********* -//////////////// ********* ///////////// ********* -/////////////////////// NEIL rand_lib code (with some Gemma rand lib also) -///////////// ********* ///////////// ********* ///////////// ********* ///////////// ********* -//////////////// ********* ///////////// ********* +//// **** NEIL rand_lib code (with some Gemma rand lib also) double ranf(void) { diff --git a/src/Sweep.cpp b/src/Sweep.cpp index c08b965e9..7c40e1d67 100644 --- a/src/Sweep.cpp +++ b/src/Sweep.cpp @@ -303,9 +303,9 @@ void InfectSweep(double t, ///(and therefore number of new infections to) i) their house; ii) their place(s); iii) other /// spatial cells. / Each force of infection includes infectiousness and susceptibility /// components. / Infectiousness is (broadly) a function of 1 person (their age, treatment status, - ///places, no. people in their household etc.) / Susceptibility is (broadly) a function of 2 - /// people (a person's susceptibility TO ANOTHER PERSON / potential infector) / After loop 1a) over - /// infectious people, spatial infections are doled out. + /// places, no. people in their household etc.) / Susceptibility is (broadly) a function of 2 + /// people (a person's susceptibility TO ANOTHER PERSON / potential infector) / After loop 1a) + /// over infectious people, spatial infections are doled out. int n; //// number of people you could potentially infect in your place group, then number of /// potential spatial infections doled out by cell on other cells. @@ -462,9 +462,9 @@ void InfectSweep(double t, // 1= household // 2..NUM_PLACE_TYPES+1 = within-class/work-group place based // transmission NUM_PLACE_TYPES+2..2*NUM_PLACE_TYPES+1 = - // between-class/work-group place based transmission 2*NUM_PLACE_TYPES+2 - // = "spatial" transmission (spatially local random mixing) - // bits >4 store the generation of infection + // between-class/work-group place based transmission 2*NUM_PLACE_TYPES+2 = + // "spatial" transmission (spatially local random mixing) bits >4 store the + // generation of infection short int infect_type = 1 + INFECT_TYPE_MASK * (1 + si->infect_type / INFECT_TYPE_MASK); @@ -1820,9 +1820,7 @@ int TreatSweep(double t) /// microcells that are within this admin unit (and around this microcell) to be treated, /// using the flags set to avoid duplication. - //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** - /////// **** //// **** //// **** / **** //// **** //// **** //// **** TREATMENT / **** //// - ///**** //// **** //// **** //// **** //// **** //// **** //// **** + //// **** TREATMENT if ((Mcells[b].treat == 2) && (ts >= Mcells[b].treat_end_time)) { @@ -1911,9 +1909,7 @@ int TreatSweep(double t) } } - //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** - /////// **** //// **** //// **** / **** //// **** //// **** //// **** VACCINATION / **** - /////// **** //// **** //// **** //// **** //// **** //// **** //// **** + //// **** VACCINATION //// vaccinates proportion VaccProp of people in microcell (or at least adds them to /// geovacc_queue). @@ -2010,9 +2006,7 @@ int TreatSweep(double t) } } - //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** - /////// **** //// **** //// **** / **** //// **** //// **** //// **** PLACE CLOSURE / **** - /////// **** //// **** //// **** //// **** //// **** //// **** //// **** + //// **** PLACE CLOSURE ///// note that here f2 bool asks whether trigger lower than stop threshold. A few blocks /// down meaning changes to almost the opposite: asking whether trigger has exceeded @@ -2124,9 +2118,7 @@ int TreatSweep(double t) } } - //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** - /////// **** //// **** //// **** / **** //// **** //// **** //// **** MOVEMENT RESTRICTIONS - //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** + //// **** MOVEMENT RESTRICTIONS if ((Mcells[b].moverest == 2) && (ts >= Mcells[b].move_end_time)) { @@ -2207,9 +2199,7 @@ int TreatSweep(double t) } } - //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** - /////// **** //// **** //// **** / **** //// **** //// **** //// **** SOCIAL DISTANCING / - ///**** //// **** //// **** //// **** //// **** //// **** //// **** //// **** + //// **** SOCIAL DISTANCING if (P.DoGlobalTriggers) f2 = (global_trig < P.SocDistCellIncStopThresh); @@ -2295,9 +2285,7 @@ int TreatSweep(double t) } } - //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** - /////// **** //// **** //// **** / **** //// **** //// **** //// **** KEY-WORKER PROPHYLAXIS - //// **** //// **** //// **** //// **** //// **** //// **** //// **** //// **** + //// **** KEY-WORKER PROPHYLAXIS if ((Mcells[b].keyworkerproph == 2) && (ts >= Mcells[b].keyworkerproph_end_time)) {