Mostly finished ex5.

This commit is contained in:
Filipe Rodrigues 2024-01-06 16:17:36 +00:00
parent e61ce5b73e
commit 1334745a58
Signed by: zenithsiz
SSH Key Fingerprint: SHA256:Mb5ppb3Sh7IarBO/sBTXLHbYEOz37hJAlslLQPPAPaU
5 changed files with 74 additions and 3 deletions

View File

@ -1,6 +1,7 @@
{
"cSpell.words": [
"byrow",
"forall",
"ggplot",
"ggsave",
"linebreak",

View File

@ -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) {

6
typst/appendixes/5.typ Normal file
View File

@ -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],
)

56
typst/exercises/5.typ Normal file
View File

@ -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.]

View File

@ -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"