Skip to content

Commit

Permalink
-Remove IntervalSets. Just keep bounds on spaces.
Browse files Browse the repository at this point in the history
-Store arc_materials to avoid calling functions unnecessarily and storing unnecasry pipeline values
  • Loading branch information
hdavid16 committed Nov 24, 2022
1 parent 54c33b2 commit 19a677a
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 10 deletions.
2 changes: 0 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Chain = "8be319e6-bccf-4806-a6f7-6fae938471bc"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MetaGraphs = "626554b9-1ddb-594c-aa3c-2596fe9399a5"
NamedArrays = "86f7a689-2022-50b4-a561-43c23ac3c673"
Expand All @@ -21,7 +20,6 @@ Chain = "0.5"
DataFrames = "1.3"
Distributions = "0.25"
Graphs = "1.7"
IntervalSets = "0.7"
MetaGraphs = "0.7"
NamedArrays = "0.9"
StatsBase = "0.33"
Expand Down
1 change: 0 additions & 1 deletion src/InventoryManagement.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ using DataFrames, NamedArrays, SparseArrays
using Chain
using Random
using Distributions
using IntervalSets
using LinearAlgebra
using Graphs, MetaGraphs
import StatsBase: mean, std
Expand Down
3 changes: 2 additions & 1 deletion src/demand.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ function replenishment_orders!(x::SupplyChainEnv, act::NamedArray)
#create order and save service lead time
for arc in arcs
amount = act[mat, arc] #amount requested
if amount > 0
arc_mats = get_prop(x.network, arc..., :arc_materials)
if amount > 0 && mat in arc_mats
serv = servs[Edge(arc...), mat] #sampled service lead time
create_order!(x, arc..., mat, amount, serv)
end
Expand Down
4 changes: 3 additions & 1 deletion src/inventory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ function update_dfs!(x::SupplyChainEnv)
push!(x.inventory, (x.period, n, m, x.tmp[n,m,:echelon], :echelon))
for dst in outneighbors(x.network, n)
arc = (n,dst)
push!(x.inventory, (x.period, arc, m, x.tmp[arc,m,:pipeline], :pipeline))
if m in get_prop(x.network,arc...,:arc_materials)
push!(x.inventory, (x.period, arc, m, x.tmp[arc,m,:pipeline], :pipeline))
end
end
end
end
Expand Down
23 changes: 20 additions & 3 deletions src/parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ function check_inputs!(network::MetaDiGraph, mrkts::Vector, plants::Vector)
nodes = vertices(network) #network nodes
arcs = [(e.src,e.dst) for e in edges(network)] #network edges as Tuples (not Edges)
mats = get_prop(network, :materials) #materials
sort!(mats)
sort!(mats) #sort alphabetically
store_arc_materials!(network) #store materials that have a lead time on each arc

#initialize flags
truncate_flag, roundoff_flag, replace_flag = false, false, false

#run checks on the parameter inputs
nonsources = filter(n -> !isempty(inneighbors(network, n)), nodes) #list of nodes with predecessors
nonsinks = filter(n -> !isempty(outneighbors(network, n)), nodes) #list of nodes with successors
Expand Down Expand Up @@ -313,6 +314,7 @@ end

"""
store_node_materials!(network::MetaDiGraph, plants::Vector)
Record which materials have non-zero capacity at each node (can be stored at that node).
This improves performance for simulations with many materials. Sort in materials in topological order
for plant nodes to account for any make-to-order intermediates.
Expand All @@ -334,4 +336,19 @@ function store_node_materials!(network::MetaDiGraph, plants::Vector)
end
set_prop!(network, n, :node_materials, n_mats)
end
end
end

"""
store_arc_materials!(network::MetaDiGraph)
Sore the materials that have a specified lead time on each arc.
"""
function store_arc_materials!(network::MetaDiGraph)
materials = get_prop(network, :materials)
for e in edges(network)
if :lead_time in keys(props(network, e))
arc_mats = Set(keys(get_prop(network, e, :lead_time)))
set_prop!(network, e, :arc_materials, arc_mats materials)
end
end
end
4 changes: 2 additions & 2 deletions src/spaces.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function action_space(env::SupplyChainEnv)
num_products = length(env.materials)
num_edges = ne(env.network)
return [Interval{:closed,:open}(0,Inf) for _ in 1:num_products*num_edges]
return [(0,Inf) for _ in 1:num_products*num_edges]
end

state(env::SupplyChainEnv) = show_state(env).amount
Expand All @@ -10,7 +10,7 @@ function state_space(env::SupplyChainEnv)
num_products = length(env.materials)
num_nodes = nv(env.network)
num_arcs = ne(env.network)
return [Interval{:closed,:open}(0,Inf) for _ in 1:num_products*(num_nodes*2+num_arcs)] #onhand and unfulfilled for each node and pipeline for each arc
return [(0,Inf) for _ in 1:num_products*(num_nodes*2+num_arcs)] #onhand and unfulfilled for each node and pipeline for each arc
end

"""
Expand Down

2 comments on commit 19a677a

@hdavid16
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/72834

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.6.1 -m "<description of version>" 19a677a4b4e3a4f5d72940dc29661d71e7f00ec4
git push origin v0.6.1

Please sign in to comment.