~vonfry/lift-dfa

f0f24dc515a4633c23c39cd78f76222d89a549da — Vonfry 2 years ago dfa54ce master
add sth
4 files changed, 55 insertions(+), 23 deletions(-)

M app/Main.hs
M doc/report.tex
M lib/Lift.hs
M lib/Scheduler.hs
M app/Main.hs => app/Main.hs +9 -3
@@ 78,9 78,15 @@ mainLoop lift = loop $ Right (lift, emptyTask)
        let lift' = onClose lift
        threadDelay delayTime
        loop $ Right (lift', tasks)
    parseTaskin ["stop"] _ _ = loop $ Left "Stop"
    parseTaskin ["exception"] _ _ = loop $ Left "Exception"
    parseTaskin ["_"] _ Empty = loop $ Left "Finish"
    parseTaskin ["stop"] lift tasks = do
        let lift' = doStop lift
        loop $ Left "Stop"
    parseTaskin ["exception"] lift tasks = do
        let lift' = doExcept lift
        loop $ Left "Exception"
    parseTaskin ["_"] lift t@Empty = do
        putStrLn "Finish"
        parseTaskin ["stop"] lift t
    parseTaskin ["_"] lift tasks = do
        let (task, tasks') = popTask tasks lift
        putStrLn "do task"

M doc/report.tex => doc/report.tex +34 -19
@@ 132,15 132,19 @@
    \node [draw,right of=S,node distance=1.5cm] (idle) {待机}
      edge[<-] (S);
    \node [draw,right of=idle] (move) {升降}
      edge[<-] node [above] {就绪任务} (idle);
    \node [draw,above of=move] (load) {装载}
      edge[<-,bend left]  node [right,scale=.8] {到达任务楼层} (move)
      edge[->,bend right] node [left, scale=.8] {就绪任务} (move)
      edge[->,bend right] node [above left, scale=.8] {无就绪任务} (idle);
    \node [draw, below of=move] (es) {紧急}
       edge[<-] node [right] {异常/紧急停止} (move)
       edge[<-] node [left] {异常/紧急停止} (idle)
       edge[<-,bend right=60] node [right] {异常/紧急停止} (load);
      edge[<-] node [below,scale=.6] {就绪} (idle);
    \node [draw,right of=move] (load) {装载}
      edge[<-,bend left=15]  node [below,scale=.6] {到达} (move)
      edge[->,bend right=15] node [above,scale=.6] {就绪} (move)
      edge[->,bend right] node [above, scale=.6] {无就绪} (idle);
    \node [draw,double,above of=move] (ws) {停止}
       edge[<-] node [above right,scale=.6] {停止} (move)
       edge[<-] node [left,scale=.6] {停止} (idle)
       edge[<-] node [right,scale=.6] {停止} (load);
    \node [draw,double,below of=move] (es) {紧急}
       edge[<-] node [left,scale=.6] {异常} (move)
       edge[<-] node [below left,scale=.6]  {异常} (idle)
       edge[<-] node [below right,scale=.6] {异常} (load);
  \end{tikzpicture}
  \caption{\label{fig:running-dfa}运行状态转移图}
\end{figure}


@@ 157,20 161,26 @@
    \node [right of=S,draw,node distance=1.5cm] (F0) {F0}
      edge[<-] (S);
    \node [draw,below of=F0, node distance=3cm]  (B1) {B1}
        edge[bend left] node [left] {上升} (F0)
        edge[<-,bend right] node [right] {下降} (F0);
        edge[bend left] node [left,scale=.6] {上升} (F0)
        edge[<-,bend right] node [right,scale=.6] {下降} (F0);
    \node [draw,right of=F0]  (F1) {F1}
        edge[<-,bend left] node [below] {上升} (F0)
        edge[bend right] node [above] {下降} (F0);
        edge[<-,bend left] node [scale=.6] [above] {上升} (F0)
        edge[bend right] node [above,scale=.6] {下降} (F0);
    \node [draw,right of=F1]  (F2) {F2}
        edge[<-,bend left] node [below] {上升} (F1)
        edge[bend right] node [above] {下降} (F1);
        edge[<-,bend left] node [scale=.6] [above] {上升} (F1)
        edge[bend right] node [above,scale=.6] {下降} (F1);
    \node [right of=F2] (dots) {$\dots$}
        edge[<-,bend left] node [below] {上升} (F2)
        edge[bend right] node [above] {下降} (F2);
        edge[<-,bend left] node [scale=.6] [above] {上升} (F2)
        edge[bend right] node [above,scale=.6] {下降} (F2);
    \node [draw,right of=dots] (Fn) {Fn}
        edge[<-,bend left] node [below] {上升} (dots)
        edge[bend right] node [above] {下降} (dots);
        edge[<-,bend left] node [above,scale=.6] {上升} (dots)
        edge[bend right] node [above,scale=.6] {下降} (dots);
    \node [draw,double,below of=dots] (qt) {$q_t$}
        edge[<-] node [below,scale=.6] {} (F0)
        edge[<-] node [below,scale=.6] {终止} (B1)
        edge[<-] node [right,scale=.6] {终止} (F1)
        edge[<-] node [below,scale=.6] {} (F2)
        edge[<-] node [right,scale=.6] {终止} (Fn);
  \end{tikzpicture}
  \caption{\label{fig:floor-dfa}楼层状态转移图}
\end{figure}


@@ 267,6 277,8 @@ doLoad :: Lift -> Lift
onExcept :: Lift -> Lift

doExcept :: Lift -> Lift

doStop :: Lift -> Lift
\end{lstlisting}

\subsection{状态转换模块}


@@ 282,6 294,7 @@ data LiftState = LiftIdle
               | LiftMove LiftMoveT
               | LiftLoad
               | LiftException
               | LiftStop
               deriving (Eq, Show, Read)

data LiftMoveT = LiftMoveUp | LiftMoveDown


@@ 317,6 330,8 @@ exceptS :: State Lift LiftFloor
moveSUp :: State Lift LiftFloor

moveSDown :: State Lift LiftFloor

stopS :: State Lift LiftFloor
\end{lstlisting}

\chapter{使用说明}

M lib/Lift.hs => lib/Lift.hs +8 -1
@@ 10,7 10,7 @@ module Lift
  , (-:-)
  , (-:)
  , moveLUp, moveLDown
  , idleS, loadS, exceptS, moveSUp, moveSDown
  , idleS, loadS, exceptS, moveSUp, moveSDown, stopS
  , runState, evalState, execState, mapState, withState
  , initLift
  ) where


@@ 28,6 28,7 @@ data LiftState = LiftIdle
               | LiftMove LiftMoveT
               | LiftLoad
               | LiftException
               | LiftStop
               deriving (Eq, Show, Read)

data LiftMoveT = LiftMoveUp | LiftMoveDown


@@ 110,6 111,12 @@ exceptS = do
    put $ s { curState = LiftException }
    return $ curFloor s

stopS :: State Lift LiftFloor
stopS = do
    s <- get
    put $ s { curState = LiftStop }
    return $ curFloor s

-- | move lift state to up, this state transformation do change 'curState'.
moveSUp :: State Lift LiftFloor
moveSUp = do

M lib/Scheduler.hs => lib/Scheduler.hs +4 -0
@@ 55,6 55,10 @@ onExcept = doExcept
doExcept :: Lift -> Lift
doExcept = execState exceptS

-- | stop lift
doStop :: Lift -> Lift
doStop = execState stopS

-- | input a floorname and returnn its mapping for 'LiftFloor'.
(<!) :: String -> Lift -> LiftFloor
(<!) s (Lift _ _ names) = fromJust $ elemIndex s names