public void UpdateRows()
        {
            int stepX = 160;

            int stepY = 80;

            int numberLastKey = adjacencyList.adjacencyList.Count - 1;

            Cells.Add(new List <CellAdjacencyList>());

            InfoTextLabel startId = new InfoTextLabel(40, 20, -adListPanel.HorizontalScroll.Value,
                                                      20 + numberLastKey * stepY - adListPanel.VerticalScroll.Value, Convert.ToString(numberLastKey) + ": ");

            adListPanel.Controls.Add(startId);

            for (int j = 0; j < adjacencyList.adjacencyList[numberLastKey].Count; ++j)
            {
                int id = adjacencyList.adjacencyList[numberLastKey][j].Connectable;

                int weight = adjacencyList.adjacencyList[numberLastKey][j].Weight;

                Cells[numberLastKey].Add(new CellAdjacencyList(id, weight, 40 + stepX * j - adListPanel.HorizontalScroll.Value
                                                               , stepY * numberLastKey - adListPanel.VerticalScroll.Value));

                adListPanel.Controls.Add(Cells[numberLastKey][j]);
            }
        }
        public AdjacencyListTable(GraphRepresentation.AdjacencyList adjacencyList, AdjacencyListPanel adListPanel)
        {
            this.adjacencyList = adjacencyList;

            this.adListPanel = adListPanel;

            Cells = new List <List <CellAdjacencyList> >();

            int stepX = 160;

            int stepY = 80;

            for (int i = 0; i < adjacencyList.adjacencyList.Count; ++i)
            {
                Cells.Add(new List <CellAdjacencyList>());

                InfoTextLabel startId = new InfoTextLabel(40, 20, adListPanel.HorizontalScroll.Value, 20 + i * stepY, Convert.ToString(i) + ": ");

                adListPanel.Controls.Add(startId);

                for (int j = 0; j < adjacencyList.adjacencyList[i].Count; ++j)
                {
                    int id = adjacencyList.adjacencyList[i][j].Connectable;

                    int weight = adjacencyList.adjacencyList[i][j].Weight;

                    Cells[i].Add(new CellAdjacencyList(id, weight, 40 + stepX * j, stepY * i));

                    adListPanel.Controls.Add(Cells[i][j]);
                }
            }
        }
        public CellAdjacencyList(int id, int weight, int positionX, int positionY)
        {
            this.id = id;

            int x = 10;

            int y = 20;

            int widthText = 60;

            int heightText = 20;

            int widthBox = 60;

            int heightBox = heightText;

            text = new InfoTextLabel(widthText, heightText, x, y, $"id: {id}; w: ");

            WeightBox = new CellBox(widthBox, heightBox, x + widthText, y, weight);

            Controls.Add(WeightBox);

            Controls.Add(text);

            Size = new System.Drawing.Size(2 * x + widthText + widthBox, 2 * y + heightText);

            Location = new System.Drawing.Point(positionX, positionY);
        }
Exemple #4
0
        public FindPathButton(int width, int height, int positionX, int positionY
                              , GraphRepresentation.AdjacencyList adList, List <EdgeDraw> edgeDraws
                              , InputCountBox startVertex, InputCountBox endVertex
                              , StartForm.DrawForm drawForm, InfoTextLabel infoText)
        {
            Size = new System.Drawing.Size(width, height);

            Location = new System.Drawing.Point(positionX, positionY);

            Text = "Find path";

            Click += new EventHandler(ButtonClick);

            this.adList = adList;

            this.edgeDraws = edgeDraws;

            this.startVertex = startVertex;

            this.endVertex = endVertex;

            this.drawForm = drawForm;

            this.infoText = infoText;

            path = null;
        }
        public ShortestPathPanel(int width, int height, int positionX, int positionY
                                 , GraphRepresentation.AdjacencyList adList, List <EdgeDraw> edgeDraws
                                 , StartForm.DrawForm drawForm)
        {
            Size = new System.Drawing.Size(width, height);

            Location = new System.Drawing.Point(positionX, positionY);

            BorderStyle = BorderStyle.Fixed3D;

            Anchor = (AnchorStyles.Top | AnchorStyles.Left);

            Visible = false;

            this.adList = adList;

            this.edgeDraws = edgeDraws;

            infoText = new InfoTextLabel(180, 20, 10, 20, "Path: ");

            Controls.Add(infoText);

            startVertexText = new InfoTextLabel(65, 20, 0, 60, "From:");

            Controls.Add(startVertexText);

            endVertexText = new InfoTextLabel(45, 20, Size.Width - 100, 60, "To:");

            Controls.Add(endVertexText);

            startVertex = new InputCountBox(20, 20, 65, 60);

            Controls.Add(startVertex);

            endVertex = new InputCountBox(20, 20, Size.Width - 55, 60);

            Controls.Add(endVertex);

            findPathButton = new FindPathButton(95, 30, Size.Width / 2 - 45, Size.Height - 60, adList, edgeDraws
                                                , startVertex, endVertex, drawForm, infoText);

            Controls.Add(findPathButton);
        }
Exemple #6
0
        private void DrawPath(int start, int end, InfoTextLabel infoText)
        {
            WeightedGraph weightedGraph = new WeightedGraph(adList);

            path = weightedGraph.FindShortestPath(start, end);

            if (SumWeightPath(path) == 0)
            {
                infoText.Text = "Path: is not exist";
            }
            else
            {
                infoText.Text += Convert.ToString(SumWeightPath(path));
            }

            ChangeColorEdges(BrushColor.Yellow);

            drawForm.Refresh();
        }