Open mdakyen opened 2 years ago
I did not get your point. Can you elaborate in details about what you want to achieve?
Good day sir, thank you for your swift response. Actually, I am trying to attain optimization for two objectives (global cost and primary energy). so far, my code works perfectly, but the only results i can see are those of my design options and objective functions. i wish to retrieve other parameters (such as initial investment replacement cost etc ) in a single data frame after my simulation. Please sir, I have will forward my code to your outlook account in the next 30mins tops
@hongyuanjia, Sir, I have sent the command code and IDF files to your outlook account.
@hongyuanjia please did you receive my mails Sir ?
@hongyuanjia, Dear Sir, kindly bear with my level of persistence at the moment. Honestly, my research progress now highly depends on your feedback.
Sorry, I have no time to debug your ~2000 lines of code. But I can give you some directions on how to do that.
The global variables stored in your current sessions can not be directly modified in your objective functions. This is because the fitness is evaluated in a separate R session. Therefore, it knows nothing about your current R session. You should make your measure function and object function self-contained, i.e., do not let them depend on other resources except the IDF itself.
One possible way to achieve data-sharing across R sessions is to use files. Below give you an example to do that. But before you do that, I recommend you perform all your calculations in the objective functions since you can access each parameter.
path_idf <- eplusr::path_eplus_example(8.9, "5Zone_Transformer.idf")
path_epw <- eplusr::path_eplus_weather(8.9, "USA_CA_San.Francisco.Intl.AP.724940_TMY3.epw")
ga <- epluspar::gaoptim_job(path_idf, path_epw)
case <- 0
north_axis <- 0
capacity <- NA_real_
df <- data.frame(case, north_axis, capacity)
# save data
data_save <- function(data, name = deparse(substitute(data)), dir = ".") {
saveRDS(data, file.path(file.path(dir, name)))
}
# read data
data_read <- function(name, dir = ".") {
readRDS(file.path(dir, name))
}
# init data
data_save(df)
mea <- function(idf, dir = 0) {
idf$Building$North_Axis <- dir
# read data
df <- data_read("df")
# update data
new <- df[nrow(df), ]
new$case <- max(df$case) + 1
new$north_axis <- dir
# save data
df <- rbind(df, new)
rownames(df) <- seq_len(nrow(df))
data_save(df)
idf
}
obj <- function(idf) {
val <- as.double(idf$last_job()$tabular_data(
report_name = "ComponentSizingSummary",
table_name = "Chiller:Electric",
column_name = "Design Size Nominal Capacity"
)$value)
# read data
df <- data_read("df")
# update data
df[nrow(df), "capacity"] <- val
# save data
data_save(df)
val
}
ga$apply_measure(mea, epluspar::float_space(0, 180, 0))
ga$objective(obj)
ga$recombinator()
ga$mutator()
ga$selector(survival = ecr::selGreedy)
ga$terminator(max_gen = 2L)
ga$run(mu = 2)
ga$population()
# index_gen index_ind dir obj
# <int> <int> <num> <num>
# 1: 1 1 65.91481 40871.42
# 2: 1 2 65.91481 40871.42
# 3: 2 1 65.91481 40871.42
# 4: 2 2 65.91481 40871.42
data_read("df")
# case north_axis capacity
# 1 0 0.00000 NA
# 2 1 101.55419 42244.54
# 3 2 101.55419 42244.54
# 4 3 65.91481 40871.42
# 5 4 65.91481 40871.42
# 6 5 101.55419 42244.54
# 7 6 65.91481 40871.42
# 8 7 65.91481 40871.42
Ok Sir, I will do my best in implementing your recommendations. Thank you so much for your time. I wish you a great week ahead.
Good day Sir,
Your recommendation has been helpful so far. However, my optimization process, has been successful for only a small number of generations.
Meaning that, when ever I increase the number of generations. My optimization process runs for awhile, then suddenly it crashes. Displaying the following error :
Error in readRDS(file.path(dir, name)) : error reading from connection
Below are functions from my optimization as you have earlier suggested sir.
# save data
data_save <- function(data, name = deparse(substitute(data)), dir = ".") {
saveRDS(data, file.path(file.path(dir, name)))
}
# read data
data_read <- function(name, dir = ".") {
readRDS(file.path(dir, name))
}
# init data
data_save(vitalsimulationresults)
Below is a screen shot explaining my issue in more detail sir.
Another sample of my error, sir
Good day Sir @hongyuanjia, Please I have been trying to store certain design parameters from my optimization process so I can access them afterwards. All my efforts have not been successful. Below is a sample of my code. Kindly assist me.