예제 #1
0
        private void button_Click(object sender, EventArgs e)
        {
            Button      b         = (Button)sender;
            IAlgorithms algorithm = null;
            string      algName   = b.Tag.ToString();

            switch (algName)
            {
            case "crc8ElfApator":
            {
                algorithm = new crc8ElfApator();
                break;
            }

            case "crc8Teplouchet":
            {
                algorithm = new crc8Teplouchet();
                break;
            }

            case "crc16Modbus":
            {
                algorithm = new crc16ModBus();
                break;
            }

            default:
            {
                MessageBox.Show("Алгоритма с названием '" + algName + "' нет");
                return;
            }
            }


            byte[] inputArr = null;
            byte[] crcArr   = null;

            if (convertInputStringToByteArray(richTextBox1.Text, ref inputArr))
            {
                algorithm.GetCRCBytes(inputArr, ref crcArr);

                if (crcArr != null)
                {
                    string crcStr = BitConverter.ToString(crcArr).Replace("-", " ").ToLower();
                    textBox1.Text = crcStr;
                }
            }
            else
            {
                MessageBox.Show("Не удается преобразовать входную строку в массив байт");
            }
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AlgFactory"/> class.
        /// </summary>
        /// <param name="method">The method.</param>
        /// <param name="N">The n.</param>
        public AlgFactory(Methods method, int N)
        {
            switch (method)
            {
            case Methods.QuickFind:
                Algorithm = new QuickFind(N);
                break;

            case Methods.QuickUnion:
                Algorithm = new QuickUnion(N);
                break;
            }
        }
예제 #3
0
        public Global(IPools pools, IAlgorithms algorithms, IConfigManager configManager)
        {
            _pools      = pools;
            _algorithms = algorithms;
            _response   = new ExpandoObject();


            // add metrics
            if (configManager.WebServerConfig.Backend.MetricsEnabled)
            {
                Metric.Gauge("global-workers", () => WorkerCount, Unit.Items);
            }
            Metric.Gauge("global-hashrate", () => Hashrate, Unit.Custom("hashes"));
        }
예제 #4
0
        static void Main(string[] args)
        {
            var algorithms = new IAlgorithms[] { new BinaryTree(), new SideWinder(),
                                                 new AldousBroder(), new HuntAndKill(), new RecursiveBacktracker() };

            var tries = 100;
            var size  = 20;

            var averages = new Dictionary <string, double>();

            foreach (var algorithm in algorithms)
            {
                var name = algorithm.GetType().Name;
                Console.WriteLine($"Running {name} algorithm");
                var deadendCounts = new List <int>();
                for (int i = 0; i < tries; i++)
                {
                    IGrid grid = new Grid(size, size);
                    algorithm.Run(ref grid);
                    deadendCounts.Add(((Grid)grid).DeadEnds.Count());
                }

                var totalDeadends = deadendCounts.Sum();
                averages.Add(name, totalDeadends / deadendCounts.Count);
            }


            var totalCells = size * size;

            Console.WriteLine(" ");
            Console.WriteLine($"Average dead-ends per {size}x{size} maze ({totalCells} cells)");
            Console.WriteLine(" ");

            var sortedAlgorithm = averages.OrderByDescending(kvp => kvp.Value);

            foreach (var algorithm in sortedAlgorithm)
            {
                var percentage = (algorithm.Value * 100.0) / (size * size);
                Console.WriteLine($"{algorithm.Key}: {algorithm.Value}/{size*size} ({percentage}%)");
            }

            Console.ReadKey();
        }
예제 #5
0
        static void Main(string[] args)
        {
            var algorithms = new IAlgorithms[] { new BinaryTree(), new SideWinder(),
                new AldousBroder(), new HuntAndKill(), new RecursiveBacktracker() };

            var tries = 100;
            var size = 20;

            var averages = new Dictionary<string, double>();

            foreach(var algorithm in algorithms)
            {
                var name = algorithm.GetType().Name;
                Console.WriteLine($"Running {name} algorithm");
                var deadendCounts = new List<int>();
                for(int i=0;i<tries;i++)
                {
                    IGrid grid = new Grid(size, size);
                    algorithm.Run(ref grid);
                    deadendCounts.Add(((Grid)grid).DeadEnds.Count());
                }

                var totalDeadends = deadendCounts.Sum();
                averages.Add(name, totalDeadends / deadendCounts.Count);
            }

            var totalCells = size * size;
            Console.WriteLine(" ");
            Console.WriteLine($"Average dead-ends per {size}x{size} maze ({totalCells} cells)");
            Console.WriteLine(" ");

            var sortedAlgorithm = averages.OrderByDescending(kvp => kvp.Value);
            foreach(var algorithm in sortedAlgorithm)
            {
                var percentage = (algorithm.Value * 100.0) / (size * size);
                Console.WriteLine($"{algorithm.Key}: {algorithm.Value}/{size*size} ({percentage}%)");
            }

            Console.ReadKey();
        }
        public static void GetAlgorithms(out IAlgorithms[] _algorithms, out string[] _names)
        {
            IAlgorithms[] iAlgorithms;

            System.Type[] _types = System.Reflection.Assembly.GetExecutingAssembly().GetTypes();
            System.Type[] _found = (from System.Type type in _types where type.IsSubclassOf(typeof(TileWorldAlgorithms)) select type).ToArray();

            iAlgorithms = new IAlgorithms[_found.Length];

            for (int i = 0; i < iAlgorithms.Length; i++)
            {
                var _obj = ScriptableObject.CreateInstance(System.Type.GetType(_found[i].ToString()));
                iAlgorithms[i] = (IAlgorithms)_obj;
            }

            _algorithms = iAlgorithms;
            _names      = new string[_found.Length];

            for (int i = 0; i < _found.Length; i++)
            {
                _names[i] = _found[i].ToString();
            }
        }
예제 #7
0
 public Global(IPools pools, IAlgorithms algorithms)
 {
     _pools = pools;
     _algorithms = algorithms;
     _response = new ExpandoObject();
 }
예제 #8
0
 public Client(IAlgorithms algorithm)
 {
     this.algorithm = algorithm;
 }
예제 #9
0
 public NumbersController(IIOFile _stream, IAlgorithms _algorithms)
 {
     stream     = _stream;
     algorithms = _algorithms;
     numbers    = stream.ReadFromFile();
 }
예제 #10
0
 /// <summary>
 /// Shows the connected result.
 /// </summary>
 /// <param name="alg">The alg.</param>
 /// <param name="a">a.</param>
 /// <param name="b">The b.</param>
 private static void ShowConnectedResult(IAlgorithms alg, int a, int b)
 {
     Console.WriteLine();
     Console.WriteLine(alg.IsConnected(a, b) ? $"{a} and {b} are connected" : $"{a} and {b} are not connected");
 }