override public void OutAct() { SetTCurrForChannels(); base.OutAct(); GetChannelByTNext().OutAct(); base.TNext = GetTNext(); if (CheckFreeChannels() == true) { base.State = 0; } if (this.Queue > 0 && CheckFreeChannels() == true) { Queue--; GetFreeChannel().InAct(); if (CheckFreeChannels() == false) { base.State = 1; } base.TNext = GetTNext(); } if (NextMss.Count > 0) { int index = 0; if (NextDespose == true) { Random random = new Random(); double value = random.NextDouble(); if (value < 0.5) { MassServiceSystem2 nextProcess = NextMss[index]; } else { // Console.WriteLine("--------Dispose--------"); } } else { MassServiceSystem2 nextProcess = NextMss[index]; nextProcess.InAct(); } } else { // Console.WriteLine("--------Dispose--------"); } }
static TimeSpan Task2(int N) { List <Element> list = new List <Element>(); Random random = new Random(); Create2 c = new Create2(2.0); list.Add(c); List <MassServiceSystem2> massServiceSystems = new List <MassServiceSystem2>(); //generate mass service systems for (int i = 0; i < N; i++) { MassServiceSystem2 massServiceSystem = new MassServiceSystem2(random.NextDouble()); massServiceSystem.Name = "SMO" + (i + 1).ToString(); massServiceSystem.Distribution = "exp"; massServiceSystems.Add(massServiceSystem); list.Add(massServiceSystem); } c.NextElement = massServiceSystems[0]; //generate channels and set relations for (int i = 0; i < N; i++) { if (i == N - 1) { massServiceSystems[i].NextDespose = true; } else { massServiceSystems[i].NextMss.Add(massServiceSystems[i + 1]); } int channelCount = random.Next(1, 5); for (int j = 0; j < channelCount; j++) { Channel channel = new Channel(); channel.Name = "Channel" + (i + 1).ToString() + "_" + (j + 1).ToString(); massServiceSystems[i].Channels.Add(channel); } } Model model = new Model(list); DateTime dateTime = DateTime.Now; model.Simulate(1000.0); DateTime dateTime1 = DateTime.Now; Element.NextId = 0; return(dateTime1 - dateTime); }