private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            GraphViewer graphViewer = new GraphViewer();
            graphViewer.BindToPanel(Panel);
            Graph graph = new Graph();

            graph.AddEdge("A", "B");
            graph.Attr.LayerDirection = LayerDirection.LR;
            graphViewer.Graph = graph; // throws exception
        }
        private void BFS_Click(object sender, RoutedEventArgs e)
        {
            Graph graph = convertFile(filename.Text);

            Microsoft.Msagl.GraphViewerGdi.GViewer viewer = new Microsoft.Msagl.GraphViewerGdi.GViewer();
            for (int i = 0; i < graph.getLenNodes(); i++)
            {
                for (int j = 0; j < graph.getNodes()[i].getLenReq(); j++)
                {
                    string a1 = graph.getNodes()[i].getCourse();
                    string a2 = graph.getNodes()[i].getReqN(j);
                    g.AddEdge(a1, a2).Attr.Color = Microsoft.Msagl.Drawing.Color.Pink;
                }
            }
            viewer.Graph = g;
            //associate the viewer with the form
            form.SuspendLayout();
            viewer.Dock      = System.Windows.Forms.DockStyle.Fill;
            form.WindowState = System.Windows.Forms.FormWindowState.Maximized;
            form.Controls.Add(viewer);
            form.ResumeLayout();
            //show the form
            form.Show();

            Graph BFSgraph = new Graph();

            graph.BFS(BFSgraph);
            result            = BFSgraph.seperateTerm();
            FinalAnswers.Text = printFinal(result);
            form.Refresh();
        }
Example #3
0
        void DrawGraph(Automaton automaton)
        {
            var graph = new Graph();
            graph.Attr.LayerDirection = LayerDirection.LR;
            int i = 0;
            foreach (var s in automaton.States)
            {
                foreach (var o in s.Output)
                {
                    var index = automaton.States.IndexOf(o.End);
                    var end = ReferenceEquals(automaton.StartState, o.End) ? "Start" : index.ToString();
                    if (ReferenceEquals(s, automaton.StartState))
                    {
                        graph.AddEdge("Start", o.ToString(), end);
                    }
                    else if (o.End.IsFinalState)
                    {
                        graph.AddEdge(i.ToString(), o.ToString(), "End");
                    }
                    else
                    {
                        graph.AddEdge(i.ToString(), o.ToString(), end);
                    }

                }
                i++;
            }
            graphViewer.Graph = graph;
        }
        private static void AddEdge(NeuronViewModelBase selectedNeuron, string id, string source, string target, MsGraph graph, string strength = "1", bool inhibitoryEndpoint = false)
        {
            if (graph.Edges.SingleOrDefault(e => e.Attr.Id == id) == null)
            {
                Edge e = null;
                if (strength != "1")
                {
                    e = graph.AddEdge(source, strength, target);
                    e.Label.FontSize = e.Label.FontSize * 0.8;
                    e.Attr.AddStyle(Microsoft.Msagl.Drawing.Style.Dashed);
                }
                else
                {
                    e = graph.AddEdge(source, target);
                }

                e.Attr.Id = id;
                if (selectedNeuron.TerminalId == id)
                {
                    e.Attr.Color = NeuronGraphView.GetHighlightColor();
                }
                else if (inhibitoryEndpoint)
                {
                    e.Attr.Color = Color.IndianRed;
                }
            }
        }
Example #5
0
        public static void SomeClass()
        {
            var graph = new MSAGL.Drawing.Graph("");
            graph.AddEdge("A", "B");
            graph.AddEdge("A", "B");
            graph.FindNode("A").Attr.FillColor = MSAGL.Drawing.Color.BlanchedAlmond;
            graph.FindNode("B").Attr.FillColor = MSAGL.Drawing.Color.BurlyWood;
            var renderer = new MSAGL.GraphViewerGdi.GraphRenderer(graph);
            renderer.CalculateLayout();
            const int width = 50;
            int height = (int)(graph.Height * (width / graph.Width));
            const PixelFormat pixfmt = System.Drawing.Imaging.PixelFormat.Format32bppPArgb;
            using (var bitmap = new System.Drawing.Bitmap(width, height, pixfmt))
            {
                using (var gfx = System.Drawing.Graphics.FromImage(bitmap))
                {
                    gfx.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                    gfx.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                    gfx.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

                    var rect = new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height);
                    renderer.Render(gfx, rect);
                    bitmap.Save("test.png");

                }

            }
           
        }
Example #6
0
        public GViewer Visualize(int t)
        {
            //create a form
            Form form = new Form();

            //create a viewer object
            GViewer viewer = new GViewer();

            //create a graph object
            Msagl.Graph graph = new Msagl.Graph("Corruption");

            //create the graph content
            foreach (City city in this.cities.Values)
            {
                graph.AddNode(city.name);
                if (city.isInfected)
                {
                    int red = 255, other = 255;
                    if (city.isInfected)
                    {
                        red   = 250;
                        other = 150 - (int)(city.InfectedPercentage(t) * 150);
                    }
                    graph.FindNode(city.name).Attr.FillColor = new Msagl.Color(255, (byte)red, (byte)other, (byte)other);
                }

                foreach (City neigh in city.neighbors.Keys)
                {
                    bool tmp = false;
                    foreach (Edge e in this.infectedEdge)
                    {
                        if ((e.fromCity == city && e.toCity == neigh))
                        {
                            tmp = true;
                        }
                    }
                    if (!tmp)
                    {
                        graph.AddEdge(city.name, neigh.name).Attr.Color = Msagl.Color.Gray;
                    }
                }
            }
            foreach (Edge e in this.infectedEdge)
            {
                graph.AddEdge(e.fromCity.name, e.toCity.name).Attr.Color = Msagl.Color.Red;
            }
            //bind the graph to the viewer
            viewer.Graph = graph;

            //associate the viewer with the form
            form.SuspendLayout();
            viewer.Dock = DockStyle.Fill;
            return(viewer);
            //form.Controls.Add(viewer);
            //form.ResumeLayout();

            //show the form
            //form.ShowDialog();
        }
Example #7
0
        public static Graph AutomatonToDot(BuchiAutomata BA)
        {
            Graph g = new Graph("graph");

            g.Directed = true;
            //g.MinNodeWidth = 0;
            //g.MinNodeHeight = 0;

            Dictionary <string, string> stateToNumber = new Dictionary <string, string>();

            for (int i = 0; i < BA.States.Length; i++)
            {
                string state = BA.States[i];

                //dot += ("s" + stateToNumber[state] + " [" + (isInitial ? "shape=box" : "") + ((isInitial && isFinal) ? "," : "") + (isFinal ? "style=dotted" : "") + "];\n");
                //Node d = g.AddNode("s" + stateToNumber[state.ToString()]);

                string label = "s" + i;
                Node   d     = g.AddNode(label);
                stateToNumber.Add(state, label);

                if (BA.InitialStates.Contains(state)) //.isInitial
                {
                    Node temp = g.AddNode("init-" + label);

                    //temp.Attr.Shape = Shape.InvHouse;
                    temp.Attr.LineWidth = 0;
                    temp.Attr.Color     = Color.White;
                    temp.LabelText      = "";
                    g.AddEdge("init-" + label, label);
                    d.Attr.FillColor = Color.Gray;
                }

                if (state.EndsWith(Constants.ACCEPT_STATE))
                {
                    d.Attr.Shape = Shape.DoubleCircle;
                    //d.Attr.AddStyle(Style.Dotted);
                }
            }

            foreach (Transition transition in BA.Transitions)
            {
                //dot += ("s" + stateToNumber[transition.getSourceState()] + " -> " + "s" + stateToNumber[transition.getTargetState()] + " [label=\"" + transition.getLabels() + "\"]" + ";\n");
                g.AddEdge(stateToNumber[transition.FromState.ToString()], Ultility.Ultility.PPStringList(transition.labels), stateToNumber[transition.ToState.ToString()]);
            }

            return(g);
        }
        private void LoadRoute()
        {
            Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph("graph");
            //create the graph content


            foreach (string[] line in InputData)
            {
                graph.AddEdge(line[0], line[1]).Attr.ArrowheadAtTarget = Microsoft.Msagl.Drawing.ArrowStyle.None;
            }
            foreach (Edge edge in graph.Edges)
            {
                for (int i = 0; i < this.PathNode.Count() - 1; i++)
                {
                    if (edge.Source == PathNode[i] && edge.Target == PathNode[i + 1])
                    {
                        edge.Attr.ArrowheadAtTarget            = ArrowStyle.Normal;
                        edge.Attr.Color                        = Microsoft.Msagl.Drawing.Color.Red;
                        graph.FindNode(edge.Source).Attr.Color = Microsoft.Msagl.Drawing.Color.Red;
                        graph.FindNode(edge.Target).Attr.Color = Microsoft.Msagl.Drawing.Color.Red;
                    }
                    if (edge.Source == PathNode[i + 1] && edge.Target == PathNode[i])
                    {
                        edge.Attr.ArrowheadAtSource            = ArrowStyle.Normal;
                        edge.Attr.Color                        = Microsoft.Msagl.Drawing.Color.Red;
                        graph.FindNode(edge.Source).Attr.Color = Microsoft.Msagl.Drawing.Color.Red;
                        graph.FindNode(edge.Target).Attr.Color = Microsoft.Msagl.Drawing.Color.Red;
                    }
                }
            }
            gViewer1.Graph = graph;
        }
        public void AddEdge(string source, string destination, string edgeText = "")
        {
            this.SuspendLayout();

            // We create an edge object and save it in a HashTable to avoid inserting
            // double edges.
            var newEdge = new NetworkMapEdge()
            {
                Source      = source,
                Destination = destination,
                Text        = edgeText
            };

            if (!_edges.Contains(newEdge))
            {
                _graph.AddEdge(source, edgeText, destination);
                _edges.Add(newEdge);
            }

            var sourceNode      = _graph.FindNode(source);
            var destinationNode = _graph.FindNode(destination);

            sourceNode.Attr.FillColor      = Microsoft.Msagl.Drawing.Color.LightBlue;
            sourceNode.LabelText           = GetNodeText(source);
            destinationNode.Attr.FillColor = Microsoft.Msagl.Drawing.Color.LightBlue;
            destinationNode.LabelText      = GetNodeText(destination);

            _viewer.Graph = _graph;
            this.ResumeLayout();
        }
Example #10
0
        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            Panel.Children.Clear();
            var         nodes       = main.storedata.scenicnode;
            GraphViewer graphViewer = new GraphViewer();

            graphViewer.BindToPanel(Panel);
            Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph();

            foreach (var node in nodes)
            {
                if (node.edges.Count == 0)
                {
                    graph.AddNode(new Node(node.name));
                }
                foreach (var edge in node.edges)
                {
                    graph.AddEdge(node.name, edge.GetDest(nodes).name);
                }
            }
            //graph.AddEdge("A", "B");
            foreach (var node in graph.Nodes)
            {
                node.Attr.Shape       = Microsoft.Msagl.Drawing.Shape.Circle;
                node.Attr.Color       = Microsoft.Msagl.Drawing.Color.Purple;
                node.Attr.LabelMargin = 10;
            }
            graph.Attr.LayerDirection = LayerDirection.LR;
            graphViewer.Graph         = graph; // throws exception
        }
Example #11
0
        /// <summary>
        /// Copies a graph and its GeometryGraph.
        /// </summary>
        /// <param name="parentGraph"></param>
        /// <returns></returns>
        public static Graph CopyGraph(Graph parentGraph)
        {
            GeometryGraph geometryCopy = CopyGraph(parentGraph.GeometryGraph);

            Graph graph=new Graph();
            graph.GeometryGraph = geometryCopy;

            Dictionary<Node,int> nodeId=new Dictionary<Node, int>(geometryCopy.Nodes.Count);
            for (int i = 0; i < geometryCopy.Nodes.Count; i++) {
                nodeId[geometryCopy.Nodes[i]] = i;
                String id = i.ToString();

               graph.AddNode(id);
                var node = graph.FindNode(id);
                node.GeometryNode = geometryCopy.Nodes[i];
                geometryCopy.Nodes[i].UserData = node;

            }

            foreach (var edge in geometryCopy.Edges) {
                String sourceId = nodeId[edge.Source].ToString();
                String targetId = nodeId[edge.Target].ToString();

                var edgeCopy=graph.AddEdge(sourceId, "", targetId);
                edgeCopy.GeometryEdge = edge;
                edge.UserData = edgeCopy;
            }
            return graph;
        }
Example #12
0
        void LoadData(string DatFile)
        {
            uniqD = new Dictionary <long, long>();

            using (var fs = File.OpenRead(DatFile))
            {
                using (var br = new BinaryReader(fs))
                {
                    graphViewer = new GraphViewer();
                    graphViewer.LayoutEditingEnabled = false;
                    graphViewer.BindToPanel(gvPanel);

                    var          dgraph = new Drawing.Graph();
                    Drawing.Edge edg    = null;

                    while (fs.Position < fs.Length - 128)
                    {
                        var tid      = br.ReadInt32();
                        var flags    = br.ReadInt32();
                        var rip      = br.ReadInt64();
                        var rsp      = br.ReadInt64();
                        var from_rip = br.ReadInt64();

                        if (!uniqD.ContainsKey(from_rip))
                        {
                            uniqD.Add(from_rip, rip);
                            edg = dgraph.AddEdge(from_rip.ToString("X"), rip.ToString("X"), rip.ToString("X"));
                        }
                    }

                    graphViewer.Graph = dgraph;
                }
            }
        }
Example #13
0
        private void button1_Click(object sender, EventArgs e)
        {
            ofd.Filter = "Text Documents (*.txt)|*.txt";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                comboBox1.Items.Clear();
                comboBox2.Items.Clear();
                g.clearGraph();
                // Dekalrasi graph drawer
                Microsoft.Msagl.Drawing.Graph graphDrawer = new Microsoft.Msagl.Drawing.Graph("graph");

                // Membuat graph dari text yang di buka
                path.Text = ofd.SafeFileName;
                string[] isi = File.ReadAllLines(ofd.FileName);
                g.setGraph(isi);
                //textBox2.Text = g.Edges[0].Node1;

                // Membuat graph drawer
                for (int i = 0; i < g.Total; i++)
                {
                    graphDrawer.AddEdge(g.Edges[i].Node1, g.Edges[i].Node2).Attr.ArrowheadLength = 1;
                }
                gViewer1.Graph = graphDrawer;

                // Menambah item pada box choose account
                foreach (string node in g.Nodes)
                {
                    comboBox1.Items.Add(node);
                }
                // Assign file ke field contents
                this.contents = new string[int.Parse(isi[0]) + 1];
                this.contents = isi;
            }
        }
Example #14
0
        private void ModulesGraph()
        {
            Graph g = new Graph();

            using (SQLiteCommand command = new SQLiteCommand(ConnectionManager.connection))
            {
                command.CommandText = @"select name from modules";

                SQLiteDataReader DataReader = command.ExecuteReader();
                while (DataReader.Read())
                    g.AddNode(DataReader["name"].ToString());
            }

            using (SQLiteCommand command = new SQLiteCommand(ConnectionManager.connection))
            {
                command.CommandText = @"select * from moddeps";
                SQLiteDataReader DataReader = command.ExecuteReader();
                while (DataReader.Read())
                {
                    Microsoft.Msagl.Drawing.Edge e = g.AddEdge(DataReader["used"].ToString(), "", DataReader["uses"].ToString());
                    e.Attr.LineWidth = int.Parse(DataReader["count"].ToString());
                    //e.Attr.Color = Microsoft.Msagl.Drawing.Color.Yellow;
                    e.LabelText = DataReader["rate"].ToString();
                }
            }
            gViewer.Graph = g;
        }
Example #15
0
 public Form1()
 {
     InitializeComponent();
     GViewer gViewer = new GViewer() { Dock = DockStyle.Fill };
     SuspendLayout();
     Controls.Add(gViewer);
     ResumeLayout();
     Graph graph = new Graph();
     var sugiyamaSettings = (SugiyamaLayoutSettings)graph.LayoutAlgorithmSettings;
     sugiyamaSettings.NodeSeparation *= 2;
     graph.AddEdge("A", "B");
     graph.AddEdge("A", "C");
     graph.AddEdge("A", "D");
     graph.LayerConstraints.PinNodesToSameLayer(new[] { graph.FindNode("A"), graph.FindNode("B"), graph.FindNode("C") });
     gViewer.Graph = graph;
 }
 private void Form1_Load(object sender, EventArgs e)
 {
     //create a viewer object
     Microsoft.Msagl.GraphViewerGdi.GViewer viewer = new Microsoft.Msagl.GraphViewerGdi.GViewer();
     //create a graph object
     Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph("graph");
     //create the graph content
     //var allServices = ServiceController.GetServices().Where(ser => Services.Contains(ser.ServiceName));
     foreach (ServiceController serviceController in ServiceController.GetServices())
     {
         var service = $"{serviceController.DisplayName} ({serviceController.ServiceName})";
         graph.AddNode(service);
         foreach (var dependentService in serviceController.DependentServices)
         {
             string dependent = $"{dependentService.DisplayName} ({dependentService.ServiceName})";
             graph.AddNode(dependent);
             graph.AddEdge(dependent, service);
         }
     }
     //bind the graph to the viewer
     graph.Attr.LayerDirection         = LayerDirection.None;
     graph.Attr.OptimizeLabelPositions = true;
     graph.CreateLayoutSettings();
     graph.LayoutAlgorithmSettings = new MdsLayoutSettings();
     viewer.Graph = graph;
     SuspendLayout();
     viewer.Dock = System.Windows.Forms.DockStyle.Fill;
     Controls.Add(viewer);
     ResumeLayout();
 }
Example #17
0
        public Microsoft.Msagl.Drawing.Graph GetGraph()
        {
            Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph("graph");

            foreach (Edge edge in edges)
            {
                graph.AddEdge(edge.source.ToString(), edge.target.ToString());
            }

            foreach (Vertex vertex in vertexes)
            {
                Node n = graph.FindNode($"{vertex.Name}");

                if (n != null)
                {
                    n.Attr.FillColor = vertex.color;


                    if (vertex.IsCorrect == false)
                    {
                        n.Attr.LineWidth = 3;
                        n.Attr.Color     = Color.Red;
                    }


                    n.Attr.Shape = Shape.Circle;
                }
            }

            return(graph);
        }
Example #18
0
 public void AddEdge()
 {
     foreach (EdgeHelper helper in edges)
     {
         graph.AddEdge(helper.One.ToString(), helper.Two.ToString());
     }
 }
Example #19
0
    public Microsoft.Msagl.GraphViewerGdi.GViewer BuildGraph(List <PrimaryGraph.Verticle> new_graph, string verticle)
    {
        //create a viewer object
        Microsoft.Msagl.GraphViewerGdi.GViewer viewer = new Microsoft.Msagl.GraphViewerGdi.GViewer();
        //create a graph object
        Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph("graph");
        //create the graph content
        for (int i = 0; i < new_graph.Count; i++)
        {
            for (int j = 0; j < new_graph[i].connections.Count; j++)
            {
                string verticle_out = new_graph[i].verticle_id;
                string verticle_in  = new_graph[i].connections[j].connectedTo;
                if (verticle_out == verticle || verticle_in == verticle)
                {
                    graph.AddEdge(verticle_out, new_graph[i].connections[j].strength.ToString(), verticle_in);
                }
            }
        }

        //graph.FindNode(verticle).Attr.FillColor = Microsoft.Msagl.Drawing.Color.Magenta;
        viewer.Graph  = graph;
        viewer.Height = 300;
        viewer.Width  = 930;

        return(viewer);
    }
Example #20
0
        private void btnRender_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(SymFile) || string.IsNullOrWhiteSpace(TraceFile))
            {
                return;
            }

            string source, target;

            graphViewer = new GraphViewer();
            graphViewer.LayoutEditingEnabled = false;
            graphViewer.BindToPanel(gvPanel);
            Drawing.Edge edg              = null;
            var          dgraph           = new Drawing.Graph();
            var          sugiyamaSettings = (SugiyamaLayoutSettings)dgraph.LayoutAlgorithmSettings;

            sugiyamaSettings.NodeSeparation *= 2;
            sugiyamaSettings.EdgeRoutingSettings.EdgeRoutingMode = EdgeRoutingMode.Rectilinear;

            var tot = new totts(SymFile, TraceFile);

            var blocks = tot.GetBlocks();

            foreach (var block in blocks)
            {
                if (block == null)
                {
                    break;
                }
                source = block.StepEvent.FROM_RIP.ToString("X");
                target = block.StepEvent.RIP.ToString("X");

                //var edge = new Drawing.Edge(source, "", target);
                edg = dgraph.AddEdge(source, target);
            }
            foreach (var block in blocks)
            {
                var blockLabel = new StringBuilder();
                foreach (var line in block.Lines.Values)
                {
                    blockLabel.Append($"{line.Address:X} \t + {line.NasmDisLine}");
                }

                var node = dgraph.FindNode(block.StepEvent.FROM_RIP.ToString("X"));
                if (node == null)
                {
                    continue;
                }

                node.LabelText       = blockLabel.ToString();
                node.Label.FontSize  = 10;
                node.Label.FontName  = "New Courier";
                node.Label.FontColor = Drawing.Color.Blue;
            }
            dgraph.Attr.LayerDirection         = Drawing.LayerDirection.TB;
            dgraph.Attr.OptimizeLabelPositions = false;
            graphViewer.Graph = dgraph;
        }
Example #21
0
        public static Edge CreateEdge(string from, string to, DiagramLine lineBetween)
        {
            Edge edge = _graph.AddEdge(from, to);

            edge.Attr.Color             = _colorAdapter.Adapt(lineBetween.DrawColor);
            edge.Attr.LineWidth         = lineBetween.Width;
            edge.Attr.ArrowheadAtSource = _arrowAdapter.Adapt(lineBetween.Arrow);
            return(edge);
        }
Example #22
0
        private void button2_Click(object sender, EventArgs e)
        {
            //upload button
            if (!(textBox1.Text.Equals("")))
            {
                //for (int i = 0; i < textData.getTotalPeople(); i++) graph.RemoveNode(graph.FindNode(textData.getPerson(i)));
                //g.Clear();
                textData    = new TextHandler();
                prevAccount = "";
                prevExplore = "";
                comboBox1.Items.Clear();
                comboBox2.Items.Clear();
                textData.Load(textBox1.Text);
                graph = new Microsoft.Msagl.Drawing.Graph("graph");
                g     = new GraphKita(textData);

                for (int i = 0; i < textData.getTotalConnection(); i++)
                {
                    g.NewEdge(textData.getFriendConnection(i)[0], textData.getFriendConnection(i)[1]);
                    var edge = graph.AddEdge(textData.getFriendConnection(i)[0], textData.getFriendConnection(i)[1]);
                    edge.Attr.ArrowheadAtSource = Microsoft.Msagl.Drawing.ArrowStyle.None;
                    edge.Attr.ArrowheadAtTarget = Microsoft.Msagl.Drawing.ArrowStyle.None;
                }
                for (int i = 0; i < textData.getTotalPeople(); i++)
                {
                    comboBox1.Items.Add(textData.getPerson(i));
                    comboBox2.Items.Add(textData.getPerson(i));
                }


                if ((textData.getTotalPeople() == 1))
                {
                    comboBox1.SelectedItem = (textData.getPerson(0));
                    comboBox2.SelectedItem = (textData.getPerson(0));
                    button3.Enabled        = true;
                }
                else if ((textData.getTotalPeople() > 1))
                {
                    comboBox1.SelectedItem = (textData.getPerson(0));
                    comboBox2.SelectedItem = (textData.getPerson(1));

                    comboBox1.Items.Remove(comboBox2.SelectedItem.ToString());
                    comboBox2.Items.Remove(comboBox1.SelectedItem.ToString());
                    comboBox1.Enabled = true;
                    comboBox2.Enabled = true;
                    button3.Enabled   = true;
                }
                printGraph();
                instantSearch();
            }
            else
            {
                Console.WriteLine("Path file tidak valid");
            }
        }
Example #23
0
 public static Microsoft.Msagl.Drawing.Graph ToMsaglGraph(this Graph g) {
     var msaglGraph = new Microsoft.Msagl.Drawing.Graph();
     for (var v = 0; v < g.V; v++) {
         foreach (var w in g.AdjacentVertices(v)) {
             var e = msaglGraph.AddEdge(v.ToString(), w.ToString());
             e.SourceNode.Attr.Shape = Shape.Circle;
             e.TargetNode.Attr.Shape = Shape.Circle;
         }
     }
     return msaglGraph;
 }
Example #24
0
        private void VisualizeNodes(IEnumerable <IWeightTensor> sourceNodes, IWeightTensor targetNode)
        {
            if (!m_visNeuralNetwork || m_deviceId != 0)
            {
                return;
            }

            // Create node for target tensor
            int index = targetNode.Name.LastIndexOf('.');

            Microsoft.Msagl.Drawing.Node tgtNode = m_opsViz.AddNode(targetNode.Name);
            tgtNode.LabelText = targetNode.Name.Substring(index + 1);

            if (targetNode.IsTrainable)
            {
                tgtNode.Attr.FillColor = Microsoft.Msagl.Drawing.Color.LightSteelBlue;
            }

            if (m_subGraph != null)
            {
                // Current compute graph is a sub-graph
                m_subGraph.AddNode(tgtNode);
            }

            // Create edges for each source node and target node
            foreach (IWeightTensor sourceNode in sourceNodes)
            {
                if (!string.IsNullOrEmpty(sourceNode.Name) && !string.IsNullOrEmpty(targetNode.Name))
                {
                    string key = $"{sourceNode.Name}->{targetNode.Name}";
                    if (m_setEdges.Contains(key))
                    {
                        continue;
                    }

                    int srcIndex = sourceNode.Name.LastIndexOf('.');
                    Microsoft.Msagl.Drawing.Node srcNode = m_opsViz.AddNode(sourceNode.Name);
                    srcNode.LabelText = sourceNode.Name.Substring(srcIndex + 1);
                    if (sourceNode.IsTrainable)
                    {
                        srcNode.Attr.FillColor = Microsoft.Msagl.Drawing.Color.LightSteelBlue;

                        if (m_subGraph != null)
                        {
                            m_subGraph.AddNode(srcNode);
                        }
                    }

                    Edge edge = m_opsViz.AddEdge(sourceNode.Name, targetNode.Name);

                    m_setEdges.Add(key);
                }
            }
        }
        private void LoadData()
        {
            Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph("graph");
            //create the graph content

            foreach (string[] line in InputData)
            {
                graph.AddEdge(line[0], line[1]).Attr.ArrowheadAtTarget = Microsoft.Msagl.Drawing.ArrowStyle.None;
            }

            gViewer1.Graph = graph;
        }
        static void ReadEdge(Graph graph, StreamReader f) {
            f.ReadLine();
            var s = f.ReadLine();
            s = s.Trim(' ', '\t', '"');
            var source = s.Split(' ')[1];
            s = f.ReadLine();

            s = s.Trim(' ', '\t', '"');
            var target = s.Split(' ')[1];
            graph.AddEdge(source, target);
            f.ReadLine();
        }
Example #27
0
        private void BuildMSGraph()
        {
            _msGraph = new Microsoft.Msagl.Drawing.Graph($"route_{RouteId}")
            {
                Attr = { LayerDirection = LayerDirection.LR }
            };

            foreach (var e in _edges)
            {
                var edge = _msGraph.AddEdge(e.Entry.Marker, e.SectionMarker, e.Exit.Marker);
                edge.Attr.Id = e.SequenceNumber.ToString();
            }
        }
Example #28
0
        public void drawGraph()
        {
            //create a form
            System.Windows.Forms.Form form = new System.Windows.Forms.Form();
            Microsoft.Msagl.GraphViewerGdi.GViewer viewer = new Microsoft.Msagl.GraphViewerGdi.GViewer();
            Microsoft.Msagl.Drawing.Graph          graph  = new Microsoft.Msagl.Drawing.Graph("graph");

            for (int i = 0; i < nodes.Count; i++)
            {
                Console.WriteLine("i:" + i);
                Console.WriteLine("children count: " + nodes[i].children.Count);
                for (int j = 0; j < nodes[i].children.Count; j++)
                {
                    Console.WriteLine("j:" + j);
                    Console.WriteLine("Parent node: " + nodes[i].getNodeName());
                    Console.WriteLine("node name: " + nodes[i].children[j].getNodeName());
                    int flow    = nodes[i].edges[j][0];
                    var newEdge = graph.AddEdge(nodes[i].getNodeName(), nodes[i].children[j].getNodeName());
                    Microsoft.Msagl.Drawing.Node childNode = graph.FindNode(nodes[i].getNodeName());
                    string cap = nodes[i].edges[j][0].ToString() + "/" + nodes[i].edges[j][1].ToString();
                    newEdge.LabelText        = cap;
                    childNode.Attr.Shape     = Microsoft.Msagl.Drawing.Shape.Circle;
                    childNode.Attr.FillColor = Microsoft.Msagl.Drawing.Color.White;
                    if (flow > 0)
                    {
                        string tempStringg = nodes[i].getNodeName() + nodes[i].children[j].getNodeName();
                        if (nameofnodes.Contains(tempStringg))
                        {
                            newEdge.Attr.Color = Microsoft.Msagl.Drawing.Color.Red;
                        }
                        else
                        {
                            newEdge.Attr.Color = Microsoft.Msagl.Drawing.Color.Orange;
                        }
                    }
                    else
                    {
                        newEdge.Attr.Color = Microsoft.Msagl.Drawing.Color.Black;
                    }
                }
            }

            viewer.Graph = graph;
            form.SuspendLayout();
            viewer.CurrentLayoutMethod = LayoutMethod.MDS;
            form.Controls.Add(viewer);
            form.ResumeLayout();
            //show the form
            form.ShowDialog();
        }
Example #29
0
 // Menghubungkan vertek asal dengan Tujuan
 public void add_Edge(City Asal, City Tujuan, float prob)
 {
     if (!Vertex.ContainsKey(Asal))
     {
         add_vertex(Asal);
     }
     if (!Vertex.ContainsKey(Tujuan))
     {
         add_vertex(Tujuan);
     }
     guiGraph.AddEdge(Asal.get_nama(), Tujuan.get_nama());
     Vertex[Asal].Add(Tujuan);
     probability.Add(new KeyValuePair <City, City>(Asal, Tujuan), prob);
 }
Example #30
0
 // Menginisialisasi gambar graph
 private void _initializeGraph()
 {
     graph = new Graph();
     for (int i = 1; i <= rootedTree.NNode; ++i)
     {
         foreach (int j in rootedTree.ChildNode[i])
         {
             graph.AddEdge(i.ToString(), j.ToString());
         }
     }
     viewer.Graph = graph;
     graphPanel.SuspendLayout();
     viewer.Dock = System.Windows.Forms.DockStyle.Fill;
     graphPanel.ResumeLayout();
 }
        public Microsoft.Msagl.Drawing.Graph buildMSAGLGraph(int countEdges, List <string> rawEdges)
        {
            Microsoft.Msagl.Drawing.Graph graphDFS = new Microsoft.Msagl.Drawing.Graph();
            this.countEdges = countEdges;

            for (int i = 0; i < rawEdges.Count; i++)
            {
                string rawNode1 = rawEdges[i].Split(" ")[0];
                string rawnode2 = rawEdges[i].Split(" ")[1];

                var Edge = graphDFS.AddEdge(rawNode1, rawnode2);
                Edge.Attr.ArrowheadAtTarget = ArrowStyle.None;
                Edge.Attr.ArrowheadAtSource = ArrowStyle.None;
            }

            return(graphDFS);
        }
Example #32
0
 // ----ΠšΠΎΠ½ΡΡ‚Ρ€ΡƒΠΊΡ‚ΠΎΡ€
 /// <summary>
 /// ΠšΠΎΠ½ΡΡ‚Ρ€ΡƒΠΊΡ‚ΠΎΡ€, ΡΠΎΠ·Π΄Π°ΡŽΡ‰ΠΈΠΉ класс, ΡΠ²ΡΠ·Ρ‹Π²Π°ΡŽΡ‰ΠΈΠΉ SGVL Π³Ρ€Π°Ρ„ с вновь созданным
 /// ΡΠΎΠΎΡ‚Π²Π΅Ρ‚ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΌ Π³Ρ€Π°Ρ„ΠΎΠΌ MSAGL
 /// </summary>
 /// <param name="graph">SGVL Π³Ρ€Π°Ρ„, для ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠ³ΠΎ Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌ ΡΠΎΠΎΡ‚Π²Π΅Ρ‚ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΉ MSAGL Π³Ρ€Π°Ρ„</param>
 public MsaglGraphWrapper(SgvlGraphs.Graph graph)
 {
     SgvlGraph           = graph;
     MsaglGraph          = new MsaglGraphs.Graph("graph");
     MsaglGraph.Directed = graph.IsDirected;
     // Π‘ΠΎΠ·Π΄Π°Ρ‘ΠΌ Π²Π΅Ρ€ΡˆΠΈΠ½Ρ‹ Π³Ρ€Π°Ρ„Π° Msagl
     foreach (var vertex in graph.Vertices)
     {
         var msaglNode = MsaglGraph.AddNode(vertex.Number.ToString());
         // ΠŸΡ€ΠΈΠ²ΠΎΠ΄ΠΈΠΌ Π² соотвСтствиС значСния ΠΈΡ… Π°Ρ‚Ρ€ΠΈΠ±ΡƒΡ‚ΠΎΠ²
         UpdateMsaglNode(msaglNode, vertex);
         // Π—Π°Π΄Π°Ρ‘ΠΌ Ρ„ΠΎΡ€ΠΌΡƒ Π² Π²ΠΈΠ΄Π΅ ΠΊΡ€ΡƒΠ³Π°
         msaglNode.Attr.Shape = MsaglGraphs.Shape.Circle;
         // Π—Π°Π΄Π°Ρ‘ΠΌ Ρ€Π°Π·ΠΌΠ΅Ρ€ ΡˆΡ€ΠΈΡ„Ρ‚Π°
         msaglNode.Label.FontSize = fontSize;
         // ΠŸΠΎΠ΄ΠΏΠΈΡΡ‹Π²Π°Π΅ΠΌΡΡ Π½Π° события измСнСния Π°Ρ‚Ρ€ΠΈΠ±ΡƒΡ‚ΠΎΠ² Π²Π΅Ρ€ΡˆΠΈΠ½Ρ‹
         vertex.LabelChanged       += OnVertexLabelChanged;
         vertex.BorderColorChanged += OnVertexBorderColorChanged;
         vertex.FillColorChanged   += OnVertexFillColorChanged;
         vertex.BoldChanged        += OnVertexBoldChanged;
         // На ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΠ΅ ΠΊΠΎΠΎΡ€Π΄ΠΈΠ½Π°Ρ‚ ΠΌΡ‹ Π½Π΅ подписываСмся - это ΠΏΠΎΠΊΠ° Π½Π΅ Ρ€Π°Π±ΠΎΡ‚Π°Π΅Ρ‚
     }
     // Π‘ΠΎΠ·Π΄Π°Ρ‘ΠΌ Ρ€Ρ‘Π±Ρ€Π° Π³Ρ€Π°Ρ„Π° Msagl
     foreach (var edge in graph.Edges)
     {
         var msaglEdge = MsaglGraph.AddEdge(edge.SourceVertex.Number.ToString(), edge.TargetVertex.Number.ToString());
         // Π—Π°Π΄Π°Ρ‘ΠΌ Ρ€Π΅Π±Ρ€Ρƒ id для быстрого поиска Π² Π²ΠΈΠ΄Π΅ строки
         msaglEdge.Attr.Id = $"{edge.SourceVertex.Number}-{edge.TargetVertex.Number}";
         // Если Π³Ρ€Π°Ρ„ Π½Π΅ΠΎΡ€ΠΈΠ΅Π½Ρ‚ΠΈΡ€ΠΎΠ²Π°Π½Π½Ρ‹ΠΉ, ΡƒΠ±ΠΈΡ€Π°Π΅ΠΌ с ΠΊΠΎΠ½Ρ†Π° стрСлку
         if (!graph.IsDirected)
         {
             msaglEdge.Attr.ArrowheadAtTarget = MsaglGraphs.ArrowStyle.None;
         }
         // ΠŸΡ€ΠΈΠ²ΠΎΠ΄ΠΈΠΌ Π² соотвСтствиС значСния ΠΈΡ… Π°Ρ‚Ρ€ΠΈΠ±ΡƒΡ‚ΠΎΠ²
         UpdateMsaglEdge(msaglEdge, edge);
         // Π—Π°Π΄Π°Ρ‘ΠΌ Ρ€Π°Π·ΠΌΠ΅Ρ€ ΡˆΡ€ΠΈΡ„Ρ‚Π°
         msaglEdge.Label.FontSize = fontSize;
         // ΠŸΠΎΠ΄ΠΏΠΈΡΡ‹Π²Π°Π΅ΠΌΡΡ Π½Π° события измСнСния Π°Ρ‚Ρ€ΠΈΠ±ΡƒΡ‚ΠΎΠ² Ρ€Π΅Π±Ρ€Π°
         edge.LabelChanged += OnEdgeLabelChanged;
         edge.ColorChanged += OnEdgeColorChanged;
         edge.BoldChanged  += OnEdgeBoldChanged;
     }
 }
Example #33
0
        private void PatchGraph(int id)
        {
            Graph g = new Graph();

            using (SQLiteCommand command = new SQLiteCommand(ConnectionManager.connection))
            {
                command.CommandText = @"select name from modules";

                SQLiteDataReader DataReader = command.ExecuteReader();
                while (DataReader.Read())
                    g.AddNode(DataReader["name"].ToString());
            }

            using (SQLiteCommand command = new SQLiteCommand(ConnectionManager.connection))
            {
                command.CommandText = @"select * from patchview where patch_id=@patch_id";
                command.Parameters.Add(new SQLiteParameter("@patch_id", id));
                SQLiteDataReader DataReader = command.ExecuteReader();
                while (DataReader.Read())
                {
                    Microsoft.Msagl.Drawing.Edge e = g.AddEdge(DataReader["used"].ToString(), "", DataReader["uses"].ToString());
                    e.Attr.LineWidth = int.Parse(DataReader["count"].ToString());
                    e.Attr.Color = Microsoft.Msagl.Drawing.Color.Red;
                    e.LabelText = DataReader["rate"].ToString();
                }
            }
            using (SQLiteCommand command = new SQLiteCommand(ConnectionManager.connection))
            {
                command.CommandText = @"select * from patchview2 where patch_id=@patch_id";
                command.Parameters.Add(new SQLiteParameter("@patch_id", id));
                SQLiteDataReader DataReader = command.ExecuteReader();
                while (DataReader.Read())
                {
                    Microsoft.Msagl.Drawing.Edge e = g.AddEdge(DataReader["used"].ToString(), "", DataReader["uses"].ToString());
                    e.Attr.LineWidth = int.Parse(DataReader["count"].ToString());
                    e.Attr.Color = Microsoft.Msagl.Drawing.Color.Yellow;
                    e.LabelText = (int.Parse(DataReader["rate"].ToString())/10).ToString();
                }
            }
            gViewer.Graph = g;
        }
Example #34
0
        public Microsoft.Msagl.Drawing.Graph ConstGraph()
        {
            var g = new Microsoft.Msagl.Drawing.Graph();

            for (int i = 0; i < Graph.graphEl.Length; i++)
            {
                g.AddNode(Graph.graphEl[i]).Attr.FillColor = Color.LightBlue;
            }
            bool[,] AdjMx = Graph.graph;
            for (int i = 0; i < Graph.graphEl.Length; i++)
            {
                for (int j = 0; j < Graph.graphEl.Length; j++)
                {
                    if (AdjMx[i, j])
                    {
                        g.AddEdge(Graph.graphEl[i], Graph.graphEl[j]);
                    }
                }
            }
            return(g);
        }
        private void DrawAutoma(AutomaFuzzy.Automa<Symbol> automma)
        {
            Graph graph = new Graph("Automa");
            //graph.GraphAttr.Backgroundcolor = Microsoft.Glee.Drawing.Color.Black;
            for (int i = 0; i < automma.States.Count; i++)
            {
                string str = automma.States[i].ToString();

                Node no = graph.AddNode(automma.States[i].Name);
                no.Attr.Shape = Shape.Box;
                no.LabelText = str;
            }

            foreach (var transition in automma.Transitions)
            {
                string symbol = ((CompilerWithFuzzy.AutomaFuzzy.Rules.SimpleIncludeRule<Symbol>)transition.Rule).Symbol.ToString();
                string label =
                    ((CompilerWithFuzzy.AutomaFuzzy.Rules.SimpleIncludeRule<Symbol>)transition.Rule).Symbol.ToString() +
                            " - " + transition.Rule.Pertinence.ToString();
                label = symbol;

                Edge arco = graph.AddEdge(transition.From.Name, label
                         , transition.To.Name);
                System.Drawing.Color c = Utils.GetColor(transition.Rule.Pertinence);
                var color = new Microsoft.Msagl.Drawing.Color((byte)c.R, (byte)c.G, (byte)c.B);
                arco.Attr.Color = color;
                //arco.Attr.Fontcolor = color;
                arco.Attr.AddStyle(Style.Bold);
                arco.Attr.LineWidth = 5;
            }

            GViewer viewer = new GViewer();
            viewer.NavigationVisible = false;
            viewer.OutsideAreaBrush = Brushes.White;
            viewer.ToolBarIsVisible = false;
            viewer.Graph = graph;
            viewer.Dock = System.Windows.Forms.DockStyle.Fill;
            pnlAutoma.Controls.Clear();
            pnlAutoma.Controls.Add(viewer);
        }
Example #36
0
        // Returns the last used id
        private int PopulateGraph(Graph graph, SyntaxWrapper wrapper, int id, string parentId)
        {
            // Check if filtering
            if ((wrapper.GetSyntaxObject() is SyntaxToken && _syntaxTokenCheckBox != null && !_syntaxTokenCheckBox.Checked) ||
                (wrapper.GetSyntaxObject() is SyntaxTrivia && _syntaxTriviaCheckBox != null && !_syntaxTriviaCheckBox.Checked))
            {
                return(id);
            }

            // Create the node
            string nodeId = id.ToString();
            Node   node   = new Node(nodeId);
            Color  color  = wrapper.GetColor();

            node.Attr.FillColor   = new Microsoft.Msagl.Drawing.Color(color.R, color.G, color.B);
            node.Attr.LabelMargin = 10;
            node.LabelText        = wrapper.GetGraphText();
            node.Label.FontColor  = Microsoft.Msagl.Drawing.Color.White;
            node.Label.FontStyle  = (Microsoft.Msagl.Drawing.FontStyle)(int) wrapper.GetGraphFontStyle();
            graph.AddNode(node);

            // Add the edge
            if (parentId != null)
            {
                graph.AddEdge(parentId, nodeId);
            }

            // Descend
            IEnumerable children = wrapper.GetChildren();

            if (children != null)
            {
                // Note that we have to iterate children in reverse order to get them to layout in the correct order
                foreach (SyntaxWrapper childWrapper in children.Cast <SyntaxWrapper>().Reverse())
                {
                    id = PopulateGraph(graph, childWrapper, id + 1, nodeId);
                }
            }
            return(id);
        }
Example #37
0
        private void Load_Graph_Click(object sender, RoutedEventArgs e)
        // Membuat graf satu arah dari file peta yang sudah diload sebelumnya
        {
            try
            {
                map = new Graf(dirGraph);
                Enter_Query.IsEnabled = true;
                Open_Query.IsEnabled  = true;
                Next.IsEnabled        = false;
                this.gViewer.Graph    = null;
                graph = new Msagl.Graph("graph");

                for (int i = map.getHouses() - 1; i > 0; i--)
                {
                    for (int j = map.getPath(i).Count() - 1; j >= 0; j--)
                    {
                        string str1 = i.ToString();
                        string str2 = map.getPath(i)[j].ToString();

                        graph.AddEdge(str1, str2).Attr.ArrowheadAtTarget = Msagl.ArrowStyle.None;

                        Microsoft.Msagl.Drawing.Node from = graph.FindNode(str1);
                        Microsoft.Msagl.Drawing.Node to   = graph.FindNode(str2);

                        from.Attr.FillColor = Microsoft.Msagl.Drawing.Color.White;
                        from.Attr.Shape     = Microsoft.Msagl.Drawing.Shape.Circle;
                        to.Attr.FillColor   = Microsoft.Msagl.Drawing.Color.White;
                        to.Attr.Shape       = Microsoft.Msagl.Drawing.Shape.Circle;
                    }
                }

                this.gViewer.Graph = graph;
            }
            catch
            {
                MessageBox.Show("      Error Code 0x05021999\n             File Input Error", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private void Draw(Automa<char> automa, int indexTable = -1)
        {
            Graph graphAutoma = new Graph("Automa");

            for (int i = 0; i < automa.States.Count; i++)
            {
                State<char> state = automa.States[i];
                Node no = graphAutoma.AddNode(state.Name);
                no.Attr.Shape = Shape.Circle;

                if (state.PertinenceFinal > 0)
                {
                    no.Attr.Shape = Shape.DoubleCircle;
                }
                if (indexTable > -1)
                {
                    System.Drawing.Color c = Utils.GetColor(regexFuzzy.TableAutomaProcessing[indexTable][i]);
                    no.Attr.FillColor = new Microsoft.Msagl.Drawing.Color((byte)c.R, (byte)c.G, (byte)c.B);
                }
                else if (state.PertinenceInitial > 0)
                {
                    no.Attr.FillColor = Microsoft.Msagl.Drawing.Color.LightGray;
                }
            }
            foreach (var transition in automa.Transitions)
            {
                Edge arco = graphAutoma.AddEdge(transition.From.Name, transition.To.Name);
                arco.LabelText = transition.ToString();
            }
            GViewer viewer = new GViewer();
            viewer.NavigationVisible = false;
            viewer.OutsideAreaBrush = Brushes.White;
            viewer.ToolBarIsVisible = false;
            viewer.Graph = graphAutoma;
            viewer.Dock = System.Windows.Forms.DockStyle.Fill;
            pnlAutoma.Controls.Clear();
            pnlAutoma.Controls.Add(viewer);
        }
        static void BindEdges(Graph graph, GeometryGraph geomGraph, Dictionary<GeomNode, string> nodeIds) {
            foreach (var edge in geomGraph.Edges) {
                if (IsUnderCollapsedCluster(edge))
                    continue;

                var e = graph.AddEdge(nodeIds[edge.Source], nodeIds[edge.Target]);
                if (edge.EdgeGeometry != null && edge.EdgeGeometry.SourceArrowhead != null)
                    e.Attr.ArrowheadAtSource = ArrowStyle.Normal;

                e.Attr.ArrowheadAtTarget = edge.EdgeGeometry != null && edge.EdgeGeometry.TargetArrowhead != null
                    ? ArrowStyle.Normal
                    : ArrowStyle.None;

                e.GeometryEdge = edge;

                e.Attr.LineWidth = edge.LineWidth;

                if (edge.Label != null && edge.Label.Width != 0) {
                    e.LabelText = "label";
                    e.Label.GeometryLabel = edge.Label;
                    e.Label.Owner = e;
                }
            }
        }
Example #40
0
    public Microsoft.Msagl.GraphViewerGdi.GViewer BuildGraphBig(List <PrimaryGraph.Verticle> new_graph)
    {
        //create a viewer object
        Microsoft.Msagl.GraphViewerGdi.GViewer viewer = new Microsoft.Msagl.GraphViewerGdi.GViewer();
        //create a graph object
        Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph("graph");
        //create the graph content
        for (int i = 0; i < new_graph.Count; i++)
        {
            for (int j = 0; j < new_graph[i].connections.Count; j++)
            {
                string verticle_out = new_graph[i].verticle_id;
                string verticle_in  = new_graph[i].connections[j].connectedTo;
                {
                    graph.AddEdge(verticle_out, new_graph[i].connections[j].strength.ToString(), verticle_in);
                }
            }
        }

        viewer.Graph = graph;
        viewer.ZoomF = 4;

        return(viewer);
    }
Example #41
0
        public Graph CreateGraph(List <Edge> edges)
        {
            Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph();

            foreach (var node in Nodes)
            {
                graph.AddNode(node.ID.ToString()).Attr.FillColor = Microsoft.Msagl.Drawing.Color.Yellow;
            }

            foreach (var edge in Edges)
            {
                var ed = graph.AddEdge(edge.Begin.ID.ToString(),
                                       edge.Cost.ToString("#.00"),
                                       edge.End.ID.ToString());

                if (edges == null)
                {
                    ed.Attr.Color             = Microsoft.Msagl.Drawing.Color.Black;
                    ed.Attr.ArrowheadAtTarget = Microsoft.Msagl.Drawing.ArrowStyle.None;
                }
                else
                {
                    if (edges.Exists(x => x.Color == edge.Color))
                    {
                        ed.Attr.Color = Microsoft.Msagl.Drawing.Color.Red;
                    }
                    else
                    {
                        ed.Attr.Color = Microsoft.Msagl.Drawing.Color.Black;
                    }
                    ed.Attr.ArrowheadAtTarget = Microsoft.Msagl.Drawing.ArrowStyle.None;
                }
            }

            return(graph);
        }
Example #42
0
 private void GenerateGraph(GraphStructure stGraph)
 {
     Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph(stGraph.Header.GraphName);
     if (stGraph.Records.Count > 1)
     {
         for (int i = 0; i < stGraph.Records.Count; i++)
         {
             for (int j = 0; j < stGraph.Records.Count; j++)
             {
                 string source = stGraph.Records.ElementAt(i).VertexName;
                 string target = stGraph.Header.Vertices.ElementAt(j);
                 string label  = stGraph.Records.ElementAt(i).Edges.ElementAt(j);
                 if (i != j && !(label.ToLower().Equals("inf"))) //if it's not pointing to itself or Inf(doesn't has an edge to target vertex)
                 {
                     graph.AddEdge(source: source,
                                   edgeLabel: label,
                                   target: target); //add vertices and make an edge between them
                     RequireAttributes(graph.FindNode(source) as Node);
                 }
             }
         }
     }
     this.gViewer.Graph = graph;
 }
Example #43
0
        private void DisplayTree()
        {
            Msagl.Graph graph = new Msagl.Graph();
             var iter = m_Stree.Edges.GetEnumerator();
             while (iter.MoveNext())
             {
            Edge edge = iter.Current.Value;
            int startNameIdx = edge.startNode;
            if (startNameIdx >= 0)
            {
               int endNameIdx = edge.endNode;
               Msagl.Edge graphEdge = graph.AddEdge(startNameIdx.ToString(), endNameIdx.ToString());
               int len = (edge.indexOfLastCharacter - edge.indexOfFirstCharacter) + 1;
               List<int> substring;
               if (edge.indexOfFirstCharacter + len < m_Stree.theString.Count)
                  substring = m_Stree.theString.GetRange(edge.indexOfFirstCharacter, (edge.indexOfLastCharacter - edge.indexOfFirstCharacter)+1);
               else
                  substring = m_Stree.theString.GetRange(edge.indexOfFirstCharacter, (edge.indexOfLastCharacter - edge.indexOfFirstCharacter));
               graphEdge.LabelText = ListToString(substring);
            }
             }

             graph.Attr.BackgroundColor = new Msagl.Color(255, 60, 60, 60);
             ctrlGraph.Graph = graph;
        }
Example #44
0
        private void CreateGraph() {
            Graph graph = new Graph("graph");
            graph.Attr.BackgroundColor = Color.DodgerBlue;
            Edge edge = (Edge)graph.AddEdge("S24", "27");
            edge.LabelText = "Edge Label Test";

            graph.AddEdge("S24", "25");
            edge = graph.AddEdge("S1", "10") as Edge;

            edge.LabelText = "Init";
            edge.Attr.ArrowheadAtTarget = ArrowStyle.Tee;
            //  edge.Attr.Weight = 10;
            edge = graph.AddEdge("S1", "2") as Edge;
            // edge.Attr.Weight = 10;
            graph.AddEdge("S35", "36");
            graph.AddEdge("S35", "43");
            graph.AddEdge("S30", "31");
            graph.AddEdge("S30", "33");
            graph.AddEdge("9", "42");
            graph.AddEdge("9", "T1");
            graph.AddEdge("25", "T1");
            graph.AddEdge("25", "26");
            graph.AddEdge("27", "T24");
            graph.AddEdge("2", "3");
            graph.AddEdge("2", "16");
            graph.AddEdge("2", "17");
            graph.AddEdge("2", "T1");
            graph.AddEdge("2", "18");
            graph.AddEdge("10", "11");
            graph.AddEdge("10", "14");
            graph.AddEdge("10", "T1");
            graph.AddEdge("10", "13");
            graph.AddEdge("10", "12");
            graph.AddEdge("31", "T1");
            edge = (Edge)graph.AddEdge("31", "32");
            edge.Attr.ArrowheadAtTarget = ArrowStyle.Tee;
            edge.Attr.LineWidth = 10;
            edge.Attr.Weight = 10;
            edge.Attr.ArrowheadLength *= 2;
            edge = (Edge)graph.AddEdge("33", "T30");
            edge.Attr.LineWidth = 15;
            edge.Attr.AddStyle(Microsoft.Msagl.Drawing.Style.Dashed);
            graph.AddEdge("33", "34");
            graph.AddEdge("42", "4");
            graph.AddEdge("26", "4");
            graph.AddEdge("3", "4");
            graph.AddEdge("16", "15");
            graph.AddEdge("17", "19");
            graph.AddEdge("18", "29");
            graph.AddEdge("11", "4");
            graph.AddEdge("14", "15");
            graph.AddEdge("37", "39");
            graph.AddEdge("37", "41");
            graph.AddEdge("37", "38");
            graph.AddEdge("37", "40");
            graph.AddEdge("13", "19");
            graph.AddEdge("12", "29");
            graph.AddEdge("43", "38");
            graph.AddEdge("43", "40");
            graph.AddEdge("36", "19");
            graph.AddEdge("32", "23");
            graph.AddEdge("34", "29");
            graph.AddEdge("39", "15");
            graph.AddEdge("41", "29");
            graph.AddEdge("38", "4");
            graph.AddEdge("40", "19");
            graph.AddEdge("4", "5");
            graph.AddEdge("19", "21");
            graph.AddEdge("19", "20");
            graph.AddEdge("19", "28");
            graph.AddEdge("5", "6");
            graph.AddEdge("5", "T35");
            graph.AddEdge("5", "23");
            edge = graph.AddEdge("21", "22");
            edge.Attr.ArrowheadLength *= 3;
            graph.AddEdge("20", "15");
            graph.AddEdge("28", "29");
            graph.AddEdge("6", "7");
            graph.AddEdge("15", "T1");
            graph.AddEdge("22", "23");
            graph.AddEdge("22", "T35");
            graph.AddEdge("29", "T30");
            graph.AddEdge("7", "T8");
            graph.AddEdge("23", "T24");
            graph.AddEdge("23", "T1");


            Node node = graph.FindNode("S1") as Node;
            node.LabelText = "Label Test";
            CreateSourceNode(graph.FindNode("S1") as Node);
            CreateSourceNode(graph.FindNode("S24") as Node);
            CreateSourceNode(graph.FindNode("S35") as Node);


            CreateTargetNode(graph.FindNode("T24") as Node);
            CreateTargetNode(graph.FindNode("T1") as Node);
            CreateTargetNode(graph.FindNode("T30") as Node);
            CreateTargetNode(graph.FindNode("T8") as Node);


            //layout the graph and draw it
            //graph.AddEdge("f", "a");
            //graph.AddEdge("a", "l").LabelText = "from node a\n to node l\n with sincerity";
            //graph.AddEdge("a", "b").LabelText="a=>b";
            //graph.AddEdge("b", "a"); //changing the order of a and b causes a crash
            //graph.AddEdge("a", "l");
            //graph.AddEdge("a", "b").LabelText = "a=>b label\n number 2";
            //graph.AddEdge("a", "c");
            //graph.AddEdge("b", "d");
            //graph.AddEdge("d", "c");
            //graph.AddEdge("c", "b");
            //graph.AddEdge("b", "c");
            //graph.AddEdge("a", "e");
            //graph.AddEdge("d", "k").LabelText="dk label";

            //Microsoft.Msagl.SugiyamaLayoutSettings settings = graph.LayoutAlgorithmSettings as Microsoft.Msagl.SugiyamaLayoutSettings;
            //settings.PinNodesToMaxLayer("2","S35");
            //settings.AddUpDownVerticalConstraint("39", "15");
            //settings.AddSameLayerNeighbors("S24", "2");
            //settings.AddUpDownVerticalConstraint("9", "3");
            //settings.AddUpDownVerticalConstraint("S1", "T8");



#if DEBUG
            Microsoft.Msagl.GraphViewerGdi.DisplayGeometryGraph.SetShowFunctions();
#endif


            //settings.AddUpDownVerticalConstraints("3", "28");

            //settings.PinNodesToMinLayer("T1", "T8", "T24");   
            //settings.PinNodesToSameLayer("12", "S30", "19");
            //settings.PinNodesToSameLayer("29", "31", "4");
            //settings.AddUpDownConstraint("29", "12");

            // Add vertical and horizontal constraints
            //settings.AddUpDownVerticalConstraint("37", "38");
            //settings.AddUpDownVerticalConstraint("38", "4");
            //settings.AddUpDownVerticalConstraint("4", "5");
            //settings.AddSameLayerNeighbors("2", "10");

            //(graph.LayoutAlgorithmSettings as Microsoft.Msagl.SugiyamaLayoutSettings).AddUpDownConstraint("19", "40");
            //(graph.LayoutAlgorithmSettings as Microsoft.Msagl.SugiyamaLayoutSettings).AddUpDownConstraint("17", "40");
            //(graph.LayoutAlgorithmSettings as Microsoft.Msagl.SugiyamaLayoutSettings).AddSameLayerNeighbors("43", "S24");

            //(graph.LayoutAlgorithmSettings as Microsoft.Msagl.SugiyamaLayoutSettings).AddUpDownConstraint("7", "T1");
            //(graph.LayoutAlgorithmSettings as Microsoft.Msagl.SugiyamaLayoutSettings).AddUpDownConstraint("7", "T245");
            //(graph.LayoutAlgorithmSettings as Microsoft.Msagl.SugiyamaLayoutSettings).AddUpDownConstraint("7", "T30");
            //(graph.LayoutAlgorithmSettings as Microsoft.Msagl.SugiyamaLayoutSettings).AddUpDownConstraint("5", "4");
            //(graph.LayoutAlgorithmSettings as Microsoft.Msagl.SugiyamaLayoutSettings).AddUpDownConstraint("4", "3");

            gViewer.Graph = graph;

            // Verify vertical and neighbour constraints
            var node2 = graph.FindNode("2");
            var node4 = graph.FindNode("4");
            var node5 = graph.FindNode("5");
            var node10 = graph.FindNode("10");
            var node37 = graph.FindNode("37");
            var node38 = graph.FindNode("38");
            bool fXalign_37_38 = (Math.Abs(node37.GeometryNode.Center.X - node38.GeometryNode.Center.X) < 0.0001)
                                && (node37.GeometryNode.Center.Y > node38.GeometryNode.Center.Y);
            bool fXalign_38_4 = (Math.Abs(node37.GeometryNode.Center.X - node38.GeometryNode.Center.X) < 0.0001)
                                && (node37.GeometryNode.Center.Y > node38.GeometryNode.Center.Y);
            bool fXalign_4_5 =  (Math.Abs(node37.GeometryNode.Center.X - node38.GeometryNode.Center.X) < 0.0001)
                                && (node37.GeometryNode.Center.Y > node38.GeometryNode.Center.Y);
            bool fXalign = true;
            if (!fXalign_37_38 || !fXalign_38_4 || !fXalign_4_5) {
                Console.WriteLine();
                Console.WriteLine("Xalign tests failed");
                Console.WriteLine();
                fXalign = false;
            }

            bool fYalign = (Math.Abs(node2.GeometryNode.Center.Y - node10.GeometryNode.Center.Y) < 0.0001)
                            && (node2.GeometryNode.Center.X < node10.GeometryNode.Center.Y);
            if (!fYalign) {
                Console.WriteLine();
                Console.WriteLine("Yalign tests failed");
                Console.WriteLine();
            }

            if (fXalign && fYalign) {
                Console.WriteLine();
                Console.WriteLine("Xalign and Yalign tests passed");
                Console.WriteLine();
            }

            this.propertyGrid1.SelectedObject = graph;
        }
        static Graph CreateGraphFromParsedStuff(Dictionary<string, Tuple<int, int, int, int>> labelsToGeom, List<Tuple<string, string>> edges) {
            var graph = new Graph();
            foreach (var label in labelsToGeom.Keys)
                graph.AddNode(label);
            foreach (var tuple in edges) {
                var e=graph.AddEdge(tuple.Item1, tuple.Item2);
                e.Attr.ArrowheadAtTarget = ArrowStyle.None;

            }

            graph.CreateGeometryGraph();
            foreach (var node in graph.Nodes) {
                var tuple = labelsToGeom[node.Id];
                int centerX = tuple.Item1;
                int centerY = tuple.Item2;
                int w=tuple.Item3;
                int h = tuple.Item4;

                node.GeometryNode.BoundaryCurve = new RoundedRect(
                    new Rectangle(centerX-(double)w/2, centerY-(double)h/2, new Microsoft.Msagl.Core.Geometry.Point(tuple.Item3, tuple.Item4)), 3, 3);
            }

            var router = new SplineRouter(graph.GeometryGraph, 1, 1, Math.PI / 6, null);
            router.Run();
            graph.GeometryGraph.UpdateBoundingBox();
            //LayoutAlgorithmSettings.ShowGraph(graph.GeometryGraph);

            return graph;
        }
        Graph GetGraph() {

            var graph = new Graph();
            foreach (var graphmlNodePair in _graphmlNodes) {
                Microsoft.Msagl.Drawing.Node dnode = graph.AddNode(graphmlNodePair.Key);
                dnode.UserData = graphmlNodePair;
                if (!string.IsNullOrEmpty(graphmlNodePair.Value.Fullname))
                    dnode.LabelText = graphmlNodePair.Value.Fullname;

            }
            foreach (var graphmlNode in _graphmlNodes.Values) {
                foreach (var edge in graphmlNode.outEdges) {
                    graph.AddEdge(graphmlNode.Id, edge.Target.Id).UserData = edge;
                }
            }
            return graph;
        }
Example #47
0
        private void InitGraph()
        {
            Graph drawingGraph = new Graph();

            drawingGraph.AddEdge(leavesId, creekId);
            drawingGraph.AddEdge(leavesId, treeId);
            drawingGraph.AddEdge(leavesId, wId);

            drawingGraph.AddEdge("uno", "otro");
            foreach (DrawingNode node in drawingGraph.Nodes)
            {
                if (!node.Id.Equals("uno"))
                {
                    node.Attr.Shape = Shape.DrawFromGeometry;
                    node.DrawNodeDelegate = new DelegateToOverrideNodeRendering(DrawNode);
                    node.NodeBoundaryDelegate = new DelegateToSetNodeBoundary(GetNodeBoundary);
                }
                else
                {
                    node.LabelText = "node with a diamond shape";
                    node.Attr.Shape = Shape.Diamond;
                }

            }

            double width = leaves.Width;
            double height = leaves.Height;

            drawingGraph.Attr.LayerSeparation = height / 2;
            drawingGraph.Attr.NodeSeparation = width / 2;
            double arrowHeadLenght = width / 10;
            foreach (Microsoft.Msagl.Drawing.Edge e in drawingGraph.Edges)
                e.Attr.ArrowheadLength = (float)arrowHeadLenght;
            drawingGraph.LayoutAlgorithmSettings = new SugiyamaLayoutSettings();
            viewer.Graph = drawingGraph;
        }
Example #48
0
        void CreateGraph()
        {
            var g = new Graph();

            // First DNA sequence
            g.AddEdge("prom1A", "rbs1A");
            g.AddEdge("rbs1A", "pcr1A");
            g.AddEdge("pcr1A", "rbs2A");
            g.AddEdge("rbs2A", "pcr2A");
            g.AddEdge("pcr2A", "ter1A");
            g.AddEdge("ter1A", "prom2A");
            g.AddEdge("prom2A", "rbs3A");
            g.AddEdge("rbs3A", "pcr3A");
            g.AddEdge("pcr3A", "ter2A");
            g.AddEdge("ter2A", "prom3A");
            g.AddEdge("prom3A", "rbs4A");
            g.AddEdge("rbs4A", "pcr4A");
            g.AddEdge("pcr4A", "ter3A");

            // Second DNA sequence
            g.AddEdge("prom1B", "rbs1B");
            g.AddEdge("rbs1B", "pcr1B");
            g.AddEdge("pcr1B", "ter1B");
            g.AddEdge("ter1B", "prom2B");
            g.AddEdge("prom2B", "rbs2B");
            g.AddEdge("rbs2B", "pcr2B");
            g.AddEdge("pcr2B", "rbs3B");
            g.AddEdge("rbs3B", "pcr3B");
            g.AddEdge("pcr3B", "ter2B");

            // Protein coding
            g.AddEdge("pcr1A", "prot_Q2b");
            g.AddEdge("pcr2A", "prot_Q1a");
            g.AddEdge("pcr3A", "prot_A");
            g.AddEdge("pcr4A", "prot_ccdB");
            g.AddEdge("pcr1B", "prot_ccdB");
            g.AddEdge("pcr2B", "prot_Q1b");
            g.AddEdge("pcr3B", "prot_Q2a");

            // Regulation
            g.AddEdge("prot_Q2b-H2", "prom2A");
            g.AddEdge("prot_H1-Q1b", "prom1B");

            // Reactions
            g.AddEdge("prot_Q2b", "r1");
            g.AddEdge("prot_H2", "r1");
            g.AddEdge("r1", "prot_Q2b-H2");
            g.AddEdge("prot_Q2b-H2", "r2");
            g.AddEdge("r2", "prot_H2");
            g.AddEdge("r2", "prot_Q2b");
            g.AddEdge("prot_H1", "r3");
            g.AddEdge("prot_Q1a", "r4");
            g.AddEdge("r4", "prot_H1");
            g.AddEdge("prot_H1", "r5");
            g.AddEdge("prot_Q1a", "r6");
            g.AddEdge("prot_ccdB", "r6");
            g.AddEdge("prot_H2", "r7");
            g.AddEdge("prot_H2", "r8");
            g.AddEdge("prot_Q2a", "r9");
            g.AddEdge("r9", "prot_H2");
            g.AddEdge("r10", "prot_H1");
            g.AddEdge("r10", "prot_Q1b");
            g.AddEdge("prot_H1-Q1b", "r10");
            g.AddEdge("prot_A", "r11");
            g.AddEdge("prot_ccdB", "r11");
            g.AddEdge("prot_Q1b", "r12");
            g.AddEdge("prot_H1", "r12");
            g.AddEdge("r12", "prot_H1-Q1b");
            g.AddEdge("prot_Q2a", "r13");
            g.AddEdge("prot_ccdB", "r13");

            // Set DNA sequences to be one above the other
            g.LayerConstraints.AddUpDownConstraint(Dn(g,"prom1A"), Dn(g,"prom1B"));

            // Set DNA sequence 1 to be in a row
            g.LayerConstraints.AddSameLayerNeighbors(Dn(g, "prom1A"),Dn(g,"rbs1A"),Dn(g,"pcr1A" ),Dn(g,"rbs2A" ),Dn(g,"pcr2A" ),Dn(g,"ter1A" ),
                Dn(g,"prom2A" ),Dn(g,"rbs3A" ),Dn(g,"pcr3A" ),Dn(g,"ter2A" ),Dn(g,"prom3A" ),Dn(g,"rbs4A" ),Dn(g,"pcr4A" ),Dn(g,"ter3A" ));

            // Set DNA sequence 2 to be in a row
            g.LayerConstraints.AddSameLayerNeighbors(Dn(g, "prom1B"), Dn(g, "rbs1B"), Dn(g, "pcr1B"), Dn(g, "ter1B"), Dn(g, "prom2B"), Dn(g, "rbs2B"),
                Dn(g, "pcr2B"), Dn(g, "rbs3B"), Dn(g, "pcr3B"), Dn(g, "ter2B"));

            // Set proteins to be below their pcr
            g.LayerConstraints.AddSequenceOfUpDownVerticalConstraint(Dn(g, "pcr1A"), Dn(g, "prot_Q2b"), Dn(g, "prot_A"), Dn(g, "prot_ccdB"));
            g.LayerConstraints.AddUpDownVerticalConstraint(Dn(g,"pcr2A"), Dn(g,"prot_Q1a"));
            g.LayerConstraints.AddUpDownConstraint(Dn(g,"pcr3A"), Dn(g,"prot_A"));
            g.LayerConstraints.AddUpDownConstraint(Dn(g,"pcr4A"), Dn(g,"prot_ccdB"));
            g.LayerConstraints.AddUpDownConstraint(Dn(g,"pcr1B"), Dn(g,"prot_ccdB"));
            g.LayerConstraints.AddUpDownConstraint(Dn(g,"pcr2B"), Dn(g,"prot_Q1b"));
            g.LayerConstraints.AddUpDownConstraint(Dn(g,"pcr3B"), Dn(g,"prot_Q2a"));
            /////////////////

            graphEditor.Graph = g;
        }
 /// <summary>
 /// Desenha o autΓ΄mato.
 /// </summary>
 private void Desenha(StackAutoma automato)
 {
     Graph grafoAutomato = new Graph("AutΓ΄mato");
     transicoes = new List<Transition>();
     // Adiciona elementos com base nas transiçáes
     foreach (KeyValuePair<string, State> estado in automato.States)
     {
         Node no = grafoAutomato.AddNode(estado.Key);
         no.Attr.Shape = Shape.Circle;
         // Faz marcaçáes no grafo..
         if (estado.Value.Final)
         {
             no.Attr.Shape = Shape.DoubleCircle;
         }
         if (estado.Value == automato.StartState)
         {
             no.Attr.FillColor = Microsoft.Msagl.Drawing.Color.LightGray;
         }
         transicoes.AddRange(estado.Value.Transitions);
     }
     foreach (Transition transicao in transicoes)
     {
         Edge arco = grafoAutomato.AddEdge(transicao.Source.Name, transicao.Destiny.Name);
         arco.LabelText = string.Format("({0}, {1}, {{{2}}})", transicao.Symbol, transicao.ConsumingStack[0], string.Join(",", transicao.PushStack.ToArray().Select(c => c.Name).ToArray()));
     }
     GViewer viewer = new GViewer();
     viewer.NavigationVisible = false;
     viewer.OutsideAreaBrush = Brushes.White;
     //viewer.RemoveToolbar();
     viewer.Graph = grafoAutomato;
     viewer.Dock = System.Windows.Forms.DockStyle.Fill;
     pnlAutomato.Controls.Clear();
     pnlAutomato.Controls.Add(viewer);
 }
        void CreateAndLayoutAndDisplayGraph(object sender, ExecutedRoutedEventArgs ex)
        {
            try
            {
            //                Graph graph = new Graph();
            //
            //                //graph.LayoutAlgorithmSettings=new MdsLayoutSettings();
            //
            //                graph.AddEdge("1", "2");
            //                graph.AddEdge("1", "3");
            //                var e = graph.AddEdge("4", "5");
            //                e.LabelText = "Some edge label";
            //                e.Attr.Color = Color.Red;
            //                e.Attr.LineWidth *= 2;
            //
            //                graph.AddEdge("4", "6");
            //                e = graph.AddEdge("7", "8");
            //                e.Attr.LineWidth *= 2;
            //                e.Attr.Color = Color.Red;
            //
            //                graph.AddEdge("7", "9");
            //                e = graph.AddEdge("5", "7");
            //                e.Attr.Color = Color.Red;
            //                e.Attr.LineWidth *= 2;
            //
            //                graph.AddEdge("2", "7");
            //                graph.AddEdge("10", "11");
            //                graph.AddEdge("10", "12");
            //                graph.AddEdge("2", "10");
            //                graph.AddEdge("8", "10");
            //                graph.AddEdge("5", "10");
            //                graph.AddEdge("13", "14");
            //                graph.AddEdge("13", "15");
            //                graph.AddEdge("8", "13");
            //                graph.AddEdge("2", "13");
            //                graph.AddEdge("5", "13");
            //                graph.AddEdge("16", "17");
            //                graph.AddEdge("16", "18");
            //                graph.AddEdge("16", "18");
            //                graph.AddEdge("19", "20");
            //                graph.AddEdge("19", "21");
            //                graph.AddEdge("17", "19");
            //                graph.AddEdge("2", "19");
            //                graph.AddEdge("22", "23");
            //
            //                e = graph.AddEdge("22", "24");
            //                e.Attr.Color = Color.Red;
            //                e.Attr.LineWidth *= 2;
            //
            //                e = graph.AddEdge("8", "22");
            //                e.Attr.Color = Color.Red;
            //                e.Attr.LineWidth *= 2;
            //
            //                graph.AddEdge("20", "22");
            //                graph.AddEdge("25", "26");
            //                graph.AddEdge("25", "27");
            //                graph.AddEdge("20", "25");
            //                graph.AddEdge("28", "29");
            //                graph.AddEdge("28", "30");
            //                graph.AddEdge("31", "32");
            //                graph.AddEdge("31", "33");
            //                graph.AddEdge("5", "31");
            //                graph.AddEdge("8", "31");
            //                graph.AddEdge("2", "31");
            //                graph.AddEdge("20", "31");
            //                graph.AddEdge("17", "31");
            //                graph.AddEdge("29", "31");
            //                graph.AddEdge("34", "35");
            //                graph.AddEdge("34", "36");
            //                graph.AddEdge("20", "34");
            //                graph.AddEdge("29", "34");
            //                graph.AddEdge("5", "34");
            //                graph.AddEdge("2", "34");
            //                graph.AddEdge("8", "34");
            //                graph.AddEdge("17", "34");
            //                graph.AddEdge("37", "38");
            //                graph.AddEdge("37", "39");
            //                graph.AddEdge("29", "37");
            //                graph.AddEdge("5", "37");
            //                graph.AddEdge("20", "37");
            //                graph.AddEdge("8", "37");
            //                graph.AddEdge("2", "37");
            //                graph.AddEdge("40", "41");
            //                graph.AddEdge("40", "42");
            //                graph.AddEdge("17", "40");
            //                graph.AddEdge("2", "40");
            //                graph.AddEdge("8", "40");
            //                graph.AddEdge("5", "40");
            //                graph.AddEdge("20", "40");
            //                graph.AddEdge("29", "40");
            //                graph.AddEdge("43", "44");
            //                graph.AddEdge("43", "45");
            //                graph.AddEdge("8", "43");
            //                graph.AddEdge("2", "43");
            //                graph.AddEdge("20", "43");
            //                graph.AddEdge("17", "43");
            //                graph.AddEdge("5", "43");
            //                graph.AddEdge("29", "43");
            //                graph.AddEdge("46", "47");
            //                graph.AddEdge("46", "48");
            //                graph.AddEdge("29", "46");
            //                graph.AddEdge("5", "46");
            //                graph.AddEdge("17", "46");
            //                graph.AddEdge("49", "50");
            //                graph.AddEdge("49", "51");
            //                graph.AddEdge("5", "49");
            //                graph.AddEdge("2", "49");
            //                graph.AddEdge("52", "53");
            //                graph.AddEdge("52", "54");
            //                graph.AddEdge("17", "52");
            //                graph.AddEdge("20", "52");
            //                graph.AddEdge("2", "52");
            //                graph.AddEdge("50", "52");
            //                graph.AddEdge("55", "56");
            //                graph.AddEdge("55", "57");
            //                graph.AddEdge("58", "59");
            //                graph.AddEdge("58", "60");
            //                graph.AddEdge("20", "58");
            //                graph.AddEdge("29", "58");
            //                graph.AddEdge("5", "58");
            //                graph.AddEdge("47", "58");
            //
            //                var subgraph = new Subgraph("subgraph 1");
            //                graph.RootSubgraph.AddSubgraph(subgraph);
            //                subgraph.AddNode(graph.FindNode("47"));
            //                subgraph.AddNode(graph.FindNode("58"));
            //
            //                graph.AddEdge(subgraph.Id, "55");
            //
            //                var node = graph.FindNode("5");
            //                node.LabelText = "Label of node 5";
            //                node.Label.FontSize = 5;
            //                node.Label.FontName = "New Courier";
            //                node.Label.FontColor = Microsoft.Msagl.Drawing.Color.Blue;
            //
            //                node = graph.FindNode("55");
            //
            //
            //                graph.Attr.LayerDirection= LayerDirection.LR;
            //             //   graph.LayoutAlgorithmSettings.EdgeRoutingSettings.RouteMultiEdgesAsBundles = true;
            //                //graph.LayoutAlgorithmSettings.EdgeRoutingSettings.EdgeRoutingMode = EdgeRoutingMode.SplineBundling;
            //                //layout the graph and draw it
                Graph graph = new Graph();
                graph.AddEdge("47", "58");
                graph.AddEdge("70", "71");

                var subgraph = new Subgraph("subgraph1");
                graph.RootSubgraph.AddSubgraph(subgraph);
                subgraph.AddNode(graph.FindNode("47"));
                subgraph.AddNode(graph.FindNode("58"));

                var subgraph2 = new Subgraph("subgraph2");
                subgraph2.Attr.Color = Color.Black;
                subgraph2.Attr.FillColor = Color.Yellow;
                subgraph2.AddNode(graph.FindNode("70"));
                subgraph2.AddNode(graph.FindNode("71"));
                subgraph.AddSubgraph(subgraph2);
                graph.AddEdge("58", subgraph2.Id);
                graph.Attr.LayerDirection = LayerDirection.LR;
                graphViewer.Graph = graph;

            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString(), "Load Failed", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Example #51
0
        private void SimulationInitialize(bool moveFirsStep)
        {
            //clear the trace and visited table
            Traces.Clear();
            visited.Clear();
            ListView_Trace.Items.Clear();

            //get the starting process

            //create the initial step
            EventStepSim initialStep = new EventStepSim(Spec.SimulationInitialization(this.ComboBox_Process.Text));
            //new EventStepSim(startingProcess, Common.Ultility.Constants.INITIAL_EVENT, null, SpecProcess.GetEnvironment()));

            //use the process string as the definition ref string, this is the only special case needs to be taken care of
            //initialStep.ProcessToString = startingProcess.Def.ToString();
            //todo: tobe checked
            //initialStep.ProcessToString = startingProcess.ToString();

            InitialState = initialStep.StepID;

            //string initialLabel = initialStep.ToFullString();

            AddToTrace("0", initialStep, "1", InitialState);

            CurrentEnableEventList.Clear();

            if (moveFirsStep)
            {
                //try
                //{
                List<EventStepSim> list = initialStep.MakeOneMove(HideTauTransition);

                for (int i = 0; i < list.Count; i++)
                {
                    EventStepSim step = list[i];
                    step.SourceProcess = InitialState;
                    step.IsUnvisitedStep = true;
                    list[i] = step;
                }

                CurrentEnableEventList.AddRange(list);
                //}
                //catch (Exception ex)
                //{

                //}
            }

            visited.Add(InitialState, null);

            g = new Graph("Graph");
            //g.GraphAttr.Orientation = System.Windows.Forms.Orientation.Landscape;
            g.Attr.LayerDirection = Direction;
            Node n = g.AddNode(InitialState);
            n.Attr.FillColor = Color.Red;
            n.LabelText = "1";
            n.UserData = initialStep; //initialLabel;

            Node tempN = g.AddNode(INITIAL_STATE);
            tempN.Attr.LineWidth = 0;
            tempN.Attr.Color = Color.White;
            tempN.LabelText = "";
            tempN.UserData = "";
            g.AddEdge(INITIAL_STATE, InitialState);

            //clear the mapping table
            Mapping.Clear();
            Mapping.Add(GetTraceEvent(this.ListView_Trace.Items.Count) + InitialState,
                        new ProcessData(initialStep, CloneGraph(g), CloneEnabledEvent()));

            SimulatorViewer.Graph = g;
            SimulatorViewer.Validate();

            FillCurrentEnabledList();
            UpdateStore(initialStep);

            WarningFlag = false;
        }
Example #52
0
 void CreateWideGraph()
 {
     graph = new Graph();
     for (int i = 0; i < 100; i++)
         graph.AddEdge("A", i.ToString());
 }
        static Graph CreateGraphFromTables(Dictionary<string, string> labelDictionary, List<Tuple<string, string>> edgeList) {
            var graph=new Graph();
            graph.LayoutAlgorithmSettings = new MdsLayoutSettings();
            foreach (var v in labelDictionary.Values)
                graph.AddNode(v);

            foreach (var tuple in edgeList) {
                var e=graph.AddEdge(labelDictionary[tuple.Item1], labelDictionary[tuple.Item2]);
            }

            return graph;
        }
Example #54
0
        static void TestMultiedges() {
            var drGraph = new Graph("foo");
            const int comps = 30;
            const int edgesInComp = 30;
            for (int i = 0; i < comps; i++) {
                string source = i.ToString();
                string target = (i + 1).ToString();
                for (int j = 0; j < edgesInComp; j++)
                    drGraph.AddEdge(source, i + " " + j, target);
            }

            var f = new Form2(false);
            object ret = f.GViewer.CalculateLayout(drGraph);

            f.StartPosition = FormStartPosition.CenterScreen;
            //   f.layerSeparationMult.Value = (decimal)(drGraph.GraphAttr.LayerSep / drGraph.GraphAttr.MinLayerSep);
            f.GViewer.SetCalculatedLayout(ret);

            f.Size = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
            f.ShowDialog();
        }
Example #55
0
        static void TestSave() {
            var g = new Graph();
            g.AddEdge("a", "b");
            var gv = new GViewer();
            gv.CalculateLayout(g);
            const string fileName = "c:\\tmp\\saved.msagl";
            g.Write(fileName);

            g = Graph.Read(fileName);

            var f = new Form();
            f.SuspendLayout();
            f.Controls.Add(gv);
            gv.Dock = DockStyle.Fill;
            gv.NeedToCalculateLayout = false;
            gv.Graph = g;
            f.ResumeLayout();

            f.ShowDialog();

            Environment.Exit(0);
        }
Example #56
0
        private void DrawProtocolStates()
        {
            graph = new Graph("graph");
            foreach (Type t in ProtocolProvider.GetProtocolStates(UserControlProtocolType))
            {
                string NodeFrom = ProtocolProvider.GetStateDesplayName(t);
                foreach (Type ts in ProtocolProvider.GetStateNextStates(t))
                {
                    UpdateEdgeNodesAttr(graph.AddEdge(NodeFrom,ProtocolProvider.GetStateDesplayName(ts)));
                }
            }

            //Node N = graph.FindNode("Grow 1");
            //N.Label.FontSize = 50;

            foreach (Node  N in  graph.NodeMap.Values )
            {
                //	N.Label.FontSize = 50;
            }

            graph.Attr.LayerDirection =LayerDirection.None;
            double AspectRatio = Convert.ToDouble(panel1.Width)/Convert.ToDouble(panel1.Height);
            graph.Attr.AspectRatio = AspectRatio;
            //graph.Attr.MinNodeHeight = 50;
            //graph.Attr.MinNodeWidth = 100;

            // aspect ratio is set

            graph.Attr.BackgroundColor = Microsoft.Msagl.Drawing.Color.White;

            //Microsoft.Msagl.GeometryGraph geomGraph = new Microsoft.Msagl.GeometryGraph();

            //	geomGraph.SimpleStretch=false;

            //	geomGraph.AspectRatio = 1;

            //	geomGraph.CalculateLayout();

            //ProtocolStatesViewer.Graph = graph;

            //	graph.GeometryGraph = geomGraph;

            //ProtocolStatesViewer.Graph = graph;

            //	ProtocolStatesViewer.NeedToCalculateLayout = false;
            ProtocolStatesViewer.Graph = graph;
        }
        private void Draw(Graph<Symbol, double> g)
        {
            treeViewSyn.Nodes.Clear();
            if (g != null && g.Root != null)
            {
                Graph graph = new Graph("Graph");
                //graph.Attr.LayerDirection = LayerDirection.TB;
                Node<Symbol, double> node = g.Root;
                TreeNode treeNode;
                Stack<Node<Symbol, double>> stack = new Stack<Node<Symbol, double>>();
                Stack<TreeNode> stackTreeNode = new Stack<TreeNode>();
                stackTreeNode.Push(null);

                stack.Push(node);
                while (stack.Count > 0)
                {
                    node = stack.Pop();
                    treeNode = stackTreeNode.Pop();
                    var treeNodeNext = AddNode(node, treeNode);

                    string str = "Root";
                    if (node.Info != null)
                        str = node.Info.Name;
                    var no = graph.AddNode(node.Name);
                    no.Attr.Shape = Shape.Circle;
                    no.LabelText = str;

                    foreach (var transition in System.Linq.Enumerable.Reverse(node.Edges))
                    {
                        Edge arco = graph.AddEdge(node.Name, "", transition.Destiny.Name);

                        System.Drawing.Color c = Utils.GetColor(transition.Cost);
                        var color = new Microsoft.Msagl.Drawing.Color((byte)c.R, (byte)c.G, (byte)c.B);
                        arco.Attr.Color = color;
                        arco.Attr.AddStyle(Style.Bold);
                        arco.Attr.LineWidth = 5;
                        arco.LabelText = transition.Cost.ToString("n2");

                        stack.Push(transition.Destiny);
                        stackTreeNode.Push(treeNodeNext);
                    }
                }

                GViewer viewer = new GViewer();
                // viewer.CurrentLayoutMethod = LayoutMethod.Ranking;

                viewer.NavigationVisible = false;
                viewer.OutsideAreaBrush = Brushes.White;
                viewer.ToolBarIsVisible = false;
                viewer.Graph = graph;
                viewer.Dock = System.Windows.Forms.DockStyle.Fill;

                pnlGraph.Controls.Clear();
                pnlGraph.Controls.Add(viewer);
                treeViewSyn.ExpandAll();
            }
        }
Example #58
0
 static void AddEdge(Graph drawingGraph, string id0, string id1)
 {
     var edge = drawingGraph.AddEdge(id0, id1);
     //        edge.Attr.ArrowheadAtTarget = ArrowStyle.None;
     edge.Attr.Length = 6;
 }
Example #59
0
        public static Graph CloneGraph(Graph graph)
        {
            Graph Graph = new Graph(graph.Label.Text);
            //Graph.GraphAttr.Orientation = graph.GraphAttr.Orientation;
            Graph.Attr.LayerDirection = graph.Attr.LayerDirection;

            Debug.Assert(graph.Edges.Count > 0);

            foreach (Edge edge in graph.Edges)
            {
                Edge newEdge = Graph.AddEdge(edge.Source, edge.LabelText, edge.Target);
                if (edge.Source == SimulationForm.INITIAL_STATE)
                {
                    newEdge.SourceNode.Attr.LineWidth = 0;
                    newEdge.SourceNode.Attr.Color = Color.White;
                }
                newEdge.SourceNode.LabelText = edge.SourceNode.LabelText;
                newEdge.SourceNode.UserData = edge.SourceNode.UserData;
                newEdge.TargetNode.LabelText = edge.TargetNode.LabelText;
                newEdge.TargetNode.Attr.FillColor = edge.TargetNode.Attr.FillColor;
                newEdge.TargetNode.UserData = edge.TargetNode.UserData;
                newEdge.Attr.Color = edge.Attr.Color;
            }

            return Graph;
        }
 protected override void UpdateOutEdges(Graph graph)
 {
     foreach (GameMasterNode file in mEncounterFiles)
     {
         if (file.NodeType == GameMasterNodeType.ENCOUNTER)
         {
             EncounterNodeData nodeData = file.NodeData as EncounterNodeData;
             if (nodeData.IsStartNode)
             {
                 graph.AddEdge(NodeFile.Id, file.Id);
             }
         }
     }
 }