Пример #1
0
        public static void Configure(ShardID addr, BaseDB.ConfigContainer config, bool forceAllLinksPassive)
        {
            CSLogicProvider.AsyncFactory = DB.GetLogicProviderAsync;

            ID      = addr;
            gridExt = config.extent;
            Ranges  = ToRanges(config);
            MySpace = SDToBox(addr.XYZ, config.extent);


            InconsistencyCoverage.CommonResolution = (int)Math.Ceiling(1f / Ranges.R);

            if (Extent.ReplicaLevel > 1)
            {
                siblings = Neighborhood.NewSiblingList(addr, Extent.ReplicaLevel, forceAllLinksPassive);
            }
            neighbors = Neighborhood.NewNeighborList(addr, Extent.XYZ, forceAllLinksPassive);
        }
Пример #2
0
        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);
            }
        }
Пример #3
0
 public SimulationContext(BaseDB.ConfigContainer cfg, Box mySpace, bool allowMotionToUnresponsiveNeighbor) : base(Simulation.ToRanges(cfg), mySpace)
 {
     AllowMotionToUnresponsiveNeighbor = allowMotionToUnresponsiveNeighbor;
 }
Пример #4
0
 public static EntityRanges ToRanges(BaseDB.ConfigContainer config)
 {
     return(new EntityRanges(config.r, config.m, ExtToWorld(config.extent)));
 }