0
下面是R的公司製造和銷售的流動模型圖形的簡化重複的例子多級製造和銷售模型
library(igraph)
# Create graph
graph= graph.formula(
R --+ P1,
P1 --+ M1,
R --+ P2,
P2 --+ M2,
P1 --+ P3,
P2 --+ P3,
P3 --+ M2,
R --+ P4,
P3 --+ P5,
P4 --+ P5,
P5 --+ M3,
P5 --+ M4
)
# Change colors for pretty plot
V(graph)$color= "gray"
V(graph)[name== "R"]$color= "cyan"
V(graph)[grepl(x= name, pattern= "M")]$color= "green"
V(graph)[name %in% c("P1", "P2", "P4")]$color= "red"
# Add sales volume as attribute and add to edge label in plot
E(graph)[4]$sales= 100
E(graph)[4]$label= paste("Sales:\n", E(graph)[4]$sales, "tons")
E(graph)[6]$sales= 200
E(graph)[6]$label= paste("Sales:\n", E(graph)[6]$sales, "tons")
E(graph)[8]$sales= 500
E(graph)[8]$label= paste("Sales:\n", E(graph)[8]$sales, "tons")
E(graph)[11]$sales= 1000
E(graph)[11]$label= paste("Sales:\n", E(graph)[11]$sales, "tons")
E(graph)[12]$sales= 2000
E(graph)[12]$label= paste("Sales:\n", E(graph)[12]$sales, "tons")
# Add bill of material share as attribute and add to edge label in plot
E(graph)[1:3]$share= 1.0
E(graph)[1:3]$label= paste("Share:\n", E(graph)[1:3]$share*100, "%")
E(graph)[7]$share= 0.8
E(graph)[7]$label= paste("Share:\n", E(graph)[7]$share*100, "%")
E(graph)[5]$share= 1 - 0.8
E(graph)[5]$label= paste("Share:\n", E(graph)[5]$share*100, "%")
E(graph)[9]$share= 0.4
E(graph)[9]$label= paste("Share:\n", E(graph)[9]$share*100, "%")
E(graph)[10]$share= 1 - 0.4
E(graph)[10]$label= paste("Share:\n", E(graph)[10]$share*100, "%")
# Add preliminary NA vol attribute to nodes and add label in plot
V(graph)$vol= NA
V(graph)$label= paste(V(graph)$name, "\nVolume:\n", V(graph)$vol, "tons")
# Plot
E(graph)$label.cex=0.8
V(graph)$label.cex=0.8
V(graph)$size=20
layout= layout.reingold.tilford(graph, root=1)
layout[3,2]=0
layout[5,2]=0
plot(graph, layout= layout)
模型網絡包括以下組件:
R
:製成產品所需的青色原料P1, P2, P4
。P1...P5
:紅色產品直接從R
(P1, P2, P4
)或多級製造產品(P3, P5
)中一步完成。每種產品都有一份配方材料清單。M...
:產品P1...5
銷往的綠色市場。唯一的例外是P4
這是沒有出售,它只是作爲P5
(組合其中P3
)的前身。
已知屬性在此網絡的邊緣:
Sales
:銷量噸P1, P2, P3, P5
市場M1, M2, M3, M4
。- 配方
Share
:製造特定產品所需的前體量(%)。例如:要製造1噸的P1, P2, P4
需要1噸原材料(因此需要100%)。要製造10噸P3
8噸(= 80%)P2
和2噸(= 20%)需要P1
。
我要尋找一個解決方案來計算體積爲節點產品P1 ... P5
和原材料R
屬性vol
。目前它們設置爲NA
。 vol
應與銷售量和產品配方的份額保持一致。
評論:我正在尋找一個適用於這個簡化示例的廣義解決方案,但也適用於更復雜(更多節點和更多製造階段)真實世界模型。我正在考慮一種多級傳播算法。首先sales
數據將被彙總,以產生出售給市場的產品的產品頂點vol
屬性。然後,另一個步驟將根據share
計算上游產品的產量以達到上一步產量的要求等等。一般化的解決方案超出了我的知識範圍R
。任何想法如何完成任務?