/* Research Project: Graphical Database for Category Theory J. Bradbury, Dr. R. Rosebrugh, I. Rutherford Mount Allison University 2001 File: InitialObject.java Description: This file contains the algorithms to test a given category for initial and terminal objects; -- when an initial object is to be tested for, the category is passed in regularly, and the calling method uses the setObjectType() method to set it as an INITIAL_OBJECT (the default). Then the algorithm is performed, and the calling method gets the output via the getOutput() method. -- when a terminal object is to be tested for, the category must first be dualled (i.e. call the makeDual() method), then passed to the InitialObject constructor. Then the calling method uses the setObjectType() method to set it as a TERMINAL_OBJECT. Then the algorithm (the exact same algorithm as performed on an INITIAL_OBJECT) is perforemd, and the calling method gets the output via the getOutput() method. */ public class InitialObject { private Category cat = new Category(); private String output; private String objectType; public InitialObject(Category newCat, String newObjectType) { cat = newCat; output = ""; objectType = newObjectType; } //INITIAL/TERMINAL OBJECT FUNCTIONS public boolean check_initial(int path[], int domain, int objects[], int object_array[][], String orig) /* Parameters: path: array of integers containing the path of arrows followed so far domain: integer representing the domain of the current arrow in the path objects:array of integers containing the objects visited along the current path object_array: uses the integers representing the objects as subscripts and stores paths to each object as the elements of the array orig: string containing the name of the object being tested for an initial object Purpose: A recursive function to determine if object domain is initial. Design: Traces all paths from object domain. If a path is the first path with its codomain, the path is stored in object_array. Otherwise, the path is compared to the path stored for the object which is the codomain; if it is not equal to the stored path, the object is not initial, a message is displayed, and the function returns false. Otherwise, the function returns true. */ { int i, j, number, current_arrow, codomain; boolean done; int arrow_array[] = new int [cat.ini.getMAXARR()]; int first[] = new int [cat.ini.getMAXWORD()]; int second[] = new int [cat.ini.getMAXWORD()]; // check for a looped path done = false; // for every object in the current path for (i=0; i 1) done = true; } } if (!done) { // make sure the current path is ok if (object_array[domain][0] == -1) { // this object has not been reached yet first = cat.copy_path(path); first = cat.reduce(first); object_array[domain] = cat.copy_path(first); } else { // make sure the current path equals the already-stored path first = cat.copy_path(path); second = cat.copy_path(object_array[domain]); first = cat.reduce(first); second = cat.reduce(second); if (!cat.equals(first, second)) { output += "\n" + orig + " NOT " + objectType.toUpperCase() + ": " + cat.path_to_string(first) + " and " + cat.path_to_string(second) + " are both paths to object " + cat.obj[domain]; return false; } } // check all arrows from this object number = cat.all_arr(domain, arrow_array); for (i=0; i=0; j--) { path[j+1] = path[j]; } path[0] = current_arrow; objects[cat.path_len(objects)+1] = -1; objects[cat.path_len(objects)] = codomain; // now recurse by checking from the next object if (!check_initial(path, codomain, objects, object_array, orig)) return false; // presuming the last call returned true, then we remove the last object from the path // and the last arrow for (j=0; j