private static bool Complete(SDSComputation comp, TimingInfo timing, bool force) { if (Clock.Now >= comp.Deadline || force) { var rs = comp.Complete(); stack.Insert(rs); if (rs.Item1.IsFullyConsistent) { DB.PutNow(new SerialSDS(rs.Item1, ID.XYZ), true); } comp = null; return(true); } return(false); }
private static void RunStupidModel() { int gridRes = 100; //2d resolution //each grid cell can 'see' +- 4 cells in all direction. All 'motion' is done via communication //hence R = 4 / gridRes float r = 4.5f / gridRes; BaseDB.ConfigContainer config = new BaseDB.ConfigContainer() { extent = Int3.One, r = r, m = r * 0.5f }; Simulation.Configure(new ShardID(Int3.Zero, 0), config, true); Vec3 outlierCoords = Simulation.MySpace.Min; var ctx = new SimulationContext(true); var intermediate0 = new IntermediateSDS(); intermediate0.entities = new EntityPool(MakeGrid2D(gridRes), ctx); //EntityTest.RandomDefaultPool(100); intermediate0.ic = InconsistencyCoverage.NewCommon(); intermediate0.inputConsistent = true; intermediate0.localChangeSet = new EntityChangeSet(); SDSStack.Entry root = new SDSStack.Entry( new SDS(0, intermediate0.entities.ToArray(), intermediate0.ic), intermediate0); //Assert.IsTrue(root.IsFullyConsistent); SDSStack stack = Simulation.Stack; stack.ResetToRoot(root); for (int i = 0; i < 13; i++) { //Assert.IsNotNull(stack.NewestSDS.FinalEntities, i.ToString()); var temp = stack.AllocateGeneration(i + 1); ctx.SetGeneration(i + 1); var comp = new SDSComputation(new DateTime(), ExtMessagePack.CompleteBlank, TimeSpan.FromMilliseconds(10), ctx); //ComputationTests.AssertNoErrors(comp, "comp"); //Assert.IsTrue(comp.Intermediate.inputConsistent); var sds = comp.Complete(); stack.Insert(sds); //Assert.IsTrue(sds.IsFullyConsistent); //Assert.AreEqual(sds.FinalEntities.Length, gridRes * gridRes); int numBugs = 0; int numPredators = 0; int numConflicts = 0; float totalFood = 0; foreach (var e in sds.Item1.FinalEntities) { Habitat h = (Habitat)Helper.Deserialize(e.SerialLogicState); if (h.bug.HasAnimal) { numBugs++; } if (h.predator.HasAnimal) { numPredators++; if (h.bug.HasAnimal) { numConflicts++; } } totalFood += h.food; } Console.WriteLine("Population: b=" + numBugs + ", p=" + numPredators + ", c=" + numConflicts + "; Food=" + totalFood); } }