public int addFunction(Function3 function3) { functionSnCount++; function3.sn = functionSnCount; functionList.Add(function3); return(1); }
/// <summary> /// Očekává ze nenastane vyjimka, výsledek vypíše /// </summary> /// <param name="funkce">funkce vracejici double ktera bere double a int parametry</param> /// <param name="a">double</param> /// <param name="b">int</param> void ExpectNoThrow(Function3 funkce, double a, int b) { try { funkce(a, b); richTextBox1.AppendText("\r\nNoThrow zadane parametry:" + a + " " + b); } catch { chyby++; richTextBox1.AppendText("\r\nChybaNoThrow zadane parametry:" + a + " " + b); } }
public async Task Run_CosmosDbReturnsNoDocument_Return404NotFound() { //arrange var mockHttpRequest = MockHttpRequestGenerator.CreateWithBodyString("COMPLETED"); //act var actionResult = await Function3.Run(mockHttpRequest.Object, null, _mockLogger); //assert Assert.IsTrue(_mockLogger.GetLogs().Where(m => m.Contains(UserFriendlyMessages.DocumentNotFound)).Count() == 1); Assert.IsInstanceOfType(actionResult, typeof(NotFoundObjectResult)); StringAssert.Contains(((NotFoundObjectResult)actionResult).Value.ToString(), UserFriendlyMessages.DocumentNotFound); }
public async Task Run_BodyDoesNotContainOneOfTheThree_Return400BadRequest(string body) { //arrange var mockHttpRequest = MockHttpRequestGenerator.CreateWithBodyString(body); //act var actionResult = await Function3.Run(mockHttpRequest.Object, new IntermediaryServiceDocument(), _mockLogger); //assert Assert.IsTrue(_mockLogger.GetLogs().Where(m => m.Contains(UserFriendlyMessages.ErrorProcessingBody)).Count() == 1); Assert.IsInstanceOfType(actionResult, typeof(BadRequestObjectResult)); StringAssert.Contains(((BadRequestObjectResult)actionResult).Value.ToString(), UserFriendlyMessages.ErrorProcessingBody); }
static void Main(string[] args) { Function1 instance1 = new Function1(); Function2 instance2 = new Function2(); Function3 instance3 = new Function3(); ParameterizedThreadStart function1 = new ParameterizedThreadStart(instance1.StartOfFunction); ParameterizedThreadStart function2 = new ParameterizedThreadStart(instance2.StartOfFunction); ParameterizedThreadStart function3 = new ParameterizedThreadStart(instance3.StartOfFunction); Thread thread1 = new Thread(function1); Thread thread2 = new Thread(function2); Thread thread3 = new Thread(function3); // Console.WriteLine("Dimension = " + methods.getSizeofArrays()); thread1.Start(4); thread2.Start(5); thread3.Start(6); }
public async Task GenerateSchedule() { var periodTimeslots = (await PeriodTimeslotRepository.GetEntityListAsync()) .Select(x => PeriodTimeslotConverter.Convert(x)).ToList(); var classrooms = (await ClassroomRepository.GetEntityListAsync()) .Select(x => ClassroomConverter.Convert(x)).ToList(); var teachingUnits = (await TeachingUnitRepository.GetEntityListAsync()) .Select(x => TeachingUnitConverter.Convert(x)).ToList(); var generation = new GeneticScheduleGeneration(10, teachingUnits.Count); generation.GlobalGA.IterationCompleted += async() => { var bestChromosome = generation.GlobalGA.ChromosomePool.First(); await HubContext.Clients.All.SendAsync("SendScheduleInfo", new ScheduleInfo() { MaxValue = bestChromosome.Value, AverageValue = generation.GlobalGA.Pool.Average(x => x.Value), AverageAge = generation.GlobalGA.Pool.Average(x => x.Age), Evaluations = { Function1.Count(bestChromosome.Schedule), Function3.Count(bestChromosome.Schedule), Function4.Count(bestChromosome.Schedule), Function5.Count(bestChromosome.Schedule), Function6.Count(bestChromosome.Schedule), Function7.Count(bestChromosome.Schedule) } }); }; var schedules = generation.Run(classrooms, periodTimeslots, teachingUnits); await ScheduleCellRepository.Clear(); await ScheduleCellRepository.AddRangeAsync(schedules.First().ScheduleCells.Select(x => ScheduleCellConverter.Convert(x))); var gridResponse = await GetScheduleGridPrivate(); await HubContext.Clients.All.SendAsync("GenerateScheduleCompleted", gridResponse); }
public async Task Run_StatusCompleted_CosmosDbDocumentUpdated_Return204Success(string status) { //arrange var thirdPartyStatus = new ThirdPartyStatus() { Detail = "", Status = status }; string json = JsonConvert.SerializeObject(thirdPartyStatus); var mockHttpRequest = MockHttpRequestGenerator.CreateWithBodyString(json); var intermediaryDocument = new IntermediaryServiceDocument(); //act var actionResult = await Function3.Run(mockHttpRequest.Object, intermediaryDocument, _mockLogger); //assert Assert.IsInstanceOfType(actionResult, typeof(NoContentResult)); Assert.IsTrue(string.Equals(status, intermediaryDocument.Status.StatusCode)); }
private void InitializeService(MinFunGettingStarted gettingStarted) { #region Selection Init _randomSelection = new MinFuncRandomSelection(gettingStarted.EarlyPopulation); _randomSelfAdaptionSelection = new MinFuncSelfAdaptionRandomSelection(gettingStarted.EarlyPopulation); _rouletteWeelSelection = new MinFuncRouletteWeelSelection(); _susSelection = new MinFuncStochasticSampleSelection(); _tournamentSelection = new MinFuncTournamentSelection(gettingStarted.KIndividualTornomantInit); _selectionList.Add(_randomSelection); _selectionList.Add(_randomSelfAdaptionSelection); _selectionList.Add(_rouletteWeelSelection); _selectionList.Add(_susSelection); _selectionList.Add(_tournamentSelection); #endregion #region Recombination Init _singleRecombination = new MinFuncSingleRecombination(gettingStarted.ChoromosemeLenght, 0.5); _simpleRecombination = new MinFuncSimpleRecombination(gettingStarted.ChoromosemeLenght, 0.5); _wholeRecombination = new MinFuncWholeRecombination(gettingStarted.ChoromosemeLenght, 0.5); _reCombinationList.Add(_singleRecombination); _reCombinationList.Add(_simpleRecombination); _reCombinationList.Add(_wholeRecombination); #endregion #region Mutation Init _onePerFiveMutation = new MinFuncOnePerFiveMutation(gettingStarted.ChoromosemeLenght, gettingStarted.Sigma); _selfAdaptionMutation = new MinFuncSelfAdaptionMutation(gettingStarted.ChoromosemeLenght, gettingStarted.Sigma); _mutationList.Add(_onePerFiveMutation); _mutationList.Add(_selfAdaptionMutation); #endregion #region Functions _function1 = new Function1(10); _function2 = new Function2(gettingStarted.A, gettingStarted.B, gettingStarted.C); _function3 = new Function3(); _functionList.Add(_function1); _functionList.Add(_function2); _functionList.Add(_function3); #endregion }
public void Run_With_ToDoSample2DataStore() { // Arrange var toDo = new ToDo { Description = $"description-{Guid.NewGuid()}" }; var function3 = new Function3( new ToDoSample2DataStore()); // Act var actionResult = function3.Run(toDo, _logger); // Assert Assert.IsType <OkObjectResult>(actionResult); var okObjectResult = (OkObjectResult)actionResult; Assert.IsType <ToDo>(okObjectResult.Value); toDo = (ToDo)okObjectResult.Value; var expectedDataStore = nameof(ToDoSample2DataStore); Assert.Equal(expectedDataStore, toDo.DataStore); }
private static void Assignment1() { Console.WriteLine("--------------ASSIGNMENT [1]--------------------"); Console.WriteLine("Starting vector:"); var x = new DenseVector(new[] { 0.0, 0.0 }); Console.WriteLine(x); var function = new Function3(); Console.WriteLine(function); Console.WriteLine("OPTIMAL DESCENT"); var optimalDescent = Algorithms.GradientDescent(function, x, useGoldenRatio: true, epsilon: 10E-6); Console.WriteLine(optimalDescent); Console.WriteLine(); Console.WriteLine("NON-OPTIMAL DESCENT"); var nonOptimalDescent = Algorithms.GradientDescent(function, x, useGoldenRatio: false, epsilon: 10E-6); Console.WriteLine(nonOptimalDescent); Console.WriteLine("--------------------END----------------------"); }
public R8Program(XElement xml) { XElement element = xml.Element("functionSnCount"); if (!Int32.TryParse(element.Value, out functionSnCount)) { functionSnCount = -1; } element = xml.Element("version"); version = element.Value.ToString(); element = xml.Element("start").Element("posX"); if (!Int32.TryParse(element.Value, out start.posX)) { start.posX = -1; } element = xml.Element("start").Element("posY"); if (!Int32.TryParse(element.Value, out start.posY)) { start.posY = -1; } //IEnumerable<XElement> functionElementst = xml.Element("function").Elements("function"); IEnumerable <XElement> functionElements = xml.Elements("function"); IEnumerable <XElement> function2Elements; Function2 function2; Function3 function3; int res; for (int i = 0; i < functionElements.Count(); i++) { function2Elements = functionElements.ElementAt(i).Elements("function"); function2 = new Function2(); element = functionElements.ElementAt(i); if (!Int32.TryParse(element.Element("sn").Value, out res)) { res = -1; } function2.sn = res; if (!Int32.TryParse(element.Element("functionSnCount").Value, out res)) { res = -1; } function2.functionSnCount = res; for (int j = 0; j < functionElements.Count(); j++) { element = functionElements.ElementAt(j); function3 = new Function3(); function3.name = element.Element("name").Value; if (!Int32.TryParse(element.Element("posX").Value, out res)) { res = -1; } function3.rectangle.X = res; if (!Int32.TryParse(element.Element("posY").Value, out res)) { res = -1; } function3.rectangle.Y = res; if (!Int32.TryParse(element.Element("sn").Value, out function3.sn)) { function3.sn = -1; } //Console.WriteLine("function.name = " + function.name); //Console.WriteLine("function.posX = " + function.posX); //Console.WriteLine("function.posY = " + function.posY); //Console.WriteLine("function.sn = " + function.sn); function2.functionList.Add(function3); } functionList.Add(function2); //Console.WriteLine("snCount = " + snCount); //Console.WriteLine("version = " + version); //Console.WriteLine("start.posX = " + start.posX); } }
/// <summary> /// After a delay, Function f will be called with parameters p1, p2, p3. /// </summary> /// <param name="owner">Mono object that will own the coroutine</param> /// <param name="f">Callback function</param> /// <param name="p1">Parameter 1</param> /// <param name="p2">Parameter 2</param> /// <param name="p3">Parameter 3</param> /// <param name="delay">A delay in seconds</param> public static void Start <P1, P2, P3>(MonoBehaviour owner, Function3 <P1, P2, P3> f, P1 p1, P2 p2, P3 p3, float delay) { owner.StartCoroutine(CallbackCoroutine(f, p1, p2, p3, delay)); }
private static IEnumerator CallbackCoroutine <P1, P2, P3>(Function3 <P1, P2, P3> f, P1 p1, P2 p2, P3 p3, float delay) { yield return(new WaitForSeconds(delay)); f(p1, p2, p3); }
// 간편 기능3 버튼 private void Function3_Click(object sender, RoutedEventArgs e) { Function3 function3 = new Function3(); function3.Show(); }
static async Task Main(string[] args) { var connectionOptions = new ConnectionOptions(ConnectionString); var periodTimeslotRepository = new MsSqlPeriodTimeslotRepository(connectionOptions); var classroomRepository = new MsSqlClassroomRepository(connectionOptions); var teachingUnitRepository = new MsSqlTeachingUnitRepository(connectionOptions); var scheduleCellRepository = new MsSqlScheduleCellRepository(connectionOptions); var periodTimeslots = (await periodTimeslotRepository.GetEntityListAsync()) .Select(x => PeriodTimeslotConverter.Convert(x)).ToList(); var classrooms = (await classroomRepository.GetEntityListAsync()) .Select(x => ClassroomConverter.Convert(x)).ToList(); var teachingUnits = (await teachingUnitRepository.GetEntityListAsync()) .Select(x => TeachingUnitConverter.Convert(x)).ToList(); var generation = new GeneticScheduleGeneration(10, teachingUnits.Count); var schedules = generation.Run(classrooms, periodTimeslots, teachingUnits); var i = 1; var sum = 0; var sum2 = 0; var sum3 = 0; var sum4 = 0; var sum5 = 0; var sum6 = 0; schedules.ForEach(x => { var f = Function1.Count(x); var f2 = Function3.Count(x); var f3 = Function4.Count(x); var f4 = Function5.Count(x); var f5 = Function6.Count(x); var f6 = Function7.Count(x); sum += f; sum2 += f2; sum3 += f3; sum4 += f4; sum5 += f5; sum6 += f6; Console.WriteLine($"Расписание {i++}"); Console.WriteLine($"Количество неутренних лекций: {f}"); Console.WriteLine($"Количество избыточных мест: {f2}"); Console.WriteLine($"Количество превышений пар в день для преподавателей: {f3}"); Console.WriteLine($"Количество окон для преподавателей: {f4}"); Console.WriteLine($"Количество превышений пар в день для студентов: {f5}"); Console.WriteLine($"Количество окон для студентов: {f6}"); Console.WriteLine($"Оценка расписания: {EvaluationCalculation.Calculate(x)}"); Console.WriteLine($"-------------------------------------"); }); Console.WriteLine($"Всего ошибок (Лекции): {sum}"); Console.WriteLine($"Всего ошибок (Избыточные места): {sum2}"); Console.WriteLine($"Всего ошибок (Количество превышений пар в день для преподавателей): {sum3}"); Console.WriteLine($"Всего ошибок (Количество окон для преподавателей): {sum4}"); Console.WriteLine($"Всего ошибок (Количество превышений пар в день для студентов): {sum5}"); Console.WriteLine($"Всего ошибок (Количество окон для студентов): {sum6}"); await scheduleCellRepository.Clear(); await scheduleCellRepository.AddRangeAsync(schedules.First().ScheduleCells.Select(x => ScheduleCellConverter.Convert(x))); Console.ReadKey(); }