Skip to content
Yvan Guifo edited this page Apr 21, 2022 · 3 revisions
	
	sirConcern := KEModelPart new.
	sirConcern attributes: {(#status -> #(#S #I #R))}.
	sirConcern addParameters: {#lambda . #gamma}.
	sirConcern 
		addTransitionFrom: {(#status -> #S)} to: {(#status -> #I)} probability: [ :aModel | aModel atParameter: #lambda ].
	sirConcern 
		addTransitionFrom: {(#status -> #I)} to: {(#status -> #R)} probability: [ :aModel | aModel atParameter: #gamma ].
	patchConcern := KEModelPart new.
	patchConcern addAttribute: #patch value: (1 to: 3) asArray.
	patchConcern addParameter: #rho.
	1 to: 2
		do: [ :i | 
	patchConcern
						addTransitionFrom: {(#patch -> i)}
						to: {(#patch -> (i + 1))}
						probability: [ :aModel | aModel atParameter: #rho ]].
	patchConcern addTransitionFrom: {(#patch -> 3)} to: {(#patch -> 1)} probability: [ :aModel | aModel atParameter: #rho ].
	
	model :=  patchConcern + sirConcern.
	
	model atParameter: #beta assignValue: 0.1.
   model atParameter: #gamma assignValue: 1/30.
   model atParameter: #N assignValue: 100.
	
	model
		atParameter: #N
		assignValue: [ :aModel | 
			| c |
			c := aModel currentCompartment at: #patch.
			aModel sizeOfPopulation: (Array with: c) ].
	model atParameter: #rho assignValue: 0.03.
	model
		atParameter: #lambda
		assignValue: [ :aModel | 
			| c |
			c := aModel currentCompartment at: #patch.
			(aModel atParameter: #beta)
				*
					(aModel
						atCompartment:
							{(#status -> #I).
							(#patch -> c)})/(aModel atParameter: #N) ].
						
	model
		atCompartment:
			{(#status -> #S).
			(#patch -> 1)}
		put: 90
		atOthersPut: 0.
	model
		atCompartment:
			{(#status -> #I).
			(#patch -> 1)}
		put: 10.
	model
		atCompartment:
			{(#status -> #S).
			(#patch -> 2)}
		put: 100.
	model
		atCompartment:
			{(#status -> #S).
			(#patch -> 3)}
		put: 100.

	simulator := KESimulator
		new: #RungeKutta
		from: 0.0
        to: 365
        step: 1.
	simulator executeOn: model.
	chart := KEChart new.
	chart
		addDataFrame: (simulator
						timeSeriesOutputsAt:
							{#status -> #I.
							#patch -> 1});
		addDataFrame: (simulator
						timeSeriesOutputsAt:
							{(#status -> #I).
							(#patch -> 2)});
							addDataFrame: (simulator
						timeSeriesOutputsAt:
							{(#status -> #I).
							(#patch -> 3)}).

	chart legendTitle: 'Infectious'.
	chart plot 

The DSL code for this example without the visualization entity

KModel SIR
	attribute: #(status -> S I R);
	parameters: #(beta lambda gamma mu);
	transitions: #(
		S -- lambda --> I.
		I -- gamma --> R.);
	lambda: #(beta*I/N).


KModel Metapop
	attribute: #(patch -> 1  2  3);
	parameters: #(rho);
	transitions: #(
		1 -- rho --> 2.
		2 -- rho --> 3.
		3 -- rho --> 1.).

Composition SIRMetapop
	model: 'SIR';
	model: 'Metapop'.

Scenario SIRMetapopPopulation
	on: 'SIRMetapop';
	S_patch: #(90 100 100);
	I_patch: #(10 0 0).
	
Scenario SIRMetapopParameters
	on: 'SIRMetapop';
   beta: 0.1;
	N: #(patch);
	lambda: #(beta*I_patch/N);
	gamma: 1/30;
	rho: 0.03.
	
Simulation SIRMetapopRK rungeKutta
	scenarios: #(SIRMetapopPopulation SIRMetapopParameters);
	from: 0; 
	to: 365; 
	step: 1.

SIRMetapopulation

Custom sidebar of the Kendrick Wiki

Basic-SIR

SIR---Metapopulation

Clone this wiki locally