Skip to content
Yvan Guifo edited this page Apr 15, 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 := KEModel new.
	model integrate: patchConcern.
	model integrate: 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 

SIRMetapopulation

Custom sidebar of the Kendrick Wiki

Basic-SIR

SIR---Metapopulation

Clone this wiki locally