-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathplot_last_iteration.oms
94 lines (79 loc) · 3.82 KB
/
plot_last_iteration.oms
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
// this variable will transmit the path where the CSV files to graph will be found
val directoryWithResults = Val[File]
// variables used to parameter the graphing function
val filesHaveHeaders = Val[Int]
val countInputs = Val[Int]
val graphWidth = Val[Int]
val graphHeight = Val[Int]
val graphFormat = Val[String]
// this variable will contain the file with the graphical rendering of the last PAreto front
val lastPareto = Val[File]
val taskPlotLastParetoFront = RTask("""
library(ggplot2)
colnames <- if (countInputs == 2) c("iteration", "x", "y", "f1", "f2") else c("iteration", "x", "f1", "f2")
coltypes <- if (countInputs == 2) c("integer", "numeric", "numeric", "numeric", "numeric") else c("integer", "numeric", "numeric", "numeric")
names(coltypes) <- colnames
directoryWithResultsName <- "mydirectory"
# ensure check the directory exists
if (!file.exists(directoryWithResultsName)) { stop(paste("ERROR: the directory", directoryWithResultsName, "does not exists!")) }
# get the most recent file (will be the last result)
allfiles <- file.info(list.files(directoryWithResultsName, full.names = T))
lastfilename <- rownames(allfiles)[which.max(allfiles$mtime)]
if (!file.exists(lastfilename)) { stop(paste("ERROR: no file found in", directoryWithResultsName) ) }
print(lastfilename)
# read the last file
pop <- read.csv(header = filesHaveHeaders>0, col.names=colnames, colClasses=coltypes, file=lastfilename)
print(paste("there are", nrow(pop), "points on the last Pareto front"))
# plot
g <- ggplot(pop, aes(x=f1,y=f2)) + geom_point()
dpi <- 72
ggsave(filename="/tmp/last_pareto",
device=graphFormat,
plot=g,
width=graphWidth/dpi, height=graphHeight/dpi)
""",
install = Seq(
// update the list of available packages
"fakeroot apt-get update ",
// required; attempts to update dbus to a newer version would require permissions we do not have
"DEBIAN_FRONTEND=noninteractive fakeroot apt-mark hold dbus",
"""echo "dbus hold" | fakeroot dpkg --set-selections""",
// install the libs required for the compilation of R packages
"DEBIAN_FRONTEND=noninteractive fakeroot apt-get install -y libssl-dev libcurl4-openssl-dev libudunits2-dev",
// install required R packages in their binary version (quicker, much stable!)
"DEBIAN_FRONTEND=noninteractive fakeroot apt-get install -y r-cran-ggplot2 r-cran-gganimate r-cran-ggally r-cran-plotly r-cran-zip",
// install external tools in the VM for rendering
"DEBIAN_FRONTEND=noninteractive fakeroot apt-get install -y ffmpeg",
), //
libraries = Seq() // were installed with the binary version earlier
) set (
inputFiles += (directoryWithResults, "mydirectory"),
outputFiles += ("/tmp/last_pareto", lastPareto),
inputs += filesHaveHeaders.mapped,
inputs += countInputs.mapped,
inputs += graphWidth.mapped,
inputs += graphHeight.mapped,
inputs += graphFormat.mapped,
filesHaveHeaders := 1,
countInputs := 2,
// in pixels
graphWidth := 600,
graphHeight := 600,
graphFormat := "png"
)
// import from the other file an example of optimization
import _file_.example_of_optimization._
// run the optimization
( evolutionSchafferN2 on envMultiThread hook (workDirectory/relativePath, keepAll=false)
) -- (
// then run the plotting function
taskPlotLastParetoFront set (
// ... which will read all the results from this file
directoryWithResults := workDirectory / relativePath,
// ... analyze them knowing there is only one input in the files
countInputs := 1,
// ... parameters of the graph
graphWidth := 500,
graphHeight := 500
) hook CopyFileHook(lastPareto, workDirectory/"last Pareto front.png" )
)