Beispiel #1
0
        static void Main(string[] args)
        {
            var stopwatch = Stopwatch.StartNew();
            var oc5       = LusCompiler.Compile(File.ReadAllText(@"Examples/pressureTank.lus"), "TANK");

            stopwatch.Stop();
            Console.WriteLine($"Lustre compilation finished after {stopwatch.Elapsed.Minutes}:{stopwatch.Elapsed.Seconds:00}");

            stopwatch = Stopwatch.StartNew();
            var runner = new Oc5Runner(oc5);

            stopwatch.Stop();
            Console.WriteLine($"Oc5 compilation finished after {stopwatch.Elapsed.Minutes}:{stopwatch.Elapsed.Seconds:00}");

            var ticksCount = 1000000;
            var rand       = new Random();

            stopwatch = Stopwatch.StartNew();

            for (int i = 0; i < ticksCount; i++)
            {
                bool randomBool = rand.NextDouble() > 0.5;
                runner.Tick(randomBool);
            }

            stopwatch.Stop();

            Console.WriteLine($"{ticksCount} ticks finished after {stopwatch.Elapsed.Minutes}:{stopwatch.Elapsed.Seconds:00}");

            Console.ReadKey(true);
        }
        public void TestExample5()
        {
            //Arrange
            var oc5Source = File.ReadAllText("Examples/example5.oc");

            //Act
            var runner        = new Oc5Runner(oc5Source);
            var oc5ModelState = runner.Oc5ModelState;

            //Assert
            Assert.AreEqual(oc5ModelState.Bools.Count, 5);
        }
        public void TestPressureTank()
        {
            //Arrange
            var oc5Source = File.ReadAllText("Examples/pressureTank.oc");

            //Act
            var runner        = new Oc5Runner(oc5Source);
            var oc5ModelState = runner.Oc5ModelState;

            //Assert
            Assert.AreEqual(oc5ModelState.Bools.Count, 5);
            Assert.AreEqual(oc5ModelState.Ints.Count, 2);
        }
Beispiel #4
0
        public void TestExample4(object[] input, bool expectedOutput, int expectedState)
        {
            //Arrange
            var oc5Source = File.ReadAllText("Examples/example4.oc");

            //Act
            var runner        = new Oc5Runner(oc5Source);
            var oc5ModelState = runner.Oc5ModelState;

            runner.Tick(input);

            //Assert
            Assert.AreEqual(oc5ModelState.CurrentState, expectedState);
            Assert.AreEqual(oc5ModelState.GetOutputs().SingleOrDefault(), expectedOutput);
        }
Beispiel #5
0
        public void TestPressureTank(object[] input, int expectedOutput, int expectedState)
        {
            //Arrange
            var oc5Source = File.ReadAllText("Examples/pressureTank.oc");

            //Act
            var runner        = new Oc5Runner(oc5Source);
            var oc5ModelState = runner.Oc5ModelState;

            for (int i = 0; i < 5; i++)
            {
                runner.Tick(input);
            }

            //Assert
            Assert.AreEqual(oc5ModelState.CurrentState, expectedState);
            Assert.AreEqual(oc5ModelState.GetOutputs().SingleOrDefault(), expectedOutput);
        }
Beispiel #6
0
        public LustreModelBase(string lustrePath, string mainNode, IEnumerable <Fault> faults)
        {
            var oc5 = LusCompiler.Compile(File.ReadAllText(lustrePath), mainNode);

            Runner = new Oc5Runner(oc5);

            StateVectorSize =
                Runner.Oc5ModelState.Bools.Count * sizeof(bool) +
                Runner.Oc5ModelState.Ints.Count * sizeof(int) +
                Runner.Oc5ModelState.Strings.Count * sizeof(char) * 30 +                    //HACK max. length of string is 30 chars (29 + '\0')
                Runner.Oc5ModelState.Floats.Count * sizeof(float) +
                Runner.Oc5ModelState.Doubles.Count * sizeof(double) +
                Runner.Oc5ModelState.Mappings.Count * sizeof(PositionInOc5State) +
                Runner.Oc5ModelState.InputMappings.Count * sizeof(PositionInOc5State) +
                Runner.Oc5ModelState.OutputMappings.Count * sizeof(PositionInOc5State) +
                sizeof(int) +                                                               // variable containing the current state
                sizeof(long);                                                               // variable containing the permanent faults
            Faults = faults.ToDictionary(fault => fault.Name, fault => fault);
        }