---
title: "Brief introduction to mcMST"
author: "Jakob Bossek"
date: "`r Sys.Date()`"
output:
  rmarkdown::html_vignette:
    fig_caption: yes
vignette: >
  %\VignetteIndexEntry{Brief introduction to mcMST}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, echo = FALSE}
knitr::opts_chunk$set(collapse = T, comment = "#>", warning = FALSE, message = FALSE)
options(tibble.print_min = 4L, tibble.print_max = 4L)
```

# Quickstart

The **mcMST** package for the statistical programming language [R](https://www.r-project.org) contains methods for solving the multi-criteria minimum spanning tree problem (mcMST).

## Generating a benchmark instance

Here we first generate a bi-criteria graph with n = 25 nodes with the [grapherator](https://github.com/jakobbossek/grapherator) package. The first weight is the Euclidean distance of node coordinates in [0, 10] x [0, 10] in the Euclidean plane. The second weight follows a normal distribution with mean 5 and standard deviation 1.5. The instance generation process is modular and thus highly flexible (see the grapherator package vignettes for details and further examples).

```{r, fig.width=8, out.width='100%', fig.cap='Plot of the bi-objective sample graph `g.'}
library(mcMST)
library(grapherator)

set.seed(1) # reproducability
g = graph(0, 10)
g = addNodes(g, n = 25, generator = addNodesUniform)
g = addWeights(g, generator = addWeightsDistance, method = "euclidean")
g = addWeights(g, generator = addWeightsRandom, method = rnorm, mean = 5, sd = 1.5)
print(g)
do.call(gridExtra::grid.arrange, c(plot(g), list(nrow = 1L)))
```

## Running an algorithm

Next, we apply a (30 + 10) genetic algorithm based on the Pruefer-number encoding as proposed by Zhou & Gen to approximate the Pareto-front for `max.iter = 500` generations.

```{r, fig.width=8, out.width='100%', fig.cap="Approximation of the Pareto-front of the benchmark graph instance."}
res = mcMSTEmoaZhou(g, mu = 30L, lambda = 10L, max.iter = 500L)
head(res$pareto.front, n = 5)
ecr::plotFront(res$pareto.front)
```
