private void timer1_Tick(object sender, EventArgs e)
        {
            for (int i = 0; i < numberOfProcessors; i++)
            {
                processors[i].MillisecondRemove();
            }

            generateTask = new GenerateTask();
            if (GENERAL_PROBABILITY > 0)
            {
                generateTask.probability = GENERAL_PROBABILITY;
            }
            if (GENERAL_COMPLEXITY > 0)
            {
                generateTask.taskComplexity = GENERAL_COMPLEXITY;
            }

            var    processorsInUse = generateTask.GetProcessors(availableProcessors.Count, availableProcessors);
            var    minInd          = processorsInUse[0];
            double load            = (double)Int32.MaxValue;
            double tmp             = 0;

            GetMinLoadedProcessor(ref minInd, ref load, ref tmp, processorsInUse);

            var currentProcessor     = minInd;
            Pair <bool, double> pair = generateTask.CanAppear();

            for (int i = 0; i < processorsInUse.Count; i++)
            {
                processorsInUse[i]++;
            }

            if (pair.First)
            {
                TOTAL_TASKS++;
                processors[currentProcessor].AddTask(generateTask.taskComplexity);

                //    if (processorsInUse.Count > 1)
                //        processorsInUse.RemoveAt(processorsInUse.Count - 1);
                ListViewItem listView = new ListViewItem(
                    new string[] { string.Join(" ", processorsInUse),
                                   generateTask.taskComplexity.ToString(),
                                   processors[currentProcessor].queue.ToString() }
                    );
                // shitty construction
                listViews.ToArray()[currentProcessor].Items.Add(listView);
            }

            ListViewItem lstRes = new ListViewItem(
                new string[] {
                (pair.Second / 100.0).ToString(),
                pair.First.ToString(),
                string.Join(" ", processorsInUse),
                generateTask.taskComplexity.ToString(),
                processors[currentProcessor].queue.ToString()
            }
                );

            listView6.Items.Add(lstRes);
        }
Exemple #2
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            for (int i = 0; i < numberOfProcessors; i++)
            {
                processors[i].MillisecondRemove();
            }

            generateTask = new GenerateTask();
            if (GENERAL_PROBABILITY > 0)
            {
                generateTask.probability = GENERAL_PROBABILITY;
            }
            if (GENERAL_COMPLEXITY > 0)
            {
                generateTask.taskComplexity = GENERAL_COMPLEXITY;
            }

            var  currentProcessor = 0;
            var  processorsInUse  = new List <int>();
            bool isPlanner        = true;

            // Planner - 4 ms
            if (processors[PLANNER_PROCESSOR_INDEX].timeToBePlanner != 0)
            {
                processorsInUse = generateTask.GetProcessors(availableProcessors.Count, availableProcessors);
                var    minInd = processorsInUse[0];
                double load   = (double)Int32.MaxValue;
                double tmp    = 0;
                GetMinLoadedProcessor(ref minInd, ref load, ref tmp, processorsInUse);

                currentProcessor = minInd;

                processors[PLANNER_PROCESSOR_INDEX].timeToBePlanner--;
                if (processors[PLANNER_PROCESSOR_INDEX].timeToBePlanner == 0)
                {
                    listViews.ToArray()[PLANNER_PROCESSOR_INDEX].Items.Add("working");
                }
            }
            else
            if (processors[PLANNER_PROCESSOR_INDEX].timeToBeProcessor != 0)
            {
                isPlanner        = false;
                processorsInUse  = generateTask.GetProcessors(numberOfProcessors);
                currentProcessor = processorsInUse[0] - 1;
                for (int i = 0; i < processorsInUse.Count; i++)
                {
                    processorsInUse[i]--;
                }
                processors[PLANNER_PROCESSOR_INDEX].timeToBeProcessor--;
                if (processors[PLANNER_PROCESSOR_INDEX].timeToBeProcessor == 0)
                {
                    listViews.ToArray()[PLANNER_PROCESSOR_INDEX].Items.Add("planner");
                    processors[PLANNER_PROCESSOR_INDEX].timeToBePlanner   = 4;
                    processors[PLANNER_PROCESSOR_INDEX].timeToBeProcessor = 20;
                }
            }
            // Queue - 20 ms
            Pair <bool, double> pair = generateTask.CanAppear();

            for (int i = 0; i < processorsInUse.Count; i++)
            {
                processorsInUse[i]++;
            }

            if (pair.First)
            {
                TOTAL_TASKS++;
                processors[currentProcessor].AddTask(generateTask.taskComplexity);

                if (processorsInUse.Count > 1 && !isPlanner)
                {
                    processorsInUse.RemoveAt(processorsInUse.Count - 1);
                }
                ListViewItem listView = new ListViewItem(
                    new string[] { string.Join(" ", processorsInUse),
                                   generateTask.taskComplexity.ToString(),
                                   processors[currentProcessor].queue.ToString() }
                    );
                // shitty construction
                listViews.ToArray()[currentProcessor].Items.Add(listView);
            }

            ListViewItem lstRes = new ListViewItem(
                new string[] {
                (pair.Second / 100.0).ToString(),
                pair.First.ToString(),
                string.Join(" ", processorsInUse),
                generateTask.taskComplexity.ToString(),
                processors[currentProcessor].queue.ToString()
            }
                );

            listView6.Items.Add(lstRes);
        }