Advertisement
Guest User

simmulate

a guest
Mar 5th, 2015
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.15 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Collections;
  10.  
  11. namespace Activity4
  12. {
  13. public partial class Simulate : Form
  14. {
  15. int y=0, x;
  16. String listBox;
  17. String type = "D";
  18.  
  19. int typeA = 0;
  20. int typeD = 0;
  21. int typeJ = 0,customerN=0;
  22.  
  23. int server = 0;
  24. int queue = 0;
  25.  
  26.  
  27. public static ArrayList arrdep = new ArrayList();
  28. public static ArrayList sort = new ArrayList();
  29. public static ArrayList arrival = new ArrayList();
  30.  
  31. int min;
  32. int eventN = 0;
  33.  
  34. public Simulate()
  35. {
  36. InitializeComponent();
  37. }
  38.  
  39. private void Simulate_Load(object sender, EventArgs e)
  40. {
  41.  
  42. for (int i = 0; i < Form1.a.Count; i++)
  43. {
  44. y++;
  45. x += Convert.ToInt32(Form1.a[i]);
  46. Form1.departure = x + Convert.ToInt32(Form1.b[i]);
  47. Form1.d.Add(Form1.departure);
  48. richTextBox1.Text += "[" + y + "]" + x + "\t" + Form1.b[i] + "\t" + Form1.d[i]+"\n";
  49.  
  50. }
  51.  
  52. int a = 0;
  53. StringBuilder sb = new StringBuilder();
  54. for (int i = 0; i < Form1.teller; i++)
  55. {
  56.  
  57. listBox += ++a + " ";
  58. }
  59. //listBox1.Items.Add(listBox);
  60. listBox1.Items.Add("Event# Type Customer# Queue Server Time Response Time ");
  61.  
  62. }
  63.  
  64. private void button2_Click(object sender, EventArgs e)
  65. {
  66. int x1 = 0,x2=0;
  67. //listBox1.Items.Add("1\tA1\t1\t1\t1\tResponse Time ");
  68. timer1.Enabled = true;
  69.  
  70. for (int i = 0; i < (Form1.customer ); i++) {
  71. x1 += Convert.ToInt32(Form1.a[i]);
  72. arrival.Add(x1);
  73. arrdep.Add(arrival[i]);
  74.  
  75. Form1.departure = x2 + Convert.ToInt32(Form1.b[i]);
  76. Form1.d.Add(Form1.departure);
  77. arrdep.Add(Form1.d[i]);
  78.  
  79.  
  80.  
  81. }
  82.  
  83. arrdep.Sort();
  84. }
  85.  
  86. private void timer1_Tick(object sender, EventArgs e)
  87. {
  88. bool k = false, served = false ;
  89.  
  90.  
  91. if (timer1.Enabled) {
  92. ++min;
  93. label3.Text = min.ToString();
  94. }
  95.  
  96.  
  97.  
  98. for (int i = 0; i < arrdep.Count; i++)
  99. {
  100. if (min == Convert.ToInt32(arrdep[i]))
  101. {
  102.  
  103.  
  104. if (arrival.Contains(min)&& !k)
  105. {
  106. type = "A";
  107. ++typeA;
  108. ++customerN;
  109. k = true;
  110. if (server < Form1.teller)
  111. {
  112. //server = 0;
  113. ++server;
  114. served = true;
  115. }
  116. else {
  117. ++queue;
  118. }
  119. }
  120. else {
  121. type = "D";
  122. ++typeD;
  123. }
  124. if(type.Equals("A") && served)
  125. listBox1.Items.Add(++eventN + " "+type+typeA+" "+typeA+" \t\t"+server+"\t"+ arrdep[i] + " - \n");
  126. else if (type.Equals("A") && !served)
  127. {
  128. listBox1.Items.Add(++eventN + " " + type + typeA + " " + typeA + " \t"+queue+"\t-\t" + arrdep[i] + " - \n");
  129. }
  130. else if (type.Equals("D"))
  131. {
  132. server = 0;
  133. listBox1.Items.Add(++eventN + " " + type + typeD + " " + typeD + " \t\t-\t" + arrdep[i] + " - \n");
  134. }
  135.  
  136. }
  137. }
  138. }
  139. }
  140. //}
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement