private static void ExecuteGeneticAlgorithm(RabbitFactory factory, Selection selection) { var rand = new Random(); var currentPopulation = new Population(factory.GenerateRabbits(RabbitCountAtGeneration), selection); for (int iteration = 0; iteration < CountIteration; iteration++) { var newPopulation = new Population(selection); for (var count = 0; count < RabbitCountAtGeneration; count++) { // Selection var parent1 = currentPopulation.RouletteWheelSelection(); var parent2 = currentPopulation.RouletteWheelSelection(); // Crossover var children = factory.CrossingRabbits(parent1, parent2); // GeneMutation if (rand.NextDouble() < MutationRate) { factory.Mutation(ref children); } // add to new population newPopulation.AddNewIndivid(children); } currentPopulation = newPopulation; currentPopulation.FindBestIndivid().Display(); } }
static void Main(string[] args) { RabbitFactory rabbitFactory = new RabbitFactory(); var payment1 = new Payment { AmountToPay = 25.0m, CardNumber = "1234123412341234", Name = "Mr S Hants 1" }; var payment2 = new Payment { AmountToPay = 2.0m, CardNumber = "1234123412341234", Name = "Mr S Hants 2" }; var payment3 = new Payment { AmountToPay = 5.0m, CardNumber = "1234123412341234", Name = "Mr S Hants 3" }; var payment4 = new Payment { AmountToPay = 236.0m, CardNumber = "1234123412341234", Name = "Mr S Hants 4" }; rabbitFactory.CreateQueue(); rabbitFactory.SendMessage(payment1); rabbitFactory.SendMessage(payment2); rabbitFactory.SendMessage(payment3); rabbitFactory.SendMessage(payment4); Thread.Sleep(10000); rabbitFactory.Recieve(); Console.ReadKey(); }
static void Main(string[] args) { var publisherId = ""; if (args.Length == 0) { Logger.Log("Enter publisher id:", true); publisherId = Console.ReadLine(); } else { publisherId = args[0]; Logger.Log($"Publisher id: {publisherId}", true); } try { var generator = new Generator(publisherId); publications = generator.Generate(); var factory = RabbitFactory.GetFactory(); using (var connection = factory.CreateConnection()) { using (var channel = connection.CreateModel()) { channel.QueueDeclare(queue: exchangeAgent, durable: true, exclusive: false, autoDelete: false, arguments: null); var properties = channel.CreateBasicProperties(); properties.Persistent = true; Stopwatch sw = new Stopwatch(); sw.Start(); var i = 0; //while (i < 100) { foreach (var publication in publications) { SendToQueue(channel, properties, publication); } i++; // Logger.Log($"Publisher P{publisherId} sent {i} times.", true); // Task.Delay(new TimeSpan(0, 5, 0)); } sw.Stop(); Logger.Log($"Publisher P{publisherId} sent all publications.", true); } } } catch (Exception e) { Logger.Log(e.ToString()); Console.ReadLine(); } Console.ReadLine(); }
private static void Main() { var fitness = new RabbitFitness(FitnessSolution); fitness.Stop += StopAlgorithm; var reproduction = new Reproduction2(); var selection = new StrangeWhellSelection(); var factory = new RabbitFactory(reproduction, fitness, DnaElementsCount); ExecuteGeneticAlgorithm(factory, selection); Console.ReadKey(); }
private static List <KeyValuePair <int, double> > ExecuteGeneticAlgorithm0(RabbitFactory factory, Selection selection) { var rand = new CustomRandom(2); var currentPopulation = new Population(factory.GenerateRabbits(CountOfIndividuals), selection); var result = new List <KeyValuePair <int, double> >(); result.AddRange(currentPopulation.Individuals.Select(GetChartPoint)); var iteration = 0; while (iteration < CountIteration) { var count = 0; var newPopulation = new Population(selection); while (count < CountOfIndividuals) { // added from older populations... for (int i = 0; i < 15; i++) { newPopulation.AddNewIndivid(currentPopulation.RouletteWheelSelection()); count++; } // Selection var parent1 = currentPopulation.RouletteWheelSelection(); var parent2 = currentPopulation.RouletteWheelSelection(); // Crossover var children = factory.CrossingRabbits(parent1, parent2); // GeneMutation if (rand.NextDouble() < MutationRate) { factory.Mutation(ref children); } // add to new population newPopulation.AddNewIndivid(children); count += 1; } currentPopulation = newPopulation; result.AddRange(currentPopulation.Individuals.Select(GetChartPoint)); iteration++; } return(result); }
public static List <KeyValuePair <int, double> > Execute() { IReproduction reproduction0 = new Reproduction2(); Selection selection0 = new StrangeWhellSelection(); var fitness0 = new FitnessSolution { Solution = 30 }; fitness0.Stop += StopAlgorithm; var factory0 = new RabbitFactory(reproduction0, fitness0, CountOfnucleotide); return(ExecuteGeneticAlgorithm0(factory0, selection0)); }
public void runConsumer() { Log.Logger = new LoggerConfiguration() .MinimumLevel.Override("Microsoft", LogEventLevel.Warning) .Enrich.With(new ThreadIdEnricher()) .Enrich.FromLogContext() .WriteTo.Console(LogEventLevel.Information, _seriLogSetting.loggerTemplate, theme: AnsiConsoleTheme.Literate) .WriteTo.File(logfile, LogEventLevel.Information, _seriLogSetting.loggerTemplate, rollingInterval: RollingInterval.Day, retainedFileCountLimit: 90) .CreateLogger(); try { Log.Information("===================================================================="); Log.Information($"Start RabbitService:" + typeof(RabbitService).Name); Log.Information($"Application Directory: {_seriLogSetting.baseDir}"); var factory = new ConnectionFactory() { HostName = _settings.RabbitMqUri }; using var connection = factory.CreateConnection(); Log.Information($"Rabbit Connection Created:"); using var channel = connection.CreateModel(); Log.Information($"Rabbit Channel Created:"); Log.Information($"Rabbit Enums Queue for Executing :", (RabbitQueue[])Enum.GetValues(typeof(RabbitQueue))); foreach (RabbitQueue item in (RabbitQueue[])Enum.GetValues(typeof(RabbitQueue))) { Log.Information($"Rabbit {item.ToString()} Going to create instance from factory:"); var rabbitServiceInstace = RabbitFactory.createInstance(item, channel, _seriLogSettingOptions, _serviceProvider); Log.Information($"Rabbit {item.ToString()} instance Created:"); rabbitServiceInstace.execute(); Log.Information($"Rabbit {item.ToString()} instance executed:"); }//convert to parallel task } catch (Exception e) { Log.Fatal(e, "Application terminated unexpectedly"); } finally { Log.Information("====================================================================\r\n"); Log.CloseAndFlush(); } }
public void SendSubscriptions() { var factory = RabbitFactory.GetFactory(); using (var connection = factory.CreateConnection()) { using (var channel = connection.CreateModel()) { channel.ExchangeDeclare(exchange: brokerSubscriptionsQueueName, type: "direct"); var subscriptions = GetSubscriptions(consumerIdentifier); foreach (var sub in subscriptions) { SendToQueue(channel, sub); } Logger.Log($"Consumer C{consumerIdentifier} sent all subscriptions.", true); } } //Console.ReadLine(); }
public void Construct( RabbitFactory rabbitFactory, WolfFactory wolfFactory, DeerFactory deerFactory, GenericPull pull) { _rabbitFactory = rabbitFactory; _wolfFactory = wolfFactory; _deerFactory = deerFactory; _rabbits = new List <Rabbit>(); _wolves = new List <Wolf>(); _deers = new List <Deer>(); _pull = pull; var localScale = ground.transform.localScale; minXAxis = -localScale.x / 2 + 10; maxXAxis = localScale.x / 2 - 10; minZAxis = -localScale.z / 2 + 10; maxZAxis = localScale.z / 2 - 10; }
static void Main(string[] args) { var factory = RabbitFactory.GetFactory(); if (args.Length == 0) { Logger.Log("Enter a consumer ID:", true); consumerId = Console.ReadLine(); Logger.Log("Enter a broker ID (if random leave empty):", true); var broker = Console.ReadLine(); if (string.IsNullOrWhiteSpace(broker)) { brokerId += GetRandomBroker(); } else { brokerId += broker; } Logger.Log($"Broker ID: {brokerId}", true); } else { consumerId = args[0]; Logger.Log($"Consumer ID: {consumerId}", true); if (args.Length == 1) { brokerId += GetRandomBroker(); } else { brokerId += args[1]; } Logger.Log($"Broker ID: {brokerId}", true); } var publicationsQueueName = $"C{consumerId}"; Subscriptions sub = new Subscriptions(brokerId, consumerId); var subFeedThreadReference = new ThreadStart(sub.SendSubscriptions); Thread subFeedThread = new Thread(subFeedThreadReference); subFeedThread.Start(); using (var connection = factory.CreateConnection()) { using (var channel = connection.CreateModel()) { channel.QueueDeclare(queue: publicationsQueueName, durable: true, exclusive: false, autoDelete: false, arguments: null); channel.BasicQos(prefetchSize: 0, prefetchCount: 1, global: false); var consumer = new EventingBasicConsumer(channel); consumer.Received += ConsumePublications; channel.BasicConsume(queue: publicationsQueueName, autoAck: true, consumer: consumer); Logger.Log("Awaiting Messages...", true); Console.ReadLine(); consumer.Received -= ConsumePublications; Logger.Log("Writing to file latency results..."); CSVFileWriter f = new CSVFileWriter(consumerId, latency: Latencies); f.WriteAllLatenciesInCSV(); Logger.Log("Finishd..."); } } }