It would be great if someone could point me towards an algorithm that would allow me to :
- create a random square matrix, with entries 0 and 1, such that
- every row and every column contain exactly two non-zero entries,
- two non-zero entries cannot be adjacent,
- 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