コード例 #1
0
ファイル: controller.cs プロジェクト: BXZR/Scheduling
        void quickSort(List <charge> a, int low, int high)
        {
            if (low >= high)
            {
                return;
            }
            int    first    = low;
            int    last     = high;
            charge keyValue = a[low];

            while (low < high)
            {
                while (low < high && a[high].LooseTimer >= keyValue.LooseTimer)
                {
                    high--;
                }
                a[low] = a[high];
                while (low < high && a[low].LooseTimer <= keyValue.LooseTimer)
                {
                    low++;
                }
                a[high] = a[low];
            }
            a[low] = keyValue;
            quickSort(a, first, low - 1);
            quickSort(a, low + 1, last);
        }
コード例 #2
0
ファイル: MainWindow.xaml.cs プロジェクト: BXZR/Scheduling
        private void button2_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string chargeNamer = "";
                string nameUse     = "示例任务1";
                if (chargeNamer.Length > nameUse.Length)
                {
                    chargeNamer = chargeNamer.Substring(0, nameUse.Length);
                }
                else if (chargeNamer.Length < nameUse.Length)
                {
                    chargeNamer += ("XXXXXXXXXXXXXX".Substring(0, nameUse.Length - chargeNamer.Length));
                }
                Console.Write(chargeNamer);
                int timeLonger  = 10;
                int deadLiner   = 12;
                int circleTimer = 12;
                int timesr      = 2;
                int startTimer  = 2;
                ////
                int    CPUindex         = getCPUIndexCanUse();
                charge newChargeForBook = new charge(timeLonger, circleTimer, deadLiner, timesr, startTimer, chargeNamer, theControlers[CPUindex], isAValuableCharge);
                newChargeForBook.theMainWindow = this;
                theControlers[CPUindex].chargesBook.Add(newChargeForBook);
                ListBoxItem f = new ListBoxItem();
                f.Content = newChargeForBook.getShortInformation();
                //AllChargeBook.Items.Add(f);
                ////

                for (int k = 0; k < theControlers.Count; k++)
                {
                    float checker = 0;
                    for (int i = 0; i < theControlers[k].chargesBook.Count; i++)
                    {
                        checker += theControlers[k].chargesBook[i].getCheckValue();
                    }
                    if (checker > 1)//检查出错了
                    {
                        MessageBox.Show("checker:" + checker + " 其实,这是不可调度的。\n请点击容错来排除这个问题。");
                        flashWindow();
                    }
                    if (theControlers[k].schedulingMode == 2) //RM的特殊性
                    {
                        theControlers[k].theSort();           //排序
                        if (!this.checkForRM(theControlers[k].chargesBook))
                        {
                            MessageBox.Show("RM算法不可调度,有超时现象发生。");
                        }
                    }

                    theControlers[k].makeChargeShower();
                }
            }
            catch
            {
                MessageBox.Show("除了名字麻烦其他项都输入整型数字。");
            }
        }
コード例 #3
0
ファイル: controller.cs プロジェクト: BXZR/Scheduling
        public void makePictures(charge selected)
        {
            if (selected != null)
            {
                int index = -1;
                for (int i = 0; i < chargeShower.Count; i++)
                {
                    if (chargeShower[i].theCharge.Name == selected.Name.Split('(')[0])
                    {
                        //Console.WriteLine(chargeShower[i].theCharge.Name + "[[");
                        index = i;
                    }
                }

                if (index >= 0)
                {
                    int i = 0;
                    for (; i < chargeShower.Count; i++)
                    {
                        if (chargeShower[i].rowIndex == (chargeShower.Count - 1 - index))
                        {
                            controllerPictures[i] += "|" + selected.Name.Split('(')[0].PadRight(5) + "|";
                        }
                        else
                        {
                            string namer = chargeShower[i].theCharge.Name.Split('(')[0];
                            string s     = "|";
                            s = s.PadLeft(namer.Length, ' ');
                            controllerPictures[i] += "|  " + s;
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < chargeShower.Count; i++)
                    {
                        string namer = chargeShower[i].theCharge.Name.Split('(')[0];
                        string s     = "|";
                        s = s.PadLeft(namer.Length, ' ');
                        controllerPictures[i] += "|  " + s;
                    }
                }
            }
            else
            {
                for (int i = 0; i < chargeShower.Count; i++)
                {
                    string namer = chargeShower[i].theCharge.Name.Split('(')[0];
                    string s     = "|";
                    s = s.PadLeft(namer.Length, ' ');
                    controllerPictures[i] += "|  " + s;
                }
            }
        }
コード例 #4
0
ファイル: charge.cs プロジェクト: BXZR/Scheduling
 public charge(charge theCharge, int indexForThisKind, controller theControllerIn)//附加,这个是某一类进程的第几个实例
 {
     this.chargeLength = theCharge.chargeLength;
     this.circleTime   = theCharge.circleTime;
     this.deadLine     = theCharge.deadLine + (indexForThisKind - 1) * CircleTimer;//相对截止时间变成绝对截止时间了
     this.timeMax      = theCharge.timeMax;
     this.startTime    = theCharge.startTime;
     this.isValueAble  = theCharge.isValueAble;
     this.name         = theCharge.name + "(第" + indexForThisKind + "实例)";
     theController     = theControllerIn;
 }
コード例 #5
0
ファイル: charge.cs プロジェクト: BXZR/Scheduling
 public charge(charge theCharge, controller theControllerIn)
 {
     this.chargeLength = theCharge.chargeLength;
     this.circleTime   = theCharge.circleTime;
     this.deadLine     = theCharge.deadLine;
     this.timeMax      = theCharge.timeMax;
     this.name         = theCharge.name;
     this.startTime    = theCharge.startTime;
     this.isValueAble  = theCharge.isValueAble;
     theController     = theControllerIn;
 }
コード例 #6
0
ファイル: controller.cs プロジェクト: BXZR/Scheduling
 public void schedule(int indexFrom = 0)
 {
     if (charges.Count >= 1)
     {
         quickSort(charges, indexFrom, charges.Count - 1);
     }
     if (charges.Count > 0)
     {
         selectedCharge = charges[0];
     }
     else
     {
         selectedCharge = null;
     }
 }
コード例 #7
0
ファイル: controller.cs プロジェクト: BXZR/Scheduling
        public void removeCharge(charge theCharge)
        {
            if (theCharge == null)
            {
                return;
            }
            if (charges.Contains(theCharge))
            {
                if (theCharge.theStreamforCharge != null && theCharge.theStreamforCharge.thePlanRoute.Count > 0 && theCharge.theStreamforCharge.isOver == false)
                {
                    int timeUseForThisStream = this.allTimer - theCharge.StartTime;
                    theCharge.theStreamforCharge.allTimeUse += timeUseForThisStream;
                    theCharge.theStreamforCharge.indexNow++;
                    if (theCharge.theStreamforCharge.indexNow < theCharge.theStreamforCharge.thePlanRoute.Count)
                    {
                        theMainWindow.textForInformation += theCharge.Name + "转到下一个节点\n";
                        theCharge.theStreamforCharge.thePlanRoute[theCharge.theStreamforCharge.indexNow].getStream(theCharge.theStreamforCharge);
                    }
                    else if (theCharge.theStreamforCharge.indexNow == theCharge.theStreamforCharge.thePlanRoute.Count)
                    {
                        //if(theCharge.theStreamforCharge.thePlanRoute[theCharge.theStreamforCharge.thePlanRoute.Count - 1] == this.theMainWindow )
                        theCharge.theStreamforCharge.isOver = true;
                        Operate.theStringForOperate        += theCharge.theStreamforCharge.theName + ":\n跳数:" + theCharge.theStreamforCharge.thePlanRoute.Count + "\ntimeUse = " + theCharge.theStreamforCharge.allTimeUse + "\n--------------------------\n";
                        //if (Operate.isAllOver())
                        //    System.Windows.MessageBox.Show(Operate.theStringForOperate);
                        Operate.thestreamShows.Add(new streamShowing(theCharge.theStreamforCharge.theName + "   ", theCharge.theStreamforCharge.thePlanRoute.Count.ToString("f0") + "   ", theCharge.theStreamforCharge.allTimeUse.ToString("f0") + "   "));
                        if (Operate.isAllOver())
                        {
                            StreamShower A = new StreamShower();
                            A.setData(Operate.thestreamShows);
                            A.Show();

                            StreamShower B = new StreamShower();
                            B.setData(Operate.allChart, this.allTimer);
                            B.Show();

                            //System.Windows.MessageBox.Show("all timer = "+ this.allTimer);

                            Console.WriteLine("OVER");
                        }
                    }
                }
                charges.Remove(theCharge);
                schedule();
                theMainWindow.textForInformation += theCharge.Name + "完成,调度一次\n";
                theCharge = null;
            }
        }
コード例 #8
0
ファイル: MainWindow.xaml.cs プロジェクト: BXZR/Scheduling
        private void makeExample()
        {
            try
            {
                int    CPUIndex         = getCPUIndexCanUse();
                charge newChargeForBook = new charge(5, 30, 29, 2, 1, "示例进程1", theControlers[CPUIndex], false);
                newChargeForBook.theMainWindow = this;
                theControlers[CPUIndex].chargesBook.Add(newChargeForBook);
                ListBoxItem f = new ListBoxItem();
                f.Content = newChargeForBook.getShortInformation();
                //AllChargeBook.Items.Add(f);

                CPUIndex         = getCPUIndexCanUse();
                newChargeForBook = new charge(8, 20, 18, 2, 2, "示例进程2", theControlers[CPUIndex], false);
                newChargeForBook.theMainWindow = this;
                theControlers[CPUIndex].chargesBook.Add(newChargeForBook);
                ListBoxItem f2 = new ListBoxItem();
                f2.Content = newChargeForBook.getShortInformation();
                //AllChargeBook.Items.Add(f2);

                CPUIndex         = getCPUIndexCanUse();
                newChargeForBook = new charge(6, 25, 25, 2, 3, "示例进程3", theControlers[CPUIndex], false);
                newChargeForBook.theMainWindow = this;
                theControlers[CPUIndex].chargesBook.Add(newChargeForBook);
                ListBoxItem f3 = new ListBoxItem();
                f3.Content = newChargeForBook.getShortInformation();
                //AllChargeBook.Items.Add(f3);

                for (int i = 0; i < theControlers.Count; i++)
                {
                    theControlers[i].makeChargeShower();
                    if (theControlers[i].schedulingMode == 2) //RM的特殊性
                    {
                        theControlers[i].theSort();           //排序
                        if (!this.checkForRM(theControlers[i].chargesBook))
                        {
                            MessageBox.Show("RM算法不可调度,有超时现象发生。");
                        }
                    }
                }
            }
            catch
            {
                Console.WriteLine("index error");
            }
        }
コード例 #9
0
ファイル: MainWindow.xaml.cs プロジェクト: BXZR/Scheduling
        public void getStream(stream theStream)
        {
            //int CPUIndex = getCPUIndexCanUse();

            //选择冲突最小的信道来处理
            int CPUIndex = getCPUIndexWithCanculate(theStream);

            for (int i = theControlers[CPUIndex].allTimer; i < theStream.allTimeUse; i++)
            {
                //---------------------------------------------------------------------------------
                for (int j = 0; j < theControlers.Count; j++)
                {
                    theControlers[j].forTimer();
                }
                //---------------------------------------------------------------------------------
                flashWindow();
            }
            //
            int timerWait = getWaitTimeForTheStream(theStream);

            //Console.WriteLine(this.Title + "get "+ theStream .theName+ " and send to " + CPUIndex);
            //在这里是一个模拟方案
            //一个新的任务需要完成本身的时间和等待的时间才可以将这个流转移到下一个节点

            charge newChargeForBook = new charge(theStream.timeSlot + timerWait, theStream.circleTime, theStream.deadLine, 1, theControlers[CPUIndex].allTimer, theStream.theName + "(第" + theStream.indexNow + "跳)", theControlers[CPUIndex], false);

            newChargeForBook.theStreamforCharge = theStream;
            newChargeForBook.theMainWindow      = this;

            //theControlers[CPUIndex].chargesBook.Add(newChargeForBook);
            theControlers[CPUIndex].charges.Add(newChargeForBook);
            theControlers[CPUIndex].schedule();
            //ListBoxItem f = new ListBoxItem();
            // f.Content = newChargeForBook.getShortInformation();
            //AllChargeBook.Items.Add(f);
        }
コード例 #10
0
ファイル: controller.cs プロジェクト: BXZR/Scheduling
        public void forTimer(bool work = true, bool canMissCrash = false)  //每一个时间单位都做些什么,算是总的调用方法
        {
            if (!work)
            {
                allTimer++;
                return;
            }

            theMainWindow.textForInformation += "\n" + theCPUName + "  第" + allTimer + "时钟——————————————\n";
            flashItems();
            for (int i = 0; i < chargesBook.Count; i++)
            {
                if ((((allTimer) % chargesBook[i].CircleTimer) == chargesBook[i].StartTime) && chargesBook[i].canAdd())
                {
                    charge aCharge = new charge(chargesBook[i], chargesBook[i].TimerCount, this);
                    aCharge.theMainWindow      = chargesBook[i].theMainWindow;
                    aCharge.theStreamforCharge = chargesBook[i].theStreamforCharge;

                    charges.Add(aCharge);
                    flashItems();
                    theMainWindow.textForInformation += chargesBook[i].Name + "新的实例到达,调度一次\n";
                    if (charges.Count == 0)
                    {
                        schedule();
                    }
                    else
                    {
                        schedule(1);
                    }
                }
            }
            if (isCanRob)
            {
                if (allTimer > 1)
                {
                    schedule(0);
                }
            }
            makePictures(selectedCharge);
            allTimer++;
            makeItem();

            if (canMissCrash)
            {
                bool isCrashed = selectedCharge.isCrashed();
                if (isCrashed)
                {
                    List <charge> toDelete = new List <charge>();
                    for (int i = 0; i < charges.Count; i++)
                    {
                        if (charges[i].Name == selectedCharge.Name)
                        {
                            toDelete.Add(charges [i]);
                        }
                    }
                    for (int i = 0; i < toDelete.Count; i++)
                    {
                        charges.Remove(toDelete [i]);
                    }
                    toDelete.Clear();
                    for (int i = 0; i < chargesBook.Count; i++)
                    {
                        if (theAllController[i].chargesBook[i].Name == selectedCharge.Name)
                        {
                            toDelete.Add(theAllController[i].chargesBook[i]);
                        }
                    }
                    for (int i = 0; i < toDelete.Count; i++)
                    {
                        theAllController[i].chargesBook.Remove(toDelete[i]);
                    }
                }
            }
            if (selectedCharge != null)
            {
                selectedCharge.work();
            }
            else
            {
                theMainWindow.textForInformation += "当前没有任何任务\n";
            }
        }
コード例 #11
0
ファイル: controller.cs プロジェクト: BXZR/Scheduling
 public void addCharge(charge newCharge)
 {
     charges.Add(newCharge);
 }
コード例 #12
0
ファイル: controller.cs プロジェクト: BXZR/Scheduling
 public showCharge(charge theCharge, int rowIndex)
 {
     this.theCharge = theCharge;
     this.rowIndex  = rowIndex;
 }