| … | … | @@ -452,20 +452,6 @@ |
| 452 | 452 | ; Run the above. |
| 453 | 453 | (initialize-state) |
| 454 | 454 | |
| 455 | | ; --------- |
| 456 | | ; Each individual is linked back to the anchor node. Each individual |
| 457 | | ; is also represented with a ConceptNode (we have some other junk |
| 458 | | ; also attached to the anchor, so filter that out.) |
| 459 | | (define individual-list |
| 460 | | (filter (lambda (ind) (equal? (cog-type ind) 'ConceptNode)) |
| 461 | | (map gar (cog-incoming-by-type anchor 'MemberLink)))) |
| 462 | | |
| 463 | | (format #t "The social network consists of ~D individuals\n" |
| 464 | | (length individual-list)) |
| 465 | | |
| 466 | | ; Pick one person, and make them infected. |
| 467 | | (cog-set-value! (car individual-list) seir-state infected) |
| 468 | | |
| 469 | 455 | ; --------------------------------------------------------------------- |
| 470 | 456 | ; Reporting statistics. |
| 471 | 457 | ; |
| … | … | @@ -510,14 +496,13 @@ |
| 510 | 496 | *unspecified*) |
| 511 | 497 | |
| 512 | 498 | ; --------------------------------------------------------------------- |
| 513 | | ; Start applying state transition rules to the network. |
| 499 | ; Apply state transition rules to the network. |
| 514 | 500 | ; |
| 515 | | ; State transitions, applied as rewrite rules, run over the AtomSpace. |
| 516 | | ; Instead of iterating over scheme lists of relations and individuals, |
| 517 | | ; the code below searches the AtomSpace directly for the relevant |
| 518 | | ; relations and individuals. This is more elegant than monkeying around |
| 519 | | ; with scheme code. It operates by applying graph rewrite rules directly |
| 520 | | ; to the AtomSpace, where the data actually lives. |
| 501 | ; The state transition rules drive the actual simulation. These rules |
| 502 | ; are applied as graph rewrite rules, running over the AtomSpace. |
| 503 | ; There are two rules to apply. One rule that runs over all pairs, |
| 504 | ; transmitting disease from one individual to another. The other rule |
| 505 | ; updates the individual state, from exposed to infected to resolved. |
| 521 | 506 | |
| 522 | 507 | ; Search for all pairs, and apply the transmission rule. |
| 523 | 508 | (define (do-transmission) |
| … | … | @@ -551,6 +536,16 @@ |
| 551 | 536 | (Variable "$person")))) |
| 552 | 537 | *unspecified*) |
| 553 | 538 | |
| 539 | ; Oh, but first, pick one person, and make them infected! |
| 540 | (define everyone (get-individuals-in-state susceptible)) |
| 541 | (define one-person (first everyone)) |
| 542 | (cog-execute! (SetValue one-person seir-state infected)) |
| 543 | |
| 544 | ; Start the simulation. Run several steps by hand, to get the |
| 545 | ; hang of it. |
| 546 | (do-transmission) (report-stats) |
| 547 | (do-state-transition) (report-stats) |
| 548 | |
| 554 | 549 | (do-transmission) (report-stats) |
| 555 | 550 | (do-state-transition) (report-stats) |
| 556 | 551 | |