System Design & Architecture

End-to-end pipeline: from user input through profiling, energy estimation, carbon calculation, AGCM scoring, to visualization.

System Flow Diagram

9-stage processing pipeline from input to green recommendation

Algorithm name, input size, region, hardware profile, carbon budget
① User Input
CLI arguments / Streamlit form / config file
Bubble, Insertion, Merge, Quick, Naive Fib, Memo Fib, BFS, DFS
② Algorithm Selection
Load algorithm class from algorithms/ module
Random array generation, graph building, fibonacci n
③ Execution Engine
Generates input data and runs selected algorithm
time.perf_counter(), psutil.cpu_percent(), tracemalloc
④ Runtime Profiler
Measures execution time, CPU usage, memory usage
E = P × t, configurable CPU wattage (default 65W)
⑤ Energy Estimation Model
Computes energy in millijoules using power × time
C = E × Rc, regional intensity lookup from regions.py
⑥ Carbon Calculator
Converts energy to CO₂ with regional carbon intensity
AGCM = O(f(n)) × E_unit × H_f × R_c
⑦ AGCM Scoring Engine
Computes novel AGCM score incorporating all factors
Rank by AGCM, filter by carbon budget, suggest alternatives
⑧ Recommendation Engine
Identifies greenest algorithm and explains savings
matplotlib charts, pandas table, Streamlit widgets
⑨ Visualization Dashboard
Renders charts, ranked tables, and budget compliance report

Component Block Diagram

How every module connects and interacts within the AGCM system

main.py / app.py

Entry point. CLI or Streamlit interface. Orchestrates all modules.

config/settings.py

Global constants: CPU power, energy units, default region & hardware.

algorithms/

sorting.py · fibonacci.py · graph.py — all algorithm implementations.

profiler/runtime_profiler.py

Wraps algorithm execution. Returns time, CPU %, memory (KB).

energy/energy_model.py

EnergyModel class. Computes E = P × t in millijoules.

carbon/carbon_calculator.py

CarbonCalculator class. Uses regions.py for R_c lookup.

agcm/agcm_engine.py

Core AGCM computation. Combines all metrics into final score.

agcm/recommender.py

Ranks algorithms by AGCM. Generates textual recommendations.

agcm/budget_mode.py

Filters algorithms exceeding user-defined CO₂ budget.

visualization/charts.py

matplotlib bar, scatter, line charts. Exports PNG.

visualization/tables.py

pandas DataFrame formatting. tabulate output for CLI.

Output / Report

CSV export, PNG charts, CLI summary, Streamlit dashboard.

Inter-Module Data Flow

What each module receives and what it returns

# Module Receives Returns Data Type
1 User Input Layer CLI args / Streamlit form Config object dict / dataclass
2 Algorithm Loader Algorithm name, input size n Algorithm function reference + input data callable list
3 Runtime Profiler Algorithm function + data ProfileResult(time_s, cpu_pct, memory_kb) dataclass
4 Energy Model time_s, cpu_watt energy_mJ (float) float
5 Carbon Calculator energy_mJ, region_key carbon_mg (float) float
6 AGCM Engine complexity_order, E_unit, H_f, R_c, n agcm_score (float) float
7 Recommender List[AlgorithmResult] Ranked list + recommendation strings list[dataclass] str
8 Budget Mode List[AlgorithmResult], budget_mg Compliant list, Filtered list list[dataclass]
9 Visualization List[AlgorithmResult], charts config matplotlib figures / pandas tables / Streamlit widgets Figure DataFrame

AGCM Formula Derivation

Step-by-step mathematical foundation of the Adaptive Green Complexity Metric

Step 1 — Traditional Time Complexity

T(n) = O(f(n)) → Operations ≈ c × f(n)

Traditional Big-O gives us the operation count growth rate. We use a complexity multiplier to convert this to an absolute operation estimate for input size n.

Step 2 — Energy per Operation

E_total = P_cpu × t_exec [Joules]

Where P_cpu is the CPU's TDP in watts and t_exec is the measured execution time in seconds. We then normalize to get E_unit = E_total / f(n) — energy cost per logical operation.

Step 3 — Carbon Emission

C = E_total × R_c [gCO₂]

R_c is the regional carbon intensity (gCO₂/kWh). We convert E_total from joules to kWh first: E_kWh = E_total / 3,600,000.

Step 4 — Hardware Factor

E_adjusted = E_total × H_f

H_f accounts for hardware efficiency. An ARM laptop (H_f = 0.6) uses less energy than a legacy desktop (H_f = 1.5) for the same algorithm and input size.

Step 5 — AGCM Score (Final)

AGCM(n, h, r) = O(f(n)) × E_unit × H_f × R_c

The AGCM score integrates all four dimensions. A lower AGCM score means the algorithm is greener and more carbon-efficient in the given hardware and regional context.

SymbolMeaningUnitsSource
nInput sizeintegerUser input
O(f(n))Time complexity order multiplierdimensionlessAlgorithm metadata
E_unitEnergy per operationnJ/openergy_model.py
H_fHardware efficiency factordimensionless [0.6–1.5]config/settings.py
R_cRegional carbon intensitygCO₂/kWhcarbon/regions.py
AGCMAdaptive Green Complexity MetricμgCO₂-equivalentagcm/agcm_engine.py

Algorithm Complexity Reference

Time, space, and expected AGCM ranking for all implemented algorithms

AlgorithmCategoryBestAverageWorst SpaceAGCM RankGreen?
Quick SortSorting O(n log n)O(n log n)O(n²) O(log n)🥇 1st✅ Yes
Merge SortSorting O(n log n)O(n log n)O(n log n) O(n)🥈 2nd✅ Yes
Insertion SortSorting O(n)O(n²)O(n²) O(1)🥉 3rd⚠️ Small n
Bubble SortSorting O(n)O(n²)O(n²) O(1)4th❌ No
Memo FibonacciRecursion O(n)O(n)O(n) O(n)🥇 1st✅ Yes
Naive FibonacciRecursion O(2ⁿ)O(2ⁿ)O(2ⁿ) O(n)2nd❌ No
DFSGraph O(V+E)O(V+E)O(V+E) O(V)🥇 1st✅ Yes
BFSGraph O(V+E)O(V+E)O(V+E) O(V)2nd⚠️ Memory

Experimental Methodology

How experiments are designed for reproducibility and academic rigor

Experiment Design

  1. Input Generation: Random arrays of sizes [100, 500, 1000, 5000, 10000]
  2. Repetition: Each algorithm runs 5 times; median time is used to reduce noise
  3. Isolation: Algorithms run sequentially, not in parallel
  4. Warmup: 2 warmup runs discarded before measurement
  5. Environment: Record Python version, OS, CPU model, RAM

Measurement Protocol

  1. Time: time.perf_counter() — microsecond precision
  2. CPU: psutil.cpu_percent(interval=None) before and after
  3. Memory: tracemalloc.get_traced_memory() peak allocation
  4. Energy: E = P_tdp × t_exec (simplified hardware model)
  5. Carbon: C = E_kWh × R_c from regional lookup table

AGCM Calculation Steps

  1. Get complexity multiplier for algorithm (e.g., n log n for Merge Sort)
  2. Compute E_unit = energy_mJ / complexity_ops(n)
  3. Apply H_f based on user-selected hardware profile
  4. Apply R_c based on user-selected region
  5. AGCM = complexity_ops(n) × E_unit × H_f × R_c

Evaluation Metrics

  1. AGCM Score: Primary ranking metric (lower = greener)
  2. Carbon Saving %: vs. worst algorithm in category
  3. Energy Efficiency: mJ per 1000 operations
  4. Budget Compliance: Pass/Fail for user-set CO₂ budget
  5. Speedup Ratio: vs. baseline (Bubble / Naive Fib)