public Choose ( int n ) : int | ||
n | int | The exclusive upper bound of the random number to be generated. n must be /// greater than or equal to zero. |
Résultat | int |
/// <summary> /// Generates a random member accepted by fa. /// Assumes that fa has no dead states, or else termination is not guaranteed. /// </summary> public string GenerateMember(Automaton <HashSet <Tuple <char, char> > > fa) { if (fa.IsEmpty) { throw new AutomataException(AutomataExceptionKind.AutomatonMustBeNonempty); } var sb = new System.Text.StringBuilder(); int state = fa.InitialState; while (!fa.IsFinalState(state) || (fa.OutDegree(state) > 0 && chooser.ChooseTrueOrFalse())) { var move = fa.GetNthMoveFrom(state, chooser.Choose(fa.GetMovesCountFrom(state))); if (!move.IsEpsilon) { Tuple <char, char> someRange = new Tuple <char, char>('\0', '\0'); foreach (var range in move.Label) { someRange = range; break; } int offset = chooser.Choose(Math.Max(1, (int)someRange.Item2 - (int)someRange.Item1)); char someChar = (char)((int)someRange.Item1 + offset); sb.Append(someChar); } state = move.TargetState; } return(sb.ToString()); }
/// <summary> /// Produces a random path of labels from the initial state to some final state. /// Assumes that the automaton is nonempty and does not contain deadends. /// </summary> /// <param name="chooser">uses the chooser for randomizing the choices</param> public IEnumerable <S> ChoosePathToSomeFinalState(Chooser chooser) { if (IsEmpty) { throw new AutomataException(AutomataExceptionKind.AutomatonMustBeNonempty); } int state = InitialState; while (!IsFinalState(state) || (OutDegree(state) > 0 && chooser.ChooseTrueOrFalse())) { if (!IsFinalState(state) && OutDegree(state) == 0) { throw new AutomataException(AutomataExceptionKind.AutomatonMustNotContainDeadStates); } var move = GetNthMoveFrom(state, chooser.Choose(GetMovesCountFrom(state))); if (!move.IsEpsilon) { yield return(move.Label); } state = move.TargetState; } yield break; }
/// <summary> /// Generates a random member accepted by fa. /// Assumes that fa has no dead states, or else termination is not guaranteed. /// </summary> public string GenerateMember(Automaton <HashSet <char> > fa) { if (fa.IsEmpty) { throw new AutomataException(AutomataExceptionKind.AutomatonMustBeNonempty); } var sb = new System.Text.StringBuilder(); int state = fa.InitialState; while (!fa.IsFinalState(state) || (fa.OutDegree(state) > 0 && chooser.ChooseTrueOrFalse())) { var move = fa.GetNthMoveFrom(state, chooser.Choose(fa.GetMovesCountFrom(state))); if (!move.IsEpsilon) { char someChar = '\0'; foreach (var c in move.Label) { someChar = c; break; } sb.Append(someChar); } state = move.TargetState; } return(sb.ToString()); }
/// <summary> /// Choose a random member uniformly at random from the ulong set. /// </summary> public char ChooseUniformly(ulong s) { int K = (int)ComputeDomainSize(s); int k = chooser.Choose(K); for (int i = 0; i < atoms.Length; i++) { if (IsSatisfiable(atoms[i] & s)) { if (k < partition[i].Count) { return((char)partition[i][k]); } else { k = k - partition[i].Count; } } } throw new AutomataException(AutomataExceptionKind.SetIsEmpty); }