If you start Julia many times, you will notice that everything becomes slow because things need to be compiled every time. Also, you cannot easily pass information back and forth. Your script contains 40 globals, my bet is that they can all be avoided when passing the program’s state around a bit more careful. That is, move the logic into functions and give the functions name. For example, instead of
#STARTUP COST ANALYSIS
elseif option == 2
mkdir("Option_2")
for gp = 1:num_gp
mkdir("Option_2\\Group_$gp")
global temp_StartUpCost = zeros(1, nUnits)
global test_StartUpCost = zeros(1, num_iter)
test_StartUpCost = collect(range(test2_limit[((gp-1)*2 + 1)], test2_limit[((gp-1)*2 + 2)], length = num_iter))
for iter = 1:num_iter
global test2[iter, ((gp-1)*2 + 1)] = round(test_StartUpCost[iter], digits=2)
var = round(test_StartUpCost[iter], digits=2)
mkdir("Option_2\\Group_$gp\\$var")
temp_StartUpCost = deepcopy(StartUpCost)
for jj = gen_gp[gp]
temp_StartUpCost[jj] = round(test_StartUpCost[iter], digits=2)
end
#Run Simulation
global test2[iter, ((gp-1)*2 + 2)] = MIQP(nUnits, nHours, a, b, c, maxPow, minPow, StartUpTime, MinimumUpTime, MinimumDownTime, RampUp, RampDown, temp_StartU pCost, ZeroStartUpCost, ShutDownCost, nZones, DLE, DLEZone, Load, SR, init_power, init_isOn, init_startup, init_rstartup1, init_rstartup2, init_shutdown, opt, gp, var)
end
end---
CSV.write("Test2_Result.csv", DataFrame(test2), writeheader=false)--
#SHUTDOWN COST ANALYSIS
elseif option == 3
write a function
function analyze_startup_costs(...)
[...]
end
and call that from the code via
elseif option == 2
analyze_startup_costs(...)
elseif option == 3
The next thing that you will walk into is that the functions receive too many variables, like happens in your MIQP function. To solve that, store you variables in structs or other appropriate data types. For instance,
struct ModelSettings
RampUp
RampDown
StartupCost
end
Implementing functions will take some time, but I guarantee that it will make it much easier to manage the complexity of the program.