Advertisement
Guest User

Untitled

a guest
Dec 16th, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.87 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. // Dodanie przestrzeni nazw z biblioteki CSL
  6. using CSL;
  7. using CSL.Time;
  8. using CSL.Groups;
  9. using CSL.Generators.Discrete;
  10. using CSL.Statistics;
  11. using System.Diagnostics;
  12.  
  13. namespace CSLProjects
  14. {
  15.     class ExampleC
  16.     {
  17.         Element[] zgloszenie;
  18.         public Random random;
  19.  
  20.         public void Run()
  21.         {
  22.  
  23.             uint maxLiczbaZgloszen = 1000;
  24.             uint srOdstepZgloszen = 1000;
  25.             uint srCzasObsl = 450;
  26.             uint maxLiczbaObs = 1000; //temp 1000
  27.  
  28.             zgloszenie = new Element[maxLiczbaZgloszen];
  29.             for (uint i = 0; i < maxLiczbaZgloszen; i++)
  30.             {
  31.                 zgloszenie[i] = new Element(); //utowrzenie zasobów wolnych
  32.             }
  33.  
  34.             SetGroup wolne = new SetGroup(maxLiczbaZgloszen);
  35.             QueueGroup kolejka = new QueueGroup(maxLiczbaZgloszen);
  36.  
  37.             Timer nadZgl = new Timer();
  38.             Timer konObsl = new Timer();
  39.  
  40.             int stanObsl;
  41.  
  42.             NegExp genOdstZgl = new NegExp(srOdstepZgloszen);
  43.             NegExp genCzasuObsl = new NegExp(srCzasObsl);
  44.  
  45.             StatD statCzasuPobytu = new StatD();
  46.             StatCRect statDlKol = new StatCRect();
  47.  
  48.             uint dlKol = 0;
  49.             Timer zegarStat = new Timer();
  50.  
  51.             Hist histLP = new Hist(7, 1, 1);
  52.  
  53.             long liczbaObs;
  54.  
  55.             uint El = uint.MaxValue;
  56.  
  57.             random = new Random();
  58.            
  59.  
  60.             wolne.Load();
  61.             kolejka.Zero();
  62.             zegarStat.t = 0;
  63.  
  64.             statDlKol.Clear();
  65.             histLP.Clear();
  66.             statCzasuPobytu.Clear();
  67.  
  68.             liczbaObs = 0;
  69.             stanObsl = -1;
  70.             nadZgl.t = 0;
  71.             nadZgl.SetOn();
  72.  
  73.             while (true)
  74.             {
  75.                
  76.                 if (nadZgl.Now())
  77.                 {
  78.                     wolne.Find(ref El, FindParameters.FIRST);
  79.                     wolne.From(El);
  80.                     zgloszenie[El].LP = 0;
  81.                     zgloszenie[El].t = 0;
  82.                     kolejka.To(El);
  83.                     dlKol++;
  84.                     statDlKol.Add(dlKol, -zegarStat.t);
  85.                     nadZgl.t = genOdstZgl.Get();
  86.                 }
  87.  
  88.                 if (konObsl.Now())
  89.                 {
  90.                     if (bRet(ref random)) // czy cofnąć do kolejki
  91.                     {
  92.                         zgloszenie[stanObsl].LP += 1;
  93.                         kolejka.To((uint)stanObsl);
  94.                         dlKol++;
  95.                         statDlKol.Add(dlKol, -zegarStat.t);
  96.                     }
  97.                     else
  98.                     {
  99.                         wolne.To((uint)stanObsl);
  100.                     }
  101.                     histLP.Add(zgloszenie[stanObsl].LP);
  102.                     liczbaObs++;
  103.                     stanObsl = -1;
  104.                     konObsl.SetOff();
  105.                 }
  106.  
  107.                 if (stanObsl == -1)
  108.                 {
  109.                     if (kolejka.Find(ref El, FindParameters.FIRST))
  110.                     {
  111.                         kolejka.From(El);
  112.                         dlKol--;
  113.                         statDlKol.Add(dlKol, -zegarStat.t);
  114.                         statCzasuPobytu.Add(-zgloszenie[El].t);
  115.                         stanObsl = (int)El;
  116.                         konObsl.t = genCzasuObsl.Get();
  117.                         konObsl.SetOn();
  118.                     }
  119.                 }
  120.  
  121.                 if(liczbaObs % 1000 == 0)
  122.                     Console.WriteLine("Liczba obserwacji " + liczbaObs);
  123.  
  124.                 if (maxLiczbaObs <= liczbaObs)
  125.                 {
  126.                     break;
  127.                 }
  128.  
  129.                 Time.TimeFlow();                
  130.             }
  131.  
  132.             double sr = -1;
  133.            
  134.  
  135.             Console.WriteLine("Wyniki po przejsciu " + liczbaObs + " obserwacji.");
  136.             Console.WriteLine("Czas symulacji: " + -zegarStat.t);
  137.  
  138.             statCzasuPobytu.GetStat(ref sr);
  139.             Console.WriteLine("Sredni czas pobytu w systemie: " + sr);
  140.  
  141.             statDlKol.GetStat(ref sr);
  142.             Console.WriteLine("Srednia dlugosc kolejki: " + sr);
  143.  
  144.             Console.WriteLine("Histogram liczby przejsc: ");
  145.             Console.WriteLine(histLP.Out());
  146.  
  147.             Console.ReadKey();
  148.         }
  149.  
  150.         bool bRet(ref Random _random)
  151.         {
  152.             double next = _random.NextDouble() * 3;
  153.             if (next > 2)
  154.             {
  155.                 return true;
  156.             }
  157.             else
  158.             {
  159.                 return false;
  160.             }
  161.         }
  162.  
  163.         /// <summary>
  164.         /// klasa Element, dziedzicząca po klasie Timer, reprezentująca zgłoszenie w systemie.
  165.         /// </summary>
  166.         class Element : Timer
  167.         {
  168.             public uint LP = 0;
  169.         }
  170.  
  171.     }
  172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement