Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

max flow tp

a guest Sep 25th, 2018 76 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. d=[
  2. 0, 3, 0, 0, 11, 0, 3, 0, 0, 0, 0, 7, 0, 0,
  3. 0, 0, 3, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
  4. 0, 0, 0, 3, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0,
  5. 0, 0, 0, 0, 0, 0, 1, 3, 0, 0, 0, 0, 0, 0,
  6. 0, 0, 0, 0, 0, 5, 0, 0, 7, 0, 0, 0, 0, 0,
  7. 0, 0, 0, 0, 5, 0, 0, 0, 5, 0, 0, 0, 0, 0,
  8. 0, 0, 0, 0, 0, 0, 0, 5, 0, 7, 5, 0, 0, 0,
  9. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0,
  10. 0, 0, 0, 0, 0, 0, 7, 0, 0, 11, 0, 0, 0, 0,
  11. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7,
  12. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  13. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  16. ];
  17.  
  18. T=[
  19. 0, 3, 0, 0, 3, 0, 1, 0, 0, 0, 0, 22, 0, 0, %1
  20. 0, 0, 5, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
  21. 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0,
  22. 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0,
  23. 0, 0, 0, 0, 0, 5, 0, 0, 3, 0, 0, 0, 0, 0, %5
  24. 0, 0, 0, 0, 5, 0, 0, 0,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, 0, 0, 0, 0, 0, 0, 0, 0
  50. ];
  51.  
  52. a=[7, 7, 7];
  53.  
  54. M=10^10;
  55. [n, m] = size(d);
  56. nm=n*m;
  57. Aeq = zeros(n, n*m);
  58.  
  59. for i = 1:n
  60.     for j = 1:m
  61.         if d(i, j) > 0
  62.             Aeq(i, (i - 1)*n + j) = 1;
  63.         end
  64.     end
  65.     for k = 1:n
  66.          if d(k, i) > 0
  67.             if (i <= n - size(a))
  68.                 Aeq(i, (k - 1)*n + i) = -1;
  69.             else
  70.                 Aeq(i, (k - 1)*n + i) = 1;
  71.             end
  72.          end
  73.     end
  74. end
  75. Aeq=[Aeq,zeros(n,nm)];
  76.  
  77. A=[eye(nm),-eye(nm)*M];
  78.  
  79. f=[reshape(C',1,[]),reshape(T',1,[])];
  80. %ub=[ones(1,nm)*inf,ones(1,nm)];
  81. ub=[reshape(d',1,[]),ones(1,nm)];
  82. lb=zeros(1,max(size(f)));
  83. b=zeros(1,nm);
  84. beq=[sum(a),zeros(1,n-1-max(size(a))),a];
  85. intcon=nm+1:max(size(f));
  86.  
  87. [x,~,eflag] = intlinprog(f,intcon,A,b,Aeq,beq,lb,ub);
  88.  
  89. x1=x(1:nm,:);
  90. res1 = round(reshape(x(1:nm,:), n, []));
  91. g = digraph;
  92.  
  93. for i = 1:n
  94.     for j = 1:m
  95.         if not(res1(i,j) == 0 )
  96.             g = addedge(g, j, i, res1(i,j));
  97.         end
  98.     end
  99. end
  100.  
  101. h = plot(g,'Layout','layered','EdgeLabel',g.Edges.Weight,'LineWidth', 4,'ArrowSize', 10, 'MarkerSize', 14, 'LineStyle', ':', 'Marker','s')
  102. hs = struct(h);   %and ignore the warning message
  103. for nhl = hs.NodeLabelHandles_
  104.   nhl.Font.Size = 23;
  105. end
  106. for nhl = hs.EdgeLabelHandles_
  107.   nhl.Font.Size = 16;
  108. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top