Last active
February 29, 2024 03:35
-
-
Save mcsee/ec7035f1f818db309662460fc8a59d96 to your computer and use it in GitHub Desktop.
This file contains 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
<? | |
final class City { | |
public function interactionBetween($somePerson, $anotherPerson) { | |
if ($this->meetingProbability() < random()) { | |
return null; // no interaction | |
} else { | |
return new PersonToPersonInteraction($somePerson, $anotherPerson); | |
} | |
} | |
} | |
final class PersonToPersonInteraction { | |
public function propagate($aVirus) { | |
if ($this->somePerson->isInfectedWith($aVirus) | |
&& $aVirus->infectionProbability() > random()) { | |
$this->anotherPerson->getInfectedWith($aVirus); | |
} | |
} | |
} | |
$covid19 = new Virus(); | |
$janeDoe = new Person(); | |
$johnSmith = new Person(); | |
$wuhan = new City(); | |
$interaction = $wuhan->interactionBetween($johnSmith, $janeDoe); | |
if ($interaction != null) { | |
$interaction->propagate($covid19); | |
} | |
/* In this example we modeled the interaction | |
between an infected person and a healthy one. | |
Jane is healthy but might be infected | |
if Virus R0 applies to her. */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment