Beispiel #1
0
        private static Runner InitializeRuntime()
        {
            var runner = new Runner();

            runner.Started += (o, e) =>
            {
                _log.Trace($"Runner started.");
            };
            runner.IterationPassed += (o, e) =>
            {
                _log.Trace($"Runner passed iteration");
            };
            runner.Stopped += (o, e) =>
            {
                _log.Trace($"Runner stopped.");
            };

            // radio channel
            var radioSim = new AdaptedFriisSimulator();

            radioSim.With((args) =>
            {
                var radioArgs = args as AdaptedFriisArgs;
                radioArgs.RadioBox.Resolution = 0.2F;
            });

            // energy
            var batterySim = new BatteryPackSimulator();

            batterySim.With((args) =>
            {
                var batteryArgs = args as BatteryArgs;
                var battery     = batteryArgs.AddBattery();
                batteryArgs.UpdateDischargeCurrent(battery.Uid, 100);
            });

            // network
            var networkSim = new MeshNetworkSimulator();

            BuildMeshNetwork(networkSim.Arguments as MeshNetworkArgs);

            // pack all simulators in a reop
            var simRepo = new SimulatorRepository();

            simRepo.AddRange(new ISimulatable[] {
                radioSim,
                networkSim,
                batterySim
            });

            runner.BindSimulators(simRepo);

            return(runner);
        }
Beispiel #2
0
        public void RunNetwork()
        {
            // arrange
            var netSim = new MeshNetworkSimulator();

            netSim.With((args) =>
            {
                base.BuildMeshNetwork(args as MeshNetworkArgs);
            });
            netSim.OnExecuting += (o, e) =>
            {
                _log.Trace($"{e.Arguments.Name} started");
            };

            netSim.Executed += (o, e) =>
            {
                _log.Trace($"{e.Arguments.Name} finished");
            };

            // act
            netSim.OnStart()
            .Run();

            // assert
            var netArgs = netSim.Arguments as MeshNetworkArgs;

            netArgs.Network.DistanceMatrix.Each((r, c, v) =>
            {
                Assert.IsTrue(v > 0, $"position at row '{r}' and col '{c}' should not be '{v}'");
                _log.Trace($"{r}:{c} -> distance: {v}");
                return(v);
            });

            netArgs.Network.AngleMatrix.Each((r, c, v) =>
            {
                Assert.IsTrue(!float.IsNaN(v.Azimuth), $"Azimuth at position at row '{r}' and col '{c}' should not be NaN");
                Assert.IsTrue(!float.IsNaN(v.Elevation), $"Elevation at position at row '{r}' and col '{c}' should not be NaN");
                _log.Trace($"{r}:{c} -> angle: {v}");
                return(v);
            });
        }
Beispiel #3
0
        public async Task SimulateRuntimeAsync()
        {
            // -- arrange

            // radio channel
            var radioSim = new AdaptedFriisSimulator();

            radioSim.With((args) =>
            {
                var radioArgs = args as AdaptedFriisArgs;
                radioArgs.RadioBox.Resolution = 0.2F;
            });

            // energy
            var batterySim = new BatteryPackSimulator();

            batterySim.With((args) =>
            {
                var batteryArgs = args as BatteryArgs;
                var battery     = batteryArgs.AddBattery();
                batteryArgs.UpdateDischargeCurrent(battery.Uid, 100);
            });

            // network
            var networkSim = new MeshNetworkSimulator();

            BuildMeshNetwork(networkSim.Arguments as MeshNetworkArgs);

            // pack all simulators in a reop
            var simRepo = new SimulatorRepository();

            simRepo.AddRange(new ISimulatable[] {
                radioSim,
                networkSim,
                batterySim
            });

            // runtime
            var runner = new Runner();

            runner.BindSimulators(simRepo);
            runner.Started += (o, e) =>
            {
                _log.Trace($"Runner started.");
            };
            runner.IterationPassed += (o, e) =>
            {
                _log.Trace($"Runner passed iteration");
            };
            runner.Stopped += (o, e) =>
            {
                _log.Trace($"Runner stopped.");
            };

            // -- act
            int iterations = 5;

            if (!runner.Validate())
            {
                Assert.Fail("Error on validating the simulation runtime.");
            }

            _log.Trace($"RunAsync for {iterations} times");
            await runner.RunAsync(iterations);

            // -- assert
            var runArgs = runner.Arguments as RuntimeArgs;

            Assert.IsTrue(runArgs.Iterations == 5, $"simulation should have passed {iterations} iterations");
        }