本文整理汇总了C#中Automaton.GetMovesFrom方法的典型用法代码示例。如果您正苦于以下问题:C# Automaton.GetMovesFrom方法的具体用法?C# Automaton.GetMovesFrom怎么用?C# Automaton.GetMovesFrom使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Automaton
的用法示例。
在下文中一共展示了Automaton.GetMovesFrom方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MoveFromStoTContainsC
//check if delta(S,T,c) exists
static bool MoveFromStoTContainsC(char c, int S, int T, Automaton<BDD> aut, CharSetSolver solver)
{
var ccond = solver.MkCharConstraint(c);
foreach(var move in aut.GetMovesFrom(S))
if (move.TargetState == T)
if (solver.IsSatisfiable(solver.MkAnd(move.Label, ccond)))
return true;
return false;
}
示例2: FinalStateHasVariableMoves
private static bool FinalStateHasVariableMoves(Automaton<GrammarSymbol> MB)
{
foreach (Move<GrammarSymbol> move in MB.GetMovesFrom(MB.FinalState))
if (move.Label is Nonterminal)
return true;
return false;
}
示例3: MoveFromStoT
//check if delta(S,T,c) exists
static bool MoveFromStoT(int S, int T, Automaton<BDD> aut, CharSetSolver solver, out char witness)
{
foreach (var move in aut.GetMovesFrom(S))
if (move.TargetState == T)
{
foreach(var w in solver.GenerateAllCharacters(move.Label,false)){
witness=w;
return true;
}
}
witness = 'a';
return false;
}
示例4: getSimplePathsDFS
internal static void getSimplePathsDFS(int currState, Automaton<BDD> dfa, List<List<int>> paths, List<int> currPath)
{
foreach (var move in dfa.GetMovesFrom(currState))
{
if (!currPath.Contains(move.TargetState))
{
var npath = new List<int>(currPath);
npath.Add(move.TargetState);
if (dfa.GetFinalStates().Contains(move.TargetState))
paths.Add(npath);
getSimplePathsDFS(move.TargetState, dfa, paths, npath);
}
}
}
示例5: getSimpleCyclesDFS
internal static void getSimpleCyclesDFS(int currState, Automaton<BDD> dfa, List<List<int>> cycles, List<int> currPath)
{
foreach (var move in dfa.GetMovesFrom(currState))
{
if (!currPath.Contains(move.TargetState))
{
var npath = new List<int>(currPath);
npath.Add(move.TargetState);
getSimpleCyclesDFS(move.TargetState, dfa, cycles, npath);
}
else
{
if (currPath.ElementAt(0) == move.TargetState)
{
var npath = new List<int>(currPath);
npath.Add(move.TargetState);
cycles.Add(npath);
}
}
}
}
示例6: normalizeMoves
/// <summary>
/// Returns an automaton where transitions between states are collapsed to a single one
/// </summary>
/// <param name="automaton"></param>
/// <param name="solver"></param>
/// <returns></returns>
public static Automaton<BDD> normalizeMoves(Automaton<BDD> automaton, CharSetSolver solver)
{
List<Move<BDD>> normMoves = new List<Move<BDD>>();
foreach (var sourceState in automaton.States)
{
Dictionary<int, BDD> moveConditions = new Dictionary<int, BDD>();
foreach (var moveFromSourceState in automaton.GetMovesFrom(sourceState))
{
var target = moveFromSourceState.TargetState;
BDD oldCondition = null;
if (moveConditions.ContainsKey(target))
oldCondition = moveConditions[target];
else
oldCondition = solver.False;
if (!moveFromSourceState.IsEpsilon)
moveConditions[target] = solver.MkOr(oldCondition, moveFromSourceState.Label);
else
normMoves.Add(moveFromSourceState);
}
foreach (var targetState in moveConditions.Keys)
normMoves.Add(new Move<BDD>(sourceState,targetState,moveConditions[targetState]));
}
return Automaton<BDD>.Create(automaton.InitialState, automaton.GetFinalStates(), normMoves);
}
示例7: getSimplePrefixes
// Accessory methods for strings
#region Accessory methods for strings
internal static List<string> getSimplePrefixes(Automaton<BDD> dfa, CharSetSolver solver)
{
if (!dfa.IsEpsilonFree)
return new List<string>();
List<string> strings = new List<string>();
foreach (var path in getSimplePaths(dfa))
{
var currStrs = new List<string>();
currStrs.Add("");
var p = new List<int>(path);
p.RemoveAt(0);
int prevNode = dfa.InitialState;
foreach (int node in p)
{
foreach (var move in dfa.GetMovesFrom(prevNode))
{
if (node == move.TargetState)
{
var newStrs = new List<string>();
foreach (var el in solver.GenerateAllCharacters(move.Label, false))
foreach (var str in currStrs)
{
newStrs.Add(str + el);
strings.Add(str + el);
}
currStrs = new List<string>(newStrs);
break;
}
}
prevNode = node;
}
}
return strings;
}
示例8: getPathStrings
// gets string that forms the loop path given as a list of states
private static void getPathStrings(Automaton<BDD> dfa, CharSetSolver solver, List<int> path, string currStr, HashSet<string> strings, int prevState)
{
List<int> path1 = new List<int>(path);
var currState = path1.ElementAt(0);
path1.RemoveAt(0);
foreach (var move in dfa.GetMovesFrom(prevState))
if (move.TargetState == currState)
{
if (move.Label == null)
{
if (path1.Count == 0)
strings.Add(currStr);
else
getPathStrings(dfa, solver, path1, currStr, strings, currState);
}
else
foreach (char c in solver.GenerateAllCharacters(move.Label, false))
if (path1.Count == 0)
strings.Add(currStr + c);
else
getPathStrings(dfa, solver, path1, currStr + c, strings, currState);
}
}
示例9: getCyclesLengthsFromNode
private static void getCyclesLengthsFromNode(int length,
Automaton<BDD> dfa, int currState, HashSet<int>[] found, int max)
{
if (length <= max)
foreach (var move in dfa.GetMovesFrom(currState))
{
if (!found[length].Contains(move.TargetState))
{
found[length].Add(move.TargetState);
getCyclesLengthsFromNode(length + 1, dfa, move.TargetState, found, max);
}
}
}
示例10: GenerateShortTerm
internal static string GenerateShortTerm(Automaton<BDD> dfa, CharSetSolver solver)
{
if (dfa.IsEmpty)
return null;
Dictionary<int, string> shortStr = new Dictionary<int, string>();
HashSet<int> reachedStates = new HashSet<int>();
List<int> toExplore = new List<int>();
reachedStates.Add(dfa.InitialState);
toExplore.Add(dfa.InitialState);
shortStr.Add(dfa.InitialState, "");
var finSts = dfa.GetFinalStates();
if (finSts.Contains(dfa.InitialState))
return "";
string sCurr = ""; char condC = 'a';
while (toExplore.Count != 0)
{
var current = toExplore.First();
toExplore.RemoveAt(0);
shortStr.TryGetValue(current, out sCurr);
var reachableFromCurr = dfa.GetMovesFrom(current);
foreach (var move in reachableFromCurr)
{
if (!reachedStates.Contains(move.TargetState))
{
reachedStates.Add(move.TargetState);
toExplore.Add(move.TargetState);
if (move.Label == null)
{
shortStr.Add(move.TargetState, sCurr);
}
else
{
foreach (var v in solver.GenerateAllCharacters(move.Label, false))
{
condC = v;
break;
}
shortStr.Add(move.TargetState, sCurr + condC);
}
if (finSts.Contains(move.TargetState))
{
return sCurr + condC;
}
}
}
}
return null;
}
示例11: ComputeModels
internal static void ComputeModels(
string currStr, int currState,
Automaton<BDD> dfa, List<int> finalStates, HashSet<char> alphabet, CharSetSolver solver,
List<string> positive, List<string> negative)
{
if (currStr.Length >= 8)
return;
if (currState == -1 || !finalStates.Contains(currState))
negative.Add(currStr);
else
positive.Add(currStr);
foreach (char ch in alphabet)
{
if (currState == -1)
ComputeModels(currStr + ch, currState, dfa, finalStates, alphabet, solver, positive, negative);
else
{
bool found = false;
foreach (var move in dfa.GetMovesFrom(currState))
{
if (solver.IsSatisfiable(solver.MkAnd(move.Label, solver.MkCharConstraint(false, ch))))
{
found = true;
ComputeModels(currStr + ch, move.TargetState, dfa, finalStates, alphabet, solver, positive, negative);
break;
}
}
if (!found)
ComputeModels(currStr + ch, -1, dfa, finalStates, alphabet, solver, positive, negative);
}
}
}
示例12: dfsRecStartingTimes
private static void dfsRecStartingTimes(Automaton<BDD> dfa, int currState, HashSet<int> discovered, List<int> order)
{
order.Add(currState);
List<Move<BDD>> moves = new List<Move<BDD>>(dfa.GetMovesFrom(currState));
moves.Sort(delegate(Move<BDD> c1, Move<BDD> c2) {
if(c1.Label==null)
return 1;
if (c2.Label == null)
return -1;
return c1.Label.ToString().CompareTo(c2.Label.ToString());
});
foreach (var move in moves)
if (!discovered.Contains(move.TargetState))
{
discovered.Add(move.TargetState);
dfsRecStartingTimes(dfa, move.TargetState, discovered, order);
}
}
示例13: GetNFAEditScriptTimeout
// looks for an edit at depth "depth"
// returns false and null in bestScript if no edit is found at depth "depth"
// returns false and not null in bestScript if found
// returns true if timeout
internal bool GetNFAEditScriptTimeout(
int depth, long lastEditHash,
Automaton<BDD> currentNfa2,
List<NFAEdit> editList, int scriptCost,
NFAEditScript bestScript)
{
// if timeout return true
if (sw.ElapsedMilliseconds > timeout)
return true;
//Stop if no more moves left
if (depth == 0)
{
if (DFAUtilities.ApproximateMNEquivalent(tests, nfa1density, currentNfa2, al, solver) && currentNfa2.IsEquivalentWith(nfa1, solver))
//check if totalCost < finalScript cost and replace if needed
if (bestScript.script == null || scriptCost < bestScript.GetCost())
bestScript.script = ObjectCopier.Clone<List<NFAEdit>>(editList);
return false;
}
NFAEdit edit = null;
long thisEditHash = 0;
#region Flip one state from fin to non fin
foreach (var state in currentNfa2.States)
{
thisEditHash = state;
if (CanAdd(thisEditHash, lastEditHash))
{
//flip its final non final status
var newFinalStates = new HashSet<int>(currentNfa2.GetFinalStates());
Automaton<BDD> nfa2new = null;
if (currentNfa2.GetFinalStates().Contains(state))
{
edit = new NFAEditState(state, false);
editList.Insert(0, edit);
newFinalStates.Remove(state);
nfa2new = Automaton<BDD>.Create(currentNfa2.InitialState, newFinalStates, currentNfa2.GetMoves());
}
else
{
edit = new NFAEditState(state, true);
editList.Insert(0, edit);
newFinalStates.Add(state);
nfa2new = Automaton<BDD>.Create(currentNfa2.InitialState, newFinalStates, currentNfa2.GetMoves());
}
if (GetNFAEditScriptTimeout(depth - 1, thisEditHash, nfa2new, editList, scriptCost + edit.GetCost(), bestScript))
return true;
editList.RemoveAt(0);
}
}
#endregion
#region Change transition from source state
currentNfa2 = NFAUtilities.normalizeMoves(currentNfa2, solver);
foreach (var sourceState in currentNfa2.States)
{
HashSet<int> unreachedStates = new HashSet<int>(currentNfa2.States);
foreach (var moveFromSource in currentNfa2.GetMovesFrom(sourceState))
{
// take all chars in alphabet
foreach (var c in al)
{
long moveHash = currentNfa2.StateCount + IntegerUtil.TripleToInt(sourceState, moveFromSource.TargetState, alphabetMap[c]);
thisEditHash = currentNfa2.StateCount + moveHash;
if (CanAdd(thisEditHash, lastEditHash))
{
BDD cCond = solver.False;
BDD newCond = solver.False;
//skip epsilon moves
if (moveFromSource.Label != null)
{
// if c in move, remove it and recursion
if (solver.Contains(moveFromSource.Label, c))
{
cCond = solver.MkNot(solver.MkCharConstraint(false, c));
newCond = solver.MkAnd(moveFromSource.Label, cCond);
}
else // if c not in move, add it and recursion
{
cCond = solver.MkCharConstraint(false, c);
newCond = solver.MkOr(moveFromSource.Label, cCond);
}
var newMoves = new List<Move<BDD>>(currentNfa2.GetMoves());
newMoves.Remove(moveFromSource);
newMoves.Add(new Move<BDD>(sourceState, moveFromSource.TargetState, newCond));
var nfa2new = Automaton<BDD>.Create(currentNfa2.InitialState, currentNfa2.GetFinalStates(), newMoves);
edit = new NFAEditMove(sourceState, moveFromSource.TargetState, c);
//.........这里部分代码省略.........
示例14: canRemoveEdge
public static bool canRemoveEdge(Automaton<BDD> nfa, int sourceState, int targetState, CharSetSolver solver, Pair<IEnumerable<string>, IEnumerable<string>> tests, HashSet<char> al)
{
List<Move<BDD>> newMoves = new List<Move<BDD>>();
newMoves = nfa.GetMoves().ToList();
bool moveExists = false;
//goes through each move from state1 and remove it if it goes to state2 resp.
foreach (var move in nfa.GetMovesFrom(sourceState))
if (move.TargetState == targetState)
{
newMoves.Remove(move);
moveExists = true;
}
var newNfa = Automaton<BDD>.Create(nfa.InitialState, nfa.GetFinalStates(), newMoves);
if(moveExists)
if (DFAUtilities.ApproximateMNEquivalent(tests, 0.5, newNfa, al, solver))
return nfa.IsEquivalentWith(newNfa, solver);
return false;
}
示例15: dfsRecFinishingTimes
private static void dfsRecFinishingTimes(Automaton<BDD> dfa, int currState, HashSet<int> discovered, List<int> order)
{
foreach (var move in dfa.GetMovesFrom(currState))
{
if (!discovered.Contains(move.TargetState))
{
discovered.Add(move.TargetState);
dfsRecFinishingTimes(dfa, move.TargetState, discovered, order);
}
}
order.Insert(0, currState);
}