public CellStateVectorVM[,] FeedBackLinear(ref int infected) { var Xn = CellSemiLinear[N1]; var Xn_1 = CellSemiLinear[N1 - 2]; HeightField = f.HeightImg; WidthField = f.WidthImg; var div = 4.0m; decimal a1 = 3 / div; decimal a2 = 1 / div; var Xn_average = new CellStateVectorVM[HeightField, WidthField]; var infC = 0; for (int i = 0; i < HeightField; i++) { for (int j = 0; j < WidthField; j++) { Xn_average[i, j] = new CellStateVectorVM() { Infected = a1 * CellSemiLinear[N1][i, j].Infected + a2 * CellSemiLinear[N1 - 2][i, j].Infected, Susceptible = a1 * CellSemiLinear[N1][i, j].Susceptible + a2 * CellSemiLinear[N1 - 2][i, j].Susceptible, Recovered = a1 * CellSemiLinear[N1][i, j].Recovered + a2 * CellSemiLinear[N1 - 2][i, j].Recovered, }; } } var res = Epidemia(Xn_average, ref infC); infected = infC; return(res); }
public void ImageData(string path) { if (path != "") { var image = new Bitmap(path); HeightImg = image.Height; WidthImg = image.Width; var initData = new CellStateVectorVM[HeightImg, WidthImg]; fieldsizeHeighttb.Text = HeightImg.ToString(); fieldsizeHeighttb.ReadOnly = true; fieldsizeWidthtb.Text = WidthImg.ToString(); fieldsizeWidthtb.ReadOnly = true; scale = 1; scaletb.Text = scale.ToString(); for (int i = 0; i < HeightImg; i++) { for (int j = 0; j < WidthImg; j++) { initData[i, j] = new CellStateVectorVM() { Susceptible = 1 - ((decimal)image.GetPixel(j, i).R) / 255, Infected = 1 - ((decimal)image.GetPixel(j, i).G) / 255, Recovered = 1 - ((decimal)image.GetPixel(j, i).B) / 255 } } } ; mainForm.SetInitialFromFile(initData); initFromImage = true; } }
public void SetInitial() { infectedCells = 0; SetInit = new CellStateVectorVM[f.HeightImg, f.WidthImg]; Random rand = new Random(); for (int i = 0; i < f.HeightImg; i++) { for (int j = 0; j < f.WidthImg; j++) { var population = (Convert.ToDecimal(rand.Next(100)) + 1) / 101; var S = (Convert.ToDecimal(rand.Next(100)) + 0.01m) / 102; var I = 0.0m; do { I = (Convert.ToDecimal(rand.Next(100)) + 1) / 101; } while (S + I >= 1); SetInit[i, j] = new CellStateVectorVM() { Susceptible = population, //S * population, Infected = 0, // I * population, Recovered = 0 //(1 - S - I) * population }; } } SetInit[f.HeightImg / 2, f.WidthImg / 2] = new CellStateVectorVM() { Infected = 0.01m * SetInit[f.HeightImg / 2, f.WidthImg / 2].Susceptible, Susceptible = 0.99m * SetInit[f.HeightImg / 2, f.WidthImg / 2].Susceptible }; }
public CellStateVectorVM[,] Epidemia(CellStateVectorVM[,] ArrayStart, ref int infectCells) { InfectedCount = 0.0m; SusceptibleCount = 0.0m; RecoveredCount = 0.0m; InfectedControllCount = 0.0m; SusceptibleControllCount = 0.0m; RecoveredControllCount = 0.0m; InfectedSemiControllCount = 0.0m; SusceptibleSemiControllCount = 0.0m; RecoveredSemiControllCount = 0.0m; infectCells = 0; //Algorithm of Cellular Automata Game 2D HeightField = f.HeightImg; WidthField = f.WidthImg; //var ret = new CellStateVectorVM[HeightField, WidthField]; decimal[] inF = f.innerParameters; decimal incode = 0; decimal[] weightCoefficient = new decimal[inF.Length]; for (int i = 0; i < inF.Length; i++) { incode += inF[i]; } for (int i = 0; i < inF.Length; i++) { weightCoefficient[i] = inF[i] / incode; } var epidemiaRecalcStart = new CellStateVectorVM[HeightField, WidthField]; for (int i = 0; i < HeightField; i++) { for (int j = 0; j < WidthField; j++) { epidemiaRecalcStart[i, j] = ArrayRecalculated(i, j, weightCoefficient, ArrayStart); infectCells += epidemiaRecalcStart[i, j].Infected != 0 ? 1 : 0; } } return(epidemiaRecalcStart); }
public CellStateVectorVM[,] FeedbackControl() { var div = 3.0m; var recalc = new CellStateVectorVM[f.HeightImg, f.WidthImg]; for (int i = 0; i < f.HeightImg; i++) { for (int j = 0; j < f.WidthImg; j++) { recalc[i, j] = new CellStateVectorVM() { Infected = (2 / div) * CellControlled[N1][i, j].Infected + (1 / div) * CellControlled[N1 - 1][i, j].Infected, Susceptible = (2 / div) * CellControlled[N1][i, j].Susceptible + (1 / div) * CellControlled[N1 - 1][i, j].Susceptible, Recovered = (2 / div) * CellControlled[N1][i, j].Recovered + (1 / div) * CellControlled[N1 - 1][i, j].Recovered }; } } return(recalc); }
public CellStateVectorVM[,] FeedbackControl3() { var div = 3.0m; var a1 = 0.56m; var a2 = 0.33m; var a3 = 0.11m; var recalc = new CellStateVectorVM[f.HeightImg, f.WidthImg]; for (int i = 0; i < f.HeightImg; i++) { for (int j = 0; j < f.WidthImg; j++) { recalc[i, j] = new CellStateVectorVM() { Infected = a1 * CellControlled[N1][i, j].Infected + a2 * CellSemiLinear[N1 - 1][i, j].Infected + a3 * CellControlled[N1 - 2][i, j].Infected, Susceptible = a1 * CellControlled[N1][i, j].Susceptible + a2 * CellSemiLinear[N1 - 1][i, j].Susceptible + a3 * CellControlled[N1 - 2][i, j].Susceptible, Recovered = a1 * CellControlled[N1][i, j].Recovered + a2 * CellSemiLinear[N1 - 1][i, j].Recovered + a3 * CellControlled[N1 - 2][i, j].Recovered }; } } return(recalc); }
public void FileInitData(string path) { if (path != "") { var fileData = new XLWorkbook(path).Worksheet(1); var range = fileData.Range(fileData.FirstCellUsed(), fileData.LastCellUsed()); HeightImg = range.RowCount() - 1; WidthImg = range.ColumnCount(); var initData = new CellStateVectorVM[HeightImg, WidthImg]; var i = 0; foreach (var item in range.Rows()) { if (i != 0) { for (int j = 1; j <= WidthImg; j++) { var val = item.Cell(j).Value.ToString().Split('|'); initData[i - 1, j - 1] = new CellStateVectorVM() { Susceptible = Convert.ToDecimal(val[0]), Infected = Convert.ToDecimal(val[1]), Recovered = Convert.ToDecimal(val[2]) }; } } i++; } fieldsizeHeighttb.Text = HeightImg.ToString(); fieldsizeHeighttb.ReadOnly = true; fieldsizeWidthtb.Text = WidthImg.ToString(); fieldsizeWidthtb.ReadOnly = true; scale = 1; scaletb.Text = scale.ToString(); mainForm.SetInitialFromFile(initData); initFromImage = true; } }
public CellStateVectorVM[,] PredicativeControl() { //let's cycle equals 2 T=2 Tetta = 4.15m * (decimal)Math.Pow(10, 7);//(decimal) Math.Pow(2,9); HeightField = f.HeightImg; WidthField = f.WidthImg; //int CAsize = f.fieldSize; decimal div = 3.0m; decimal Epsilon = 0.000000000001m; decimal a1 = Tetta / (1 + Tetta); decimal a2 = 1 / (1 + Tetta); var Xn_predicative = new CellStateVectorVM[HeightField, WidthField]; var Xn_predicativeTemporary = Cell[N1]; var Xn_controled = new CellStateVectorVM[HeightField, WidthField]; var infectedCount = 0; //Calculating for predicative part of control for (int p = 0; p < Tcycle; p++) { Xn_predicative = Epidemia(Xn_predicativeTemporary, ref infectedCount); Xn_predicativeTemporary = Xn_predicative; } //calculating control body for main function for (int i = 0; i < HeightField; i++) { for (int j = 0; j < WidthField; j++) { Xn_controled[i, j] = new CellStateVectorVM() { Infected = a1 * Cell[N1][i, j].Infected + a2 * Xn_predicative[i, j].Infected, Susceptible = a1 * Cell[N1][i, j].Susceptible + a2 * Xn_predicative[i, j].Susceptible, Recovered = a1 * Cell[N1][i, j].Recovered + a2 * Xn_predicative[i, j].Recovered }; } } return(Xn_controled); }
public CellStateVectorVM[,] FeedBackControlSemiLinear() { var X_nonL = new List <CellStateVectorVM[, ]>(); var X_L = new List <CellStateVectorVM[, ]>(); var optCoeff = new List <decimal>(); for (int i = 1; i <= 10; i++) { X_nonL.Add(CellSemiLinear[N1 - i * Tcycle + Tcycle]); X_L.Add(CellSemiLinear[N1 - i * Tcycle + 1]); } optCoeff.Add(0.6327m); optCoeff.Add(0.1211m); optCoeff.Add(0.0676m); optCoeff.Add(0.0466m); optCoeff.Add(0.0354m); optCoeff.Add(0.0284m); optCoeff.Add(0.0237m); optCoeff.Add(0.02m); optCoeff.Add(0.0166m); optCoeff.Add(0.0079m); var gamma = 0.1m; var div = 19.0m; HeightField = f.HeightImg; WidthField = f.WidthImg; var Xn_average = new CellStateVectorVM[HeightField, WidthField]; var Xn_controled = new CellStateVectorVM[HeightField, WidthField]; for (int i = 0; i < HeightField; i++) { for (int j = 0; j < WidthField; j++) { var infected = 0.0m; var susceptible = 0.0m; var recovered = 0.0m; for (int k = 0; k < 10; k++) { infected += optCoeff[k] * X_nonL[k][i, j].Infected; susceptible += optCoeff[k] * X_nonL[k][i, j].Susceptible; recovered += optCoeff[k] * X_nonL[k][i, j].Recovered; } Xn_average[i, j] = new CellStateVectorVM() { Infected = infected, Susceptible = susceptible, Recovered = recovered }; } } var Xl_average = new CellStateVectorVM[HeightField, WidthField]; for (int i = 0; i < HeightField; i++) { for (int j = 0; j < WidthField; j++) { var infected = 0.0m; var susceptible = 0.0m; var recovered = 0.0m; for (int k = 0; k < 9; k++) { infected += 2 / div * X_nonL[k][i, j].Infected; susceptible += 2 / div * X_nonL[k][i, j].Susceptible; recovered += 2 / div * X_nonL[k][i, j].Recovered; } infected += 1 / div * X_nonL[9][i, j].Infected; susceptible += 1 / div * X_nonL[9][i, j].Susceptible; recovered += 1 / div * X_nonL[9][i, j].Recovered; Xn_average[i, j] = new CellStateVectorVM() { Infected = infected, Susceptible = susceptible, Recovered = recovered }; } } var infectCells = 0; var temp = Epidemia(Xn_average, ref infectCells); for (int i = 0; i < HeightField; i++) { for (int j = 0; j < WidthField; j++) { Xn_controled[i, j] = new CellStateVectorVM() { Infected = (1 - gamma) * temp[i, j].Infected + gamma * Xl_average[i, j].Infected, Susceptible = (1 - gamma) * temp[i, j].Susceptible + gamma * Xl_average[i, j].Susceptible, Recovered = (1 - gamma) * temp[i, j].Recovered + gamma * Xl_average[i, j].Recovered }; } } return(Xn_controled); }
public decimal GetCellPopulation(CellStateVectorVM cell) { return(cell.Infected + cell.Recovered + cell.Susceptible); }