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


C# Set.Choose方法代码示例

本文整理汇总了C#中Set.Choose方法的典型用法代码示例。如果您正苦于以下问题:C# Set.Choose方法的具体用法?C# Set.Choose怎么用?C# Set.Choose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Set的用法示例。


在下文中一共展示了Set.Choose方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ShowReachable

        /// <summary>
        /// Show all transitions from the given node and from the nodes that are reached from 
        /// the given node etc., until the maximum nr of transitions is reached
        /// </summary>
        internal void ShowReachable(Node node)
        {
            int transCnt = (firstExploration ? (initTransitions < 0 ? maxTransitions : initTransitions) : maxTransitions);
            firstExploration = false;

            if (excludeIsomorphicStates)
            {
                Set<IState> frontier = new Set<IState>(stateMap[node]);
                StateContainer<IState> visited = new StateContainer<IState>(this.modelProgram, stateMap[node]);
                while (!frontier.IsEmpty && this.transitions.Count < transCnt)
                {
                    IState sourceIState = frontier.Choose(0);
                    Node sourceNode = nodeMap[sourceIState];
                    frontier = frontier.Remove(sourceIState);
                    foreach (Symbol aSymbol in this.modelProgram.PotentiallyEnabledActionSymbols(sourceIState))
                    {
                        foreach (CompoundTerm action in this.modelProgram.GetActions(sourceIState, aSymbol))
                        {
                            Node targetNode;
                            if (TryGetTargetNode(sourceNode, action, out targetNode))
                            {
                                IState targetIState = stateMap[targetNode];
                                IState isomorphicState;
                                Transition t;
                                if (!visited.HasIsomorphic(targetIState, out isomorphicState))
                                {
                                    frontier = frontier.Add(targetIState);
                                    //visited = visited.Add(targetIState);
                                    visited.Add(targetIState);
                                    t = new Triple<Term, CompoundTerm, Term>(sourceNode, action, targetNode);
                                }
                                else
                                {
                                    if (collapseExcludedIsomorphicStates)
                                        t = new Triple<Term, CompoundTerm, Term>(sourceNode, action, nodeMap[isomorphicState]);
                                    else
                                    {
                                        Term isoNode = nodeMap[isomorphicState];
                                        t = new Triple<Term, CompoundTerm, Term>(sourceNode, action, targetNode);
                                        if (!targetNode.Equals(sourceNode) && !targetNode.Equals(isoNode))
                                            groupingTransitions = groupingTransitions.Add(new Triple<Term, CompoundTerm, Term>(targetNode, new CompoundTerm(new Symbol("IsomorphicTo"), new Sequence<Term>()), isoNode));
                                    }
                                }
                                this.transitions = this.transitions.Add(t);
                                this.hiddenTransitions = this.hiddenTransitions.Remove(t);
                            }
                        }
                    }
                }
                //Console.WriteLine(dashedTransitions.ToString());
                //Console.WriteLine(visited.ToString());
            }
            else
            {
                Set<Node> frontier = new Set<Node>(node);
                Set<Node> visited = frontier;

                while (!frontier.IsEmpty && this.transitions.Count < transCnt)
                {
                    Node sourceNode = frontier.Choose(0);
                    frontier = frontier.Remove(sourceNode);
                    foreach (Symbol aSymbol in this.modelProgram.PotentiallyEnabledActionSymbols(stateMap[sourceNode]))
                    {
                        foreach (CompoundTerm action in this.modelProgram.GetActions(stateMap[sourceNode], aSymbol))
                        {
                            Node targetNode;
                            if (TryGetTargetNode(sourceNode, action, out targetNode))
                            {
                                if (!visited.Contains(targetNode))
                                {
                                    frontier = frontier.Add(targetNode);
                                    visited = visited.Add(targetNode);
                                }
                                Transition t = new Triple<Term, CompoundTerm, Term>(sourceNode, action, targetNode);
                                this.transitions = this.transitions.Add(t);
                                this.hiddenTransitions = this.hiddenTransitions.Remove(t);
                            }
                        }
                    }
                }
            }
        }
开发者ID:juhan,项目名称:NModel,代码行数:86,代码来源:ModelProgramGraphView.cs

示例2: CheckReachability

        /// <summary>
        /// Check if the term represented by goal is reachable. Empty string results in traversing the whole state space.
        /// </summary>
        /// <param name="goal">The goal term involving the model program name as outer function symbol.</param>
        public ReachabilityResult CheckReachability(string goal)
        {
            uint transCnt = 0;
            uint stateCount = 0;
            //(firstExploration ? (initTransitions < 0 ? maxTransitions : initTransitions) : maxTransitions);
            //firstExploration = false;
            //excludeIsomorphicStates = false;
            Set<CompoundTerm> goals = processGoal(modelProgram, goal);
            Pair<Set<CompoundTerm>, Set<Term>> simpleAndFsmGoals = splitGoals(goals);
            if (GoalsSatisfied(simpleAndFsmGoals, modelProgram.InitialState)) goto end;

            if (excludeIsomorphicStates)
            {

                Set<IState> frontier = new Set<IState>(modelProgram.InitialState);
                //stateCount++;
                //Set<IState> visited = Set<IState>.EmptySet;
                StateContainer<IState> visited = new StateContainer<IState>(this.modelProgram, modelProgram.InitialState);
                stateCount++;
                // need to add a check about the initial state.
                Set<string> transitionPropertyNames = Set<string>.EmptySet;
                TransitionProperties transitionProperties;
                while (!frontier.IsEmpty)
                {
                    IState sourceIState = frontier.Choose(0);
                    frontier = frontier.Remove(sourceIState);
                    foreach (Symbol aSymbol in this.modelProgram.PotentiallyEnabledActionSymbols(sourceIState))
                    {
                        foreach (CompoundTerm action in this.modelProgram.GetActions(sourceIState, aSymbol))
                        {
                            //Node targetNode = GetTargetNode(sourceNode, action);
                            IState targetIState = modelProgram.GetTargetState(sourceIState, action, transitionPropertyNames, out transitionProperties);
                            //if (this.modelProgram.IsAccepting(targetIState))
                            //    this.acceptingNodes = this.acceptingNodes.Add(targetNode);
                            //if (!this.modelProgram.SatisfiesStateInvariant(targetState))
                            //    this.errorNodes = this.errorNodes.Add(targetNode);
                            //IState isomorphicState;
                            //Transition t;
                            transCnt++;
                            IState isomorphicState;
                            if (!visited.HasIsomorphic(targetIState, out isomorphicState))
                            {
                                if (GoalsSatisfied(simpleAndFsmGoals, targetIState)) goto end;
                                frontier = frontier.Add(targetIState);
                                visited.Add(targetIState);
                                stateCount++;
                                //visited.Add(targetIState);
                                //t = new Triple<Term, CompoundTerm, Term>(sourceNode, action, targetNode);
                            }
                            //else
                            //{
                            //    //if (collapseExcludedIsomorphicStates)
                            //    //    t = new Triple<Term, CompoundTerm, Term>(sourceNode, action, nodeMap[isomorphicState]);
                            //    //else
                            //    {
                            //        Term isoNode = nodeMap[isomorphicState];
                            //        t = new Triple<Term, CompoundTerm, Term>(sourceNode, action, targetNode);
                            //        if (!targetNode.Equals(sourceNode) && !targetNode.Equals(isoNode))
                            //            groupingTransitions = groupingTransitions.Add(new Triple<Term, CompoundTerm, Term>(targetNode, new CompoundTerm(new Symbol("IsomorphicTo"), new Sequence<Term>()), isoNode));
                            //    }
                            //}
                            //this.transitions = this.transitions.Add(t);
                            //this.hiddenTransitions = this.hiddenTransitions.Remove(t);
                        }
                    }
                }

                //Set<IState> frontier = new Set<IState>(stateMap[node]);
                //StateContainer<IState> visited = new StateContainer<IState>(this.modelProgram, stateMap[node]);
                //while (!frontier.IsEmpty && this.transitions.Count < transCnt)
                //{
                //    IState sourceIState = frontier.Choose(0);
                //    Node sourceNode = nodeMap[sourceIState];
                //    frontier = frontier.Remove(sourceIState);
                //    foreach (Symbol aSymbol in this.modelProgram.PotentiallyEnabledActionSymbols(sourceIState))
                //    {
                //        foreach (CompoundTerm action in this.modelProgram.GetActions(sourceIState, aSymbol))
                //        {
                //            Node targetNode = GetTargetNode(sourceNode, action);
                //            IState targetIState = stateMap[targetNode];
                //            IState isomorphicState;
                //            Transition t;
                //            if (!visited.HasIsomorphic(targetIState, out isomorphicState))
                //            {
                //                frontier = frontier.Add(targetIState);
                //                //visited = visited.Add(targetIState);
                //                visited.Add(targetIState);
                //                t = new Triple<Term, CompoundTerm, Term>(sourceNode, action, targetNode);
                //            }
                //            else
                //            {
                //                if (collapseExcludedIsomorphicStates)
                //                    t = new Triple<Term, CompoundTerm, Term>(sourceNode, action, nodeMap[isomorphicState]);
                //                else
                //                {
                //                    Term isoNode = nodeMap[isomorphicState];
//.........这里部分代码省略.........
开发者ID:juhan,项目名称:NModel,代码行数:101,代码来源:Reachability.cs

示例3: HideReachable

 /// <summary>
 /// Hide all previously shown transitions from the given node
 /// and those that can be reached recursively
 /// </summary>
 internal void HideReachable(Node node)
 {
     Set<Transition> alltransitions = this.hiddenTransitions.Union(this.transitions);
     Set<Node> frontier = new Set<Term>(node);
     Set<Node> visited = frontier;
     Set<Transition> tobehidden = Set<Transition>.EmptySet;
     while (!frontier.IsEmpty)
     {
         Node n = frontier.Choose(0);
         frontier = frontier.Remove(n);
         Set<Transition> toBeHiddenTransitions =
            alltransitions.Select(delegate(Transition t) { return t.First.Equals(n); });
         Set<Node> targetStates =
             toBeHiddenTransitions.Convert<Node>(delegate(Transition t) { return t.Third; });
         frontier = frontier.Union(targetStates.Difference(visited));
         visited = visited.Union(targetStates);
         tobehidden = tobehidden.Union(toBeHiddenTransitions);
     }
     this.hiddenTransitions = this.hiddenTransitions.Union(tobehidden);
     this.transitions = this.transitions.Difference(tobehidden);
 }
开发者ID:juhan,项目名称:NModel,代码行数:25,代码来源:ModelProgramGraphView.cs

示例4: ComputeIsomorphismFromNode

        /// <summary>
        /// Computes an isomorphism that is consistent with M.
        /// M already includes a partial isomorphism from all g1 nodes not in ns.
        /// </summary>
        Map<Node, Set<Node>> ComputeIsomorphismFromNode(Set<Node> ns, Map<Node, Set<Node>> M)
        {
            //isomorphism was found
            if (ns.IsEmpty)
                return M;

            //choose a particular node from ns
            Node x = ns.Choose(0);
            Set<Node> ns1 = ns.Remove(x);

            //TBD: use the optimization with order-idependent nodes
            //to eliminate backtracking over orders that do not make a difference
            //this is done by choosing a subset of nodes from ns and removing them
            //all at once thus skipping several levels in the search tree rather than
            //picking nodes one at a time

            //try with a mapping from x to to some y
            //this basically corresponds to backtracking over the y's
            foreach (Node y in M[x])
            {
                Map<Node, Set<Node>> M1 = M.Override(x, new Set<Node>(y));
                //Remove first all instances of y from the other candidates
                Map<Node, Set<Node>> M1a = RemoveUsedG2Node(M1, x, y);
                if (M1a != null)
                {
                    Map<Node, Set<Node>> M2 = Refine(M1a);
                    if (M2 != null)
                    {
                        Map<Node, Set<Node>> I = ComputeIsomorphismFromNode(ns1, M2);
                        if (I != null)
                            return I;
                    }
                }
            }
            //isomorphism was not found
            return null;
        }
开发者ID:juhan,项目名称:NModel,代码行数:41,代码来源:GraphIsomorphism.cs


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