当前位置: 首页>>代码示例>>C#>>正文


C# Sequence.Choose方法代码示例

本文整理汇总了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;
            }
        }
开发者ID:juhan,项目名称:NModel,代码行数:86,代码来源:Algorithms.cs

示例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();
        }
开发者ID:juhan,项目名称:NModel,代码行数:24,代码来源:Strategy.cs


注:本文中的Sequence.Choose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。