本文整理汇总了C#中Automaton.Determinize方法的典型用法代码示例。如果您正苦于以下问题:C# Automaton.Determinize方法的具体用法?C# Automaton.Determinize怎么用?C# Automaton.Determinize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Automaton
的用法示例。
在下文中一共展示了Automaton.Determinize方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetDFADifferenceRatio
/// <summary>
/// Computes the ratio of the symmetric difference to the size of dfa1 enumerating paths up to length n (uses the complement if density is high)
/// </summary>
/// <returns>size of ((dfa2-dfa1)+(dfa1-dfa2))/dfa1</returns>
public static double GetDFADifferenceRatio(Automaton<BDD> dfa1, Automaton<BDD> dfa2, HashSet<char> al, CharSetSolver solver)
{
var solutionDensity = DFADensity.GetDFADensity(dfa1, al, solver);
//Symmetric difference
var dfadiff1 = dfa1.Minus(dfa2, solver);
var dfadiff2 = dfa2.Minus(dfa1, solver);
var dfatrue = Automaton<BDD>.Create(0, new int[] { 0 }, new Move<BDD>[] { new Move<BDD>(0, 0, solver.True) });
var dfadiff = dfatrue.Minus(dfatrue.Minus(dfadiff1, solver).Intersect(dfatrue.Minus(dfadiff2, solver), solver), solver).Determinize(solver).Minimize(solver);
//Use smallest of |dfa1| and complement of |dfa1| for cardinality base
return GetDFARatio(dfa1.Determinize(solver).Minimize(solver), dfadiff, al, solver, solutionDensity > 0.5);
}
示例2: YieldTypeChecker
static YieldTypeChecker()
{
yieldTypeCheckerAutomatonSolver = new CharSetSolver(BitWidth.BV7);
yieldTypeCheckerAutomaton =
Automaton<BvSet>.MkProduct(yieldTypeCheckerAutomatonSolver.Convert(yieldTypeCheckerRegex),
yieldTypeCheckerAutomatonSolver.Convert(@"^[1-9A-D]*$"), // result of product with this Automaton provides us
//an automaton that has (*) existence alphanum chars in our property automaton
yieldTypeCheckerAutomatonSolver);
minimizedTypeCheckerAutomaton = yieldTypeCheckerAutomaton.Determinize(yieldTypeCheckerAutomatonSolver).Minimize(yieldTypeCheckerAutomatonSolver);
#if DEBUG && !DEBUG_DETAIL
yieldTypeCheckerAutomatonSolver.ShowGraph(minimizedTypeCheckerAutomaton, "minimizedPropertyAutomaton.dgml");
#endif
}
示例3: NFAEditDistanceProvider
/// <summary>
/// create new instance of NFAEdit distance and assigns a number to each character
/// </summary>
/// <param name="nfa1"></param>
/// <param name="nfa2"></param>
/// <param name="al"></param>
/// <param name="solver"></param>
/// <param name="timeout"></param>
public NFAEditDistanceProvider(Automaton<BDD> nfa1,
HashSet<char> al, CharSetSolver solver, long timeout)
{
this.nfa1 = nfa1;
this.al = al;
this.solver = solver;
this.timeout = timeout;
this.alphabetMap = new Dictionary<char, int>();
int index = 0;
foreach(var c in al){
this.alphabetMap[c] = index;
index++;
}
this.sw = new Stopwatch();
this.tests = NFAUtilities.MyHillTestGeneration(al, nfa1.Determinize(solver), solver);
var dfa1 = nfa1.RemoveEpsilons(solver.MkOr).Determinize(solver).Minimize(solver);
this.nfa1density = DFADensity.GetDFADensity(dfa1, al, solver);
}
示例4: Minimize
/// <summary>
/// Minimize the automaton
/// </summary>
public Automaton<BDD> Minimize(Automaton<BDD> aut)
{
return aut.Determinize().Minimize();
}
示例5: Complement
/// <summary>
/// Complement the automaton
/// </summary>
public Automaton<BDD> Complement(Automaton<BDD> aut)
{
return aut.Determinize().Complement();
}
示例6: MyHillTestGeneration
//returns a pair of string enumerable of positive and negative test set respectively
internal static Pair<IEnumerable<string>, IEnumerable<string>> MyHillTestGeneration(HashSet<char> alphabet, Automaton<BDD> dfa, CharSetSolver solver)
{
Automaton<BDD> normDfa = normalizeDFA(dfa.Determinize(solver).Minimize(solver)).First;
HashSet<string> pos = new HashSet<string>();
HashSet<string> neg = new HashSet<string>();
Automaton<BDD> ait, bif, bjf, adif;
HashSet<string> testSet = new HashSet<string>();
var finStates = normDfa.GetFinalStates();
string[] a = new string[normDfa.StateCount];
string[,] b = new string[normDfa.StateCount, normDfa.StateCount];
#region Compute ai and bij
foreach (var state1 in normDfa.States)
{
ait = Automaton<BDD>.Create(normDfa.InitialState, new int[] { state1 }, normDfa.GetMoves());
a[state1] = GenerateShortTerm(ait, solver);
bif = Automaton<BDD>.Create(state1, finStates, normDfa.GetMoves());
foreach (var state2 in normDfa.States)
{
bjf = Automaton<BDD>.Create(state2, finStates, new List<Move<BDD>>(normDfa.GetMoves()));
adif = bif.Minus(bjf, solver).Determinize(solver).Minimize(solver);
b[state1, state2] = GenerateShortTerm(adif, solver);
}
}
#endregion
for (int i = 0; i < normDfa.StateCount; i++)
for (int j = 0; j < normDfa.StateCount; j++)
{
if (b[i, j] != null)
pos.Add(a[i] + b[i, j]);
if (b[j, i] != null)
neg.Add(a[i] + b[j, i]);
foreach (char c in alphabet)
{
int new_i = GetNextState(i, c, normDfa, solver);
if (new_i!=-1 && b[new_i, j] != null)
pos.Add(a[i] + c + b[new_i, j]);
if (new_i != -1 && b[j, new_i] != null)
neg.Add(a[i] + c + b[j, new_i]);
}
}
return new Pair<IEnumerable<string>, IEnumerable<string>>(pos, neg);
}
示例7: GetGrade
/// <summary>
/// Computes the grade for attempt using all the possible metrics
/// </summary>
/// <param name="dfaGoal">minimal correct dfa</param>
/// <param name="dfaAttempt">dfa to be graded</param>
/// <param name="al">input alphabet</param>
/// <param name="solver">SMT solver for char set</param>
/// <param name="timeout">timeout for the PDL enumeration (suggested > 1000)</param>
/// <param name="maxGrade">Max grade for the homework</param>
/// <param name="enableDFAED">true to enable DFA edit distance</param>
/// <param name="enablePDLED">true to enable PDL edit distance</param>
/// <param name="enableDensity">true to enable density distance</param>
/// <returns>Grade for dfa2</returns>
public static Pair<int, IEnumerable<DFAFeedback>> GetGrade(
Automaton<BDD> dfaGoal, Automaton<BDD> dfaAttempt, HashSet<char> al,
CharSetSolver solver, long timeout,
int maxGrade, FeedbackLevel level,
bool enableDFAED, bool enablePDLED, bool enableDensity)
{
PDLEnumerator pdlEnumerator = new PDLEnumerator();
var feedList = new List<DFAFeedback>();
DFAFeedback defaultFeedback = new StringFeedback(level, StringFeedbackType.Wrong, al, solver);
#region Accessory and initial vars
//Compute minimized version of DFAs
var dfaGoalMin = dfaGoal.Determinize(solver).Minimize(solver);
var dfaAttemptMin = dfaAttempt.Determinize(solver).Minimize(solver);
//Initialize distances at high values in case they are not used
// they only produce positive grade if between 0 and 1
double pdlEditDistanceScaled = 2;
double densityRatio = 2;
double dfaED = 2;
#endregion
#region deductions on the grade based on the size of the dfa
//Deduction if DFA is smaller than it should be: used only for PDL ed and for density
var smallerDFADeduction = 0.2 * Math.Sqrt(
Math.Max(0.0, dfaGoalMin.StateCount - dfaAttemptMin.StateCount) /
((double)dfaGoalMin.StateCount));
#endregion
#region check whether the attempt is equivalent to the solution
if (dfaGoal.IsEquivalentWith(dfaAttempt, solver))
{
Console.WriteLine("Correct");
feedList.Add(new StringFeedback(level, StringFeedbackType.Correct, al, solver));
return new Pair<int, IEnumerable<DFAFeedback>>(maxGrade, feedList);
}
#endregion
#region metrics computation
Stopwatch swPDLed = new Stopwatch();
swPDLed.Start();
#region PDL edit distance
Transformation feedbackTransformation = null;
if (enablePDLED)
{
var trpair = PDLEditDistance.GetMinimalFormulaEditDistanceTransformation(dfaGoalMin, dfaAttemptMin, al, solver, timeout, pdlEnumerator);
if (trpair != null)
{
var transformationGrade = trpair.First;
feedbackTransformation = trpair.Second;
var scaling = 1.0;
pdlEditDistanceScaled = transformationGrade.totalCost / (transformationGrade.minSizeForTreeA * scaling) + smallerDFADeduction;
}
}
#endregion
swPDLed.Stop();
Stopwatch swDensity = new Stopwatch();
swDensity.Start();
#region density distance
if (enableDensity)
{
densityRatio = DFADensity.GetDFADifferenceRatio(dfaGoalMin, dfaAttemptMin, al, solver);
densityRatio += smallerDFADeduction;
}
#endregion
swDensity.Stop();
Stopwatch swDFAed = new Stopwatch();
swDFAed.Start();
#region DFA edit distance
DFAEditScript dfaEditScript = null;
if (enableDFAED)
{
//limit the depth of the DFA edit distance search
var maxMoves = Math.Max(1, 6 - (int)Math.Sqrt(dfaAttempt.MoveCount + dfaAttempt.StateCount));
dfaEditScript = DFAEditDistance.GetDFAOptimalEdit(dfaGoal, dfaAttempt, al, solver, timeout, new StringBuilder());
if (dfaEditScript != null)
dfaED = ((double)(dfaEditScript.GetCost())) / ((double)((dfaGoalMin.StateCount + 1) * al.Count));
}
#endregion
swDFAed.Stop();
//.........这里部分代码省略.........