From 7c9f176fab79eae9c0bb08d0120411ef06b09946 Mon Sep 17 00:00:00 2001 From: Abhishek Bhatt Date: Tue, 26 Nov 2024 17:30:11 -0500 Subject: [PATCH] keep record of node wise workloads(requests being served) --- src/ProtocolZoo/utils.jl | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/src/ProtocolZoo/utils.jl b/src/ProtocolZoo/utils.jl index 2366daeb..c1e618b2 100644 --- a/src/ProtocolZoo/utils.jl +++ b/src/ProtocolZoo/utils.jl @@ -11,17 +11,28 @@ $TYPEDFIELDS """The vector of paths between the user pair""" paths::Vector{Vector{Int}} """The vector containing the workload information of a path""" - workloads::Vector{Int} - """The number of slots available at each node. Scalar if all are same, vector otherwise.""" - capacity::Union{Vector{Int}, Int} + workloads::Dict{Int, Int} + """The number of slots available at each node. Scalar if all are same, otherwise a dictionary.""" + capacity::Union{Dict{Int, Int}} """Number of failed requests due to high request traffic""" failures::Ref{Int} end -function PathMetadata(graph::SimpleGraph{Int64}, src::Int, dst::Int, caps::Union{Vector{Int}, Int}; failures=Ref{Int}(0)) +function PathMetadata(graph::SimpleGraph{Int64}, src::Int, dst::Int, caps::Union{Dict{Int, Int}, Int}; failures=Ref{Int}(0)) paths = sort(collect(all_simple_paths(graph, src, dst)); by = x->length(x)) - workloads = zeros(length(paths)) - PathMetadata(paths, workloads, caps, failures) + src = paths[1][1] + dst = paths[1][end] + workloads = Dict{Int, Int}() + capacity = isa(caps, Number) ? Dict{Int, Int}() : caps + for node in 1:size(graph)[1] + if !(node == src || node == dst) + workloads[node] = 0 + if isa(caps, Number) + capacity[node] = caps + end + end + end + PathMetadata(paths, workloads, capacity, failures) end @@ -29,12 +40,13 @@ end A simple path selection algorithm for connection oriented networks. """ function path_selection(sim, pathobj::PathMetadata) - for i in 1:length(pathobj.paths) - capacity = isa(pathobj.capacity, Number) ? pathobj.capacity : pathobj.capacity[i] - if pathobj.workloads[i]