Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Collections;
- namespace Activity4
- {
- public partial class Simulate : Form
- {
- int y=0, x;
- String listBox;
- String type = "D";
- int typeA = 0;
- int typeD = 0;
- int typeJ = 0,customerN=0;
- int server = 0;
- int queue = 0;
- public static ArrayList arrdep = new ArrayList();
- public static ArrayList sort = new ArrayList();
- public static ArrayList arrival = new ArrayList();
- int min;
- int eventN = 0;
- public Simulate()
- {
- InitializeComponent();
- }
- private void Simulate_Load(object sender, EventArgs e)
- {
- for (int i = 0; i < Form1.a.Count; i++)
- {
- y++;
- x += Convert.ToInt32(Form1.a[i]);
- Form1.departure = x + Convert.ToInt32(Form1.b[i]);
- Form1.d.Add(Form1.departure);
- richTextBox1.Text += "[" + y + "]" + x + "\t" + Form1.b[i] + "\t" + Form1.d[i]+"\n";
- }
- int a = 0;
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < Form1.teller; i++)
- {
- listBox += ++a + " ";
- }
- //listBox1.Items.Add(listBox);
- listBox1.Items.Add("Event# Type Customer# Queue Server Time Response Time ");
- }
- private void button2_Click(object sender, EventArgs e)
- {
- int x1 = 0,x2=0;
- //listBox1.Items.Add("1\tA1\t1\t1\t1\tResponse Time ");
- timer1.Enabled = true;
- for (int i = 0; i < (Form1.customer ); i++) {
- x1 += Convert.ToInt32(Form1.a[i]);
- arrival.Add(x1);
- arrdep.Add(arrival[i]);
- Form1.departure = x2 + Convert.ToInt32(Form1.b[i]);
- Form1.d.Add(Form1.departure);
- arrdep.Add(Form1.d[i]);
- }
- arrdep.Sort();
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- bool k = false, served = false ;
- if (timer1.Enabled) {
- ++min;
- label3.Text = min.ToString();
- }
- for (int i = 0; i < arrdep.Count; i++)
- {
- if (min == Convert.ToInt32(arrdep[i]))
- {
- if (arrival.Contains(min)&& !k)
- {
- type = "A";
- ++typeA;
- ++customerN;
- k = true;
- if (server < Form1.teller)
- {
- //server = 0;
- ++server;
- served = true;
- }
- else {
- ++queue;
- }
- }
- else {
- type = "D";
- ++typeD;
- }
- if(type.Equals("A") && served)
- listBox1.Items.Add(++eventN + " "+type+typeA+" "+typeA+" \t\t"+server+"\t"+ arrdep[i] + " - \n");
- else if (type.Equals("A") && !served)
- {
- listBox1.Items.Add(++eventN + " " + type + typeA + " " + typeA + " \t"+queue+"\t-\t" + arrdep[i] + " - \n");
- }
- else if (type.Equals("D"))
- {
- server = 0;
- listBox1.Items.Add(++eventN + " " + type + typeD + " " + typeD + " \t\t-\t" + arrdep[i] + " - \n");
- }
- }
- }
- }
- }
- //}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement