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


C# Graph.GetVertices方法代码示例

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


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

示例1: Main

    public static void Main( string[] args ) {

        Graph g = new  Graph();

        Vertex pre = null;
        for(int i = 0; i < 10; i++) {
            Vertex v = new Vertex();
            v.assignName("vertex " + i);
            g.AddVertex(v);
            if(pre != null) {
                g.AddEdge(pre, v);
            }
            pre = v;
        }
		g.run(g.GetVertices().next());
        g.display();
        System.Console.In.Read();
    }
开发者ID:flaviommedeiros,项目名称:FeatureIDE,代码行数:18,代码来源:MainClass.cs

示例2: GetPath

    //Pathfinding tattico: costruisce il percorso a costo minimo con A* con costi delle connessioni che tengono conto della mappa di influenza
    public List<PathFindingVertex> GetPath(Graph graph, int start, int goal)
    {
        PathFindingNode startNode = new PathFindingNode (start, 0, EstimateFrom(start,goal));

        PathFindingNode current = new PathFindingNode(-1,0,0);

        //Inizializza lista nodi chiusi (già visitati) e aperti (da visitare)
        PathFindingList open = new PathFindingList();
        PathFindingList closed = new PathFindingList();

        open.AddNode(startNode);

        //Itera tutti i nodi da visitare
        while (open.Length() > 0) {

            current = open.SmallestElement();

            //Se il nodo corrente da visitare è l'obiettivo, termina iterazione
            if (current.ID == goal){
                break;
            }

            List<Vertex> connections = graph.GetVertices(current.ID);

            //Itera tutte le connessioni che partono dal nodo corrente
            foreach (Vertex connection in connections){

                Node end = connection.END;
                float endCost = current.costSoFar + connection.Cost;
                float endHeuristic;
                PathFindingNode endRecord;

                //Se il nodo al termine della connessione è tra i chiusi....
                if (closed.Contains(end)){

                    //Record corrispondente al nodo terminale nella lista dei visitati
                    endRecord = closed.Find(end);

                    /*Se è stato trovato un percorso migliore verso il nodo terminale
                    rispetto a quello già registrato tra gli aperti...*/
                    if (endRecord!=null && endRecord.costSoFar > endCost) {

                        //Rimuove il nodo dai chiusi
                        closed.RemoveNode(endRecord);

                        //Usa i vecchi valori del nodo per ricalcolare l'euristica
                        endHeuristic = endRecord.estimatedTotalCost - endRecord.costSoFar;
                    }

                    else continue;

                }

                //Se invece il nodo terminale è tra gli aperti....
                else if (open.Contains(end)) {

                    //Record corrispondente al nodo terminale nella lista degli aperti
                    endRecord = open.Find(end);

                    /*Se è stato trovato un percorso migliore verso il nodo terminale
                    rispetto a quello già registrato tra gli aperti....*/
                    if (endRecord.costSoFar > endCost) {

                        //Uso i vecchi valori del nodo per ricalcolare l'euristica
                        endHeuristic = endRecord.estimatedTotalCost - endRecord.costSoFar;
                    }

                    else continue;

                }

                /*Se invece il nodo terminale non è nè tra i chiusi nè tra gli aperti, crea un nuovo record
                 * ed effettua la stima della distanza dall'obiettivo*/
                else {

                    endRecord = new PathFindingNode(end.ID);

                    endHeuristic = EstimateFrom(end.ID,goal);

                }

                //Aggiorno record con nuovi valori
                endRecord.costSoFar = endCost;
                endRecord.connection = new PathFindingVertex(current,endRecord);
                endRecord.estimatedTotalCost = endCost + endHeuristic;

                if (!open.Contains(end))
                    open.AddNode(endRecord);

            }

            open.RemoveNode(current);
            closed.AddNode(current);

        }

        //Se il nodo corrente non è l'obiettivo, il nodo non è stato trovato e restituisce null
        if (current.ID!=goal)
            return null;
//.........这里部分代码省略.........
开发者ID:Nosfe7,项目名称:Island-Wars,代码行数:101,代码来源:PathFinding.cs

示例3: ComputeTranspose

    //refines
    public Graph ComputeTranspose( Graph the_graph )
    {
        int i;
        string theName;

        //dja: Added for performance improvement
        Dictionary<string, Vertex> newVertices = new Dictionary<string, Vertex>();

        // Creating the new Graph
        Graph newGraph = new  Graph();

        // Creates and Adds the vertices with the same name
        for ( Iterator<Vertex> vxiter = GetVertices(); vxiter.hasNext(); )
        {
            theName = vxiter.next().GetName();
            //dja: changes for performance improvement
            Vertex v = new  Vertex( ).assignName( theName );
        //            newGraph.AddVertex( new  Vertex().assignName( theName ) );
            newGraph.AddVertex( v );

            //dja: Added for performance improvement
            newVertices.Add( theName, v );
        }

        Vertex theVertex, newVertex;
        Vertex theNeighbor;
        Vertex newAdjacent;
        EdgeIfc newEdge;

        // Adds the transposed edges
        // dja: Added line below for performance improvements
        Iterator<Vertex> newvxiter = newGraph.GetVertices( );
        for ( Iterator<Vertex> vxiter = GetVertices(); vxiter.hasNext(); )
        {
            // theVertex is the original source vertex
            // the newAdjacent is the reference in the newGraph to theVertex
            theVertex = vxiter.next();

            // dja: performance improvement fix
            // newAdjacent = newGraph.findsVertex( theVertex.GetName() );
            newAdjacent = newvxiter.next( );

            for( Iterator<Vertex> neighbors = theVertex.GetNeighbors(); neighbors.hasNext(); )
            {
                // Gets the neighbor object
                theNeighbor = neighbors.next();

                // the new Vertex is the vertex that was adjacent to theVertex
                // but now in the new graph
                // dja: performance improvement fix
                // newVertex = newGraph.findsVertex( theNeighbor.GetName() );
                newVertex = ( Vertex ) newVertices[theNeighbor.GetName( )];

                // Creates a new Edge object and adjusts the adornments
                newEdge = newGraph.AddEdge( newVertex, newAdjacent );
                //newEdge.adjustAdorns( theNeighbor.edge );

                // Adds the new Neighbor object with the newly formed edge
                // newNeighbor = new $TEqn.Neighbor(newAdjacent, newEdge);
                // (newVertex.neighbors).Add(newNeighbor);

            } // all adjacentNeighbors
        } // all the vertices

        return newGraph;
    }
开发者ID:bungaca,项目名称:abstools,代码行数:67,代码来源:Graph.cs

示例4: populateGraph

        //Takes a graph, creates a new tab for it, and fills in the GUI components
        //The vertices are created where each vertex is in verts
        private void populateGraph(Graph g, List<GUIVertex> verts)
        {
            int n = g.GetVertices().Count;

            makeNewGraphPanel(g);

            updateCurrentTool(AppTool.AddVertexTool);

            float angleAmount = 360f / n;
            Vector2 center = new Vector2(256, 170);

            for (int i = 0; i < g.GetVertices().Count; i++ )
            {
                Point addPoint = verts[i].Pos;
                for (int j = 0; j < verts.Count; j++)
                {
                    if (g.GetVertices()[i].Label.Equals(verts[j]))
                    {
                        addPoint = verts[j].Pos;
                        break;
                    }
                }

                CurrentGraphPanel.AddVertex(g.GetVertices()[i], addPoint);
            }

            foreach (Edge e in g.GetEdges())
            {
                int guiIndex1 = g.GetVertices().IndexOf(e.GetFromVertex());
                int guiIndex2 = g.GetVertices().IndexOf(e.GetToVertex());

                CurrentGraphPanel.AddEdge(CurrentGraphPanel.Vertices[guiIndex1], CurrentGraphPanel.Vertices[guiIndex2], e);
            }

            selectedItemPropertyGrid.SelectedObject = g;
        }
开发者ID:bschwind,项目名称:Graph-App,代码行数:38,代码来源:GraphAppGUI.cs


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