diff --git a/CHANGELOG.md b/CHANGELOG.md index 351aeb9..6d3d897 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,15 @@ +# v2.2.0 + +- Add `.remove` and `.add` functions to `Model` class in `model` module to add and remove compartments. + +# v2.1.2 + +- Fix error from previous release + +# v2.1.1 + +- Fix key error in `model` + # v2.1.0 - Adds `manipulate` to manipulate outputs with `plots` - Adds `mexport` and `mimport` to `model`, which allow for exporting and importing models to `.js` and `.json` files. diff --git a/EpiJS/model.js b/EpiJS/model.js index 87dc7e0..2d8ceb6 100644 --- a/EpiJS/model.js +++ b/EpiJS/model.js @@ -87,6 +87,64 @@ class Model { } } } + + /** + * Remove a compartment from the model. + * @param {Object} compartment - The compartment to remove. + * @example + * + * let susceptible = new Idiom("S-(B*S*I/p)"); + * let infected = new Idiom("I+(B*S*I/p)-(u*I)"); + * let recovered = new Idiom("R+(u*I)"); + * + * let key = { + * "S": 10000, + * "B": 0.3, + * "I": 100, + * "R": 0, + * "p": 10100, + * "u": 0.2 + * }; + * + * let sirm = new Model([[susceptible, "S"], [infected, "I"], [recovered, "R"]], key) + * + * sirm.remove(recovered) // Removes the recovered compartment. + */ + remove(compartment) { + for (var x = 0; x < this.compartments.length; x++) { + if (this.compartments[x][0] === compartment) { + this.compartments.splice(x, 1) + } + } + } + + /** + * Add a compartment to the model. + * @param {Array} compartment - The compartment to add, should be a list, with the first value being the compartment, and the second being it's value in the key. + * @param {Number} index - The index to add the compartment at. + * @example + * + * let susceptible = new Idiom("S-(B*S*I/p)"); + * let infected = new Idiom("I+(B*S*I/p)-(u*I)"); + * let recovered = new Idiom("R+(u*I)"); + * + * let key = { + * "S": 10000, + * "B": 0.3, + * "I": 100, + * "R": 0, + * "p": 10100, + * "u": 0.2 + * }; + * + * let sirm = new Model([[susceptible, "S"], [infected, "I"], [recovered, "R"]], key) + * + * sirm.remove(susceptible) // Removes the susceptible compartment. + * sirm.add([susceptible, "S"], 0) // Adds the susceptible compartment back to the beginning + */ + add(compartment, index) { + this.compartments.splice(index, 0, compartment) + } } /** diff --git a/docs/.vuepress/dist/404.html b/docs/.vuepress/dist/404.html index 9575ebb..ce799ea 100644 --- a/docs/.vuepress/dist/404.html +++ b/docs/.vuepress/dist/404.html @@ -8,13 +8,13 @@ - +
-