示例#1
0
        public void TestArrayConcat()
        {
            byte[] test1 = new byte[] { 0, 1, 2, 3 };
            byte[] test2 = new byte[] { 5, 4, 3, 2, 1 };

            byte[] output = MathConvert.CombineByteArrays(test1, test2);

            Assert.That(output, Has.Length.EqualTo(test1.Length + test2.Length));
            Assert.AreEqual(output, new byte[] { 0, 1, 2, 3, 5, 4, 3, 2, 1 });
        }
示例#2
0
        /// <summary>
        /// Получение средней особи для метода селекции
        /// </summary>
        /// <returns>Средняя особь</returns>
        public Candidate GetAvgBestCandidate(List <Candidate> candidateList)
        {
            var avgBestCandidate = new Candidate();
            var avgDecValue      = Convert.ToInt32(candidateList.Average(c => c.DecValue));

            avgBestCandidate.DecValue   = avgDecValue;
            avgBestCandidate.Chromosome = new Chromosome(MathConvert.ConvertFromDecToBin(avgDecValue, AlgorithmSetting.IsOnlyPositive));
            avgBestCandidate.Fitness    = AlgorithmSetting.CalcFunction(Convert.ToDouble(avgDecValue));

            return(avgBestCandidate);
        }
示例#3
0
        /// <summary>
        /// Отображение популяции
        /// </summary>
        /// <param name="text">Подпись</param>
        /// <param name="population">Популяция</param>
        public void DisplayPopulation(string text, List <Candidate> population)
        {
            DisplayText(text);

            foreach (var item in population)
            {
                DisplayText($"Число {item.DecValue}\t", false);
                DisplayText($"Двоичный вид {MathConvert.ConvertBinToString(item.Chromosome)}\t", false);
                DisplayText($"Функция приспособленности {item.Fitness}", false);
                AddNewLine();
            }

            AddNewLine();
        }
示例#4
0
文件: Program.cs 项目: WinduIVS/INPTP
        static void Main(string[] args)
        {
            int    volba, cislo;
            string retezec;

            do
            {
                Console.WriteLine(@"
Menu:
 * 1) Převod z 10 do 2 soustavy
 * 2) převod z 2 do 10 soustavy
 * 3) převod z 10 do římské
 * 4) převod z římské do desítkové
 * 0) konec programu
");
                volba = Cteni.NactiInt("Vyberte volbu z menu");
                switch (volba)
                {
                case 1:
                    cislo   = Cteni.NactiInt("Zadejte celé číslo:");
                    retezec = MathConvert.ToBinary(cislo);
                    if (retezec == null)
                    {
                        Console.WriteLine("Převod nelze uskutečnit");
                    }
                    else
                    {
                        Console.WriteLine("Číslo v binární soustavě je {0}", retezec);
                    }
                    break;

                case 2:
                    retezec = Cteni.NactiString("Zadejte číslo ve dvojkové soustavě");
                    cislo   = MathConvert.FromBinary(retezec);
                    if (cislo == -1)
                    {
                        Console.WriteLine("Převod nelze uskutečnit");
                    }
                    else
                    {
                        Console.WriteLine("Číslo v desítkové soustavě je {0}", cislo);
                    }
                    break;

                case 3:

                    break;
                }
            } while (volba != 0);
        }
        public bool?IsRightTriangle()
        {
            var result = new TriangleValidator().Validate(_triangle);

            if (!result.IsValid)
            {
                return(default(bool?));
            }

            var hypOppositeAngle = MathConvert.ToDegrees(
                Math.Acos(
                    MathConvert.ToRadians(
                        (Math.Pow(_triangle.SideA, 2) + Math.Pow(_triangle.SideB, 2) - Math.Pow(_triangle.SideC, 2))
                        / 2F * _triangle.SideA * _triangle.SideB
                        )
                    )
                );

            return(Math.Abs(hypOppositeAngle - 90F) <= MathConvert.Precision);
        }
示例#6
0
        private void lueAnalysisSelectionMethods_EditValueChanged(object sender, EventArgs e)
        {
            try
            {
                var checkedComboBoxEdit = sender as CheckedComboBoxEdit;

                var values = checkedComboBoxEdit.EditValue.ToString();

                if (AnalysisSetting.Type == null)
                {
                    return;
                }

                AnalysisSetting.List = MathConvert.ConvertStringToEnumList(AnalysisSetting.Type, values);

                //DisplaySetting();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
 public double MathConvertDegreesToRadiansTest(double degrees)
 {
     return(MathConvert.ToRadians(degrees));
 }
 public double MathConvertRadiansToDegreesTest(double radians)
 {
     return(MathConvert.ToDegrees(radians));
 }
 public ITexture Create(Color[] Colors, Vector2 Size)
 {
     return(Create(MathConvert.ToRawBytes(Colors), 4, Size));
 }