/* Research Project: Graphical Database for Category Theory J. Bradbury, Dr. R. Rosebrugh, I. Rutherford M. Graves, J. Tweedle Mount Allison University 2001 Updated: May 8th, 2003 File: Iso.java Description: This class contains the algorithms to perform the isomorphism test on a given category. It is used only by the IsoFrame class. */ public class Iso { private Category cat; private String output; private int maxpaths; private boolean includeid; private boolean endopassed; public Iso(Category category_) { cat = category_; output = ""; maxpaths = 50; includeid = true; endopassed = false; } public void checkzero(String path1, String path2) { // both paths are specified, so this function simply has to // verify both paths, make sure they have matching domains and // codomains, then check if they're inverses int p1[], p2[]; String str1 = path1; String str2 = path2; if (!cat.check_string(str1)) { output += "Invalid first path."; return; } if (!cat.check_string(str2)) { output += "Invalid second path."; return; } p1 = cat.string_to_path(str1); p2 = cat.string_to_path(str2); if (cat.path_len(p1) == 0 || !cat.check_path(p1)) { output += "Invalid first path."; return; } if (cat.path_len(p2) == 0 || !cat.check_path(p2)) { output += "Invalid second path."; return; } if (cat.arr[p1[0]][1] != cat.arr[p2[cat.path_len(p2)-1]][0]) { output += "The codomain of first path must equal the domain of the second path.\n\n"; return; } if (cat.arr[p2[0]][1] != cat.arr[p1[cat.path_len(p1)-1]][0]) { output += "The domain of first path must equal the codomain of the second path.\n\n"; return; } // check if the two paths are mutually inverse if (cat.path_len(cat.reduce(cat.append_path(p1, p2))) == 0 && cat.path_len(cat.reduce(cat.append_path(p2, p1))) == 0) { output += str1 + " and " + str2 + " are mutually inverse!\n\n"; } else { output += str1 + " and " + str2 + " are not mutually inverse.\n\n"; } } public void checkone(String path1) { int i; int path[]; int temp[] = new int[cat.ini.getMAXWORD()]; int obj1, obj2, numisos = 0, numpaths; HomTree paths = new HomTree(); HomTree tree = new HomTree(); String str = path1; if (!cat.check_string(str)) { output += "Invalid path."; return; } path = cat.string_to_path(str); if (cat.path_len(path) == 0 || !cat.check_path(path)) { output += "Invalid path."; return; } obj1 = cat.arr[path[0]][1]; obj2 = cat.arr[path[cat.path_len(path)-1]][0]; temp[0] = -1; // get all paths from obj1 to obj2 and then check them all numpaths = get_all_paths(temp, paths, obj1, obj2, cat.ini.getMaxLoop(), 0, tree); // go through each path and see if it is an inverse temp = paths.getFirstPath(); for (i=0; i= maxloop) { this.setEndoPassed(true); } else if (pathlen < cat.ini.getMAXWORD()-1 && (!tree.containsPath(path) || pathlen == 0)) { // now check all paths from here, recursively if (pathlen != 0) tree.addPath(path); int arrows[] = new int[cat.num_arrows]; for (i = cat.all_arr(obj1, arrows)-1; i>=0; i--) { // add the new arrow to the path, and the new object to the object list for (j=pathlen; j>=0; j--) path[j+1] = path[j]; path[0] = arrows[i]; numpaths = get_all_paths(path, paths, cat.arr[arrows[i]][1], obj2, maxloop, numpaths, tree); // now remove the arrow and object from the path and object list for (j=0; j<=pathlen; j++) path[j] = path[j+1]; } // if we're at the second object, then add the path to the list, unless // it's already in there if (pathlen > 0 && cat.arr[path[0]][1] == obj2) { if (paths.addPath(path)) { numpaths++; numnewpaths++; } } } return numpaths; } public String getOutput() { return output; } public void setOutput(String newOutput) { output = newOutput; } public boolean getIncludeId() { return includeid; } public void setIncludeId(boolean newIncludeId) { includeid = newIncludeId; } public boolean getEndoPassed() { return endopassed; } public void setEndoPassed(boolean newEndoPassed) { endopassed = newEndoPassed; } }