Exemple #1
0
        // tworzenie zbioru premutacji
        static public void createPermuTest(SetPer pi)
        {
            int[] pis = { 0, 1, 2, 0, 3, 17, 16, 18, 0, 4, 5, 7, 9, 11, 14, 19, 0, 6, 12, 13, 0, 8, 15, 0, 10, 0 };
            int   op = 19, m = 6;

            pi.init(op, m);
            for (int i = 1; i <= op + m; i++)
            {
                pi.pi[i] = pis[i];
            }
            pi.createPS();
        }
Exemple #2
0
        public static int timetable2(CGraph G, SetPer pi, int[] topOrder, int[] S, int[] C, int[] PH)
        {
            for (int i = 1; i <= G.n; i++)
            {
                PH[i] = 0;
            }

            for (int i = 1; i <= G.n; i++)
            {
                int w = topOrder[i], s = 0;
                foreach (int p in G.pred(w))
                {
                    if (s < C[p])
                    {
                        s     = C[p];
                        PH[w] = p;
                    }
                }
                // added
                int pp = pi.pi[pi.ps[w] - 1];
                if (pp != 0)
                {
                    if (s < C[pp])
                    {
                        s     = C[pp];
                        PH[w] = pp;
                    }
                }
                // added
                S[w] = s;
                C[w] = s + G.weights[w];
            }
            PH[0] = 1;
            for (int i = 1; i <= G.n; i++)
            {
                if (C[PH[0]] < C[i])
                {
                    PH[0] = i;
                }
            }

            return(C[PH[0]]);
        }
Exemple #3
0
        //////////// ver 2 ////////////


        // added methods
        static public int[] topOrder2(CGraph G, SetPer pi)
        {
            int[] LP  = new int[G.n + 1];
            int[] ORD = new int[G.n + 1];

            for (int i = 1; i <= G.n; i++)
            {
                LP[i] = G.pred(i).Count;
            }

            // added
            for (int i = 1; i <= pi.size; i++)
            {
                if (pi.pi[i - 1] != 0)
                {
                    LP[pi.pi[i]]++;
                }
            }
            // added
            Queue <int> Q = new Queue <int>();

            for (int i = 1; i <= G.n; i++)
            {
                if (LP[i] == 0)
                {
                    Q.Enqueue(i);
                }
            }

            int l = 0;

            while (Q.Count > 0)
            {
                int w = Q.Dequeue();
                ORD[++l] = w;
                foreach (int ns in G.succ(w))
                {
                    if (--LP[ns] == 0)
                    {
                        Q.Enqueue(ns);
                    }
                }
                // added
                int nsp = pi.pi[pi.ps[w] + 1];
                if (nsp != 0)
                {
                    if (--LP[nsp] == 0)
                    {
                        Q.Enqueue(nsp);
                    }
                }
                // added
            }

            if (l < G.n)
            {
                ORD[0] = -1;
            }
            else
            {
                ORD[0] = 0;
            }

            return(ORD);
        }