I here have two different structs that represent the same data. The main objective is to achieve as fast as possible performance.
#Using array of arrays representation
struct Route_array
Station::Vector{Int64}
Tank::Vector{Vector{Int64}}
Amount::Vector{Vector{Float64}}
end
#Using dictionaries to represent the data
struct Route_dict
Station::Vector{Int64}
Tank::Dict{Int64,Vector{Int64}}
Amount::Dict{Tuple{Int64,Int64},Float64}
end
Which of these formulations would be optimal if you have to access and update the values of structs more than say ~10^10 times? The dictionary version would be the preferable one since it would make the following code easier to write, but I am concerned about losing performance.
EDIT: The data structures comes from the an optimization problem where the goal is to find the optimal way to deliver fuel. The route structs that you see is the foundation of a solution to this problem. (The structs here have been significantly reduced, to better understand the difference between the two formulations. In the original struct there are 8 members). A complete solution to my instance of the problem will contain around 3000 of these route structs. These routes are then nested inside another structs (Called Solution) which together with the routes also contain the objective value (given in km) and the current level of fuel in all tanks and all stations.
From here the goal is to improve the solution by, for example, creating or deleting route structs. It could also be by making smaller changes to an existence route struct, this could be done by changing the order in which the stations and tanks are visited or how much fuel (amount) are put in each of these. Again, there are 8 structs members in the original struct, so what you see have been significantly reduced. But essentially, I access the route struct many, many times in which a function adds something to the struct members or change some of the values in the struct. Calculating these changes can involve some operations the scope of which depends to how big the changes are. For example, when creating a new route struct I need to do “a lot” of calculations (Determine amount to each tank, determine if there is an vehicle available, making sure that constraints are not violated, etc…).