Skip to content

Commit

Permalink
add a few more examples
Browse files Browse the repository at this point in the history
  • Loading branch information
MHenderson committed May 3, 2023
1 parent 035ad7e commit d9ff5f7
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 14 deletions.
23 changes: 15 additions & 8 deletions R/plot_room_square.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
plot_room_square <- function(R) {

n <- max(R$col) + 1

nf <- n_filled_cells(R)
v <- volume(R)
n <- max(R$col) + 1

ggplot2::ggplot(data = R, ggplot2::aes(col, row)) +
ggplot2::geom_tile(data = R %>% dplyr::filter(!is.na(first)), ggplot2::aes(fill = visit)) +
Expand All @@ -16,10 +13,20 @@ plot_room_square <- function(R) {
ggplot2::theme(
legend.position = "none"
) +
ggplot2::scale_fill_gradient(limits = c(0, choose(n, 2)), low = "white", high = "blue") +
ggplot2::scale_fill_gradient(limits = c(0, choose(n, 2)), low = "white", high = "blue")
}

plot_room_square_labs <- function(R) {

n <- max(R$col) + 1

nf <- n_filled_cells(R)
v <- volume(R)

plot_room_square(R) +
ggplot2::labs(
title = glue::glue("A maximal partial Room square of order {n}"),
subtitle = glue::glue("Number of filled cells: {nf}, Volume: {v}.")
)
caption = glue::glue("Order: {n}\nFilled cells: {nf}\nVolume: {v}")
) +
ggplot2::theme(plot.caption = ggplot2::element_text(hjust = 0))

}
39 changes: 36 additions & 3 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ author: Matthew Henderson
output:
github_document:
toc: yes
toc_depth: 1
html_document:
toc: yes
editor_options:
Expand Down Expand Up @@ -69,8 +70,8 @@ of being a partial Room square
will not be violated.

```{r greedy1_example_plot}
R <- greedy1(8)
plot_room_square(R)
R <- greedy1(6)
plot_room_square_labs(R)
```

In this plot colour represents the order in which cells were filled.
Expand All @@ -81,6 +82,23 @@ The cells were filled in order from lightest to darkest.
is_maximal_proom(R)
```

## A few examples of maximal partial Room squares constructed with greedy1

```{r greedy1_examples_1, echo=FALSE}
library(patchwork)
R1 <- greedy1(8)
R2 <- greedy1(10)
(plot_room_square_labs(R1) + plot_room_square_labs(R2))
```

```{r greedy1_examples_2, echo=FALSE}
R3 <- greedy1(12)
plot_room_square_labs(R3)
```

# II: greedy2

`greedy2`
Expand All @@ -91,7 +109,7 @@ Room square are not violated.

```{r greedy2_example_plot}
R <- greedy2(8)
plot_room_square(R)
plot_room_square_labs(R)
```

Again colour represents order of filling, proceeding from lightest to darkest.
Expand All @@ -101,4 +119,19 @@ Again colour represents order of filling, proceeding from lightest to darkest.
is_maximal_proom(R)
```

## A few examples of maximal partial Room squares constructed with greedy2

```{r greedy2_examples_1, echo=FALSE, fig.cap="Put a caption here"}
R1 <- greedy2(8)
R2 <- greedy2(10)
(plot_room_square_labs(R1) + plot_room_square_labs(R2))
```

```{r greedy2_examples_2, echo=FALSE}
R3 <- greedy2(12)
plot_room_square_labs(R3)
```

# References
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ available pair such that the conditions of being a partial Room square
will not be violated.

``` r
R <- greedy1(8)
plot_room_square(R)
R <- greedy1(6)
plot_room_square_labs(R)
```

![](figure/greedy1_example_plot-1.png)<!-- -->
Expand All @@ -33,6 +33,12 @@ is_maximal_proom(R)
#> [1] TRUE
```

## A few examples of maximal partial Room squares constructed with greedy1

![](figure/greedy1_examples_1-1.png)<!-- -->

![](figure/greedy1_examples_2-1.png)<!-- -->

# II: greedy2

`greedy2` iterates through all pairs in order placing the next pair in
Expand All @@ -41,7 +47,7 @@ Room square are not violated.

``` r
R <- greedy2(8)
plot_room_square(R)
plot_room_square_labs(R)
```

![](figure/greedy2_example_plot-1.png)<!-- -->
Expand All @@ -55,6 +61,12 @@ is_maximal_proom(R)
#> [1] TRUE
```

## A few examples of maximal partial Room squares constructed with greedy2

![Put a caption here](figure/greedy2_examples_1-1.png)

![](figure/greedy2_examples_2-1.png)<!-- -->

# References

<div id="refs" class="references csl-bib-body hanging-indent">
Expand Down
Binary file modified figure/greedy1_example_plot-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added figure/greedy1_examples_1-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added figure/greedy1_examples_2-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figure/greedy2_example_plot-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added figure/greedy2_examples_1-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added figure/greedy2_examples_2-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d9ff5f7

Please sign in to comment.