Last active
December 3, 2024 18:34
-
-
Save kenwebb/c8c90e6e6d761e1268747bb1b5e0d430 to your computer and use it in GitHub Desktop.
Industrial Dynamics - Chapter 15 code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!--Xholon Workbook http://www.primordion.com/Xholon/gwt/ MIT License, Copyright (C) Ken Webb, Tue Dec 03 2024 13:31:31 GMT-0500 (Eastern Standard Time)--> | |
<XholonWorkbook> | |
<Notes><![CDATA[ | |
Xholon | |
------ | |
Title: Industrial Dynamics - Chapter 15 code | |
Description: | |
Url: http://www.primordion.com/Xholon/gwt/ | |
InternalName: c8c90e6e6d761e1268747bb1b5e0d430 | |
Keywords: | |
My Notes | |
-------- | |
11 Nov 2024 | |
### To edit and run locally (localstorage): | |
http://127.0.0.1:8080/wb/editwb.html?app=Industrial+Dynamics+-+Chapter+15+code&src=lstr | |
http://127.0.0.1:8080/Xholon.html?app=Industrial+Dynamics+-+Chapter+15+code&src=lstr&gui=clsc | |
### To edit and run from github: | |
https://primordion.com/Xholon/gwt/wb/editwb.html?app=c8c90e6e6d761e1268747bb1b5e0d430&src=gist | |
https://primordion.com/Xholon/gwt/Xholon.html?app=c8c90e6e6d761e1268747bb1b5e0d430&src=gist&gui=clsc | |
14 Nov 2024 | |
### To view earlier versions of this workbook: | |
I am removing earlier experimental subtrees from this workbook. | |
To see the latest version where those experiments are still (mostly) visible: | |
https://gist.github.com/kenwebb/c8c90e6e6d761e1268747bb1b5e0d430/6f1b9cccb296edae1bbdf0269a7a91f0fc34956b | |
- note that I commented out some XML and JavaScript code, to make these earlier code less distracting | |
### References | |
() Jay Forrester, Industrial Dynamics, 1961 | |
Chapter 15, "Model of the Production-Distribution System of Chapter 2", pp. 137-186 | |
Appendix B, "Model Tabulations", pp. 383-386 | |
]]></Notes> | |
<_-.XholonClass> | |
<DynamicalSystem> | |
<!-- Production - Distribution System, chapters 2, 15 --> | |
<ProdDistSystem/> | |
</DynamicalSystem> | |
</_-.XholonClass> | |
<xholonClassDetails> | |
<Avatar><Color>red</Color></Avatar> | |
</xholonClassDetails> | |
<ProdDistSystem> | |
<Script roleName="Xh Test 02" abc="ABCDEFGHIJKLMNOPQRSTUVWXYZ"> | |
//const retail = "UOR,IAR,STR,NIR,SSR,DFR,MNR,IDR,RSR,PDR,LDR,LAR,UNR,CPR,PSR,PMR,RRD,MTR,SRR".split(","); | |
//const distributor = "UOD,IAD,STD,NID,SSD,DFD,MOD,IDD,RSD,PDD,LDD,LAD,UND,CPD,PSD,PMD,RRF,MTD,SRD".split(","); | |
//const factory = "UOF,IAF,STF,NIF,SSF,DFF,MPF,IDF,RSF,MWF,MDF,LDF,LAF,UNF,CPF,MOF,OPF,SRF".split(","); | |
// what is special about these? why are they here? | |
const RRR = {KL:1}; // Requisitions (orders) Received at Retail (units/week) from customers | |
const RCR = {K:1}; // ??? | |
const STP = {K:1}; | |
const SNE = {K:1}; | |
//const STR = {K:1}; // already done below | |
const TIME = {K:1}; | |
// what is special about these? why are they here? | |
let PER, RRI, SIH, STH, STT; | |
PER=1; | |
RRI=1; | |
SIH=1; | |
STH=1; | |
STT=1; | |
// constants | |
let AID, AIF, AIR, ALF, DCD, DCF, DCR, DHD, DHF, DHR, DID, DIF, DIR, DMD, DMR, DRD, DRF, DRR, DPF, DTD, DTR, DUD, DUF, DUR; | |
let DT; // Delta Time (weeks), the time interval between solutions of the equations | |
// RETAIL ------------------------ | |
// levels | |
const CPR={K:1}; | |
const IAR={K:1}; | |
const MTR={K:1}; | |
const PMR={K:1}; | |
const RSR={K:1}; | |
const UOR={K:1}; // Unfilled Orders at Retail (measured in units of goods on order) | |
// rates | |
const PDR={KL:1}; | |
const PSR={KL:1}; | |
const RRD={KL:1}; | |
const SRR={KL:1}; | |
const SSR={KL:1}; // Shipments Sent from Retail (units/week) | |
// auxiliary | |
const DFR={K:1}; | |
const IDR={K:1}; | |
const LAR={K:1}; | |
const LDR={K:1}; | |
const MNR={K:1}; | |
const NIR={K:1}; | |
const STR={K:1}; | |
const UNR={K:1}; | |
// DISTRIBUTOR ------------------- | |
// levels | |
const CPD={K:1}; | |
const IAD={K:1}; | |
const MTD={K:1}; | |
const PMD={K:1}; | |
const RSD={K:1}; | |
const UOD={K:1}; | |
// rates | |
const PDD={KL:1}; | |
const PSD={KL:1}; | |
const RRF={KL:1}; | |
const SRD={KL:1}; | |
const SSD={KL:1}; | |
// auxiliary | |
const DFD={K:1}; | |
const IDD={K:1}; | |
const LAD={K:1}; | |
const LDD={K:1}; | |
const MOD={K:1}; | |
const NID={K:1}; | |
const STD={K:1}; | |
const UND={K:1}; | |
// FACTORY ----------------------- | |
// levels | |
const CPF={K:1}; | |
const IAF={K:1}; | |
const OPF={K:1}; | |
const RSF={K:1}; | |
const UOF={K:1}; | |
// rates | |
const MDF={KL:1}; | |
const MOF={KL:1}; | |
const SRF={KL:1}; | |
const SSF={KL:1}; | |
// auxiliary | |
const DFF={K:1}; | |
const IDF={K:1}; | |
const LAF={K:1}; | |
const LDF={K:1}; | |
const MPF={K:1}; | |
const MWF={K:1}; | |
const NIF={K:1}; | |
const STF={K:1}; | |
const UNF={K:1}; | |
// FUNCTIONS ---------------------- | |
// TODO implement these functions correctly; see book | |
const STEP = (sth, stt) => 1; | |
const SIN = (x) => Math.sin(x); | |
const _2PI = () => Math.PI * 2; | |
const CLIP = (a,b,c,d) => 1; | |
const DELAY3 = (a,b) => 1; | |
var beh = { | |
postConfigure: () => { | |
this.println("this.abc " + this.abc); // OK | |
RCR.K=1 | |
RRR.KL=1 | |
SNE.K=1 | |
STP.K=1 | |
STR.K=1 | |
TIME.K=1 | |
// TEST INPUT CONDITIONS | |
PER=52 | |
RRI=1000 | |
SIH=0.0 | |
STH=0 | |
STT=4 | |
// INPUT TEST FUNCTIONS | |
RRR.KL=RRI+RCR.K | |
this.println("7R " + RRR.KL); | |
RCR.K=STP.K+SNE.K | |
this.println("7A " + RCR.K); | |
STR.K=STEP(STH,STT) | |
this.println("45A " + STR.K); | |
SNE.K=SIH*SIN(_2PI()*TIME.K/PER) | |
this.println("31A " + SNE.K); // OK | |
// constants | |
AID=6 | |
AIF=4 | |
AIR=8 | |
ALF=(1000)*(RRI) | |
DCD=2 | |
DCF=1 | |
DCR=3 | |
DHD=1 | |
DHF=1 | |
DHR=1 | |
DID=4 | |
DIF=4 | |
DIR=4 | |
DMD=.5 | |
DMR=.5 | |
DRD=8 | |
DRF=8 | |
DRR=8 | |
DPF=6 | |
DTD=2 | |
DTR=1 | |
DUD=.6 | |
DUF=1 | |
DUR=.4 | |
DT=1; | |
//this.println("ALF " + ALF); | |
UOR.J=5 | |
SSR.JK=3 | |
RRR.JK=2; | |
SSR.JK=3; | |
UOR.K=UOR.J+(DT)*(RRR.JK-SSR.JK) | |
IAR.J = 6; | |
//STR.J = 7; // Aux no .J | |
//NIR.J = 8; // Aux no .J | |
//DFR.J = 9; // Aux no .J | |
//MNR.J = 10; // Aux no .J | |
this.println("UOR.K " + UOR.K); | |
this.println(`\nUOR,IAR,SSR,RSR,PDR,CPR,PSR,PMR,RRD,MTR,SRR`); | |
}, // end postConfigure() | |
act: () => { | |
// retail RETAIL SECTOR--FIGURE 15-14, SECTION 15.5.1 | |
// (L)evel (R)ate (A)uxiliary | |
UOR.K=UOR.J+(DT)*(RRR.JK-SSR.JK) // 15- 1 1L | |
IAR.K=IAR.J+(DT)*(SRR.JK-SSR.JK) // 15- 2 1L | |
STR.K=UOR.K/DFR.K // 15- 3 20A | |
NIR.K=IAR.K/DT // 15- 4 20A | |
SSR.KL=CLIP(STR.K,NIR.K,NIR.K,STR.K) // 15- 5 51R | |
DFR.K=(MNR.K/IAR.K)+DMR //A15- 6 27A | |
MNR.K=(DUR)*(IDR.K) //B15- 6 12A | |
IDR.K=(AIR)*(RSR.K) // 15- 7 12A | |
RSR.K=RSR.J+(DT)*(1/DRR)*(RRR.JK-RSR.J) // 15- 8 3L | |
PDR.KL=RRR.JK+(1/DIR)*(IDR.K-IAR.K-LDR.K-LAR.K+UOR.K-UNR.K) // 15- 9 25R | |
LDR.K=(RSR.K)*(DCR)+(RSR.K)*(DMR)+(RSR.K)*(DFD.K)+(RSR.K)*(DTR) // 15-10 16A | |
LAR.K=CPR.K+PMR.K+UOD.K+MTR.K // 15-11 9A | |
UNR.K=(RSR.K)*(DHR+DUR) // 15-12 18A | |
CPR.K=CPR.J+(DT)*(PDR.JK-PSR.JK) // 15-13 1L | |
PSR.KL=DELAY3(PDR.JK,DCR) // 15-14 39R | |
PMR.K=PMR.J+(DT)*(PSR.JK-RRD.JK) // 15-15 1L | |
RRD.KL=DELAY3(PSR.JK,DMR) // 15-16 39R | |
MTR.K=MTR.J+(DT)*(SSD.JK-SRR.JK) // 15-17 1L | |
SRR.KL=DELAY3(SSD.JK,DTR) // 15-18 39R | |
// distributor DISTRIBUTOR SECTOR--FIGURE 15-15, SECTION 15.5.2 | |
UOD.K=UOD.J+(DT)*(RRD.JK-SSD.JK) // 15-19 1L | |
IAD.K=IAD.J+(DT)*(SRD.JK-SSD.JK) // 15-20 1L | |
STD.K=UOD.K/DFD.K // 15-21 20A | |
NID.K=IAD.K/DT // 15-22 20A | |
SSD.KL=CLIP(STD.K,NID.K,NID.K,STD.K) // 15-23 51R | |
DFD.K=(MOD.K/IAD.K)+DHD //A15-24 27A | |
MOD.K=(DUD)*(IDD.K) //B15-24 12A | |
IDD.K=(AID)*(RSD.K) // 15-25 12A | |
RSD.K=RSD.J+(DT)*(1/DRD)*(RRD.JK-RSD.J) // 15-26 3L | |
PDD.KL=RRD.JK+(1/DID)*(IDD.K-IAD.K+LDD.K-LAD.K+UOD.K-UND.K) // 15-27 25R | |
LDD.K=(RSD.K)*(DCD)+(RSD.K)*(DMD)+(RSD.K)*(DFF.K)+(RSD.K)*(DTD) // 15-28 16A | |
LAD.K=CPD.K+PMD.K+UOF.K+MTD.K // 15-29 9A | |
UND.K=(RSD.K)*(DHD+DUD) // 15-30 18A | |
CPD.K=CPD.J+(DT)*(PDD.JK-PSD.JK) // 15-31 1L | |
PSD.KL=DELAY3(PDD.JK,DCD) // 15-32 39R | |
PMD.K=PMD.J+(DT)*(PSD.JK-RRF.JK) // 15-33 1L | |
RRF.KL=DELAY3(PSD.JK,DMD) // 15-34 39R | |
MTD.K=MTD.J+(DT)*(SSF.JK-SRD.JK) // 15-35 1L | |
SRD.KL=DELAY3(SSF.JK,DTD) // 15-36 39R | |
// factory FACTORY SECTOR--FIGURE 15-16, SECTION 15.5.3 | |
UOF.K=UOF.J+(DT)*(RRF.JK-SSF.JK) // 15-37 1L | |
IAF.K=IAF.J+(DT)*(SRF.JK-SSF.JK) // 15-38 1L | |
STF.K=UOF.K/DFF.K // 15-39 20A | |
NIF.K=IAF.K/DT // 15-40 20A | |
SSF.KL=CLIP(STF.K,NIF.K,NIF.K,STF.K) // 15-41 51R | |
DFF.K=(MPF.K/IAF.K)+DHF //A15-42 27A | |
MPF.K=(DUF)*(IDF.K) //B15-42 12A | |
IDF.K=(AIF)*(RSF.K) // 15-43 12A | |
RSF.K=RSF.J+(DT)*(1/DRF)*(RRF.JK-RSF.J) // 15-44 3L | |
MWF.K=RRF.JK+(1/DIF)*(IDF.K-IAF.K+LDF.K-LAF.K+UOF.K-UNF.K) // 15-45 25A | |
MDF.KL=CLIP(MWF.K,ALF,ALF,MWF.K) // 15-46 51R | |
LDF.K=(RSF.K)*(DCF+DPF) // 15-47 18A | |
LAF.K=CPF.K+OPF.K // 15-48 7A | |
UNF.K=(RSF.K)*(DHF+DUF) // 15-49 18A | |
CPF.K=CPF.J+(DT)*(MDF.JK-MOF.JK) // 15-50 1L | |
MOF.KL=DELAY3(MDF.JK+DCF) // 15-51 39R | |
OPF.K=OPF.J+(DT)*(MOF.JK-SRF.JK) // 15-52 1L | |
SRF.KL=DELAY3(MOF.JK,DPF) // 15-53 39R | |
}, // end act() | |
postAct: () => { | |
let dpl = 3; // number of decimal places | |
this.print(`${UOR.J.toFixed(dpl)},${IAR.J.toFixed(dpl)},${SSR.JK.toFixed(dpl)},${RSR.J.toFixed(dpl)},${PDR.JK.toFixed(dpl)},`); | |
this.print(`${CPR.J.toFixed(dpl)},${PSR.JK.toFixed(dpl)},${PMR.J.toFixed(dpl)},${RRD.JK.toFixed(dpl)},${MTR.J.toFixed(dpl)},${SRR.JK.toFixed(dpl)}`); | |
this.print("\n"); | |
/* | |
UOR,IAR,SSR,RSR,PDR,CPR,PSR,PMR,RRD,MTR,SRR | |
4.000,1.000,1.000,1.000,1.000,1.000,1.000,1.000,1.000,1.000,1.000 | |
5.000,1.000,1.000,1.125,4.250,1.000,1.000,1.000,1.000,1.000,1.000 | |
6.000,1.000,1.000,1.234,2.559,4.250,1.000,1.000,1.000,1.000,1.000 | |
7.000,1.000,1.000,1.330,2.531,5.809,1.000,1.000,1.000,1.000,1.000 | |
... | |
*/ | |
}, | |
preAct: () => { | |
// handle the transition as the present (K) becomes the past (J) | |
// TODO some of these may be unnecessary/unused and/or may cause problems | |
// retail - levels, rates | |
CPR.J = CPR.K; | |
IAR.J = IAR.K; | |
MTR.J = MTR.K; | |
PMR.J = PMR.K; | |
RSR.J = RSR.K; | |
UOR.J = UOR.K; | |
PDR.JK = PDR.KL; | |
PSR.JK = PSR.KL; | |
RRD.JK = RRD.KL; | |
SRR.JK = SRR.KL; | |
SSR.JK = SSR.KL; | |
// distributor - levels, rates | |
CPD.J = CPD.K; | |
IAD.J = IAD.K; | |
MTD.J = MTD.K; | |
PMD.J = PMD.K; | |
RSD.J = RSD.K; | |
UOD.J = UOD.K; | |
PDD.JK = PDD.KL; | |
PSD.JK = PSD.KL; | |
RRF.JK = RRF.KL; | |
SRD.JK = SRD.KL; | |
SSD.JK = SSD.KL; | |
// factory - levels, rates | |
CPF.J = CPF.K; | |
IAF.J = IAF.K; | |
LAF.J = LAF.K; // ??? | |
MPF.J = MPF.K; | |
OPF.J = OPF.K; | |
RSF.J = RSF.K; | |
UOF.J = UOF.K; | |
MDF.JK = MDF.KL; | |
MOF.JK = MOF.KL; | |
SRF.JK = SRF.KL; | |
SSF.JK = SSF.KL; | |
} // end preAct | |
} | |
//# sourceURL=XhTest02.js | |
</Script> | |
</ProdDistSystem> | |
<SvgClient><Attribute_String roleName="svgUri"><![CDATA[data:image/svg+xml, | |
<svg width="100" height="50" xmlns="http://www.w3.org/2000/svg"> | |
<g> | |
<title>Script</title> | |
<rect id="ProdDistSystem/Script" fill="#98FB98" height="50" width="50" x="25" y="0"/> | |
<g> | |
<title>Script</title> | |
<rect id="ProdDistSystem/Script" fill="#6AB06A" height="50" width="10" x="80" y="0"/> | |
</g> | |
</g> | |
</svg> | |
]]></Attribute_String><Attribute_String roleName="setup">${MODELNAME_DEFAULT},${SVGURI_DEFAULT}</Attribute_String></SvgClient> | |
</XholonWorkbook> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment