|
12 | 12 | import java.util.List;
|
13 | 13 | import java.util.ArrayList;
|
14 | 14 | import java.util.Collections;
|
| 15 | +import java.io.BufferedWriter; |
| 16 | +import java.io.FileWriter; |
| 17 | +import java.io.IOException; |
15 | 18 |
|
16 |
| -//Author: Hannah Simon, HTiigee on Git |
| 19 | +//Author: Hannah Simon, HTigee on Git |
17 | 20 |
|
18 | 21 | class CellFunctions extends AgentSQ2Dunstackable<OnLattice2DCells.OnLattice2DGrid>
|
19 | 22 | {
|
@@ -409,6 +412,10 @@ public class OnLattice2DGrid extends AgentGrid2D<OnLattice2DCells.CellFunctions>
|
409 | 412 | public static String className = "Figure2";
|
410 | 413 | public static int radiationDose;
|
411 | 414 |
|
| 415 | + public static final String directory = "C:\\Users\\Hannah\\Documents\\HALModeling2024Outs\\"; |
| 416 | + public static final String fileName = "TrialRun.csv"; |
| 417 | + public static final String fullPath = directory + fileName; |
| 418 | + |
412 | 419 | public OnLattice2DGrid(int x, int y)
|
413 | 420 | {
|
414 | 421 | super(x, y, OnLattice2DCells.CellFunctions.class);
|
@@ -574,6 +581,38 @@ else if (colorIndex == 18)
|
574 | 581 | }
|
575 | 582 | }
|
576 | 583 |
|
| 584 | + public void saveToCSV(String fullPath, boolean append, int timestep) |
| 585 | + { |
| 586 | + //System.out.println("Attempting to write to: " + fullPath); |
| 587 | + try (BufferedWriter writer = new BufferedWriter(new FileWriter(fullPath, append))) |
| 588 | + { |
| 589 | + if (timestep == 0) |
| 590 | + { |
| 591 | + writer.write("Timestep," + Lymphocytes.name + "," + TumorCells.name + "," + DoomedCells.name); |
| 592 | + writer.newLine(); |
| 593 | + } |
| 594 | + writer.write(timestep + "," + Lymphocytes.count + "," + TumorCells.count + "," + DoomedCells.count); |
| 595 | + writer.newLine(); |
| 596 | + |
| 597 | + /*writer.write("Cell Type, Count"); |
| 598 | + writer.newLine(); |
| 599 | + writer.write(Lymphocytes.name + "," + Lymphocytes.count); |
| 600 | + writer.newLine(); |
| 601 | + writer.write( TumorCells.name + "," + TumorCells.count); |
| 602 | + writer.newLine(); |
| 603 | + writer.write(DoomedCells.name + "," + DoomedCells.count); |
| 604 | + writer.newLine(); |
| 605 | + writer.write("Total Cells," + Pop());*/ |
| 606 | + //System.out.println("CSV file written successfully"); |
| 607 | + } |
| 608 | + catch (IOException e) |
| 609 | + { |
| 610 | + System.err.println("Failed to write CSV file: " + e.getMessage()); |
| 611 | + e.printStackTrace(); |
| 612 | + System.exit(0); |
| 613 | + } |
| 614 | + } |
| 615 | + |
577 | 616 | public void printPopulation(String name, int colorIndex, int count)
|
578 | 617 | {
|
579 | 618 | System.out.println("Population of " + name + " (" + findColor(colorIndex) + "): " + count);
|
@@ -620,27 +659,43 @@ else if (figureCount == 6)
|
620 | 659 | OnLattice2DCells.OnLattice2DGrid model = new OnLattice2DCells.OnLattice2DGrid(x, y);
|
621 | 660 |
|
622 | 661 | model.Init();
|
| 662 | + |
| 663 | + int timestep = 0; |
| 664 | + model.saveToCSV(fullPath, false, timestep); |
| 665 | + timestep++; |
623 | 666 | //Lymphocytes.dieProb = CellFunctions.survivingFraction("radiationSensitivityOfLymphocytesAlpha", "radiationSensitivityOfLymphocytesBeta");
|
624 | 667 | //TumorCells.dieProb = CellFunctions.survivingFraction("radiationSensitivityOfTumorCellsAlpha", "radiationSensitivityOfTumorCellsBeta");
|
625 | 668 |
|
626 | 669 | for (int i = 0; i < timesteps; i++) //this for loop loops over all the time steps. The model stops running after we finish all timesteps.
|
627 | 670 | {
|
628 |
| - win.TickPause(20); |
| 671 | + win.TickPause(1); |
629 | 672 | if (model.Pop() == 0)
|
630 | 673 | {
|
| 674 | + timesteps += timestep - 1; |
| 675 | + |
631 | 676 | model.Init();
|
| 677 | + timestep = 0; |
| 678 | + model.saveToCSV(fullPath, true, timestep); |
| 679 | + timestep++; |
632 | 680 | }
|
| 681 | + //I considered adding checks for if either lymphocytes or tumor cells only reaches zero, but not necessary |
| 682 | + |
633 | 683 | model.StepCells(Lymphocytes.dieProb, Lymphocytes.divProb, Lymphocytes.colorIndex);
|
634 | 684 | model.StepCells(TumorCells.dieProb, TumorCells.divProb, TumorCells.colorIndex);
|
635 | 685 | model.StepCells(DoomedCells.dieProb, DoomedCells.divProb, DoomedCells.colorIndex);
|
636 | 686 | model.getAvailableSpaces(win);
|
637 | 687 | model.DrawModel(win);
|
| 688 | + |
| 689 | + model.saveToCSV(fullPath, true, timestep); |
| 690 | + timestep++; |
638 | 691 | }
|
639 | 692 |
|
640 | 693 | model.printPopulation(Lymphocytes.name, Lymphocytes.colorIndex, Lymphocytes.count);
|
641 | 694 | model.printPopulation(TumorCells.name, TumorCells.colorIndex, TumorCells.count);
|
642 | 695 | model.printPopulation(DoomedCells.name, DoomedCells.colorIndex, DoomedCells.count);
|
| 696 | + System.out.println("Population Total: " + model.Pop()); |
643 | 697 | System.out.println();
|
| 698 | + System.exit(0); |
644 | 699 | }
|
645 | 700 | }
|
646 | 701 | }
|
|
0 commit comments