/* * node.cpp * * Implementation of the Node class. See node.hpp for interface. * * Written by Alex Popkin * For Math 164 Final Project, Srping 2004 * Mar. 14, 2004 */ #include "node.hpp" using namespace std; #define SUSCEPTIBLE 1 #define INFECTED 2 #define IMMUNE 3 #define HUB 4 #define NOTHUB 5 // Constructor Node::Node(int my_id) { id = my_id; degree = 0; status = SUSCEPTIBLE; Htype = NOTHUB; } // Destructor Node::~Node() { } // addEdge function, puts new edge onto edges list void Node::addEdge(int new_){ edges.push_back(new_); degree++; } // getK function returns the degree of this vertex int Node::getK() { return degree; } // getStatus function returns the status of this node int Node::getStatus() { return status; } // Cure function, changes status from infected to susceptible void Node::cure() { if (status != IMMUNE) { status = SUSCEPTIBLE; } } // Infect function, changes status to infected unless the node is immune void Node::infect() { if (status != IMMUNE) { status = INFECTED; } } // Immunize function, changes status to immune void Node::immunize() { status = IMMUNE; Htype = HUB; } // Suscept function, changes status from immune to susceptible void Node::suscept() { if (status == IMMUNE) { status = SUSCEPTIBLE; } } // Spread function, takes an array of bools. At the end, that array will // indicate which nodes may be infected. void Node::spread(bool* infArray) { // An iterator will moves through the list of edges list::iterator nIter = edges.begin(); while (nIter != edges.end()) { // Informs all adjacent nodes infArray[*nIter] = true; // of the possibility of infection nIter++; } } /* Junk to make emacs use the right C++ style when editing this code: * Local Variables: * c-file-style: "stroustrup" * End: */