Esempio n. 1
0
        public static int FindMinimumTime(AssemblyLine line1, AssemblyLine line2)
        {
            int n = line1.Stations.Length;

            int[] T1 = new int[n];
            int[] T2 = new int[n];

            T1[0] = line1.Entry + line1.Stations[0];
            T2[0] = line2.Entry + line2.Stations[0];
            for (int i = 1; i < n; ++i)
            {
                T1[i] = Math.Min(T1[i - 1] + line1.Stations[i], T2[i - 1] + line2.Transitions[line1.ID][i] + line1.Stations[i]);
                T2[i] = Math.Min(T2[i - 1] + line2.Stations[i], T1[i - 1] + line1.Transitions[line2.ID][i] + line2.Stations[i]);
            }
            return(Math.Min(T1[n - 1] + line1.Exit, T2[n - 1] + line2.Exit));
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            // Longest Increasing Subsequence
            Console.WriteLine(" ## Longest Increasing Subsequence");
            int[] n   = { 10, 22, 9, 33, 21, 50, 41, 60, 80 }; // result = 6
            LIS   lis = new LIS();

            int[] res = lis.CalcLength(n);
            Console.WriteLine("Numbers: " + string.Join(" ", n));
            Console.WriteLine("Length of LIS: " + res.Length.ToString());
            Console.WriteLine("Sequence: " + string.Join(" ", res));
            Console.WriteLine();

            // Longest Common Subsequeces
            Console.WriteLine(" ## Longest Common Subsequeces");
            string a   = "nematode knowledge";
            string b   = "empty bottle";
            LCS    lcs = new LCS();

            Console.WriteLine("string a: " + a);
            Console.WriteLine("string b: " + b);
            Console.WriteLine("Length of LCS: " + lcs.CalcLength(a, b).ToString());

            Console.WriteLine();

            // Edit Distance
            Console.WriteLine(" ## Edit Distance");
            a = "sunday";
            b = "saturday";
            EDIST e = new EDIST();

            Console.WriteLine("string a: " + a);
            Console.WriteLine("string b: " + b);
            Console.WriteLine("Cost: " + e.CalcCost(a, b).ToString());

            Console.WriteLine();
            Console.WriteLine(" ## Maximum sum such that no two elements are adjacent");

            n = new int[] { 5, 5, 10, 100, 10, 5 };
            Console.WriteLine(string.Join(" ", n));
            Console.WriteLine("Sum: " + MaxSum.Calc(n).ToString()); // 110;
            Console.WriteLine();

            // Assembly Line Scheduling
            Console.WriteLine(" ## Assembly Line Scheduling");

            AssemblyLine l1 = new AssemblyLine(1, new int[] { 4, 5, 3, 2 });

            l1.Entry = 10;
            l1.Exit  = 18;
            l1.AddTransitions(2, new int[] { 0, 7, 4, 5 });
            AssemblyLine l2 = new AssemblyLine(2, new int[] { 2, 10, 1, 4 });

            l2.Entry = 12;
            l2.Exit  = 7;
            l2.AddTransitions(1, new int[] { 0, 9, 2, 8 });
            Console.WriteLine("Minimum assembly time: " + AssemblyLineScheduling.FindMinimumTime(l1, l2).ToString());


            Console.Read();
        }