Loading src/edu/bu/ec504/project/Atom.java +17 −5 Original line number Diff line number Diff line Loading @@ -11,21 +11,33 @@ public class Atom implements Serializable { degree = 0; connected = new HashMap<>(); elementType = elem; marked = false; } public void addEdge(Atom i) { degree++; if(connected.containsKey(i.getName())) { connected.put(i.getName(),connected.get(i.getName())+1); connected.put(i.getName(),new ElemOrderPair(i.elementType,connected.get(i.getName()).bondOrder+1)); } else connected.put(i.getName(),1); connected.put(i.getName(),new ElemOrderPair(i.elementType,1)); } public String getName() { return this.atomName; } private String atomName; private int elementType; private int degree; private Map<String,Integer> connected; public int elementType; public int degree; public Map<String,ElemOrderPair> connected; public boolean marked; class ElemOrderPair implements Serializable{ public int eType; public int bondOrder; public ElemOrderPair(int eType, int bondOrder) { this.eType = eType; this.bondOrder = bondOrder; } } } src/edu/bu/ec504/project/Main.java +8 −1 Original line number Diff line number Diff line Loading @@ -15,12 +15,19 @@ public class Main { if (files != null) { for (File file : files) { if (file.isFile()) { for(int oo = 0;oo <1000;oo++) moleculeArrayList.add(new Molecule(file.getPath())); } } } } Molecule tester = new Molecule(filename); for(Molecule f: moleculeArrayList) { Molecule testing = new Molecule(filename); if (moleculeArrayList.get(0).areMoleculesEqual(testing) == null) { System.out.println("err"); } } } } src/edu/bu/ec504/project/Molecule.java +47 −9 Original line number Diff line number Diff line Loading @@ -75,22 +75,59 @@ public class Molecule implements Serializable { // return null; // Number of atoms is different, molecules are not equal // } // Compare the number of elements if (!Arrays.equals(this.numElements, otherMolecule.numElements)) { System.out.println("different numElements"); return null; // Number of elements is different, molecules are not equal } // Compare the number of edges if (this.numEdges != otherMolecule.numEdges) { System.out.println("different numEdges"); return null; // Number of edges is different, molecules are not equal } // Clean the atom list of any marked atoms for(Atom cleanAtom : otherMolecule.atomArrayList) cleanAtom.marked = false; // Compare the atom lists // if (!this.atomArrayList.equals(otherMolecule.atomArrayList)) { // System.out.println("different atomArrayList"); // return null; // Atom lists are different, molecules are not equal // } // Compare the number of elements if (!Arrays.equals(this.numElements, otherMolecule.numElements)) { System.out.println("different numElements"); return null; // Number of elements is different, molecules are not equal for(Atom dbAtom : this.atomArrayList) { boolean atomFound = false; for (Atom newAtom : otherMolecule.atomArrayList) { if (!newAtom.marked && newAtom.degree == dbAtom.degree && newAtom.elementType == dbAtom.elementType) { //Check if degrees and elements are the same boolean sameConnected = true; // Compare connected of each atom //for each connected atom in dbAtom boolean [] edgeMarked = new boolean[newAtom.connected.size()]; for (Atom.ElemOrderPair dbValues : dbAtom.connected.values()) { boolean matchingEdgeIsFound = false; int marker = 0; //for each connected element in input for (Atom.ElemOrderPair newAtomValues : newAtom.connected.values()) { //if its a match if (!edgeMarked[marker] && dbValues.eType == newAtomValues.eType && dbValues.bondOrder == newAtomValues.bondOrder) { //mark the newAtom edge as already found edgeMarked[marker]=true; matchingEdgeIsFound = true; //go to next connected atom in dbAtom (break) break; } marker++; } if (!matchingEdgeIsFound) sameConnected = false; } if (sameConnected) { atomFound = true; newAtom.marked = true; break; } //if connected isnt the same //go to next newAtom; } } if(!atomFound) return null; } // If all comparisons passed, the molecules are equal Loading @@ -104,5 +141,6 @@ public class Molecule implements Serializable { return numAtoms; } } Loading
src/edu/bu/ec504/project/Atom.java +17 −5 Original line number Diff line number Diff line Loading @@ -11,21 +11,33 @@ public class Atom implements Serializable { degree = 0; connected = new HashMap<>(); elementType = elem; marked = false; } public void addEdge(Atom i) { degree++; if(connected.containsKey(i.getName())) { connected.put(i.getName(),connected.get(i.getName())+1); connected.put(i.getName(),new ElemOrderPair(i.elementType,connected.get(i.getName()).bondOrder+1)); } else connected.put(i.getName(),1); connected.put(i.getName(),new ElemOrderPair(i.elementType,1)); } public String getName() { return this.atomName; } private String atomName; private int elementType; private int degree; private Map<String,Integer> connected; public int elementType; public int degree; public Map<String,ElemOrderPair> connected; public boolean marked; class ElemOrderPair implements Serializable{ public int eType; public int bondOrder; public ElemOrderPair(int eType, int bondOrder) { this.eType = eType; this.bondOrder = bondOrder; } } }
src/edu/bu/ec504/project/Main.java +8 −1 Original line number Diff line number Diff line Loading @@ -15,12 +15,19 @@ public class Main { if (files != null) { for (File file : files) { if (file.isFile()) { for(int oo = 0;oo <1000;oo++) moleculeArrayList.add(new Molecule(file.getPath())); } } } } Molecule tester = new Molecule(filename); for(Molecule f: moleculeArrayList) { Molecule testing = new Molecule(filename); if (moleculeArrayList.get(0).areMoleculesEqual(testing) == null) { System.out.println("err"); } } } }
src/edu/bu/ec504/project/Molecule.java +47 −9 Original line number Diff line number Diff line Loading @@ -75,22 +75,59 @@ public class Molecule implements Serializable { // return null; // Number of atoms is different, molecules are not equal // } // Compare the number of elements if (!Arrays.equals(this.numElements, otherMolecule.numElements)) { System.out.println("different numElements"); return null; // Number of elements is different, molecules are not equal } // Compare the number of edges if (this.numEdges != otherMolecule.numEdges) { System.out.println("different numEdges"); return null; // Number of edges is different, molecules are not equal } // Clean the atom list of any marked atoms for(Atom cleanAtom : otherMolecule.atomArrayList) cleanAtom.marked = false; // Compare the atom lists // if (!this.atomArrayList.equals(otherMolecule.atomArrayList)) { // System.out.println("different atomArrayList"); // return null; // Atom lists are different, molecules are not equal // } // Compare the number of elements if (!Arrays.equals(this.numElements, otherMolecule.numElements)) { System.out.println("different numElements"); return null; // Number of elements is different, molecules are not equal for(Atom dbAtom : this.atomArrayList) { boolean atomFound = false; for (Atom newAtom : otherMolecule.atomArrayList) { if (!newAtom.marked && newAtom.degree == dbAtom.degree && newAtom.elementType == dbAtom.elementType) { //Check if degrees and elements are the same boolean sameConnected = true; // Compare connected of each atom //for each connected atom in dbAtom boolean [] edgeMarked = new boolean[newAtom.connected.size()]; for (Atom.ElemOrderPair dbValues : dbAtom.connected.values()) { boolean matchingEdgeIsFound = false; int marker = 0; //for each connected element in input for (Atom.ElemOrderPair newAtomValues : newAtom.connected.values()) { //if its a match if (!edgeMarked[marker] && dbValues.eType == newAtomValues.eType && dbValues.bondOrder == newAtomValues.bondOrder) { //mark the newAtom edge as already found edgeMarked[marker]=true; matchingEdgeIsFound = true; //go to next connected atom in dbAtom (break) break; } marker++; } if (!matchingEdgeIsFound) sameConnected = false; } if (sameConnected) { atomFound = true; newAtom.marked = true; break; } //if connected isnt the same //go to next newAtom; } } if(!atomFound) return null; } // If all comparisons passed, the molecules are equal Loading @@ -104,5 +141,6 @@ public class Molecule implements Serializable { return numAtoms; } }