public Action <Graphics> GetStrategyDrawer() { return((g) => { DateTime NewYear = new DateTime(2018, 1, 1); CSingleAssignment[] Genes = this.GetBestFitness()?.GetGenes(); if (Genes != null) { int CounterY = 0; int OffsetX = 0; CSingleAssignment FirstAssignemnt; CSingleAssignment CurrentAssignemnt; CSimpleSector ActiveSector; b.Color = Color.Yellow; g.DrawString("גדוד מסוג מסויים משובץ בגזרה שדורשת סוג אחר", f, b, 0, -60); b.Color = Color.Red; g.DrawString("גדוד משובץ על אילוץ שהגדיר", f, b, 0, -80); b.Color = Color.Black; for (int i = 0; i < CStrategyPool.ActiveStrategy.GetSectorsCount(); i++) { FirstAssignemnt = Genes[i * TaamCalendar.ChunksCount]; int xPad = (int)(FirstAssignemnt.Start - NewYear).TotalDays * 4; Point2D Location = new Point2D(xPad, CounterY); ActiveSector = CStrategyPool.ActiveStrategy.SectorsData[i]; g.DrawString(ActiveSector.Name + ":", f, b, (int)Location.X - 130, (int)Location.Y + 40); g.DrawString(ActiveSector.MySectorialBrigade.ToString() + ":", f, b, (int)Location.X - 130, (int)Location.Y + 60); g.DrawRectangle(p, (int)Location.X, (int)Location.Y, 800, 100); for (int j = 0; j < TaamCalendar.ChunksCount; j++) { CurrentAssignemnt = Genes[i * TaamCalendar.ChunksCount + j]; CSimpleBattalion AssignedBattalion = CStrategyPool.ActiveStrategy.BattalionsData[CurrentAssignemnt.BattalionUID]; g.DrawLine(p, (int)Location.X + 200 * j, (int)Location.Y, (int)Location.X + 200 * j, (int)Location.Y + 100); g.DrawString(CurrentAssignemnt.Start.ToShortDateString(), f, b, (int)Location.X + 200 * j, (int)Location.Y); if (j == TaamCalendar.ChunksCount - 1) { g.DrawString(CurrentAssignemnt.End.ToShortDateString(), f, b, (int)Location.X + 200 * TaamCalendar.ChunksCount, (int)Location.Y); } if (AssignedBattalion != null) { SolidBrush bbb = new SolidBrush(CStrategyPool.ActiveStrategy.BattalionsData[AssignedBattalion.UID].ScoreAssignment(CurrentAssignemnt.Start, CurrentAssignemnt.End) > 0 ? Color.Red : Color.Black); CSimpleBattalion Battalion = CStrategyPool.ActiveStrategy.BattalionsData[CurrentAssignemnt.BattalionUID]; CSimpleSector Sector = CStrategyPool.ActiveStrategy.SectorsData[CurrentAssignemnt.SectorUID]; if ((Battalion.Force & Sector.ForceConstraint) == 0) { bbb.Color = Color.Yellow; } OffsetX = 65 + (200 * j); g.DrawString(AssignedBattalion.Name, f, bbb, (int)Location.X + OffsetX, (int)Location.Y + 40); } } CounterY += 100; } } }); }
public Form1() { InitializeComponent(); Font f = new Font(FontFamily.GenericMonospace, 15); SolidBrush b = new SolidBrush(Color.Black); Pen p = new Pen(new SolidBrush(Color.Black), 3); Annealer = new AnnealingProccess(); this.ipStrategy.DrawFunction = (g) => { if (Annealer?.BestFitness != null) { CTaamAssignment BestFitness = (CTaamAssignment)Annealer?.BestFitness; // this.Terrain.Draw(g); int CounterY = 0; var Genes = BestFitness.GetGenes(); for (int i = 0; i < CStrategyPool.ActiveStrategy.GetSectorsCount(); i++) { var ActiveSector = CStrategyPool.ActiveStrategy.SectorsData[i]; CSimpleBattalion[] AssignedBattalions = new CSimpleBattalion[TaamCalendar.ChunksCount]; Point2D Location = new Point2D(); for (int j = 0; j < TaamCalendar.ChunksCount; j++) { CSingleAssignment SectorAssignment = Genes[i * TaamCalendar.ChunksCount + j]; AssignedBattalions[j] = CStrategyPool.ActiveStrategy.BattalionsData[SectorAssignment.BattalionUID]; } Location.Y = CounterY; g.DrawString(ActiveSector.UID.ToString() + ":", f, b, (int)Location.X - 130, (int)Location.Y + 40); g.DrawString(ActiveSector.MySectorialBrigade.ToString() + ":", f, b, (int)Location.X - 130, (int)Location.Y + 60); g.DrawRectangle(p, (int)Location.X, (int)Location.Y, 800, 100); for (int j = 0; j < TaamCalendar.ChunksCount; j++) { g.DrawLine(p, (int)Location.X + 200 * j, (int)Location.Y, (int)Location.X + 200 * j, (int)Location.Y + 100); if (AssignedBattalions[j] != null) { SolidBrush bbb = new SolidBrush(CStrategyPool.ActiveStrategy.BattalionsData[AssignedBattalions[j].UID].ScoreAssignment(Genes[i * TaamCalendar.ChunksCount + j]) > 0 ? Color.Red : Color.Black); CSimpleBattalion Battalion = CStrategyPool.ActiveStrategy.BattalionsData[Genes[i * TaamCalendar.ChunksCount + j].BattalionUID]; CSimpleSector Sector = CStrategyPool.ActiveStrategy.SectorsData[Genes[i * TaamCalendar.ChunksCount + j].SectorUID]; if ((Battalion.Force & Sector.ForceConstraint) == 0) { bbb.Color = Color.Yellow; } int OffsetX = 90 + (200 * j); g.DrawString(AssignedBattalions[j].UID.ToString(), f, bbb, (int)Location.X + OffsetX, (int)Location.Y + 40); } } CounterY += 120; } } }; this.ipStrategy.UpdateFunction = () => CStrategyPool.ActiveStrategy.Update(); this.ipStatus.DrawFunction = (g) => { Annealer?.StatusGraph.Draw(g); }; this.ipBattalionToSectorSum.DrawFunction = g => { if (Annealer?.BestFitness != null) { CTaamAssignment BestFitness = (CTaamAssignment)Annealer.BestFitness; int yCounter = 0; var Assignments = BestFitness.GetGenes(); // [] Battalion, [] 4 Rotations DrawFollower[] BattalionToSectorRotation = Shared.SafeArray(CStrategyPool.ActiveStrategy.GetBattalionsCount(), () => new DrawFollower()); for (int i = 0; i < Assignments.Length; i++) { BattalionToSectorRotation[Assignments[i].BattalionUID][i % TaamCalendar.ChunksCount]++; } for (int i = 0; i < BattalionToSectorRotation.Length; i++) { SolidBrush bb = new SolidBrush(Color.Black); string strRow = string.Format("b" + (i < 10 ? "0" + i : i + "")); string strRotations = ""; int nMoreThenOne = 0; for (int j = 0; j < BattalionToSectorRotation[i].RotationsCount.Length; j++) { if (BattalionToSectorRotation[i][j] != 0) { strRotations += "r" + j + ": " + BattalionToSectorRotation[i][j] + ", "; nMoreThenOne++; } if (BattalionToSectorRotation[i][j] > 1 || nMoreThenOne > 2) { bb.Color = Color.Red; } } strRow += "; " + strRotations; g.DrawString(strRow, f, bb, 0, yCounter); yCounter += 20; } } }; this.initConfigDelegation(); CStrategyPool.CreateRandomStrategy(); }