Пример #1
1
        private void RebuildGraph()
        {
            // Clear prev Graph
            this.node_map.Clear();
            this.in_edge_map.Clear();
            this.out_edge_map.Clear();
            this.Graph.Nodes.Clear();
            this.Graph.Edges.Clear();

            // Build new Graph
            if( this.grammar == null || this.canonical_sets == null )
                return;

            // Make the layout with the Glee lib
            var layout_g = new Microsoft.Glee.Drawing.Graph("Fdsm");
            layout_g.Directed = true;
            var layout_nodes = new Dictionary<Node, Microsoft.Glee.Drawing.Node>();
            var layout_edges = new Dictionary<Edge, Microsoft.Glee.Drawing.Edge>();

            // Create nodes
            for( int state_index = 0; state_index < this.canonical_sets.Sets.Count; ++state_index )
            {
                var node = new Node();
                node.Shape = NodeShape.Circle;
                node.Box = new RectangleF(this.node_diameter / -2, this.node_diameter / -2, this.node_diameter, this.node_diameter);
                node.BorderType = (this.canonical_sets.Sets[state_index].FirstOrDefault(
                    item => item.CursorPosition == item.Rule.RightHandSide.Count) == null)
                        ? NodeBorderType.Single
                        : NodeBorderType.Double;
                node.LabelText = state_index.ToString();
                node.LabelFont = this.Font;
                var label_size = this.Graph.MeasureString(this.Font, node.LabelText);
                node.LabelOffset = new PointF(label_size.Width / -2, label_size.Height / -2);
                node.BorderPen = this.border_pen;
                node.BackBrush = this.back_brush;
                node.LabelBrush = this.label_brush;

                this.Graph.Nodes.Add(node);
                this.node_map.Add(state_index, node);
                this.in_edge_map.Add(state_index, new Dictionary<SyntacticAnalysis.Symbol, Edge>());
                this.out_edge_map.Add(state_index, new Dictionary<SyntacticAnalysis.Symbol, Edge>());

                // Layout
                var layout_node = layout_g.AddNode(node.LabelText);
                layout_node.Attr.LabelMargin = 6;
                layout_nodes.Add(node, layout_node);
            }

            // Create edges
            for( int state_index = 0; state_index < this.canonical_sets.Sets.Count; ++state_index )
            {
                // Terminals
                foreach( var symbol in this.grammar.Terminals )
                {
                    int transition_to = this.canonical_sets.GetTransition(state_index, symbol);
                    if( transition_to != -1 )
                    {
                        var edge = new Edge();
                        edge.StartNode = this.node_map[state_index];
                        edge.EndNode = this.node_map[transition_to];
                        edge.LabelText = symbol.Name;
                        edge.LabelFont = this.Font;
                        edge.LabelBrush = this.label_brush;
                        edge.LinePen = this.edge_pen;

                        this.Graph.Edges.Add(edge);
                        this.out_edge_map[state_index][symbol] = edge;
                        this.in_edge_map[transition_to][symbol] = edge;

                        // Layout
                        var layout_edge = layout_g.AddEdge(edge.StartNode.LabelText, edge.EndNode.LabelText);
                        layout_edge.Attr.Label = edge.LabelText;
                        layout_edges.Add(edge, layout_edge);
                    }
                }

                // Grammaticals
                foreach( var symbol in this.grammar.Grammaticals )
                {
                    int transition_to = this.canonical_sets.GetTransition(state_index, symbol);
                    if( transition_to != -1 )
                    {
                        var edge = new Edge();
                        edge.StartNode = this.node_map[state_index];
                        edge.EndNode = this.node_map[transition_to];
                        edge.LabelText = symbol.Name;
                        edge.LabelFont = this.Font;
                        edge.LabelBrush = this.label_brush;
                        edge.LinePen = this.edge_pen;

                        this.Graph.Edges.Add(edge);
                        this.out_edge_map[state_index][symbol] = edge;
                        this.in_edge_map[transition_to][symbol] = edge;

                        // Layout
                        var layout_edge = layout_g.AddEdge(edge.StartNode.LabelText, edge.EndNode.LabelText);
                        layout_edge.Attr.Label = edge.LabelText;
                        layout_edges.Add(edge, layout_edge);
                    }
                }
            }

            // Let Glee calculate a layout
            var layout_rnd = new Microsoft.Glee.GraphViewerGdi.GraphRenderer(layout_g);
            layout_rnd.CalculateLayout();

            // Extract and replicate layout
            // Nodes
            foreach( var kv in layout_nodes )
                kv.Key.Position = this.FromGleePoint(kv.Value.Attr.Pos);

            // Edges
            foreach( var kv in layout_edges )
            {
                var edge = kv.Key;
                var layout_edge = kv.Value;

                var curve = layout_edge.Attr.EdgeCurve as Microsoft.Glee.Splines.Curve;
                if( curve != null )
                {
                    var segments = new List<CurveSegment>();

                    foreach( Microsoft.Glee.Splines.ICurve segment in curve.Segs )
                    {
                        if( segment is Microsoft.Glee.Splines.CubicBezierSeg )
                        {
                            var b = (Microsoft.Glee.Splines.CubicBezierSeg)segment;

                            segments.Add(new CurveSegment(new PointF[]
                                {
                                    this.FromGleePoint(b.B(0)),
                                    this.FromGleePoint(b.B(1)),
                                    this.FromGleePoint(b.B(2)),
                                    this.FromGleePoint(b.B(3)),
                                }));
                        }
                        else // Fallback to linearity, even if it is not a LineSeg.
                        {
                            segments.Add(new CurveSegment(new PointF[]
                                {
                                    this.FromGleePoint(segment.Start),
                                    this.FromGleePoint(segment.End),
                                }));
                        }
                    }

                    // Snap edge ends to nodes
                    var e = new PointF(
                        edge.StartNode.Position.X - segments[0].Points[0].X,
                        edge.StartNode.Position.Y - segments[0].Points[0].Y);
                    var diff = e.Norm().Multiply(e.Length() - this.node_radius);
                    edge.StartPosition = segments[0].Points[0] = segments[0].Points[0].Add(diff);

                    var seg = segments[segments.Count - 1];
                    e = new PointF(
                        edge.EndNode.Position.X - seg.Points[seg.Points.Length - 1].X,
                        edge.EndNode.Position.Y - seg.Points[seg.Points.Length - 1].Y);
                    diff = e.Norm().Multiply(e.Length() - this.node_radius);
                    edge.EndPosition = seg.Points[seg.Points.Length - 1] =
                        seg.Points[seg.Points.Length - 1].Add(diff);

                    edge.Segments = segments.ToArray();
                }
                else
                {
                    // Fallback to line
                    edge.StartPosition = edge.StartNode.Position;
                    edge.EndPosition = edge.EndNode.Position;

                    // Snap edge ends to nodes
                    var e = new PointF(
                        edge.EndPosition.X - edge.StartPosition.X,
                        edge.EndPosition.Y - edge.StartPosition.Y)
                        .Norm().Multiply(this.node_radius);

                    edge.StartPosition = edge.StartPosition.Add(e);
                    edge.EndPosition = edge.EndPosition.Substract(e);
                }

                // Label
                edge.LabelPosition = new PointF(
                    -(float)layout_edge.Attr.LabelTop,
                    (float)layout_edge.Attr.LabelLeft);
            }

            // Add an 'in-edge' to the start state node
            var start_edge = new Edge();
            start_edge.LinePen = this.edge_pen;
            start_edge.EndNode = this.node_map[0];
            start_edge.EndPosition = new PointF(
                start_edge.EndNode.Position.X - this.node_radius,
                start_edge.EndNode.Position.Y);
            start_edge.StartPosition = new PointF(
                start_edge.EndPosition.X - this.node_diameter,
                start_edge.EndPosition.Y);

            this.Graph.Edges.Add(start_edge);
        }
Пример #2
0
        static void Main()
        {
            Microsoft.Glee.Drawing.Graph graph = new
                                                 Microsoft.Glee.Drawing.Graph("");
            graph.AddEdge("A", "B");
            graph.AddEdge("A", "B");
            graph.FindNode("A").Attr.Fillcolor =
                Microsoft.Glee.Drawing.Color.Red;
            graph.FindNode("B").Attr.Fillcolor =
                Microsoft.Glee.Drawing.Color.Blue;
            Microsoft.Glee.GraphViewerGdi.GraphRenderer renderer
                = new Microsoft.Glee.GraphViewerGdi.GraphRenderer
                      (graph);
            renderer.CalculateLayout();
            int    width  = 500;
            Bitmap bitmap = new Bitmap(width, (int)(graph.Height *
                                                    (width / graph.Width)), PixelFormat.Format32bppPArgb);

            renderer.Render(bitmap);
            bitmap.Save("test1.png");

            //        //create a form
            //        System.Windows.Forms.Form form = new
            //System.Windows.Forms.Form();
            //        //create a viewer object
            //        Microsoft.Glee.GraphViewerGdi.GViewer viewer
            //= new Microsoft.Glee.GraphViewerGdi.GViewer();
            //        //create a graph object
            //        Microsoft.Glee.Drawing.Graph graph = new
            //Microsoft.Glee.Drawing.Graph("graph");
            //        //create the graph content
            //        graph.AddEdge("A", "B");
            //        graph.AddEdge("B", "C");
            //        graph.AddEdge("A", "C").EdgeAttr.Color =
            //Microsoft.Glee.Drawing.Color.Green;
            //        graph.FindNode("A").Attr.Fillcolor =
            //Microsoft.Glee.Drawing.Color.Magenta;
            //        graph.FindNode("B").Attr.Fillcolor =
            //Microsoft.Glee.Drawing.Color.MistyRose;
            //        Microsoft.Glee.Drawing.Node c =
            //graph.FindNode("C");
            //        c.Attr.Fillcolor =
            //Microsoft.Glee.Drawing.Color.PaleGreen;
            //        c.Attr.Shape =
            //Microsoft.Glee.Drawing.Shape.Diamond;
            //        //bind the graph to the viewer viewer.Graph = graph;
            //        //associate the viewer with the form
            //        form.SuspendLayout();
            //        viewer.Dock =
            //System.Windows.Forms.DockStyle.Fill;
            //        form.Controls.Add(viewer);
            //        form.ResumeLayout();
            //        ///show the form
            //        ///
            //form.ShowDialog();

            //Application.EnableVisualStyles();
            //Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new Form1());
        }
Пример #3
0
        public static void ShowDialog(Microsoft.Glee.Drawing.Graph graph)
        {
            if (graph == null)
            {
                throw new ArgumentNullException(nameof(graph));
            }

            var viewerForm = new Form();

            viewerForm.SuspendLayout();
            var viewer = new GViewer();

            viewer.Dock = DockStyle.Fill;
            viewerForm.Controls.Add(viewer);
            viewerForm.ResumeLayout();

            viewer.Graph = graph;
            viewerForm.ShowDialog();
        }
Пример #4
0
    public void GambarPeta()
    //Method menggabarkan peta penyebaran atribut graf pada form baru
    {
        System.Windows.Forms.Form             peta = new System.Windows.Forms.Form();
        Microsoft.Glee.GraphViewerGdi.GViewer view = new Microsoft.Glee.GraphViewerGdi.GViewer();
        Microsoft.Glee.Drawing.Graph          map  = new Microsoft.Glee.Drawing.Graph("Peta Penyebaran Virus");

        Dictionary <string, Graph> .KeyCollection keys = this.graf.Keys;
        foreach (string node1 in keys)
        {
            if (graf[node1].GetNEdge() == 0)
            {
                map.AddNode(node1);
            }
            else
            {
                foreach (string node2 in graf[node1].GetEdge())
                {
                    map.AddEdge(node1, node2);
                }
                if (graf[node1].GetDayInf() != -1)
                {
                    Microsoft.Glee.Drawing.Node temp = map.FindNode(node1);
                    temp.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.Red;
                }
            }
        }

        //bind the graph to the viewer
        view.Graph = map;

        //associate the viewer with the form
        peta.SuspendLayout();
        view.Dock = System.Windows.Forms.DockStyle.Fill;
        peta.Controls.Add(view);
        peta.ResumeLayout();
        peta.Text          = "Peta Penyebaran Virus";
        peta.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;

        //show the form
        peta.ShowDialog();
    }
        private void ShowGraphDialog(Microsoft.Glee.Drawing.Graph graph)
        {
            //create a form
            System.Windows.Forms.Form form = new System.Windows.Forms.Form();

            //create a viewer object
            Microsoft.Glee.GraphViewerGdi.GViewer viewer = new Microsoft.Glee.GraphViewerGdi.GViewer();

            //bind the graph to the viewer
            viewer.Graph = graph;

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

            //show the form
            form.ShowDialog();
        }
Пример #6
0
        private int critical_path()
        {
            ////////////////////////////////////////////////////////////////////////////////////
            graph = new Microsoft.Glee.Drawing.Graph("graph");
            DataTable task = new DataTable("task");

            DataColumn task_name = new DataColumn("task_name");

            task_name.DataType = Type.GetType("System.String");

            DataColumn task_duration = new DataColumn("task_duration");

            task_duration.DataType = Type.GetType("System.Int32");

            DataColumn task_duration_type = new DataColumn("task_duration_type");

            task_duration_type.DataType = Type.GetType("System.String");

            DataColumn task_starting_time = new DataColumn("task_starting_time");

            task_starting_time.DataType = Type.GetType("System.DateTime");

            DataColumn task_finishing_time = new DataColumn("task_finishing_time");

            task_finishing_time.DataType = Type.GetType("System.DateTime");


            task.Columns.Add(task_name);
            task.Columns.Add(task_duration);
            task.Columns.Add(task_duration_type);
            task.Columns.Add(task_starting_time);
            task.Columns.Add(task_finishing_time);
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            DataTable Tas_dep = new DataTable("Tas_dep");

            DataColumn Tas_dep_t = new DataColumn("Tas_dep_t");

            Tas_dep_t.DataType = Type.GetType("System.String");

            DataColumn Tas_dep_tp = new DataColumn("Tas_dep_tp");

            Tas_dep_tp.DataType = Type.GetType("System.String");

            Tas_dep.Columns.Add(Tas_dep_t);
            Tas_dep.Columns.Add(Tas_dep_tp);
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            DataTable flip = new DataTable("flip");

            DataColumn fatherr = new DataColumn("fatherr");

            fatherr.DataType = Type.GetType("System.String");

            DataColumn sonn = new DataColumn("sonn");

            sonn.DataType = Type.GetType("System.String");

            flip.Columns.Add(fatherr);
            flip.Columns.Add(sonn);
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            DataTable dep = new DataTable("dep");

            DataColumn f = new DataColumn("f");

            Tas_dep_t.DataType = Type.GetType("System.String");

            DataColumn s = new DataColumn("s");

            Tas_dep_tp.DataType = Type.GetType("System.String");

            dep.Columns.Add(f);
            dep.Columns.Add(s);
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            ods.Tables.Add(task);
            ods.Tables.Add(Tas_dep);
            ods.Tables.Add(flip);
            ods.Tables.Add(dep);
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            graph.CleanNodes();
            for (int k = 0; k < ods.Tables[0].Rows.Count; k++)
            {
                ods.Tables[0].Rows.RemoveAt(k);
            }
            for (int k = 0; k < ods.Tables[1].Rows.Count; k++)
            {
                ods.Tables[1].Rows.RemoveAt(k);
            }
            for (int k = 0; k < Program.ods.Tables[0].Rows.Count; k++)
            {
                string name = Program.ods.Tables[0].Rows[k][0].ToString();
                int    dur  = int.Parse(Program.ods.Tables[0].Rows[k][1].ToString());
                string type = Program.ods.Tables[0].Rows[k][2].ToString();
                switch (type)
                {
                case "Month": { dur = dur * 30; } break;

                case "Hour":
                {
                    double duration_ = ((double)dur / Program.number_of_working_hours);
                    dur = (int)Math.Ceiling(duration_);
                }
                break;

                case "Week": { dur = dur * 7; } break;
                }
                string   d1  = Program.ods.Tables[0].Rows[k][3].ToString();
                string   d2  = Program.ods.Tables[0].Rows[k][4].ToString();
                string[] d11 = d1.Split(' ');

                DateTime st = DateTime.Parse(d11[0]);

                //DateTime fn= null;
                ods.Tables["task"].Rows.Add(name, dur, type, st);
            }
            for (int k = 0; k < Program.ods.Tables[3].Rows.Count; k++)
            {
                string col1 = Program.ods.Tables[3].Rows[k][0].ToString();
                string col2 = Program.ods.Tables[3].Rows[k][1].ToString();
                ods.Tables[1].Rows.Add(col1, col2);
            }

            for (int q = 0; q < Tas_dep.Rows.Count; q++)
            {
                flip.Rows.Add(null, null);
                flip.Rows[q][0] = Tas_dep.Rows[q][1];
                flip.Rows[q][1] = Tas_dep.Rows[q][0];
            }

            for (int q = 0; q < flip.Rows.Count; q++)
            {
                dep.Rows.Add(null, null);
                dep.Rows[q][0] = flip.Rows[q][0];
                dep.Rows[q][1] = flip.Rows[q][1];
            }

            for (int q = 0; q < task.Rows.Count; q++)//for father
            {
                int y = 0;
                for (int w = 0; w < flip.Rows.Count; w++)//if there is father
                {
                    if (task.Rows[q][0] == flip.Rows[w][1])
                    {
                        y = 1;
                    }
                }
                if (y != 1)
                {
                    dep.Rows.Add(null, task.Rows[q][0]);
                }
                y = 0;
            }
            for (int q = 0; q < task.Rows.Count; q++)//for son
            {
                int y = 0;
                for (int w = 0; w < flip.Rows.Count; w++)//if there is son
                {
                    if (task.Rows[q][0] == flip.Rows[w][0])
                    {
                        y = 1;
                    }
                }
                if (y != 1)
                {
                    dep.Rows.Add(task.Rows[q][0], null);
                }
                y = 0;
            }
            Console.WriteLine("this is the dep that u are going to use\n");
            for (int q = 0; q < dep.Rows.Count; q++)
            {
                Console.WriteLine("fa:{0}  son:{1}\n", dep.Rows[q][0], dep.Rows[q][1]);
            }


            int n;

            n = ods.Tables[0].Rows.Count;
            int i;

            init(n);
            net_work[0].flag        = 1;
            net_work[n + 1].flag    = 1;
            net_work[0].early_start = 0;
            net_work[0].early_end   = 0;
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            for (i = 1; i < n + 1; i++)
            {
                int x = int.Parse(ods.Tables[0].Rows[i - 1][1].ToString());
                net_work[i].value = x;
            }
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            int m;

            m = dep.Rows.Count;
            int fa = new int(), son = new int();

            for (i = 0; i < m; i++)
            {
                string sonName, sonNameToCheck, fatherName, fatherNameToCheck;
                //for the father
                for (int j = 0; j < n; j++)
                {
                    fatherName        = dep.Rows[i][0].ToString();
                    fatherNameToCheck = ods.Tables[0].Rows[j][0].ToString();
                    if (fatherName == "")
                    {
                        fa = 0;
                        break;
                    }

                    if (fatherName == fatherNameToCheck)
                    {
                        fa = j + 1;
                        break;
                    }// comparison for parent to find its number from a string
                }

                // for the son
                for (int j = 0; j < n; j++)
                {
                    sonName        = dep.Rows[i][1].ToString();
                    sonNameToCheck = ods.Tables[0].Rows[j][0].ToString();
                    if (sonName == "")
                    {
                        son = n + 1;
                        break;
                    }
                    if (sonName == sonNameToCheck)
                    {
                        son = j + 1;
                        break;
                    }
                }

                //fa = int.Parse(ods.Tables[1].Rows[i][0].ToString());
                //son = int.Parse(ods.Tables[1].Rows[i][1].ToString());
                add_node(fa, son);
            }
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            for (int z = 0; z < n + 1; z++)
            {
                Console.WriteLine("value:{0}\n", net_work[z].value);
            }
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            topological_order();
            show_item(n);
            net_work[n + 1].last_start = net_work[n + 1].early_start;
            net_work[n + 1].last_end   = net_work[n + 1].early_end;
            inverse_topological_order(n + 1);
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // find_critical_path(0);
            show_item(n);

            //create a form
            System.Windows.Forms.Form form = new System.Windows.Forms.Form();
            //create a viewer object
            Microsoft.Glee.GraphViewerGdi.GViewer viewer = new Microsoft.Glee.GraphViewerGdi.GViewer();
            //create a graph object
            //create the graph content
            //graph.AddEdge("Start", "T1");
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

            for (i = 0; i < m; i++)
            {
                if (dep.Rows[i][0].ToString() == "")
                {
                    graph.AddEdge("start", dep.Rows[i][1].ToString());
                    continue;
                }
                if (dep.Rows[i][1].ToString() == "")
                {
                    graph.AddEdge(dep.Rows[i][0].ToString(), "end");
                    continue;
                }

                graph.AddEdge(dep.Rows[i][0].ToString(), dep.Rows[i][1].ToString()).Attr.Color = Microsoft.Glee.Drawing.Color.Green;
            }
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //graph.AddEdge("Start", "End").Attr.Color = Microsoft.Glee.Drawing.Color.Green;
            //graph.FindNode("start").Attr.Fillcolor = Microsoft.Glee.Drawing.Color.Magenta;

            find_critical_path(0);
            //graph.FindNode("T1").Attr.Fillcolor = Microsoft.Glee.Drawing.Color.MistyRose;
            //Microsoft.Glee.Drawing.Node c = graph.FindNode("End");
            //c.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.PaleGreen;
            //c.Attr.Shape = Microsoft.Glee.Drawing.Shape.Diamond;
            //bind the graph to the viewer
            viewer.Graph = graph;

            //associate the viewer with the form
            form.SuspendLayout();
            viewer.Dock = System.Windows.Forms.DockStyle.Fill;
            form.Controls.Add(viewer);
            form.ResumeLayout();
            //show the form
            form.ShowDialog();

            return(0);
        }
Пример #7
0
        public FormGanttChart()
        {
            InitializeComponent();

            /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
            *                          GANTT CHART                                      *
            * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
            chart.ChartAreas[0].AxisY.IntervalType = DateTimeIntervalType.Days;
            //chart.ChartAreas[0].AxisY.Interval = 1;

            // Get each task start date and finish date
            HashSet <Node> Nodes        = Program.formMain.GetNodes();
            int            maxEmployees = 0;
            // While there are uncomlited tasks
            DateTime currentDate = Program.formMain.dateTimePicker.Value;

            for (; Nodes.Any(new Func <Node, bool>(delegate(Node node) { return(node.Days > 0); })); currentDate = currentDate.AddDays(1))
            {
                // Start unstarted tasks that have all dependencies complited
                foreach (Node node in Nodes)
                {
                    if (!node.HasStarted && node.Dependencies.All(new Func <Node, bool>(delegate(Node dependency) { return(dependency.Days == 0); })))
                    {
                        node.HasStarted = true;
                        node.StartDate  = currentDate;
                    }
                }

                // Decrese days of uncomplited started tasks and finish them if current day was last
                if (Program.formMain.checkboxes[(int)currentDate.DayOfWeek].Checked)
                {
                    // Count of employees required at current day
                    int employ = 0;
                    foreach (Node node in Nodes)
                    {
                        if (node.HasStarted && node.Days > 0)
                        {
                            employ++;
                            if (--node.Days == 0)
                            {
                                node.FinishDate = currentDate;
                            }
                        }
                    }
                    // Check for loops
                    if (employ == 0)
                    {
                        throw new Exception("Loop detected");
                    }
                    // Check if max emloyees required at current day
                    if (employ > maxEmployees)
                    {
                        maxEmployees = employ;
                    }
                }
            }
            employees.Text = maxEmployees.ToString();
            deadline.Text  = currentDate.ToLongDateString();
            period.Text    = (currentDate - Program.formMain.dateTimePicker.Value).Days.ToString() + " days";

            // Set Y axis maximum an minimum dates
            chart.ChartAreas[0].AxisY.Minimum = Program.formMain.dateTimePicker.Value.AddDays(-1).ToOADate();
            chart.ChartAreas[0].AxisY.Maximum = currentDate.ToOADate();

            // Add DataPoints to chart
            for (int i = 0; i < Nodes.Count(); i++)
            {
                Node node = Nodes.ElementAt(i);
                chart.Series[0].Points.AddXY(i, node.StartDate, node.FinishDate.AddDays(1));
                chart.Series[0].Points[i].Label   = chart.Series[0].Points[i].AxisLabel = node.ID;
                chart.Series[0].Points[i].ToolTip = node.StartDate.ToShortDateString() + " - " + node.FinishDate.ToShortDateString();
            }


            /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
            * Program Evaluation and Review Technique                                   *
            * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
            // Get union of all nodes dependencies
            List <Node> allDependencies = new List <Node>();
            // List of checkpoints
            List <Checkpoint> checkpoints = new List <Checkpoint>();

            for (int i = 0, m = 0; i < Nodes.Count; i++)
            {
                Node node = Nodes.ElementAt(i);
                allDependencies.AddRange(node.Dependencies);
                if (node.checkpoint == null)
                {
                    // Set checkpoint to node
                    Checkpoint checkpoint = new Checkpoint();
                    checkpoint.ID   = (checkpoint.Dependencies = node.Dependencies).Count == 0 ? "Start" : Checkpoint.template + m++.ToString();
                    node.checkpoint = checkpoint;
                    // Check other nodes for same dependencies
                    for (int j = i + 1; j < Nodes.Count; j++)
                    {
                        Node otherNode = Nodes.ElementAt(j);
                        if (otherNode.Dependencies.SetEquals(node.Dependencies))
                        {
                            otherNode.checkpoint = checkpoint;
                        }
                    }
                    checkpoints.Add(checkpoint);
                }
            }

            // Create finish checkpoint
            Checkpoint finish = new Checkpoint();

            finish.ID           = "Finish";
            finish.Dependencies = new HashSet <Node>(Nodes.Except(allDependencies));
            checkpoints.Add(finish);

            // Get critical way
            List <object> critical = new List <object>();

            critical.Add(finish);
            for (Checkpoint checkpoint = finish; checkpoint.Dependencies.Count > 0;)
            {
                DateTime latestDate = checkpoint.Dependencies.Max(new Func <Node, DateTime>(delegate(Node node) { return(node.FinishDate); }));
                Node     latestNode = checkpoint.Dependencies.First(new Func <Node, bool>(delegate(Node next) { return(next.FinishDate == latestDate); }));
                critical.Add(checkpoint = latestNode.checkpoint);
                critical.Add(latestNode);
            }

            // Create graph
            Microsoft.Glee.Drawing.Graph graph = new Microsoft.Glee.Drawing.Graph("PERT");
            // Add nodes
            foreach (Node node in Nodes)
            {
                graph.AddNode(node.ID);
                graph.FindNode(node.ID).Attr.Fillcolor = Microsoft.Glee.Drawing.Color.Azure;
            }
            // Add checkpoints
            foreach (Checkpoint checkpoint in checkpoints)
            {
                graph.AddNode(checkpoint.ID);
                Microsoft.Glee.Drawing.Node graphNode = graph.FindNode(checkpoint.ID);
                graphNode.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.MistyRose;
                graphNode.Attr.Shape     = Microsoft.Glee.Drawing.Shape.Diamond;
            }
            // Connect each node to its dependency checkpoint
            foreach (Node node in Nodes)
            {
                Microsoft.Glee.Drawing.Edge edge = new Microsoft.Glee.Drawing.Edge(node.checkpoint.ID, null, node.ID);
                if (critical.Contains(node))
                {
                    edge.Attr.Color = Microsoft.Glee.Drawing.Color.Red;
                }
                graph.Edges.Add(edge);
            }
            // Connect each checkpoint to all dependency nodes
            foreach (Checkpoint checkpoint in checkpoints)
            {
                foreach (Node node in checkpoint.Dependencies)
                {
                    Microsoft.Glee.Drawing.Edge edge = new Microsoft.Glee.Drawing.Edge(node.ID, null, checkpoint.ID);
                    if (critical.Contains(node) && critical.Contains(checkpoint))
                    {
                        edge.Attr.Color = Microsoft.Glee.Drawing.Color.Red;
                    }
                    graph.Edges.Add(edge);
                }
            }

            // Bind the graph to the viewer
            gViewer.Graph            = graph;
            gViewer.OutsideAreaBrush = Brushes.OldLace;
        }
Пример #8
0
        public FormGanttChart()
        {
            InitializeComponent();

            /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
             *                          GANTT CHART                                      *
             * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
            chart.ChartAreas[0].AxisY.IntervalType = DateTimeIntervalType.Days;
            //chart.ChartAreas[0].AxisY.Interval = 1;

            // Get each task start date and finish date
            HashSet<Node> Nodes = Program.formMain.GetNodes();
            int maxEmployees = 0;
            // While there are uncomlited tasks
            DateTime currentDate = Program.formMain.dateTimePicker.Value;
            for (; Nodes.Any(new Func<Node, bool>(delegate(Node node) { return node.Days > 0; })); currentDate = currentDate.AddDays(1))
            {
                // Start unstarted tasks that have all dependencies complited
                foreach (Node node in Nodes)
                    if (!node.HasStarted && node.Dependencies.All(new Func<Node, bool>(delegate(Node dependency) { return dependency.Days == 0; })))
                    {
                        node.HasStarted = true;
                        node.StartDate = currentDate;
                    }

                // Decrese days of uncomplited started tasks and finish them if current day was last
                if (Program.formMain.checkboxes[(int)currentDate.DayOfWeek].Checked)
                {
                    // Count of employees required at current day
                    int employ = 0;
                    foreach (Node node in Nodes)
                        if (node.HasStarted && node.Days > 0)
                        {
                            employ++;
                            if (--node.Days == 0)
                                node.FinishDate = currentDate;
                        }
                    // Check for loops
                    if (employ == 0) throw new Exception("Loop detected");
                    // Check if max emloyees required at current day
                    if (employ > maxEmployees) maxEmployees = employ;
                }
            }
            employees.Text = maxEmployees.ToString();
            deadline.Text = currentDate.ToLongDateString();
            period.Text = (currentDate - Program.formMain.dateTimePicker.Value).Days.ToString() + " days";

            // Set Y axis maximum an minimum dates
            chart.ChartAreas[0].AxisY.Minimum = Program.formMain.dateTimePicker.Value.AddDays(-1).ToOADate();
            chart.ChartAreas[0].AxisY.Maximum = currentDate.ToOADate();

            // Add DataPoints to chart
            for (int i = 0; i < Nodes.Count(); i++)
            {
                Node node = Nodes.ElementAt(i);
                chart.Series[0].Points.AddXY(i, node.StartDate, node.FinishDate.AddDays(1));
                chart.Series[0].Points[i].Label = chart.Series[0].Points[i].AxisLabel = node.ID;
                chart.Series[0].Points[i].ToolTip = node.StartDate.ToShortDateString() + " - " + node.FinishDate.ToShortDateString();
            }

            /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
             * Program Evaluation and Review Technique                                   *
             * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
            // Get union of all nodes dependencies
            List<Node> allDependencies = new List<Node>();
            // List of checkpoints
            List<Checkpoint> checkpoints = new List<Checkpoint>();
            for (int i = 0, m = 0; i < Nodes.Count; i++)
            {
                Node node = Nodes.ElementAt(i);
                allDependencies.AddRange(node.Dependencies);
                if (node.checkpoint == null)
                {
                    // Set checkpoint to node
                    Checkpoint checkpoint = new Checkpoint();
                    checkpoint.ID = (checkpoint.Dependencies = node.Dependencies).Count == 0 ? "Start" : Checkpoint.template + m++.ToString();
                    node.checkpoint = checkpoint;
                    // Check other nodes for same dependencies
                    for (int j = i + 1; j < Nodes.Count; j++)
                    {
                        Node otherNode = Nodes.ElementAt(j);
                        if (otherNode.Dependencies.SetEquals(node.Dependencies))
                            otherNode.checkpoint = checkpoint;
                    }
                    checkpoints.Add(checkpoint);
                }
            }

            // Create finish checkpoint
            Checkpoint finish = new Checkpoint();
            finish.ID = "Finish";
            finish.Dependencies = new HashSet<Node>(Nodes.Except(allDependencies));
            checkpoints.Add(finish);

            // Get critical way
            List<object> critical = new List<object>();
            critical.Add(finish);
            for (Checkpoint checkpoint = finish; checkpoint.Dependencies.Count > 0; )
            {
                DateTime latestDate = checkpoint.Dependencies.Max(new Func<Node, DateTime>(delegate(Node node) { return node.FinishDate; }));
                Node latestNode = checkpoint.Dependencies.First(new Func<Node, bool>(delegate(Node next) { return next.FinishDate == latestDate; }));
                critical.Add(checkpoint = latestNode.checkpoint);
                critical.Add(latestNode);
            }

            // Create graph
            Microsoft.Glee.Drawing.Graph graph = new Microsoft.Glee.Drawing.Graph("PERT");
            // Add nodes
            foreach (Node node in Nodes)
            {
                graph.AddNode(node.ID);
                graph.FindNode(node.ID).Attr.Fillcolor = Microsoft.Glee.Drawing.Color.Azure;
            }
            // Add checkpoints
            foreach (Checkpoint checkpoint in checkpoints)
            {
                graph.AddNode(checkpoint.ID);
                Microsoft.Glee.Drawing.Node graphNode = graph.FindNode(checkpoint.ID);
                graphNode.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.MistyRose;
                graphNode.Attr.Shape = Microsoft.Glee.Drawing.Shape.Diamond;
            }
            // Connect each node to its dependency checkpoint
            foreach (Node node in Nodes)
            {
                Microsoft.Glee.Drawing.Edge edge = new Microsoft.Glee.Drawing.Edge(node.checkpoint.ID, null, node.ID);
                if (critical.Contains(node))
                    edge.Attr.Color = Microsoft.Glee.Drawing.Color.Red;
                graph.Edges.Add(edge);
            }
            // Connect each checkpoint to all dependency nodes
            foreach (Checkpoint checkpoint in checkpoints)
                foreach (Node node in checkpoint.Dependencies)
                {
                    Microsoft.Glee.Drawing.Edge edge = new Microsoft.Glee.Drawing.Edge(node.ID, null, checkpoint.ID);
                    if (critical.Contains(node) && critical.Contains(checkpoint))
                        edge.Attr.Color = Microsoft.Glee.Drawing.Color.Red;
                    graph.Edges.Add(edge);
                }

            // Bind the graph to the viewer
            gViewer.Graph = graph;
            gViewer.OutsideAreaBrush = Brushes.OldLace;
        }
Пример #9
0
        private void draw_button_Click(object sender, EventArgs e)
        {
            ////////////////////////////////////////
            ///////////////////////////////////////
            for (int z = 0; z < gridorg.RowCount - 1; z++)
            {
                if (gridorg.Rows[z].Cells[2].Value == null)
                {
                    gridorg.Rows[z].Cells[2].Value = "";
                }
            }
            ///////////////////////////////////////
            for (int z = 0; z < gridorg.RowCount - 1; z++)
            {
                if (gridorg.Rows[z].Cells[1].Value == null)
                {
                    gridorg.Rows[z].Cells[1].Value = "";
                }
            }
            ///////////////////////////////////////
            for (int z = 0; z < gridorg.RowCount - 1; z++)
            {
                if (gridorg.Rows[z].Cells[0].Value == null)
                {
                    gridorg.Rows[z].Cells[0].Value = "";
                }
            }
            ///////////////////////////////////////
            int x = 0;

            Microsoft.Glee.Drawing.Graph graph = new Microsoft.Glee.Drawing.Graph("graph");
            ////////////////////////////////////////
            ///////////////////////////////////////
            for (int i = 0; i < gridorg.Rows.Count - 1; i++)
            {
                /* x = gridorg.Rows[i].Cells[0].Value.ToString();
                 * Console.WriteLine("{0}", x);
                 * graph.AddEdge("hellow","hello");*/
                if (gridorg.Rows[i].Cells[2].Value.ToString() == "")
                {
                    graph.AddNode(gridorg.Rows[i].Cells[0].Value.ToString() + "\n" + gridorg.Rows[i].Cells[1].Value.ToString());
                    graph.FindNode(gridorg.Rows[i].Cells[0].Value.ToString() + "\n" + gridorg.Rows[i].Cells[1].Value.ToString()).Attr.Shape     = Microsoft.Glee.Drawing.Shape.Ellipse;
                    graph.FindNode(gridorg.Rows[i].Cells[0].Value.ToString() + "\n" + gridorg.Rows[i].Cells[1].Value.ToString()).Attr.Fillcolor = Microsoft.Glee.Drawing.Color.AliceBlue;
                    graph.FindNode(gridorg.Rows[i].Cells[0].Value.ToString() + "\n" + gridorg.Rows[i].Cells[1].Value.ToString()).Attr.FontName  = "Tahoma";
                    continue;
                }
                for (int j = 0; j < gridorg.RowCount - 1; j++)//looks for the description of the rankabove
                {
                    if (gridorg.Rows[i].Cells[2].Value.ToString() == gridorg.Rows[j].Cells[0].Value.ToString())
                    {
                        x = j;
                    }
                }
                graph.AddEdge(gridorg.Rows[i].Cells[2].Value.ToString() + "\n" + gridorg.Rows[x].Cells[1].Value.ToString(), gridorg.Rows[i].Cells[0].Value.ToString() + "\n" + gridorg.Rows[i].Cells[1].Value.ToString()).Attr.Color = Microsoft.Glee.Drawing.Color.Black;
                graph.FindNode(gridorg.Rows[i].Cells[2].Value.ToString() + "\n" + gridorg.Rows[x].Cells[1].Value.ToString()).Attr.Shape     = Microsoft.Glee.Drawing.Shape.Box;
                graph.FindNode(gridorg.Rows[i].Cells[2].Value.ToString() + "\n" + gridorg.Rows[x].Cells[1].Value.ToString()).Attr.Color     = Microsoft.Glee.Drawing.Color.Black;
                graph.FindNode(gridorg.Rows[i].Cells[2].Value.ToString() + "\n" + gridorg.Rows[x].Cells[1].Value.ToString()).Attr.Fillcolor = Microsoft.Glee.Drawing.Color.AliceBlue;
                graph.FindNode(gridorg.Rows[i].Cells[0].Value.ToString() + "\n" + gridorg.Rows[i].Cells[1].Value.ToString()).Attr.Shape     = Microsoft.Glee.Drawing.Shape.Box;
                graph.FindNode(gridorg.Rows[i].Cells[0].Value.ToString() + "\n" + gridorg.Rows[i].Cells[1].Value.ToString()).Attr.Color     = Microsoft.Glee.Drawing.Color.Black;
                graph.FindNode(gridorg.Rows[i].Cells[0].Value.ToString() + "\n" + gridorg.Rows[i].Cells[1].Value.ToString()).Attr.Fillcolor = Microsoft.Glee.Drawing.Color.AliceBlue;
            }
            //graph.FindNode("Mohamed Bahaa" + "hello world");
            ////////////////////////////////////////
            ///////////////////////////////////////bind the graph to the viewer
            graph.GraphAttr.Orientation = Microsoft.Glee.Drawing.Orientation.Portrait;
            graph.GraphAttr.Border      = 2;

            graph.GraphAttr.AspectRatio = 1;

            graph.GraphAttr.NodeAttr.FontName = "Tahoma";
            graph.GraphAttr.NodeAttr.Fontsize = 5;
            graph.GraphAttr.NodeAttr.Shape    = Microsoft.Glee.Drawing.Shape.Box;

            graph.GraphAttr.EdgeAttr.FontName          = "Tahoma";
            graph.GraphAttr.EdgeAttr.Fontsize          = 50;
            graph.GraphAttr.EdgeAttr.Separation        = 1000;
            graph.GraphAttr.EdgeAttr.ArrowHeadAtTarget = Microsoft.Glee.Drawing.ArrowStyle.Tee;

            viewer.Graph = graph;

            //associate the viewer with the form
            form.SuspendLayout();
            viewer.Dock = System.Windows.Forms.DockStyle.Fill;
            //viewer.Size = new Size(1000, 1000);
            //viewer.MinimumSize = new Size(Screen.PrimaryScreen.Bounds.Height, Screen.PrimaryScreen.Bounds.Width);
            //viewer.AutoScroll = true;
            form.Controls.Add(viewer);

            form.ResumeLayout();
            //show the form
            form.ShowDialog();
        }