Passer au contenu principal
SciNet
  • Accueil
  • Tous les cours
  • Calendrier
  • Certificats
  • SciNet
    Site principal Documentation my.SciNet
  • CCDB
  • Plus
Fermer
Activer/désactiver la saisie de recherche
Français
English Français
Vous êtes connecté anonymement
Connexion
SciNet
Accueil Tous les cours Calendrier Certificats SciNet Replier Déplier
Site principal Documentation my.SciNet
CCDB
Tout déplier Tout replier
  1. Tableau de bord
  2. PHY1610 - Winter 2021
  3. 2. Modularize Ants

2. Modularize Ants

Conditions d’achèvement
Ouvert le : jeudi 21 janvier 2021, 23:59
À rendre : jeudi 28 janvier 2021, 23:59

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 août 2023, 17:09
Contacter l’assistance du site
Vous êtes connecté anonymement (Connexion)
Résumé de conservation de données


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.
Fourni par Moodle