Skip to content
Jodoin, Nathan edited this page Nov 4, 2022 · 11 revisions

Table of Contents

  1. Data Structures
    1. Map struct
    2. z_list struct
    3. Local Adjacency Lists
    4. Remote Adjacency Lists
  2. General Design
  3. File Structure

Data Structures

We have two custom datatypes, each defined in definitions.hpp, which house the two of the four main data structures we work with through the execution of the application. The other two main datatypes are data members of specific zone objects, industrial objects, and commercial objects.

1. Map struct

- Contains a 2D vector of zone pointers

The map struct contains three data members. The first is a two-dimensional vector of zone pointer objects. This structure will contain the primary data for our zones from the map region. The second and third data members are integer values representing the x and y size of the 2D vector, set at runtime for ease of access in later function calls.

2. z_list struct

- Contains 3 vectors of populated pointers

The z_list contains the workhorse data structures for the population update functions. Each populated pointer list represents one of the different types of populated zones and is sorted in accordance with the update rule deconfliction requirements so that each zone is iterated over correctly for population updates. The populated pointers will reference the same objects stored in the 2D vector of zone pointers, to save memory.

3. Local Adjacency Lists

It is most efficient for each node to retain a list of the node's direct adjacencies, and remote adjacencies if applicable by type. Local adjacencies are stored in a vector data member of size 8 populated with zone pointers. Index 0 represents the top left corner adjacency, and each subsequent index represents a clockwise rotation around the node. Remote adjacencies are stored in a list. The local adjacency list is a data member of the zone class type, and once stored never changes.

4. Remote adjacency Lists

Remote adjacency lists, as with local adjacency lists, are useful for increasing the efficiency of map updates. Each industrial and commercial zone has one and two data members respectively which are adjacency lists. As defined by the program requirements, industrial nodes must have a list of every residential zone to which they are adjacent, in order by distance, from which they assign workers for growth. Commercial nodes also require this information. Additionally, they require an adjacency list of all industrial nodes from which they may receive goods. These adjacencies are calculated using the local adjacency lists and once stored never change.

General Design

Design choices made with data in mind

At runtime, the program will read a series of characters from a provided file. Each character will be translated into a zone object or zone descendant object, and then stored in a 2D vector. The 2D vector will be the main copy of each zone object and is stored in a Map struct, discussed above.

To avoid potential instances of multiple states from objects calling functions on other objects, our program will access all of our data from the top level through a series of ordered function calls. These calls will operate on the list members of the z_list struct.

During the update and display loop of the simulation, the z_list members will be the primary means by which our zone objects are accessed. For example, pollution, which affects populated zones, may be updated through a function that iterates through the list of each industrial zone, and then for each zone updates the adjacent nodes, moving outward until the appropriate depth has been reached.

File Structure

Filename Description
adjacencies.cpp adjacency calculation logic
analysis.cpp included in main, the analysis process
commercial.cpp commercial class definition
definitions.hpp main header for organizing non-functional global includes
display.cpp map display logic
fileIO.cpp file IO and initialization logic
industrial.cpp industrial zone class definition
listSort.cpp zlist sorting logic
main.cpp the main function
populated.cpp the parent class of populated zones, commercial, industrial, and residential
README.md A markdown readme files
README.txt A text file version of the MD readme
residential.cpp residential zone class definition
unpopZones.cpp unpopulated zone simple class definitions
updateMap.cpp population and pollution update logic
zone.cpp: zone superclass definition

Clone this wiki locally