public void GenerateChartElement(PropertiesData Process, float timestamp)
    {
        GameObject @object = Instantiate(prefabObject, ganttChartHolder.transform);

        @object.GetComponent <ChartElement>().timeStamp.text   = timestamp.ToString("f2");
        @object.GetComponent <ChartElement>().ProcessName.text = Process.ProcessName;
        summaryChartMaker(Process, timestamp);
    }
 private void process()
 {
     if (running)
     {
         for (int i = 0; i < waiting.Count; i++)
         {
             PropertiesData propertiesData = waiting[i];
             if (scheduler.SchedulerTime >= propertiesData.ArrivalTime)
             {
                 arrived.Add(propertiesData);
                 waiting.Remove(propertiesData);
             }
         }
         if (!processing)
         {
             if (arrived.Count > 0)
             {
                 float minPriority = arrived[0].Priority;
                 CurrentlyProcessing = arrived[0];
                 foreach (PropertiesData processes in arrived)
                 {
                     if (processes.Priority < minPriority)
                     {
                         minPriority         = processes.Priority;
                         CurrentlyProcessing = processes;
                     }
                 }
                 arrived.Remove(CurrentlyProcessing);
                 processing      = true;
                 ProcessorFreeAt = Mathf.Min(CurrentlyProcessing.BurstTime, 1);
                 CurrentlyProcessing.remainingBurstTime -= ProcessorFreeAt;
                 chartMaker.GenerateChartElement(CurrentlyProcessing, scheduler.SchedulerTime);
             }
         }
         else
         {
             ProcessorFreeAt -= scheduler.SchedulerDeltaTime;
             if (ProcessorFreeAt <= 0)
             {
                 if (CurrentlyProcessing.remainingBurstTime <= 0)
                 {
                     float SpeedAdjustment = -ProcessorFreeAt;
                     scheduler.makeSummary(CurrentlyProcessing, SpeedAdjustment);
                 }
                 else
                 {
                     arrived.Add(CurrentlyProcessing);
                 }
                 processing = false;
                 if (waiting.Count == 0 && arrived.Count == 0)
                 {
                     running           = false;
                     scheduler.running = false;
                 }
             }
         }
     }
 }
Example #3
0
 public void reset()
 {
     waiting             = new List <PropertiesData>();
     arrived             = new List <PropertiesData>();
     running             = false;
     CurrentlyProcessing = null;
     ProcessorFreeAt     = 0.0f;
     processing          = false;
 }
 void process()
 {
     if (running)
     {
         foreach (PropertiesData propertiesData in waiting.ToArray())
         {
             if (scheduler.SchedulerTime >= propertiesData.ArrivalTime)
             {
                 arrived.Add(propertiesData);
                 waiting.Remove(propertiesData);
             }
         }
         if (!processing)
         {
             if (arrived.Count > 0)
             {
                 float minBurst = arrived[0].BurstTime;
                 CurrentlyProcessing = arrived[0];
                 foreach (PropertiesData processes in arrived.ToArray())
                 {
                     if (processes.BurstTime < minBurst)
                     {
                         minBurst            = processes.BurstTime;
                         CurrentlyProcessing = processes;
                     }
                 }
                 arrived.Remove(CurrentlyProcessing);
                 processing      = true;
                 ProcessorFreeAt = Mathf.Min(CurrentlyProcessing.BurstTime, 1);
                 CurrentlyProcessing.remainingBurstTime -= ProcessorFreeAt;
                 chartMaker.GenerateChartElement(CurrentlyProcessing, scheduler.SchedulerTime);
             }
         }
         if (processing)
         {
             if (ProcessorFreeAt <= 0)
             {
                 if (CurrentlyProcessing.remainingBurstTime <= 0)
                 {
                     scheduler.makeSummary(CurrentlyProcessing);
                 }
                 else
                 {
                     arrived.Add(CurrentlyProcessing);
                 }
                 processing = false;
                 if (waiting.Count == 0 && arrived.Count == 0)
                 {
                     scheduler.running = false;
                     running           = false;
                 }
             }
             ProcessorFreeAt -= scheduler.SchedulerDeltaTime;
         }
     }
 }
Example #5
0
 public void AddPrefabInstance()
 {
     InstantiatedGameObject = Instantiate(PrefabToInstantiate, parentGameObject.transform);
     try
     {
         instantiatedPropertiesData = InstantiatedGameObject.GetComponent <PropertiesData>();
         AddToData();
     }
     catch { }
 }
Example #6
0
 public void reset()
 {
     waiting             = new List <PropertiesData>();
     Ready               = new Queue <PropertiesData>();
     CurrentlyProcessing = null;
     ProcessorFreeAt     = 0.0f;
     processing          = false;
     running             = false;
     ProcessStartedAt    = 0.0f;
 }
Example #7
0
    //IEnumerator StepSchedulerEnumerator()
    //{
    //    SchedulerPause = true;
    //    SchedulerDeltaTime = Mathf.Ceil(SchedulerTime) - SchedulerTime;
    //    yield return null;
    //    SchedulerDeltaTime = 1.0f;
    //}
    public void makeSummary(PropertiesData CurrentlyProcessing, float SpeedAdjustment = 0.0f)
    {
        SummaryData summaryData = new SummaryData();

        summaryData.ProcessName    = CurrentlyProcessing.ProcessName;
        summaryData.ArrivalTime    = CurrentlyProcessing.ArrivalTime;
        summaryData.BurstTime      = CurrentlyProcessing.BurstTime;
        summaryData.CompletionTime = (float)System.Math.Round(SchedulerTime - SpeedAdjustment, 2);
        summaryData.TurnAroundTime = summaryData.CompletionTime - summaryData.ArrivalTime;
        summaryData.WaitingTime    = (float)System.Math.Round(summaryData.TurnAroundTime - summaryData.BurstTime, 2);
        summaryManager.summaryDatas.Add(summaryData);
    }
Example #8
0
 private void process()
 {
     if (running)
     {
         for (int i = 0; i < waiting.Count; i++)
         {
             PropertiesData propertiesData = waiting[i];
             if (scheduler.SchedulerTime >= propertiesData.ArrivalTime)
             {
                 Ready.Enqueue(propertiesData);
                 waiting.Remove(propertiesData);
             }
         }
         if (!processing)
         {
             if (Ready.Count > 0)
             {
                 CurrentlyProcessing = Ready.Peek();
                 Ready.Dequeue();
                 processing      = true;
                 ProcessorFreeAt = Mathf.Min(CurrentlyProcessing.BurstTime, Tq);
                 CurrentlyProcessing.remainingBurstTime -= ProcessorFreeAt;
                 ProcessStartedAt = scheduler.SchedulerTime;
                 chartMaker.GenerateChartElement(CurrentlyProcessing, scheduler.SchedulerTime);
             }
         }
         else
         {
             ProcessorFreeAt -= scheduler.SchedulerDeltaTime;
             if (ProcessorFreeAt <= 0)
             {
                 if (CurrentlyProcessing.remainingBurstTime > 0)
                 {
                     Ready.Enqueue(CurrentlyProcessing);
                 }
                 else
                 {
                     float SpeedAdjustment = -ProcessorFreeAt;
                     scheduler.makeSummary(CurrentlyProcessing, SpeedAdjustment);
                 }
                 processing = false;
                 if (Ready.Count == 0 && waiting.Count == 0)
                 {
                     running           = false;
                     scheduler.running = false;
                 }
             }
         }
     }
 }
 void process()
 {
     if (running)
     {
         foreach (PropertiesData propertiesData in waiting.ToArray())
         {
             if (scheduler.SchedulerTime >= propertiesData.ArrivalTime)
             {
                 arrived.Add(propertiesData);
                 waiting.Remove(propertiesData);
             }
         }
         if (!processing)
         {
             if (arrived.Count > 0)
             {
                 float minPriority = arrived[0].Priority;
                 CurrentlyProcessing = arrived[0];
                 for (int i = 0; i < arrived.Count; i++)
                 {
                     PropertiesData processes = arrived[i];
                     if (processes.Priority < minPriority)
                     {
                         minPriority         = arrived[i].Priority;
                         CurrentlyProcessing = arrived[i];
                     }
                 }
                 arrived.Remove(CurrentlyProcessing);
                 processing      = true;
                 ProcessorFreeAt = CurrentlyProcessing.BurstTime;
                 chartMaker.GenerateChartElement(CurrentlyProcessing, scheduler.SchedulerTime);
             }
         }
         if (processing)
         {
             if (ProcessorFreeAt <= 0)
             {
                 scheduler.makeSummary(CurrentlyProcessing);
                 processing = false;
                 if (waiting.Count == 0 && arrived.Count == 0)
                 {
                     running           = false;
                     scheduler.running = false;
                 }
             }
             ProcessorFreeAt -= scheduler.SchedulerDeltaTime;
         }
     }
 }
 void process()
 {
     if (running)
     {
         for (int i = 0; i < waiting.Count; i++)
         {
             PropertiesData propertiesData = waiting[i];
             if (scheduler.SchedulerTime >= propertiesData.ArrivalTime)
             {
                 arrived.Enqueue(propertiesData);
                 waiting.Remove(propertiesData);
             }
         }
         if (!processing)
         {
             if (arrived.Count > 0)
             {
                 CurrentlyProcessing = arrived.Dequeue();
                 processing          = true;
                 ProcessorFreeAt     = CurrentlyProcessing.BurstTime;
                 chartMaker.GenerateChartElement(CurrentlyProcessing, scheduler.SchedulerTime);
             }
         }
         if (processing)
         {
             if (ProcessorFreeAt <= 0)
             {
                 float SpeedAdjustment = -ProcessorFreeAt;
                 scheduler.makeSummary(CurrentlyProcessing, SpeedAdjustment);
                 processing = false;
                 if (waiting.Count == 0 && arrived.Count == 0)
                 {
                     running           = false;
                     scheduler.running = false;
                 }
             }
             ProcessorFreeAt -= scheduler.SchedulerDeltaTime;
         }
     }
 }
 public void summaryChartMaker(PropertiesData Process, float timestamp)
 {
     if (Process.chartData == null)
     {
         GameObject @object = new GameObject("GanttChartDataHolder");
         try
         {
             summaryAdded.Add(Process);
             @object.transform.parent = this.transform;
             @object.AddComponent <GanttChartData>();
             GanttChartDataHolders.Add(@object);
         }
         catch
         {
             print("Caught unknown error!");
         }
         GanttChartData ganttChartData = @object.GetComponent <GanttChartData>();
         ganttChartData.ProcessName = Process.ProcessName;
         Texture2D texture;
         if (!tabData.GetPreemptive())
         {
             texture = new Texture2D((int)(timestamp + Process.BurstTime), 1);
         }
         else
         {
             texture = new Texture2D((int)timestamp + 1, 1);
         }
         texture.filterMode = FilterMode.Point;
         for (int x = 0; x < (int)timestamp; x++)
         {
             texture.SetPixel(x, 0, Color.clear);
         }
         if (!tabData.GetPreemptive())
         {
             for (int x = (int)(timestamp); x < (int)(timestamp + Process.remainingBurstTime); x++)
             {
                 texture.SetPixel(x, 0, Color.blue);
             }
         }
         else
         {
             texture.SetPixel((int)timestamp, 0, Color.blue);
         }
         texture.Apply();
         ganttChartData.texture = texture;
         Rect rec = new Rect(0, 0, texture.width, 1);
         //float scalingFactor = 2.0f / Mathf.Max((int)Mathf.Log10((int)(timestamp + Process.remainingBurstTime)), 3);
         ganttChartData.ProcessingPos = Sprite.Create(texture, rec, Vector2.zero, 0.01f);
         GanttChartManager.DetailedGanttChart.Add(ganttChartData);
         Process.chartData = ganttChartData;
     }
     else
     {
         //retrieve texture resize and repeat
         Texture2D texture             = Process.chartData.texture;
         int       textureWidth        = texture.width;
         Color32[] textureColorsBackup = texture.GetPixels32(0);
         texture.Resize((int)(timestamp + 1), 1);
         texture.Apply();
         for (int x = textureWidth; x < (int)timestamp; x++)
         {
             texture.SetPixel(x, 0, Color.clear);
         }
         texture.Apply();
         for (int i = 0; i < textureColorsBackup.Length; i++)
         {
             texture.SetPixel(i, 0, textureColorsBackup[i]);
         }
         texture.Apply();
         texture.SetPixel((int)timestamp, 0, Color.blue);
         texture.Apply();
         Rect rec = new Rect(0, 0, texture.width, 1);
         Process.chartData.texture       = texture;
         Process.chartData.ProcessingPos = Sprite.Create(texture, rec, Vector2.zero, 0.01f);
     }
 }