Abstract

Introduction

Topic

The topic of project 5-7 is concurrent elevator simulation. The program read requests from stdin, simulate the elevator system, and print runtime infomation to stdout.

Request

<PersonID>-FROM-<FromLevel>-TO-<ToLevel>

  • On behalf of a pessenger
  • <PersonID> must be unique

Elevator

  • Function

    • Move: Move up or down to next level in <MoveTime>, and print ARRIVE-<Level>-<ElevatorName>
    • Open Door: Open Door in <OpenTime>, and print OPEN-<Level>-<ElevatorName> when begin opening
    • Close Door: Close Door in <CloseTime>, and print CLOSE-<Level>-<ElevatorName> when close finished
    • Pessenger in: Print IN-<PersonID>-<Level>-<ElevatorName>
    • Pessenger out: Print OUT-<PersonID>-<Level>-<ElevatorName>
  • Argument
    • Name
    • Time
      • OpenTime
      • CloseTime
      • MoveTime
    • Level
      • InitialLevel
      • SupLevel
      • InfLevel
      • ApprovedLevel
    • Capacity

Analysis

The major focus is concurrency: The program has to plan and simulate while reading requests, so it has to be concurrent. Thus we have to design a concurrent architechture and guarantee its thread safety.

Also, for multi-elevator scene, we need to design a coordinating thread to coordinate elevators.

The program's function can be classified as follows, and the threads can be designed correspondingly:

Reading Requests

Reading requests in real time, and pass them to coordinating thread.

Coordinating

Get requests from reading thread, set path for the person and pass it to scheduling thread.

Scheduling and controling

Get requests from reading thread, schedule and pass the action of elevator to elevator, and control the movement of passenger.

Elevator simulation

Get command from scheduling thread, open and close door, and go up or down stairs.

Course

This topic has three assignments.

P5-P6

Reading (and coordinating)

  • Read from given input interface
  • Analyse the request, put the person to corresponse location in concurrent two-dimensional map
    • Dimension 1: From level
    • Dimension 2: To level
  • Pass person to scheduling and controling thread through cuncurrent map: ConcurrentHashMap<MapKey, Set<Integer>>

Scheduling and controling

  • Move up and down again and again

    • Take in person whose destination direction is consistent with the elevator
    • Free person who arrived
    • U-turn if there's no person ahead
    • Stop if there's no person anywhere
  • Give command through TransferQueue<Command> to elevator

Elevator simulation

  • Execute command

    • Print information
    • Change level
    • Sleep for given time

P7

Reading and coordinating

  • Read from given input interface
  • Analyse and coordinate
    • If there's a single elevator approved to access both from and to floor

      • The person only have one request: from <FromLevel> to <ToLevel>
    • else
      • Because it takes at most two steps to go from <FromLevel> to <ToLevel>
      • Find the elevator who can access <FromLevel>
      • Find the elevator who can access <ToLevel>
      • Find the level which can be accessed by both elevator
      • The person has two request
        • From <FromLevel> to <TransferLevel>
        • From <TransgerLevel> to <ToLevel>
    • The coordinate algorithm can be refacted to recursive one to support any number of transfers
  • Pass
    • Pass person to scheduling and controling thread through cuncurrent map: ConcurrentHashMap<MapKey, Set<Integer>>
    • The mapkey presents the first request: new MapKey(<FromLevel>, <ToLevel>)
    • The rest requests stored in the person object

Scheduling and controling

  • Move up and down again and again

    • If current level is accessable

      • Take in person

        • Destination direction is consistent with the elevator
        • Destination level is accessable
      • Free person who arrived
        • If the person has rest requests, put him to correspensive location in reqMap, and delete its next request
    • U-turn if there's no person at accessable level ahead
    • Stop if there's no person anywhere
  • Give command through TransferQueue<Command> to elevator

Elevator simulation

  • Execute command

    • Print information
    • Change level
    • Sleep for given time

Class Design

Measurement

Complexity Metric

Method Complexity

Method ev(G) iv(G) v(G)
com.nyan.EleSysTest.main(String[]) 1 1 1
com.nyan.elesys.Commander.Commander(int,String,Integer[],Integer,Integer,Integer,ConcurrentHashMap<MapKey, Set<Person>>,Long,Long,Long) 1 1 1
com.nyan.elesys.Commander.closeDoor() 1 2 2
com.nyan.elesys.Commander.downHave() 3 2 3
com.nyan.elesys.Commander.inDownPsgers() 1 3 3
com.nyan.elesys.Commander.inPsgers(Integer) 4 4 5
com.nyan.elesys.Commander.inUpPsgers() 1 3 3
com.nyan.elesys.Commander.levelHave(int) 5 6 8
com.nyan.elesys.Commander.loop() 7 5 9
com.nyan.elesys.Commander.openDoor() 1 2 2
com.nyan.elesys.Commander.outPsgers() 1 4 4
com.nyan.elesys.Commander.run() 1 4 5
com.nyan.elesys.Commander.upHave() 3 2 3
com.nyan.elesys.Coordinator.Coordinator(ConcurrentHashMap<MapKey, Set<Person>>,Integer[][]) 1 2 2
com.nyan.elesys.Coordinator.run() 12 11 14
com.nyan.elesys.Elevator.Elevator(Long,Long,Long,Integer,String,TransferQueue<Command>) 1 1 1
com.nyan.elesys.Elevator.getLevelNum() 1 1 1
com.nyan.elesys.Elevator.run() 3 7 8
com.nyan.elesys.Level.Level(Integer) 1 1 1
com.nyan.elesys.Level.add(Integer) 1 2 2
com.nyan.elesys.Level.addOne() 1 1 2
com.nyan.elesys.Level.equals(Object) 2 2 2
com.nyan.elesys.Level.getLevelNum() 1 1 1
com.nyan.elesys.Level.sub(Integer) 1 2 2
com.nyan.elesys.Level.subOne() 1 1 2
com.nyan.elesys.Level.toString() 1 1 1
com.nyan.elesys.MapKey.MapKey(Integer,Integer) 1 1 1
com.nyan.elesys.MapKey.equals(Object) 2 3 3
com.nyan.elesys.MapKey.hashCode() 1 1 1
com.nyan.elesys.MapKey.toString() 1 1 1
com.nyan.elesys.Person.Person(Integer) 1 1 1
com.nyan.elesys.Person.addReq(Request) 1 1 1
com.nyan.elesys.Person.compareTo(Person) 1 1 1
com.nyan.elesys.Person.nextReq() 2 1 2
com.nyan.elesys.Person.toString() 1 1 1
com.nyan.elesys.PsgsList.PsgsList(Integer,Integer) 1 2 2
com.nyan.elesys.PsgsList.add(int,Set<Person>) 1 1 1
com.nyan.elesys.PsgsList.get(int) 1 1 1
com.nyan.elesys.PsgsList.getTotal() 1 2 2
com.nyan.elesys.PsgsList.isEmpty() 3 3 4
com.nyan.elesys.Request.Request(Integer,Integer) 1 1 1
com.nyan.elesys.Request.getFromLevel() 1 1 1
com.nyan.elesys.Request.getToLevel() 1 1 1

Class Complexity

Class OCavg WMC
com.nyan.EleSysTest 1 1
com.nyan.elesys.Command n/a 0
com.nyan.elesys.Commander 3.33 40
com.nyan.elesys.Coordinator 7 14
com.nyan.elesys.Elevator 3 9
com.nyan.elesys.Level 1.62 13
com.nyan.elesys.MapKey 1.25 5
com.nyan.elesys.Person 1.2 6
com.nyan.elesys.PsgsList 1.8 9
com.nyan.elesys.Request 1 3

Package Complexity

Package v(G)avg v(G)tot
com.nyan 1 1
com.nyan.elesys 2.67 112

Module Complexity

Module v(G)avg v(G)tot
P7Project 2.63 113

Project Complexity

Project v(G)avg v(G)tot
project 2.63 113

Bug Review

Level movement step

Door movement time

Test Strategy

Concurrent Knowledge

Acknowledge

Reference

BUAAOO P5-P7 Elevator Simulation的更多相关文章

  1. hdu分类 Dynamic Programming(这是一场漫长的旅途)

    下面是difficulty 1的题 1003   Max Sum 最长递增子序列.非常经典,最棒的解法是在线算法O(n)的复杂度. 贴的呢,是用dp做的代码. 先是一个高亮的dp递推式,然后找到最大处 ...

  2. [android]亲自破解Flappy Bird(去广告+永生)

    以下内容为原创,欢迎转载,转载请注明 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/3544785.html  听说最近Flappy Bird很火,但 ...

  3. BZOJ3679 : 数字之积

    设f[i][p2][p3][p5][p7][j][k]表示前i位,2,3,5,7的次数,前i位是否等于x,是否有数字的方案数 然后数位DP即可,ans=cal(r)-cal(l) #include&l ...

  4. ADF_Starting系列1_JDeveloper IDE开发环境简介

    2013-05-01 Created By BaoXinjian

  5. SOA_环境安装系列3_Oracle Weblogic安装和环境搭建(案例)

    2014-01-03 Created By BaoXinjian

  6. WLS_Oracle Weblogic安装和环境搭建(案例)

    2014-01-03 Created By BaoXinjian

  7. mysql颠覆实战笔记(一)--设计一个项目需求,灌入一万数据先

    版权声明:笔记整理者亡命小卒热爱自由,崇尚分享.但是本笔记源自www.jtthink.com(程序员在囧途)沈逸老师的<web级mysql颠覆实战课程 >.如需转载请尊重老师劳动,保留沈逸 ...

  8. poj3307

    可以证明,每个符合的数都由2,3,5,7相乘得到. 依据猜想:下一个出现的数是由前面某个数乘上这几个数之一得到的新的数. 假设之前的数均满足序列,则因为下一个数必有2,3,5,7相乘得到,而这个数之前 ...

  9. springmvc(六)——视图和视图解析器

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAoIAAAGrCAIAAADb2WEhAAAgAElEQVR4nOzdaVhTd78vfF8/z772c9 ...

随机推荐

  1. python运用PIL制作GIF

    与一.安装Pillow 安装地址:https://pypi.org/project/Pillow/#files 二.准备好图片,并从0开始命名,如下图: (ps:记得存图位置与新建的py文件在同一存放 ...

  2. 小程序tab切换 点击左右滑动

    wxml <scroll-view scroll-x="true" class="navbar-box"> <block wx:for=&qu ...

  3. jsp页面输出当前时间

    <% out.print(new java.text.SimpleDateFormat("yyyy年MM月dd号 hh:mm:ss").format(new Date())) ...

  4. mybatis获取insert插入之后的id

    一.为什么要获取insert的id 写了测试类测试插入,插入之后用select查询出来进行Assert 插入成功后,不管Select对比的结果成功还是失败,都希望删除掉测试插入的结果 二.运行环境 m ...

  5. C++标准模板库(STL)之String

    1.String的常用用法 在C语言中,使用字符数组char str[]来存字符串,字符数组操作比较麻烦,而且容易有'\0'的问题,C++在STL中加入string类型,对字符串常用的需求功能进行封装 ...

  6. webform的代码设计文件莫名出错的解决

    不知道怎么回事,建立webform工程时,编译,出错,提示代码设计文件(自动生成的文件代码,不能修改)出错,提示有的对象正在使用,于是删除里面多余的对象标记,还是没用,又自动生成了. 解决办法: 1. ...

  7. Java垃圾回收算法和内存分配策略

    垃圾回收算法和内存分配策略 Java垃圾回收 垃圾收集,也就是GC并不是Java的伴生物,而对于GC的所需要完成任务主要就是: 1.哪些内存是需要回收的? 2.何时去回收这些内存? 3.以何种方式去回 ...

  8. JS的全局变量与局部变量及变量的提升

    遇到全局变量与局部变量的时候总是出一些或多或少的问题,于是专门花时间去认真研究了一下全局变量与局部变量. 这是在网上看到的一个关于全局变量与局部变量的代码,看了下作者的解析,自己也进行了研究. < ...

  9. Java面向对象编程思想

    面向对象三个特征:封装.继承.多态封装:    语法:属性私有化(private).提供相对应的get/set 的方法进行访问(public). 在set/get的方法中对属性的数据 做相对应的业务逻 ...

  10. spring整合redis(哨兵模式)

    首先服务器搭建哨兵模式(我这里使用的是Windows8系统),感谢两位博主,少走不少弯路,在此给出链接:服务器哨兵模式搭建和整合哨兵模式 什么一些介绍就不介绍了,可以看一下连接,比较详细,初次接触,当 ...