Skip to content

Commit

Permalink
bug fix, ignore same atom to be visited twice
Browse files Browse the repository at this point in the history
  • Loading branch information
asad committed May 25, 2014
1 parent 6146973 commit 473a0f8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/org/openscience/smsd/algorithm/vflib/map/Match.java
Expand Up @@ -63,7 +63,7 @@ public class Match {

@Override
public String toString() {
return "Match{" + "query=" + query.getAtomMatcher().getQueryAtom().getID()
return "Match{" + "query=" + query.getAtomMatcher().getQueryAtom().getID()
+ ", target=" + target.getID() + '}';
}

Expand Down
40 changes: 22 additions & 18 deletions src/org/openscience/smsd/algorithm/vflib/map/VFMCSState.java
Expand Up @@ -50,6 +50,7 @@
*/
package org.openscience.smsd.algorithm.vflib.map;

import com.google.common.collect.HashBiMap;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand All @@ -74,12 +75,12 @@
@TestClass("org.openscience.cdk.smsd.algorithm.vflib.VFLibTest")
public class VFMCSState implements IState {

private List<Match> candidates;
private IQuery query;
private IAtomContainer target;
private List<INode> queryPath;
private List<IAtom> targetPath;
private Map<INode, IAtom> map;
private final List<Match> candidates;
private final IQuery query;
private final IAtomContainer target;
private final List<INode> queryPath;
private final List<IAtom> targetPath;
private final Map<INode, IAtom> map;

/**
* initialize the VFState with query and target
Expand All @@ -88,20 +89,20 @@ public class VFMCSState implements IState {
* @param target
*/
public VFMCSState(IQuery query, IAtomContainer target) {
this.map = new HashMap<INode, IAtom>();
this.queryPath = new ArrayList<INode>();
this.targetPath = new ArrayList<IAtom>();
this.candidates = new ArrayList<Match>();
this.map = HashBiMap.create();
this.queryPath = new ArrayList<>();
this.targetPath = new ArrayList<>();
this.candidates = new ArrayList<>();
this.query = query;
this.target = target;
loadRootCandidates();

}

private VFMCSState(VFMCSState state, Match match) {
this.candidates = new ArrayList<Match>();
this.queryPath = new ArrayList<INode>(state.queryPath);
this.targetPath = new ArrayList<IAtom>(state.targetPath);
this.candidates = new ArrayList<>();
this.queryPath = new ArrayList<>(state.queryPath);
this.targetPath = new ArrayList<>(state.targetPath);
this.map = state.map;
this.query = state.query;
this.target = state.target;
Expand All @@ -125,6 +126,12 @@ public void backTrack() {
}
map.clear();
for (int i = 0; i < queryPath.size() - 1; i++) {
if (map.containsKey(queryPath.get(i))) {
continue;
}
if (map.containsValue(targetPath.get(i))) {
continue;
}
map.put(queryPath.get(i), targetPath.get(i));
}
}
Expand All @@ -134,7 +141,7 @@ public void backTrack() {
*/
@Override
public Map<INode, IAtom> getMap() {
return Collections.synchronizedMap(new HashMap<INode, IAtom>(map));
return Collections.synchronizedMap(new HashMap<>(map));
}

/**
Expand Down Expand Up @@ -173,10 +180,7 @@ public boolean isMatchFeasible(Match match) {
if (!matchAtoms(match)) {
return false;
}
if (!matchBonds(match)) {
return false;
}
return true;
return matchBonds(match);
}

/**
Expand Down

0 comments on commit 473a0f8

Please sign in to comment.