forked from StShenanigan/birch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.Rhistory
101 lines (101 loc) · 3.28 KB
/
.Rhistory
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
q()
q()
install.packages("genalg")
library(genalg)
library(ggplot)
install.packages("ggplot2")
library(ggplot2)
dataset <- data.frame(item = c("pocketknife", "beans", "potatoes", "unions",
"sleeping bag", "rope", "compass"), survivalpoints = c(10, 20, 15, 2, 30,
10, 30), weight = c(1, 5, 10, 1, 7, 5, 1))
weightlimit <- 20
chromosome = c(1, 0, 0, 1, 1, 0, 0)
dataset[chromosome == 1, ]
cat(chromosome %*% dataset$survivalpoints)
evalFunc <- function(x) {
current_solution_survivalpoints <- x %*% dataset$survivalpoints
current_solution_weight <- x %*% dataset$weight
if (current_solution_weight > weightlimit)
return(0) else return(-current_solution_survivalpoints)
}
iter = 100
GAmodel <- rbga.bin(size = 7, popSize = 200, iters = iter, mutationChance = 0.01,
elitism = T, evalFunc = evalFunc)
cat(summary.rbga(GAmodel))
summary(GAmodel)
cat(summary(GAmodel))
solution = c(1, 1, 1, 1, 1, 0, 1)
dataset[solution == 1, ]
# solution vs available
cat(paste(solution %*% dataset$survivalpoints, "/", sum(dataset$survivalpoints)))
cat(paste(solution %*% dataset$survivalpoints))
cat(paste(solution %*% dataset$weights))
cat(paste(solution %*% dataset$weight))
cat(summary(GAmodel))
solution = c(1, 1, 0, 1, 1, 1, 1)
cat(paste(solution %*% dataset$weight))
# solution vs available
cat(paste(solution %*% dataset$survivalpoints, "/", sum(dataset$survivalpoints)))
animate_plot <- function(x) {
for (i in seq(1, iter)) {
temp <- data.frame(Generation = c(seq(1, i), seq(1, i)), Variable = c(rep("mean",
i), rep("best", i)), Survivalpoints = c(-GAmodel$mean[1:i], -GAmodel$best[1:i]))
pl <- ggplot(temp, aes(x = Generation, y = Survivalpoints, group = Variable,
colour = Variable)) + geom_line() + scale_x_continuous(limits = c(0,
iter)) + scale_y_continuous(limits = c(0, 110)) + geom_hline(y = max(temp$Survivalpoints),
lty = 2) + annotate("text", x = 1, y = max(temp$Survivalpoints) +
2, hjust = 0, size = 3, color = "black", label = paste("Best solution:",
max(temp$Survivalpoints))) + scale_colour_brewer(palette = "Set1") +
opts(title = "Evolution Knapsack optimization model")
print(pl)
}
}
# in order to save the animation
library(animation)
install.packages("animation")
# in order to save the animation
library(animation)
saveMovie(animate_plot(), interval = 0.1, outdir = getwd())
q()
c
q()
install.packages("igraph")
q()
devtools::install_github("SymbolixAU/colourvalues", force = TRUE)
devtools::install_github("SymbolixAU/spatialwidget", force = TRUE)
devtools::install_github("SymbolixAU/spatialwidget", force = TRUE)
devtools::install_github("SymbolixAU/mapdeck", force = TRUE)
library(data.table)
library(sf)
library(mongolite)
library(knitr)
library(geojsonsf)
library(map.deck)
library(mapdeck)
library(symbolix.utils)
library(DBI)
library(ggplot2)
library(binom)
install.packages("binom")
library(binom)
library(xaringan)
install.packages("xaringan")
install.packages("xaringan")
library(kabelExtra)
install.packages("kabelExtra")
install.packages("kableExtra")
library(kableExtra)
install.packages("xaringanthemer")
install.packages("xaringanthemer", type = "source")
library(xaringanthemer)
library(xaringan.themer)
devtools::install_github("yihui/xaringan")
library(xaringan)
devtools::install_github("gadenbuie/xaringanthemer")
library(xaringanthemer)
q()
setwd("~/GitStuff/birch")
install.packages("ellipse")
library(birch)
?birch::birch()
q()