0% found this document useful (0 votes)
21 views

Automata (1)

Uploaded by

syedarbuu7867
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Automata (1)

Uploaded by

syedarbuu7867
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

A Project Report on

Traffic Light System using Finite State Machine


(FSM)

Submitted by

Vidyasagar R 4VV22IS117

Yashwanth N 4VV22IS126

Under the guidance of

Dr.Ravi kumar V
Head Of The Department
Department of ISE

Automata theory [BISAT504]


2024-2025
Introduction

The Traffic Light System can be effectively modeled using a Deterministic Finite
Automaton (DFA). The system consists of a finite set of states (Red, Green, Yellow) with
deterministic transitions based on time intervals. Additionally, a Fault State is introduced
to represent scenarios where the traffic light system encounters an error or failure.

Objective:

The purpose of this project is to implement a traffic light system using a DFA to model
the states and transitions. This report will cover the design, implementation, and analysis
of the system, including handling faults.
Finite State Machine (FSM):

Definition:
A Finite State Machine (FSM) is a computational model used to design algorithms and
systems that can be in one of a limited number of states at any given time. The system
transitions from one state to another based on inputs or conditions.

Types of FSM:

Deterministic Finite Automaton (DFA):


A DFA is a special type of FSM where for each state and input, there is exactly one
possible next state. The transitions are deterministic, meaning there is no ambiguity in the
system’s behavior.

Non-deterministic Finite Automaton (NFA):


An NFA can have multiple possible next states for a given state and input.

Applications of FSM:
FSMs are used in various systems such as traffic light control, vending machines,
protocol design, and even games where events trigger state transitions
Deterministic Finite Automaton (DFA):

Definition:

A Deterministic Finite Automaton (DFA) is a type of finite state machine where:


• A finite number of states exist.
• Deterministic transitions occur, meaning there is only one possible next state for each
state and input.
• No ambiguity: For each current state and input, there is exactly one next state.

Components of DFA:

1. States: The set of possible configurations of the system.


2. Alphabet: A set of symbols (inputs) that trigger state transitions.
3. Transition Function: A rule that specifies how to move from one state to another
based on an input symbol.
4. Start State: The state at the beginning of the process.
5. Accept States: The states where the automaton ends up after processing all inputs
(for non-accepting systems, all states can be considered valid as long as transitions follow
predefined rules).

Example of DFA:
For the Traffic Light System, the DFA defines the set of states (Red, Green, Yellow) and
the transitions that occur after fixed time intervals.
Traffic Light System Design:

States:

The system has the following primary states:


1. Red: The light is red, signaling vehicles to stop.
2. Green: The light is green, signaling vehicles to go.
3. Yellow: The light is yellow, signaling caution and preparing for the next transition.

Fault:
A state representing a malfunction or error in the system. When the system encounters a
fault, no transitions occur until the system is reset or fixed.

State Transitions:
The system transitions between states based on time, but if a Fault occurs, the system
enters a state where no further transitions are possible unless corrected.

Normal Transitions:

1. Red → Green: After 5 seconds, transition to Green.


2. Green → Yellow: After 5 seconds, transition to Yellow.
3. Yellow → Red: After 2 seconds, transition to Red.

Fault Transitions:

4. Any State → Fault:


If a malfunction occurs, the system enters the Fault state, where no further transitions
occur until the fault is resolved.
Transition table:

Current State Input (Timer or Next State Action/Duration


Fault Condition)
Red Timer (5s) Green 5 seconds (Red to
Green)
Green Timer (5s) Yellow 5 seconds (Green
to Yellow)
Yellow Timer (2s) Red 2 seconds
(Yellow to Red)
Any State Fault/Condition Fault Malfunction (no
further transition)

DFA Model:
This system remains deterministic, as every state has one transition based on
either the timer or a fault condition. If the system is working normally, the
transitions occur in the usual cycle. If a fault occurs, the system moves to the
Fault state and remains there until the error is fixed.

Transition diagram:
Code:
public class TrafficLightFSM {

enum State {
RED, YELLOW, GREEN, FAULT
}

private State currentState;


private static final int RED_TIME = 5000;
private static final int GREEN_TIME = 5000;
private static final int YELLOW_TIME = 2000;
private static final int FAULT_TIME = 1000;

public TrafficLightFSM() {
currentState = State.RED;
}

public void transition() {


switch (currentState) {
case RED:
currentState = State.GREEN;
break;
case GREEN:
currentState = State.YELLOW;
break;
case YELLOW:
currentState = State.RED;
break;
case FAULT:

System.out.println("System is in FAULT state, no further


transitions.");
break;
}
}

public void start() {


while (true) {
System.out.println("Current state: " + currentState);
try {
switch (currentState) {
case RED:
Thread.sleep(RED_TIME);
break;
case GREEN:
Thread.sleep(GREEN_TIME);
break;
case YELLOW:
Thread.sleep(YELLOW_TIME);
break;
case FAULT:
Thread.sleep(FAULT_TIME);
break;
}
} catch (InterruptedException e) {
System.out.println("Error: " + e.getMessage());
}

if (currentState != State.FAULT) {
transition();
} else {
break;
}
}
}

public static void main(String[] args) {


TrafficLightFSM trafficLight = new TrafficLightFSM();
trafficLight.start();
}
}
Output:
Analysis of DFA:

• Deterministic Nature:
The traffic light system behaves deterministically, where each state has one
well-defined next state. For example, after 5 seconds in the Red state, it always
transitions to Green.

• Fault Handling:
The introduction of the Fault state ensures that when a malfunction occurs, the
system will enter a state where no transitions can take place, effectively halting
the traffic light cycle until the system is manually reset or repaired.

• No Ambiguity:
Given the current state and the input (timer or fault condition), the system will
always know exactly what the next state is.

• Cyclic Behavior:
Under normal conditions, the system follows a cyclic pattern: Red → Green
→ Yellow → Red. When the system enters the Fault state, it stops the cycle
until the error is addressed.

Applications and Use Cases:

1. Real-World Applications:
The Fault state in this DFA is highly relevant in real-world traffic light systems,
where malfunctions or maintenance issues can stop the system from functioning
normally. Such systems may need a manual reset or an alert to technicians.

2. Autonomous Vehicles:
Autonomous vehicles must be able to recognize the state of traffic lights,
including fault signals. For example, if a traffic light is malfunctioning and
stuck in the Fault state, the vehicle needs to handle the situation appropriately
(e.g., treat the intersection as an all-stop or all-go).

3. Scalability:
The DFA model can be extended by adding more states, such as Pedestrian
Crossing, or introducing more complex conditions for state transitions (e.g.,
varying light durations based on traffic flow).
Conclusion:

• The Traffic Light System is a clear example of a Deterministic Finite Automaton


(DFA). It operates through a finite set of states with deterministic transitions,
ensuring reliable and predictable behavior.

• The addition of a Fault state provides a robust way to handle errors in the system,
preventing unpredictable behavior during malfunctions.

• This model serves as a foundational approach for real-world traffic management


systems and can be easily expanded for more complex scenarios.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy