Skip to content

Commit

Permalink
Perform more effective search to build indices sets
Browse files Browse the repository at this point in the history
  • Loading branch information
abelsiqueira committed Jan 11, 2024
1 parent 4f6ce2f commit 371a593
Showing 1 changed file with 38 additions and 37 deletions.
75 changes: 38 additions & 37 deletions src/create-model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,35 @@ function create_model(graph, representative_periods, constraints_partitions; wri
end
end

function add_to_flow!(flow_sum_indices, a, rp, P, f)
search_start_index = 1
flow_partitions = graph[f...].partitions[rp]
num_flow_partitions = length(flow_partitions)
for B P
# Update search_start_index
while last(flow_partitions[search_start_index]) < first(B)
search_start_index += 1
if search_start_index > num_flow_partitions
break
end
end
if search_start_index > num_flow_partitions
break
end
last_B = last(B)
for j = search_start_index:num_flow_partitions
B_flow = flow_partitions[j]
d = duration(B, B_flow, rp)
if d != 0
push!(flow_sum_indices[a, rp, B], (d, f, B_flow))
end
if first(B_flow) > last_B
break
end
end
end
end

flow_sum_indices_incoming_lowest =
Dict{TupleAssetRPTimeBlock,Vector{TupleDurationFlowTimeBlock}}()
flow_sum_indices_outgoing_lowest =
Expand All @@ -152,48 +181,20 @@ function create_model(graph, representative_periods, constraints_partitions; wri
for B Pl[(a, rp)]
flow_sum_indices_incoming_lowest[a, rp, B] = TupleDurationFlowTimeBlock[]
flow_sum_indices_outgoing_lowest[a, rp, B] = TupleDurationFlowTimeBlock[]
for u inneighbor_labels(graph, a)
add_to_flow_sum_indices!(
flow_sum_indices_incoming_lowest[a, rp, B],
a,
rp,
B,
(u, a),
)
end

for v outneighbor_labels(graph, a)
add_to_flow_sum_indices!(
flow_sum_indices_outgoing_lowest[a, rp, B],
a,
rp,
B,
(a, v),
)
end
end
for B Ph[(a, rp)]
flow_sum_indices_incoming_highest[a, rp, B] = TupleDurationFlowTimeBlock[]
flow_sum_indices_outgoing_highest[a, rp, B] = TupleDurationFlowTimeBlock[]
for u inneighbor_labels(graph, a)
add_to_flow_sum_indices!(
flow_sum_indices_incoming_highest[a, rp, B],
a,
rp,
B,
(u, a),
)
end
end

for v outneighbor_labels(graph, a)
add_to_flow_sum_indices!(
flow_sum_indices_outgoing_highest[a, rp, B],
a,
rp,
B,
(a, v),
)
end
for u inneighbor_labels(graph, a)
add_to_flow!(flow_sum_indices_incoming_lowest, a, rp, Pl[(a, rp)], (u, a))
add_to_flow!(flow_sum_indices_incoming_highest, a, rp, Ph[(a, rp)], (u, a))
end

for v outneighbor_labels(graph, a)
add_to_flow!(flow_sum_indices_outgoing_lowest, a, rp, Pl[(a, rp)], (a, v))
add_to_flow!(flow_sum_indices_outgoing_highest, a, rp, Ph[(a, rp)], (a, v))
end
end

Expand Down

0 comments on commit 371a593

Please sign in to comment.