| … | … | @@ -528,40 +528,11 @@ |
| 528 | 528 | (length stranger-relations)) |
| 529 | 529 | |
| 530 | 530 | ; --------------------------------------------------------------------- |
| 531 | | ; Start applying state transition rules to the network. |
| 531 | ; Reporting statistics. |
| 532 | ; |
| 533 | ; As the simulation progresses, some reports are needed. This implements |
| 534 | ; a very simple reporting function. |
| 532 | 535 | ; |
| 533 | | ; This will be done "by hand" for the first few rounds, just to show how |
| 534 | | ; it works. Several different styles will be shown. One is by directly |
| 535 | | ; running scheme code. A second, better way is by applying Atomese |
| 536 | | ; search-and-update rules directly to the AtomSpace contents. The |
| 537 | | ; second way is ultimately simpler, and provides better automation, |
| 538 | | ; but both ways are illustrated, for comparison. |
| 539 | | |
| 540 | | ; A function that runs the transmission step once. This is written |
| 541 | | ; using a scheme `for-each` loop to iterate over all encounters. |
| 542 | | ; It requires, as input, the list of all relations created above. |
| 543 | | ; As such, it is "static", depending on a static relationship list. |
| 544 | | ; Later in the demo, we'll replace this loop by a search over the |
| 545 | | ; AtomSpace. |
| 546 | | (define (run-one-transmission-step) |
| 547 | | |
| 548 | | ; The transmission rule is directed, from second to first individual. |
| 549 | | ; But the relation-pairs are undirected, so we have to run the rule |
| 550 | | ; twice, swapping the individuals the second time. |
| 551 | | (for-each |
| 552 | | (lambda (relation) |
| 553 | | (exec-unwrap (Put (DefinedSchema "transmission") |
| 554 | | (List (gar relation) (gdr relation))))) |
| 555 | | all-relations) |
| 556 | | |
| 557 | | ; And now swapped ... |
| 558 | | (for-each |
| 559 | | (lambda (relation) |
| 560 | | (exec-unwrap (Put (DefinedSchema "transmission") |
| 561 | | (List (gdr relation) (gar relation))))) |
| 562 | | all-relations) |
| 563 | | ) |
| 564 | | |
| 565 | 536 | ; Obtain a list of individuals in a given state. |
| 566 | 537 | (define (get-individuals-in-state STATE) |
| 567 | 538 | (exec-unwrap |
| … | … | @@ -582,29 +553,9 @@ |
| 582 | 553 | (length individual-list)) |
| 583 | 554 | *unspecified*) |
| 584 | 555 | |
| 585 | | ; A function that rolls the dice, and updates state: looping over |
| 586 | | ; all individuals, to see if they got infected, or recovered, or died. |
| 587 | | ; As before, this uses a `for-each` loop in scheme to loop over all |
| 588 | | ; individuals. |
| 589 | | (define (run-one-state-transition) |
| 590 | | (for-each |
| 591 | | (lambda (individual) |
| 592 | | (exec-unwrap (Put (DefinedSchema "state transition") |
| 593 | | individual))) |
| 594 | | individual-list)) |
| 595 | | |
| 596 | | ; Now, actually run a few iterations, and see what happens. |
| 597 | | (run-one-transmission-step) |
| 598 | | (report-stats) |
| 599 | | (run-one-state-transition) |
| 600 | | (report-stats) |
| 601 | | |
| 602 | | (run-one-transmission-step) |
| 603 | | (report-stats) |
| 604 | | (run-one-state-transition) |
| 605 | | (report-stats) |
| 606 | | |
| 607 | 556 | ; --------------------------------------------------------------------- |
| 557 | ; Start applying state transition rules to the network. |
| 558 | ; |
| 608 | 559 | ; State transitions, applied as rewrite rules, run over the AtomSpace. |
| 609 | 560 | ; Instead of iterating over scheme lists of relations and individuals, |
| 610 | 561 | ; the code below searches the AtomSpace directly for the relevant |