Esempio n. 1
0
        public static SerializationDelegate CreateFastInPlaceDeserializer(SimpleModelBase model)
        {
            var permanentFaults = model.Faults.OfType <PermanentFault>().ToArray();

            var isActiveField = typeof(PermanentFault).GetField("_isActive", BindingFlags.NonPublic | BindingFlags.Instance);

            SerializationDelegate deserialize = state =>
            {
                // States
                model.State = *((int *)state + 0);

                // Faults
                var faultsSerialized = *(long *)(state + sizeof(int));
                for (var i = 0; i < permanentFaults.Length; ++i)
                {
                    var fault = permanentFaults[i];
                    if ((faultsSerialized & (1L << i)) != 0)
                    {
                        isActiveField.SetValue(fault, true);
                    }
                    else
                    {
                        isActiveField.SetValue(fault, false);
                    }
                }
            };

            return(deserialize);
        }
Esempio n. 2
0
        public static SafetyAnalysisResults <SimpleExecutableModel> AnalyzeHazard(SimpleModelBase model, Formula hazard, int maxCardinality = Int32.MaxValue,
                                                                                  SafetyAnalysisBackend backend = SafetyAnalysisBackend.FaultOptimizedOnTheFly)
        {
            var modelCreator = SimpleExecutableModel.CreateExecutedModelCreator(model, hazard);

            return(AnalyzeHazard(modelCreator, hazard, maxCardinality, backend));
        }
Esempio n. 3
0
        public static SerializationDelegate CreateFastInPlaceSerializer(SimpleModelBase model)
        {
            var permanentFaults = model.Faults.OfType <PermanentFault>().ToArray();

            var isActiveField = typeof(PermanentFault).GetField("_isActive", BindingFlags.NonPublic | BindingFlags.Instance);

            SerializationDelegate serialize = state =>
            {
                // States
                *((int *)state) = model.State;

                // Faults
                var faultsSerialized = 0L;
                for (var i = 0; i < permanentFaults.Length; ++i)
                {
                    var fault    = permanentFaults[i];
                    var isActive = (bool)isActiveField.GetValue(fault);
                    if (isActive)
                    {
                        faultsSerialized |= 1L << i;
                    }
                }
                *(long *)(state + sizeof(int)) = faultsSerialized;
            };

            return(serialize);
        }
Esempio n. 4
0
        public static byte[] SerializeToByteArray(SimpleModelBase model, Formula[] formulas)
        {
            Requires.NotNull(model, nameof(model));

            using (var buffer = new MemoryStream())
                using (var writer = new BinaryWriter(buffer, Encoding.UTF8, leaveOpen: true))
                {
                    // write C# type of model
                    var exactTypeOfModel     = model.GetType();
                    var exactTypeOfModelName = exactTypeOfModel.AssemblyQualifiedName;
                    Requires.NotNull(exactTypeOfModelName, $"{exactTypeOfModelName} != null");
                    writer.Write(exactTypeOfModelName);

                    // write state
                    writer.Write(model.State);

                    // write formulas
                    writer.Write((uint)formulas.Length);
                    foreach (var formula in formulas)
                    {
                        WriteFormula(writer, formula);
                    }

                    // return result as array
                    return(buffer.ToArray());
                }
        }
 public override bool Evaluate(SimpleModelBase model)
 {
     if (model.LocalInts[Index] >= From && model.LocalInts[Index] <= To)
     {
         return(true);
     }
     return(false);
 }
 public override bool Evaluate(SimpleModelBase model)
 {
     if (model.State >= From && model.State <= To)
     {
         return(true);
     }
     return(false);
 }
 public override bool Evaluate(SimpleModelBase model)
 {
     return(model.LocalBools[Index]);
 }
 public abstract bool Evaluate(SimpleModelBase model);
Esempio n. 9
0
 public SimpleMarkovDecisionProcessFromExecutableModelGenerator(SimpleModelBase model) : base(SimpleExecutableModel.CreateExecutedModelFromFormulasCreator(model))
 {
 }
Esempio n. 10
0
 public SimpleMarkovChainFromExecutableModelGenerator(SimpleModelBase model) : base(SimpleExecutableModel.CreateExecutedModelFromFormulasCreator(model))
 {
 }
Esempio n. 11
0
        public static CoupledExecutableModelCreator <SimpleExecutableModel> CreateExecutedModelCreator(SimpleModelBase inputModel, params Formula[] formulasToCheckInBaseModel)
        {
            Requires.NotNull(inputModel, nameof(inputModel));
            Requires.NotNull(formulasToCheckInBaseModel, nameof(formulasToCheckInBaseModel));


            Func <int, SimpleExecutableModel> creatorFunc = (reservedBytes) =>
            {
                // Each model checking thread gets its own SimpleExecutableModel.
                // Thus, we serialize the C# model and load this file again.
                // The serialization can also be used for saving counter examples
                var serializedModelWithFormulas = SimpleModelSerializer.SerializeToByteArray(inputModel, formulasToCheckInBaseModel);
                var simpleExecutableModel       = new SimpleExecutableModel(serializedModelWithFormulas);
                return(simpleExecutableModel);
            };

            var faults = inputModel.Faults;

            return(new CoupledExecutableModelCreator <SimpleExecutableModel>(creatorFunc, inputModel, formulasToCheckInBaseModel, faults));
        }
Esempio n. 12
0
        public SafetyAnalysisResults <SimpleExecutableModel> ComputeMinimalCriticalSets(SimpleModelBase model, Formula hazard, int maxCardinality = Int32.MaxValue)
        {
            var modelCreator = SimpleExecutableModel.CreateExecutedModelCreator(model, hazard);

            return(ComputeMinimalCriticalSets(modelCreator, hazard, maxCardinality));
        }
        public AnalysisResult <SimpleExecutableModel> CheckInvariant(SimpleModelBase model, Formula invariant)
        {
            var modelCreator = SimpleExecutableModel.CreateExecutedModelCreator(model, invariant);

            return(CheckInvariant(modelCreator, formulaIndex: 0));
        }
Esempio n. 14
0
        public static ExecutableModelCreator <SimpleExecutableModel> CreateExecutedModelFromFormulasCreator(SimpleModelBase model)
        {
            Requires.NotNull(model, nameof(model));

            Func <Formula[], CoupledExecutableModelCreator <SimpleExecutableModel> > creator = formulasToCheckInBaseModel =>
            {
                Requires.NotNull(formulasToCheckInBaseModel, nameof(formulasToCheckInBaseModel));
                return(CreateExecutedModelCreator(model, formulasToCheckInBaseModel));
            };

            return(new ExecutableModelCreator <SimpleExecutableModel>(creator, model));
        }
Esempio n. 15
0
 /// <summary>
 ///   Initializes a new instance.
 /// </summary>
 /// <param name="model">The model that should be simulated.</param>
 /// <param name="formulas">The formulas that can be evaluated on the model.</param>
 public SimpleSimulator(SimpleModelBase model, params Formula[] formulas)
     : base(SimpleExecutableModel.CreateExecutedModelCreator(model, formulas).Create(0))
 {
 }
Esempio n. 16
0
 public SimpleQualitativeChecker(SimpleModelBase model, params Formula[] formulas)
     : base(SimpleExecutableModel.CreateExecutedModelCreator(model, formulas))
 {
 }
Esempio n. 17
0
 /// <summary>
 ///   Initializes a new instance.
 /// </summary>
 /// <param name="model">The model that should be simulated.</param>
 /// <param name="formulas">The formulas that can be evaluated on the model.</param>
 public SimpleProbabilisticSimulator(SimpleModelBase model, params Formula[] formulas)
     : base(SimpleExecutableModel.CreateExecutedModelFromFormulasCreator(model), formulas, Configuration)
 {
 }
Esempio n. 18
0
        public static CoupledExecutableModelCreator <SimpleExecutableModel> CreateExecutedModelCreator(SimpleModelBase inputModel, params Formula[] formulasToCheckInBaseModel)
        {
            Requires.NotNull(inputModel, nameof(inputModel));
            Requires.NotNull(formulasToCheckInBaseModel, nameof(formulasToCheckInBaseModel));


            Func <int, SimpleExecutableModel> creatorFunc = (reservedBytes) =>
            {
                // Each model checking thread gets its own SimpleExecutableModel.
                // Thus, we serialize the C# model and load this file again.
                // The serialization can also be used for saving counter examples
                var serializedModelWithFormulas = SimpleModelSerializer.SerializeToByteArray(inputModel, formulasToCheckInBaseModel);
                var simpleExecutableModel       = new SimpleExecutableModel(serializedModelWithFormulas);
                return(simpleExecutableModel);
            };
            Action <TextWriter> writeOptimizedStateVectorLayout = (textWriter) =>
            {
                textWriter.WriteLine("bytes[0-4] state: int");
                textWriter.WriteLine("bytes[5-12] permanent faults: long");
            };

            var faults = inputModel.Faults;

            return(new CoupledExecutableModelCreator <SimpleExecutableModel>(creatorFunc, writeOptimizedStateVectorLayout, inputModel, formulasToCheckInBaseModel, faults));
        }