Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I want to make changes in my code that will enable to do that things: For example of the output: the text file input My

I want to make changes in my code that will enable to do that things:

image text in transcribed

image text in transcribed

For example of the output:

image text in transcribed

the text file input

image text in transcribed

My code is:

#include

#include

#include

#include

template

class MatrixT; // forward declaration

template

void swap(MatrixT&, MatrixT&); // proto

template

class MatrixT {

friend void swap(MatrixT&, MatrixT&);

public:

typedef VALUE Value;

private:

size_t _nRows, _nCols;

std::vector _values;

public:

MatrixT(size_t nRows, size_t nCols, Value value = (Value)0) :

_nRows(nRows), _nCols(nCols), _values(_nRows * _nCols, value)

{ }

~MatrixT() = default;

MatrixT(const MatrixT&) = default;

MatrixT& operator=(const MatrixT&) = default;

size_t getNumCols() const { return _nCols; }

size_t getNumRows() const { return _nRows; }

const std::vector& get() const { return _values; }

Value* operator[](size_t i) { return &_values[0] + i * _nCols; }

const Value* operator[](size_t i) const { return &_values[0] + i * _nCols; }

};

template

void swap(MatrixT &mat1, MatrixT &mat2)

{

std::swap(mat1._nRows, mat2._nRows);

std::swap(mat1._nCols, mat2._nCols);

std::swap(mat1._values, mat2._values);

}

typedef MatrixT Board;

bool operator==(const Board &board1, const Board &board2)

{

return board1.getNumRows() == board2.getNumRows()

&& board1.getNumCols() == board2.getNumCols()

&& board1.get() == board2.get();

}

std::ostream& operator

{

for (size_t i = 1, nRows = board.getNumRows() - 1; i

for (size_t j = 1, nCols = board.getNumCols() - 1; j

out

}

out

}

return out;

}

void doSimStep(const Board &board, Board &board1)

{

assert(board.getNumRows() == board1.getNumRows());

assert(board.getNumCols() == board1.getNumCols());

for (size_t i = 1, nRows = board.getNumRows() - 1; i

for (size_t j = 1, nCols = board.getNumCols() - 1; j

const char person = board[i][j];

char person1 = person;

switch (person) {

case 's': { // search for infection in neighbourhood

bool infect = false;

for (int iP = -2; !infect && iP

for (int jP = -2; !infect && jP

infect = board[i + iP][j + jP] == 'i';

}

}

person1 = infect ? 'i' : 's';

} break;

case 'i': // infected -> recover

// fall through

case 'r': // recovered: stable state

person1 = 'r';

break;

default: assert(false); // Wrong cell contents!

}

board1[i][j] = person1;

}

}

}

int main()

{

size_t nRows = 10, nCols = 10;

#if 0 // disabled for demo

std::cout > nRows;

std::cout > nCols;

/// @todo check nRows, nCols for sufficient values

#endif // 0

// init board

std::cout

Board board(nRows + 2, nCols + 2);

std::fill(board[0], board[nRows + 2], 's');

std::cout

// infect somebody

size_t i = nRows / 2 + 1, j = nCols / 2 + 1;

#if 0 // disabled for demo

std::cout

std::cout > i;

std::cout > j;

/// @todo check i, j for matching the boundaries

#endif // 0

board[i][j] = 'i';

// simulation loop

for (unsigned day = 0;;) {

std::cout

std::cout

// simulate next day

++day;

Board board1(board);

doSimStep(board, board1);

if (board == board1) {

std::cout

break; // exit sim. loop

}

// store data of new day

swap(board, board1);

}

// done

std::cout

return 0;

}

Allow the user to choose the file describing the initial setup of the simulation The first line indicates the required number of infectious agents in a susceptible agent's neighborhood for the susceptible agent to become infectious on the next day The second line indicates how many days an agent remains infectious before it becomes recovered on the following day, i.e. if the infectious period is 2, then the agent becomes recovered after being infectious for 2 days The third line indicates the display frequently for how frequently the region should be displayed in days All subsequent lines will indicate the starting health states of the different agents in the region o o o o S: susceptible i: infectious r: recovered v: vaccinated Agents that are one square away from some other agent are considered to be in that agent's neighborhood Agents on the left and right boundaries of the region should be considered adjacent, i.e. the region is not a flat map but more like a cylinder An agent can have one of four health states: susceptible, infectious, recovered, vaccinated o An agent can only move through the states as follows: S->R o A susceptible agent becomes infectious if they have threshold or greater number of infectious agents in their neighborhood on any given day o An infectious agent becomes recovered after infectious period number of days o Vaccinated agents are permanently vaccinated and cannot change states The simulation should run until the number of infectious agents is 0, indicating the outbreak has ended. There should only be S, R, and/or V agents left over Allow the user to choose the file describing the initial setup of the simulation The first line indicates the required number of infectious agents in a susceptible agent's neighborhood for the susceptible agent to become infectious on the next day The second line indicates how many days an agent remains infectious before it becomes recovered on the following day, i.e. if the infectious period is 2, then the agent becomes recovered after being infectious for 2 days The third line indicates the display frequently for how frequently the region should be displayed in days All subsequent lines will indicate the starting health states of the different agents in the region o o o o S: susceptible i: infectious r: recovered v: vaccinated Agents that are one square away from some other agent are considered to be in that agent's neighborhood Agents on the left and right boundaries of the region should be considered adjacent, i.e. the region is not a flat map but more like a cylinder An agent can have one of four health states: susceptible, infectious, recovered, vaccinated o An agent can only move through the states as follows: S->R o A susceptible agent becomes infectious if they have threshold or greater number of infectious agents in their neighborhood on any given day o An infectious agent becomes recovered after infectious period number of days o Vaccinated agents are permanently vaccinated and cannot change states The simulation should run until the number of infectious agents is 0, indicating the outbreak has ended. There should only be S, R, and/or V agents left over

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems For Advanced Applications Dasfaa 2023 International Workshops Bdms 2023 Bdqm 2023 Gdma 2023 Bundlers 2023 Tianjin China April 17 20 2023 Proceedings Lncs 13922

Authors: Amr El Abbadi ,Gillian Dobbie ,Zhiyong Feng ,Lu Chen ,Xiaohui Tao ,Yingxia Shao ,Hongzhi Yin

1st Edition

3031354141, 978-3031354144

More Books

Students also viewed these Databases questions