public IActionResult Index() { int[] a = new int[16] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; //For every angorithm we generate initial array 4x4 HillClimbingVM VM = new HillClimbingVM() { array = a, dimension = 4, heuristic = _IFunctions.Heuristic(_IFunctions.array1Dto2D(a, 4), 4), dimensions = new List <SelectListItem>() { new SelectListItem { Text = "4x4", Value = "4" }, new SelectListItem { Text = "5x5", Value = "5" }, new SelectListItem { Text = "6x6", Value = "6" }, new SelectListItem { Text = "7x7", Value = "7" }, new SelectListItem { Text = "8x8", Value = "8" }, new SelectListItem { Text = "9x9", Value = "9" }, new SelectListItem { Text = "10x10", Value = "10" }, new SelectListItem { Text = "11x11", Value = "11" }, new SelectListItem { Text = "12x12", Value = "12" }, }, }; return(View(VM)); }
public IActionResult GenerateRandomState(int dim, int stepsInSameState) { int[][] array = _IFunctions.GenerateArray(dim); //Generates random state HillClimbingVM VM = new HillClimbingVM() { array = _IFunctions.array2Dto1D(array, dim), dimension = dim, heuristic = _IFunctions.Heuristic(array, dim), //Heuristic function calculates heuristic of this array stepsInSameState = stepsInSameState, dimensions = new List <SelectListItem>() { new SelectListItem { Text = "4x4", Value = "4" }, new SelectListItem { Text = "5x5", Value = "5" }, new SelectListItem { Text = "6x6", Value = "6" }, new SelectListItem { Text = "7x7", Value = "7" }, new SelectListItem { Text = "8x8", Value = "8" }, new SelectListItem { Text = "9x9", Value = "9" }, new SelectListItem { Text = "10x10", Value = "10" }, new SelectListItem { Text = "11x11", Value = "11" }, new SelectListItem { Text = "12x12", Value = "12" }, }, }; return(View("Index", VM)); }
public IActionResult HillClimbingA(string stringArray, int dim, int stepsInSameState) { int[] array = _IFunctions.StringToInt(stringArray, dim); int[][] Array = new int[dim][]; Array = _IFunctions.array1Dto2D(array, dim); int h = _IFunctions.Heuristic(Array, dim); int h2 = 1000; int[][] array2; int brojac = 0; int brojac2 = 0; while (h != 0 && stepsInSameState > brojac) { array2 = GetBestH(Array, dim, h); //Searching for next state with the best heuristic h2 = _IFunctions.Heuristic(array2, dim); if (h2 >= h) { brojac++; //if we don't have better solution we keep the state with same h for stepsInSameState number of itterations } if (h2 <= h) { h = h2; Array = _IFunctions.CopyRow(array2, dim); h2 = 1000; } brojac2++; } HillClimbingVM VM = new HillClimbingVM() { array = _IFunctions.array2Dto1D(Array, dim), dimension = dim, heuristic = _IFunctions.Heuristic(Array, dim), dimensions = new List <SelectListItem>() { new SelectListItem { Text = "4x4", Value = "4" }, new SelectListItem { Text = "5x5", Value = "5" }, new SelectListItem { Text = "6x6", Value = "6" }, new SelectListItem { Text = "7x7", Value = "7" }, new SelectListItem { Text = "8x8", Value = "8" }, new SelectListItem { Text = "9x9", Value = "9" }, new SelectListItem { Text = "10x10", Value = "10" }, new SelectListItem { Text = "11x11", Value = "11" }, new SelectListItem { Text = "12x12", Value = "12" }, }, counter = brojac2, stepsInSameState = stepsInSameState }; return(PartialView("HillClimbingDone", VM)); }