Advertisement
Guest User

vova_nata2

a guest
Sep 21st, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.38 KB | None | 0 0
  1. A1=[
  2.     2, 3, 4, 1, 7;
  3.     3, 2, 5, 8, 10;
  4.     2, 2, 1, 10, 2;
  5.     3, 3, 4, 3, 1;
  6.     2, 1, 9, 8, 9;
  7.     0, 10, 20, 1, 1;
  8.     2, 1, 5, 3, 7
  9.     ];
  10. b1=[100, 100, 103, 67, 89, 98, 39];
  11. B=[1, 1, 5];
  12. p=[1, 2, 30, 1, 10 ];
  13. C=[
  14.     2, 3, 2;
  15.     1, 4, 2;
  16.     2, 5, 1;
  17.     0.9, 1, 2;
  18.     1, 1, 4
  19.     ];
  20.  
  21. [m, n]=size(A1);
  22. [cm, cn]=size(C);
  23.  
  24. %inequalities
  25. A=[A1,zeros(m,cm*cn)];
  26. %inequalities end
  27.  
  28. %equalities
  29. Aeq_1=[];
  30. for i=1:cm
  31.    Aeq_1=[Aeq_1,eye(cn)];
  32. end
  33. Aeq_1=[zeros(cn, n),Aeq_1];
  34.  
  35. Aeq_2=[];
  36. k=1;
  37. for i=1:cm*cn
  38.     Aeq_2(k,i)=1;
  39.    if mod(i,cn)==0
  40.       k=k+1;
  41.    end
  42. end
  43. Aeq_2=[-eye(n),Aeq_2];
  44.  
  45. Aeq=[Aeq_1;Aeq_2];
  46. %equalities
  47.  
  48. f=[p,reshape(C',1,[])];
  49. ub=ones(1,max(size(f)))*inf;
  50. lb=zeros(1,max(size(f)));
  51. b=b1;
  52. beq=[B,zeros(1,n)];
  53. intcon=1:max(size(f));
  54.  
  55. [x,~,eflag] = intlinprog(f,intcon,A,b,Aeq,beq,lb,ub);
  56.  
  57. x1=x(n+1:end,:);
  58. a=x(1:n,:);
  59. res1 = reshape(x(n+1:end,:), cn, []);
  60. %res1=C';
  61. g = digraph;
  62.  
  63. for i = 1:cn
  64.     for j = 1:cm
  65.         if not(res1(i,j) == 0 )
  66.             g = addedge(g, i, j+cn, res1(i,j));
  67.         end
  68.     end
  69. end
  70.  
  71. h = plot(g,'Layout','layered','EdgeLabel',g.Edges.Weight,'LineWidth', 4,'ArrowSize', 10, 'MarkerSize', 14, 'LineStyle', ':', 'Marker','s')
  72. hs = struct(h);   %and ignore the warning message
  73. for nhl = hs.NodeLabelHandles_
  74.   nhl.Font.Size = 25;
  75. end
  76. for nhl = hs.EdgeLabelHandles_
  77.   nhl.Font.Size = 18;
  78. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement