How i can create array with fixed sum for each row and column?

조회 수: 1 (최근 30일)
reshdev
reshdev 2014년 8월 19일
댓글: Image Analyst 2014년 8월 21일
Hello Everyone,
Please help me to write matlab code, I am trying to create 5*5 matrix containing random values having constraints....... (1) sum of elements of row 1(X1) = sum of elements of column 1 (X1) (Sum = X1<= 7)............. (2) sum of elements of row 2 =7 and sum of elements of column 2 = 0 .......... (3) sum of elements of row 3(X3) = sum elements of column 3(X3) (Sum X3 <= 7)............ (4) sum of elements of row 4 =0 and sum of elements of column 4 = 7 ................ (5) sum of elements of row 5(X5) = sum elements of column 5(X5) (X5<= 7)........
Rows act as sources nodes. columns act as destination nodes.
Actually, this matrix represents a transshipment problem which is sending 7 units of data from (starting node 2) to (termination node 4).above constraints show that data going into node 2 from all nodes is zero and going out to all nodes is 7 units. Similarly, data going into destination node 4 is 7 units and nothing comes out from this. Whereas for all the other nodes, total amount of data coming in = total amount of data coming out.
all the diagonal elements should be zero. like (1,1)...(2,2).....(5,5) and range for all elements of matrix = 0 to 7
This is what i am able to do so far....
no_sourcenode = input ('ENTER THE NUMBER OF source NODE :');
no_destiantion = input ('ENTER THE NUMBER OF destination node :');
chromosome = round(rand(no_sourcenode,no_destiantion));
chromosomes(1:(no_sourcenode+1):no_sourcenode*no_destiantion)= 0; (to make diagonal elements zero)
Thank you very much

채택된 답변

Image Analyst
Image Analyst 2014년 8월 19일
Looks like something Roger can answer better than me. In the meantime, see his randfixedsum utility: http://www.mathworks.com/matlabcentral/fileexchange/9700-random-vectors-with-fixed-sum
  댓글 수: 2
Image Analyst
Image Analyst 2014년 8월 21일
You're welcome. Can you officiall "Accept" the answer if it answered your question?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Genetic Algorithm에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by