Added rust implementation of 3b.

This commit is contained in:
Filipe Rodrigues 2023-12-04 19:41:39 +00:00
parent 3bb4f52cff
commit f31830d785
10 changed files with 566 additions and 4 deletions

1
.gitignore vendored
View File

@ -2,6 +2,7 @@
typst/**/*.pdf
output/
Rplots.pdf
code/target/
# Exceptions
!guide.pdf

View File

@ -1,4 +1,4 @@
data <- read.table("data/2dtmc_data.csv", sep = "\t")
data <- read.csv("data/2dtmc_data.csv", sep = "\t")
data <- data$x
occur_matrix <- matrix(

View File

@ -7,7 +7,7 @@ status_backlogged <- "Backlogged"
calc_throughput <- function(slots_len, prob_backlogged, prob_thinking) {
slots <- as.list(rep(status_thinking, slots_len))
total_steps <- 50000
total_steps <- 10000000
successes <- 0
for (cur_step in 1:total_steps) {
# Get all the slots that will be transmitting

29
code/3b_rust.R Normal file
View File

@ -0,0 +1,29 @@
require(ggplot2)
require(pracma)
data <- read.csv("output/3b.csv")
data <- data[with(data, order(data$p, data$s)), ]
create_graph <- function(slots_len, probs_thinking, probs_backlogged, output_file) {
throughput <- subset(data, data$N == slots_len)$t
prob_names <- lapply(probs_backlogged, function(prob) rep(as.character(prob), length(probs_thinking)))
throughput_data <- data.frame(
x = probs_thinking,
y = unlist(throughput),
p = unlist(prob_names)
)
plot <- ggplot(throughput_data) +
geom_line(aes(.data$x, .data$y, color = .data$p)) +
scale_x_log10(limit = c(0.0005, 0.3)) +
ylim(0.0, 0.4) +
xlab("σ") +
ylab("Throughput")
ggsave(plot, file = output_file, device = "svg")
}
set.seed(0)
pdf(NULL)
create_graph(10, logseq(1 + 1e-7, 1.3, 1000) - 1, c(0.3, 0.4, 0.5, 0.6), "output/3b-aloha10.svg")
create_graph(25, logseq(1 + 1e-7, 1.3, 1000) - 1, c(0.2, 0.3), "output/3b-aloha25.svg")

163
code/Cargo.lock generated Normal file
View File

@ -0,0 +1,163 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "arrayvec"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711"
[[package]]
name = "autocfg"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "crossbeam-deque"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef"
dependencies = [
"cfg-if",
"crossbeam-epoch",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-epoch"
version = "0.9.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae211234986c545741a7dc064309f67ee1e5ad243d0e48335adc0484d960bcc7"
dependencies = [
"autocfg",
"cfg-if",
"crossbeam-utils",
"memoffset",
"scopeguard",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294"
dependencies = [
"cfg-if",
]
[[package]]
name = "either"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07"
[[package]]
name = "ex_3b"
version = "0.1.0"
dependencies = [
"arrayvec",
"rand",
"rayon",
]
[[package]]
name = "getrandom"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f"
dependencies = [
"cfg-if",
"libc",
"wasi",
]
[[package]]
name = "libc"
version = "0.2.150"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c"
[[package]]
name = "memoffset"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c"
dependencies = [
"autocfg",
]
[[package]]
name = "ppv-lite86"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
]
[[package]]
name = "rand_chacha"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
dependencies = [
"getrandom",
]
[[package]]
name = "rayon"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c27db03db7734835b3f53954b534c91069375ce6ccaa2e065441e07d9b6cdb1"
dependencies = [
"either",
"rayon-core",
]
[[package]]
name = "rayon-core"
version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ce3fb6ad83f861aac485e76e1985cd109d9a3713802152be56c3b1f0e0658ed"
dependencies = [
"crossbeam-deque",
"crossbeam-utils",
]
[[package]]
name = "scopeguard"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"

11
code/Cargo.toml Normal file
View File

@ -0,0 +1,11 @@
[workspace]
resolver = "2"
members = ["ex_3b"]
[workspace.dependencies]
rand = "0.8.5"
rayon = "1.8.0"
arrayvec = "0.7.4"

10
code/ex_3b/Cargo.toml Normal file
View File

@ -0,0 +1,10 @@
[package]
name = "ex_3b"
version = "0.1.0"
edition = "2021"
[dependencies]
rand = { workspace = true }
rayon = { workspace = true }
arrayvec = { workspace = true }

281
code/ex_3b/src/main.rs Normal file
View File

@ -0,0 +1,281 @@
//! Ex. 3b
use arrayvec::ArrayVec;
// Imports
use rand::distributions::{Bernoulli, Distribution};
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
enum State {
Thinking,
Backlogged,
}
fn calc_throughput(slots_len: usize, prob_backlogged: f64, prob_thinking: f64) -> f64 {
let mut slots = vec![State::Thinking; slots_len];
let total_steps = 10_000_000;
let mut successes = 0;
let mut transmitting = ArrayVec::<_, 25>::new();
let mut rng = rand::thread_rng();
let dist_backlogged = Bernoulli::new(prob_backlogged).expect("Unable to create bernoulli distribution");
let dist_thinking = Bernoulli::new(prob_thinking).expect("Unable to create bernoulli distribution");
for _cur_step in 0..total_steps {
transmitting.extend(slots.iter_mut().enumerate().filter_map(|(slot_idx, slot)| {
let dist = match slot {
State::Thinking => &dist_backlogged,
State::Backlogged => &dist_thinking,
};
dist.sample(&mut rng).then_some(slot_idx)
}));
let success = transmitting.len() == 1;
let next_state = match success {
true => State::Thinking,
false => State::Backlogged,
};
for slot_idx in transmitting.drain(..) {
slots[slot_idx] = next_state;
}
successes += usize::from(success);
}
successes as f64 / total_steps as f64
}
fn main() {
#[rustfmt::skip]
let probs_backlogged = [
0.0000001000, 0.0002627613, 0.0005254916, 0.0007882909, 0.0010511592,
0.0013140966, 0.0015771031, 0.0018401786, 0.0021033232, 0.0023665370,
0.0026298198, 0.0028931719, 0.0031565931, 0.0034200835, 0.0036836431,
0.0039472719, 0.0042109700, 0.0044747373, 0.0047385739, 0.0050024799,
0.0052664551, 0.0055304997, 0.0057946136, 0.0060587969, 0.0063230496,
0.0065873717, 0.0068517632, 0.0071162242, 0.0073807546, 0.0076453546,
0.0079100240, 0.0081747629, 0.0084395714, 0.0087044494, 0.0089693970,
0.0092344142, 0.0094995010, 0.0097646575, 0.0100298835, 0.0102951793,
0.0105605447, 0.0108259798, 0.0110914847, 0.0113570593, 0.0116227036,
0.0118884177, 0.0121542016, 0.0124200553, 0.0126859789, 0.0129519723,
0.0132180355, 0.0134841687, 0.0137503717, 0.0140166447, 0.0142829876,
0.0145494005, 0.0148158833, 0.0150824362, 0.0153490590, 0.0156157519,
0.0158825148, 0.0161493478, 0.0164162509, 0.0166832241, 0.0169502674,
0.0172173809, 0.0174845645, 0.0177518183, 0.0180191423, 0.0182865365,
0.0185540010, 0.0188215357, 0.0190891406, 0.0193568159, 0.0196245615,
0.0198923774, 0.0201602636, 0.0204282202, 0.0206962472, 0.0209643446,
0.0212325124, 0.0215007506, 0.0217690593, 0.0220374385, 0.0223058881,
0.0225744083, 0.0228429990, 0.0231116603, 0.0233803921, 0.0236491945,
0.0239180675, 0.0241870111, 0.0244560254, 0.0247251103, 0.0249942659,
0.0252634923, 0.0255327893, 0.0258021570, 0.0260715955, 0.0263411048,
0.0266106849, 0.0268803358, 0.0271500575, 0.0274198500, 0.0276897134,
0.0279596477, 0.0282296529, 0.0284997290, 0.0287698761, 0.0290400941,
0.0293103831, 0.0295807431, 0.0298511741, 0.0301216761, 0.0303922492,
0.0306628933, 0.0309336086, 0.0312043949, 0.0314752524, 0.0317461810,
0.0320171808, 0.0322882517, 0.0325593939, 0.0328306072, 0.0331018919,
0.0333732477, 0.0336446749, 0.0339161733, 0.0341877430, 0.0344593841,
0.0347310965, 0.0350028803, 0.0352747355, 0.0355466621, 0.0358186601,
0.0360907296, 0.0363628705, 0.0366350829, 0.0369073668, 0.0371797222,
0.0374521492, 0.0377246477, 0.0379972178, 0.0382698594, 0.0385425727,
0.0388153577, 0.0390882142, 0.0393611425, 0.0396341424, 0.0399072140,
0.0401803574, 0.0404535725, 0.0407268594, 0.0410002180, 0.0412736485,
0.0415471507, 0.0418207248, 0.0420943708, 0.0423680887, 0.0426418784,
0.0429157400, 0.0431896736, 0.0434636792, 0.0437377567, 0.0440119062,
0.0442861277, 0.0445604212, 0.0448347868, 0.0451092244, 0.0453837341,
0.0456583160, 0.0459329699, 0.0462076960, 0.0464824943, 0.0467573647,
0.0470323073, 0.0473073222, 0.0475824093, 0.0478575686, 0.0481328002,
0.0484081041, 0.0486834803, 0.0489589289, 0.0492344498, 0.0495100430,
0.0497857087, 0.0500614468, 0.0503372572, 0.0506131402, 0.0508890956,
0.0511651234, 0.0514412238, 0.0517173967, 0.0519936421, 0.0522699601,
0.0525463507, 0.0528228139, 0.0530993497, 0.0533759581, 0.0536526392,
0.0539293929, 0.0542062194, 0.0544831185, 0.0547600904, 0.0550371351,
0.0553142525, 0.0555914427, 0.0558687057, 0.0561460415, 0.0564234502,
0.0567009317, 0.0569784861, 0.0572561134, 0.0575338137, 0.0578115869,
0.0580894330, 0.0583673521, 0.0586453443, 0.0589234094, 0.0592015476,
0.0594797588, 0.0597580431, 0.0600364005, 0.0603148311, 0.0605933347,
0.0608719115, 0.0611505615, 0.0614292846, 0.0617080810, 0.0619869506,
0.0622658935, 0.0625449096, 0.0628239990, 0.0631031617, 0.0633823978,
0.0636617071, 0.0639410899, 0.0642205460, 0.0645000755, 0.0647796785,
0.0650593549, 0.0653391047, 0.0656189281, 0.0658988249, 0.0661787953,
0.0664588392, 0.0667389566, 0.0670191476, 0.0672994122, 0.0675797505,
0.0678601623, 0.0681406478, 0.0684212070, 0.0687018399, 0.0689825465,
0.0692633268, 0.0695441809, 0.0698251088, 0.0701061104, 0.0703871858,
0.0706683351, 0.0709495582, 0.0712308552, 0.0715122261, 0.0717936708,
0.0720751895, 0.0723567822, 0.0726384488, 0.0729201894, 0.0732020040,
0.0734838926, 0.0737658552, 0.0740478919, 0.0743300027, 0.0746121876,
0.0748944467, 0.0751767798, 0.0754591871, 0.0757416686, 0.0760242243,
0.0763068542, 0.0765895583, 0.0768723367, 0.0771551894, 0.0774381163,
0.0777211176, 0.0780041932, 0.0782873432, 0.0785705675, 0.0788538662,
0.0791372394, 0.0794206870, 0.0797042090, 0.0799878055, 0.0802714764,
0.0805552219, 0.0808390420, 0.0811229365, 0.0814069057, 0.0816909494,
0.0819750677, 0.0822592607, 0.0825435283, 0.0828278705, 0.0831122875,
0.0833967792, 0.0836813455, 0.0839659867, 0.0842507026, 0.0845354932,
0.0848203587, 0.0851052990, 0.0853903142, 0.0856754042, 0.0859605691,
0.0862458089, 0.0865311236, 0.0868165132, 0.0871019779, 0.0873875175,
0.0876731321, 0.0879588217, 0.0882445863, 0.0885304261, 0.0888163408,
0.0891023307, 0.0893883958, 0.0896745359, 0.0899607512, 0.0902470417,
0.0905334074, 0.0908198483, 0.0911063644, 0.0913929558, 0.0916796225,
0.0919663645, 0.0922531817, 0.0925400744, 0.0928270423, 0.0931140857,
0.0934012044, 0.0936883986, 0.0939756682, 0.0942630132, 0.0945504338,
0.0948379298, 0.0951255013, 0.0954131484, 0.0957008710, 0.0959886692,
0.0962765430, 0.0965644924, 0.0968525174, 0.0971406181, 0.0974287945,
0.0977170465, 0.0980053743, 0.0982937778, 0.0985822570, 0.0988708121,
0.0991594429, 0.0994481495, 0.0997369320, 0.1000257903, 0.1003147245,
0.1006037345, 0.1008928205, 0.1011819824, 0.1014712203, 0.1017605341,
0.1020499240, 0.1023393898, 0.1026289317, 0.1029185496, 0.1032082436,
0.1034980137, 0.1037878599, 0.1040777822, 0.1043677807, 0.1046578554,
0.1049480062, 0.1052382333, 0.1055285366, 0.1058189161, 0.1061093719,
0.1063999040, 0.1066905125, 0.1069811972, 0.1072719583, 0.1075627958,
0.1078537096, 0.1081446999, 0.1084357666, 0.1087269098, 0.1090181294,
0.1093094255, 0.1096007982, 0.1098922473, 0.1101837730, 0.1104753753,
0.1107670542, 0.1110588097, 0.1113506418, 0.1116425506, 0.1119345361,
0.1122265982, 0.1125187371, 0.1128109527, 0.1131032450, 0.1133956142,
0.1136880601, 0.1139805828, 0.1142731824, 0.1145658588, 0.1148586121,
0.1151514423, 0.1154443494, 0.1157373334, 0.1160303944, 0.1163235324,
0.1166167474, 0.1169100394, 0.1172034084, 0.1174968545, 0.1177903776,
0.1180839779, 0.1183776552, 0.1186714097, 0.1189652414, 0.1192591503,
0.1195531363, 0.1198471996, 0.1201413401, 0.1204355578, 0.1207298529,
0.1210242252, 0.1213186749, 0.1216132019, 0.1219078062, 0.1222024880,
0.1224972471, 0.1227920837, 0.1230869977, 0.1233819891, 0.1236770581,
0.1239722045, 0.1242674285, 0.1245627300, 0.1248581091, 0.1251535658,
0.1254491001, 0.1257447120, 0.1260404015, 0.1263361687, 0.1266320136,
0.1269279362, 0.1272239366, 0.1275200147, 0.1278161705, 0.1281124042,
0.1284087156, 0.1287051049, 0.1290015720, 0.1292981170, 0.1295947399,
0.1298914407, 0.1301882194, 0.1304850761, 0.1307820108, 0.1310790234,
0.1313761141, 0.1316732828, 0.1319705295, 0.1322678544, 0.1325652573,
0.1328627383, 0.1331602975, 0.1334579349, 0.1337556504, 0.1340534441,
0.1343513160, 0.1346492662, 0.1349472946, 0.1352454013, 0.1355435863,
0.1358418497, 0.1361401913, 0.1364386114, 0.1367371098, 0.1370356866,
0.1373343419, 0.1376330756, 0.1379318877, 0.1382307784, 0.1385297475,
0.1388287952, 0.1391279214, 0.1394271262, 0.1397264096, 0.1400257716,
0.1403252123, 0.1406247315, 0.1409243295, 0.1412240061, 0.1415237615,
0.1418235956, 0.1421235084, 0.1424235001, 0.1427235705, 0.1430237197,
0.1433239478, 0.1436242547, 0.1439246405, 0.1442251052, 0.1445256489,
0.1448262714, 0.1451269730, 0.1454277535, 0.1457286130, 0.1460295516,
0.1463305692, 0.1466316658, 0.1469328415, 0.1472340964, 0.1475354304,
0.1478368435, 0.1481383358, 0.1484399073, 0.1487415580, 0.1490432879,
0.1493450971, 0.1496469855, 0.1499489533, 0.1502510004, 0.1505531268,
0.1508553325, 0.1511576177, 0.1514599822, 0.1517624261, 0.1520649495,
0.1523675524, 0.1526702347, 0.1529729966, 0.1532758379, 0.1535787588,
0.1538817593, 0.1541848394, 0.1544879990, 0.1547912383, 0.1550945573,
0.1553979559, 0.1557014342, 0.1560049922, 0.1563086300, 0.1566123475,
0.1569161448, 0.1572200218, 0.1575239787, 0.1578280155, 0.1581321321,
0.1584363285, 0.1587406049, 0.1590449612, 0.1593493974, 0.1596539136,
0.1599585098, 0.1602631860, 0.1605679422, 0.1608727785, 0.1611776948,
0.1614826912, 0.1617877677, 0.1620929244, 0.1623981612, 0.1627034782,
0.1630088754, 0.1633143528, 0.1636199104, 0.1639255483, 0.1642312665,
0.1645370650, 0.1648429438, 0.1651489029, 0.1654549424, 0.1657610623,
0.1660672626, 0.1663735433, 0.1666799045, 0.1669863461, 0.1672928683,
0.1675994709, 0.1679061541, 0.1682129178, 0.1685197621, 0.1688266870,
0.1691336925, 0.1694407787, 0.1697479455, 0.1700551930, 0.1703625212,
0.1706699301, 0.1709774197, 0.1712849902, 0.1715926414, 0.1719003734,
0.1722081863, 0.1725160800, 0.1728240545, 0.1731321100, 0.1734402464,
0.1737484637, 0.1740567620, 0.1743651412, 0.1746736015, 0.1749821428,
0.1752907651, 0.1755994685, 0.1759082529, 0.1762171185, 0.1765260652,
0.1768350930, 0.1771442020, 0.1774533922, 0.1777626637, 0.1780720163,
0.1783814502, 0.1786909654, 0.1790005619, 0.1793102397, 0.1796199988,
0.1799298393, 0.1802397612, 0.1805497645, 0.1808598492, 0.1811700153,
0.1814802630, 0.1817905921, 0.1821010027, 0.1824114949, 0.1827220686,
0.1830327239, 0.1833434608, 0.1836542793, 0.1839651794, 0.1842761613,
0.1845872248, 0.1848983699, 0.1852095969, 0.1855209055, 0.1858322960,
0.1861437682, 0.1864553223, 0.1867669581, 0.1870786759, 0.1873904755,
0.1877023570, 0.1880143204, 0.1883263658, 0.1886384931, 0.1889507024,
0.1892629937, 0.1895753670, 0.1898878224, 0.1902003599, 0.1905129794,
0.1908256811, 0.1911384649, 0.1914513309, 0.1917642790, 0.1920773093,
0.1923904219, 0.1927036167, 0.1930168937, 0.1933302531, 0.1936436947,
0.1939572187, 0.1942708250, 0.1945845137, 0.1948982848, 0.1952121384,
0.1955260743, 0.1958400927, 0.1961541936, 0.1964683770, 0.1967826429,
0.1970969914, 0.1974114224, 0.1977259360, 0.1980405323, 0.1983552111,
0.1986699726, 0.1989848168, 0.1992997437, 0.1996147533, 0.1999298457,
0.2002450208, 0.2005602787, 0.2008756194, 0.2011910429, 0.2015065493,
0.2018221385, 0.2021378107, 0.2024535657, 0.2027694037, 0.2030853247,
0.2034013286, 0.2037174155, 0.2040335855, 0.2043498385, 0.2046661746,
0.2049825937, 0.2052990960, 0.2056156814, 0.2059323500, 0.2062491017,
0.2065659366, 0.2068828548, 0.2071998562, 0.2075169408, 0.2078341088,
0.2081513600, 0.2084686946, 0.2087861126, 0.2091036139, 0.2094211986,
0.2097388667, 0.2100566182, 0.2103744533, 0.2106923718, 0.2110103738,
0.2113284593, 0.2116466284, 0.2119648811, 0.2122832173, 0.2126016372,
0.2129201407, 0.2132387278, 0.2135573987, 0.2138761532, 0.2141949915,
0.2145139135, 0.2148329193, 0.2151520088, 0.2154711822, 0.2157904394,
0.2161097805, 0.2164292055, 0.2167487143, 0.2170683071, 0.2173879838,
0.2177077445, 0.2180275892, 0.2183475179, 0.2186675306, 0.2189876273,
0.2193078082, 0.2196280731, 0.2199484222, 0.2202688554, 0.2205893728,
0.2209099744, 0.2212306602, 0.2215514302, 0.2218722844, 0.2221932230,
0.2225142458, 0.2228353530, 0.2231565445, 0.2234778203, 0.2237991806,
0.2241206252, 0.2244421543, 0.2247637679, 0.2250854659, 0.2254072484,
0.2257291155, 0.2260510670, 0.2263731032, 0.2266952239, 0.2270174292,
0.2273397192, 0.2276620938, 0.2279845531, 0.2283070971, 0.2286297258,
0.2289524393, 0.2292752375, 0.2295981205, 0.2299210883, 0.2302441410,
0.2305672785, 0.2308905009, 0.2312138082, 0.2315372003, 0.2318606775,
0.2321842396, 0.2325078867, 0.2328316188, 0.2331554359, 0.2334793381,
0.2338033254, 0.2341273977, 0.2344515552, 0.2347757978, 0.2351001256,
0.2354245386, 0.2357490368, 0.2360736202, 0.2363982889, 0.2367230429,
0.2370478821, 0.2373728067, 0.2376978166, 0.2380229119, 0.2383480926,
0.2386733587, 0.2389987102, 0.2393241472, 0.2396496697, 0.2399752777,
0.2403009711, 0.2406267502, 0.2409526148, 0.2412785650, 0.2416046008,
0.2419307223, 0.2422569294, 0.2425832222, 0.2429096007, 0.2432360649,
0.2435626149, 0.2438892506, 0.2442159722, 0.2445427795, 0.2448696727,
0.2451966518, 0.2455237168, 0.2458508676, 0.2461781044, 0.2465054271,
0.2468328358, 0.2471603306, 0.2474879113, 0.2478155781, 0.2481433309,
0.2484711698, 0.2487990949, 0.2491271060, 0.2494552033, 0.2497833869,
0.2501116566, 0.2504400125, 0.2507684547, 0.2510969831, 0.2514255978,
0.2517542989, 0.2520830863, 0.2524119600, 0.2527409202, 0.2530699667,
0.2533990997, 0.2537283191, 0.2540576249, 0.2543870173, 0.2547164962,
0.2550460617, 0.2553757137, 0.2557054523, 0.2560352775, 0.2563651893,
0.2566951878, 0.2570252730, 0.2573554448, 0.2576857034, 0.2580160488,
0.2583464809, 0.2586769998, 0.2590076055, 0.2593382980, 0.2596690774,
0.2599999437, 0.2603308969, 0.2606619371, 0.2609930641, 0.2613242782,
0.2616555792, 0.2619869673, 0.2623184424, 0.2626500046, 0.2629816539,
0.2633133903, 0.2636452138, 0.2639771244, 0.2643091223, 0.2646412073,
0.2649733796, 0.2653056391, 0.2656379859, 0.2659704200, 0.2663029415,
0.2666355502, 0.2669682463, 0.2673010298, 0.2676339007, 0.2679668591,
0.2682999049, 0.2686330382, 0.2689662589, 0.2692995672, 0.2696329631,
0.2699664465, 0.2703000175, 0.2706336761, 0.2709674224, 0.2713012563,
0.2716351780, 0.2719691873, 0.2723032843, 0.2726374692, 0.2729717417,
0.2733061021, 0.2736405503, 0.2739750864, 0.2743097103, 0.2746444221,
0.2749792219, 0.2753141096, 0.2756490852, 0.2759841488, 0.2763193004,
0.2766545401, 0.2769898678, 0.2773252836, 0.2776607875, 0.2779963795,
0.2783320597, 0.2786678280, 0.2790036846, 0.2793396293, 0.2796756623,
0.2800117835, 0.2803479931, 0.2806842909, 0.2810206771, 0.2813571516,
0.2816937145, 0.2820303659, 0.2823671056, 0.2827039338, 0.2830408504,
0.2833778556, 0.2837149493, 0.2840521315, 0.2843894022, 0.2847267616,
0.2850642096, 0.2854017462, 0.2857393715, 0.2860770854, 0.2864148881,
0.2867527795, 0.2870907596, 0.2874288285, 0.2877669862, 0.2881052327,
0.2884435681, 0.2887819923, 0.2891205055, 0.2894591075, 0.2897977985,
0.2901365784, 0.2904754474, 0.2908144053, 0.2911534523, 0.2914925883,
0.2918318134, 0.2921711276, 0.2925105309, 0.2928500234, 0.2931896050,
0.2935292758, 0.2938690359, 0.2942088852, 0.2945488238, 0.2948888516,
0.2952289688, 0.2955691753, 0.2959094711, 0.2962498564, 0.2965903310,
0.2969308951, 0.2972715486, 0.2976122916, 0.2979531241, 0.2982940462,
0.2986350578, 0.2989761589, 0.2993173496, 0.2996586300, 0.3000000000,
];
let probs_thinking_10 = [0.3, 0.4, 0.5, 0.6];
let probs_thinking_25 = [0.2, 0.3];
println!("N,s,p,t");
let thread_pool = rayon::ThreadPoolBuilder::new()
.build()
.expect("Unable to build thread pool");
thread_pool.scope(|s| {
for prob_thinking in probs_thinking_10 {
for prob_backlogged in probs_backlogged {
s.spawn(move |_| {
let throughput = self::calc_throughput(10, prob_backlogged, prob_thinking);
println!("10,{prob_backlogged},{prob_thinking},{throughput}")
});
}
}
for prob_thinking in probs_thinking_25 {
for prob_backlogged in probs_backlogged {
s.spawn(move |_| {
let throughput = self::calc_throughput(25, prob_backlogged, prob_thinking);
println!("25,{prob_backlogged},{prob_thinking},{throughput}")
});
}
}
});
}

56
code/rustfmt.toml Normal file
View File

@ -0,0 +1,56 @@
# We're fine with unstable features
unstable_features = true
binop_separator = "Back"
blank_lines_lower_bound = 0
blank_lines_upper_bound = 2
brace_style = "SameLineWhere"
combine_control_expr = true
condense_wildcard_suffixes = true
control_brace_style = "AlwaysSameLine"
empty_item_single_line = true
enum_discrim_align_threshold = 100
error_on_line_overflow = false
error_on_unformatted = false
fn_params_layout = "Tall"
fn_single_line = false
force_explicit_abi = true
force_multiline_blocks = false
format_code_in_doc_comments = false
format_macro_bodies = true
format_macro_matchers = true
format_strings = true
group_imports = "Preserve"
hard_tabs = true
hex_literal_case = "Lower"
imports_granularity = "One"
imports_indent = "Block"
imports_layout = "HorizontalVertical"
indent_style = "Block"
inline_attribute_width = 0
match_arm_blocks = false
match_arm_leading_pipes = "Never"
match_block_trailing_comma = true
max_width = 120
merge_derives = false
newline_style = "Unix"
normalize_comments = false
normalize_doc_attributes = false
overflow_delimited_expr = true
remove_nested_parens = true
reorder_impl_items = true
reorder_imports = true
reorder_modules = true
space_after_colon = true
space_before_colon = false
spaces_around_ranges = false
struct_field_align_threshold = 20
struct_lit_single_line = true
trailing_comma = "Vertical"
trailing_semicolon = true
type_punctuation_density = "Wide"
use_field_init_shorthand = true
use_small_heuristics = "Default"
use_try_shorthand = true
where_single_line = false
wrap_comments = false

View File

@ -77,15 +77,26 @@ rules:
- code/3a.R
# Exercise 3.b
ex3_b_data:
out:
- output/3b.csv
deps:
- code/ex_3b/src/main.rs
exec:
- - bash
- -c
- "cargo run --manifest-path=code/Cargo.toml --release > output/3b.csv"
ex3_b:
out:
- output/3b-aloha10.svg
- output/3b-aloha25.svg
deps:
- code/3b.R
- output/3b.csv
- code/3b_rust.R
exec:
- - Rscript
- code/3b.R
- code/3b_rust.R
# Exercise 4 solve
ex4_solve: