This project implements K-Means Clustering, Genetic Algorithms (GA), and Particle Swarm Optimization (PSO) in both sequential and parallel versions. The implementations are written in C++ and Haskell, leveraging parallelism with Charm++ for C++ and Haskell Strategies for Haskell. The goal is to provide a comparative framework for these optimization and clustering algorithms across different languages and parallelization techniques.
- Algorithms: K-Means, Genetic Algorithm, Particle Swarm Optimization
- Languages: C++ and Haskell
- Parallelism:
- C++: Uses Charm++ for parallel execution.
- Haskell: Uses Haskell Strategies for parallel execution.
- Structure: Each algorithm has its own directory, with subdirectories for the implementation technology (C++/Charm++ or Haskell) and further divided into
parallelandsequentialversions.
.
├── kmeans
│ ├── charm++
│ │ ├── parallel # Parallel K-Means in C++ with Charm++
│ │ │ └── Makefile
│ │ └── sequential # Sequential K-Means in C++
│ │ └── Makefile
│ └── haskell
│ ├── parallel # Parallel K-Means in Haskell
│ │ └── kmeans.cabal
│ └── sequential # Sequential K-Means in Haskell
│ └── kmeans.cabal
├── ga
│ ├── charm++
│ │ ├── parallel # Parallel GA in C++ with Charm++
│ │ │ └── Makefile
│ │ └── sequential # Sequential GA in C++
│ │ └── Makefile
│ └── haskell
│ ├── parallel # Parallel GA in Haskell
│ │ └── ga.cabal
│ └── sequential # Sequential GA in Haskell
│ └── ga.cabal
├── pso
│ ├── charm++
│ │ ├── parallel # Parallel PSO in C++ with Charm++
│ │ │ └── Makefile
│ │ └── sequential # Sequential PSO in C++
│ │ └── Makefile
│ └── haskell
│ ├── parallel # Parallel PSO in Haskell
│ │ └── pso.cabal
│ └── sequential # Sequential PSO in Haskell
│ └── pso.cabal
└── README.md
- g++: C++ compiler (e.g., GCC).
- Charm++: Required for parallel C++ implementations. Install it by following the Charm++ installation guide.
- GHC: Glasgow Haskell Compiler (version compatible with base >=4.13).
- Cabal: Haskell package manager (version >= 1.10).
- Dependencies: Install required Haskell libraries:
cabal update cabal install random split normaldistribution criterion-measurement deepseq parallel
Each charm++/parallel and charm++/sequential directory contains a Makefile to compile the code.
-
Navigate to the desired directory:
cd ga/charm++/parallel # Example for parallel GA
-
Build the project:
make
This compiles the source files (e.g.,
main.cpp,ga.cpp) into an executable named after the algorithm (e.g.,ga). -
Run the executable:
./ga
-
Clean up (optional):
make clean
This removes object files and the executable.
- Ensure Charm++ is installed and configured.
- You may need to adjust the
Makefileto include Charm++-specific flags (e.g., linking withcharmcinstead ofg++).
Each haskell/parallel and haskell/sequential directory contains a .cabal file (e.g., ga.cabal) to build and run the code.
-
Navigate to the desired directory:
cd ga/haskell/parallel # Example for parallel GA
-
Build the project:
cabal build
This compiles the Haskell source files (e.g.,
Main.hs,GA.hs) with optimizations (-O2) and threading support. -
Run the executable:
cabal run ga
For parallel execution, you can specify runtime options:
cabal run ga -- +RTS -N -RTS
-Nenables all available CPU cores for parallelism. -
Clean up (optional):
cabal clean
- Makefile (C++): Compiles
.cppfiles into object files and links them into an executable. - ga.cabal (Haskell): Specifies dependencies, source directories, and GHC options like
-threadedfor parallelism.
Feel free to fork this repository, submit issues, or contribute improvements via pull requests.
See the LICENSE file for details.