コード例 #1
0
        public virtual void TestFrom_Atom_Benzene()
        {
            IAtomContainer        benzene = TestMoleculeFactory.MakeBenzene();
            AllPairsShortestPaths asp     = new AllPairsShortestPaths(benzene);

            IAtom c1 = benzene.Atoms[0];
            IAtom c2 = benzene.Atoms[1];
            IAtom c3 = benzene.Atoms[2];
            IAtom c4 = benzene.Atoms[3];
            IAtom c5 = benzene.Atoms[4];
            IAtom c6 = benzene.Atoms[5];

            //    c2 - c3
            //  /        \
            // c1         c4
            //  \        /
            //    c6 - c5

            Assert.IsNotNull(asp.From(c1));
            Assert.IsNotNull(asp.From(c2));
            Assert.IsNotNull(asp.From(c3));
            Assert.IsNotNull(asp.From(c4));
            Assert.IsNotNull(asp.From(c5));
            Assert.IsNotNull(asp.From(c6));

            {
                IAtom[] expected = new IAtom[] { c1, c2, c3 };
                IAtom[] actual   = asp.From(c1).GetAtomsTo(c3);
                Assert.IsTrue(Compares.AreEqual(expected, actual));
            }

            {
                IAtom[] expected = new IAtom[] { c3, c2, c1 };
                IAtom[] actual   = asp.From(c3).GetAtomsTo(c1);
                Assert.IsTrue(Compares.AreEqual(expected, actual));
            }

            {
                IAtom[] expected = new IAtom[] { c1, c6, c5 };
                IAtom[] actual   = asp.From(c1).GetAtomsTo(c5);
                Assert.IsTrue(Compares.AreEqual(expected, actual));
            }

            {
                IAtom[] expected = new IAtom[] { c5, c6, c1 };
                IAtom[] actual   = asp.From(c5).GetAtomsTo(c1);
                Assert.IsTrue(Compares.AreEqual(expected, actual));
            }
        }
コード例 #2
0
        public virtual void TestConstruction_Empty()
        {
            AllPairsShortestPaths asp = new AllPairsShortestPaths(new AtomContainer());

            // all vs all fro -10 -> 10
            for (int i = -10; i < 10; i++)
            {
                for (int j = -10; j < 10; j++)
                {
                    Assert.IsTrue(Compares.AreEqual(Array.Empty <int[]>(), asp.From(i).GetPathsTo(0)));
                    Assert.IsTrue(Compares.AreEqual(Array.Empty <int>(), asp.From(i).GetPathTo(0)));
                    Assert.IsTrue(Compares.AreEqual(Array.Empty <IAtom>(), asp.From(i).GetAtomsTo(0)));

                    Assert.AreEqual(0, asp.From(i).GetNPathsTo(j));
                    Assert.AreEqual(int.MaxValue, asp.From(i).GetDistanceTo(j));
                }
            }
        }
コード例 #3
0
        public virtual void TestFrom_Int_Benzene()
        {
            IAtomContainer        benzene = TestMoleculeFactory.MakeBenzene();
            AllPairsShortestPaths asp     = new AllPairsShortestPaths(benzene);

            //    1 - 2
            //  /       \
            // 0         3
            //  \       /
            //    5 - 4

            Assert.IsNotNull(asp.From(0));
            Assert.IsNotNull(asp.From(1));
            Assert.IsNotNull(asp.From(2));
            Assert.IsNotNull(asp.From(3));
            Assert.IsNotNull(asp.From(4));
            Assert.IsNotNull(asp.From(5));

            {
                int[] expected = new int[] { 0, 1, 2 };
                int[] actual   = asp.From(0).GetPathTo(2);
                Assert.IsTrue(Compares.AreEqual(expected, actual));
            }

            {
                int[] expected = new int[] { 2, 1, 0 };
                int[] actual   = asp.From(2).GetPathTo(0);
                Assert.IsTrue(Compares.AreEqual(expected, actual));
            }

            {
                int[] expected = new int[] { 0, 5, 4 };
                int[] actual   = asp.From(0).GetPathTo(4);
                Assert.IsTrue(Compares.AreEqual(expected, actual));
            }

            {
                int[] expected = new int[] { 4, 5, 0 };
                int[] actual   = asp.From(4).GetPathTo(0);
                Assert.IsTrue(Compares.AreEqual(expected, actual));
            }
        }
コード例 #4
0
        public void Main()
        {
            {
                #region
                IAtomContainer        benzene = TestMoleculeFactory.MakeBenzene();
                AllPairsShortestPaths apsp    = new AllPairsShortestPaths(benzene);
                for (int i = 0; i < benzene.Atoms.Count; i++)
                {
                    // only to half the comparisons, we can reverse the
                    // path[] to get all j to i
                    for (int j = i + 1; j < benzene.Atoms.Count; j++)
                    {
                        // reconstruct shortest path from i to j
                        int[] path = apsp.From(i).GetPathTo(j);

                        // reconstruct all shortest paths from i to j
                        int[][] paths = apsp.From(i).GetPathsTo(j);

                        // reconstruct the atoms in the path from i to j
                        IAtom[] atoms = apsp.From(i).GetAtomsTo(j);

                        // access the number of paths from i to j
                        int nPaths = apsp.From(i).GetNPathsTo(j);

                        // access the distance from i to j
                        int distance = apsp.From(i).GetNPathsTo(j);
                    }
                }
                #endregion
            }
            {
                IAtomContainer benzene = TestMoleculeFactory.MakeBenzene();
                #region From
                AllPairsShortestPaths apsp = new AllPairsShortestPaths(benzene);

                // access explicitly
                ShortestPaths sp = apsp.From(0);
                // or chain method calls
                int[] path = apsp.From(0).GetPathTo(5);
                #endregion
            }
            {
                IAtomContainer molecule = TestMoleculeFactory.MakeBenzene();
                #region From_IAtom
                AllPairsShortestPaths apsp = new AllPairsShortestPaths(molecule);
                IAtom start = molecule.Atoms[0];
                IAtom end   = molecule.Atoms[1];

                // access explicitly
                ShortestPaths sp = apsp.From(start);

                // or chain the method calls together

                // first path from start to end atom
                int[] path = apsp.From(start).GetPathTo(end);

                // first atom path from start to end atom
                IAtom[] atoms = apsp.From(start).GetAtomsTo(end);
                #endregion
            }
        }