Skip to main content
SciNet
  • Home
  • All Courses
  • Calendar
  • Certificates
  • SciNet
    Main Site Documentation my.SciNet
  • CCDB
  • More
Close
Toggle search input
English
English Français
You are currently using guest access
Log in
SciNet
Home All Courses Calendar Certificates SciNet Collapse Expand
Main Site Documentation my.SciNet
CCDB
Expand all Collapse all
  1. Dashboard
  2. PHY1610 - Winter 2021
  3. 2. Modularize Ants

2. Modularize Ants

Completion requirements
Opened: Thursday, 21 January 2021, 11:59 PM
Due: Thursday, 28 January 2021, 11:59 PM

You're given a C++ code calledantsontable.cpp along with some other related files (click to download a zip file). On the teach cluster, you can find these files in the directory /scinet/course/phy1610/antsontable.

Brief description of the ants' code:

The code simulates ants walking on a table. The table is subdivided into squares. A number of ants is initially put on the table, divided as evenly as possible over the squares. Ants can move to a neighbouring square or stay put at every time step. How many of a square's ants move in each of the 9 different directions is random (using the C++ random library). To be precise, the number of ants in each square is randomly partitioned into 9 sets corresponding to the 9 possible moves (up-left, up, up-right, down-left, down, down-right, left, right, stay). Ants can fall of the edges of the table. The program prints the number of ants left on the table after every time step, as well as the minimum number of ants on a square and the maximum. It also write the number of ants on each square at every timestep to a file called ants.txt.

The addition files are:

  • teachsetup: a script to load all necessary modules on the teach cluster (gcc, graphsviz, texlive, doxygen, gnuplot and python/3)
  • README.md: which explains what the code is about and how to get it to work
  • Makefile: to help compile the code, create documentation, run, and plot.
  • Documentation.mk: a separate makefile to produce the documentation
  • Plotting.mk: a separate makefile to produce plots from the output.
  • plotsnapshots.gnuplot: a gnuplot script to produce plots of snapshots of the output
  • plotsnapshots.py: a python script to produce plots of snapshots of the output.

You should:

  • Compile and run the code and create its documentation and plots.
  • Save the original code and its output, to check against.

You will then restructure the code in the following way:

  • Replace the automatic 1d arrays with dynamically allocated arrays.
  • Modularize the code. There should at least be separate modules for
    • Initialization of the ants
    • The random partitioning function
    • The 'linear' function (even though it's debatable if that's worthwhile).
    • The single time step (i.e., the code block following the loop body of the for(int timestep...) loop, but excluding that for statement)
    • Output, i.e., reporting the number of ants to screen and writing to ants.txt
    The program with the main function is then essentially just a 'driver' that puts it altogether.

    Please recall that a proper "modularization" implies separating your functions in several files (header with prototypes, preprocessor guards and necessary includes, and source files with the implementation of such functions.

  • Adapt the existing Makefile to be able to compile this modular code.
Ensure the code is (remains) clearly commented and documented. Modify the README.md if necessary.

Submit your code files (source and header files), your makefile and the README.md file by January 28, 2021 at 23:55 PM. The late policy can be found in the syllabus. Do NOT submit the output of your program (it's too large).

  • antsontable2021.zip antsontable2021.zip
    2 August 2023, 5:09 PM
Contact site support
You are currently using guest access (Log in)
Data retention summary


All content on this website is made available under the Creative Commons Attribution 4.0 International licence, with the exception of all videos which are released under the Creative Commons Attribution-NoDerivatives 4.0 International licence.
Powered by Moodle