本文整理汇总了C#中Sequence.Choose方法的典型用法代码示例。如果您正苦于以下问题:C# Sequence.Choose方法的具体用法?C# Sequence.Choose怎么用?C# Sequence.Choose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sequence
的用法示例。
在下文中一共展示了Sequence.Choose方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ChooseAction
private CompoundTerm ChooseAction(Sequence<Action> actions, IState iState)
{
Set<int> coveredActs;
double minCov = 1.0;
double maxv = 0.0;
IState tState;
Action maxAct = actions.Head;
TransitionProperties tp;
if (!cov.ContainsKey(iState))
{
maxAct = actions.Choose();
cov[iState] = (1.0/actions.Count);
v[iState] = 1.0;
// System.Console.WriteLine("inside if " + iState.GetHashCode() + " cov"+ cov[iState]);
return maxAct;
}
else if (cov.ContainsKey(iState) && cov[iState] < 1.0)
{
coveredActs = new Set<int>(this.findCoveredActs(iState));
Set<int> acts = new Set<int>();
foreach (Action a in actions)
{
if (!coveredActs.Contains(a.GetHashCode()))
{
System.Console.WriteLine(a.GetHashCode());
tState = modelProgram.GetTargetState(iState, a, null, out tp);
if (!cov.ContainsKey(tState))
{
minCov = 0;
maxAct = a;
}
else if (cov[tState] <= minCov)
{
minCov = cov[tState];
maxAct = a;
}
}
else
{
acts.Add(a.GetHashCode());
tState = modelProgram.GetTargetState(iState, a, null, out tp);
if (v.ContainsKey(tState))
maxv = Math.Max(maxv, v[tState]);
}
}
acts = acts.Add(maxAct.GetHashCode());
cov[iState] = ( acts.Count/ actions.Count);
if (v.ContainsKey(iState))
v[iState] = Math.Min(v[iState], (alpha * maxv));
else
v[iState] = alpha * maxv;
//System.Console.WriteLine("inside <1.0 " + iState.GetHashCode() + " cov " + cov[iState]);
return maxAct;
}
else if (cov.ContainsKey(iState) && cov[iState] == 1.0)
{
foreach (Action a in actions)
{
tState = modelProgram.GetTargetState(iState, a, null, out tp);
if (!cov.ContainsKey(tState))
{
maxv = 1.0;
maxAct = a;
}
else if (cov.ContainsKey(tState) && maxv <= v[tState])
{
maxv = v[tState];
maxAct = a;
}
}
if (v.ContainsKey(iState))
v[iState] = Math.Min(v[iState], (alpha * maxv));
else
v[iState] = alpha * maxv;
//System.Console.WriteLine("inside else " + iState.GetHashCode() + " " + v[iState]);
return maxAct;
}
else
{
//System.Console.WriteLine("Should not be reachable!! cov" + cov[iState]);
return maxAct;
}
}
示例2: SelectAction
/// <summary>
/// Select an action that is enabled in the current state
/// and whose action symbol is in the set <paramref name="actionSymbols"/>.
/// Default action selection strategy is random.
/// </summary>
/// <param name="actionSymbols">set of candidate action symbols</param>
/// <returns>the chosen action or null if no choice is possible</returns>
/// <remarks>Can be overwritten in a dervied class to encorporate different
/// action selection strategies.</remarks>
public virtual CompoundTerm SelectAction(Set<Symbol> actionSymbols)
{
if (actionSymbols == null)
throw new ArgumentNullException("actionSymbols");
if (actionSymbols.IsEmpty)
return null;
Sequence<CompoundTerm> actions = new Sequence<CompoundTerm>(this.GetEnabledActions(actionSymbols));
if (actions.IsEmpty)
return null;
return actions.Choose();
}