public void AddNode(NodeD vertices)
        {
            LinkedList <DEdge> neighbor = new LinkedList <DEdge>();

            AdjList.Add(vertices, neighbor);
            Size = 1 + Size;
        }
        public JsonResult PostAdjustment(AdjList savdlist)
        {
            List <Info> aa = JsonConvert.DeserializeObject <List <Info> >(savdlist.Infos[0]);

            StockAdjustmentVoucher stockAdjustmentVoucher = new StockAdjustmentVoucher();

            stockAdjustmentVoucher.AdjustmentVoucherNumber = (db.StockAdjustmentVouchers.Count() + 1).ToString();
            stockAdjustmentVoucher.Status  = "Pending";
            stockAdjustmentVoucher.Date    = DateTime.Today;
            stockAdjustmentVoucher.Remarks = "Store clerk";
            int num = db.StockAdjustmentVoucherDetails.Count();

            db.StockAdjustmentVouchers.Add(stockAdjustmentVoucher);
            db.SaveChanges();

            for (int i = 0; i < aa.Count; i++)
            {
                int hh = num + 1 + i;
                StockAdjustmentVoucherDetail savd = new StockAdjustmentVoucherDetail
                {
                    AdjustmentDetailsNumber = hh,
                    AdjustmentVoucherNumber = stockAdjustmentVoucher.AdjustmentVoucherNumber,
                    ItemNumber       = aa[i].ItemNumber,
                    QuantityAdjusted = Convert.ToInt32(aa[i].QuantityAdjusted),
                    Reason           = aa[i].Reason
                };
                db.StockAdjustmentVoucherDetails.Add(savd);
                db.SaveChanges();
            }

            return(Json(new { status = "Submited Successfully" }));
        }
        public List <DEdge> GetNeighbors(NodeD vertex)
        {
            LinkedList <DEdge> neighbor = new LinkedList <DEdge>();

            AdjList.TryGetValue(vertex, out neighbor);
            return(neighbor.ToList());
        }
        public List <object> BreadthFirst(NodeD root)
        {
            List <object> order   = new List <object>();
            Hashtable     table   = new Hashtable();
            Queue <NodeD> breadth = new Queue <NodeD>();

            breadth.Enqueue(root);

            while (breadth.TryPeek(out root))
            {
                NodeD front = breadth.Dequeue();

                LinkedList <DEdge> neighbor = new LinkedList <DEdge>();
                AdjList.TryGetValue(front, out neighbor);
                foreach (DEdge child in neighbor)
                {
                    if (!table.ContainsKey(child))
                    {
                        table.Add(front.Value, front.Value);
                        breadth.Enqueue(front);
                        order.Add(front);
                    }
                }
            }
            return(order);
        }
        private void Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e)
        {
            if (this.IsLoaded)
            {
                Slider slider = (Slider)sender;

                lblVertexCount.Content = (int)slider.Value;

                ResetLines();
                adjMat  = new AdjMatrix((int)slider.Value);
                incMat  = new IncidenceMatrix((int)slider.Value);
                adjList = new AdjList((int)vertsSlider.Value);

                if (vertsUI.Count == 0)
                {
                    return;
                }

                for (int i = 0; i < (int)slider.Value; i++)
                {
                    vertsUI[i].Visibility = Visibility.Visible;
                }
                for (int i = (int)slider.Value; i < vertsUI.Count; i++)
                {
                    vertsUI[i].Visibility = Visibility.Hidden;
                }
            }
        }
        public AdjListWindow()
        {
            InitializeComponent();

            AdjList adjList = MainWindow.adjList;

            for (int i = 0; i < adjList.noOfVertices; i++)
            {
                Label tempLabel = new Label();
                tempLabel.Content = "v" + (i + 1) + " ->";
                tempLabel.Margin  = new Thickness(10, ((i + 1) * HEIGHTDIFF) + 10, 0, 0);

                matGrid.Children.Add(tempLabel);
            }

            for (int i = 0; i < adjList.noOfVertices; i++)
            {
                for (int j = 0; j < adjList.adjacencyList[i].Count; j++)
                {
                    Label tempLabel = new Label();
                    tempLabel.Content = "v" + (adjList.adjacencyList[i][j] + 1) + " ->";
                    tempLabel.Margin  = new Thickness(((j + 1) * WIDTHDIFF) + 10, ((i + 1) * HEIGHTDIFF) + 10, 0, 0);

                    matGrid.Children.Add(tempLabel);
                }
            }
        }
Example #7
0
        public void AddEdge(int vertex, int weight)
        {
            if (AdjList.ContainsKey(vertex))
            {
                AdjList[vertex].Add(weight);
            }
            else
            {
                var list = new List <int>
                {
                    weight
                };
                AdjList.Add(vertex, list);
            }

            if (AdjList.ContainsKey(weight))
            {
                AdjList[weight].Add(vertex);
            }
            else
            {
                var list = new List <int>
                {
                    vertex
                };
                AdjList.Add(weight, list);
            }
        }
Example #8
0
 public Graph(int cnt)
 {
     count = cnt;
     array = new AdjList[cnt];
     for (int i = 0; i < cnt; i++)
     {
         array[i]      = new AdjList();
         array[i].head = null;
     }
 }
Example #9
0
 public Graph(int count)
 {
     size  = count;
     glist = new AdjList[6];
     for (int i = 0; i < count; i++)
     {
         glist[i]      = new AdjList();
         glist[i].head = null;
     }
 }
Example #10
0
    public static void Dijkstra(Graph gph, int source)
    {
        int[] previous = new int[gph.count];
        int[] dist     = new int[gph.count];

        for (int i = 0; i < gph.count; i++)
        {
            previous[i] = -1;
            dist[i]     = int.MaxValue;         //infinite
        }

        dist[source]     = 0;
        previous[source] = -1;

        PriorityQueue <AdjNode> queue = new PriorityQueue <AdjNode>();

        AdjNode node = new AdjNode(source, source, 0);

        queue.Enqueue(node);

        while (queue.Count != 0)
        {
            node = queue.Peek();
            queue.Dequeue();

            AdjList adl = gph.array[node.destination];
            AdjNode adn = adl.head;
            while (adn != null)
            {
                int alt = adn.cost + dist[adn.source];
                if (alt < dist[adn.destination])
                {
                    dist[adn.destination]     = alt;
                    previous[adn.destination] = adn.source;
                    node = new AdjNode(adn.source, adn.destination, alt);
                    queue.Enqueue(node);
                }
                adn = adn.next;
            }
        }

        int count = gph.count;

        for (int i = 0; i < count; i++)
        {
            if (dist[i] == int.MaxValue)
            {
                Console.WriteLine(" node id " + i + "  prev " + previous[i] + " distance : Unreachable");
            }
            else
            {
                Console.WriteLine(" node id " + i + "  prev " + previous[i] + " distance : " + dist[i]);
            }
        }
    }
 public void AddEdge(NodeD start, NodeD end, int weight)
 {
     if (AdjList.ContainsKey(start) && AdjList.ContainsKey(end))
     {
         LinkedList <DEdge> neighbor = new LinkedList <DEdge>();
         AdjList.TryGetValue(start, out neighbor);
         DEdge edge = new DEdge(start, end, weight);
         neighbor.AddFirst(edge);
         AdjList[start] = neighbor;
     }
     else
     {
         throw null;
     }
 }
        public MainWindow()
        {
            InitializeComponent();

            adjMat  = new AdjMatrix((int)vertsSlider.Value);
            incMat  = new IncidenceMatrix((int)vertsSlider.Value);
            adjList = new AdjList((int)vertsSlider.Value);

            vertsUI.Add(v1);
            vertsUI.Add(v2);
            vertsUI.Add(v3);
            vertsUI.Add(v4);
            vertsUI.Add(v5);
            vertsUI.Add(v6);
            vertsUI.Add(v7);
            vertsUI.Add(v8);
            vertsUI.Add(v9);
            vertsUI.Add(v10);
        }
        public void Convert(int n, int m, bool isDirected, Type expectedType)
        {
            AdjList net = new AdjList(Guid.NewGuid(), isDirected);
            AdjListRandomGenerator rgg = new AdjListRandomGenerator();
            rgg.NodeCount = n;
            rgg.EdgeCount = m;
            rgg.AllowSelfLoops = true;
            rgg.AllowMultiEdges = false;
            rgg.IsDirected = isDirected;
            rgg.Generate(net);

            INetwork mtrx = _Converter.Convert(net);

            Assert.IsNotNull(mtrx, "Resulting matrix should not be null");
            Assert.IsInstanceOfType(expectedType, mtrx, "Matrix type should match expected type");
            Assert.AreEqual(net.IsDirected, mtrx.IsDirected, "Directedness should match");
            Assert.AreEqual(net.NodeCount, mtrx.NodeCount, "NodeCount should match");
            Assert.AreEqual(net.EdgeCount, mtrx.EdgeCount, "EdgeCount should match");
        }
        private void adjListMenuItem_Click(object sender, RoutedEventArgs e)
        {
            Tuple <int, int> tuple = CommonOperations1();

            if (tuple == null)
            {
                IsEnabled = true; return;
            }
            GViewer gViewerReference = tuple.Item1 == 0 ? viewer_1 : viewer_2;
            int     size             = tuple.Item2;

            AdjList            adjacencyList = new AdjList(size);
            List <List <int> > list          = adjacencyList.ReturnAdjList();

            if (list == null)
            {
                IsEnabled = true; return;
            }

            CommonOperations2(tuple.Item1, list);
        }
Example #15
0
    public void AddEdge(int source, int dest)
    {
        AdjListNode node = new AdjListNode {
            Destination = dest
        };

        if (arr[source] == null)
        {
            arr[source] = new AdjList {
                Head = node
            };
        }
        else
        {
            node.Next        = arr[source].Head;
            arr[source].Head = node;
        }

        //undirected graph so add edge from destination to source also

        AdjListNode newNode = new AdjListNode {
            Destination = source
        };

        if (arr[dest] == null)
        {
            arr[dest] = new AdjList {
                Head = newNode
            };
        }
        else
        {
            newNode.Next   = arr[dest].Head;
            arr[dest].Head = newNode;
        }
    }
Example #16
0
        public static INetworkAdjList GenerateAdjList(Guid id, int n, int m, bool directed, bool allowSelfLoops, bool allowCycles, bool allowMultiEdges)
        {
            AdjList net = new AdjList(id, directed);
            AdjListRandomGenerator rgg = new AdjListRandomGenerator();
            rgg.NodeCount = n;
            rgg.EdgeCount = m;
            rgg.AllowCycles = allowCycles;
            rgg.AllowSelfLoops = allowSelfLoops;
            rgg.AllowMultiEdges = allowMultiEdges;
            rgg.IsDirected = directed;
            rgg.Generate(net);
            net.Name = string.Copy(Name);

            return net;
        }
Example #17
0
 public Vertex(T content)
 {
     Content = content;
     Edges   = new AdjList();
 }
        public void ConvertToMatrix_VerifyEdges(int n, int m, bool isDirected, NetworkObjectImplementation imp, Type expectedType)
        {
            AdjList net = new AdjList(Guid.NewGuid(), isDirected);
            AdjListRandomGenerator rgg = new AdjListRandomGenerator();
            rgg.NodeCount = n;
            rgg.EdgeCount = m;
            rgg.AllowSelfLoops = true;
            rgg.AllowMultiEdges = false;
            rgg.Generate(net);

            INetworkMatrix mtrx = _Converter.ConvertToMatrix(net, imp);

            INode srcNode = null;
            INode destNode = null;
            int i=0;
            int j=0;
            double val = 0.0;

            foreach (IEdge edge in net.EdgeEnumerator)
            {
                srcNode = edge.SourceNode;
                destNode = edge.DestinationNode;
                i = srcNode.Index;
                j = destNode.Index;
                val = mtrx[i, j];
                Assert.AreNotEqual(0.0, val, string.Format("Entry [{0},{1}] should not be 0.0 for an edge.", i,j));
            }
        }
Example #19
0
    public static void Prims(Graph gph)
    {
        int[] previous = new int[gph.count];
        int[] dist     = new int[gph.count];
        int   source   = 1;

        for (int i = 0; i < gph.count; i++)
        {
            previous[i] = -1;
            dist[i]     = int.MaxValue;
        }

        dist[source]     = 0;
        previous[source] = -1;

        PriorityQueue <AdjNode> queue = new PriorityQueue <AdjNode>();
        AdjNode node = new AdjNode(source, source, 0);

        queue.Enqueue(node);

        while (queue.Count != 0)
        {
            node = queue.Peek();
            queue.Dequeue();

            if (dist[node.destination] < node.cost)
            {
                continue;
            }

            dist[node.destination]     = node.cost;
            previous[node.destination] = node.source;

            AdjList adl = gph.array[node.destination];
            AdjNode adn = adl.head;

            while (adn != null)
            {
                if (previous[adn.destination] == -1)
                {
                    node = new AdjNode(adn.source, adn.destination, adn.cost);
                    queue.Enqueue(node);
                }
                adn = adn.next;
            }
        }

        // Printing result.
        int count = gph.count;

        for (int i = 0; i < count; i++)
        {
            if (dist[i] == int.MaxValue)
            {
                Console.WriteLine(" node id " + i + "  prev " + previous[i] + " distance : Unreachable");
            }
            else
            {
                Console.WriteLine(" node id " + i + "  prev " + previous[i] + " distance : " + dist[i]);
            }
        }
    }