Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Social Network Simulation

Author: Harsh Raj Singh (250847420)

Overview

This project implements a concurrent social network simulation using Advanced Functional Programming techniques. It models 10 independent user threads interacting via message passing, designed to demonstrate High-Assurance software architecture.

Unlike standard implementations, this project uses:

  • Software Transactional Memory (STM) for deadlock-free concurrency (replacing raw MVars).
  • Tagless Final style to decouple pure logic from IO effects.
  • Type-Level States (GADTs) to make invalid agent states unrepresentable.

Extensions Implemented (Top 20%)

  1. Mood Propagation Dynamics: Users are emotional agents. Their internal mood (Happy, Neutral, Sad) evolves based on the "Vibe" of messages received, creating a dynamic feedback loop.
    • Effect: Mood influences both the content of sent messages and the response latency (simulating human reaction times).
  2. Log Parsing & Analytics: A custom Megaparsec grammar parses the simulation logs to generate an ASCII Pie Chart of the final network mood distribution, verifying the propagation mechanics.

Usage

The application uses a CLI for various operations:

  1. Run Simulation (Default):

    stack run

    Executes the simulation (10 users, 100 messages) and prints the final message counts.

  2. Analyze Log (Visualization):

    stack run -- analyze-log

    Parses the generated social_network_chat.log and displays the Mood Distribution Pie Chart.

  3. View Log/Help:

    stack run -- view-log
    stack run -- help

Testing & Verification

The project employs Property-Based Testing (QuickCheck) to verify invariants (e.g., algebraic laws for counters, round-trip correctnes for parsers).

  • Run All Tests:
    stack test
  • Check Code Coverage:
    stack test --coverage
    (Open the generated HTML report in .stack-work/.../hpc/index.html to verify 100% coverage of pure logic modules).

Project Structure

  • app/Main.hs: CLI Entry point.
  • src/Run.hs: Simulation wiring and Supervisor.
  • src/Config.hs: Global simulation constants.
  • src/UserBehaviour.hs: Core "Brain" logic (Pure).
  • src/Types.hs: Domain types (User, Message, Monoids).
  • src/Env.hs: Runtime environment context.
  • src/Effects.hs: Abstract Effect capability definitions.
  • src/AppM.hs: Concrete interpreter (ReaderT Env IO).
  • src/Logger.hs: Concurrent logging service.
  • src/LogParser.hs: Parsing logic for analytics.
  • test/Spec.hs: Test suite (Properties & Unit tests).

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages