Пример #1
0
 internal void FindInitialMatching(int[] mMatch, int[] wMatch, SMInstance smi)
 {
     for (int i = 0; i < mMatch.Length; i++) {
         mMatch[i] = i;
         wMatch[i] = i;
     }
 }
Пример #2
0
        public SMResult(int[] mMatch, int[] wMatch, SMInstance smi)
        {
            this.mMatch = (int []) mMatch.Clone();
            this.wMatch = (int []) wMatch.Clone();

            this.smInstance = smi;
            this.resultString = "Match found";
        }
Пример #3
0
        public override Instance Generate(int size)
        {
            SMInstance sm = new SMInstance(this.Name, size);

            for (int i = 0; i < sm.Size; i++) {
                Utilities.Util.Permute<int>(sm.MPrefMatrix[i]);
                Utilities.Util.Permute<int>(sm.WPrefMatrix[i]);
            }
            sm.BuildRankMatrices();
            return sm;
        }
Пример #4
0
        int[][] BuildRankGraph(SMInstance smi)
        {
            int n = smi.Size;

            int[][] graph = new int[n][];
            for (int i = 0; i < n; i++)
                graph[i] = new int[n];

            for (int i = 0; i < n; i++)
                for (int j = 0; j < n; j++)
                    graph[i][j] = smi.MRankMatrix[i][j] + smi.WRankMatrix[j][i];

            return graph;
        }
Пример #5
0
        // Look for an uphappy pair.
        internal bool FindUnhappyPair(int[] mMatch, int[] wMatch, SMInstance smi, out int m, out int w)
        {
            m = -1;
            w = -1;
            for (int i = 0; i < mMatch.Length; i++)
                for (int j = 0; j < mMatch.Length; j++) {
                    if (Elope(i, j, wMatch[j], mMatch[i], smi)) {
                        m = i;
                        w = j;
                        return true;
                    }
                }

            return false;
        }
Пример #6
0
        public override Instance Generate(int size)
        {
            SMInstance sm = new SMInstance(this.Name, size);

            // Compute shifts for each preference list.  This takes advantage of the initialization
            // to the identify.
            for (int i = 1; i < size; i++) {
                Utilities.Util.LeftShift<int>(sm.WPrefMatrix[i - 1], i);
                Utilities.Util.LeftShift<int>(sm.MPrefMatrix[i], i);
            }

            sm.BuildRankMatrices();

            return sm;
        }
Пример #7
0
        internal override void FindInitialMatching(int[] mMatch, int[] wMatch, SMInstance smi)
        {
            int[][] graph = BuildRankGraph(smi);
            int n = smi.Size;

            for (int i = 0; i < n; i++) {
                int j = minIndex(graph[i]);
                mMatch[i] = j;
                for (int k = i + 1; k < n; k++)
                    graph[k][j] = 2 * n;
            }

            for (int i = 0; i < n; i++)
                wMatch[mMatch[i]] = i;
        }
Пример #8
0
        // Look for an uphappy pair - this finds the best match for the first unhappy man.  Needs to be changed to
        // a random man
        internal bool FindUnhappyPair(int[] mMatch, int[] wMatch, SMInstance smi, out int m, out int w)
        {
            m = -1;
            w = -1;

            int[] randOrder = Utilities.Util.RandomPermutation(mMatch.Length);
            for (int i = 0; i < mMatch.Length; i++) {
                int a = randOrder[i];
                int b = smi.MFindBestPartner(a, mMatch, wMatch);
                if (b > -1) {
                    m = a;
                    w = b;
                    return true;
                }
            }

            return false;
        }
Пример #9
0
 internal bool Elope(int m, int w, int m1, int w1, SMInstance smi)
 {
     return (smi.MRankMatrix[m][w] < smi.MRankMatrix[m][w1]) && (smi.WRankMatrix[w][m] < smi.WRankMatrix[w][m1]);
 }