Advertisement
Guest User

Untitled

a guest
Oct 27th, 2018
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.55 KB | None | 0 0
  1. L=[100, 100, 100, 100];
  2. bl = [40;60;70;100];
  3. A1 =[1,2,6,2;
  4.     2,6,9,4;
  5.     5,7,1,5;
  6.     4,8,9,8];
  7. [A1_n, A1_m]=size(A1);
  8. price=[4,9,10.5,6.5];
  9. Q=3;
  10. [L_n, L_m]=size(L);
  11. f=[1, 2, 3, 4];
  12. [f_n, f_m]=size(f);
  13. c=[
  14. 7, 8, 7, 8, 7, 8, 7;
  15. 8, 5, 8, 3, 8, 2, 5;
  16. 2, 7, 6, 7, 4, 3, 6;
  17. 7, 0, 5, 2, 5, 5, 5];
  18. a=[1,2,5,1,2,2,3
  19.     ];
  20. M=10^10;
  21.  
  22. %stock problem
  23. ub=ones(1,f_m);
  24. lb=ub-1;
  25. Aeq=ones(1,f_m);
  26. beq=Q;
  27. [x, fval, exitflag,lambda]=intlinprog(f,1:f_m,[],[],Aeq,beq,lb,ub);
  28. %end
  29.  
  30. %manufacturing problem
  31. A=[A1;eye(f_m)];
  32. b=[bl;x*M];
  33. ub=ones(1,f_m)*inf;
  34. lb=zeros(1,f_m);
  35. [x1, fval, exitflag,lambda]=intlinprog(-price,1:f_m,A,b,[],[],lb,ub);
  36. %end
  37.  
  38. %TP
  39. [n m]=size(c);
  40. k=n*m;
  41. %Формирование матрицы ограничений
  42. %по строкам
  43. mrow=[];
  44. for i=1:m
  45. mrow=[mrow eye(n)];
  46. end
  47. %по столбцам
  48. mcol=[];
  49. j=0;
  50. for i=1:m
  51. j=j+1;
  52. v=zeros(m,n);
  53. v(j,:)=1;
  54. mcol=[mcol v];
  55. end
  56. [x2, fval, exitflag,output,lambda]=linprog(c(:)',[],[],[mrow;mcol],[x1;a'],zeros(k,1));
  57. res=reshape(x2,n,m);
  58. g = digraph;
  59.  
  60. for i = 1:n
  61.     for j = 1:m
  62.         if not(res(i,j) == 0 )
  63.             g = addedge(g, i, j+n, res(i,j));
  64.         end
  65.     end
  66. end
  67.  
  68. h = plot(g,'Layout','layered','EdgeLabel',g.Edges.Weight,'LineWidth', 4,'ArrowSize', 8, 'MarkerSize', 14, 'LineStyle', ':', 'Marker','s')
  69. hs = struct(h);   %and ignore the warning message
  70. for nhl = hs.NodeLabelHandles_
  71.   nhl.Font.Size = 25;
  72. end
  73. for nhl = hs.EdgeLabelHandles_
  74.   nhl.Font.Size = 20;
  75. end
  76. %end
  77. zapas=bl-A1*x1
  78. TPcost=x2'*c(:)
  79. TR=price*x1
  80. Profit=TR-TPcost
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement