Skip to content

Instantly share code, notes, and snippets.

@oxinabox
Last active April 26, 2017 08:08
Show Gist options
  • Save oxinabox/f652b0c28061221ec1f7b528e3272cd7 to your computer and use it in GitHub Desktop.
Save oxinabox/f652b0c28061221ec1f7b528e3272cd7 to your computer and use it in GitHub Desktop.
how to use backticks
```julia
@everywhere function par(i, u)
a=Dict{Int64, Array{Tuple{Int64,Int64},1}}()
dum_a = Array{Tuple{Int64,Int64}}(0)
# for i in 1:10
for j in 1:10
for k in 1:u
push!(dum_a,(j,k))
end
end
a[i] = dum_a
# end
# println(length(a))
return a
end
@time Results = pmap((i) -> par(i,u), 1:10, 2)
Result = merge(Results...)
print(keys(Result))
```
@Mason-P
Copy link

Mason-P commented Apr 26, 2017

function Read_Input_Data()
     input_file_neme = "data_matched_nodes_500.csv"
     individual_data,header = readcsv(input_file_neme, header=true)
     ind_id = convert(Array{Int64,1}, individual_data[:,9])         # these lines read the individual file
     ind_space = convert(Array{Int64,1}, individual_data[:,6])
     ind_time = convert(Array{Int64,1}, individual_data[:,7])
     num_of_individuals = length(unique(ind_id))

     input_file_dist = "distance_matrix_84.csv"
     dist_nodes_data = readcsv(input_file_dist)
     # dist_nodes = dist_nodes_data[2:end, 2:end]
     dist_nodes = convert(Array{Float64,2}, dist_nodes_data[2:end, 2:end])
     ################################################################# Input Data #########################################################
     ind_ticks = 1:num_of_individuals
     typeof(ind_ticks)
     space_ticks = 1:length(dist_nodes[1,:])
     time_ticks = 1:37       # 48 for 48 hours
     delta_time_ticks=0.5  # hour
     V=1.0  # km/hour

     srand(10);
     ratio_of_new_inst_cost = 50.0             # FIXME    this ratio is multiplied to a random array(each between 20 and 50) to generate installation cost ($)
     ratio_of_new_inst_to_ind_utility = 0.01    # FIXME this ratio is multiplied to average installation cost to generate utility benefit ($)
     Tot_Budget = 2.0*ratio_of_new_inst_cost     # FIXME
     cost_of_new_inst = rand(20:ratio_of_new_inst_cost,length(space_ticks))  ## 23.6, 55.57, 7.69
     # ind_utility = 1 # 0.35266
     ind_utility = convert(Array{Float64,1},rand(05:10,num_of_individuals))  ## 23.6, 55.57, 7.69
     nodes_of_inds , opt_Q_init = Nodes_of_individuals(ind_id, ind_space ,ind_time ,space_ticks, time_ticks, ind_ticks, dist_nodes, delta_time_ticks, V)
     # println(keys(nodes_of_inds))
     graph = Build_network_graph(space_ticks)
     @show (nodes_of_inds, graph, time_ticks)
     @time links_of_inds = pmap((h) -> LINKS_of_INdividuals(h, nodes_of_inds, graph, time_ticks), 1:num_of_individuals)
     Result = merge(links_of_inds...)

end

@time Read_Input_Data()

@Mason-P
Copy link

Mason-P commented Apr 26, 2017

######################################################### LINKS of INdividuals ####################################################
@everywhere function LINKS_of_INdividuals(h, nodes_of_inds::Dict{Int64,Array{Tuple{Int64,Int64},1}}, graph::Dict{Int64,Vector{Int64}}, time_ticks::UnitRange{Int64})
     ind_s_t_link_prob = Dict{Tuple{Int64,Int64, Int64, Int64}, Float64}()
     # @parallel for h = 1:num_of_individuals
     # for h = 1:20

      for nodes in nodes_of_inds[h]
          # println("h,  nodeeeeeeeeeeeee        ",h, " ", nodes[1], " ", nodes[2])
          if nodes[2] == time_ticks[end]
               continue
          end
          counter = 0
          for neighbour in graph[nodes[1]]
               # println("neighbour ", neighbour)
               if (neighbour, nodes[2]+1) in nodes_of_inds[h]
                     counter += 1
               end
          end
          for neighbour in graph[nodes[1]]
               if (neighbour, nodes[2]+1) in nodes_of_inds[h]
                    # println(typeof(h), typeof(nodes[1]),typeof(neighbour) , typeof(nodes[2]+1))
                     ind_s_t_link_prob[h,nodes[1],neighbour,nodes[2]+1] = 1/counter
               end
          end
      end
     return ind_s_t_link_prob
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment