├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── misc.xml ├── modules.xml ├── uiDesigner.xml ├── vcs.xml └── workspace.xml ├── LICENSE ├── ProcessSchedulingRules.iml ├── README.md ├── images ├── 20151119115655.jpg ├── 20151119135721.jpg ├── 20151119220312.jpg ├── 20151119224410.jpg ├── 20151120010912.jpg └── 20151120141643.jpg └── src └── org └── rule └── process └── scheduling ├── TestSchedule.java ├── algorithm ├── AFPF.java ├── EDF.java ├── FCFS.java ├── LLF.java ├── ProcessSchedule.java ├── RFPF.java └── SPF.java ├── bll └── ProcessBLL.java ├── model ├── ProcessAFPFModel.java ├── ProcessEDFModel.java ├── ProcessFCFSModel.java ├── ProcessLLFModel.java ├── ProcessModel.java ├── ProcessRFPFModel.java └── ProcessSPFModel.java ├── sort └── QKSort.java └── tools ├── StringTools.java └── Tools.java /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Mobile Tools for Java (J2ME) 4 | .mtj.tmp/ 5 | 6 | # Package Files # 7 | *.jar 8 | *.war 9 | *.ear 10 | 11 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 12 | hs_err_pid* 13 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | ProcessSchedulingRules -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/uiDesigner.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/workspace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 15 | 16 | 17 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 81 | 82 | 83 | 89 | 90 | 93 | 94 | 95 | 124 | 125 | 126 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 192 | 193 | 206 | 207 | 208 | 212 | 213 | 214 | 241 | 242 | 243 | 271 | 272 | 279 | 280 | 281 | 294 | 295 | 296 | 303 | 306 | 308 | 309 | 310 | 311 | 312 | 313 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 373 | 374 | 375 | 386 | 387 | 394 | 395 | 396 | 397 | 415 | 422 | 423 | 424 | 425 | 443 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 1447894050885 467 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 529 | 532 | 533 | 534 | 536 | 537 | 538 | 540 | 541 | 542 | 543 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | 559 | 560 | 561 | 562 | 563 | 564 | 565 | 566 | 567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 | 625 | 626 | 627 | 628 | 629 | 630 | 631 | 632 | 633 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 | 643 | 644 | 645 | 646 | 647 | 648 | 649 | 650 | 651 | 652 | 653 | 654 | 655 | 656 | 657 | 658 | 659 | 660 | 661 | 662 | 663 | 664 | 665 | 666 | 667 | 668 | 669 | 670 | 671 | 672 | 673 | 674 | 675 | 676 | 677 | 678 | 679 | 680 | 681 | 682 | 683 | 684 | 685 | 686 | 687 | 688 | 689 | 690 | 691 | 692 | 693 | 694 | 695 | 696 | 697 | 698 | 699 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | 725 | 726 | 727 | 728 | 729 | 730 | 731 | 732 | 733 | 734 | 735 | 736 | 737 | 738 | 739 | 740 | 741 | 742 | 743 | 744 | 745 | 746 | 747 | 748 | 749 | 750 | 751 | 752 | 753 | 754 | 755 | 756 | 757 | 758 | 759 | 760 | 761 | 762 | 763 | 764 | 765 | 766 | 767 | 768 | 769 | 770 | 771 | 772 | 773 | 774 | 775 | 776 | 777 | 778 | 779 | 780 | 781 | 782 | 783 | 784 | 785 | 786 | 787 | 788 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | 341 | -------------------------------------------------------------------------------- /ProcessSchedulingRules.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ProcessSchedulingRules 2 | 各种进程调度的算法 3 | 4 | # FCFS 先来先服务算法 5 |
过程
6 | ![](https://github.com/William-Hai/ProcessSchedulingRules/blob/master/images/20151119220312.jpg) 7 |
结果
8 | ![](https://github.com/William-Hai/ProcessSchedulingRules/blob/master/images/20151119115655.jpg) 9 | # SPF 短进程优先算法 10 |
过程
11 | ![](https://github.com/William-Hai/ProcessSchedulingRules/blob/master/images/20151119224410.jpg) 12 |
结果
13 | ![](https://github.com/William-Hai/ProcessSchedulingRules/blob/master/images/20151119135721.jpg) 14 | # RFPF & AFPF (非)抢占式优先权算法 15 |
结果
16 | ![](https://github.com/William-Hai/ProcessSchedulingRules/blob/master/images/20151120141643.jpg) 17 |
18 |
19 | [本人博客首页](http://blog.csdn.net/lemon_tree12138) 20 | -------------------------------------------------------------------------------- /images/20151119115655.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qwhai/ProcessSchedulingRules/0a1410ec9dbae84200ff025ab79beb4a8bd421e1/images/20151119115655.jpg -------------------------------------------------------------------------------- /images/20151119135721.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qwhai/ProcessSchedulingRules/0a1410ec9dbae84200ff025ab79beb4a8bd421e1/images/20151119135721.jpg -------------------------------------------------------------------------------- /images/20151119220312.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qwhai/ProcessSchedulingRules/0a1410ec9dbae84200ff025ab79beb4a8bd421e1/images/20151119220312.jpg -------------------------------------------------------------------------------- /images/20151119224410.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qwhai/ProcessSchedulingRules/0a1410ec9dbae84200ff025ab79beb4a8bd421e1/images/20151119224410.jpg -------------------------------------------------------------------------------- /images/20151120010912.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qwhai/ProcessSchedulingRules/0a1410ec9dbae84200ff025ab79beb4a8bd421e1/images/20151120010912.jpg -------------------------------------------------------------------------------- /images/20151120141643.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qwhai/ProcessSchedulingRules/0a1410ec9dbae84200ff025ab79beb4a8bd421e1/images/20151120141643.jpg -------------------------------------------------------------------------------- /src/org/rule/process/scheduling/TestSchedule.java: -------------------------------------------------------------------------------- 1 | package org.rule.process.scheduling; 2 | 3 | import org.rule.process.scheduling.algorithm.AFPF; 4 | import org.rule.process.scheduling.algorithm.FCFS; 5 | import org.rule.process.scheduling.algorithm.RFPF; 6 | import org.rule.process.scheduling.algorithm.SPF; 7 | import org.rule.process.scheduling.bll.ProcessBLL; 8 | import org.rule.process.scheduling.model.ProcessAFPFModel; 9 | import org.rule.process.scheduling.model.ProcessFCFSModel; 10 | import org.rule.process.scheduling.model.ProcessRFPFModel; 11 | import org.rule.process.scheduling.model.ProcessSPFModel; 12 | import org.rule.process.scheduling.tools.StringTools; 13 | 14 | /** 15 | * 测试类 16 | * Created by Naga on 2015/11/19. 17 | * Blog : http://blog.csdn.net/lemon_tree12138 18 | */ 19 | public class TestSchedule { 20 | 21 | public static void main(String[] args) { 22 | TestSchedule schedule = new TestSchedule(); 23 | 24 | schedule.testFCFS(); 25 | System.out.println("---------------------------------------------------------------------------------"); 26 | schedule.testSPF(); 27 | System.out.println("---------------------------------------------------------------------------------"); 28 | schedule.testRFPF(); 29 | System.out.println("---------------------------------------------------------------------------------"); 30 | schedule.testAFPF(); 31 | } 32 | 33 | private void testFCFS() { 34 | FCFS fcfs = new FCFS(); 35 | ProcessFCFSModel[] processArray = ProcessBLL.getFCFSModelArray(); 36 | int timeSum = fcfs.execute(processArray); 37 | int turnaroundSum = 0; 38 | double turnaroundWeightSum = 0; 39 | System.out.println("FCFS总运行时间:" + timeSum + "(ms)"); 40 | System.out.println("进程调度过程:\n进程名\t到达时间\t服务时间\t开始时间\t完成时间\t周转时间\t带权周转时间"); 41 | for (ProcessFCFSModel process : processArray) { 42 | turnaroundSum += process.getTurnaroundTime(); 43 | turnaroundWeightSum += process.getTurnaroundWeightTime(); 44 | 45 | System.out.println(process.getProcessId() + "\t" + 46 | process.getComingTime() + "\t" + process.getRunTime() + "\t" + 47 | process.getStartRunTime() + "\t" + process.getFinishTime() + "\t" + 48 | process.getTurnaroundTime() + "\t" + StringTools.format(process.getTurnaroundWeightTime())); 49 | } 50 | 51 | System.out.println("平均周转时间:" + StringTools.format(turnaroundSum / processArray.length)); 52 | System.out.println("平均带权周转时间:" + StringTools.format(turnaroundWeightSum / processArray.length)); 53 | } 54 | 55 | private void testSPF() { 56 | ProcessSPFModel[] processArray = ProcessBLL.getSPFModelArray(); 57 | SPF spf = new SPF(); 58 | int timeSum = spf.execute(processArray); 59 | int turnaroundSum = 0; 60 | double turnaroundWeightSum = 0; 61 | System.out.println("SPF总运行时间:" + timeSum + "(ms)"); 62 | System.out.println("进程调度过程:\n进程名\t到达时间\t服务时间\t开始时间\t完成时间\t周转时间\t带权周转时间"); 63 | for (ProcessSPFModel process : processArray) { 64 | turnaroundSum += process.getTurnaroundTime(); 65 | turnaroundWeightSum += process.getTurnaroundWeightTime(); 66 | 67 | System.out.println(process.getProcessId() + "\t" + 68 | process.getComingTime() + "\t" + process.getRunTime() + "\t" + 69 | process.getStartRunTime() + "\t" + process.getFinishTime() + "\t" + 70 | process.getTurnaroundTime() + "\t" + StringTools.format(process.getTurnaroundWeightTime())); 71 | } 72 | 73 | System.out.println("平均周转时间:" + StringTools.format(turnaroundSum / processArray.length)); 74 | System.out.println("平均带权周转时间:" + StringTools.format(turnaroundWeightSum / processArray.length)); 75 | } 76 | 77 | private void testRFPF() { 78 | ProcessRFPFModel[] processArray = ProcessBLL.getRFPFModelArray(); 79 | RFPF rfpf = new RFPF(); 80 | int timeSum = rfpf.execute(processArray); 81 | int turnaroundSum = 0; 82 | double turnaroundWeightSum = 0; 83 | System.out.println("RFPF总运行时间:" + timeSum + "(ms)"); 84 | System.out.println("进程调度过程:\n进程名\t到达时间\t服务时间\t优先级\t开始时间\t完成时间\t周转时间\t带权周转时间"); 85 | for (ProcessRFPFModel process : processArray) { 86 | turnaroundSum += process.getTurnaroundTime(); 87 | turnaroundWeightSum += process.getTurnaroundWeightTime(); 88 | 89 | System.out.println(process.getProcessId() + "\t" + 90 | process.getComingTime() + "\t" + process.getRunTime() + "\t" + 91 | process.getPriority() + "\t" + 92 | process.getStartRunTime() + "\t" + process.getFinishTime() + "\t" + 93 | process.getTurnaroundTime() + "\t" + StringTools.format(process.getTurnaroundWeightTime())); 94 | } 95 | 96 | System.out.println("平均周转时间:" + StringTools.format(turnaroundSum / processArray.length)); 97 | System.out.println("平均带权周转时间:" + StringTools.format(turnaroundWeightSum / processArray.length)); 98 | } 99 | 100 | private void testAFPF() { 101 | ProcessAFPFModel[] processArray = ProcessBLL.getAFPFModelArray(); 102 | AFPF afpf = new AFPF(); 103 | int timeSum = afpf.execute(processArray); 104 | int turnaroundSum = 0; 105 | double turnaroundWeightSum = 0; 106 | System.out.println("AFPF总运行时间:" + timeSum + "(ms)"); 107 | System.out.println("进程调度过程:\n进程名\t到达时间\t服务时间\t优先级\t开始时间\t完成时间\t周转时间\t带权周转时间\t剩余时间"); 108 | for (ProcessAFPFModel process : processArray) { 109 | turnaroundSum += process.getTurnaroundTime(); 110 | turnaroundWeightSum += process.getTurnaroundWeightTime(); 111 | 112 | System.out.println(process.getProcessId() + "\t" + 113 | process.getComingTime() + "\t" + process.getRunTime() + "\t" + 114 | process.getPriority() + "\t" + process.getStartRunTime() + "\t" + 115 | process.getFinishTime() + "\t" + process.getTurnaroundTime() + "\t" + 116 | StringTools.format(process.getTurnaroundWeightTime()) + "\t" + process.getFreeTime()); 117 | } 118 | 119 | System.out.println("平均周转时间:" + StringTools.format(turnaroundSum / processArray.length)); 120 | System.out.println("平均带权周转时间:" + StringTools.format(turnaroundWeightSum / processArray.length)); 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /src/org/rule/process/scheduling/algorithm/AFPF.java: -------------------------------------------------------------------------------- 1 | package org.rule.process.scheduling.algorithm; 2 | 3 | import org.rule.process.scheduling.bll.ProcessBLL; 4 | import org.rule.process.scheduling.model.ProcessAFPFModel; 5 | import org.rule.process.scheduling.model.ProcessModel; 6 | import org.rule.process.scheduling.sort.QKSort; 7 | 8 | /** 9 | * 抢占式优先权调度算法(绝对优先权) 10 | * 本算法可以从时间的角度来模拟 11 | * 即随着时间的推移,进程逐个被完成. 12 | * 当有一个优先更高的进程进来时,当前进程被挂起 13 | * Created by Naga on 2015/11/19. 14 | * Blog : http://blog.csdn.net/lemon_tree12138 15 | */ 16 | public class AFPF implements ProcessSchedule { 17 | 18 | private static final String TAG = AFPF.class.getSimpleName(); 19 | 20 | @Override 21 | public int execute(ProcessModel... processList) { 22 | if (processList == null || processList.length == 0) { 23 | System.err.println(TAG + ">数据为空"); 24 | return -1; 25 | } 26 | 27 | if (!(processList instanceof ProcessAFPFModel[])) { 28 | System.err.println(TAG + ">数据类型出错"); 29 | return -2; 30 | } 31 | 32 | ProcessAFPFModel[] processes = (ProcessAFPFModel[]) processList; 33 | long[] comingTime = new long[processes.length]; 34 | recordComingTime(processes, comingTime); 35 | ProcessAFPFModel currentProcess = null; // 占用CPU的进程 36 | int index = -1; 37 | long currentTime = 0; // 当前时间 38 | while(!isDone(processes)) { 39 | index = getNextIndex(processes, currentTime); 40 | if (index > processes.length || index < 0) { 41 | System.err.println(TAG + ">未知异常"); 42 | break; 43 | } 44 | 45 | // 针对尚未初始化和已经运行结束的进程 46 | if (null == currentProcess || currentProcess.getFreeTime() <= 0) { 47 | currentProcess = processes[index]; 48 | } 49 | 50 | // 针对有抢占进程时 51 | if (!processes[index].getProcessId().equals(currentProcess.getProcessId())) { 52 | currentProcess = processes[index]; 53 | } 54 | 55 | // 针对中间CPU空闲的逻辑处理 56 | if (currentTime < currentProcess.getComingTime()) { 57 | currentTime = currentProcess.getComingTime(); 58 | } 59 | 60 | { // 进程被执行过程模拟 61 | currentProcess.reduceSelfFreeTime(); 62 | currentTime++; 63 | if (currentProcess.getFreeTime() <= 0) { 64 | currentProcess.setFinishTime(currentTime); 65 | currentProcess.setTurnaroundTime(currentProcess.getFinishTime() - currentProcess.getComingTime()); 66 | currentProcess.setTurnaroundWeightTime(1.0 * currentProcess.getTurnaroundTime() / currentProcess.getRunTime()); 67 | } 68 | } 69 | } 70 | 71 | return (int)currentTime; 72 | } 73 | 74 | /** 75 | * 获得将在下一个时间单位获得CPU的进程下标 76 | * 77 | * @param processAarry 78 | * 进程列表 79 | * @param currentTime 80 | * 当前时间 81 | * @return 82 | * 进程下标 83 | */ 84 | private int getNextIndex(ProcessAFPFModel[] processAarry, long currentTime) { 85 | int index = -1; 86 | if (processAarry == null || processAarry.length == 0) { 87 | return index; 88 | } 89 | 90 | int maxPriority = Integer.MIN_VALUE; 91 | int earliestIndex = -1; // 未执行的最早的进程 92 | long earliestTime = Long.MAX_VALUE; 93 | int earliestMaxPriority = Integer.MIN_VALUE; 94 | for (int i = 0; i < processAarry.length; i++) { 95 | if (processAarry[i].getFreeTime() <= 0) { 96 | continue; 97 | } 98 | 99 | // 过滤尚未到达的进程 100 | if (!ProcessBLL.isProcessComing(processAarry[i], currentTime)) { 101 | if (earliestTime > processAarry[i].getComingTime()) { 102 | earliestIndex = i; 103 | earliestTime = processAarry[i].getComingTime(); 104 | earliestMaxPriority = processAarry[i].getPriority(); 105 | } else if (earliestTime == processAarry[i].getComingTime()) { 106 | if (earliestMaxPriority < processAarry[i].getPriority()) { 107 | earliestMaxPriority = processAarry[i].getPriority(); 108 | earliestIndex = i; 109 | } 110 | } 111 | continue; 112 | } 113 | 114 | if (maxPriority < processAarry[i].getPriority()) { 115 | maxPriority = processAarry[i].getPriority(); 116 | index = i; 117 | } 118 | } 119 | 120 | index = index < 0 ? earliestIndex : index; 121 | 122 | return index; 123 | } 124 | 125 | /** 126 | * 是否所有的进程都执行完毕 127 | * 128 | * @param array 129 | * 进程列表 130 | * @return 131 | * 是否执行结束 132 | */ 133 | private boolean isDone(ProcessAFPFModel[] array) { 134 | for (ProcessAFPFModel process : array) { 135 | if (process.getFreeTime() > 0) { 136 | return false; 137 | } 138 | } 139 | 140 | return true; 141 | } 142 | 143 | /** 144 | * 记录下当前进程的到达时间 145 | * 146 | * @param array 147 | * 进程队列 148 | * @param times 149 | * 进程到达时间列表 150 | */ 151 | private void recordComingTime(ProcessAFPFModel[] array, long[] times) { 152 | if (times == null || times.length == 0) { 153 | times = new long[array.length]; 154 | } 155 | 156 | for (int i = 0; i < array.length; i++) { 157 | times[i] = array[i].getComingTime(); 158 | } 159 | 160 | QKSort.quickSort(times); 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /src/org/rule/process/scheduling/algorithm/EDF.java: -------------------------------------------------------------------------------- 1 | package org.rule.process.scheduling.algorithm; 2 | 3 | import org.rule.process.scheduling.model.ProcessModel; 4 | 5 | /** 6 | * 最早截止时间优先即EDF(Earliest Deadline First)算法 7 | * Created by Naga on 2015/11/19. 8 | * Blog : http://blog.csdn.net/lemon_tree12138 9 | */ 10 | public class EDF implements ProcessSchedule { 11 | 12 | @Override 13 | public int execute(ProcessModel... processList) { 14 | return 0; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/org/rule/process/scheduling/algorithm/FCFS.java: -------------------------------------------------------------------------------- 1 | package org.rule.process.scheduling.algorithm; 2 | 3 | import org.rule.process.scheduling.model.ProcessFCFSModel; 4 | import org.rule.process.scheduling.model.ProcessModel; 5 | 6 | /** 7 | * 先来先服务算法 8 | * Created by Naga on 2015/11/19. 9 | * Blog : http://blog.csdn.net/lemon_tree12138 10 | */ 11 | public class FCFS implements ProcessSchedule { 12 | 13 | private static final String TAG = FCFS.class.getSimpleName(); 14 | 15 | @Override 16 | public int execute(ProcessModel... processList) { 17 | if (processList == null || processList.length == 0) { 18 | System.out.println(TAG + ">数据为空"); 19 | return -1; 20 | } 21 | 22 | if (!(processList instanceof ProcessFCFSModel[])) { 23 | System.out.println(TAG + ">数据类型出错"); 24 | return -2; 25 | } 26 | 27 | ProcessFCFSModel[] fcfsModels = (ProcessFCFSModel[])processList; 28 | int runTimeSum = 0; 29 | for (ProcessFCFSModel model : fcfsModels) { 30 | if (runTimeSum < model.getComingTime()) { 31 | runTimeSum = (int)model.getComingTime(); 32 | } 33 | 34 | model.setStartRunTime(runTimeSum); 35 | runTimeSum += model.getRunTime(); 36 | model.setFinishTime(runTimeSum); 37 | model.setTurnaroundTime(runTimeSum - model.getComingTime()); 38 | model.setTurnaroundWeightTime(1.0 * model.getTurnaroundTime() / model.getRunTime()); 39 | } 40 | 41 | return runTimeSum; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/org/rule/process/scheduling/algorithm/LLF.java: -------------------------------------------------------------------------------- 1 | package org.rule.process.scheduling.algorithm; 2 | 3 | import org.rule.process.scheduling.model.ProcessModel; 4 | 5 | /** 6 | * 最低松弛度优先即LLF(Least Laxity First)算法 7 | * Created by Naga on 2015/11/19. 8 | * Blog : http://blog.csdn.net/lemon_tree12138 9 | */ 10 | public class LLF implements ProcessSchedule { 11 | 12 | @Override 13 | public int execute(ProcessModel... processList) { 14 | return 0; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/org/rule/process/scheduling/algorithm/ProcessSchedule.java: -------------------------------------------------------------------------------- 1 | package org.rule.process.scheduling.algorithm; 2 | 3 | import org.rule.process.scheduling.model.ProcessModel; 4 | 5 | /** 6 | * 进程调度接口 7 | * 其他的进程调度算法类都是要来实现这个接口 8 | * Created by Naga on 2015/11/19. 9 | * Blog : http://blog.csdn.net/lemon_tree12138 10 | */ 11 | public interface ProcessSchedule { 12 | 13 | int execute(ProcessModel ... processList); 14 | } 15 | -------------------------------------------------------------------------------- /src/org/rule/process/scheduling/algorithm/RFPF.java: -------------------------------------------------------------------------------- 1 | package org.rule.process.scheduling.algorithm; 2 | 3 | import org.rule.process.scheduling.bll.ProcessBLL; 4 | import org.rule.process.scheduling.model.ProcessModel; 5 | import org.rule.process.scheduling.model.ProcessRFPFModel; 6 | 7 | /** 8 | * 非抢占式优先权算法(相对优先权) 9 | * Created by Naga on 2015/11/19. 10 | * Blog : http://blog.csdn.net/lemon_tree12138 11 | */ 12 | public class RFPF implements ProcessSchedule { 13 | 14 | private static final String TAG = RFPF.class.getSimpleName(); 15 | 16 | @Override 17 | public int execute(ProcessModel... processList) { 18 | if (processList == null || processList.length == 0) { 19 | System.out.println(TAG + ">数据为空"); 20 | return -1; 21 | } 22 | 23 | if (!(processList instanceof ProcessRFPFModel[])) { 24 | System.out.println(TAG + ">数据类型出错"); 25 | return -2; 26 | } 27 | 28 | ProcessRFPFModel[] processes = (ProcessRFPFModel[])processList; 29 | boolean[] runFlag = new boolean[processes.length]; 30 | int currentTime = 0; 31 | int index = -1; 32 | ProcessRFPFModel currentProcess; 33 | for (int i = 0; i < processes.length; i++) { 34 | index = getIndexComingMaxPriority(processes, runFlag, currentTime); 35 | if (0 <= index && index <= processes.length) { 36 | currentProcess = processes[index]; 37 | if (currentTime < currentProcess.getComingTime()) { 38 | currentTime = (int)currentProcess.getComingTime(); 39 | } 40 | 41 | currentProcess.setStartRunTime(currentTime); 42 | currentTime += currentProcess.getRunTime(); 43 | currentProcess.setFinishTime(currentTime); 44 | currentProcess.setTurnaroundTime(currentTime - currentProcess.getComingTime()); 45 | currentProcess.setTurnaroundWeightTime(1.0 * currentProcess.getTurnaroundTime() / currentProcess.getRunTime()); 46 | 47 | runFlag[index] = true; 48 | } else { 49 | System.out.println("未知异常"); 50 | break; 51 | } 52 | } 53 | 54 | return currentTime; 55 | } 56 | 57 | /** 58 | * 获得队列中已经到达、尚未执行且优先权最大的进程下标 59 | * 如果在尚未执行的进程队列中,所有的都未到达,就取最先到达的 60 | * 61 | * @param processes 62 | * 进程队列 63 | * @param runFlag 64 | * 进程执行标志 65 | * @param currentTime 66 | * 当前时间 67 | * @return 68 | * 进程下标 69 | */ 70 | private int getIndexComingMaxPriority(ProcessRFPFModel[] processes, boolean[] runFlag, int currentTime) { 71 | int maxPriority = Integer.MIN_VALUE; 72 | int maxPriorityIndex = -1; 73 | int earliestIndex = -1; // 未执行的最早的进程 74 | long earliestTime = Long.MAX_VALUE; 75 | ProcessRFPFModel currentProcess; 76 | for (int i = 0; i < processes.length; i++) { 77 | if (runFlag[i]) { 78 | continue; 79 | } 80 | 81 | currentProcess = processes[i]; 82 | if (!ProcessBLL.isProcessComing(currentProcess, currentTime)) { 83 | if (earliestTime > currentProcess.getComingTime()) { 84 | earliestIndex = i; 85 | earliestTime = currentProcess.getComingTime(); 86 | } 87 | continue; 88 | } 89 | 90 | if (currentProcess.getPriority() > maxPriority) { 91 | maxPriority = currentProcess.getPriority(); 92 | maxPriorityIndex = i; 93 | } 94 | } 95 | 96 | maxPriorityIndex = maxPriorityIndex < 0 ? earliestIndex : maxPriorityIndex; 97 | 98 | return maxPriorityIndex; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/org/rule/process/scheduling/algorithm/SPF.java: -------------------------------------------------------------------------------- 1 | package org.rule.process.scheduling.algorithm; 2 | 3 | import org.rule.process.scheduling.bll.ProcessBLL; 4 | import org.rule.process.scheduling.model.ProcessModel; 5 | import org.rule.process.scheduling.model.ProcessSPFModel; 6 | 7 | /** 8 | * 短进程优先 9 | * Created by Naga on 2015/11/19. 10 | * Blog : http://blog.csdn.net/lemon_tree12138 11 | */ 12 | public class SPF implements ProcessSchedule { 13 | 14 | private static final String TAG = SPF.class.getSimpleName(); 15 | 16 | @Override 17 | public int execute(ProcessModel... processList) { 18 | if (processList == null || processList.length == 0) { 19 | System.out.println(TAG + ">数据为空"); 20 | return -1; 21 | } 22 | 23 | if (!(processList instanceof ProcessSPFModel[])) { 24 | System.out.println(TAG + ">数据类型出错"); 25 | return -2; 26 | } 27 | 28 | ProcessSPFModel[] processArray = (ProcessSPFModel[])processList; 29 | boolean[]runFlag = new boolean[processArray.length]; 30 | int runTimeSum = 0; 31 | int index = 0; 32 | ProcessSPFModel currentProcess = processArray[index]; 33 | while(!ProcessBLL.noProcessWaitting(runFlag)) { 34 | currentProcess.setStartRunTime(runTimeSum); 35 | if (runTimeSum < currentProcess.getComingTime()) { 36 | runTimeSum = (int)currentProcess.getComingTime(); 37 | } 38 | 39 | runTimeSum += currentProcess.getRunTime(); 40 | currentProcess.setFinishTime(runTimeSum); 41 | currentProcess.setTurnaroundTime(runTimeSum - currentProcess.getComingTime()); 42 | currentProcess.setTurnaroundWeightTime(1.0 * currentProcess.getTurnaroundTime() / currentProcess.getRunTime()); 43 | 44 | runFlag[index] = true; 45 | 46 | index = getIndexMinRuntime(processArray, runFlag, runTimeSum); 47 | if (0 <= index && index < processArray.length) { 48 | currentProcess = processArray[index]; 49 | } else { 50 | System.out.println("未知异常"); 51 | break; 52 | } 53 | } 54 | 55 | return runTimeSum; 56 | } 57 | 58 | /** 59 | * 获得进程列表中服务时间最短的进程 60 | * @param processArray 61 | * 进程列表 62 | * @param runFlag 63 | * 进程运行标志位 64 | * @return 65 | * 进程下标 66 | */ 67 | private int getIndexMinRuntime(ProcessSPFModel[] processArray, boolean[] runFlag, int runTimeSum) { 68 | if (processArray.length == 0 || runFlag.length != processArray.length) { 69 | return -1; 70 | } 71 | 72 | int earliestIndex = 0; // 未执行的最早的进程 73 | long earliestTime = Long.MAX_VALUE; 74 | int index = -1; 75 | long minTime = Long.MAX_VALUE; 76 | for (int i = 0; i < processArray.length; i++) { 77 | if (runFlag[i]) { 78 | continue; 79 | } 80 | 81 | if (processArray[i].getComingTime() < earliestTime) { 82 | earliestIndex = i; 83 | earliestTime = processArray[i].getComingTime(); 84 | } 85 | 86 | if (processArray[i].getComingTime() > runTimeSum) { 87 | continue; 88 | } 89 | 90 | if (processArray[i].getRunTime() < minTime) { 91 | minTime = processArray[i].getRunTime(); 92 | index = i; 93 | } 94 | } 95 | 96 | index = index < 0 ? earliestIndex : index; 97 | 98 | return index; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/org/rule/process/scheduling/bll/ProcessBLL.java: -------------------------------------------------------------------------------- 1 | package org.rule.process.scheduling.bll; 2 | 3 | import org.rule.process.scheduling.model.*; 4 | 5 | /** 6 | * 算法帮助类 7 | * Created by Naga on 2015/11/19. 8 | * Blog : http://blog.csdn.net/lemon_tree12138 9 | */ 10 | public class ProcessBLL { 11 | 12 | public static ProcessFCFSModel[] getFCFSModelArray() { 13 | 14 | ProcessFCFSModel[] models = new ProcessFCFSModel[5]; 15 | 16 | models[0] = new ProcessFCFSModel("A", 4, 0); 17 | models[1] = new ProcessFCFSModel("B", 3, 1); 18 | models[2] = new ProcessFCFSModel("C", 5, 2); 19 | models[3] = new ProcessFCFSModel("D", 2, 3); 20 | models[4] = new ProcessFCFSModel("E", 4, 4); 21 | 22 | return models; 23 | } 24 | 25 | public static ProcessSPFModel[] getSPFModelArray() { 26 | 27 | ProcessSPFModel[] models = new ProcessSPFModel[5]; 28 | 29 | models[0] = new ProcessSPFModel("A", 4, 0); 30 | models[1] = new ProcessSPFModel("B", 3, 1); 31 | models[2] = new ProcessSPFModel("C", 5, 2); 32 | models[3] = new ProcessSPFModel("D", 2, 3); 33 | models[4] = new ProcessSPFModel("E", 4, 4); 34 | 35 | return models; 36 | } 37 | 38 | public static ProcessRFPFModel[] getRFPFModelArray() { 39 | 40 | ProcessRFPFModel[] models = new ProcessRFPFModel[6]; 41 | 42 | models[0] = new ProcessRFPFModel("A", 4, 0, 1); 43 | models[1] = new ProcessRFPFModel("B", 4, 1, 2); 44 | models[2] = new ProcessRFPFModel("C", 4, 3, 3); 45 | models[3] = new ProcessRFPFModel("D", 1, 5, 4); 46 | models[4] = new ProcessRFPFModel("E", 2, 14, 3); 47 | models[5] = new ProcessRFPFModel("F", 3, 15, 4); 48 | 49 | return models; 50 | } 51 | 52 | public static ProcessAFPFModel[] getAFPFModelArray() { 53 | 54 | ProcessAFPFModel[] models = new ProcessAFPFModel[6]; 55 | 56 | models[0] = new ProcessAFPFModel("A", 4, 0, 1); 57 | models[1] = new ProcessAFPFModel("B", 4, 1, 2); 58 | models[2] = new ProcessAFPFModel("C", 4, 3, 3); 59 | models[3] = new ProcessAFPFModel("D", 1, 5, 4); 60 | models[4] = new ProcessAFPFModel("E", 2, 14, 3); 61 | models[5] = new ProcessAFPFModel("F", 3, 15, 4); 62 | 63 | return models; 64 | } 65 | 66 | /** 67 | * 判断所有进行是否都已经运行完毕 68 | * @param runFlag 69 | * 进程队列中的进程运行情况 70 | * @return 71 | * 是否全部执行结束 72 | */ 73 | public static boolean noProcessWaitting(boolean[] runFlag) { 74 | for (boolean flag : runFlag) { 75 | if (!flag) { 76 | return false; 77 | } 78 | } 79 | 80 | return true; 81 | } 82 | 83 | /** 84 | * 判断一个进程是否已经到达 85 | * @param process 86 | * 进程 87 | * @param currentTime 88 | * 当前时间 89 | * @return 90 | * 是否到达 91 | */ 92 | public static boolean isProcessComing(ProcessModel process, long currentTime) { 93 | 94 | 95 | if (process instanceof ProcessFCFSModel) { 96 | return ((ProcessFCFSModel)process).getComingTime() <= currentTime; 97 | } 98 | 99 | if (process instanceof ProcessSPFModel) { 100 | return ((ProcessSPFModel)process).getComingTime() <= currentTime; 101 | } 102 | 103 | if (process instanceof ProcessRFPFModel) { 104 | return ((ProcessRFPFModel)process).getComingTime() <= currentTime; 105 | } 106 | 107 | if (process instanceof ProcessAFPFModel) { 108 | return ((ProcessAFPFModel)process).getComingTime() <= currentTime; 109 | } 110 | 111 | return false; 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /src/org/rule/process/scheduling/model/ProcessAFPFModel.java: -------------------------------------------------------------------------------- 1 | package org.rule.process.scheduling.model; 2 | 3 | /** 4 | * 模拟抢占式优先权算法(绝对优先权)进程对象 5 | * Created by Naga on 2015/11/20. 6 | * Blog : http://blog.csdn.net/lemon_tree12138 7 | */ 8 | public class ProcessAFPFModel extends ProcessModel { 9 | 10 | private long comingTime; // 到达时间 11 | private int priority; // 进程优先级 12 | private long startRunTime; // 开始执行时间 13 | private long freeTime; // 剩余时间(针对中间被中断过的进程而言) 14 | private long finishTime; // 完成时间 15 | private long turnaroundTime; // 周转时间 16 | private double turnaroundWeightTime; // 带权周转时间 17 | 18 | public ProcessAFPFModel(String processId, long runTime, long comingTime, int priority) { 19 | this.processId = processId; 20 | this.runTime = runTime; 21 | this.comingTime = comingTime; 22 | this.freeTime = this.runTime; 23 | this.priority = priority; 24 | } 25 | 26 | public long getComingTime() { 27 | return comingTime; 28 | } 29 | 30 | public void setComingTime(long comingTime) { 31 | this.comingTime = comingTime; 32 | } 33 | 34 | public int getPriority() { 35 | return priority; 36 | } 37 | 38 | public void setPriority(int priority) { 39 | this.priority = priority; 40 | } 41 | 42 | public long getStartRunTime() { 43 | return startRunTime; 44 | } 45 | 46 | public void setStartRunTime(long startRunTime) { 47 | this.startRunTime = startRunTime; 48 | } 49 | 50 | public long getFreeTime() { 51 | return freeTime; 52 | } 53 | 54 | public void setFreeTime(long freeTime) { 55 | this.freeTime = freeTime; 56 | } 57 | 58 | public void reduceSelfFreeTime() { 59 | this.freeTime--; 60 | } 61 | 62 | public long getFinishTime() { 63 | return finishTime; 64 | } 65 | 66 | public void setFinishTime(long finishTime) { 67 | this.finishTime = finishTime; 68 | } 69 | 70 | public long getTurnaroundTime() { 71 | return turnaroundTime; 72 | } 73 | 74 | public void setTurnaroundTime(long turnaroundTime) { 75 | this.turnaroundTime = turnaroundTime; 76 | } 77 | 78 | public double getTurnaroundWeightTime() { 79 | return turnaroundWeightTime; 80 | } 81 | 82 | public void setTurnaroundWeightTime(double turnaroundWeightTime) { 83 | this.turnaroundWeightTime = turnaroundWeightTime; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/org/rule/process/scheduling/model/ProcessEDFModel.java: -------------------------------------------------------------------------------- 1 | package org.rule.process.scheduling.model; 2 | 3 | /** 4 | * 模拟最早截止时间优先即EDF(Earliest Deadline First)算法对象 5 | * Created by Naga on 2015/11/19. 6 | * Blog : http://blog.csdn.net/lemon_tree12138 7 | */ 8 | public class ProcessEDFModel extends ProcessModel { 9 | 10 | private long startTime; // 进程开始截止时间 11 | 12 | private long deadline; // 进程结束截止时间 13 | 14 | public long getStartTime() { 15 | return startTime; 16 | } 17 | 18 | public void setStartTime(long startTime) { 19 | this.startTime = startTime; 20 | } 21 | 22 | public long getDeadline() { 23 | return deadline; 24 | } 25 | 26 | public void setDeadline(long deadline) { 27 | this.deadline = deadline; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/org/rule/process/scheduling/model/ProcessFCFSModel.java: -------------------------------------------------------------------------------- 1 | package org.rule.process.scheduling.model; 2 | 3 | /** 4 | * 模拟FCFS的进程对象 5 | * Created by Naga on 2015/11/19. 6 | * Blog : http://blog.csdn.net/lemon_tree12138 7 | */ 8 | public class ProcessFCFSModel extends ProcessModel { 9 | 10 | private long comingTime; // 到达时间 11 | private long startRunTime; // 开始执行时间 12 | private long finishTime; // 完成时间 13 | private long turnaroundTime; // 周转时间 14 | private double turnaroundWeightTime; // 带权周转时间 15 | 16 | public ProcessFCFSModel(String processId, long runTime, long comingTime) { 17 | this.processId = processId; 18 | this.runTime = runTime; 19 | this.comingTime = comingTime; 20 | } 21 | 22 | public long getComingTime() { 23 | return comingTime; 24 | } 25 | 26 | public void setComingTime(long comingTime) { 27 | this.comingTime = comingTime; 28 | } 29 | 30 | public long getStartRunTime() { 31 | return startRunTime; 32 | } 33 | 34 | public void setStartRunTime(long startRunTime) { 35 | this.startRunTime = startRunTime; 36 | } 37 | 38 | public long getFinishTime() { 39 | return finishTime; 40 | } 41 | 42 | public void setFinishTime(long finishTime) { 43 | this.finishTime = finishTime; 44 | } 45 | 46 | public long getTurnaroundTime() { 47 | return turnaroundTime; 48 | } 49 | 50 | public void setTurnaroundTime(long turnaroundTime) { 51 | this.turnaroundTime = turnaroundTime; 52 | } 53 | 54 | public double getTurnaroundWeightTime() { 55 | return turnaroundWeightTime; 56 | } 57 | 58 | public void setTurnaroundWeightTime(double turnaroundWeightTime) { 59 | this.turnaroundWeightTime = turnaroundWeightTime; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/org/rule/process/scheduling/model/ProcessLLFModel.java: -------------------------------------------------------------------------------- 1 | package org.rule.process.scheduling.model; 2 | 3 | /** 4 | * Created by Naga on 2015/11/19. 5 | * Blog : http://blog.csdn.net/lemon_tree12138 6 | */ 7 | public class ProcessLLFModel extends ProcessModel { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/org/rule/process/scheduling/model/ProcessModel.java: -------------------------------------------------------------------------------- 1 | package org.rule.process.scheduling.model; 2 | 3 | /** 4 | * 单个进程对象 5 | * Created by Naga on 2015/11/19. 6 | * Blog : http://blog.csdn.net/lemon_tree12138 7 | */ 8 | public class ProcessModel { 9 | 10 | String processId; // 进程标识 11 | 12 | long runTime; // 进程完整执行预计的时间 13 | 14 | 15 | 16 | public String getProcessId() { 17 | return processId; 18 | } 19 | 20 | public void setProcessId(String processId) { 21 | this.processId = processId; 22 | } 23 | 24 | public long getRunTime() { 25 | return runTime; 26 | } 27 | 28 | public void setRunTime(long runTime) { 29 | this.runTime = runTime; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/org/rule/process/scheduling/model/ProcessRFPFModel.java: -------------------------------------------------------------------------------- 1 | package org.rule.process.scheduling.model; 2 | 3 | /** 4 | * 模拟非抢占式优先权算法(相对优先权)进程对象 5 | * Created by Coding on 2015/11/20. 6 | * Blog : http://blog.csdn.net/lemon_tree12138 7 | */ 8 | public class ProcessRFPFModel extends ProcessModel { 9 | 10 | private long comingTime; // 到达时间 11 | private int priority; // 进程优先级 12 | private long startRunTime; // 开始执行时间 13 | private long finishTime; // 完成时间 14 | private long turnaroundTime; // 周转时间 15 | private double turnaroundWeightTime; // 带权周转时间 16 | 17 | public ProcessRFPFModel(String processId, long runTime, long comingTime, int priority) { 18 | this.processId = processId; 19 | this.runTime = runTime; 20 | this.comingTime = comingTime; 21 | this.priority = priority; 22 | } 23 | 24 | public long getComingTime() { 25 | return comingTime; 26 | } 27 | 28 | public void setComingTime(long comingTime) { 29 | this.comingTime = comingTime; 30 | } 31 | 32 | public int getPriority() { 33 | return priority; 34 | } 35 | 36 | public void setPriority(int priority) { 37 | this.priority = priority; 38 | } 39 | 40 | public long getStartRunTime() { 41 | return startRunTime; 42 | } 43 | 44 | public void setStartRunTime(long startRunTime) { 45 | this.startRunTime = startRunTime; 46 | } 47 | 48 | public long getFinishTime() { 49 | return finishTime; 50 | } 51 | 52 | public void setFinishTime(long finishTime) { 53 | this.finishTime = finishTime; 54 | } 55 | 56 | public long getTurnaroundTime() { 57 | return turnaroundTime; 58 | } 59 | 60 | public void setTurnaroundTime(long turnaroundTime) { 61 | this.turnaroundTime = turnaroundTime; 62 | } 63 | 64 | public double getTurnaroundWeightTime() { 65 | return turnaroundWeightTime; 66 | } 67 | 68 | public void setTurnaroundWeightTime(double turnaroundWeightTime) { 69 | this.turnaroundWeightTime = turnaroundWeightTime; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/org/rule/process/scheduling/model/ProcessSPFModel.java: -------------------------------------------------------------------------------- 1 | package org.rule.process.scheduling.model; 2 | 3 | /** 4 | * 模拟SPF的进程对象 5 | * Created by Naga on 2015/11/19. 6 | * Blog : http://blog.csdn.net/lemon_tree12138 7 | */ 8 | public class ProcessSPFModel extends ProcessModel { 9 | 10 | private long comingTime; // 到达时间 11 | private long startRunTime; // 开始执行时间 12 | private long finishTime; // 完成时间 13 | private long turnaroundTime; // 周转时间 14 | private double turnaroundWeightTime; // 带权周转时间 15 | 16 | public ProcessSPFModel(String processId, long runTime, long comingTime) { 17 | this.processId = processId; 18 | this.runTime = runTime; 19 | this.comingTime = comingTime; 20 | } 21 | 22 | public long getComingTime() { 23 | return comingTime; 24 | } 25 | 26 | public void setComingTime(long comingTime) { 27 | this.comingTime = comingTime; 28 | } 29 | 30 | public long getStartRunTime() { 31 | return startRunTime; 32 | } 33 | 34 | public void setStartRunTime(long startRunTime) { 35 | this.startRunTime = startRunTime; 36 | } 37 | 38 | public long getFinishTime() { 39 | return finishTime; 40 | } 41 | 42 | public void setFinishTime(long finishTime) { 43 | this.finishTime = finishTime; 44 | } 45 | 46 | public long getTurnaroundTime() { 47 | return turnaroundTime; 48 | } 49 | 50 | public void setTurnaroundTime(long turnaroundTime) { 51 | this.turnaroundTime = turnaroundTime; 52 | } 53 | 54 | public double getTurnaroundWeightTime() { 55 | return turnaroundWeightTime; 56 | } 57 | 58 | public void setTurnaroundWeightTime(double turnaroundWeightTime) { 59 | this.turnaroundWeightTime = turnaroundWeightTime; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/org/rule/process/scheduling/sort/QKSort.java: -------------------------------------------------------------------------------- 1 | package org.rule.process.scheduling.sort; 2 | 3 | /** 4 | * 快速排序 5 | * Created by Naga on 2015/11/20. 6 | * Blog : http://blog.csdn.net/lemon_tree12138 7 | */ 8 | public class QKSort { 9 | 10 | public static long[] quickSort(long[] array) { 11 | if (array != null) { 12 | return quickSort(array, 0, array.length - 1); 13 | } 14 | 15 | return null; 16 | } 17 | 18 | private static long[] quickSort(long[] array, int beg, int end) { 19 | if (beg >= end || array == null) { 20 | return null; 21 | } 22 | 23 | int p = partition(array, beg, end); 24 | 25 | quickSort(array, beg, p - 1); 26 | quickSort(array, p + 1, end); 27 | 28 | return array; 29 | } 30 | 31 | /** 32 | * 找到分界点 33 | * 34 | * @param array 35 | * @param beg 36 | * @param end 37 | * @return 38 | */ 39 | private static int partition(long[] array, int beg, int end) { 40 | long last = array[end]; 41 | int i = beg - 1; 42 | 43 | for (int j = beg; j <= end - 1; j++) { 44 | if (array[j] <= last) { 45 | i++; 46 | if (i != j) { 47 | array = getSwap(array, i, j); 48 | } 49 | } 50 | } 51 | 52 | if ((i + 1) != end) { 53 | array = getSwap(array, i + 1, end); 54 | } 55 | 56 | return i + 1; 57 | } 58 | 59 | /** 60 | * 交换array数组中的第i个元素和第j个元素 61 | * 62 | * @param a 63 | * @param i 64 | * @param j 65 | * @return 66 | */ 67 | private static long[] getSwap(long[] a, int i, int j) { 68 | a[i] = a[i] ^ a[j]; 69 | a[j] = a[i] ^ a[j]; 70 | a[i] = a[i] ^ a[j]; 71 | 72 | return a; 73 | } 74 | } -------------------------------------------------------------------------------- /src/org/rule/process/scheduling/tools/StringTools.java: -------------------------------------------------------------------------------- 1 | package org.rule.process.scheduling.tools; 2 | 3 | import java.util.regex.Matcher; 4 | import java.util.regex.Pattern; 5 | 6 | /** 7 | * Blog : http://blog.csdn.net/lemon_tree12138 8 | */ 9 | public class StringTools extends Tools { 10 | 11 | /** 12 | * 判断一个字符串是否为空字符串 13 | * 14 | * @param text 15 | * 待判断的字符串 16 | * @return 是否为空字符串 17 | */ 18 | public static boolean isEmpty(String text) { 19 | if (text == null || text.length() == 0) { 20 | return true; 21 | } 22 | 23 | return false; 24 | } 25 | 26 | /** 27 | * 获得匹配的字符串 28 | * 29 | * @param str 30 | * 待匹配的字符串 31 | * @param re 32 | * 匹配的正则表达式 33 | * @return 返回匹配结果 34 | */ 35 | public static String getSub(String str, String re) { 36 | String name = ""; 37 | Pattern pattern = Pattern.compile(re); 38 | Matcher match = pattern.matcher(str); 39 | if (match.find(0)) { 40 | name = match.group(); 41 | } 42 | 43 | return name; 44 | } 45 | 46 | /** 47 | * 判断一段字符串中是否包含中文 48 | * 49 | * @param text 50 | * 待匹配的字符串 51 | * @return 52 | * 是否包含中文 53 | */ 54 | public static boolean hasChinese(String text) { 55 | // 匹配的字符串的正则表达式 56 | String reg_charset = "[\u4e00-\u9fa5]*"; 57 | 58 | Pattern p = Pattern.compile(reg_charset); 59 | Matcher m = p.matcher(text); 60 | 61 | while (m.find()) { 62 | if (m.group().length() > 0) { 63 | return true; 64 | } 65 | } 66 | 67 | return false; 68 | } 69 | 70 | /** 71 | * 判断str是否匹配正则表达式re 72 | * 73 | * @param str 74 | * 待匹配的字符串 75 | * @param re 76 | * 匹配的正则表达式 77 | * @return 78 | * 匹配结果 79 | */ 80 | public static boolean isSub(String str, String re) { 81 | Pattern pattern = Pattern.compile(re); 82 | Matcher match = pattern.matcher(str); 83 | if (match.find(0)) { 84 | return true; 85 | } 86 | 87 | return false; 88 | } 89 | 90 | public static String format(double number) { 91 | return (String.format("%.2f", number)); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/org/rule/process/scheduling/tools/Tools.java: -------------------------------------------------------------------------------- 1 | package org.rule.process.scheduling.tools; 2 | 3 | /** 4 | * Created by Naga on 2015/11/19. 5 | * Blog : http://blog.csdn.net/lemon_tree12138 6 | */ 7 | public abstract class Tools { 8 | 9 | public String toString() { 10 | return Tools.class.getName(); 11 | } 12 | } 13 | --------------------------------------------------------------------------------