Esempio n. 1
0
 public bool TraverseGraph(WGraphNode root, int weight, WGraphNode destination)
 {
     if (root.isVisited)
     {
         return(false);
     }
     return(false);
 }
Esempio n. 2
0
        public WeightedGraph CreateDummyGraph()
        {
            WeightedGraph graph = new WeightedGraph();

            graph.vertices = 4;
            graph.edges    = new List <WGraphEdge>();
            WGraphNode a = new WGraphNode();

            a.data = 1;
            WGraphNode b = new WGraphNode();

            b.data = 1;
            WGraphNode c = new WGraphNode();

            c.data = 1;
            WGraphNode d = new WGraphNode();

            d.data = 1;

            WGraphEdge edge = new WGraphEdge();

            edge.source      = a;
            edge.destination = b;
            edge.weight      = 10;
            graph.edges.Add(edge);

            edge             = new WGraphEdge();
            edge.source      = a;
            edge.destination = c;
            edge.weight      = 5;
            graph.edges.Add(edge);

            edge             = new WGraphEdge();
            edge.source      = a;
            edge.destination = d;
            edge.weight      = 6;
            graph.edges.Add(edge);

            edge             = new WGraphEdge();
            edge.source      = b;
            edge.destination = c;
            edge.weight      = 15;
            graph.edges.Add(edge);

            edge             = new WGraphEdge();
            edge.source      = c;
            edge.destination = d;
            edge.weight      = 4;
            graph.edges.Add(edge);

            return(graph);
        }
Esempio n. 3
0
        private void btnAddEdge_Click(object sender, EventArgs e)
        {
            try
            {
                int[] input = SearchForm.ConvertToIntArray(txtConnectVertices.Text.Trim().Split(','));
                nodes = nodes ?? new List <WGraphNode>();
                WGraphNode source = FindNode(input[0]);
                if (source == null)
                {
                    source      = new WGraphNode();
                    source.data = input[0];
                    nodes.Add(source);
                }

                WGraphNode destination = FindNode(input[1]);
                if (destination == null)
                {
                    destination      = new WGraphNode();
                    destination.data = input[1];
                    nodes.Add(destination);
                }

                WGraphEdge edge = new WGraphEdge();
                edge.source      = source;
                edge.destination = destination;
                edge.weight      = Convert.ToInt32(txtWeight.Text);
                if (source.edges == null)
                {
                    source.edges = new List <WGraphEdge>();
                }
                source.edges.Add(edge);
                txtOperation.Text = "Operation Add Edge Successful";
            }
            catch (Exception ex)
            {
                MessageBox.Show("btnAddEdge_Click: " + ex.Message);
            }
        }
Esempio n. 4
0
        public int FindLongestPath(WGraphNode root, int inputWeight)
        {
            if (root.isVisited)
            {
                return(0);
            }
            int distance  = 0;
            int maxWeight = 0;

            if (root.edges == null)
            {
                return(0);
            }

            foreach (WGraphEdge edge in root.edges)
            {
                distance += FindLongestPath(edge.destination, inputWeight);
                distance += edge.weight;
                maxWeight = Math.Max(maxWeight, inputWeight + distance);
                distance  = 0;
            }

            return(maxWeight);
        }