Exemple #1
0
    public void generate_random(int vertices, int edges)
    {
        this.size = vertices;

        this.mv = new MatrixVertex[vertices];
        for (int i = 0; i < vertices; i++)
        {
            mv[i]        = new MatrixVertex();
            mv[i].number = i;
            mv[i].graph  = this;
        }



        this.adj_matrix = new bool[vertices][];
        for (int i = 0; i < vertices; i++)
        {
            this.adj_matrix[i] = new bool[vertices];
        }

        for (int i = 0; i < vertices; i++)
        {
            for (int j = 0; j < vertices; j++)
            {
                this.adj_matrix[i][j] = false;
            }
        }

        Random rnd = new Random();

        for (int i = 0; i < edges; i++)
        {
            int x_coeff = rnd.Next(0, vertices);
            int y_coeff = rnd.Next(0, vertices);

            this.adj_matrix[x_coeff][y_coeff] = true;
            this.adj_matrix[y_coeff][x_coeff] = true;
        }
    }
Exemple #2
0
 void set_neighbour(MatrixVertex vert)
 {
     graph.adj_matrix[vert.number][this.number] = true;
     graph.adj_matrix[this.number][vert.number] = true;
 }
 private void AddConnection(MatrixVertex <int[][]> vertex, int value = 0)
 {
     vertex.Data[vertex.Index.Item1][vertex.Index.Item2] = value;
 }