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
- Java
- Python (for plotting)
Navigate to the project directory and compile all Java source files:
javac *.javaThis will compile all .java files in the directory, including:
Main.javaExperimentRunner.javaProcessor.javaInterfaceProcessor.javaMessage.javaSimulator.java
The Main.java file contains hand-crafted examples to demonstrate the algorithm's correctness with specific topologies.
Run:
java MainWhat 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
The ExperimentRunner.java file runs comprehensive experiments to collect performance data for analysis.
Run:
java ExperimentRunnerWhat it does:
- 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
- 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.
After running ExperimentRunner.java, use the Python scripts to generate visualizations.
- Install Python dependencies:
cd "./plots"
pip install -r requirements.txt- Run plotting scripts:
For Experiment 1 plots:
python plot_exp1.pyThis generates:
exp1_total_messages.png- Message complexity vs. network sizeexp1_total_rounds.png- Time complexity vs. network size
For Experiment 2 plots:
python plot_exp2.pyThis generates:
exp2_total_messages.png- Messages vs. number of subringsexp2_total_rounds.png- Rounds vs. number of subringsexp2_total_messages_vs_ringsize.png- Messages vs. average ring sizeexp2_total_rounds_vs_ringsize.png- Rounds vs. average ring size