本文整理汇总了C#中CharSetSolver.MkAnd方法的典型用法代码示例。如果您正苦于以下问题:C# CharSetSolver.MkAnd方法的具体用法?C# CharSetSolver.MkAnd怎么用?C# CharSetSolver.MkAnd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CharSetSolver
的用法示例。
在下文中一共展示了CharSetSolver.MkAnd方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: getDFA
public Automaton<BDD> getDFA(BDD alphabet, CharSetSolver solver)
{
var opt = this.Normalize(solver).PushQuantifiers();
var dfa1= opt.getDFA(new List<string>(), alphabet, solver);
var moves = new List<Move<BDD>>();
foreach (var move in dfa1.GetMoves())
{
moves.Add(new Move<BDD>(move.SourceState, move.TargetState, solver.MkAnd(move.Label, alphabet)));
}
return Automaton<BDD>.Create(dfa1.InitialState, dfa1.GetFinalStates(), moves, true, true).Determinize(solver).Minimize(solver);
}
示例2: GetClosestElement
//.........这里部分代码省略.........
Pold[S, T] = int.MaxValue;
P1[S, T] = false;
foreach (var c in chars)
Lold[c][S, T] = false;
}
}
}
}
#endregion
//solver.ShowGraph(automaton,"as");
//Inductive step
for(int k=1;k<=bound;k++){
foreach (var stT in automaton.States)
{
var T = stToInd[stT];
foreach (var stS in automaton.States)
{
var S = stToInd[stS];
if (Pold[S, T] == int.MaxValue)
{
bool found=false;
foreach (var move in automaton.GetMovesFrom(stS))
{
var stk = move.TargetState;
var K = stToInd[stk];
if (Pold[K, T] != int.MaxValue)
if (P1[S, K])
{
found = true;
Pnew[S, T] = Pold[K, T] + 1;
foreach (var c in chars)
Lnew[c][S, T] = Lold[c][K, T] || solver.IsSatisfiable(solver.MkAnd(move.Label,solver.MkCharConstraint(c)));
}
}
if (!found)
{
Pnew[S, T] = Pold[S, T];
foreach (var c in chars)
Lnew[c][S, T] = Lold[c][S, T];
}
}
else
{
Pnew[S, T] = Pold[S, T];
foreach (var c in chars)
Lnew[c][S, T] = Lold[c][S, T];
}
}
}
Pold = Pnew;
Pnew=new int[states.Length, states.Length];
foreach (var c in chars)
Lold[c] = Lnew[c];
Lnew = new Dictionary<char, bool[,]>();
foreach (var c in chars)
Lnew[c] = new bool[states.Length, states.Length];
}
//Initialize table for value 0
Pair<int, int>[,] F = new Pair<int, int>[maxl, automaton.StateCount];
foreach (var st in automaton.States)
示例3: MoveFromStoTContainsC
//check if delta(S,T,c) exists
static bool MoveFromStoTContainsC(char c, int S, int T, Automaton<BDD> aut, CharSetSolver solver, out char witness)
{
var ccond = solver.MkCharConstraint(c);
foreach (var move in aut.GetMovesFrom(S))
if (move.TargetState == T)
{
if (solver.IsSatisfiable(solver.MkAnd(move.Label, ccond)))
{
witness = c;
return true;
}
else
foreach (var w in solver.GenerateAllCharacters(move.Label, false))
{
witness = w;
return true;
}
}
witness = c;
return false;
}
示例4: TestRanges3
public void TestRanges3()
{
CharSetSolver solver = new CharSetSolver(BitWidth.BV16);
BDD cond = solver.MkCharSetFromRegexCharClass(@"\d");
int cnt = cond.CountNodes();
Pair<uint, uint>[] ranges = solver.ToRanges(cond);
BDD set = solver.MkCharSetFromRanges(ranges);
int nodes = set.CountNodes();
var ranges2 = new List<Pair<uint, uint>>(ranges);
ranges2.Reverse();
BDD set2 = solver.MkCharSetFromRanges(ranges2);
int nodes2 = set.CountNodes();
var ranges3 = solver.ToRanges(set2);
BDD set3 = solver.MkCharSetFromRanges(ranges3);
int cnt2 = set2.CountNodes();
int cnt3 = set3.CountNodes();
Assert.IsTrue(set2 == set3);
Assert.AreEqual<int>(nodes, nodes2);
Assert.AreSame(set,set2);
set.ToDot("digits.dot");
//check equivalence
bool equiv = solver.MkOr(solver.MkAnd(cond, solver.MkNot(set)), solver.MkAnd(set, solver.MkNot(cond))) == solver.False;
Assert.AreEqual<int>(31, ranges.Length);
}
示例5: 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);
}
}
}
示例6: GetNextState
// returns the state reached from currState when reading c
private static int GetNextState(int currState, char c, Automaton<BDD> dfa, CharSetSolver solver)
{
foreach (var move in dfa.GetNonepsilonMovesFrom(currState))
if (solver.IsSatisfiable(solver.MkAnd(move.Label, solver.MkCharConstraint(false, c))))
return move.TargetState;
return -1;
}
示例7: GetDFAEditScriptTimeout
// 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 static bool GetDFAEditScriptTimeout(
Automaton<BDD> dfa1, Automaton<BDD> dfa2,
HashSet<char> al, CharSetSolver solver,
List<long> editScriptHash, List<DFAEdit> editList,
int depth, long timeout, Stopwatch sw,
Pair<IEnumerable<string>, IEnumerable<string>> tests,
double dfa1density,
int totalCost,
DFAEditScript bestScript, Dictionary<int, int> stateNamesMapping)
{
// check timer
if (sw.ElapsedMilliseconds > timeout)
return true;
//Compute worst case distance, call finalScript with this value?
int dist = (dfa1.StateCount + dfa2.StateCount) * (al.Count + 1);
//Stop if no more moves left
if (depth == 0)
{
if (DFAUtilities.ApproximateMNEquivalent(tests, dfa1density, dfa2, al, solver) && dfa2.IsEquivalentWith(dfa1, solver))
//check if totalCost < finalScript cost and replace if needed
if (bestScript.script == null || totalCost < bestScript.GetCost())
bestScript.script = ObjectCopier.Clone<List<DFAEdit>>(editList);
return false;
}
DFAEdit edit = null;
#region Flip one move target state
foreach (var move in dfa2.GetMoves())
{
//Creaty copy of the moves without current move
var movesWithoutCurrMove = dfa2.GetMoves().ToList();
movesWithoutCurrMove.Remove(move);
//Redirect every ch belonging to move condition
foreach (var c in solver.GenerateAllCharacters(move.Label, false))
{
long hash = IntegerUtil.PairToInt(move.SourceState, c - 97) + dfa2.StateCount;
if (CanAdd(hash, editScriptHash))
{
editScriptHash.Insert(0, hash);
//Local copy of moves
var newMoves = movesWithoutCurrMove.ToList();
var newMoveCondition = solver.MkCharConstraint(false, c);
#region Remove ch from current move
var andCond = solver.MkAnd(move.Label, solver.MkNot(newMoveCondition));
//add back move without ch iff satisfiable
if (solver.IsSatisfiable(andCond))
newMoves.Add(new Move<BDD>(move.SourceState, move.TargetState, andCond));
#endregion
#region Redirect c to a different state
foreach (var state in dfa2.States)
if (state != move.TargetState)
{
var newMovesComplete = newMoves.ToList();
newMovesComplete.Add(new Move<BDD>(move.SourceState, state, newMoveCondition));
var dfa2new = Automaton<BDD>.Create(dfa2.InitialState, dfa2.GetFinalStates(), newMovesComplete);
edit = new DFAEditMove(stateNamesMapping[move.SourceState], stateNamesMapping[state], c);
editList.Insert(0, edit);
if (GetDFAEditScriptTimeout(dfa1, dfa2new, al, solver, editScriptHash, editList, depth - 1, timeout, sw, tests, dfa1density, totalCost + edit.GetCost(), bestScript, stateNamesMapping))
return true;
editList.RemoveAt(0);
}
#endregion
editScriptHash.RemoveAt(0);
}
}
}
#endregion
#region Flip one state from fin to non fin
foreach (var state in dfa2.States)
{
if (CanAdd(state, editScriptHash))
{
//flip its final non final status
editScriptHash.Insert(0, state);
var newFinalStates = new HashSet<int>(dfa2.GetFinalStates());
Automaton<BDD> dfa2new = null;
if (dfa2.GetFinalStates().Contains(state))
{
edit = new DFAEditState(stateNamesMapping[state], false);
editList.Insert(0, edit);
newFinalStates.Remove(state);
dfa2new = Automaton<BDD>.Create(dfa2.InitialState, newFinalStates, dfa2.GetMoves());
}
//.........这里部分代码省略.........
示例8: computeDFA
internal static Automaton<BDD> computeDFA(List<string> variables, BDD alphabet, CharSetSolver solver, string set1, string set2)
{
int pos1 = variables.IndexOf(set1);
int pos2 = variables.IndexOf(set2);
Dictionary<int, Dictionary<Pair<int, int>, Automaton<BDD>>> dic1;
if (!hashedDfa.ContainsKey(alphabet))
hashedDfa[alphabet] = new Dictionary<int, Dictionary<Pair<int, int>, Automaton<BDD>>>();
dic1 = hashedDfa[alphabet];
Dictionary<Pair<int, int>, Automaton<BDD>> dic2;
if (!dic1.ContainsKey(variables.Count))
dic1[variables.Count] = new Dictionary<Pair<int, int>, Automaton<BDD>>();
dic2 = dic1[variables.Count];
var hash = new Pair<int, int>(pos1, pos2);
if (dic2.ContainsKey(hash))
return dic2[hash];
//Create conditions that bit in pos1 is smaller than pos2
var trueBv = solver.MkSetFromRange(0, (uint)(Math.Pow(2, variables.Count + 16) - 1), variables.Count + 16 - 1);
var both1 = solver.MkAnd(new BDD[] { trueBv, solver.MkSetWithBitTrue(pos1), solver.MkSetWithBitTrue(pos2) });
var both0 = solver.MkAnd(new BDD[] { trueBv, solver.MkSetWithBitFalse(pos1), solver.MkSetWithBitFalse(pos2) });
var eqCond = solver.MkOr(new BDD[] { both0, both1 });
//Create automaton for condition
var moves = new Move<BDD>[] { new Move<BDD>(0, 0, eqCond) };
var dfa = Automaton<BDD>.Create(0, new int[] { 0 }, moves).Determinize(solver).Minimize(solver);
if(hashing)
dic2[hash] = dfa;
return dfa;
}
示例9: Normalize
public override WS1SFormula Normalize(CharSetSolver solver)
{
var ln = left.Normalize(solver);
var rn = right.Normalize(solver);
if (ln is WS1SUnaryPred && rn is WS1SUnaryPred)
{
var cln = ln as WS1SUnaryPred;
var crn = rn as WS1SUnaryPred;
if (cln.set == crn.set)
return new WS1SUnaryPred(cln.set, solver.MkAnd(cln.pred, crn.pred));
}
else
{
if (ln is WS1SFalse || rn is WS1SFalse)
return new WS1SFalse();
if (ln is WS1STrue)
return rn;
if (rn is WS1STrue)
return ln;
}
return new WS1SAnd(ln,rn);
}