lundi 30 octobre 2017

An algorithm for creating a random matrix with non-adjacent non-zero entries (with some extra requirements)

It would be great if someone could point me towards an algorithm that would allow me to :

  1. create a random square matrix, with entries 0 and 1, such that
  2. every row and every column contain exactly two non-zero entries,
  3. two non-zero entries cannot be adjacent,
  4. all possible matrices are equiprobable.

Right now I manage to achieve points 1 and 2 doing the following : such a matrix can be transformed, using suitable permutations of rows and columns, into a diagonal block matrix with blocks of the form

1 1 0 0 ... 0
0 1 1 0 ... 0
0 0 1 1 ... 0
.............
1 0 0 0 ... 1

So I start from such a matrix using a partition of [0, ..., n-1] and scramble it by permuting rows and columns randomly. Unfortunately, I can't find a way to integrate the adjacency condition, and I am quite sure that my algorithm won't treat all the matrices equally.




Aucun commentaire:

Enregistrer un commentaire