README.md

M2algorithmique Vignette

Vincent Runge

LaMME, Evry Paris-Saclay University

March 27, 2025

Package Presentation

Quick Start

Examples

Analysis

Package Presentation

The M2algorithmique R/Rcpp package is an example package designed to help students develop their own R/Rcpp packages as part of the M2 Algorithmic courses in the Data Science master’s program at Université d’Évry Paris-Saclay.

This package provides implementations of various algorithmic strategies in both R and Rcpp, including:

This package serves as a reference for students, demonstrating good practices in algorithm implementation and package development in Rcpp.

Quick Start

Prerequisites for Package Development

To develop and use the package, install the necessary dependencies:

install.packages(c("Rcpp", "RcppArmadillo", "devtools", "roxygen2", "testthat"))

Installing the Package from GitHub

To install the M2algorithmique package, use:

devtools::install_github("vrunge/M2algorithmique")

Then, load the package:

library(M2algorithmique)

Setting Up a C++ Compiler (Windows Users)

Since Rcpp requires a C++ compiler, Windows users must install Rtools:

Download and install Rtools from: https://cran.r-project.org/bin/windows/Rtools/

For general R updates and additional package downloads, visit the CRAN: https://cran.r-project.org/

Package Structure

Examples

Sorting Algorithms (Recursive)

n <- 10
v <- sample(n)
v
##  [1] 10  7  3  2  1  6  8  5  4  9

We implemeted 4 algorithms:

They all have a unique argument: the unsorted vector v. Examples:

insertion_sort(v)
##  [1]  1  2  3  4  5  6  7  8  9 10
heap_sort_Rcpp(v)
##  [1]  1  2  3  4  5  6  7  8  9 10

Dijkstra Algorithms (Dynamic Programming)

TSP Algorithms (Heuristic)

We generate n = 20 towns (villes) randomly in a 2D plane using a uniform distribution:

n <- 20
villes <- matrix(runif(2 * n), n, 2)

Visualization of the Towns

We implemented four heuristic algorithms and one exact algorithm for solving the Travelling Salesman Problem (TSP):

Each algorithm also has an equivalent Rcpp implementation for performance optimization.

Example

Analysis

The Pour_les_etudiants folder contains the following analysis files:

These documents, written in French, outline the type of analysis students are expected to conduct to validate this course.



vrunge/M2algorithmique documentation built on April 5, 2025, 4:06 a.m.