Example #1
0
 private void button4_Click(object sender, EventArgs e)
 {
     Nodes grafDecart1 = new Nodes(3, 3, true);
     graf1 = new Graph(grafDecart1);
     VisualGraph drawGraf = new VisualGraph(10, 10, panel1);
     drawGraf.paintGraf(graf1);
     if (graf2 != null && graf2 != null)
     {
         groupBox2.Enabled = true;
         checkBoxList();
     }
     else
     {
         groupBox2.Enabled = false;
     }
 }
Example #2
0
        /// <summary>
        /// генераци ребер графа 
        /// </summary>
        private void createGraf(Nodes grafDecard)
        {
            Random random = new Random();
            this.setSize(grafDecard.count());
            for (int y = 0; y < grafDecard.count(); y++)
            {
                List<Boolean> bufGrafMatrix = new List<Boolean>();
                for (int x = 0; x < grafDecard.count(); x++)
                {
                    Boolean hasLink = false;
                    int edgeGraf = random.Next(2);
                    if (edgeGraf == 1)
                    {
                        hasLink = true;
                    }

                    bufGrafMatrix.Add(hasLink);

                }
                graf.Add(bufGrafMatrix);
            }
            for (int y = 0; y < grafDecard.count(); y++)
            {
                for (int x = 0; x < grafDecard.count(); x++)
                {
                    if (!graf[x][y])
                    {
                        graf[x][y] = graf[y][x];
                    }
                }
            }
        }
Example #3
0
        public Graph setWith(Graph graf)
        {
            Graph graf1 = new Graph(graf.getGrafDecart().count());

            //заполняю координаты в пространстве
            Nodes grafDecart = new Nodes(graf.getGrafDecart().getSizeDecartGrafMatrixX(),
                                                   graf.getGrafDecart().getSizeDecartGrafMatrixY(), false);
            for (int y = 0; y < graf.getGrafDecart().getSizeDecartGrafMatrixY(); y++)
            {
                for (int x = 0; x < graf.getGrafDecart().getSizeDecartGrafMatrixX(); x++)
                {
                    grafDecart.setGrafMatrixDecart(x, y, graf.getGrafDecart().getElementDecartGraf(x, y));
                }
            }
            graf1.setGrafDecart(grafDecart);

            //заполняю грани в пространстве
            for (int y = 0; y < graf.getSize(); y++)
            {
                for (int x = 0; x < graf.getSize(); x++)
                {
                    graf1.setCoordinates(x, y, graf.getCoordinates(x, y));
                }
            }
            //заполняю размеры путей
            for (int y = 0; y < graf.getSize(); y++)
            {
                List<OptionsGraf> listbuf = new List<OptionsGraf>();
                for (int x = 0; x < graf.getSize(); x++)
                {
                    listbuf.Add(graf.grafSizeWay[x][y]);
                }
                graf1.grafSizeWay.Add(listbuf);
            }

            for (int y = 0; y < graf.getSize(); y++)
            {
                List<OptionsGraf> listbuf = new List<OptionsGraf>();
                for (int x = 0; x < graf.getSize(); x++)
                {
                    listbuf.Add(graf.resultSizeWay[x][y]);
                }
                graf1.resultSizeWay.Add(listbuf);
            }

            return graf1;
        }
Example #4
0
 public void setGrafDecart(Nodes grafDecart)
 {
     this.grafDecart = grafDecart;
 }
Example #5
0
 /// <summary>
 /// генерит связанный граф
 /// </summary>
 /// <param name="grafDecart"></param>
 /// <param name="countDot"></param>
 /// <param name="countEdge"></param>
 public Graph(Nodes grafDecart, int countDot, int countEdge)
 {
 }
Example #6
0
 /// <summary>
 /// получение количкство точек на декартовой поверхности от двух пространственных 
 /// </summary>
 /// <param name="grafDecart"></param>
 /// <returns></returns>
 public int getCountPoint(Nodes grafDecart)
 {
     int count = getGrafDecart().count();
     for (int y = 0; y < grafDecart.getSizeDecartGrafMatrixY(); y++)
     {
         for (int x = 0; x < grafDecart.getSizeDecartGrafMatrixX(); x++)
         {
             if (grafDecart.getElementDecartGraf(x, y) > 0)
             {
                 if (this.grafDecart.getSizeDecartGrafMatrixX() <= grafDecart.getSizeDecartGrafMatrixX() &&
                     this.grafDecart.getSizeDecartGrafMatrixY() <= grafDecart.getSizeDecartGrafMatrixY())
                 {
                     if (this.grafDecart.getElementDecartGraf(x, y) == 0)
                     {
                         count++;
                     }
                 }
             }
         }
     }
     return count;
 }
Example #7
0
 public Graph(Nodes grafDecart)
 {
     setGrafDecart(grafDecart);
     createGraf(getGrafDecart());
     createGrafSizeWay();
 }
Example #8
0
        //операция объединения
        public static Graph operator +(Graph graf1, Graph graf2)
        {
            Graph graf = graf1.getSize() > graf2.getSize()
                            ? new Graph(graf1.getCountPoint(graf2.getGrafDecart()))
                            : new Graph(graf2.getCountPoint(graf1.getGrafDecart()));

            //заполняю координаты в пространстве
            int grafDecartX = graf1.getGrafDecart().getSizeDecartGrafMatrixX() >
                              graf2.getGrafDecart().getSizeDecartGrafMatrixX()
                                  ? graf1.getGrafDecart().getSizeDecartGrafMatrixX()
                                  : graf2.getGrafDecart().getSizeDecartGrafMatrixX();
            int grafDecartY = graf1.getGrafDecart().getSizeDecartGrafMatrixY() >
                              graf2.getGrafDecart().getSizeDecartGrafMatrixY()
                                  ? graf1.getGrafDecart().getSizeDecartGrafMatrixY()
                                  : graf2.getGrafDecart().getSizeDecartGrafMatrixY();

            Nodes grafDecart = new Nodes(grafDecartX, grafDecartY, false);
            for (int y = 0; y < graf2.getGrafDecart().getSizeDecartGrafMatrixY(); y++)
            {
                for (int x = 0; x < graf2.getGrafDecart().getSizeDecartGrafMatrixX(); x++)
                {
                    grafDecart.setGrafMatrixDecart(x, y, graf2.getGrafDecart().getElementDecartGraf(x, y));
                }
            }

            for (int y = 0; y < graf1.getGrafDecart().getSizeDecartGrafMatrixY(); y++)
            {
                for (int x = 0; x < graf1.getGrafDecart().getSizeDecartGrafMatrixX(); x++)
                {
                    if (grafDecart.getElementDecartGraf(x, y) == 0)
                    {
                        grafDecart.setGrafMatrixDecart(x, y,
                                                       graf1.getGrafDecart().getElementDecartGraf(x, y) > 0
                                                           ? grafDecart.findLastDot() + 1
                                                           : 0);
                    }

                }
            }
            graf.setGrafDecart(grafDecart);

            //заполняю грани в пространстве
            for (int y = 0; y < graf2.getSize(); y++)
            {
                for (int x = 0; x < graf2.getSize(); x++)
                {
                    if (graf2.getCoordinates(x, y))
                    {
                        graf.setCoordinates(x, y, true);
                    }
                }
            }

            for (int y = 0; y < graf1.getGraf().Count; y++)
            {
                for (int x = 0; x < graf1.getGraf().Count; x++)
                {
                    if (graf1.getCoordinates(x, y))
                    {
                        graf.setCoordinates(
                            graf.getGrafDecart().getElementDecartGraf(
                                graf1.getCoordinatePoint(x).getStartCoordinate().getX(),
                                graf1.getCoordinatePoint(x).getStartCoordinate().getY()) - 1,
                            graf.getGrafDecart().getElementDecartGraf(
                                graf1.getCoordinatePoint(y).getStartCoordinate().getX(),
                                graf1.getCoordinatePoint(y).getStartCoordinate().getY()) - 1, true);

                    }
                }
            }

            return graf;
        }