//Методы расчетов public void SystemCalc() { CurrentSystem = new RfSystem(comboBox1.SelectedItem as Element, comboBox2.SelectedItem as Element, comboBox3.SelectedItem as Element, comboBox4.SelectedItem as Element); label14.Text = "Усиление системы = " + Convert.ToString(CurrentSystem.TotalGain()) + " dB"; label15.Text = "Шум системы = " + Convert.ToString(CurrentSystem.TotalNoise()) + " dB"; label16.Text = "Цена системы = " + Convert.ToString(CurrentSystem.TotalCost()) + " $"; } // Расчет текущей системы
static public void TryRandomSearch() { var Random = new Random(); List <RfSystem> RandomSearchList = new List <RfSystem>(); Console.WriteLine("Поиск случайным образом "); for (int i = 0; i < 115980; i++) { int random_index_switch = Random.Next(0, ElementStore.Switches.Count); int random_index_lna = Random.Next(0, ElementStore.LNAs.Count); int random_index_mixer = Random.Next(0, ElementStore.Mixers.Count); int random_index_filter = Random.Next(0, ElementStore.Filters.Count); RfSystem RandomSystem = new RfSystem( ElementStore.Switches[random_index_switch], ElementStore.LNAs[random_index_lna], ElementStore.Mixers[random_index_mixer], ElementStore.Filters[random_index_filter]); if (RandomSystem.TotalGain() > MainBody.UserGain && RandomSystem.TotalNoise() < MainBody.UserNoise) { RandomSearchList.Add(new RfSystem( ElementStore.Switches[random_index_switch], ElementStore.LNAs[random_index_lna], ElementStore.Mixers[random_index_mixer], ElementStore.Filters[random_index_filter] )); } } if (RandomSearchList.Count() > 0) { RandomSearchList = RandomSearchList.OrderBy(x => x.TotalCost()).ToList(); // Console.WriteLine("*************Результат рандомного поиска**********************"); Console.WriteLine("Подходящие системы, количество = " + RandomSearchList.Count); // Console.WriteLine("Самая дешевая система по заданным условиям"); Console.WriteLine(RandomSearchList[0].SystemDescription()); // Console.WriteLine("Усиление = " + RandomSearchList[0].TotalGain() + " дБ "); // Console.WriteLine("Шум = " + RandomSearchList[0].TotalNoise() + " дБ "); //Console.WriteLine("Цена = " + RandomSearchList[0].TotalCost() + " $ "); } else { Console.WriteLine("Число найденных систем =" + RandomSearchList.Count); Console.WriteLine("Видимо не повезло, испытай удачу еще раз!"); } }
//Конструктор хромосомы с задаными индексами для детей public Chromosome(int SwitchIndex, int LNAIndex, int MixerIndex, int FilterIndex) { this.SwitchIndex = SwitchIndex; this.LNAIndex = LNAIndex; this.MixerIndex = MixerIndex; this.FilterIndex = FilterIndex; RfSystem SystemChromosome = new RfSystem(ElementStore.Switches[SwitchIndex], ElementStore.LNAs[LNAIndex], ElementStore.Mixers[MixerIndex], ElementStore.Filters[FilterIndex]); ChromosomeTotalGain = SystemChromosome.TotalGain(); ChromosomeTotalNoise = SystemChromosome.TotalNoise(); ChromosomeTotalCost = SystemChromosome.TotalCost(); // Есть и цена, и цена фитнесс - надо определиться и что то одно оставить ChromosomeDescription = SystemChromosome.SystemDescription(); //Запрос имен ChromosomeIndexes = SwitchIndex + " " + LNAIndex + " " + MixerIndex + " " + FilterIndex; //Запрос индексов SystemSwitch = SystemChromosome.SystemSwitch(); SystemLNA = SystemChromosome.SystemLNA(); SystemMixer = SystemChromosome.SystemMixer(); SystemFilter = SystemChromosome.SystemFilter(); GetRecall(); //Пересчет всегда, при создании хромосомы }
static public void BruteForce() { List <RfSystem> AllList = new List <RfSystem>(); List <RfSystem> BruteForceCheck = new List <RfSystem>(); foreach (Element _switch in ElementStore.Switches) { foreach (Element _lna in ElementStore.LNAs) { foreach (Element _mixer in ElementStore.Mixers) { foreach (Element _filter in ElementStore.Filters) { RfSystem СurrentBruteSystem = new RfSystem(_switch, _lna, _mixer, _filter); RfSystem AllListSystem = new RfSystem(_switch, _lna, _mixer, _filter); AllList.Add(AllListSystem); if (СurrentBruteSystem.TotalGain() >= MainBody.UserGain && СurrentBruteSystem.TotalNoise() <= MainBody.UserNoise) { BruteForceCheck.Add(item: new RfSystem(_switch, _lna, _mixer, _filter)); } } } } } if (BruteForceCheck.Count == 0) { Console.WriteLine("Systems not found"); } else { Console.WriteLine("==============Итого в работе =========" + AllList.Count); Console.WriteLine("Количество найденных подходящих систем === " + BruteForceCheck.Count); BruteForceCheck = BruteForceCheck.OrderBy(x => x.TotalCost()).ToList(); Console.WriteLine("***************************************************"); Console.WriteLine("Самая дешевая система по заданным условиям используя Полный перебор "); Console.WriteLine(BruteForceCheck[0].SystemDescription()); Console.WriteLine("Усиление = " + BruteForceCheck[0].TotalGain() + " дБ "); Console.WriteLine("Шум = " + BruteForceCheck[0].TotalNoise() + " дБ "); Console.WriteLine("Цена = " + BruteForceCheck[0].TotalCost() + " $ "); bruteresult = (BruteForceCheck[0].SystemDescription()); systemgain = BruteForceCheck[0].TotalGain(); systemnoise = BruteForceCheck[0].TotalNoise(); systemcost = BruteForceCheck[0].TotalCost(); SystemSwitch = BruteForceCheck[0].SystemSwitch(); SystemLNA = BruteForceCheck[0].SystemLNA(); SystemMixer = BruteForceCheck[0].SystemMixer(); SystemFilter = BruteForceCheck[0].SystemFilter(); } }