Exemplo n.º 1
0
        private void AddTransitionConsolidate(byte *stateToAdd, StateFormulaSet formulas, FaultSet activatedFaults, double probability)
        {
            // Try to find a matching transition. If not found, then add a new one
            var successorState = AddStateConsolidate(stateToAdd);

            for (var i = 0; i < _count; i++)
            {
                var candidateTransition = _transitions[i];
                if (candidateTransition.TargetStatePointer == successorState &&
                    candidateTransition.Formulas == formulas                     //&&
                    //candidateTransition.ActivatedFaults == activatedFaults
                    )
                {
                    candidateTransition.Probability += probability;
                    _transitions[i] = candidateTransition;
                    return;
                }
            }

            if (_count >= _capacity)
            {
                throw new OutOfMemoryException("Unable to store an additional transition. Try increasing the successor state capacity.");
            }

            _transitions[_count] = new LtmcTransition
            {
                TargetStatePointer = successorState,
                Formulas           = formulas,
                //ActivatedFaults = activatedFaults,
                Flags       = TransitionFlags.IsValidFlag,
                Probability = probability
            };
            ++_count;
        }
Exemplo n.º 2
0
        public void AddTransition(int targetState, double probability, StateFormulaSet formulas)
        {
            // Try to find a matching transition. If not found, then add a new one
            var state = AddState(targetState);

            for (var i = 0; i < _transitionCount; i++)
            {
                var candidateTransition = _transitions[i];
                if (candidateTransition.TargetStatePointer == state &&
                    candidateTransition.Formulas == formulas)
                {
                    candidateTransition.Probability += probability;
                    _transitions[i] = candidateTransition;
                    return;
                }
            }

            Requires.That(_transitionCount < _capacity, "more space needed");

            _transitions[_transitionCount] = new LtmcTransition
            {
                TargetStatePointer = state,
                Formulas           = formulas,
                ActivatedFaults    = new FaultSet(),
                Flags       = TransitionFlags.IsValidFlag,
                Probability = probability
            };
            ++_transitionCount;
        }
Exemplo n.º 3
0
        private void AddTransition(byte *stateToAdd, StateFormulaSet formulas, FaultSet activatedFaults, double probability)
        {
            if (_consolidateOnTheFly)
            {
                AddTransitionConsolidate(stateToAdd, formulas, activatedFaults, probability);
            }
            else
            {
                if (_count >= _capacity)
                {
                    throw new OutOfMemoryException("Unable to store an additional transition. Try increasing the successor state capacity.");
                }

                var successorState = _temporalStateStorage.GetFreeTemporalSpaceAddress();
                MemoryBuffer.Copy(stateToAdd, successorState, _temporalStateStorage.StateVectorSize);
                _transitions[_count] = new LtmcTransition
                {
                    TargetStatePointer = successorState,
                    Formulas           = formulas,
                    //ActivatedFaults = activatedFaults,
                    Flags       = TransitionFlags.IsValidFlag,
                    Probability = probability
                };
                ++_count;
            }
        }
Exemplo n.º 4
0
 private void UpdateNormalizedFormulaSatisfactionCount(StateFormulaSet evaluatedCompilableFormulas)
 {
     for (var i = 0; i < NormalizedFormulas.Length; i++)
     {
         if (evaluatedCompilableFormulas[i])
         {
             NormalizedFormulaSatisfactionCount[i]++;
         }
     }
 }
Exemplo n.º 5
0
        private StateFormulaSet DeriveNewStateFormulaSet(StateFormulaSet oldStateFormulaSet, int newEnrichment)
        {
            var evaluatedStateFormulas = new bool[_newFormulaEvaluators.Length];

            for (var i = 0; i < _newFormulaEvaluators.Length; i++)
            {
                var setNewBit = _newFormulaEvaluators[i](oldStateFormulaSet, newEnrichment);
                evaluatedStateFormulas[i] = setNewBit;
            }
            return(new StateFormulaSet(evaluatedStateFormulas));
        }
Exemplo n.º 6
0
        private StateFormulaSet DeriveNewStateFormulaSet(StateFormulaSet oldStateFormulaSet)
        {
            var evaluatedStateFormulas = new bool[_formulas.Length];

            for (var i = 0; i < _formulas.Length; i++)
            {
                var setNewBit = _formulaInStateTransitionEvaluators[i](oldStateFormulaSet);
                evaluatedStateFormulas[i] = setNewBit;
            }
            return(new StateFormulaSet(evaluatedStateFormulas));
        }
Exemplo n.º 7
0
        public void CreateArtificalStateFormula()
        {
            var indexOfArtificialStateFormula = _nmdp.StateFormulaLabels.Length;

            Requires.That(indexOfArtificialStateFormula < 32, "Too many formulas. Cannot create a state formula for artificial states during the mdp transformation");
            var satisfiedOnlyInNewIndexArray = new bool[indexOfArtificialStateFormula + 1];

            satisfiedOnlyInNewIndexArray[indexOfArtificialStateFormula] = true;             //other values already initialized to false
            _stateFormulaSetforArtificialState       = new StateFormulaSet(satisfiedOnlyInNewIndexArray);
            FormulaForArtificalState                 = new AtomarPropositionFormula();
            MarkovDecisionProcess.StateFormulaLabels =
                _nmdp.StateFormulaLabels.Concat(new[] { FormulaForArtificalState.Label }).ToArray();
        }
Exemplo n.º 8
0
        private int DeriveNewEnrichment(StateFormulaSet oldStateFormulaSet)
        {
            int newEnrichment = 0;

            for (var i = 0; i < _newEnrichmentEvaluator.Length; i++)
            {
                var setNewBit = _newEnrichmentEvaluator[i](oldStateFormulaSet);
                if (setNewBit)
                {
                    newEnrichment |= 1 << i;
                }
            }
            return(newEnrichment);
        }
Exemplo n.º 9
0
		/// <summary>
		///   Adds a transition to the <paramref name="successorState" /> to the set.
		/// </summary>
		/// <param name="successorState">The successor state of the transition that should be added.</param>
		/// <param name="activatedFaults">The faults activated by the transition that should be added.</param>
		/// <param name="formulas">The formulas holding in the successor state of the transition that should be added.</param>
		public void Add(byte* successorState, FaultSet activatedFaults, StateFormulaSet formulas)
		{
			var targetState = _targetStateMemory + _count * _stateVectorSize;
			MemoryBuffer.Copy(successorState, targetState, _stateVectorSize);

			_transitions[_count] = new CandidateTransition
			{
				TargetState = targetState,
				Formulas = formulas,
				ActivatedFaults = activatedFaults,
				IsValid = true,
			};

			++_count;
		}
Exemplo n.º 10
0
        internal void CreateTransition(bool[] isFormulaSatisfied, byte *targetState, double p)
        {
            var transition = _transitionCount;

            _transitionCount++;
            _transitions[transition] = new LtmcTransition {
                Probability = p
            };
            var t = _transitions + transition;

            t->TargetStatePointer = targetState;
            t->Formulas           = new StateFormulaSet(isFormulaSatisfied);
            t->Flags           = TransitionFlags.IsValidFlag | TransitionFlags.IsStateTransformedToIndexFlag;
            t->ActivatedFaults = new FaultSet();
        }
Exemplo n.º 11
0
        /// <summary>
        ///   Adds a transition to the <paramref name="successorState" /> to the set.
        /// </summary>
        /// <param name="successorState">The successor state of the transition that should be added.</param>
        /// <param name="activatedFaults">The faults activated by the transition that should be added.</param>
        /// <param name="formulas">The formulas holding in the successor state of the transition that should be added.</param>
        public void Add(byte *successorState, FaultSet activatedFaults, StateFormulaSet formulas)
        {
            var targetState = _targetStateMemory + _count * _stateVectorSize;

            MemoryBuffer.Copy(successorState, targetState, _stateVectorSize);

            _transitions[_count] = new CandidateTransition
            {
                TargetStatePointer = targetState,
                Formulas           = formulas,
                ActivatedFaults    = activatedFaults,
                Flags = TransitionFlags.IsValidFlag,
            };

            ++_count;
        }
Exemplo n.º 12
0
        private void CreateTransition(bool isFormulaSatisfied, int targetStateIndex, int continuationId, double p)
        {
            var transition = _transitionCount;

            _transitionCount++;
            _transitions[transition] = new LtmdpTransition {
                Probability = p, ContinuationId = continuationId
            };
            var t = (Transition *)(_transitions + transition);

            t->SourceStateIndex = 0;
            t->TargetStateIndex = targetStateIndex;
            t->Formulas         = new StateFormulaSet(new Func <bool>[] { () => isFormulaSatisfied });
            t->Flags            = TransitionFlags.IsValidFlag | TransitionFlags.IsStateTransformedToIndexFlag;
            t->ActivatedFaults  = new FaultSet();
        }
Exemplo n.º 13
0
        internal void CreateTransition(bool[] isFormulaSatisfied, int targetStateIndex, int continuationId)
        {
            var transition = _transitionCount;

            _transitionCount++;
            _transitions[transition] = new LtmdpTransition {
                Index = transition
            };
            var t = (Transition *)(_transitions + transition);

            t->SourceStateIndex = 0;
            t->TargetStateIndex = targetStateIndex;
            t->Formulas         = new StateFormulaSet(isFormulaSatisfied);
            t->Flags            = TransitionFlags.IsValidFlag | TransitionFlags.IsStateTransformedToIndexFlag;
            t->ActivatedFaults  = new FaultSet();
            StepGraph.SetTargetOfFinalOrUnsplitChoice(continuationId, transition);
        }
Exemplo n.º 14
0
 private void AddTransition(byte *stateToAdd, StateFormulaSet formulas, FaultSet activatedFaults, double probability)
 {
     if (_consolidateOnTheFly)
     {
         AddTransitionConsolidate(stateToAdd, formulas, activatedFaults, probability);
     }
     else
     {
         var successorState = _temporalStateStorage.GetFreeTemporalSpaceAddress();
         MemoryBuffer.Copy(stateToAdd, successorState, _temporalStateStorage.StateVectorSize);
         _transitions[_count] = new LtmcTransition
         {
             TargetStatePointer = successorState,
             Formulas           = formulas,
             //ActivatedFaults = activatedFaults,
             Flags       = TransitionFlags.IsValidFlag,
             Probability = probability
         };
         ++_count;
     }
 }
Exemplo n.º 15
0
 protected void CheckConsistencyAfterInitialization()
 {
     StateFormulaSet.CheckFormulaCount(AtomarPropositionFormulas.Length);
 }
Exemplo n.º 16
0
 internal void SetStateLabeling(int markovChainState, StateFormulaSet formula)
 {
     StateLabeling[markovChainState] = formula;
 }
Exemplo n.º 17
0
 internal StateStorageEntry(StateFormulaSet formula, int stateStorageState)
 {
     Formula           = formula;
     StateStorageState = stateStorageState;
 }
Exemplo n.º 18
0
        public int ColumnToState(int state) => state;         //Do nothing! Just here to make the algorithms more clear.


        internal void SetStateLabeling(int state, StateFormulaSet formula)
        {
            StateLabeling[state] = formula;
        }
 public EnrichedTargetState(int targetState, StateFormulaSet formulas)
 {
     TargetState = targetState;
     Formulas    = formulas;
 }
Exemplo n.º 20
0
 private void AddEvaluatedCompilableFormulas(SimulationTraceStep step, StateFormulaSet evaluatedCompilableFormulas)
 {
     step.EvaluatedNormalizedFormulas = evaluatedCompilableFormulas;
 }