How to start a new Julia session from script

Can you provide me with some documentation for doing this?

This seems correct, and a definite improvement from before.

Side note, CSV.read(file) is deprecated. You can do CSV.read(file, DataFrame) to get the data frame directly.

Unfortunately, getting rid of the global variables did not solve my problem.

Note that Julia does not copy on assignment - any modification to temp_ will also modify the original. You need to explicitly copy arrays:

julia> cost1, cost2 = rand(1), rand(1)
([0.10489078104085436], [0.24938919112321623])

julia> tmp_cost1, tmp_cost2 = cost1, copy(cost2)
([0.10489078104085436], [0.24938919112321623])

julia> tmp_cost1[1] = tmp_cost2[1] = 0
0

julia> cost1, cost2
([0.0], [0.24938919112321623])

This may be what’s causing you to see irregular Guirobi results when doing multiple runs at once: you’re currently modifying your StartUpCost parameter on each iteration.

Some other notes:

  • You’ll spare yourself a lot of indexing pain if you use 2D arrays instead of 1D (e.g. test2_limit = zeros(2, num_gp) instead of zeros(1, (2*num_gp)). If you need to treat a 2D array as 1D for some reason, you can easily reshape it using vec(arr), which refers to the same underlying chunk of memory.
  • You don’t need to set global variables as constants if you’re passing them as function arguments. “Dynamic multiple dispatch” means that Julia figures out which methods to call based on a function’s argument types at run-time, but as long as those function arguments have a concrete type, there’s no need to set them as constant.
  • Array{Float64} (as used in your StartUpCost initialization) is not a concrete type, since you didn’t specify the dimension of the array:
julia> isconcretetype(Array{Float64})
false

julia> isconcretetype(Array{Float64, 1})
true
  • Unlike Matlab, Julia has built-in 1D arrays, and “row vectors” like reshape(..., (1, nUnits)) are not considered idiomatic in cases where a 1D array would do the same thing.
  • Multiple function definitions can (and typically do) coexist in the same file - there’s no need to split things across multiple files unless it helps you with code organization.

Thanks everyone, the problem has been resolved.

Thank you, the problem has been resolved.

It would be nice if you could change the title so that another person with a similar issue can find this. In the end, the post was not solved by starting new sessions from a script.