From 1334745a580044daec494ae843eee88154bed0de Mon Sep 17 00:00:00 2001 From: Filipe Rodrigues Date: Sat, 6 Jan 2024 16:17:36 +0000 Subject: [PATCH] Mostly finished ex5. --- .vscode/settings.json | 1 + code/5.R | 4 +-- typst/appendixes/5.typ | 6 +++++ typst/exercises/5.typ | 56 ++++++++++++++++++++++++++++++++++++++++++ typst/main.typ | 10 ++++++++ 5 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 typst/appendixes/5.typ create mode 100644 typst/exercises/5.typ diff --git a/.vscode/settings.json b/.vscode/settings.json index c99f5e4..912a180 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,7 @@ { "cSpell.words": [ "byrow", + "forall", "ggplot", "ggsave", "linebreak", diff --git a/code/5.R b/code/5.R index 0cbdf4d..a3dfdfb 100644 --- a/code/5.R +++ b/code/5.R @@ -2,14 +2,12 @@ source("code/util/network_4_5.R") source("code/util/shortest_path.R") require(lpSolve) -numServers <- 1 +numServers <- 5 numNodes <- nrow(L) - Costs <- L Costs[L == 0] <- Inf -# Delays are deltas Delays <- matrix(rep(0, len = numNodes^2), nrow = numNodes) for (i in 1:numNodes) { for (j in 1:numNodes) { diff --git a/typst/appendixes/5.typ b/typst/appendixes/5.typ new file mode 100644 index 0000000..7d8637b --- /dev/null +++ b/typst/appendixes/5.typ @@ -0,0 +1,6 @@ +#import "/typst/util.typ" as util: indent_par, code_figure + +#code_figure( + text(size: 0.8em, raw(read("/code/5.R"), lang: "R", block: true)), + caption: [Code used for exercise 5], +) diff --git a/typst/exercises/5.typ b/typst/exercises/5.typ new file mode 100644 index 0000000..4e7e9d6 --- /dev/null +++ b/typst/exercises/5.typ @@ -0,0 +1,56 @@ +#import "/typst/util.typ" as util: indent_par, code_figure + + +#indent_par[In order to optimize the server locations, we've used the `lpSolve` package from `R`.] + +#indent_par[First, we declared the following variables:] + +- Number of servers, $z_i$, in node $i$. +- Replica, $g_i^j$, has node $i$ be served by node $j$ + + +#indent_par[Afterwards, we can construct the following equations:] + +#figure( + pad(1em, table( + columns: (auto, 1fr), + align: left + horizon, + + [Description], [Equation], + [Have at most `numServers` replicas], [$sum_i z_i = "numServers"$], + [For each node, it must be served by exactly 1 replica], [$forall_i sum_j g_i^j == 1$], + [If a node isn't a replica, no other node can be served by it.], [$forall_(i,j) g_i^j <= z_j$], + )), + kind: table, + caption: [Problem equations] +) + +#indent_par[Our objective function is the following in equation 2:] + +$ sum_i,j g_i^j dot C_i^j $ + +#indent_par[Where $C_i^j$ is the delay between nodes $i$ and $j$.] + +#indent_par[The code used to implement this is present in the appendix.] + +#pagebreak() + +#indent_par[After running our code for several different number of servers, we obtained the following results in table 14:] + +#figure( + pad(1em, table( + columns: (auto, auto, auto), + align: left + horizon, + + [Servers], [Replica servers], [Cost], + [1], [8], [3862.00], + [2], [5, 15], [2412.00], + [3], [5, 12, 13], [1832.00], + [4], [3, 5, 10, 13], [1521.00], + [5], [3, 5, 11, 12, 15], [1269.00], + )), + kind: table, + caption: [Problem equations] +) + +#indent_par[From this we can conclude that more replicas leads to a lower overall cost.] diff --git a/typst/main.typ b/typst/main.typ index 8236599..b803201 100644 --- a/typst/main.typ +++ b/typst/main.typ @@ -56,9 +56,16 @@ === 3. Exercise 3 #include "exercises/3.typ" +== B. Heuristic methods + === 4. Exercise 4 #include "exercises/4.typ" +== C. Replica placement + +=== 5. Exercise 5 +#include "exercises/5.typ" + #pagebreak() = Appendix @@ -74,3 +81,6 @@ === 4. Exercise 4 #include "appendixes/4.typ" + +=== 5. Exercise 5 +#include "appendixes/5.typ"