public void Mark()
        {
            CompatibilityMatrix m = new CompatibilityMatrix(5, 5);

            m.Set1(0, 1);
            m.Set1(0, 2);
            m.Set1(0, 4);
            m.Set1(1, 0);
            m.Set1(1, 3);
            Assert.IsTrue(m.Get1(0, 1));
            Assert.IsTrue(m.Get1(0, 4));
            m.Mark(0, 1, -1);
            m.Mark(0, 4, -4);
            m.Mark(1, 3, -6);
            Assert.IsFalse(m.Get1(0, 1));
            Assert.IsFalse(m.Get1(0, 4));
            Assert.IsFalse(m.Get1(1, 3));
            m.ResetRows(0, -1);
            Assert.IsTrue(m.Get1(0, 1));
            Assert.IsFalse(m.Get1(0, 4));
            Assert.IsFalse(m.Get1(1, 3));
            m.ResetRows(0, -4);
            Assert.IsTrue(m.Get1(0, 1));
            Assert.IsTrue(m.Get1(0, 4));
            Assert.IsFalse(m.Get1(1, 3));
            m.ResetRows(0, -6);
            Assert.IsTrue(m.Get1(0, 1));
            Assert.IsTrue(m.Get1(0, 4));
            Assert.IsTrue(m.Get1(1, 3));
        }
Example #2
0
        /// <summary>
        /// Refines the compatibility removing any mappings which have now become
        /// invalid (since the last mapping). The matrix is refined from the row
        /// after the current <paramref name="row"/> - all previous rows are fixed. If when
        /// refined we find a query vertex has no more candidates left in the target
        /// we can never reach a feasible matching and refinement is aborted (false
        /// is returned).
        /// </summary>
        /// <param name="row">refine from here</param>
        /// <returns>match is still feasible</returns>
        private bool Refine(int row)
        {
            int  marking = -(row + 1);
            bool changed;

            do
            {
                changed = false;
                // for every feasible mapping verify if it is still valid
                for (int n = row + 1; n < matrix.nRows; n++)
                {
                    for (int m = 0; m < matrix.mCols; m++)
                    {
                        if (matrix.Get1(n, m) && !Verify(n, m))
                        {
                            // remove the now invalid mapping
                            matrix.Mark(n, m, marking);
                            changed = true;

                            // no more mappings for n in the feasibility matrix
                            if (!HasCandidate(n))
                            {
                                return(false);
                            }
                        }
                    }
                }
            } while (changed);
            return(true);
        }