How to construct (0,1)-matrices with prescribed row and column sum vectors
Show older comments
- All matrix elements are either 1 or 0.
- Both row sum vector and column sum vector are given.
- Return a 3-dimensional result that stacks all possible solutions along the third dimension. (exhaustive, all possible solutions need to be included.)
- Avoid looping at best due to performance, use matrix operations whenever possible.
- Thank you so much for your assistance :)
6 Comments
John D'Errico
on 15 Sep 2020
Edited: John D'Errico
on 15 Sep 2020
You do understand the total number of solutions will likely be immense? And therefore, the result of this operation will be highly memory intensive? The computation of all such solutions will likely take more work than solving whatever it is that you want to solve in the first place.
The thing is, almost always when someone asks for a brute force solution like this, where ALL possible solutions are listed, this is the wrong approach. Instead, you should learn to use optimization tools to solve what you want to use this to solve.
Yingao Zhang
on 15 Sep 2020
Edited: Yingao Zhang
on 15 Sep 2020
Ameer Hamza
on 15 Sep 2020
What are the sizes of the row sum and column sum vectors? Is brute-force even feasible considering all the possible combination will be 2^(numel(row_sum)*numel(col_sum)). Unless there is a pattern with the selection matrix, I guess you will have to be contented with a sub-optimal solution using some heuristic-based algorithm.
Yingao Zhang
on 15 Sep 2020
Edited: Yingao Zhang
on 15 Sep 2020
Ameer Hamza
on 16 Sep 2020
Edited: Ameer Hamza
on 16 Sep 2020
If rows represent objects, then does that mean that row sum for all values is 1? And the column sum should add up to the number of objects. For example, if there are 200 objects and 20 destinations, then do you have
row_sum = ones(200, 1);
col_sum = % [1x20] matrix where sum(col_sum)=200
Is this correct?
Yingao Zhang
on 16 Sep 2020
Edited: Yingao Zhang
on 16 Sep 2020
Accepted Answer
More Answers (0)
Categories
Find more on Function Creation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!