Project 3 Algorithm
By: Minh Than
Collaborated with: Ben Evans
1. Declare and define a void function to print out student’s information.
2. Declare and define a void function to print out the program’s description.
3. Declare a global integer constant called SIZE and initialize it to 10.
4. Declare a global enum variable that will support 10 values – each representing an ant
colony {A, B, C, D, E, F, G, H, I, J}.
5. In int main():
a. Declare a 2-dimensional array of the global integer constant SIZE. The number of
rows and columns should be equal to SIZE.
b. Declare a 1-dimensional array of the global integer constant SIZE that will hold
the colonies visited in the order in which they visited.
c. Declare and initialize an int variable to make sure the ant always start at A.
6. Declare and define a void function to print out student information.
7. Declare and define a void function to print out program description.
8. Declare and define a void function to initialize the 2-dimensional int array declared in the
main function, generating random numbers assigning them to the matrix elements.
a. Set a 2-dimensional array as a parameter.
b. Generate seeded random numbers between 1 and 20 (inclusive) and assign these
values in a row-major format (i.e., fill an entire row with random values before
moving to the next row).
c. If the row and column number are equal, assign a value of 0 to that node.
9. Declare and define a void function to print the contents of the two-dimensional array
generated in the previous step.
a. Set up the previously generated two-dimensional int array as its parameter.
b. Display the matrix as a table, making sure to align the numbers properly.
10. Declare and define a bool function that checks if a particular colony was visited before.
a. Set up two parameters: the 1-dimensional array that holds the colonies visited and
an integer that represents a colony.
b. Set up an if-else statement to check whether or not a colony has been visited.
c. If it has been visited, return true as a Boolean, false if otherwise.
11. Declare and define an int function that computes the index where the lowest (non-zero)
pheromone levels are found in a given row.
a. Set up three parameters; the 2-dimensional array declared in the main function that
contains all the pheromone levels, the 1-dimensional array that contains the list of all
the colonies that were visited and an integer that represents a row in the 2-dimensional
array.
b. Declare and initialize an integer variable for minimum value in order to compare and
find the lowest pheromone level.
c. For each of the columns in a row, compute the lowest non-zero value only if that colony
wasn’t visited before. To check if a colony was visited before, call the bool function
defined in the previous step.
d. Return the index with the lowest pheromone level.
12. Declare and define a void function that prints the contents the array that holds the colonies
visited.
a. Set up a 1-dimensional array as a parameter.
b. Set up a for loop to iterate with index of the array
c. Inside the for loop, use switch statement and each of the enum values as case
constants, print the path that Anthony took between the ant colonies. For example,
for case A, print “A- - - - ->”. Do this for the rest of the cases.
13. In int main():
a. Call student_info and description function.
b. Call in matrix_content and content_display function.
c. Mark the first colony A as visited as the ant will always start at A.
d. Set up a for loop and call in lowest_PL function to compute to lowest pheromone
level for each row.
e. Repeat until the ant reaches the last colony, storing the index with the lowest
pheromone level.
f. Call in printPathway function.