---
title: "SSSP Worked Example"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{SSSP Worked Example}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, collapse=TRUE}
library(sssp)
v <- c(10, -1, 2, 3, 9, 0, -4, -8, 7, 6)
groups <- c(3, 4, 3)
res <- sssp_project(v, groups, r = 3, s = 6)
print(res)
```

Here `v` is \(v \in \mathbb{R}^{10}\), `groups` encodes
\(\mathcal{L}_1=\{1,2,3\}\), \(\mathcal{L}_2=\{4,5,6,7\}\), and
\(\mathcal{L}_3=\{8,9,10\}\), `r` is the group sparsity level \(r\), and `s`
is the sparsity level \(s\). With \(r=p=3\), the group sparsity restriction is
removed and the feasible exact-\(s\) tuple count is 13.

```{r, collapse=TRUE}
res_r2 <- sssp_project(v, groups, r = 2, s = 6)
print(res_r2)
```

The same projection call accepts a list of 1-based index vectors. The next
example uses non-uniform groups of sizes 2, 6, and 4, with
\(|\mathcal{L}_1| < s\).

```{r, collapse=TRUE}
v2 <- c(4, -3, 5, 2, -6, 1, 7, -8, 0.5, 9, -2, 3)
groups2 <- list(c(1, 4), c(2, 3, 5, 8, 9, 10), c(6, 7, 11, 12))
res2 <- sssp_project(v2, groups2, r = 2, s = 5)
print(res2)
```
