Example #1
0
        // wyznaczenie harmonogramu
        // S - starting times, C - completition times, PH - critical path
        public static int timetable(CGraph G, 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;
                    }
                }
                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]]);
        }
Example #2
0
        // wyznaczenie kolejnosci topologicznej
        static public int[] topOrder(CGraph G)
        {
            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;
            }



            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);
                    }
                }
            }

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

            return(ORD);
        }
Example #3
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]]);
        }
Example #4
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);
        }