Skip to content

Repository files navigation

COMP212 Assignment 1 - Asynchronous LCR Algorithm in Hierarchical Ring Topology

Project Structure

Assignment1/
├── Main.java                    # Manual demonstration with example topologies
├── ExperimentRunner.java        # Automated experiments for data collection
├── Processor.java               # Base processor implementation
├── InterfaceProcessor.java      # Interface processor for subrings
├── Message.java                 # Message data structure
├── Simulator.java               # Simulation orchestrator
├── plots/                       # Experimental data and visualization
│   ├── plot_exp1.py            # Python script for Experiment 1 plots
│   ├── plot_exp2.py            # Python script for Experiment 2 plots
│   └── requirements.txt        # Python dependencies
└── README.md                    # This file

Prerequisites

  • Java
  • Python (for plotting)

Compilation

Navigate to the project directory and compile all Java source files:

javac *.java

This will compile all .java files in the directory, including:

  • Main.java
  • ExperimentRunner.java
  • Processor.java
  • InterfaceProcessor.java
  • Message.java
  • Simulator.java

Running the Code

Option 1: Manual Demonstration (Main.java)

The Main.java file contains hand-crafted examples to demonstrate the algorithm's correctness with specific topologies.

Run:

java Main

What it does:

  • Example 1: Creates a main ring with 4 processors and 2 subrings (3 processors each)

    • Demonstrates hierarchical topology with interface processors
    • Shows asynchronous wake-up behavior
    • Outputs: Leader ID, status of all processors, total rounds, and messages
  • Example 2: Creates a simple ring with 6 processors (no subrings)

    • Demonstrates the algorithm on a flat topology
    • Outputs: Leader ID, status of all processors, total rounds, and messages

Expected Output:

Asynchronous-Start and Terminating LCR Algorithm
Processor 40 Status: NON_LEADER, Leader ID: 1000, Terminated: true
Processor -1(Interface) Status: NON_LEADER, Leader ID: 1000, Terminated: true
Processor 99 Status: NON_LEADER, Leader ID: 1000, Terminated: true
Processor -1(Interface) Status: NON_LEADER, Leader ID: 1000, Terminated: true
Processor 92 Status: NON_LEADER, Leader ID: 1000, Terminated: true
Processor 19 Status: NON_LEADER, Leader ID: 1000, Terminated: true
Rounds: 8 Messages: 41
Validation passed

Asynchronous-Start and Terminating LCR Algorithm (No Subrings)
Processor 25 Status: NON_LEADER, Leader ID: 80, Terminated: true
Processor 60 Status: NON_LEADER, Leader ID: 80, Terminated: true
Processor 45 Status: NON_LEADER, Leader ID: 80, Terminated: true
Processor 80 Status: LEADER, Leader ID: 80, Terminated: true
Processor 55 Status: NON_LEADER, Leader ID: 80, Terminated: true
Processor 70 Status: NON_LEADER, Leader ID: 80, Terminated: true
Rounds: 14 Messages: 65
Validation passed

Option 2: Automated Experiments (ExperimentRunner.java)

The ExperimentRunner.java file runs comprehensive experiments to collect performance data for analysis.

Run:

java ExperimentRunner

What it does:

Experiment 1: Impact of Scale (N) and ID Assignment

  • Variables tested:
    • Network sizes: 20, 40, 60, 80, 100, 150, 200, 400, 500 processors
    • ID distributions: RANDOM, ASCENDING, DESCENDING
  • Output: plots/exp1_scale_and_id.csv

Experiment 2: Topology Fragmentation and Spatial Placement

  • Variables tested:
    • Fixed network size: N = 1000
    • Number of subrings: 1, 2, 4, 8, 16, 32, 64, 128
    • Placement strategies: CLUSTERED (interface processors adjacent), EVEN (interface processors distributed)
  • Output: plots/exp2_topology_and_placement.csv

Expected Output:

Validation passed
Experiment 1 data successfully saved to exp1_scale_and_id.csv
Validation passed
Experiment 2 data successfully saved to exp2_topology_and_placement.csv
All automated tests completed! Please check the generated CSV files in the project root directory.

Generating Plots

After running ExperimentRunner.java, use the Python scripts to generate visualizations.

Setup Python Environment

  1. Install Python dependencies:
cd "./plots"
pip install -r requirements.txt
  1. Run plotting scripts:

For Experiment 1 plots:

python plot_exp1.py

This generates:

  • exp1_total_messages.png - Message complexity vs. network size
  • exp1_total_rounds.png - Time complexity vs. network size

For Experiment 2 plots:

python plot_exp2.py

This generates:

  • exp2_total_messages.png - Messages vs. number of subrings
  • exp2_total_rounds.png - Rounds vs. number of subrings
  • exp2_total_messages_vs_ringsize.png - Messages vs. average ring size
  • exp2_total_rounds_vs_ringsize.png - Rounds vs. average ring size

About

97/100 Distributed System, LCR Leader Election in Ring of Rings

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages