Skip to content

Commit

Permalink
PMD variable name warning fixes
Browse files Browse the repository at this point in the history
Change-Id: I37a0421e297189ab46ce8a8ddfea6fcb04bd77d1

Signed-off-by: John May <john@nextmovesoftware.com>
  • Loading branch information
egonw authored and johnmay committed Jan 1, 2015
1 parent d93a4ef commit 9805f3e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 51 deletions.
42 changes: 18 additions & 24 deletions base/core/src/main/java/org/openscience/cdk/graph/PathTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
* @cdk.module core
* @cdk.githash
* @cdk.created 2001-06-17
* @cdk.bug 1817487
*/
@TestClass("org.openscience.cdk.graph.PathToolsTest")
public class PathTools {
Expand Down Expand Up @@ -82,28 +81,25 @@ public static int[] getInt2DColumnSum(int[][] apsp) {
*/
@TestMethod("testComputeFloydAPSP_arrayintint")
public static int[][] computeFloydAPSP(int costMatrix[][]) {
int i;
int j;
int k;
int nrow = costMatrix.length;
int[][] distMatrix = new int[nrow][nrow];
//logger.debug("Matrix size: " + n);
for (i = 0; i < nrow; i++) {
for (j = 0; j < nrow; j++) {
for (int i = 0; i < nrow; i++) {
for (int j = 0; j < nrow; j++) {
if (costMatrix[i][j] == 0) {
distMatrix[i][j] = 999999999;
} else {
distMatrix[i][j] = 1;
}
}
}
for (i = 0; i < nrow; i++) {
for (int i = 0; i < nrow; i++) {
distMatrix[i][i] = 0;
// no self cycle
}
for (k = 0; k < nrow; k++) {
for (i = 0; i < nrow; i++) {
for (j = 0; j < nrow; j++) {
for (int k = 0; k < nrow; k++) {
for (int i = 0; i < nrow; i++) {
for (int j = 0; j < nrow; j++) {
if (distMatrix[i][k] + distMatrix[k][j] < distMatrix[i][j]) {
distMatrix[i][j] = distMatrix[i][k] + distMatrix[k][j];
//P[i][j] = k; // k is included in the shortest path
Expand All @@ -125,13 +121,11 @@ public static int[][] computeFloydAPSP(int costMatrix[][]) {
*/
@TestMethod("testComputeFloydAPSP_arraydoubledouble")
public static int[][] computeFloydAPSP(double costMatrix[][]) {
int i;
int j;
int nrow = costMatrix.length;
int[][] distMatrix = new int[nrow][nrow];
//logger.debug("Matrix size: " + n);
for (i = 0; i < nrow; i++) {
for (j = 0; j < nrow; j++) {
for (int i = 0; i < nrow; i++) {
for (int j = 0; j < nrow; j++) {
if (costMatrix[i][j] == 0) {
distMatrix[i][j] = 0;
} else {
Expand Down Expand Up @@ -429,14 +423,14 @@ public static int getVertexCountAtDistance(IAtomContainer atomContainer, int dis
int[][] admat = AdjacencyMatrix.getMatrix(atomContainer);
int[][] distanceMatrix = computeFloydAPSP(admat);

int n = 0;
int matches = 0;

for (int i = 0; i < natom; i++) {
for (int j = 0; j < natom; j++) {
if (distanceMatrix[i][j] == distance) n++;
if (distanceMatrix[i][j] == distance) matches++;
}
}
return n / 2;
return matches / 2;
}

/**
Expand Down Expand Up @@ -472,25 +466,25 @@ public static List<IAtom> getShortestPath(IAtomContainer atomContainer, IAtom st
}
dist[atomContainer.getAtomNumber(start)] = 0;

List<IAtom> Slist = new ArrayList<IAtom>();
List<Integer> Qlist = new ArrayList<Integer>();
List<IAtom> sList = new ArrayList<IAtom>();
List<Integer> qList = new ArrayList<Integer>();
for (int i = 0; i < natom; i++)
Qlist.add(i);
qList.add(i);

while (true) {
if (Qlist.size() == 0) break;
if (qList.size() == 0) break;

// extract min
int u = 999999;
int index = 0;
for (Integer tmp : Qlist) {
for (Integer tmp : qList) {
if (dist[tmp] < u) {
u = dist[tmp];
index = tmp;
}
}
Qlist.remove(Qlist.indexOf(index));
Slist.add(atomContainer.getAtom(index));
qList.remove(qList.indexOf(index));
sList.add(atomContainer.getAtom(index));
if (index == endNumber) break;

// relaxation
Expand Down
53 changes: 26 additions & 27 deletions base/core/src/main/java/org/openscience/cdk/graph/SpanningTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
* @cdk.dictref blue-obelisk:graphSpanningTree
* @cdk.keyword spanning tree
* @cdk.keyword ring finding
* @cdk.bug 1817487
*/
@TestClass("org.openscience.cdk.graph.SpanningTreeTest")
public class SpanningTree {
Expand Down Expand Up @@ -86,22 +85,22 @@ public SpanningTree(IAtomContainer atomContainer) {
buildSpanningTree(atomContainer);
}

private boolean fastfind(int v1, int v2, boolean union) {
int i = v1;
private boolean fastfind(int vertex1, int vertex2, boolean union) {
int i = vertex1;
while (parent[i] > 0)
i = parent[i];
int j = v2;
int j = vertex2;
while (parent[j] > 0)
j = parent[j];
int t;
while (parent[v1] > 0) {
t = v1;
v1 = parent[v1];
while (parent[vertex1] > 0) {
t = vertex1;
vertex1 = parent[vertex1];
parent[t] = i;
}
while (parent[v2] > 0) {
t = v2;
v2 = parent[v2];
while (parent[vertex2] > 0) {
t = vertex2;
vertex2 = parent[vertex2];
parent[t] = j;
}
if (union && (i != j)) {
Expand All @@ -116,9 +115,9 @@ private boolean fastfind(int v1, int v2, boolean union) {
return (i != j);
}

private void fastFindInit(int V) {
parent = new int[V + 1];
for (int i = 1; i <= V; i++) {
private void fastFindInit(int vertexCount) {
parent = new int[vertexCount + 1];
for (int i = 1; i <= vertexCount; i++) {
parent[i] = 0;
}
}
Expand All @@ -140,18 +139,18 @@ private void buildSpanningTree(IAtomContainer atomContainer) {
(atomContainer.getAtom(i)).setProperty(ATOM_NUMBER, Integer.toString(i + 1));
}
IBond bond;
int v1, v2;
int vertex1, vertex2;
bondsInTree = new boolean[totalEdgeCount];

for (int b = 0; b < totalEdgeCount; b++) {
bondsInTree[b] = false;
bond = atomContainer.getBond(b);
v1 = Integer.parseInt((bond.getAtom(0)).getProperty(ATOM_NUMBER).toString());
v2 = Integer.parseInt((bond.getAtom(1)).getProperty(ATOM_NUMBER).toString());
vertex1 = Integer.parseInt((bond.getAtom(0)).getProperty(ATOM_NUMBER).toString());
vertex2 = Integer.parseInt((bond.getAtom(1)).getProperty(ATOM_NUMBER).toString());
//this below is a little bit slower
//v1 = atomContainer.getAtomNumber(bond.getAtomAt(0))+1;
//v2 = atomContainer.getAtomNumber(bond.getAtomAt(1))+1;
if (fastfind(v1, v2, true)) {
if (fastfind(vertex1, vertex2, true)) {
bondsInTree[b] = true;
sptSize++;
//logger.debug("ST : includes bond between atoms "+v1+","+v2);
Expand Down Expand Up @@ -185,32 +184,32 @@ private void buildSpanningTree(IAtomContainer atomContainer) {
*/
@TestMethod("testGetSpanningTree")
public IAtomContainer getSpanningTree() {
IAtomContainer ac = molecule.getBuilder().newInstance(IAtomContainer.class);
IAtomContainer container = molecule.getBuilder().newInstance(IAtomContainer.class);
for (int a = 0; a < totalVertexCount; a++)
ac.addAtom(molecule.getAtom(a));
container.addAtom(molecule.getAtom(a));
for (int b = 0; b < totalEdgeCount; b++)
if (bondsInTree[b]) ac.addBond(molecule.getBond(b));
return ac;
if (bondsInTree[b]) container.addBond(molecule.getBond(b));
return container;
}

/**
* Find a path connected <i>a1</i> and <i>a2</i> in the tree. If there was
* an edge between <i>a1</i> and <i>a2</i> this path is a cycle.
*
* @param spt spanning tree
* @param a1 start of path (source)
* @param a2 end of path (target)
* @param atom1 start of path (source)
* @param atom2 end of path (target)
* @return a path through the spanning tree from the source to the target
* @throws NoSuchAtomException thrown if the atom is not in the spanning
* tree
*/
@TestMethod("testGetPath_IAtomContainer_IAtom_IAtom")
public IAtomContainer getPath(IAtomContainer spt, IAtom a1, IAtom a2) throws NoSuchAtomException {
public IAtomContainer getPath(IAtomContainer spt, IAtom atom1, IAtom atom2) throws NoSuchAtomException {
IAtomContainer path = spt.getBuilder().newInstance(IAtomContainer.class);
PathTools.resetFlags(spt);
path.addAtom(a1);
PathTools.depthFirstTargetSearch(spt, a1, a2, path);
if (path.getAtomCount() == 1) path.removeAtom(a1); // no path found: remove initial atom
path.addAtom(atom1);
PathTools.depthFirstTargetSearch(spt, atom1, atom2, path);
if (path.getAtomCount() == 1) path.removeAtom(atom1); // no path found: remove initial atom
return path;
}

Expand Down

0 comments on commit 9805f3e

Please sign in to comment.