Джава - Java

Узнай цену своей работы

Формулировка задачи:

Помогите въехать в код и напишите пожалуйста комментарии к коду Вот само задание: 1.выполнить по тактовую визуализацию системы обслуживания заявок с распределенным ресурсом, параметрами системы является диапазон весов заявок, диапазон интервалов возникновения следующей заявки (интенсивность входящего потока), диапазон приоритетов (для приоритетных дисциплин обслуживания). В систему может поступать любое количество заявок. 2. Если система обслуживания с очередями, то количество очередей не больше 32. Если система обслуживания с приоритетами, то число приоритетов не более 32. 3. Построить графики зависимости среднего времени ожидания от интенсивности входящего потока заявок и зависимость процента простой ресурса от интенсивности входящего потока заявок. 4. Для приоритетных систем построить график зависимости среднего времени ожидания от приоритета при фиксированной интенсивности входящего потока заявок. Вот код программы:
Листинг программы
  1. public class Request {
  2. private int weight;
  3. private int priority;
  4. private int processed;
  5. private int inTime;
  6. private int outTime;
  7. public Request(int weight, int priority, int inTime) {
  8. this.weight = weight;
  9. this.priority = priority;
  10. this.inTime = inTime;
  11. processed=0;
  12. }
  13. public int getWeight() {
  14. return weight;
  15. }
  16. public int getPriority() {
  17. return priority;
  18. }
  19. public void incProcessed() {
  20. processed++;
  21. }
  22. public int getProcessed() {
  23. return processed;
  24. }
  25. public void setInTime(int inTime) {
  26. this.inTime = inTime;
  27. }
  28. public void setOutTime(int outTime) {
  29. this.outTime = outTime;
  30. }
  31. public int getInTime() {
  32. return inTime;
  33. }
  34. public int getOutTime() {
  35. return outTime;
  36. }
  37. }
  38. public class Queue {
  39. private int n;
  40. private Request[] queue;
  41. private int defaultPriority;
  42. public Queue(int defaultPriority, int n) {
  43. this.defaultPriority=defaultPriority;
  44. this.n=n;
  45. queue = new Request[n];
  46. }
  47. public void addRequest(Request request) {
  48. int i=n;
  49. do {
  50. i--;
  51. }
  52. while ((i>0)&(queue[i]!=null));
  53. if ((i==0)&(queue[i]!=null)) {
  54. ExtendQueue(2*n);
  55. i=n/2-1;
  56. }
  57. queue[i]=request;
  58. }
  59. public String getQueue() {
  60. String res = "";
  61. for (int i=n-1;i>=0;i--) {
  62. if (queue[i]!=null) {
  63. res=res+queue[i].getProcessed()+"/"+queue[i].getWeight()+ " ";
  64. }
  65. }
  66. return res;
  67. }
  68. public boolean isEmpty() {
  69. if (queue[n-1]==null) {
  70. return true;
  71. }
  72. else
  73. return false;
  74. }
  75. public Request ExtractRequest() {
  76. Request request;
  77. request=queue[n-1];
  78. for (int i=n-2;i>=0; i--) {
  79. queue[i+1]=queue[i];
  80. }
  81. queue[0]=null;
  82. return request;
  83. }
  84. public void ExtendQueue(int n) {
  85. Request[] newQueue = new Request[n];
  86. for (int i=this.n-1; i>=0;i--) {
  87. newQueue[i+n-this.n]=queue[i];
  88. }
  89. queue=newQueue;
  90. this.n=n;
  91. }
  92. }
  93. public class QueueBlock {
  94. private Queue[] queueBlock;
  95. private int number;
  96. private int minPriority;
  97. public QueueBlock(int n, int minPriority) {
  98. number = n+1;
  99. this.minPriority = minPriority;
  100. queueBlock = new Queue[number];
  101. BlockInitialization();
  102. }
  103. private void BlockInitialization() {
  104. for (int i=0;i<number;i++) {
  105. queueBlock[i] = new Queue(i+minPriority,1);
  106. }
  107. }
  108. public void addRequestWithFilter(Request request) {
  109. queueBlock[request.getPriority()-minPriority].addRequest(request);
  110. }
  111. public void addRequestDirectly(Request request, int queueNumber) {
  112. queueBlock[queueNumber].addRequest(request);
  113. }
  114. public String getBlock() {
  115. String res = "";
  116. for (int i=0;i<number;i++) {
  117. res=res+("Приоритет: "+(i+minPriority)+" | ");
  118. res=res+queueBlock[i].getQueue()+"\n";
  119. }
  120. return res;
  121. }
  122. public Request ExtractMaxPriorityRequest() {
  123. int i = -1;
  124. do {
  125. i++;
  126. }
  127. while ((i<number-1)&(queueBlock[i].isEmpty()));
  128. if (queueBlock[number-1]!=null) {
  129. if (i!=number-1)
  130. return queueBlock[i].ExtractRequest();
  131. else
  132. return queueBlock[number-1].ExtractRequest();
  133. }
  134. else
  135. return null;
  136. }
  137. public int getMinPriority() {
  138. return minPriority;
  139. }
  140. public int getQueueNumber() {
  141. return number;
  142. }
  143.  
  144. }
  145. public class Resource {
  146. private Request currentRequest;
  147. private int processingTime;
  148. private int quant;
  149. private int idleTime = 0;
  150. private boolean occupied = false;
  151. private QueueBlock queue;
  152. private int counter = 0;
  153. private Form form;
  154. private int[] priorities;
  155. private short[] number;
  156. public Resource(Form form, QueueBlock queue, int quant) {
  157. this.form = form;
  158. this.queue = queue;
  159. this.quant = quant;
  160. priorities = new int[queue.getMinPriority()+queue.getQueueNumber()+1];
  161. number = new short[queue.getMinPriority()+queue.getQueueNumber()+1];
  162. for (int i=0;i<priorities.length;i++) {
  163. priorities[i]=0;
  164. number[i] = 0;
  165. }
  166. }
  167. public void setRequest(Request request) {
  168. currentRequest = request;
  169. processingTime = 0;
  170. if (request!=null) {
  171. occupied = true;
  172. }
  173. else
  174. occupied = false;
  175. }
  176. public void processOneTact() {
  177. if (occupied) {
  178. currentRequest.incProcessed();
  179. processingTime++;
  180. if (currentRequest.getProcessed()>=currentRequest.getWeight()) {
  181. currentRequest.setOutTime(form.getTime());
  182. form.addWaitingTime(currentRequest.getOutTime()-currentRequest.getInTime()-currentRequest.getWeight());
  183. int waitingTime=(form.getTime()-currentRequest.getInTime()-currentRequest.getWeight());
  184. priorities[currentRequest.getPriority()]+=waitingTime;
  185. number[currentRequest.getPriority()]++;
  186. setRequest(queue.ExtractMaxPriorityRequest());
  187. form.setRequestsNumber(form.getRequestsNumber()-1);
  188. counter++;
  189. }
  190. if (processingTime>=quant) {
  191. queue.addRequestDirectly(currentRequest, currentRequest.getPriority()-queue.getMinPriority());
  192. setRequest(queue.ExtractMaxPriorityRequest());
  193. }
  194. }
  195. else {
  196. idleTime++;
  197. setRequest(queue.ExtractMaxPriorityRequest());
  198. }
  199. }
  200. public Request getCurrentRequest() {
  201. return currentRequest;
  202. }
  203. public int getQuant() {
  204. return quant;
  205. }
  206. public int getProcessingTime() {
  207. return processingTime;
  208. }
  209. public int getIdleTime() {
  210. return idleTime;
  211. }
  212. public void setIdleTime(int time) {
  213. idleTime = time;
  214. }
  215. public int getProcessedNumber() {
  216. return counter;
  217. }
  218. public void setQueue(QueueBlock queue) {
  219. this.queue=queue;
  220. }
  221. public int[] getPriorityArray() {
  222. return priorities;
  223. }
  224. public short[] getProcessedNumberWithPriorities() {
  225. return number;
  226. }
  227. }
  228. import java.awt.Color;
  229. import java.awt.Graphics;
  230. import javax.swing.*;
  231. public class Graph extends JFrame{
  232. protected short[] value;
  233. protected Form form;
  234. protected String x,y;
  235. public Graph(Form form, short[] value, String x, String y) {
  236. super("График");
  237. this.form=form;
  238. setSize(510, 600);
  239. setDefaultCloseOperation(DISPOSE_ON_CLOSE);
  240. setResizable(false);
  241. this.value = value;
  242. this.x=x;
  243. this.y=y;
  244. setVisible(true);
  245. }
  246. public void paint(Graphics g) {
  247. g.setColor(Color.BLACK);
  248. DrawAxises(g);
  249. g.drawOval(50, 580-value[1]*2,1,1);
  250. if ((580-value[1]*2)<30) {
  251. g.drawString(String.valueOf(value[1]),70,60);
  252. }
  253. g.drawString(String.valueOf(value[1]),60,580-value[1]*2);
  254. for (int i=form.getIMin()+1; i<=form.getIMax(); i++) {
  255. g.setColor(Color.BLACK);
  256. if ((value[i]!=32767)) {
  257. g.drawOval(40+i*10, 580-value[i]*2, 1, 1);
  258. }
  259. g.setColor(Color.RED);
  260. if (value[i-1]!=32767) {
  261. g.drawLine(40+(i-1)*10, 580-value[i-1]*2, 40+(i)*10, 580-value[i]*2);
  262. }
  263. }
  264. }
  265. public void DrawAxises(Graphics g) {
  266. g.drawString(y,10,40);
  267. g.drawString(x,410,593);
  268. g.drawLine(40, 40, 40, 580);
  269. g.drawLine(40, 580, 480, 580);
  270. for (int i=0; i<27;i++) {
  271. g.drawString(String.valueOf(i*10),15,580-i*20);
  272. g.drawLine(38,580-i*20,42,580-i*20);
  273. }
  274. for (int i=0; i<9; i++) {
  275. g.drawString(String.valueOf(i*4),40+i*40,593);
  276. g.drawLine(40+i*40, 582, 40+i*40, 578);
  277. }
  278. for (int i=9; i<12;i++) {
  279. g.drawString(String.valueOf(i*4),40+i*40, 578);
  280. g.drawLine(40+i*40, 582, 40+i*40, 578);
  281. }
  282. }
  283. }
  284. import java.awt.Color;
  285. import java.awt.Graphics;
  286.  
  287. public class Graph2 extends Graph {
  288. public Graph2(Form form,short[] value, String x, String y) {
  289. super(form,value,x,y);
  290. setSize(510,300);
  291. }
  292. public void paint(Graphics g) {
  293. g.setColor(Color.BLACK);
  294. DrawAxises(g);
  295. g.drawOval(50, 280-value[1]*2,1,1);
  296. g.drawString(String.valueOf(value[form.getIMax()-1]),40+(form.getIMax()-1)*10,280-value[form.getIMax()-1]*2);
  297. for (int i=form.getIMin()+1; i<form.getIMax(); i++) {
  298. g.setColor(Color.BLACK);
  299. g.drawOval(40+i*10, 280-value[i]*2, 1, 1);
  300. g.setColor(Color.RED);
  301. g.drawLine(40+(i-1)*10, 280-value[i-1]*2, 40+(i)*10, 280-value[i]*2);
  302. }
  303. }
  304. public void DrawAxises(Graphics g) {
  305. g.drawString(y,10,40);
  306. g.drawString(x,410,293);
  307. g.drawLine(40, 40, 40, 280);
  308. g.drawLine(40, 280, 480, 280);
  309. for (int i=0; i<11;i++) {
  310. g.drawString(String.valueOf(i*10),15,280-i*20);
  311. g.drawLine(38,280-i*20,42,280-i*20);
  312. }
  313. for (int i=0; i<9; i++) {
  314. g.drawString(String.valueOf(i*4),40+i*40,293);
  315. g.drawLine(40+i*40, 282, 40+i*40, 278);
  316. }
  317. for (int i=9; i<12;i++) {
  318. g.drawString(String.valueOf(i*4),40+i*40, 278);
  319. g.drawLine(40+i*40, 282, 40+i*40, 278);
  320. }
  321. }
  322. }
import java.awt.Color; import java.awt.Graphics; import javax.swing.JFrame;

Решение задачи: «Джава»

textual
Листинг программы
  1. import java.awt.Color;
  2. import java.awt.Graphics;
  3. import javax.swing.JFrame;
  4.  
  5. public class Graph3 extends JFrame {
  6.     protected int value[];
  7.     protected Form form;
  8.     protected String x,y;
  9.     public Graph3(Form form, int[] value, String x, String y) {
  10.         super("График зависимости ср. времени ожидания от приоритета заявок");
  11.         this.form=form;
  12.         this.x=x;
  13.         this.y=y;
  14.         this.value=value;
  15.         setSize(700, 610);
  16.         setVisible(true);
  17.     }
  18.      public void paint(Graphics g) {
  19.             g.setColor(Color.BLACK);
  20.             DrawAxises(g);
  21.             g.drawOval(40+form.getPrMin()*20, 580-value[form.getPrMin()],1,1);
  22.             g.drawString(String.valueOf(value[form.getPrMin()]),38+20, 578-value[form.getPrMin()]);
  23.             for (int i=form.getPrMin()+1; i<=form.getPrMax(); i++) {
  24.                 g.setColor(Color.BLACK);
  25.                 g.drawOval(40+i*20, 580-value[i], 1, 1);
  26.                 g.setColor(Color.RED);
  27.                 g.drawLine(40+(i-1)*20, 580-value[i-1], 40+(i)*20, 580-value[i]);
  28.                 g.setColor(Color.BLACK);
  29.                 g.drawString(String.valueOf(value[i]),38+i*20, 578-value[i]);
  30.             }
  31.      }
  32.      public void DrawAxises(Graphics g) {
  33.             g.drawString(y,10,40);
  34.             g.drawString(x,610,593);
  35.             g.drawLine(40, 40, 40, 580);
  36.             g.drawLine(40, 580, 680, 580);
  37.             for (int i=0; i<27;i++) {
  38.                 g.drawString(String.valueOf(i*20),15,580-i*20);
  39.                 g.drawLine(38,580-i*20,42,580-i*20);
  40.             }
  41.             for (int i=0; i<13; i++) {
  42.                 g.drawString(String.valueOf(2*i),40+i*40,593);
  43.                 g.drawLine(40+i*40, 582, 40+i*40, 578);
  44.             }
  45.            
  46.             for (int i=13; i<16;i++) {
  47.                 g.drawString(String.valueOf(2*i),40+i*40, 578);
  48.                 g.drawLine(40+i*40, 582, 40+i*40, 578);
  49.             }
  50.            
  51.         }
  52. }
  53. import java.awt.Color;
  54. import java.awt.event.ActionEvent;
  55. import java.awt.event.ActionListener;
  56.  
  57. import javax.swing.*;
  58. import javax.swing.border.LineBorder;
  59. public class Form extends JFrame {
  60.     private JLabel iminLabel = new JLabel("Мин. t поступления: ");
  61.     private JLabel imaxLabel = new JLabel("Макс. t поступления: ");
  62.     private JTextField imin = new JTextField(5);
  63.     private JTextField imax = new JTextField(5);
  64.     private JLabel wminLabel = new JLabel("Мин. вес: ");
  65.     private JLabel wmaxLabel = new JLabel("Макс. вес: ");
  66.     private JTextField wmin = new JTextField(5);
  67.     private JTextField wmax = new JTextField(5);
  68.     private JLabel prminLabel = new JLabel("Мин. приоритет: ");
  69.     private JLabel prmaxLabel = new JLabel("Макс. приоритет: ");
  70.     private JTextField prmin = new JTextField(5);
  71.     private JTextField prmax = new JTextField(5);
  72.     private JPanel iPanel = new JPanel();
  73.     private JPanel wPanel = new JPanel();
  74.     private JPanel prPanel = new JPanel();
  75.     private JPanel fieldsPanel = new JPanel();
  76.     private JPanel buttonsPanel = new JPanel();
  77.     private JPanel textPanel = new JPanel();
  78.     private JTextArea area = new JTextArea(20,50);
  79.     private JScrollPane scroll = new JScrollPane(area);
  80.     private JButton tact = new JButton("Выполнить такт");
  81.     private JButton graph1 = new JButton("График Тож(I)");
  82.     private JButton graph2 = new JButton("График idle(I)");
  83.     private JButton graph3 = new JButton("График Тож(Pr)");
  84.     private JButton graphs = new JButton("Построение графиков");
  85.     private JButton init = new JButton("Задать значения");
  86.     private JTextField quant = new JTextField(5);
  87.     private JLabel quantLabel = new JLabel("Квант времени: ");
  88.     private JPanel quantPanel = new JPanel();
  89.     private JButton values = new JButton("Задать новые значения");
  90.     private JLabel nLabel = new JLabel("Кол-во тактов: ");
  91.     private JTextField nField = new JTextField(5);
  92. //------------------------------------------------------------------//
  93.     private int iminValue;
  94.     private int imaxValue;
  95.     private int wminValue;
  96.     private int wmaxValue;
  97.     private int prminValue;
  98.     private int prmaxValue;
  99.     private int time = 0;
  100.     private int waitingTime;
  101.     private int quantValue;
  102.     private int waitingTime_all=0;
  103.     private int requestsNum = 0;
  104.     private QueueBlock queue;
  105.     private Resource resource;
  106.    
  107.    
  108.    
  109.     public Form() {
  110.         super("Lab3");
  111.         setSize(600,500);
  112.         setDefaultCloseOperation(EXIT_ON_CLOSE);
  113.         Interface();
  114.         setVisible(true);
  115.         init.addActionListener(new ActionListener(){
  116.             public void actionPerformed(ActionEvent e) {
  117.                 Init();
  118.                 setFieldsEditable(false);
  119.                 init.setVisible(false);
  120.                 tact.setVisible(true);
  121.                 graphs.setVisible(true);
  122.                 values.setVisible(true);
  123.             }
  124.         });
  125.        
  126.         tact.addActionListener(new ActionListener(){
  127.             public void actionPerformed(ActionEvent e) {
  128.                 ExecuteOneTact(queue, resource);
  129.                 Visualisation(queue, resource);
  130.             }
  131.         });
  132.         values.addActionListener(new ActionListener(){
  133.             public void actionPerformed(ActionEvent e) {
  134.                 values.setVisible(false);
  135.                 setFieldsEditable(true);
  136.                 graph1.setVisible(false);
  137.                 graph2.setVisible(false);
  138.                 graph3.setVisible(false);
  139.                 graphs.setVisible(false);
  140.                 tact.setVisible(false);
  141.                 init.setVisible(true);
  142.             }
  143.         });
  144.         graphs.addActionListener(new ActionListener(){
  145.             public void actionPerformed(ActionEvent e) {
  146.                 tact.setVisible(false);
  147.                 nField.setEditable(true);
  148.                 graphs.setVisible(false);
  149.                 graph1.setVisible(true);
  150.                 graph2.setVisible(true);
  151.                 graph3.setVisible(true);
  152.                 values.setVisible(true);
  153.             }
  154.         });
  155.         graph1.addActionListener(new ActionListener(){
  156.             public void actionPerformed(ActionEvent e) {
  157.                 int min = iminValue;
  158.                 int max = imaxValue;
  159.                 short[] array = new short[imaxValue+iminValue+1];
  160.                 for (int i=1;i<=max;i++) {
  161.                     imaxValue=i;
  162.                     iminValue=i;
  163.                     QueueBlock testBlock = new QueueBlock(prmaxValue-prminValue,prminValue);
  164.                     resource.setQueue(testBlock);
  165.                     resource.setRequest(null);
  166.                     for (short j=0;j<Integer.parseInt(nField.getText());j++) {
  167.                         ExecuteOneTact(testBlock, resource);
  168.                     }
  169.                     array[iminValue]=(short)(waitingTime_all/resource.getProcessedNumber());
  170.                     waitingTime_all=0;
  171.                    
  172.                 }
  173.                 iminValue=min;
  174.                 imaxValue=max;
  175.                 resource.setQueue(queue);
  176.                 Init();
  177.                 new Graph(Form.this, array, "Тпоступления","Tожидания");
  178.             }
  179.  
  180.            
  181.         });
  182.         graph2.addActionListener(new ActionListener(){
  183.             public void actionPerformed(ActionEvent e) {
  184.                 int min = iminValue;
  185.                 int max = imaxValue;
  186.                 short[] array = new short[imaxValue+iminValue+1];
  187.                 for (int i=1;i<max;i++) {
  188.                     imaxValue=i;
  189.                     iminValue=i;
  190.                     QueueBlock testBlock = new QueueBlock(prmaxValue-prminValue,prminValue);
  191.                     resource.setQueue(testBlock);
  192.                     resource.setRequest(null);
  193.                     for (short j=0;j<Integer.parseInt(nField.getText());j++) {
  194.                         ExecuteOneTact(testBlock, resource);
  195.                     }
  196.                     array[iminValue]=(short)(((float)resource.getIdleTime()/time)*100);
  197.                     time=0;
  198.                     resource.setIdleTime(0);
  199.                    
  200.                 }
  201.                 iminValue=min;
  202.                 imaxValue=max;
  203.                 resource.setQueue(queue);
  204.                 Init();
  205.                 new Graph2(Form.this, array, "Тпоступления","% простоя");
  206.             }
  207.            
  208.         });
  209.         graph3.addActionListener(new ActionListener(){
  210.             public void actionPerformed(ActionEvent e) {
  211.                 Init();
  212.                 QueueBlock testBlock = new QueueBlock(prmaxValue-prminValue,prminValue);
  213.                 resource.setQueue(testBlock);
  214.                 resource.setRequest(null);
  215.            
  216.                 for (short j=0;j<Integer.parseInt(nField.getText());j++) {
  217.                      ExecuteOneTact(testBlock, resource );
  218.                 }
  219.                 int[] array = resource.getPriorityArray();
  220.                 short[] numbers = resource.getProcessedNumberWithPriorities();
  221.                 Request r;
  222.                 while ((r = testBlock.ExtractMaxPriorityRequest())!=null) {
  223.                     numbers[r.getPriority()]++;
  224.                     array[r.getPriority()]+=getTime()-r.getInTime()-r.getProcessed();
  225.                 }
  226.                 for (int i=1;i<array.length; i++) {
  227.                    
  228.                     if (numbers[i]!=0) {
  229.                         array[i]/=numbers[i];
  230.                     }
  231.                 }
  232.                 resource.setQueue(queue);
  233.                 new Graph3(Form.this, array, "Приоритет","Тожидания");
  234.                
  235.             }
  236.         });
  237.     }
  238.    
  239.     public void Interface() {
  240.         getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
  241.         getContentPane().add(fieldsPanel);
  242.         getContentPane().add(buttonsPanel);
  243.         getContentPane().add(textPanel);
  244.         fieldsPanel.setBorder(new LineBorder(Color.BLACK));
  245.         fieldsPanel.add(iPanel);
  246.         fieldsPanel.add(wPanel);
  247.         fieldsPanel.add(prPanel);
  248.         fieldsPanel.add(quantPanel);
  249.         iPanel.setLayout(new BoxLayout(iPanel, BoxLayout.Y_AXIS));
  250.         wPanel.setLayout(new BoxLayout(wPanel, BoxLayout.Y_AXIS));
  251.         prPanel.setLayout(new BoxLayout(prPanel, BoxLayout.Y_AXIS));
  252.         quantPanel.setLayout(new BoxLayout(quantPanel, BoxLayout.Y_AXIS));
  253.         iPanel.add(iminLabel);
  254.         iPanel.add(imin);
  255.         iPanel.add(imaxLabel);
  256.         iPanel.add(imax);
  257.         wPanel.add(wminLabel);
  258.         wPanel.add(wmin);
  259.         wPanel.add(wmaxLabel);
  260.         wPanel.add(wmax);
  261.         prPanel.add(prminLabel);
  262.         prPanel.add(prmin);
  263.         prPanel.add(prmaxLabel);
  264.         prPanel.add(prmax);
  265.         quantPanel.add(quantLabel);
  266.         quantPanel.add(quant);
  267.         quantPanel.add(nLabel);
  268.         quantPanel.add(nField);
  269.         nField.setText("30000");
  270.         nField.setEditable(false);
  271.         buttonsPanel.setBorder(new LineBorder(Color.BLUE));
  272.         buttonsPanel.add(init);
  273.         tact.setVisible(false);
  274.         graphs.setVisible(false);
  275.         values.setVisible(false);
  276.         graph1.setVisible(false);
  277.         graph2.setVisible(false);
  278.         graph3.setVisible(false);
  279.         buttonsPanel.add(tact);
  280.         buttonsPanel.add(graphs);
  281.         tact.setToolTipText("Выполнить один такт");
  282.         graph1.setToolTipText("Построить график зависимости среднего времени ожидания от интенсивности поступления заявок");
  283.         graph2.setToolTipText("Построить график зависимости процента простоя ресурса от интенсивности поступления заявок");
  284.         graph3.setToolTipText("Построить график зависимости среднего времени ожидания от приоритета");
  285.         buttonsPanel.add(graph1);
  286.         buttonsPanel.add(graph2);
  287.         buttonsPanel.add(graph3);
  288.         buttonsPanel.add(values);
  289.         textPanel.add(scroll);
  290.         area.setEditable(false);
  291.         setVisible(true);
  292.        
  293.     }
  294.     private void Init() {
  295.         time = 0;
  296.         requestsNum = 0;
  297.         iminValue = Integer.parseInt(imin.getText());
  298.         imaxValue = Integer.parseInt(imax.getText());
  299.         wminValue = Integer.parseInt(wmin.getText());
  300.         wmaxValue = Integer.parseInt(wmax.getText());
  301.         prminValue = Integer.parseInt(prmin.getText());
  302.         prmaxValue = Integer.parseInt(prmax.getText());
  303.         quantValue = Integer.parseInt(quant.getText());
  304.         queue = new QueueBlock(prmaxValue-prminValue, prminValue);
  305.         waitingTime = iminValue+(int)(Math.round(Math.random()*(imaxValue-iminValue)));
  306.         resource = new Resource(this, queue, quantValue);
  307.         resource.setRequest(null);
  308.     }
  309.     public void ExecuteOneTact(QueueBlock queue, Resource resource) {
  310.         resource.processOneTact();
  311.         time++;
  312.         waitingTime--;
  313.         if (waitingTime == 0) {
  314.             queue.addRequestWithFilter(new Request(wminValue+(int)(Math.round(Math.random()*(wmaxValue-wminValue))),prminValue+(int)(Math.round(Math.random()*(prmaxValue-prminValue))),time));
  315.             requestsNum+=1;
  316.             waitingTime = iminValue+(int)(Math.round(Math.random()*(imaxValue-iminValue)));
  317.         }
  318.     }
  319.     public void Visualisation(QueueBlock queue, Resource resource) {
  320.         area.setText(queue.getBlock());
  321.         if (resource.getCurrentRequest()!=null) {
  322.            area.append("Обработка текущей заявки: "+resource.getCurrentRequest().getProcessed()+"/"+resource.getCurrentRequest().getWeight()+ "(Приоритет: "+ resource.getCurrentRequest().getPriority()+") \n");
  323.            area.append("Квант: "+String.valueOf(resource.getQuant())+ "\n");
  324.            area.append("Время пребывания текущей заявки на ресурсе "+String.valueOf(resource.getProcessingTime())+"\n");
  325.         }
  326.         else {
  327.             area.append("Ресурс простаивает. Общее время простоя: "+String.valueOf(resource.getIdleTime())+ "\n");
  328.             area.append("Процент простоя: "+ ((float)resource.getIdleTime()/time)*100 +"\n");
  329.         }
  330.         area.append("Общее время работы системы: "+getTime()+" \n");
  331.         area.append("Текущее кол-во заявок в системе: "+getRequestsNumber()+"\n");
  332.         area.append("Заявок обработано: "+resource.getProcessedNumber()+"\n");
  333.        
  334.     }
  335.     public void addWaitingTime(int time) {
  336.         waitingTime_all+=time;
  337.     }
  338.     public int getRequestsNumber() {
  339.         return requestsNum;
  340.     }
  341.     public void setRequestsNumber(int num) {
  342.         requestsNum = num;
  343.     }
  344.     public int getTime() {
  345.         return time;
  346.     }
  347.     public int getIMin() {
  348.         return iminValue;
  349.     }
  350.     public int getIMax() {
  351.         return imaxValue;
  352.     }
  353.     public void setFieldsEditable(boolean value) {
  354.         imin.setEditable(value);
  355.         imax.setEditable(value);
  356.         wmin.setEditable(value);
  357.         wmax.setEditable(value);
  358.         prmin.setEditable(value);
  359.         prmax.setEditable(value);
  360.         quant.setEditable(value);
  361.     }
  362.     public int getPrMin() {
  363.         return prminValue;
  364.     }
  365.     public int getPrMax() {
  366.         return prmaxValue;
  367.     }
  368.     public static void main(String[] args) {
  369.        
  370.         new Form();
  371.     }
  372.  
  373. }

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

14   голосов , оценка 4.214 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут