結對項目:電梯調度算法的實現和測試

做業要求有一點小修改並增長了一點提示,用紅色標出。html

項目截止時間:2014年10月19日中午12:00前。ios

TFS服務器地址及用戶名、密碼見課程中心。算法

 

Design and implement an Elevator Scheduler to aim for both correctness and performance, in managed code.編程

Skills to learn and practice:設計模式

a)       Peer to peer collaboration服務器

b)       Requirement Analysisapp

c)       Design by contract, Interface design and comprehensiondom

d)       Test Driven Development, Unit Testide

e)       Algorithm design測試

f)        Implementation

 

 

1. Background

Imagine we’re building a tall office building, it has the following configuration about elevators:

Building has 21 floors, 4 elevators, many passengers use these elevators everyday (passenger weight: average 70kg. max 120kg, min 45kg).

Other constant data: Elevator speed, door open/close time, passenger time for going in/out of the elevator.  We can make reasonable assumptions about these.

The building has 21 floors, from floor 0, 1, ... to 20.  Floor 0 is the underground parking level, floor 1 is the lobby level. Most people come in/out the building via these 2 floors.

 

Elevator name

Service floor list

Passenger limit

Weight limit

1

1, 10-20

12

1000 kg

2

0-10

10

1000 kg

3

1, 10-20

20

1500 kg

4

0-20

20

2000 kg

 

 

2.  Requirement to Student pairs

A framework with a naive algorithm is prepared and shared to students.  The core task for students is to design and implement the scheduling algorithm.  Students need to write their own scheduler class (implements the IScheduler interface), Update the SchedulerFactory.CreateScheduler method so the test framework can instantiate your class.

TA will come up with a consistent testing model to test your program according to the 「rush hour」 scenario (see below), and record the total travel time of each passengers.  

Total Travel Time = the time delta between the passenger appears in front of the elevator, and the time she gets off the elevator at this designated floor.

You (student pair) have:

1)      A set of API

2)      A naive solution (BUS program)

3)      A set of test cases to run

 

Explanation of BUS program:

We can have a naive algorithm called 「BUS」.   BUS algorithm treats an elevator as a bus, it goes from bottom to top, stops at every floor, opens its door, to let people in and out (if any), then closes the door and moves on.  After it reaches the top floor, it will go down and stop at each floor again.  This algorithm can serve all requests, but it’s apparently not the fastest algorithm.

Your code is required to be managed code (C#, managed C++, etc).

It has to generate 0 (zero) VS Code Analysis warnings and errors.

It has to be correct

It has to be fast

Score guideline:  TA will evaluate the 「average total travel time」 for all passengers in the same test case, the lower, the better.  If your performance is slower than 「bus」 solution, you get 0 points; if your program can’t deliver any passenger to the correct destination, you get 0 points.

One hint about elevator scheduling: When total weight is within 45 kg of the max limit, or the number of passengers is already at maximum, the elevator doesn’t need to stop for more external requests.

The elevator scheduler program doesn’t know how many passengers are waiting on each floor, it doesn’t know how many passengers will show up either.  This is the same with the real world situation.

please consider these scenarios:

a) XiaoMing  arrives at floor 1,  he needs to go to floor 19,  he presses the 「up」 button in the waiting area.  a while later, elevator #2 (this elevator can reach floor 0 to floor 10)  opens its door,  should XiaoMing go in elevalor #2?   if so, when he enters the elevaltor #2, which floor should he press?  where should he go out?  In your program,  which classes need to change to build in such logic?

 

3. Testing

TA will simulate a 「rush hour」 (上下班高峯時刻) test. The 「rush hour」 test is to simulate the come-to-work and leave-work scenario in a business building, which has the following 2 parts (they can be run next to each other).

1) Simple test. 20 passengers

20 people going thru random floors within 5 minutes.  

2) Come-to-work. 1000 total passengers

a)   80% of them goes from floor 0 and 1 to all other floors, the destination is distributed evenly.  The time each passenger arrives at the elevator can be emulated as a normal distribution.

b)   20% of them are going between any 2 floors of [2, 20], very few people travel between 2 adjacent floors (e.g. from floor 5 to 4).  Other than this, the distribution is also even.

3) Leave-work. 1000 total passengers

a)   90% of them go from other floors to floor 1 or floor 0.

b)   10% of them travel between floors [2, 20], again, Very few people travel between 2 adjacent floors.

 

4. 做業步驟

 

做業

博客要求 (寫1個博客,附加題的解法寫另外一個博客)

博客註明結對編程人員的名字/或學號後3位.

 

看教科書和其它參考書, 網站中關於結對編程的章節。例如:

http://www.cnblogs.com/xinz/archive/2011/08/07/2130332.html

照至少一張照片, 展示兩人在一塊兒合做編程的狀況。

說明結對編程的優勢和缺點。

結對的每個人的優勢和缺點在哪裏 (要列出至少三個優勢和一個缺點)。

看教科書和其它資料中關於 Information Hiding, interface design, loose coupling 的章節

 

說明怎樣利用這些好的設計方法。

看 Design by Contract, Code Contract 的內容:

http://en.wikipedia.org/wiki/Design_by_contract

http://msdn.microsoft.com/en-us/devlabs/dd491992.aspx

描述這些作法的優缺點, 說明你是如何把它們融入你的做業中的。

看教科書中,網上有關 unit test 的內容

http://www.cnblogs.com/xinz/archive/2011/11/20/2255830.html

 

經過截屏顯示你是如何用VS 的unit test 來保證你寫的類的質量的。顯示unit test 對你的寫的類(class) 的覆蓋率

閱讀有關 UML 的內容

畫出UML 圖顯示各個實體之間的關係 (畫一個圖便可)

實現你的算法

說明你的算法的關鍵 (沒必要列出源代碼), 以及獨到之處。

 

把你的代碼簽入TFS (問老師要權限及小組的路徑)

[附加題] 改進電梯調度的interface 設計, 讓它更好地反映現實, 更能讓學生練習算法, 更好地實現信息隱藏和信息共享。

目前的設計有什麼缺點, 你會如何改進它?  Analyze the   API design, and propose a better API so that Scheduler can have more freedom   and students can do more realistic scheduling. 

[附加題] 目前的這個測試程序只有命令行界面, 請給它設計UI界面, 顯示乘客/電梯的運動, 並實現之。

Implement a UI to show   how people/elevator moves  (write  a  blog to show your code   and UI)

 

[附加題]  閱讀有關 MVC 和  MVVM 設計模式的文章。

說明你寫的電梯調度的UI /Algorithm/interface 如何實現了MVC 或MVVM 的算法。

相關文章
相關標籤/搜索