本文整理汇总了C#中Automaton.EliminateDeadStates方法的典型用法代码示例。如果您正苦于以下问题:C# Automaton.EliminateDeadStates方法的具体用法?C# Automaton.EliminateDeadStates怎么用?C# Automaton.EliminateDeadStates使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Automaton
的用法示例。
在下文中一共展示了Automaton.EliminateDeadStates方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetGrade
/// <summary>
/// Computes the grade for attempt using all the possible metrics
/// </summary>
/// <param name="solutionNFA">correct nfa</param>
/// <param name="attemptNFA">nfa to be graded</param>
/// <param name="alpahbet">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="level">Feedback level</param>
/// <returns>Grade for nfa2</returns>
public static Pair<int, IEnumerable<NFAFeedback>> GetGrade(
Automaton<BDD> solutionNFA, Automaton<BDD> attemptNFA, HashSet<char> alphabet,
CharSetSolver solver, long timeout, int maxGrade, FeedbackLevel level)
{
var feedbacks = new List<NFAFeedback>();
int deadStateDeduction = 0;
int tooBigDeduction = 0;
int incorrectDeduction = 0;
// Remove at most a percentage of max grade when NFA is big
double maxDeductionForTooBig = ((double)maxGrade * 0.3);
double maxDeductionForDeadStates = ((double)maxGrade * 0.1);
double solutionStateCount = solutionNFA.StateCount;
double attemptStateCount = attemptNFA.StateCount;
double solutionTransCount = solutionNFA.MoveCount;
double attemptTransCount = attemptNFA.MoveCount;
NFAEditDistanceProvider nfaedp = new NFAEditDistanceProvider(solutionNFA, alphabet, solver, timeout);
//Check if using epsilon and nondeterminism
if (solutionNFA.IsEpsilonFree)
solutionNFA.CheckDeterminism(solver);
if (attemptNFA.IsEpsilonFree)
attemptNFA.CheckDeterminism(solver);
bool shouldUseEpsilon = !solutionNFA.IsEpsilonFree && attemptNFA.IsEpsilonFree;
bool shouldUseNonDet = !shouldUseEpsilon && !solutionNFA.isDeterministic && attemptNFA.isDeterministic;
//Check if solution has dead states and remove if it does
var statesBeforeDeadStatesElimination = attemptNFA.StateCount;
attemptNFA.EliminateDeadStates();
var solutionHasDeadStates = attemptNFA.StateCount < statesBeforeDeadStatesElimination;
//Start checking equiv
bool areEquivalent = solutionNFA.IsEquivalentWith(attemptNFA, solver);
if (areEquivalent)
{
// prompt nfa is correct
feedbacks.Insert(0, new NFAStringFeedback(level, alphabet, solver, "Your NFA accepts the CORRECT language."));
#region Check number of states and decrease grade if too big
int stateDiff = (int)(attemptStateCount - solutionStateCount);
int transDiff = (int)(attemptTransCount - solutionTransCount);
//If is not minimal apply deduction and compute edit
if (stateDiff > 0 || transDiff > 0)
{
#region Try to collapse for feedback
// Try to find a way to collaps states or remove states and transitions to make the NFA smaller
NFAEditScript collapseScript = null;
var edit = nfaedp.NFACollapseSearch(attemptNFA);
if (edit != null)
{
collapseScript = new NFAEditScript();
collapseScript.script.Insert(0, edit);
}
feedbacks.Add(new NFANotMinimalFeedback(level, alphabet, stateDiff, transDiff, collapseScript, solver));
#endregion
#region Compute tooBigDeduction
if (stateDiff > 0)
{
// ((att/sol)^2)-1
var stateRatio = attemptStateCount / solutionStateCount;
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
//.........这里部分代码省略.........