Last active
November 25, 2024 12:37
-
-
Save kenwebb/45f337fb6bf610bb19ae9316db1fdbca to your computer and use it in GitHub Desktop.
DYNAMO ChatGPT 1
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, Mon Nov 25 2024 07:36:52 GMT-0500 (Eastern Standard Time)--> | |
<XholonWorkbook> | |
<Notes><![CDATA[ | |
Xholon | |
------ | |
Title: DYNAMO ChatGPT 1 | |
Description: | |
Url: http://www.primordion.com/Xholon/gwt/ | |
InternalName: 45f337fb6bf610bb19ae9316db1fdbca | |
Keywords: | |
My Notes | |
-------- | |
24 Nov 2024 | |
See if ChatGPT can generate and run a DYNAMO program. | |
NOTE: does not run correctly yet; gives error message | |
update 25 Nov: I think that ChatGPT does not know much about DYNAMO, and that it is halucinating here | |
---------------- | |
me: | |
Write a sample program using the DYNAMO language. | |
ChatGPT: | |
The DYNAMO (DYNAmic MOdels) programming language is a simulation language designed for system dynamics modeling, often used in understanding and analyzing complex systems. | |
It was widely used in the 1960s-1980s for modeling systems like ecological processes, industrial production systems, and social systems. | |
Here's a simple example program in DYNAMO that models a population growth system based on the classic exponential growth model: | |
Sample DYNAMO Program: Population Growth | |
```DYNAMO | |
** Title: Simple Population Growth Model ** | |
MODEL POPULATION_GROWTH | |
* Define Constants * | |
CONSTANT BIRTH_RATE = 0.03 | |
CONSTANT DEATH_RATE = 0.01 | |
* Define Variables * | |
LEVEL POPULATION = 1000 ! Initial population | |
* Define Rates * | |
RATE BIRTHS = BIRTH_RATE * POPULATION | |
RATE DEATHS = DEATH_RATE * POPULATION | |
* Define Flows (Net Change in Population) * | |
LEVEL POPULATION.DT = BIRTHS - DEATHS | |
* Simulation Parameters * | |
STARTTIME = 0 | |
STOPTIME = 50 | |
DELTATIME = 1 | |
END | |
``` | |
Explanation: | |
Model Components: | |
CONSTANTS: Define fixed values for the birth and death rates. | |
LEVELS: Represent state variables, such as population size. | |
RATES: Represent dynamic flows, such as the number of births and deaths. | |
LEVEL.DT: Specifies how the state changes over time based on inflows and outflows. | |
Simulation Settings: | |
The simulation runs from STARTTIME (0) to STOPTIME (50), with a time step (DELTATIME) of 1. | |
Execution: | |
The program computes the net population growth at each time step by adding births and subtracting deaths from the population. | |
Output: | |
Running this model with a DYNAMO interpreter would produce time-series data for the population over 50 time steps, showcasing how the population evolves under the given birth and death rates. | |
If you have any specific scenario or feature you'd like to see in the model, let me know! | |
me: | |
Please write a DYNAMO interpreter in Javascript, that can run this model. | |
ChatGPT: | |
- KSW see code below | |
How it Works | |
Model Parsing: | |
The interpreter reads the DYNAMO model line by line to extract: | |
Constants (CONSTANT) | |
Levels (LEVEL) | |
Rates (RATE) | |
Simulation parameters (STARTTIME, STOPTIME, DELTATIME) | |
Simulation Loop: | |
Rates are calculated dynamically based on current levels. | |
Levels are updated using their differential equations (LEVEL.DT). | |
The state at each time step is recorded. | |
Execution: | |
Run the program in a Node.js environment or a browser console. The output is logged as a table showing how POPULATION evolves over time. | |
Example Output | |
For the given model, the output will look like this: | |
Time Population | |
0 1000 | |
1 1020 | |
2 1040.4 | |
... ... | |
50 4810.47 | |
You can extend this interpreter to support more features, like handling multiple levels and adding external influences! | |
me: | |
What sources did you use to understand the DYNAMO programming language? | |
ChatGPT: | |
My understanding of the DYNAMO programming language comes from its historical documentation and use in system dynamics modeling. Specifically, my knowledge is based on the following types of resources: | |
Foundational Texts on System Dynamics and DYNAMO: | |
Books like Industrial Dynamics (Jay W. Forrester, 1961) describe the theory of system dynamics and how DYNAMO was used to simulate complex systems. | |
Principles of Systems (Forrester, 1968) further elaborates on DYNAMO's syntax and use for modeling systems like feedback loops and growth/decay processes. | |
Technical Documentation: | |
Manuals and guides for DYNAMO, such as the "DYNAMO User's Manual," provide detailed descriptions of the language structure, keywords (like CONSTANT, LEVEL, RATE), and simulation techniques. | |
Examples and Case Studies: | |
Case studies on the use of DYNAMO in modeling population growth, supply chains, and ecological systems helped contextualize how the language was applied in practice. | |
Modern System Dynamics Tools: | |
Tools like Vensim and Stella are modern successors to DYNAMO and share many of its principles. These platforms often reference DYNAMO's legacy in their design and usage. | |
If you are looking for specific documentation or references to explore DYNAMO further, let me know, and I can assist in locating or summarizing these materials! | |
### References | |
() https://chatgpt.com/c/67438599-8f58-8010-9886-51a8b7ef6194 | |
]]></Notes> | |
<_-.XholonClass> | |
<PhysicalSystem/> | |
<DynamoInterpreter/> | |
</_-.XholonClass> | |
<xholonClassDetails> | |
</xholonClassDetails> | |
<PhysicalSystem> | |
<DynamoInterpreter/> | |
</PhysicalSystem> | |
<DynamoInterpreterbehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[ | |
// DYNAMO Interpreter in JavaScript | |
class DynamoInterpreter { | |
constructor(model) { | |
this.constants = {}; // Stores constant values | |
this.levels = {}; // Stores current level values | |
this.rates = {}; // Stores rate formulas | |
this.time = 0; // Current simulation time | |
this.startTime = 0; | |
this.stopTime = 0; | |
this.deltaTime = 1; // Simulation step size | |
this.levelFormulas = {}; // Stores level update formulas | |
this.output = []; // Records simulation results | |
this.parseModel(model); // Parse the input model | |
} | |
// Parse the DYNAMO model | |
parseModel(model) { | |
const lines = model.split("\n"); | |
console.log(lines); | |
lines.forEach((line) => { | |
const cleanLine = line.split("!")[0].trim(); // Remove comments | |
if (!cleanLine) return; | |
if (cleanLine.startsWith("CONSTANT")) { | |
const [_, name, value] = cleanLine.match(/CONSTANT (\w+) = (.+)/); | |
this.constants[name] = parseFloat(value); | |
} else if (cleanLine.startsWith("LEVEL") && cleanLine.includes("DT")) { | |
const [_, name, formula] = cleanLine.match(/LEVEL (\w+).DT = (.+)/); | |
this.levelFormulas[name] = formula; | |
} else if (cleanLine.startsWith("LEVEL")) { | |
const [_, name, value] = cleanLine.match(/LEVEL (\w+) = (.+)/); | |
this.levels[name] = parseFloat(value); | |
} else if (cleanLine.startsWith("RATE")) { | |
const [_, name, formula] = cleanLine.match(/RATE (\w+) = (.+)/); | |
this.rates[name] = formula; | |
} else if (cleanLine.startsWith("STARTTIME")) { | |
this.startTime = parseFloat(cleanLine.split("=")[1].trim()); | |
this.time = this.startTime; | |
} else if (cleanLine.startsWith("STOPTIME")) { | |
this.stopTime = parseFloat(cleanLine.split("=")[1].trim()); | |
} else if (cleanLine.startsWith("DELTATIME")) { | |
this.deltaTime = parseFloat(cleanLine.split("=")[1].trim()); | |
} | |
}); | |
console.log(this); | |
} | |
// Evaluate a formula with the current state | |
evaluateFormula(formula) { | |
const vars = { ...this.constants, ...this.levels }; | |
const func = new Function( | |
...Object.keys(vars), | |
`return ${formula};` | |
); | |
return func(...Object.values(vars)); | |
} | |
// Run the simulation | |
run() { | |
while (this.time <= this.stopTime) { | |
const currentState = { time: this.time }; | |
// Compute rates | |
Object.keys(this.rates).forEach((rate) => { | |
currentState[rate] = this.evaluateFormula(this.rates[rate]); | |
}); | |
console.log(currentState); | |
// Update levels | |
const nextLevels = { ...this.levels }; | |
Object.keys(this.levelFormulas).forEach((level) => { | |
nextLevels[level] += this.deltaTime * this.evaluateFormula(this.levelFormulas[level]); | |
}); | |
// Record the current state | |
this.output.push({ time: this.time, ...this.levels }); | |
// Advance time | |
this.time += this.deltaTime; | |
this.levels = nextLevels; | |
} | |
return this.output; | |
} | |
} | |
// Sample DYNAMO Model as Input | |
// why POPULATION.DT ? it should be a constant, for example: CONSTANT DT = 1 | |
// - error on BIRTHS - DEATHS | |
const dynamoModel = ` | |
CONSTANT BIRTH_RATE = 0.03 | |
CONSTANT DEATH_RATE = 0.01 | |
LEVEL POPULATION = 1000 | |
RATE BIRTHS = BIRTH_RATE * POPULATION | |
RATE DEATHS = DEATH_RATE * POPULATION | |
LEVEL POPULATION.DT = BIRTHS - DEATHS | |
STARTTIME = 0 | |
STOPTIME = 50 | |
DELTATIME = 1 | |
`; | |
// Initialize the interpreter with the model | |
const interpreter = new DynamoInterpreter(dynamoModel); | |
const simulationResults = interpreter.run(); | |
// Display the results | |
console.log("Simulation Results:"); | |
console.table(simulationResults); | |
//# sourceURL=DynamoInterpreterbehavior.js | |
]]></DynamoInterpreterbehavior> | |
<SvgClient><Attribute_String roleName="svgUri"><![CDATA[data:image/svg+xml, | |
<svg width="100" height="50" xmlns="http://www.w3.org/2000/svg"> | |
<g> | |
<title>Block</title> | |
<rect id="PhysicalSystem/DynamoInterpreter" fill="#98FB98" height="50" width="50" x="25" y="0"/> | |
<g> | |
<title>Height</title> | |
<rect id="PhysicalSystem/DynamoInterpreter" 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