Advertisement
makispaiktis

Course 8 - Radiation Therapy Optimization

Aug 30th, 2023
1,365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.38 KB | None | 0 0
  1. clear all
  2. close all
  3. clc
  4.  
  5. % 1. Basics
  6. prob = optimproblem("Description","Radiation Therapy Optimization")
  7. I = optimvar("I",8,"LowerBound",0)
  8.  
  9. % 2. Objective - Linear
  10. d = [10 7 3 8 8 5 9 10];
  11. D = d * I
  12. prob.Objective = D;
  13.  
  14. % 3. Spinal constraint (1 inequality)
  15. A = zeros(1, 8);
  16. A(3) = 2;       A(7) = 2;           % 2I3 + 2I7 <= 5
  17. ineq1 = A * I <= 5;
  18. prob.Constraints.spinal = ineq1;
  19.  
  20. % 4. Tumor constraints (4 inequalities)
  21. ineqA = 3*I(2) + 3*I(6) >= 7;
  22. ineqB = 3*I(3) + 2*I(6) >= 7;
  23. ineqC = 4*I(3) + 2*I(5) >= 7;
  24. ineqD = 2*I(4) + 1*I(7) >= 7;
  25. prob.Constraints.A = ineqA;
  26. prob.Constraints.B = ineqB;
  27. prob.Constraints.C = ineqC;
  28. prob.Constraints.D = ineqD;
  29.  
  30.  
  31. % 5. OSlve the problem: it is linear (both objective and contraints) ---> no initial guess is needed
  32. sol = solve(prob);
  33. bar(sol.I);
  34.  
  35. % 6. Calculations
  36. check = A * sol.I
  37.  
  38. % 7. Visualization
  39. verticalBeamTable = [4 4 4 4; 3 3 3 3; 2 2 2 2; 1 1 1 1];
  40. horizontalBeamTable = [4 3 2 1; 4 3 2 1; 4 3 2 1; 4 3 2 1];
  41. verticalIntensity = [0 2.33 0 0];
  42. horizontalIntensity = [0 0 1.75 3.5];
  43.  
  44. horizontalDose = horizontalBeamTable .* horizontalIntensity';
  45. verticalDose = verticalBeamTable .* verticalIntensity;
  46. Doses = horizontalDose + verticalDose;
  47.  
  48. imagesc(Doses)
  49. hold on
  50. plot([.5 .5 1.5 1.5 2.5 2.5 3.5 3.5 2.5 2.5 0.5],...
  51.  [3.5 2.5 2.5 1.5 1.5 3.5 3.5 4.5 4.5 3.5 3.5], 'r-', "LineWidth",2)
  52. hold off
  53. colorbar
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement