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 ofzeros(1, (2*num_gp))
. If you need to treat a 2D array as 1D for some reason, you can easily reshape it usingvec(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 yourStartUpCost
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.