第二单元总结性博客作业
第二单元总结性博客作业
架构设计
第一、二次作业
- 设计WaitingQueue类(等待队列)、Scheduler类(调度器)、Elevator类(电梯)、SafeOutput类(阻塞输出)。
第三次作业
- 由于换乘复杂,单层调度器不能满足第三次作业的需求了,设计主调度器和次级调度器。
- 还建立了PartRequest类,把每个请求拆分成1至3个请求。
- 增添Counter类,作为主调度器结束条件。
基于度量分析程序结构
经典OO度量
CogC 认知复杂度
ev(G) 基本复杂度是用来衡量程序非结构化程度的,非结构成分降低了程序的质量,增加了代码的维护难度,使程序难于理解。因此,基本复杂度高意味着非结构化程度高,难以模块化和维护。实际上,消除了一个错误有时会引起其他的错误。
iv(G) 模块设计复杂度是用来衡量模块判定结构,即模块和其他模块的调用关系。软件模块设计复杂度高意味模块耦合度高,这将导致模块难于隔离、维护和复用。模块设计复杂度是从模块流程图中移去那些不包含调用子模块的判定和循环结构后得出的圈复杂度,因此模块设计复杂度不能大于圈复杂度,通常是远小于圈复杂度。
v(G) 圈复杂度是用来衡量一个模块判定结构的复杂程度,数量上表现为独立路径的条数,即合理的预防错误所需测试的最少路径条数,圈复杂度大说明程序代码可能质量低且难于测试和维护,经验表明,程序的可能错误和高的圈复杂度有着很大关系。
第一、二次作业
Method | CogC | ev(G) | iv(G) | v(G) |
---|---|---|---|---|
Elevator.run() | 24.0 | 3.0 | 10.0 | 13.0 |
Scheduler.run() | 18.0 | 3.0 | 9.0 | 9.0 |
Elevator.lookLeftRight() | 13.0 | 1.0 | 12.0 | 12.0 |
Elevator.lookUpDown() | 13.0 | 1.0 | 16.0 | 16.0 |
Elevator.moveLeft() | 10.0 | 1.0 | 6.0 | 8.0 |
Elevator.moveRight() | 10.0 | 1.0 | 6.0 | 8.0 |
Main.main(String[]) | 8.0 | 3.0 | 5.0 | 5.0 |
Elevator.moveDown() | 7.0 | 1.0 | 6.0 | 6.0 |
Elevator.moveUp() | 7.0 | 1.0 | 6.0 | 6.0 |
Elevator.Elevator(int, String, char, int) | 6.0 | 1.0 | 5.0 | 5.0 |
Elevator.offBoard() | 6.0 | 1.0 | 6.0 | 6.0 |
Elevator.onBoard() | 6.0 | 1.0 | 8.0 | 8.0 |
Elevator.moveLeftRight() | 5.0 | 1.0 | 3.0 | 5.0 |
WaitingQueue.getOneRequest() | 4.0 | 2.0 | 3.0 | 4.0 |
Elevator.moveUpDown() | 3.0 | 1.0 | 3.0 | 3.0 |
Scheduler.leastLoadElevator(ArrayList) | 3.0 | 1.0 | 3.0 | 3.0 |
Elevator.doorAndBoard() | 2.0 | 1.0 | 3.0 | 3.0 |
Scheduler.Scheduler(WaitingQueue) | 2.0 | 1.0 | 3.0 | 3.0 |
Scheduler.addElevator(ElevatorRequest) | 2.0 | 1.0 | 3.0 | 3.0 |
Elevator.peekInsideRequest() | 1.0 | 2.0 | 1.0 | 2.0 |
Elevator.peekOutsideRequest() | 1.0 | 2.0 | 1.0 | 2.0 |
Elevator.Elevator() | 0.0 | 1.0 | 1.0 | 1.0 |
Elevator.addOutside(PersonRequest) | 0.0 | 1.0 | 1.0 | 1.0 |
Elevator.elevatorLoad() | 0.0 | 1.0 | 1.0 | 1.0 |
Elevator.isInsideEmpty() | 0.0 | 1.0 | 1.0 | 1.0 |
Elevator.isOutsideEmpty() | 0.0 | 1.0 | 1.0 | 1.0 |
Elevator.setEnd(boolean) | 0.0 | 1.0 | 1.0 | 1.0 |
SafeOutput.println(String) | 0.0 | 1.0 | 1.0 | 1.0 |
WaitingQueue.WaitingQueue() | 0.0 | 1.0 | 1.0 | 1.0 |
WaitingQueue.addRequest(PersonRequest) | 0.0 | 1.0 | 1.0 | 1.0 |
WaitingQueue.isEmpty() | 0.0 | 1.0 | 1.0 | 1.0 |
WaitingQueue.isEnd() | 0.0 | 1.0 | 1.0 | 1.0 |
WaitingQueue.setEnd(boolean) | 0.0 | 1.0 | 1.0 | 1.0 |
Total | 151 | 42 | 130 | 142 |
Average | 4.58 | 1.27 | 3.94 | 4.30 |
Class | OCavg | OCmax | WMC |
---|---|---|---|
Elevator | 3.43 | 10.0 | 72.0 |
Main | 5.0 | 5.0 | 5.0 |
SafeOutput | 1.0 | 1.0 | 1.0 |
Scheduler | 4.25 | 8.0 | 17.0 |
WaitingQueue | 1.33 | 3.0 | 8.0 |
Total | 103.0 | ||
Average | 3.12 | 5.4 | 20.6 |
第三次作业
Method | CogC | ev(G) | iv(G) | v(G) |
---|---|---|---|---|
MainScheduler.crossFloor(char, char, int) | 25.0 | 13.0 | 13.0 | 13.0 |
SecondaryScheduler.run() | 16.0 | 3.0 | 8.0 | 8.0 |
Elevator.offBoard() | 14.0 | 1.0 | 8.0 | 8.0 |
Elevator.run() | 14.0 | 3.0 | 8.0 | 11.0 |
Elevator.lookLeftRight() | 13.0 | 1.0 | 12.0 | 12.0 |
Elevator.lookUpDown() | 13.0 | 1.0 | 16.0 | 16.0 |
Elevator.moveLeft() | 10.0 | 1.0 | 6.0 | 8.0 |
Elevator.moveRight() | 10.0 | 1.0 | 6.0 | 8.0 |
MainScheduler.cutPersonRequest(Person) | 10.0 | 1.0 | 6.0 | 6.0 |
MainScheduler.run() | 9.0 | 3.0 | 7.0 | 7.0 |
Main.main(String[]) | 8.0 | 3.0 | 5.0 | 5.0 |
Elevator.moveDown() | 7.0 | 1.0 | 6.0 | 6.0 |
Elevator.moveUp() | 7.0 | 1.0 | 6.0 | 6.0 |
Elevator.Elevator(SecondaryScheduler, int, String, char, int, int, double, ...) | 6.0 | 1.0 | 5.0 | 5.0 |
Elevator.onBoard() | 6.0 | 1.0 | 8.0 | 8.0 |
Elevator.moveLeftRight() | 5.0 | 1.0 | 3.0 | 5.0 |
WaitingQueue.getOneRequest() | 4.0 | 2.0 | 3.0 | 4.0 |
Elevator.moveUpDown() | 3.0 | 1.0 | 3.0 | 3.0 |
MainScheduler.pToSeScheduler(Person) | 3.0 | 1.0 | 3.0 | 3.0 |
SecondaryScheduler.getCrossElevator(char, char) | 3.0 | 1.0 | 3.0 | 3.0 |
SecondaryScheduler.hasCrossElevator(char, char) | 3.0 | 3.0 | 1.0 | 3.0 |
SecondaryScheduler.leastLoadElevator(HashSet) | 3.0 | 1.0 | 3.0 | 3.0 |
Elevator.doorAndBoard() | 2.0 | 1.0 | 3.0 | 3.0 |
MainScheduler.MainScheduler(WaitingQueue) | 2.0 | 1.0 | 3.0 | 3.0 |
MainScheduler.addElevator(ElevatorRequest) | 2.0 | 1.0 | 3.0 | 3.0 |
MainScheduler.endSeSch() | 2.0 | 1.0 | 3.0 | 3.0 |
Person.getPartRequest() | 2.0 | 2.0 | 2.0 | 2.0 |
Elevator.peekInsideRequest() | 1.0 | 2.0 | 1.0 | 2.0 |
Elevator.peekOutsideRequest() | 1.0 | 2.0 | 1.0 | 2.0 |
SecondaryScheduler.endElevators() | 1.0 | 1.0 | 2.0 | 2.0 |
Counter.Counter() | 0.0 | 1.0 | 1.0 | 1.0 |
Counter.beginPlus() | 0.0 | 1.0 | 1.0 | 1.0 |
Counter.endPlus() | 0.0 | 1.0 | 1.0 | 1.0 |
Counter.sameNumber() | 0.0 | 1.0 | 1.0 | 1.0 |
Elevator.Elevator() | 0.0 | 1.0 | 1.0 | 1.0 |
Elevator.addOutside(Person) | 0.0 | 1.0 | 1.0 | 1.0 |
Elevator.elevatorLoad() | 0.0 | 1.0 | 1.0 | 1.0 |
Elevator.getSwitchInfo() | 0.0 | 1.0 | 1.0 | 1.0 |
Elevator.setEnd(boolean) | 0.0 | 1.0 | 1.0 | 1.0 |
MainScheduler.addMainScQueue(Person) | 0.0 | 1.0 | 1.0 | 1.0 |
PartRequest.PartRequest(int, int, char, char, int, PersonRequest) | 0.0 | 1.0 | 1.0 | 1.0 |
PartRequest.getFromBuilding() | 0.0 | 1.0 | 1.0 | 1.0 |
PartRequest.getFromFloor() | 0.0 | 1.0 | 1.0 | 1.0 |
PartRequest.getOriginalPersonRequest() | 0.0 | 1.0 | 1.0 | 1.0 |
PartRequest.getPersonId() | 0.0 | 1.0 | 1.0 | 1.0 |
PartRequest.getToBuilding() | 0.0 | 1.0 | 1.0 | 1.0 |
PartRequest.getToFloor() | 0.0 | 1.0 | 1.0 | 1.0 |
Person.Person(PersonRequest) | 0.0 | 1.0 | 1.0 | 1.0 |
Person.getOriginalRequest() | 0.0 | 1.0 | 1.0 | 1.0 |
Person.getPartValue() | 0.0 | 1.0 | 1.0 | 1.0 |
Person.getRequestsSize() | 0.0 | 1.0 | 1.0 | 1.0 |
Person.partPp() | 0.0 | 1.0 | 1.0 | 1.0 |
Person.setRequests(ArrayList) | 0.0 | 1.0 | 1.0 | 1.0 |
SafeOutput.println(String) | 0.0 | 1.0 | 1.0 | 1.0 |
SecondaryScheduler.SecondaryScheduler(MainScheduler) | 0.0 | 1.0 | 1.0 | 1.0 |
SecondaryScheduler.addElevator(Elevator) | 0.0 | 1.0 | 1.0 | 1.0 |
SecondaryScheduler.sendToMainSch(Person) | 0.0 | 1.0 | 1.0 | 1.0 |
SecondaryScheduler.sendToSecondary(Person) | 0.0 | 1.0 | 1.0 | 1.0 |
SecondaryScheduler.setEnd() | 0.0 | 1.0 | 1.0 | 1.0 |
WaitingQueue.WaitingQueue() | 0.0 | 1.0 | 1.0 | 1.0 |
WaitingQueue.addRequest(Person) | 0.0 | 1.0 | 1.0 | 1.0 |
WaitingQueue.isEmpty() | 0.0 | 1.0 | 1.0 | 1.0 |
WaitingQueue.isEnd() | 0.0 | 1.0 | 1.0 | 1.0 |
WaitingQueue.setEnd(boolean) | 0.0 | 1.0 | 1.0 | 1.0 |
Total | 205 | 90 | 191 | 205 |
Average | 3.20 | 1.41 | 2.98 | 3.20 |
Class | OCavg | OCmax | WMC |
---|---|---|---|
Elevator | 3.65 | 10.0 | 73.0 |
MainScheduler | 4.62 | 13.0 | 37.0 |
SecondaryScheduler | 2.3 | 7.0 | 23.0 |
Person | 1.14 | 2.0 | 8.0 |
WaitingQueue | 1.33 | 3.0 | 8.0 |
PartRequest | 1.0 | 1.0 | 7.0 |
Main | 5.0 | 5.0 | 5.0 |
Counter | 1.0 | 1.0 | 4.0 |
SafeOutput | 1.0 | 1.0 | 1.0 |
Total | 166.0 | ||
Average | 2.59 | 4.78 | 18.43 |
类图
第一、二次作业
第三次作业
调度策略
- 主调度器拆分请求,规划路线,依次分给次级调度器。
- 每组电梯有一个次级调度器,每层或每栋楼的电梯成为一组。
- 捎带时考虑运行方向、载客数量。
心得体会
- 多线程挺好玩的
- 调度挺好玩的