private void SetProperties() { properties = new MainProperties() { RangeWidth = (int)Image.Width, RangeHeight = (int)Image.Height, AmountOfGrains = Converters.StringToInt(NumOfGrainsTextBox.Text), NeighbourhoodType = ChooseNeighbourhoodType(), GrowthProbability = Converters.StringToInt(GrowthProbabilityTextBox.Text), MCS = Converters.StringToInt(MCSTextBox.Text), SubstructuresType = ChooseSubstructuresType(), MethodType = ChooseMethodType() }; inclusions = new InitInclusions() { CreationTime = ChooseInlcusionCreationTime(), InclusionsType = ChooseInclusionsType(), IsEnable = (bool)InclusionsCheckBox.IsChecked, AmountOfInclusions = Converters.StringToInt(NumOfInclusionsTextBox.Text), Size = Converters.StringToInt(SizeOfInclusionsTextBox.Text) }; boundaries = new InitBoundaries(properties); nucleons = new InitNucleons() { IsEnable = (bool)SRXCheckBox.IsChecked, AmountOfNucleons = Converters.StringToInt(NumOfNucleonsTextBox.Text), NucleonsStates = new Color[Converters.StringToInt(NumOfStatesTextBox_SRX.Text)], TypeOfcreation = ChooseTypeOfNucleonsCreation(), EnergyDistribution = ChooseEnegryDistribution(), EnergyInside = Converters.StringToInt(EnergyInsideTextBox.Text), EnergyOnEdges = Converters.StringToInt(EnergyOnEdgesTextBox.Text), PositionDistribiution = ChoosePositionDistribution(), EnergyRange = new Range() }; tempIteration = Converters.StringToInt(MCSTextBox.Text); }
public Range Grow(Range tempRange, InitNucleons nucleons) { List <Grain> neighbourhood = new List <Grain>(); List <Point> pointsCoordinates = new List <Point>(); List <Point> neighbourhoodPoints = new List <Point>(); Grain centerGrain; int EnergyAfter, EnergyBefore, EnergyDelta, randomNumberOfList; if (nucleons.IsEnable == true) { for (int i = 1; i < tempRange.Width - 1; i++) { for (int j = 1; j < tempRange.Height - 1; j++) { neighbourhood = TakeNeumannNeighbourhood(i, j, tempRange.GrainsArray); if (neighbourhood.Where(g => g.Id == -5).Select(g => g.Id).Count() > 0 && tempRange.GrainsArray[i, j].Id != -5) { pointsCoordinates.Add(new Point(i, j)); } } } pointsCoordinates.OrderBy(a => Random.Next()); while (pointsCoordinates.Count > 0) { EnergyAfter = 0; EnergyBefore = 0; EnergyDelta = 0; //step 1 centerGrain = tempRange.GrainsArray[pointsCoordinates.First().X, pointsCoordinates.First().Y]; //step 2 neighbourhood = TakeMooreNeighbourhood(pointsCoordinates.First().X, pointsCoordinates.First().Y, tempRange.GrainsArray); EnergyBefore = neighbourhood.Where(g => !SpecialId.IsIdSpecial(g.Id) && g.Id != centerGrain.Id) .Select(g => g.Id).Count() + centerGrain.Energy_H; //step 3 randomNumberOfList = Random.Next(InitStructures.AllGrainsTypes.Length); centerGrain = InitStructures.AllGrainsTypes[randomNumberOfList]; EnergyAfter = neighbourhood.Where(g => !SpecialId.IsIdSpecial(g.Id) && g.Id != centerGrain.Id) .Select(g => g.Id).Count(); //step 4 EnergyDelta = EnergyAfter - EnergyBefore; //step 5 if (EnergyDelta <= 0) { tempRange.GrainsArray[pointsCoordinates.First().X, pointsCoordinates.First().Y] = neighbourhood.Where(g => g.Id == (int)SpecialId.Id.Nucleon).OrderBy(a => Random.Next()).First(); } pointsCoordinates.RemoveAt(0); } } else { for (int i = 1; i < tempRange.Width - 1; i++) { for (int j = 1; j < tempRange.Height - 1; j++) { pointsCoordinates.Add(new Point(i, j)); } } pointsCoordinates.OrderBy(a => Random.Next()); while (pointsCoordinates.Count > 0) { EnergyAfter = 0; EnergyBefore = 0; EnergyDelta = 0; //step 1 centerGrain = tempRange.GrainsArray[pointsCoordinates.First().X, pointsCoordinates.First().Y]; //step 2 neighbourhood = TakeMooreNeighbourhood(pointsCoordinates.First().X, pointsCoordinates.First().Y, tempRange.GrainsArray); neighbourhoodPoints = TakeMooreNeighbourhood(pointsCoordinates.First().X, pointsCoordinates.First().Y); EnergyBefore = neighbourhood.Where(g => (g.Id != centerGrain.Id)) .Select(g => g.Id).Count(); //step 3 randomNumberOfList = Random.Next(InitStructures.AllGrainsTypes.Length); centerGrain = InitStructures.AllGrainsTypes[randomNumberOfList]; EnergyAfter = neighbourhood.Where(g => (g.Id != centerGrain.Id)) .Select(g => g.Id).Count(); //step 4 EnergyDelta = EnergyAfter - EnergyBefore; //step 5 if (EnergyDelta <= 0 && !SpecialId.IsIdSpecial(tempRange.GrainsArray[pointsCoordinates.First().X, pointsCoordinates.First().Y].Id)) { tempRange.GrainsArray[pointsCoordinates.First().X, pointsCoordinates.First().Y] = centerGrain; } pointsCoordinates.RemoveAt(0); } } UpdateBitmap(tempRange); return(tempRange); }