Search in sources :

Example 1 with Stopwatch

use of nl.uu.cs.treewidth.timing.Stopwatch in project Smiles2Monomers by yoann-dufresne.

the class MolTreeWidth method calculateTreeWidth.

public int calculateTreeWidth(IMolecule m) {
    NGraph<InputData> g;
    AtomContainerToNgraph converter = new AtomContainerToNgraph();
    IAtomContainer mol = m;
    if (!ConnectivityChecker.isConnected(mol)) {
        IMoleculeSet comps = ConnectivityChecker.partitionIntoMolecules(mol);
        int maxIndex = 0;
        int maxCount = -9999;
        for (int i = 0; i < comps.getAtomContainerCount(); i++) {
            if (comps.getAtomContainer(i).getAtomCount() > maxCount) {
                maxCount = comps.getAtomContainer(i).getAtomCount();
                maxIndex = i;
            }
        }
        mol = comps.getAtomContainer(maxIndex);
    }
    g = converter.convert(mol);
    Stopwatch stopwatch = new Stopwatch(new JavaNanoTime());
    Permutation<InputData> p = new LexBFS<InputData>();
    PermutationToTreeDecomposition<InputData> pttd = new PermutationToTreeDecomposition<InputData>(p);
    stopwatch.reset();
    stopwatch.start();
    pttd.setInput(g);
    pttd.run();
    stopwatch.stop();
    return pttd.getUpperBound();
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IMoleculeSet(org.openscience.cdk.interfaces.IMoleculeSet) LexBFS(nl.uu.cs.treewidth.algorithm.LexBFS) Stopwatch(nl.uu.cs.treewidth.timing.Stopwatch) JavaNanoTime(nl.uu.cs.treewidth.timing.JavaNanoTime) PermutationToTreeDecomposition(nl.uu.cs.treewidth.algorithm.PermutationToTreeDecomposition) InputData(nl.uu.cs.treewidth.input.GraphInput.InputData)

Aggregations

LexBFS (nl.uu.cs.treewidth.algorithm.LexBFS)1 PermutationToTreeDecomposition (nl.uu.cs.treewidth.algorithm.PermutationToTreeDecomposition)1 InputData (nl.uu.cs.treewidth.input.GraphInput.InputData)1 JavaNanoTime (nl.uu.cs.treewidth.timing.JavaNanoTime)1 Stopwatch (nl.uu.cs.treewidth.timing.Stopwatch)1 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)1 IMoleculeSet (org.openscience.cdk.interfaces.IMoleculeSet)1