本文整理汇总了C#中Automaton.RemoveEpsilons方法的典型用法代码示例。如果您正苦于以下问题:C# Automaton.RemoveEpsilons方法的具体用法?C# Automaton.RemoveEpsilons怎么用?C# Automaton.RemoveEpsilons使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Automaton
的用法示例。
在下文中一共展示了Automaton.RemoveEpsilons方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: ApproximateMNEquivalent
// Return true iff dfa2 behaves correctly on all the inputs the pair (pos,neg)
// To be used only when testing again same dfa1 over and over
internal static bool ApproximateMNEquivalent(
Pair<IEnumerable<string>, IEnumerable<string>> testSets,
double lanDensity,
Automaton<BDD> shouldbeDfa, HashSet<char> al, CharSetSolver solver)
{
var dfa = shouldbeDfa;
if(!shouldbeDfa.isDeterministic || !shouldbeDfa.IsEpsilonFree)
dfa = shouldbeDfa.RemoveEpsilons(solver.MkOr).Determinize(solver).MakeTotal(solver).Minimize(solver);
//Check against test cases
var positive = testSets.First;
var negative = testSets.Second;
if (lanDensity < 0.5)
{
foreach (var s in positive)
if (!Accepts(dfa, s, al, solver))
return false;
foreach (var s in negative)
if (Accepts(dfa, s, al, solver))
return false;
}
else
{
foreach (var s in negative)
if (Accepts(dfa, s, al, solver))
return false;
foreach (var s in positive)
if (!Accepts(dfa, s, al, solver))
return false;
}
return true;
}
示例3: GetGrade
//.........这里部分代码省略.........
var stateRatioSqM1 = Math.Pow(stateRatio, 2) - 1;
var sclaedStateRatio = stateRatioSqM1 * maxDeductionForTooBig / 2;
tooBigDeduction = (int)Math.Round(Math.Min(sclaedStateRatio, maxDeductionForTooBig));
}
else
{
if (transDiff > 0)
{
// ((att/sol)^2)-1
var transRatio = attemptTransCount / solutionTransCount;
var transRatioSqM1 = Math.Pow(transRatio, 2) - 1;
var sclaedTransRatio = transRatioSqM1 * maxDeductionForTooBig / 2;
tooBigDeduction = (int)Math.Round(Math.Min(sclaedTransRatio, maxDeductionForTooBig));
}
}
//Make sure deduction is positive
tooBigDeduction = Math.Max(tooBigDeduction, 0);
#endregion
}
#endregion
}
else
{
// prompt nfa is incorrect
feedbacks.Add(new NFAStringFeedback(level, alphabet, solver, "Your NFA does NOT accept the correct langauge."));
//inequivalent, try using grading metrics and based on winning metric give feedback
int remainingGrade = maxGrade - tooBigDeduction;
#region metric computation
//compute deterministic versions
var solutionNFAdet = solutionNFA.RemoveEpsilons(solver.MkOr).Determinize(solver).MakeTotal(solver).Minimize(solver);
var attemptNFAdet = attemptNFA.RemoveEpsilons(solver.MkOr).Determinize(solver).MakeTotal(solver).Minimize(solver);
solutionNFAdet.EliminateDeadStates();
attemptNFAdet.EliminateDeadStates();
//compute density
double densityRatio = DFADensity.GetDFADifferenceRatio(solutionNFAdet, attemptNFAdet, alphabet, solver);
//compute edit distance
double nfaED = 2;
var editScript = nfaedp.GetNFAOptimalEdit(attemptNFA);
if (editScript != null)
nfaED = ((double)(editScript.GetCost())) / ((double)((solutionNFA.StateCount + 1) * alphabet.Count));
#endregion
#region metrics scaling
var scalingSquareDensity = 1; var multv2 = 0.5;
var scalingSquareDFAED = 1.03;
var scaledDensityRatio = (scalingSquareDensity + (multv2 * densityRatio)) * (scalingSquareDensity + (multv2 * densityRatio)) - scalingSquareDensity * scalingSquareDensity;
var scaledNfaED = (scalingSquareDFAED + nfaED) * (scalingSquareDFAED + nfaED) - scalingSquareDFAED * scalingSquareDFAED;
//If the edit script was not computed make sure it loses.
if (editScript == null)
scaledNfaED = Double.MaxValue;
//Select dominating Feedback based on grade
double unscaledGrade = Math.Min(scaledDensityRatio, scaledNfaED);
var dfaedwins = scaledNfaED <= scaledDensityRatio;
var densitywins = scaledDensityRatio <= scaledNfaED;
incorrectDeduction = (int)Math.Round(unscaledGrade * (double)(maxGrade));
#endregion
//If edit distance search works, provides feedback based upon result
//Otherwise, gives counterexample feedback
if (level != FeedbackLevel.Minimal)
{
if (dfaedwins)
feedbacks.Add(new NFAEDFeedback(solutionNFA, attemptNFA, level, alphabet, editScript, solver));
else
feedbacks.Add(new NFACounterexampleFeedback(level, alphabet, solutionNFAdet, attemptNFAdet, solver));
}
}
// Feedback related to nondeterminism and epislon
if (shouldUseEpsilon)
feedbacks.Add(new NFAStringFeedback(level, alphabet, solver, "You should try using epsilon transitions."));
if (shouldUseNonDet)
feedbacks.Add(new NFAStringFeedback(level, alphabet, solver, "You should try using nondeterminism."));
// Deduct points and prompt feedback is solution has dead states
if (solutionHasDeadStates)
{
deadStateDeduction = (int)maxDeductionForDeadStates;
feedbacks.Add(new NFAStringFeedback(level, alphabet, solver, "Your NFA has some dead states."));
}
//Grade computation
int grade = Math.Max(maxGrade - deadStateDeduction - tooBigDeduction - incorrectDeduction, 0);
return new Pair<int, IEnumerable<NFAFeedback>>(grade, feedbacks);
}