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


C# Graph.addEdge方法代码示例

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


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

示例1: Start

    // Use this for initialization
    public void Start()
    {
        //build graph
        graph = new Graph<SpeechData, string>(15,false);
        string[] arr;// = gameObject.GetComponent<speech>().introLines;

        //Quest
        arr = new string[] {
            "You want a quest?",
            "Sure",
            "No",
        };
        graph.addItem(new SpeechData(arr, "quest", true));

        //Accept quest
        arr = new string[] {
            "Quest Accepted"
        };
        graph.addItem(new SpeechData(gameObject.GetComponent<speech>().questLines, "accept", false));

        //Decline quest
        arr = new string[] {
            "Quest Declined"
        };
        graph.addItem(new SpeechData(arr, "decline", false, true));

        //Close
        arr = new string[] {
            "See you later."
        };
        graph.addItem(new SpeechData(arr, "close", false, true));

        //Help
        arr = new string[] {
            "Temp help string"
        };
        graph.addItem(new SpeechData(arr, "help", false));

        //Busy
        arr = new string[] {
            "I see you're busy.",
            "You're already on a job.",
            "You can't help me if you're helping someone else.",
            "Sorry, the script says you can only help one person at a time."
        };
        graph.addItem(new SpeechData(arr, "busy", false, true));

        //Complain
        arr = new string[] {
            "Well you should get back on the job.",
            "You still don't have it!"
        };
        graph.addItem(new SpeechData(arr, "complain", false, true));

        //Congrat
        arr = new string[] {
            "Great job!",
            "Thanks a lot!"
        };
        graph.addItem(new SpeechData(arr, "congrat", false, true));

        //Reveal
        arr = new string[] {
            "Person has weapon format"
        };
        graph.addItem(new SpeechData(arr, "reveal", false));

        //Hope
        arr = new string[] {
            "Hope that helps.",
            "Glad to be of some help.",
            "Good Luck"
        };
        graph.addItem(new SpeechData(arr, "hope", false, true));

        arr = new string[] {
            "Accuse this person?",
            "GUILTY!!",
            "NOT GUILTY...YET"
        };
        graph.addItem(new SpeechData(arr, "accuse", true));

        arr = new string[] {
            "This person is...",
            ""
        };
        graph.addItem(new SpeechData(arr, "end", false));

        //Intro Lines
        graph.addItem(new SpeechData(gameObject.GetComponent<speech>().introLines, "intro", false));
        curNode = graph.findNode("intro");

        //Passive Lines
        graph.addItem(new SpeechData(gameObject.GetComponent<speech>().passiveLines, "passive", false, true));

        //edges
        graph.addEdge("intro", "accuse", 0);

        graph.addEdge("accuse", "end", 0);
//.........这里部分代码省略.........
开发者ID:aj3x,项目名称:enigmatic,代码行数:101,代码来源:SpeechGraph.cs

示例2: addEdgeWithVertices

		/// <summary> Adds the specified source and target vertices to the graph, if not
		/// already included, and creates a new edge and adds it to the specified
		/// graph similarly to the {@link Graph#addEdge(Object, Object)} method.
		/// 
		/// </summary>
		/// <param name="g">the graph for which the specified edge to be added.
		/// </param>
		/// <param name="sourceVertex">source vertex of the edge.
		/// </param>
		/// <param name="targetVertex">target vertex of the edge.
		/// 
		/// </param>
		/// <returns> The newly created edge if added to the graph, otherwise
		/// <code>null</code>.
		/// </returns>
		public static Edge addEdgeWithVertices(Graph g, System.Object sourceVertex, System.Object targetVertex)
		{
			g.addVertex(sourceVertex);
			g.addVertex(targetVertex);
			
			return g.addEdge(sourceVertex, targetVertex);
		}
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:22,代码来源:GraphHelper.cs

示例3: addEdge

		} // ensure non-instantiability.
		
		/// <summary> Creates a new edge and adds it to the specified graph similarly to the
		/// {@link Graph#addEdge(Object, Object)} method.
		/// 
		/// </summary>
		/// <param name="g">the graph for which the edge to be added.
		/// </param>
		/// <param name="sourceVertex">source vertex of the edge.
		/// </param>
		/// <param name="targetVertex">target vertex of the edge.
		/// </param>
		/// <param name="weight">weight of the edge.
		/// 
		/// </param>
		/// <returns> The newly created edge if added to the graph, otherwise
		/// <code>null</code>.
		/// 
		/// </returns>
		/// <seealso cref="Graph.addEdge(Object, Object)">
		/// </seealso>
		public static Edge addEdge(Graph g, System.Object sourceVertex, System.Object targetVertex, double weight)
		{
			EdgeFactory ef = g.EdgeFactory;
			Edge e = ef.createEdge(sourceVertex, targetVertex);
			
			// we first create the edge and set the weight to make sure that 
			// listeners will see the correct weight upon addEdge.
			e.Weight = weight;
			
			return g.addEdge(e)?e:null;
		}
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:32,代码来源:GraphHelper.cs

示例4: generateGraph

        public void generateGraph(int rows, int columns, String[] inp)
        {
            int num_nodes = 0;
            String key;
            char[] charArray, charArray2;

            for (int i = 1; i < rows-1; i++)
            {
                charArray = inp[i].ToCharArray();
                for (int j = 1; j < columns-1; j++)
                {
                    if (charArray[j] != '#')
                    {
                        key = i + "," + j;
                        h.Add(key, num_nodes);
                        if (charArray[j] == 'S')
                        {
                            start_node = num_nodes;
                        }
                        if (charArray[j] == 'E')
                        {
                            end_node = num_nodes;
                        }
                        num_nodes++;
                    }
                }
            }
            g = new Graph<Square>(num_nodes);

            int x, y;

            //Matrica na sosednost
            for (int i = 1; i < rows - 1; i++)
            {
                charArray = inp[i].ToCharArray();
                for (int j = 1; j < columns - 1; j++)
                {
                    if (charArray[j] != '#')
                    {
                        if (charArray[j - 1] != '#')
                        {
                            h.TryGetValue(i + "," + j, out x);
                            h.TryGetValue(i + "," + (j-1), out y);
                            g.addEdge(x, y);
                        }
                        if (charArray[j + 1] != '#')
                        {
                            h.TryGetValue(i + "," + j, out x);
                            h.TryGetValue(i + "," + (j + 1), out y);
                            g.addEdge(x, y);
                        }
                        charArray2 = inp[i - 1].ToCharArray();
                        if (charArray2[j] != '#')
                        {
                            h.TryGetValue(i + "," + j, out x);
                            h.TryGetValue((i-1) + "," + j, out y);
                            g.addEdge(x, y);
                        }
                        charArray2 = inp[i + 1].ToCharArray();
                        if (charArray2[j] != '#')
                        {
                            h.TryGetValue(i + "," + j, out x);
                            h.TryGetValue((i+1) + "," + j, out y);
                            g.addEdge(x, y);
                        }
                    }
                }
            }
        }
开发者ID:brunomore,项目名称:Squares-Desktop,代码行数:69,代码来源:Maze.cs

示例5: parse

	public Graph parse()
	{
		Graph graph = new Graph();
		string line;
		Random rng = new Random();

		// Read the file and line by line and fill the graph.
		System.IO.StreamReader file = 
			new System.IO.StreamReader(filepath);

		if (file == null) 
		{
			Console.WriteLine ("file not found");
			return null;
		}

		while((line = file.ReadLine()) != null)
		{
			if(line.Equals("  node"))
			{
				int id;
				string sid;
				string name;
				string[] words;
				char[] separatingChars = { ' ' };

				file.ReadLine(); // [

				sid = file.ReadLine(); // id ie. id 0
				words = sid.Split(separatingChars, System.StringSplitOptions.RemoveEmptyEntries );
				id = Int32.Parse(words[1]);

				name = file.ReadLine(); // name ie. lable "Beak"
				words = name.Split(separatingChars, System.StringSplitOptions.RemoveEmptyEntries );
				name = words[1];

				graph.addNode(new Graph.Node(id, name, rng.Next(-100, 100), rng.Next(-100, 100), rng.Next(-100, 100)));

			}
			else if(line.Equals("  edge"))
			{
				int target, source;
				string s;
				string[] words;
				char[] separatingChars = { ' ' };

				file.ReadLine(); // [

				s = file.ReadLine(); // source ie. source 19
				words = s.Split(separatingChars, System.StringSplitOptions.RemoveEmptyEntries );
				source = Int32.Parse(words[1]);

				s = file.ReadLine(); // target ie. target 1
				words = s.Split(separatingChars, System.StringSplitOptions.RemoveEmptyEntries );
				target = Int32.Parse(words[1]);

				graph.addEdge(source, target);
			}
		}

		file.Close();
		return graph;
	}
开发者ID:wkjdfx,项目名称:165-P2,代码行数:63,代码来源:Parser.cs

示例6: createGraph

    //Will create the graph treating all reachable areas as nodes
    private void createGraph()
    {
        currentGraph = new Graph();

        int height = boolTiles.GetLength (0);
        int width = boolTiles.GetLength (1);
        //Here is where we form our graph
        //First we add all of the nodes
        for (int i = 0; i < height; i++) {
            for (int j = 0; j < width; j++) {
                if (boolTiles[i, j] == true) {
                    currentGraph.addNode(new Node(i, j));
                }
            }
        }
        //Now we add all of our connections
        foreach(Node node in currentGraph.nodes.Values) {
            int nodeHeight = node.heightPos;
            int nodeWidth = node.widthPos;

            bool isUp = nodeHeight > 0;
            bool isRight = nodeWidth < (width - 1);
            bool isDown = nodeHeight < (height - 1);
            bool isLeft = nodeWidth > 0;

            /*
            //We need to check upper left pos
            if (isUp && isLeft && boolTiles[nodeHeight - 1, nodeWidth - 1]) {
                currentGraph.addEdge(node, currentGraph.getNodeByLocation(nodeHeight - 1, nodeWidth - 1));
            }
            */
            //We need to check upper pos
            if (isUp && boolTiles[nodeHeight - 1, nodeWidth]) {
                currentGraph.addEdge(node, currentGraph.getNodeByLocation(nodeHeight - 1, nodeWidth));
            }
            /*
            //We need to check upper right pos
            if (isUp && isRight && boolTiles[nodeHeight - 1, nodeWidth + 1]) {
                currentGraph.addEdge(node, currentGraph.getNodeByLocation(nodeHeight - 1, nodeWidth + 1));
            }
            */
            //We need to check right pos
            if (isRight && boolTiles[nodeHeight, nodeWidth + 1]) {
                currentGraph.addEdge(node, currentGraph.getNodeByLocation(nodeHeight, nodeWidth + 1));
            }
            /*
            //We need to check lower right pos
            if (isDown && isRight && boolTiles[nodeHeight + 1, nodeWidth + 1]) {
                currentGraph.addEdge(node, currentGraph.getNodeByLocation(nodeHeight + 1, nodeWidth + 1));
            }
            */
            //We need to check lower pos
            if (isDown && boolTiles[nodeHeight + 1, nodeWidth]) {
                currentGraph.addEdge(node, currentGraph.getNodeByLocation(nodeHeight + 1, nodeWidth));
            }
            /*
            //We need to check lower left pos
            if (isDown && isLeft && boolTiles[nodeHeight + 1, nodeWidth - 1]) {
                currentGraph.addEdge(node, currentGraph.getNodeByLocation(nodeHeight + 1, nodeWidth - 1));
            }
            */
            //We need to check left pos
            if (isLeft && boolTiles[nodeHeight, nodeWidth - 1]) {
                currentGraph.addEdge(node, currentGraph.getNodeByLocation(nodeHeight, nodeWidth - 1));
            }
        }
    }
开发者ID:charder,项目名称:GameAIUnity,代码行数:68,代码来源:WorldCreator.cs

示例7: AddEdgeCommand

        public AddEdgeCommand(Graph g, Vertex v1, Vertex v2)
        {
            mementos.Add(g.getMemento());

            _edge = g.addEdge(v1, v2);
        }
开发者ID:bidacek,项目名称:GraphTheoryEditor,代码行数:6,代码来源:Parser.cs


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