public static void InitializeNeighbourhoods1D(AbstractCell[] cellSpace, Hyperparameters hyperParams) { int width = hyperParams.neighbourhoodWidth; int highestIndex = hyperParams.spaceSize; Task[] tasks = new Task[2]; tasks[0] = Task.Run(() => InitializeSafeCellNeigbhourhoods(cellSpace, highestIndex, width)); tasks[1] = Task.Run(() => InitializeEdgeNeighbourhoods(cellSpace, highestIndex, width)); Task.WaitAll(tasks); }
//TODO make public static void InitializeNeighbourhoods2D(AbstractCell[,] cellSpace, Hyperparameters hyperParams) { int highestIndex = hyperParams.spaceSize - 1; int width = hyperParams.neighbourhoodWidth; Task[] tasks = new Task[3]; tasks[0] = Task.Run(() => InitializeSafeCellNeighbourhoods(cellSpace, highestIndex, width)); tasks[1] = Task.Run(() => InitializeOutlierCellNeighbourhoods(cellSpace, highestIndex, hyperParams)); tasks[2] = Task.Run(() => InitializeCornerCellNeighbourhoods(cellSpace, highestIndex, hyperParams)); Task.WaitAll(tasks); }
public static List <AbstractCell> getLowerNeighbourhood(AbstractCell[,] cellSpace, int i, Hyperparameters hyperParams) { List <AbstractCell> neighbourhoodState = new List <AbstractCell>(); if (hyperParams.neighbourhoodWidth >= 1) { neighbourhoodState.Add(cellSpace[hyperParams.spaceSize - 2, i]); neighbourhoodState.Add(cellSpace[hyperParams.spaceSize - 1, i + 1]); neighbourhoodState.Add(cellSpace[0, i]); neighbourhoodState.Add(cellSpace[hyperParams.spaceSize - 1, i - 1]); } if (hyperParams.neighbourhoodWidth >= 2) { neighbourhoodState.Add(cellSpace[hyperParams.spaceSize - 2, i - 1]); neighbourhoodState.Add(cellSpace[hyperParams.spaceSize - 2, i + 1]); neighbourhoodState.Add(cellSpace[0, i + 1]); neighbourhoodState.Add(cellSpace[0, i - 1]); } return(neighbourhoodState); }
public static List <AbstractCell> getUpperRightNeighbourhood(AbstractCell[,] cellSpace, Hyperparameters hyperParams) { List <AbstractCell> neighbourhoodState = new List <AbstractCell>(); if (hyperParams.neighbourhoodWidth >= 1) { neighbourhoodState.Add(cellSpace[hyperParams.spaceSize - 1, hyperParams.spaceSize - 1]); neighbourhoodState.Add(cellSpace[0, 0]); neighbourhoodState.Add(cellSpace[1, hyperParams.spaceSize - 1]); neighbourhoodState.Add(cellSpace[0, hyperParams.spaceSize - 2]); } if (hyperParams.neighbourhoodWidth >= 2) { neighbourhoodState.Add(cellSpace[hyperParams.spaceSize - 1, hyperParams.spaceSize - 2]); neighbourhoodState.Add(cellSpace[hyperParams.spaceSize - 1, 0]); neighbourhoodState.Add(cellSpace[1, 0]); neighbourhoodState.Add(cellSpace[1, hyperParams.spaceSize - 2]); } return(neighbourhoodState); }
private static void InitializeCornerCellNeighbourhoods(AbstractCell[,] cellSpace, int highestIndex, Hyperparameters hyperParams) { cellSpace[0, 0].Neighbourhood = NeighbourhoodConstructor.getUpperLeftNeighbourhood(cellSpace, hyperParams); cellSpace[0, highestIndex].Neighbourhood = NeighbourhoodConstructor.getUpperRightNeighbourhood(cellSpace, hyperParams); cellSpace[highestIndex, 0].Neighbourhood = NeighbourhoodConstructor.getLowerLeftNeighbourhood(cellSpace, hyperParams); cellSpace[highestIndex, highestIndex].Neighbourhood = NeighbourhoodConstructor.getLowerRightNeighbourhood(cellSpace, hyperParams); }
private static void InitializeOutlierCellNeighbourhoods(AbstractCell[,] cellSpace, int highestIndex, Hyperparameters hyperParams) { Parallel.For(1, highestIndex, (int i) => { cellSpace[0, i].Neighbourhood = NeighbourhoodConstructor.getUpperNeighbourhood(cellSpace, i, hyperParams); cellSpace[i, 0].Neighbourhood = NeighbourhoodConstructor.getLeftNeighbourhood(cellSpace, i, hyperParams); cellSpace[highestIndex, i].Neighbourhood = NeighbourhoodConstructor.getLowerNeighbourhood(cellSpace, i, hyperParams); cellSpace[i, highestIndex].Neighbourhood = NeighbourhoodConstructor.getRightNeighbourhood(cellSpace, i, hyperParams); }); }