Beispiel #1
0
        private FSMGraph GenerateGraph()
        {
            //FOR DETAILED EXPLANATION please see SimpleGraph example project
            var dataGraph = new FSMGraph();

            foreach (FSM_State state in fsmStates)
            {
                var dataVertex = new DataVertex(state.name);
                dataGraph.AddVertex(dataVertex);
            }
            var vlist = dataGraph.Vertices.ToList();

            for (int i = 0; i < vlist.Count; i++)
            {
                FSM_State stateDst = fsmStates[i];
                for (int j = 0; j < vlist.Count; j++)
                {
                    FSM_State stateSrc = fsmStates[j];
                    if (stateSrc.next_states.ContainsKey(stateDst.name))
                    {
                        var dataEdge = new DataEdge(vlist[j], vlist[i])
                        {
                            Text = string.Format("{0} -> {1}", vlist[j], vlist[i])
                        };
                        dataGraph.AddEdge(dataEdge);
                    }
                }
            }
            //Then create two edges optionaly defining Text property to show who are connected
            //var dataEdge = new DataEdge(vlist[0], vlist[1]) { Text = string.Format("{0} -> {1}", vlist[0], vlist[1]) };
            //dataGraph.AddEdge(dataEdge);
            //dataEdge = new DataEdge(vlist[2], vlist[0]) { Text = string.Format("{0} -> {1}", vlist[2], vlist[0]) };
            //dataGraph.AddEdge(dataEdge);


            //dataEdge = new DataEdge(vlist[1], vlist[2]) { Text = string.Format("{0} -> {1}", vlist[2], vlist[1]) };
            //dataGraph.AddEdge(dataEdge);
            return(dataGraph);
        }