SHARE
TWEET

Untitled

a guest May 6th, 2019 98 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. clc
  2. clear
  3. printf("------------task_1----------\n")
  4. c=[4.5 4.5 4.5 5.9 5.9 5.9 2.3 2.3 2.3 5.9 5.9 5.9]';
  5. A=[1 0 1 1 0 1 0 0 0 0 0 0;
  6.    0 0 0 0 0 0 1 0 1 1 0 1;
  7.    0 1 0 0 1 0 0 0 0 0 0 0;
  8.    0 0 0 0 0 0 0 1 0 0 1 0;
  9.    1 0 0 0 0 0 1 0 0 0 0 0;
  10.    0 0 0 1 0 0 0 0 0 1 0 0;
  11.    0 1 0.7 0 0 0 0 1 0.7 0 0 0;
  12.    0 0 0 0 1 0.7 0 0 0 0 1 0.7;
  13.    1 1 0.7 0 0 0 1 1 0.7 0 0 0;
  14.    0 0 0 1 1 0.7 0 0 0 1 1 0.7];
  15. b=[3800 2700 4600 6000 3000 1100 3200 5500 6500 8200]';
  16. [x_min,z_min,ec,extra]=glpk(c,A,b,zeros(12,1),[],"UUUULLLLSS","CCCCCCCCCCCC",1)
  17.  
  18. printf("------------task_2----------\n")
  19. db=[5 5 -5 -5 0 0 0 0 0 0]';
  20. i=1;
  21. while(1)
  22.   i=i+1;
  23.   B=b+i*db;
  24.   [x_min,z_min]=glpk(c,A,B,zeros(12,1),[],"UUUULLLLSS","CCCCCCCCCCCC",1);
  25.   if((x_min(3)>=100) || (x_min(6)>=100) || (x_min(9)>=100) || (x_min(12)>=100))
  26.     printf("%d %d %d %d Optimal solution\n",B(1),B(2),B(3),B(4))
  27.     [x_min,z_min,ec,extra]=glpk(c,A,B,zeros(12,1),[],"UUUULLLLSS","CCCCCCCCCCCC",1)
  28.     break
  29.   else
  30.     printf("%d %d %d %d No changes\n",B(1),B(2),B(3),B(4))
  31.   endif  
  32. endwhile
  33.  
  34. printf("------------task_3----------\n")
  35. b_task_3=[20000 20000 20000 20000 3000 1100 3200 5500 6500 8200]';
  36. [x_min_task_3,z_min_task_3]=glpk(c,A,b_task_3,zeros(12,1),[],"UUUULLLLSS","CCCCCCCCCCCC",1)
  37.  
  38. dc=[0 0.1 0 0 0.1 0 0 0.1 0 0 0.1 0]';
  39. j=1;
  40. while(1)
  41.   j=j+1;
  42.   C=c+j*dc;
  43.   [x_min_task_3,z_min_task_3]=glpk(C,A,b_task_3,zeros(12,1),[],"UUUULLLLSS","CCCCCCCCCCCC",1);
  44.   if((x_min_task_3(3)>=100) || (x_min_task_3(6)>=100) || (x_min_task_3(9)>=100) || (x_min_task_3(12)>=100))
  45.     printf("%d %d %d %d Optimal solution\n",C(2),C(5),C(8),C(11))
  46.     [x_min_task_3,z_min_task_3]=glpk(C,A,b_task_3,zeros(12,1),[],"UUUULLLLSS","CCCCCCCCCCCC",1)
  47.     break
  48.   else
  49.     printf("%d %d %d %d No changes\n",C(2),C(5),C(8),C(11))
  50.   endif  
  51. endwhile
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