├── .gitignore ├── CITATION.cff ├── Examples ├── BasicCellularAutomata │ └── BasicCellularAutomata.java ├── Chemotaxis │ └── ChemotaxisModel.java ├── ClinicianSim │ └── ExampleModelInteractive.java ├── ColorBarGenerator │ └── ColorBarGenerator.java ├── GameOfLife │ ├── GOLGrid.java │ └── GOLSweepEx.java ├── GasPopulationGrid │ └── Gas.java ├── Lenia │ ├── Orbium.java │ └── OrbiumNPlayer.java ├── ModuleSetExample │ └── DivisionDeathMutation.java ├── MultiwellOutbreak │ ├── MultiOutbreak.java │ ├── OutbreakWorld.java │ └── Person.java ├── ODEmodel │ └── TumorGrowth.java ├── PersianModel │ └── PersianCarpets.java ├── PhylogenyTracker │ └── PhylogenyModel.java ├── PopulationTumor │ └── PopTumor.java ├── Template_Models │ ├── TemplateMultiGrid.java │ ├── TemplateOffLattice2D.java │ └── TemplateOnLattice2D.java ├── _1DivisionDeathMutation │ └── DivisionDeathMutation.java ├── _2StemCellExample │ └── StemCellExample.java ├── _3OffLatticeExample │ └── ExampleOffLattice.java ├── _4PDEexample │ └── PDEexample.java ├── _5Example3D │ └── Example3D.java └── _6CompetitiveRelease │ └── ExampleModel.java ├── FrameworkPresentation.pdf ├── HAL ├── GridsAndAgents │ ├── Agent0D.java │ ├── Agent1DBase.java │ ├── Agent2DBase.java │ ├── Agent3DBase.java │ ├── AgentBase.java │ ├── AgentBaseSpatial.java │ ├── AgentGrid0D.java │ ├── AgentGrid1D.java │ ├── AgentGrid2D.java │ ├── AgentGrid3D.java │ ├── AgentList.java │ ├── AgentPT1D.java │ ├── AgentPT2D.java │ ├── AgentPT3D.java │ ├── AgentSQ1D.java │ ├── AgentSQ1Dunstackable.java │ ├── AgentSQ2D.java │ ├── AgentSQ2Dunstackable.java │ ├── AgentSQ3D.java │ ├── AgentSQ3Dunstackable.java │ ├── Grid1Ddouble.java │ ├── Grid1Dint.java │ ├── Grid1Dlong.java │ ├── Grid1Dobject.java │ ├── Grid2Ddouble.java │ ├── Grid2Dint.java │ ├── Grid2Dlong.java │ ├── Grid2Dobject.java │ ├── Grid3Ddouble.java │ ├── Grid3Dint.java │ ├── Grid3Dlong.java │ ├── Grid3Dobject.java │ ├── InternalGridAgentList.java │ ├── KernelGrid.java │ ├── PDEGrid1D.java │ ├── PDEGrid2D.java │ ├── PDEGrid3D.java │ ├── PopulationGrid1D.java │ ├── PopulationGrid1DLong.java │ ├── PopulationGrid2D.java │ ├── PopulationGrid2DLong.java │ ├── PopulationGrid3D.java │ ├── PopulationGrid3DLong.java │ ├── PopulationGridBase.java │ ├── PopulationGridLongBase.java │ ├── SphericalAgent2D.java │ └── SphericalAgent3D.java ├── Gui │ ├── GifMaker.java │ ├── GridWindow.java │ ├── OpenGL2DWindow.java │ ├── OpenGL3DWindow.java │ ├── PlotLine.java │ ├── PlotPointInternal.java │ ├── PlotWindow.java │ ├── TickTimer.java │ ├── UIBoolInput.java │ ├── UIButton.java │ ├── UIComboBoxInput.java │ ├── UIDoubleInput.java │ ├── UIFileChooserInput.java │ ├── UIGrid.java │ ├── UIGridView.java │ ├── UIIntInput.java │ ├── UILabel.java │ ├── UIPlot.java │ ├── UIStringInput.java │ └── UIWindow.java ├── Interfaces │ ├── AgentAction.java │ ├── AgentRadDispToAction1D.java │ ├── AgentRadDispToAction2D.java │ ├── AgentRadDispToAction3D.java │ ├── AgentStepFunction.java │ ├── AgentToBool.java │ ├── AgentToColorInt.java │ ├── AgentToDouble.java │ ├── AgentToInts.java │ ├── AgentToString.java │ ├── ButtonAction.java │ ├── ColorIntGenerator.java │ ├── Coords1DBool.java │ ├── Coords1DDouble.java │ ├── Coords1DInt.java │ ├── Coords2DAction.java │ ├── Coords2DBool.java │ ├── Coords2DColor.java │ ├── Coords2DDouble.java │ ├── Coords2DInt.java │ ├── Coords2DSetArray.java │ ├── Coords3DAction.java │ ├── Coords3DBool.java │ ├── Coords3DDouble.java │ ├── Coords3DInt.java │ ├── Coords3DSetArray.java │ ├── Coords6DDouble.java │ ├── CustomSerialization.java │ ├── DistToForceMap.java │ ├── DoubleArrayToDouble.java │ ├── DoubleArrayToVoid.java │ ├── DoubleToAction.java │ ├── DoubleToColor.java │ ├── DoubleToDouble.java │ ├── DoubleToDoubles.java │ ├── DoubleToInt.java │ ├── Doubles2DDouble.java │ ├── Doubles3DDouble.java │ ├── DoublesToColor.java │ ├── DrawFunction.java │ ├── GAMutantToString.java │ ├── GAMutationFunction.java │ ├── GAScoreFunction.java │ ├── GenDouble.java │ ├── GetGenomeAttrs.java │ ├── GetMutationInfo.java │ ├── Grid1D.java │ ├── Grid2D.java │ ├── Grid3D.java │ ├── GridDiff2MultiThreadFunction.java │ ├── GuiCloseAction.java │ ├── GuiComp.java │ ├── ICoords2DAction.java │ ├── ICoords3DAction.java │ ├── IndexAction.java │ ├── IndexBool.java │ ├── IndexCoords2DAction.java │ ├── IndexCoords2DBool.java │ ├── IndexCoords2DDouble.java │ ├── IndexCoords3DAction.java │ ├── IndexCoords3DBool.java │ ├── IndexIntAction.java │ ├── IndexIntToAction.java │ ├── IndexLongAction.java │ ├── IntDoubleToVoid.java │ ├── IntToBool.java │ ├── IntToDouble.java │ ├── IntToInt.java │ ├── IntToVoid.java │ ├── IsEntry1Before2.java │ ├── KeyResponse.java │ ├── LocalIndexAction.java │ ├── MenuItem.java │ ├── ObjectToDouble.java │ ├── OdeSolution.java │ ├── OverlapForceResponse2D.java │ ├── OverlapForceResponse3D.java │ ├── ParallelFunction.java │ ├── ParamSetChangeAction.java │ ├── Point1DBool.java │ ├── Point2DBool.java │ ├── Point3DBool.java │ ├── RNG.java │ ├── SerializableModel.java │ ├── Sortable.java │ ├── SwapEntries.java │ └── VoidFunction.java ├── Rand.java ├── Tools │ ├── BoolSet.java │ ├── FileIO.java │ ├── InteractiveModel │ │ ├── InteractiveModel.java │ │ └── TreatableTumor.java │ ├── Internal │ │ ├── ADIequations.java │ │ ├── Binomial.java │ │ ├── Gaussian.java │ │ ├── KeyRecorder.java │ │ ├── PDEequations.java │ │ ├── ParamSet.java │ │ ├── PopulationGridPDEequations.java │ │ ├── SplittableRN.java │ │ └── SweepRun.java │ ├── Lenia │ │ ├── Coords1DDoubleArrToDouble.java │ │ ├── Coords2DDoubleToDouble.java │ │ ├── FFTGrid.java │ │ ├── FFTbase.java │ │ ├── Lenia1Player.java │ │ └── LeniaNPlayer.java │ ├── Modularity │ │ ├── ModuleSetManager.java │ │ ├── VarSet.java │ │ └── VarSetManager.java │ ├── MultiWellExperiment │ │ ├── DrawWell.java │ │ ├── MultiWellExperiment.java │ │ └── StepWell.java │ ├── MultinomialCalc.java │ ├── MultinomialCalcLong.java │ ├── ODESolver │ │ ├── Derivative.java │ │ └── ODESolver.java │ ├── PY4J │ │ ├── DoublesDataFrame.java │ │ ├── Py4jModel.java │ │ └── Py4jRunner.java │ ├── PhylogenyTracker │ │ ├── Genome.java │ │ ├── GenomeFn.java │ │ ├── GenomeLineageFn.java │ │ └── PhylogenyTrackerInternal.java │ └── TdmaSolver.java ├── Util.java └── lib │ ├── lwjgl-assimp-javadoc.jar │ ├── lwjgl-assimp-natives-linux-arm32.jar │ ├── lwjgl-assimp-natives-linux-arm64.jar │ ├── lwjgl-assimp-natives-linux.jar │ ├── lwjgl-assimp-natives-macos-arm64.jar │ ├── lwjgl-assimp-natives-macos.jar │ ├── lwjgl-assimp-natives-windows-arm64.jar │ ├── lwjgl-assimp-natives-windows-x86.jar │ ├── lwjgl-assimp-natives-windows.jar │ ├── lwjgl-assimp-sources.jar │ ├── lwjgl-assimp.jar │ ├── lwjgl-glfw-javadoc.jar │ ├── lwjgl-glfw-natives-linux-arm32.jar │ ├── lwjgl-glfw-natives-linux-arm64.jar │ ├── lwjgl-glfw-natives-linux.jar │ ├── lwjgl-glfw-natives-macos-arm64.jar │ ├── lwjgl-glfw-natives-macos.jar │ ├── lwjgl-glfw-natives-windows-arm64.jar │ ├── lwjgl-glfw-natives-windows-x86.jar │ ├── lwjgl-glfw-natives-windows.jar │ ├── lwjgl-glfw-sources.jar │ ├── lwjgl-glfw.jar │ ├── lwjgl-javadoc.jar │ ├── lwjgl-natives-linux-arm32.jar │ ├── lwjgl-natives-linux-arm64.jar │ ├── lwjgl-natives-linux.jar │ ├── lwjgl-natives-macos-arm64.jar │ ├── lwjgl-natives-macos.jar │ ├── lwjgl-natives-windows-arm64.jar │ ├── lwjgl-natives-windows-x86.jar │ ├── lwjgl-natives-windows.jar │ ├── lwjgl-openal-javadoc.jar │ ├── lwjgl-openal-natives-linux-arm32.jar │ ├── lwjgl-openal-natives-linux-arm64.jar │ ├── lwjgl-openal-natives-linux.jar │ ├── lwjgl-openal-natives-macos-arm64.jar │ ├── lwjgl-openal-natives-macos.jar │ ├── lwjgl-openal-natives-windows-arm64.jar │ ├── lwjgl-openal-natives-windows-x86.jar │ ├── lwjgl-openal-natives-windows.jar │ ├── lwjgl-openal-sources.jar │ ├── lwjgl-openal.jar │ ├── lwjgl-opengl-javadoc.jar │ ├── lwjgl-opengl-natives-linux-arm32.jar │ ├── lwjgl-opengl-natives-linux-arm64.jar │ ├── lwjgl-opengl-natives-linux.jar │ ├── lwjgl-opengl-natives-macos-arm64.jar │ ├── lwjgl-opengl-natives-macos.jar │ ├── lwjgl-opengl-natives-windows-arm64.jar │ ├── lwjgl-opengl-natives-windows-x86.jar │ ├── lwjgl-opengl-natives-windows.jar │ ├── lwjgl-opengl-sources.jar │ ├── lwjgl-opengl.jar │ ├── lwjgl-sources.jar │ ├── lwjgl-stb-javadoc.jar │ ├── lwjgl-stb-natives-linux-arm32.jar │ ├── lwjgl-stb-natives-linux-arm64.jar │ ├── lwjgl-stb-natives-linux.jar │ ├── lwjgl-stb-natives-macos-arm64.jar │ ├── lwjgl-stb-natives-macos.jar │ ├── lwjgl-stb-natives-windows-arm64.jar │ ├── lwjgl-stb-natives-windows-x86.jar │ ├── lwjgl-stb-natives-windows.jar │ ├── lwjgl-stb-sources.jar │ ├── lwjgl-stb.jar │ └── lwjgl.jar ├── HalColorSchemes.jar ├── LEARN_HERE ├── Agents │ ├── BirthDeath.java │ ├── BirthDeathOffLattice.java │ ├── Mover3D.java │ ├── MultiwellExample.java │ ├── PopGrid.java │ ├── SaveLoadModel.java │ └── mover3DoffLattice.java ├── Diffusibles │ ├── DiffusionAdvection3D.java │ ├── Gradient2D.java │ ├── Gradient3D.java │ └── ReactionDiffusion2D.java └── Other │ ├── BinomialTest.java │ ├── ColorInterpolation.java │ ├── ColorTest.java │ ├── FileIOTest.java │ ├── GIFtest.java │ ├── GuiExample.java │ ├── HeatMaps.java │ ├── LineSegmentTest.java │ ├── LockExample.java │ ├── NonSpatialABM.java │ ├── PNGexample.java │ ├── PlotExample.java │ ├── vis3Dtest.java │ └── yCbCrTest.java ├── LICENSE ├── README.md ├── Testing ├── AgentTests.java ├── ConvergenceTesting │ ├── ConvergenceDiffusionAdvection1D.java │ ├── ConvergenceDiffusionAdvection2D.java │ ├── ConvergenceDiffusionAdvection3D.java │ ├── ConvergencePlotAdvectionGaussian.png │ ├── ConvergenceReaction1D.java │ ├── ConvergenceReaction2D.java │ ├── ConvergenceReaction3D.java │ ├── ConvergenceTests.java │ ├── Dx.txt │ ├── L1.txt │ ├── L2.txt │ └── Linf.txt ├── KernelTest.java ├── MathTests.java ├── OldTests │ ├── ADITest.java │ ├── AdvectionTest1D.java │ ├── AgentListTest.java │ ├── AgetGrid0DTest.java │ ├── BitGenomeTest.java │ ├── CircleHoodTest.java │ ├── ConvectionTest.java │ ├── ConvectionTest2.java │ ├── ConvergenceTestAdvection.java │ ├── CrankTest.java │ ├── CubeTest.java │ ├── DiffAnalyticalTest.java │ ├── DiffTest3D.java │ ├── DiffusionDisc1D.java │ ├── DiffusionExampleSimple.java │ ├── DoubleAdditionTest.java │ ├── GGVScaleTest.java │ ├── GGVtest.java │ ├── GuiPrintTest.java │ ├── HSBRGB.java │ ├── HsLuvTest.java │ ├── JetTest.java │ ├── KeyListenerTest.java │ ├── LightingTest.java │ ├── LinePlotTest.java │ ├── MovementTest.java │ ├── MultinomialTest.java │ ├── MutlinomialTest.java │ ├── ODEtest.java │ ├── OnVsOffLatticeSpeedTest.java │ ├── PDEtest2.java │ ├── PMFtests.java │ ├── Painter.java │ ├── ParticleExample.java │ ├── PlotLineTest.java │ ├── PlotTest.java │ ├── PopGrid3DTest.java │ ├── RandTest.java │ ├── SerializableModelTest.java │ ├── ShellCommandTest.java │ ├── SigmoidTest.java │ ├── StringTest.java │ ├── SwapPositionsTest.java │ ├── TDMAtests.java │ ├── Vis2DCircle.java │ ├── ZeroDiffusionTest.java │ └── mkdirs.java ├── PDETests.java ├── PerformanceTestModels │ ├── OffLatticePerformanceModel.java │ └── OnLatticePerformanceModel.java ├── SortTest.java └── UnitTester.java └── what_is_hybrid_modeliing.png /.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !*/ 3 | !*/*/ 4 | !*/*/*/ 5 | !*/*/*/*/ 6 | !*/*/*/*/*/ 7 | !*.java 8 | !HAL/lib/* 9 | # only allow scource files 10 | #!HAL/**.java 11 | #!LEARN_HERE/**.java 12 | #!Testing/**.java 13 | #!Examples/** 14 | #!.gitignore 15 | !HalColorSchemes.jar 16 | !manual.pdf 17 | !FrameworkPresentation.pdf 18 | #.DS_Store 19 | -------------------------------------------------------------------------------- /CITATION.cff: -------------------------------------------------------------------------------- 1 | # This CITATION.cff file was generated with cffinit. 2 | # Visit https://bit.ly/cffinit to generate yours today! 3 | 4 | cff-version: 1.2.0 5 | title: Hybrid Automata Library 6 | message: >- 7 | If you use this software, please cite it using the 8 | metadata from this file. 9 | type: software 10 | authors: 11 | - given-names: Rafael 12 | family-names: Bravo 13 | - given-names: Etienne 14 | family-names: Baratchart 15 | - given-names: Jeffrey 16 | family-names: West 17 | - given-names: Ryan 18 | family-names: Schenck 19 | - given-names: Anna 20 | family-names: Miller 21 | - given-names: Jill 22 | family-names: Gallaher 23 | - given-names: Chandler 24 | family-names: Gatenbee 25 | - given-names: David 26 | family-names: Basanta 27 | - given-names: Mark 28 | family-names: Robertson-Tessi 29 | - given-names: Alexander 30 | family-names: Anderson 31 | repository-code: 'https://github.com/mathonco/hal' 32 | url: 'https://halloworld.org/' 33 | abstract: >- 34 | Hybrid Automata Library (HAL) is a Java library that 35 | facilitates hybrid modeling: spatial models with 36 | interacting agent-based and partial-differential equation 37 | components. HAL’s components can be broadly classified 38 | into: agent containers (on and off-lattice), finite 39 | difference diffusion fields, graphical user interface 40 | (GUI) components, and additional tools or utilities for 41 | computation and data manipulation. These components have a 42 | standardized interface that expedites the construction, 43 | analysis, and visualization of complex models. 44 | -------------------------------------------------------------------------------- /Examples/Chemotaxis/ChemotaxisModel.java: -------------------------------------------------------------------------------- 1 | package Examples.Chemotaxis; 2 | 3 | import HAL.GridsAndAgents.*; 4 | import HAL.Gui.OpenGL2DWindow; 5 | import HAL.Rand; 6 | import HAL.Util; 7 | 8 | 9 | class SphericalCow extends SphericalAgent2D{ 10 | public void Step(){ 11 | if(G.grass.Get(Isq())>0){ 12 | G.grass.Add(Isq(),-G.EAT_RATE); 13 | } 14 | //chemotaxis 15 | double gradX=G.grass.GradientX(Xsq(),Ysq()); 16 | double gradY=G.grass.GradientY(Xsq(),Ysq()); 17 | double norm= Util.Norm(gradX,gradY); 18 | if(gradX!=0) { 19 | xVel += gradX / norm * G.CHEMOTAX_RATE; 20 | } 21 | if(gradY!=0) { 22 | yVel += gradY / norm * G.CHEMOTAX_RATE; 23 | } 24 | //random movement and forces 25 | G.rng.RandomPointInCircle(G.RANDOM_MOVE_RATE,G.randomMoveScratch); 26 | xVel+=G.randomMoveScratch[0]; 27 | yVel+=G.randomMoveScratch[1]; 28 | SumForces(radius,(overlap,other)->Math.pow(G.FORCE_SCALER*overlap, G.FORCE_EXPONENT)); 29 | ForceMove(); 30 | ApplyFriction(G.FRICTION); 31 | } 32 | } 33 | 34 | public class ChemotaxisModel extends AgentGrid2D { 35 | PDEGrid2D grass; 36 | double FORCE_EXPONENT=2;//these constants have been found to be rather stable, but tweak them and see what happens! 37 | double FORCE_SCALER=0.7; 38 | double FRICTION=0.5; 39 | double GROW_RATE=0.01; 40 | double EAT_RATE=1; 41 | double CHEMOTAX_RATE=0.1; 42 | double RANDOM_MOVE_RATE=0.1; 43 | double[]randomMoveScratch=new double[2]; 44 | double COW_RAD=0.5; 45 | Rand rng=new Rand(); 46 | OpenGL2DWindow win; 47 | 48 | public ChemotaxisModel(int x, int y) { 49 | super(x,y,SphericalCow.class); 50 | grass=new PDEGrid2D(x,y); 51 | grass.SetAll(1); 52 | grass.Update(); 53 | win=new OpenGL2DWindow(500,500,x,y); 54 | } 55 | public void GrowGrass(){ 56 | for (int i = 0; i < grass.length; i++) { 57 | grass.Add(i,GROW_RATE); 58 | } 59 | grass.Update(); 60 | for (int i = 0; i < grass.length; i++) { 61 | if(grass.Get(i)>1){ 62 | grass.Set(i,1); 63 | } 64 | } 65 | grass.Update(); 66 | } 67 | public void Draw(){ 68 | for (int i = 0; i < grass.length; i++) { 69 | win.SetPix(i,Util.RGB(0,grass.Get(i)/2,0)); 70 | } 71 | for (SphericalCow cow : this) { 72 | win.Circle(cow.Xpt(),cow.Ypt(),cow.radius,Util.WHITE); 73 | } 74 | win.Update(); 75 | } 76 | 77 | public static void main(String[] args) { 78 | OpenGL2DWindow.MakeMacCompatible(args); 79 | ChemotaxisModel m=new ChemotaxisModel(200,200); 80 | for (int i = 0; i < 500; i++) { 81 | m.NewAgentSQ(m.rng.Int(m.length)).radius=m.COW_RAD; 82 | } 83 | while(!m.win.IsClosed()){ 84 | for (SphericalCow cow : m) { 85 | cow.Step(); 86 | } 87 | m.GrowGrass(); 88 | m.Draw(); 89 | m.win.TickPause(0); 90 | } 91 | m.win.Close(); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /Examples/ColorBarGenerator/ColorBarGenerator.java: -------------------------------------------------------------------------------- 1 | package Examples.ColorBarGenerator; 2 | 3 | import HAL.Gui.*; 4 | import HAL.Util; 5 | 6 | public class ColorBarGenerator{ 7 | static final int TICKS_EXTRA_SPACE=8*4+2; 8 | 9 | public static void main(String[] args){ 10 | UIWindow win=new UIWindow(); 11 | win.AddCol(0,new UIIntInput("width",5,0,100)); 12 | win.AddCol(0,new UIIntInput("height",50,1,1000)); 13 | win.AddCol(0,new UIIntInput("scalefactor",2,1,10)); 14 | win.AddCol(0,new UIDoubleInput("min",0.0,-Double.MAX_VALUE,Double.MAX_VALUE)); 15 | win.AddCol(0,new UIDoubleInput("max",1.0,-Double.MAX_VALUE,Double.MAX_VALUE)); 16 | win.AddCol(0,new UIIntInput("ticks",2,2,1000)); 17 | win.AddCol(0,new UIComboBoxInput("color function",0,new String[]{"HeatMapRGB","HeatMapRBG","HeatMapGRB","HeatMapGBR","HeatMapBRG","HeatMapBGR","HeatMapJet","GreyScale"})); 18 | win.AddCol(0,new UIButton("Show",true,(e)->{ 19 | double min=win.GetDouble("min"); 20 | double max=win.GetDouble("max"); 21 | GridWindow draw=new GridWindow(win.GetInt("width")+TICKS_EXTRA_SPACE,win.GetInt("height"),win.GetInt("scalefactor"),false,null); 22 | Util.DrawColorBar(draw,0,0,win.GetInt("width"),win.GetInt("height"),win.GetDouble("min"),win.GetDouble("max"),win.GetInt("ticks"),(double in)->{ 23 | switch(win.GetInt("color function")){ 24 | case 0: return Util.HeatMapRGB(in,min,max); 25 | case 1: return Util.HeatMapRBG(in,min,max); 26 | case 2: return Util.HeatMapGRB(in,min,max); 27 | case 3: return Util.HeatMapGBR(in,min,max); 28 | case 4: return Util.HeatMapBRG(in,min,max); 29 | case 5: return Util.HeatMapBGR(in,min,max); 30 | case 6: return Util.HeatMapJet(in,min,max); 31 | case 7: return Util.GreyScale(in,min,max); 32 | default: return Util.WHITE; 33 | } 34 | }); 35 | })); 36 | win.RunGui(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Examples/GameOfLife/GOLSweepEx.java: -------------------------------------------------------------------------------- 1 | package Examples.GameOfLife; 2 | import HAL.Rand; 3 | import HAL.Tools.FileIO; 4 | import HAL.Util; 5 | 6 | import java.util.ArrayList; 7 | 8 | import static HAL.Util.*; 9 | 10 | /** 11 | * Created by mark on 7/7/17. 12 | */ 13 | class ReturnVals{ 14 | //this object will hold the results of each run 15 | int[] pops; 16 | double startLivingProb; 17 | ReturnVals(int timeSteps,double startLivingProb){ 18 | pops=new int[timeSteps]; 19 | this.startLivingProb=startLivingProb; 20 | } 21 | } 22 | 23 | public class GOLSweepEx { 24 | public static void main(String[] args) { 25 | int nRuns=100; 26 | ArrayListrunOutputs=new ArrayList<>(nRuns); 27 | for (int i = 0; i < nRuns; i++) { 28 | runOutputs.add(null); 29 | } 30 | MultiThread(nRuns,8,(iThread)->{ 31 | Rand rng=new Rand(); 32 | //the function that will run in parallel is specified here 33 | System.out.println("Started Thread:"+iThread); 34 | double startLivingProb=rng.Double(); 35 | int runTicks=1000; 36 | GOLGrid model=new GOLGrid(100,100,startLivingProb,runTicks,0,null); 37 | double[]ret=new double[runTicks+1]; 38 | ret[0]=startLivingProb; 39 | for (int i = 0; i < runTicks; i++) { 40 | model.StepAgents(); 41 | ret[i+1]=model.liveCt; 42 | } 43 | System.out.println("Finished Thread:"+iThread); 44 | runOutputs.set(iThread,ret); 45 | }); 46 | //after all runs finish, we loop through the array of ReturnVals objects and write out their data 47 | FileIO out=new FileIO("SweepResults.csv","w"); 48 | out.Write("startProp,popAtEachStep\n"); 49 | for (double[] ret : runOutputs) { 50 | out.Write(Util.ArrToString(ret,",")+"\n");//first entry is the starting prob of living cells 51 | } 52 | out.Close(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Examples/GasPopulationGrid/Gas.java: -------------------------------------------------------------------------------- 1 | package Examples.GasPopulationGrid; 2 | 3 | 4 | import HAL.GridsAndAgents.AgentGrid2D; 5 | import HAL.GridsAndAgents.AgentPT2D; 6 | import HAL.Gui.GridWindow; 7 | import HAL.Rand; 8 | 9 | import static HAL.Util.HeatMapRGB; 10 | 11 | class Particle extends AgentPT2D { 12 | public void BrownianMotion(){ 13 | //loads moveCoords with a random x,y pair 14 | G.rng.RandomPointInCircle(0.5, G.moveCoords); 15 | //displaces the particle, particle will not move if movement would cause it to move out of the grid 16 | MoveSafePT(Xpt()+ G.moveCoords[0],Ypt()+ G.moveCoords[1]); 17 | } 18 | } 19 | 20 | public class Gas extends AgentGrid2D { 21 | Rand rng=new Rand(); 22 | double moveRad=50; 23 | double[]moveCoords=new double[2]; 24 | double displayColorMax=1; 25 | public GridWindow display; 26 | public Gas(int x, int y) { 27 | super(x, y, Particle.class); 28 | display=new GridWindow("density",xDim,yDim,5); 29 | } 30 | public void Draw(){ 31 | for (int i = 0; i < length; i++) { 32 | //sets each pixel of the display based on the density at the same model grid index 33 | //0 cells will be colored black, 4 or more cells will be colored white 34 | display.SetPix(i,HeatMapRGB(PopAt(i),0,4)); 35 | } 36 | } 37 | public static void main(String[] args) { 38 | Gas gas=new Gas(100,100); 39 | for (int i = 0; i < 10000; i++) { 40 | gas.NewAgentPT(gas.xDim/2,gas.yDim/2); 41 | } 42 | for (int i = 0; i < 100000; i++) { 43 | gas.display.TickPause(0); 44 | for (Particle particle : gas) { 45 | particle.BrownianMotion(); 46 | } 47 | gas.Draw(); 48 | if(i%10000==0){ 49 | gas.display.ToPNG("gas"+i+".png"); 50 | } 51 | } 52 | gas.display.Close(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Examples/MultiwellOutbreak/MultiOutbreak.java: -------------------------------------------------------------------------------- 1 | package Examples.MultiwellOutbreak; 2 | import HAL.Tools.MultiWellExperiment.MultiWellExperiment; 3 | 4 | import static HAL.Util.*; 5 | 6 | public class MultiOutbreak { 7 | 8 | // used for "StepFn" argument of MultiWellExperiment 9 | // - arguments: model, well index 10 | // - update the model argument for one timestep. 11 | public static void StepModel(OutbreakWorld model,int iWell){ 12 | model.StepCells(); 13 | } 14 | 15 | // used for "ColorFn" argument of MultiWellExperiment 16 | // - arguments: model, x, and y 17 | // - used to set one pixel of the visualization. 18 | public static int DrawModel(OutbreakWorld model,int x,int y){ 19 | Person c = model.GetAgent(x,y); 20 | return OutbreakWorld.ReturnColor(c.type); 21 | } 22 | public static void main(String[] args){ 23 | 24 | 25 | // how many model simulations would you like to run? 26 | int x_dimension = 7; 27 | int y_dimension = 3; 28 | 29 | OutbreakWorld[] models=new OutbreakWorld[x_dimension*y_dimension]; 30 | 31 | // set up all models 32 | for (int row = 0; row < x_dimension; row++) { 33 | for (int col = 0; col < y_dimension; col++) { 34 | 35 | OutbreakWorld model = new OutbreakWorld(); 36 | 37 | model.QUARANTINE_RATE_SYMPTOMATIC = ((double) row / 20.0); 38 | model.QUARANTINE_RATE_ASYMPTOMATIC = ((double) row / 20.0); 39 | 40 | models[row*y_dimension + col] = model; 41 | } 42 | } 43 | 44 | MultiWellExperiment expt=new MultiWellExperiment<>(x_dimension,y_dimension,models,models[0].DIMENSION,models[0].DIMENSION, 1, WHITE, MultiOutbreak::StepModel, MultiOutbreak::DrawModel); 45 | expt.RunGIF(80, "multi_world_outbreak.gif",4,false); 46 | } 47 | } 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /Examples/MultiwellOutbreak/Person.java: -------------------------------------------------------------------------------- 1 | package Examples.MultiwellOutbreak; 2 | 3 | import HAL.GridsAndAgents.AgentSQ2Dunstackable; 4 | 5 | //cells grow and mutate 6 | class Person extends AgentSQ2Dunstackable{ 7 | 8 | public final static int SUSCEPTIBLE = 0; 9 | public final static int DEAD = 1; 10 | public final static int RECOVERED = 2; 11 | public final static int ASYMPTOMATIC_INFECTED = 3; 12 | public final static int SYMPTOMATIC_INFECTED = 4; 13 | 14 | // cell attributes: type; future_type; fitness 15 | int type; 16 | int future_type; 17 | boolean quarantined; 18 | 19 | // count-down timers until next state: 20 | int day_counter; 21 | 22 | 23 | public void Init(int type) { 24 | this.type = type; 25 | this.future_type = type; 26 | this.quarantined = false; 27 | this.day_counter = 0; 28 | G.counts[type]++; 29 | } 30 | 31 | void IncrementCounters() { 32 | day_counter++; 33 | 34 | if ((this.type == ASYMPTOMATIC_INFECTED) && (day_counter >= G.TIME_UNTIL_SYMPTOMATIC)) { 35 | this.future_type = SYMPTOMATIC_INFECTED; 36 | day_counter = 0; 37 | } 38 | if ((this.type == SYMPTOMATIC_INFECTED) && (day_counter >= G.TIME_UNTIL_RECOVERED)) { 39 | this.future_type = RECOVERED; 40 | day_counter = 0; 41 | } 42 | } 43 | 44 | // assumes you are infected, checks neighborhood to see if you infect someone else 45 | void InfectOthers() { 46 | double infection_rate = G.TRANSMISSION; 47 | int nNeighbors = this.MapOccupiedHood(G.hood); 48 | 49 | for (int i = 0; i < G.ENCOUNTERS_PER_DAY; i++) { 50 | Person thisNeighbor = G.GetAgent(G.hood[G.rn.Int(nNeighbors)]); // random neighbor in hood 51 | if ((thisNeighbor.type == SUSCEPTIBLE) && (!thisNeighbor.quarantined)) { 52 | if ((G.rn.Double() < infection_rate)) { 53 | thisNeighbor.future_type = Person.ASYMPTOMATIC_INFECTED; 54 | } 55 | } 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /Examples/ODEmodel/TumorGrowth.java: -------------------------------------------------------------------------------- 1 | package Examples.ODEmodel; 2 | 3 | import HAL.Gui.PlotLine; 4 | import HAL.Gui.PlotWindow; 5 | import HAL.Tools.ODESolver.ODESolver; 6 | 7 | import java.util.ArrayList; 8 | 9 | import static HAL.Util.BLUE; 10 | import static HAL.Util.GREEN; 11 | 12 | public class TumorGrowth { 13 | public final double tumorGrowthRate; 14 | public final double immuneDeathRate; 15 | public final double immuneKillTumorRate; 16 | public final double immuneRecrutimentRate; 17 | 18 | public final static int TUMOR=0,IMMUNE=1; 19 | 20 | public TumorGrowth(double tumorGrowthRate, double immuneDeathRate, double immuneKillTumorRate, double immuneRecrutimentRate) { 21 | this.tumorGrowthRate = tumorGrowthRate; 22 | this.immuneDeathRate = immuneDeathRate; 23 | this.immuneKillTumorRate = immuneKillTumorRate; 24 | this.immuneRecrutimentRate = immuneRecrutimentRate; 25 | } 26 | 27 | public void PopulationDerivatives(double t,double[]pops,double[]deltas){ 28 | //tumor update 29 | deltas[TUMOR]=tumorGrowthRate*pops[TUMOR]-immuneKillTumorRate*pops[TUMOR]*pops[IMMUNE]; 30 | deltas[IMMUNE]=-immuneDeathRate*pops[IMMUNE]+immuneRecrutimentRate*pops[TUMOR]*pops[IMMUNE]; 31 | } 32 | 33 | public static void main(String[] args) { 34 | TumorGrowth model=new TumorGrowth(Math.sqrt(2),0.5,0.001,0.001); 35 | double[]startPops=new double[]{100,10}; 36 | ArrayList states=new ArrayList<>(); 37 | states.add(startPops); 38 | ArrayList ts=new ArrayList<>(); 39 | ts.add(0.0); 40 | PlotWindow win=new PlotWindow("Tumor Immune Example",250,250,4,0,0,1,1); 41 | PlotLine tumorLine=new PlotLine(win,GREEN); 42 | PlotLine immuneLine=new PlotLine(win,BLUE); 43 | ODESolver solver=new ODESolver(); 44 | double dtStart=0.001; 45 | double errorTol=0.001; 46 | solver.Runge45(model::PopulationDerivatives,states,ts,10,dtStart,errorTol,0); 47 | for (int i = 0; i < states.size(); i++) { 48 | tumorLine.AddSegment(ts.get(i),states.get(i)[0]); 49 | immuneLine.AddSegment(ts.get(i),states.get(i)[1]); 50 | win.TickPause(100); 51 | } 52 | win.DrawAxesLabels(); 53 | win.ToPNG("TumorImmuneModel.png"); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Examples/Template_Models/TemplateMultiGrid.java: -------------------------------------------------------------------------------- 1 | package Examples.Template_Models; 2 | 3 | import HAL.GridsAndAgents.*; 4 | import HAL.Gui.OpenGL3DWindow; 5 | import HAL.Rand; 6 | import HAL.Util; 7 | 8 | class CellType1 extends AgentSQ3D { 9 | int exampleProperty; 10 | 11 | } 12 | class CellType2 extends SphericalAgent3D> { 13 | int exampleProperty; 14 | 15 | } 16 | 17 | public class TemplateMultiGrid { 18 | AgentGrid3D cells1; 19 | AgentGrid3D cells2; 20 | PDEGrid3D pde; 21 | OpenGL3DWindow win; 22 | Rand rng=new Rand(); 23 | int[]hood=Util.VonNeumannHood3D(false); 24 | 25 | public TemplateMultiGrid(int x,int y, int z){ 26 | cells1=new AgentGrid3D<>(x,y,z,CellType1.class); 27 | cells2=new AgentGrid3D<>(x,y,z,CellType2.class); 28 | pde=new PDEGrid3D(x,y,z); 29 | win=new OpenGL3DWindow(500,500,x,y,z); 30 | } 31 | public void StepAll() { 32 | for (CellType1 c1 : cells1) { 33 | c1.exampleProperty = Util.RGB(rng.Double(), rng.Double(), rng.Double()); 34 | c1.MoveSQ(hood[rng.Int(c1.MapHood(hood))]); 35 | } 36 | for (CellType2 c2 : cells2) { 37 | c2.exampleProperty = Util.RGB(rng.Double(), rng.Double(), rng.Double()); 38 | c2.radius = rng.Double(); 39 | c2.xVel += rng.Double(2) - 1; 40 | c2.yVel += rng.Double(2) - 1; 41 | c2.zVel += rng.Double(2) - 1; 42 | c2.ForceMove(); 43 | c2.ApplyFriction(0.0); 44 | } 45 | pde.Diffusion(0.1, (x, y, z) -> { 46 | if (x < 0) { 47 | return 1.0; 48 | } else { 49 | return 0.0; 50 | } 51 | }); 52 | pde.Update(); 53 | 54 | } 55 | public void DrawAll(){ 56 | win.ClearBox(Util.BLACK,Util.WHITE); 57 | for (int x=0;x { 10 | int exampleProperty; 11 | 12 | void ExampleFunction(){ 13 | this.exampleProperty=Util.RGB(G.rng.Double(),G.rng.Double(),G.rng.Double()); 14 | this.radius=G.rng.Double(); 15 | this.xVel+=G.rng.Double(2)-1; 16 | this.yVel+=G.rng.Double(2)-1; 17 | this.ForceMove(); 18 | this.ApplyFriction(0.0); 19 | } 20 | } 21 | 22 | public class TemplateOffLattice2D extends AgentGrid2D { 23 | Rand rng=new Rand(); 24 | 25 | public TemplateOffLattice2D(int x, int y) { 26 | super(x, y, TemplateOffLatticeCell.class); 27 | } 28 | 29 | public static void main(String[]args){ 30 | OpenGL2DWindow.MakeMacCompatible(args); 31 | TemplateOffLattice2D grid=new TemplateOffLattice2D(11,11); 32 | OpenGL2DWindow vis=new OpenGL2DWindow(500,500,11,11); 33 | 34 | grid.NewAgentPT(grid.xDim/2.0,grid.yDim/2.0); 35 | 36 | while(true){ 37 | for (TemplateOffLatticeCell cell : grid) { 38 | cell.ExampleFunction(); 39 | } 40 | vis.Clear(Util.BLACK); 41 | for (TemplateOffLatticeCell cell : grid) { 42 | vis.Circle(cell.Xpt(),cell.Ypt(),cell.radius,cell.exampleProperty); 43 | } 44 | vis.Update(); 45 | vis.TickPause(1000); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Examples/Template_Models/TemplateOnLattice2D.java: -------------------------------------------------------------------------------- 1 | package Examples.Template_Models; 2 | 3 | import HAL.GridsAndAgents.AgentGrid2D; 4 | import HAL.GridsAndAgents.AgentSQ2D; 5 | import HAL.Gui.GridWindow; 6 | import HAL.Rand; 7 | import HAL.Util; 8 | 9 | class TemplateOnLatticeCell extends AgentSQ2D { 10 | int exampleProperty; 11 | 12 | void ExampleFunction(){ 13 | this.exampleProperty=Util.RGB(G.rng.Double(),G.rng.Double(),G.rng.Double()); 14 | this.MoveSQ(G.hood[G.rng.Int(MapHood(G.hood))]); 15 | } 16 | } 17 | 18 | class TemplateOnLattice2D extends AgentGrid2D { 19 | Rand rng=new Rand(); 20 | int[]hood=Util.VonNeumannHood(false); 21 | 22 | public TemplateOnLattice2D(int x, int y) { 23 | super(x, y, TemplateOnLatticeCell.class); 24 | } 25 | 26 | public static void main(String[]args){ 27 | TemplateOnLattice2D grid=new TemplateOnLattice2D(11,11); 28 | GridWindow vis=new GridWindow(11,11,50); 29 | 30 | grid.NewAgentSQ(grid.xDim/2,grid.yDim/2); 31 | 32 | while(true){ 33 | for (TemplateOnLatticeCell cell : grid) { 34 | cell.ExampleFunction(); 35 | } 36 | 37 | for (int i=0;i{ 16 | int type; 17 | void Init(int type){ 18 | this.type=type; 19 | } 20 | void Reaction(){ 21 | G.diff.Set(Isq(),type==PDEexample.SRC?1:0);//set the local concentration to 1 if source, 0 if sink 22 | } 23 | } 24 | 25 | public class PDEexample extends AgentGrid2D { 26 | public static int SRC=RGB(0,1,0),SINK=RGB(0,1,1); 27 | PDEGrid2D diff; 28 | Rand rn=new Rand(); 29 | public PDEexample(int x, int y) { 30 | super(x, y, SrcOrSink.class,true,true); 31 | diff=new PDEGrid2D(x,y);//we add a PDEGrid to store the concentration of our diffusible 32 | } 33 | public void Setup(int nSinks,int sinkDist){ 34 | for (int x = xDim/2; x < xDim/2+3; x++) { 35 | for (int y = yDim/2; y < yDim/2+3; y++) { 36 | NewAgentSQ(x, y).Init(SRC);//create source 37 | } 38 | } 39 | int[]sinkIs= Util.GenIndicesArray(length); 40 | rn.Shuffle(sinkIs); 41 | int sinksPlaced=0; 42 | for (int i = 0; i < sinkIs.length; i++) { 43 | int sinkI=sinkIs[i]; 44 | if(DistSquared(ItoX(sinkI),ItoY(sinkI),xDim/2,yDim/2)>sinkDist*sinkDist){ 45 | NewAgentSQ(sinkI).Init(SINK);//create sink 46 | sinksPlaced++; 47 | if(sinksPlaced==nSinks){ 48 | //IncTick(); //IncTick called to make sources and sinks appear during iteration 49 | return; 50 | } 51 | } 52 | } 53 | //IncTick();//in case we never place enough sinks, we still call IncTick to make sure they appear during iteration 54 | } 55 | public void Step(int stepI){ 56 | double advectionX=Math.sin(stepI*1.0/1000)*0.2;//sine and cosine based on timestep cause circular advection 57 | double advectionY=Math.cos(stepI*1.0/1000)*0.2; 58 | for (SrcOrSink srcOrSink : this) { 59 | srcOrSink.Reaction(); 60 | } 61 | diff.Advection(advectionX,advectionY,0); 62 | double drate=(Math.sin(stepI*1.0/250)+1)*0.05; 63 | diff.Diffusion(drate); 64 | diff.Update(); 65 | } 66 | public void Draw(UIGrid visSrcSinks, UIGrid visDiff){ 67 | for (SrcOrSink srcOrSink : this) { 68 | visSrcSinks.SetPix(srcOrSink.Isq(),srcOrSink.type);//draw sources and sinks 69 | } 70 | for (int i = 0; i < length; i++) {//length of the Grid 71 | //visDiff.SetPix(i,SetAlpha(HeatMapRGB(diff.Get(i)*4),diff.Get(i)*4)); 72 | visDiff.SetPix(i,HeatMapRGB(diff.Get(i)*4)); 73 | } 74 | } 75 | 76 | public static void main(String[] args) { 77 | int x=400,y=400,scale=2; 78 | GridWindow visCells=new GridWindow(x,y,scale,true,null,false); 79 | GridWindow visDiff=new GridWindow(x,y,scale); 80 | //visCells.AddAlphaGrid(visDiff);//facilitates alpha blending 81 | PDEexample ex=new PDEexample(x,y); 82 | ex.Setup(100,10); 83 | int i=0; 84 | while(true){ 85 | visCells.TickPause(100);//slows down simulation for presentation 86 | ex.Step(i); 87 | ex.Draw(visCells,visDiff); 88 | i++; 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /FrameworkPresentation.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/FrameworkPresentation.pdf -------------------------------------------------------------------------------- /HAL/GridsAndAgents/Agent0D.java: -------------------------------------------------------------------------------- 1 | package HAL.GridsAndAgents; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * An agent type without any spatial representation 7 | */ 8 | abstract public class Agent0D extends AgentBase implements Serializable { 9 | 10 | /** 11 | * deletes the agent 12 | */ 13 | public void Dispose() { 14 | //kills agent 15 | G.RemoveAgent(this); 16 | if (myNodes != null) { 17 | myNodes.DisposeAll(); 18 | } 19 | } 20 | 21 | /** 22 | * returns the age of the agent, in ticks. Be sure to use IncTick on the AgentGrid appropriately for this function 23 | * to work. 24 | */ 25 | public int Age() { 26 | return birthTick - G.GetTick(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /HAL/GridsAndAgents/AgentBase.java: -------------------------------------------------------------------------------- 1 | package HAL.GridsAndAgents; 2 | 3 | import HAL.GridsAndAgents.AgentListNode; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * AgentBase functions are shared amongst all agent types 9 | */ 10 | public abstract class AgentBase implements Serializable{ 11 | long stateID; 12 | int iList; 13 | int birthTick; 14 | boolean alive; 15 | /** 16 | * returns the grid that the agent belongs to (this is a permanent agent property, not a function) 17 | */ 18 | public final T G; 19 | AgentListNode myNodes; 20 | 21 | public AgentBase(){ 22 | G=null; 23 | } 24 | 25 | /** 26 | * Returns whether the agent is alive or has been disposed 27 | */ 28 | public boolean IsAlive(){ 29 | return alive; 30 | } 31 | 32 | /** 33 | * returns the tick on which the agent was born 34 | */ 35 | 36 | public int BirthTick(){ 37 | return birthTick; 38 | } 39 | 40 | /** 41 | * sets the agent's birthtick value, which is used for the Age calculation 42 | */ 43 | public void SetBirthTick(int tick){ 44 | this.birthTick=tick; 45 | } 46 | 47 | /** 48 | * returns the age of the agent, in ticks. Be sure to use IncTick on the AgentGrid appropriately for this function to work. 49 | */ 50 | abstract public int Age(); 51 | 52 | /** 53 | * removes the agent from the grid 54 | */ 55 | abstract public void Dispose(); 56 | 57 | } 58 | -------------------------------------------------------------------------------- /HAL/GridsAndAgents/AgentBaseSpatial.java: -------------------------------------------------------------------------------- 1 | package HAL.GridsAndAgents; 2 | 3 | import HAL.Interfaces.AgentToBool; 4 | 5 | import java.io.Serializable; 6 | import java.util.ArrayList; 7 | 8 | /** 9 | * AgentBaseSpatial functions are shared amongst all spatial agent types 10 | */ 11 | public abstract class AgentBaseSpatial extends AgentBase implements Serializable { 12 | int iSq; 13 | 14 | /** 15 | * returns the index of the square that the agent is currently on 16 | */ 17 | public int Isq() { 18 | return iSq; 19 | } 20 | 21 | /** 22 | * moves the agent to the middle of the square at the indices/index specified 23 | */ 24 | abstract public void MoveSQ(int iNext); 25 | 26 | abstract void Setup(double i); 27 | 28 | abstract void Setup(double x, double y); 29 | 30 | abstract void Setup(double x, double y, double z); 31 | 32 | abstract void Setup(int i); 33 | 34 | abstract void Setup(int x, int y); 35 | 36 | abstract void Setup(int x, int y, int z); 37 | 38 | abstract void RemSQ(); 39 | 40 | abstract void AddSQ(int iNext); 41 | 42 | abstract void GetAllOnSquare(ArrayList putHere); 43 | 44 | abstract int GetCountOnSquare(); 45 | 46 | abstract int GetCountOnSquare(AgentToBool evalAgent); 47 | 48 | abstract void GetAllOnSquare(ArrayList putHere, AgentToBool evalAgent); 49 | } 50 | -------------------------------------------------------------------------------- /HAL/GridsAndAgents/Grid1Dobject.java: -------------------------------------------------------------------------------- 1 | package HAL.GridsAndAgents; 2 | 3 | import HAL.Interfaces.Grid1D; 4 | 5 | import java.io.Serializable; 6 | import java.util.Arrays; 7 | 8 | /** 9 | * a 1D Grid of objects 10 | */ 11 | public class Grid1Dobject implements Grid1D,Serializable { 12 | final public int xDim; 13 | final public int length; 14 | public boolean wrapX; 15 | final public T[] field; 16 | 17 | /** 18 | * creates a new Grid1Dobject of length xDim wtihout wraparound 19 | */ 20 | public Grid1Dobject(int xDim) { 21 | this.xDim=xDim; 22 | this.length=xDim; 23 | this.wrapX=false; 24 | field = (T[]) (new Object[this.xDim]); 25 | } 26 | 27 | /** 28 | * creates a new Grid1Ddouble of length xDim with optional wraparound 29 | */ 30 | public Grid1Dobject(int xDim, boolean wrapX) { 31 | this(xDim); 32 | this.wrapX=wrapX; 33 | } 34 | 35 | /** 36 | * gets the current field value at the specified index 37 | */ 38 | public T Get(int x) { 39 | return field[x]; 40 | } 41 | 42 | public T[] GetField() { 43 | return this.field; 44 | } 45 | 46 | /** 47 | * sets the current field value at the specified index 48 | */ 49 | public void Set(int x, T val) { 50 | field[x] = val; 51 | } 52 | 53 | 54 | /** 55 | * sets all squares in current the field to the specified value 56 | */ 57 | public void SetAll(T val) { 58 | Arrays.fill(field, val); 59 | } 60 | 61 | @Override 62 | public int Xdim() { 63 | return 0; 64 | } 65 | 66 | @Override 67 | public int Length() { 68 | return 0; 69 | } 70 | 71 | @Override 72 | public boolean IsWrapX() { 73 | return false; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /HAL/GridsAndAgents/Grid2Dobject.java: -------------------------------------------------------------------------------- 1 | package HAL.GridsAndAgents; 2 | 3 | import HAL.Interfaces.Grid2D; 4 | 5 | import java.io.Serializable; 6 | import java.util.Arrays; 7 | 8 | /** 9 | * a 2D Grid of objects 10 | */ 11 | public class Grid2Dobject implements Grid2D,Serializable{ 12 | final public int xDim; 13 | final public int yDim; 14 | final public int length; 15 | public boolean wrapX; 16 | public boolean wrapY; 17 | final public T[] field; 18 | 19 | /** 20 | * creates a new Grid2Dobject of dimensions xDim by yDim without wraparound 21 | */ 22 | public Grid2Dobject(int xDim, int yDim){ 23 | this(xDim,yDim,false,false); 24 | } 25 | 26 | /** 27 | * creates a new Grid2Dobject of dimensions xDim by yDim with optional wraparound 28 | */ 29 | public Grid2Dobject(int xDim, int yDim, boolean wrapX, boolean wrapY){ 30 | this.xDim=xDim; 31 | this.yDim=yDim; 32 | this.length=xDim*yDim; 33 | this.wrapX=wrapX; 34 | this.wrapY=wrapY; 35 | field =(T[])new Object[this.xDim * this.yDim]; 36 | } 37 | /** 38 | * gets the current field value at the specified index 39 | */ 40 | public T Get(int i){return field[i];} 41 | public T[] GetField(){ 42 | return this.field; 43 | } 44 | /** 45 | * gets the current field value at the specified coordinates 46 | */ 47 | public T Get(int x, int y) { return field[x*yDim+y]; } 48 | 49 | /** 50 | * sets the current field value at the specified index 51 | */ 52 | public void Set(int i, T val){ 53 | field[i]=val;} 54 | 55 | /** 56 | * sets the current field value at the specified coordinates 57 | */ 58 | public void Set(int x, int y, T val){ field[x*yDim+y]=val; } 59 | 60 | /** 61 | * sets all squares in the field to the specified value 62 | */ 63 | public void SetAll(T val){ 64 | Arrays.fill(field,val); 65 | } 66 | 67 | /** 68 | * copies the array of values into the field 69 | */ 70 | public void SetAll(T[]vals){ 71 | System.arraycopy(vals,0, field,0,length); 72 | } 73 | 74 | @Override 75 | public int Xdim() { 76 | return xDim; 77 | } 78 | 79 | @Override 80 | public int Ydim() { 81 | return yDim; 82 | } 83 | 84 | @Override 85 | public int Length() { 86 | return length; 87 | } 88 | 89 | @Override 90 | public boolean IsWrapX() { 91 | return wrapX; 92 | } 93 | 94 | @Override 95 | public boolean IsWrapY() { 96 | return wrapY; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /HAL/GridsAndAgents/Grid3Dobject.java: -------------------------------------------------------------------------------- 1 | package HAL.GridsAndAgents; 2 | 3 | import HAL.Interfaces.Grid3D; 4 | 5 | import java.io.Serializable; 6 | import java.util.Arrays; 7 | 8 | /** 9 | * a 3D Grid of objects 10 | */ 11 | public class Grid3Dobject implements Grid3D,Serializable { 12 | public final int xDim; 13 | public final int yDim; 14 | public final int zDim; 15 | public final int length; 16 | public boolean wrapX; 17 | public boolean wrapY; 18 | public boolean wrapZ; 19 | final public T[] field; 20 | 21 | /** 22 | * creates a new Grid3Dobject of dimensions xDim by yDim by zDim without wraparound 23 | */ 24 | public Grid3Dobject(int xDim, int yDim, int zDim, boolean wrapX, boolean wrapY, boolean wrapZ) { 25 | this.xDim=xDim; 26 | this.yDim=yDim; 27 | this.zDim=zDim; 28 | this.length=xDim*yDim*zDim; 29 | this.wrapX=wrapX; 30 | this.wrapY=wrapY; 31 | this.wrapZ=wrapZ; 32 | field = (T[]) (new Object[length]); 33 | //middleField = new T[numElements]; 34 | } 35 | 36 | /** 37 | * creates a new Grid3Dojbect of dimensions xDim by yDim by zDim with optional wraparound 38 | */ 39 | public Grid3Dobject(int xDim, int yDim, int zDim) { 40 | this(xDim, yDim, zDim, false, false, false); 41 | } 42 | 43 | /** 44 | * gets the field value at the specified index 45 | */ 46 | public T Get(int i) { 47 | return field[i]; 48 | } 49 | 50 | /** 51 | * gets the field value at the specified coordinates 52 | */ 53 | public T Get(int x, int y, int z) { 54 | return field[x * yDim * zDim + y * zDim + z]; 55 | } 56 | 57 | /** 58 | * sets the current field value at the specified index 59 | */ 60 | public void Set(int i, T val) { 61 | field[i] = val; 62 | } 63 | 64 | /** 65 | * sets the current field value at the specified coordinates 66 | */ 67 | public void Set(int x, int y, int z, T val) { 68 | field[x * yDim * zDim + y * zDim + z] = val; 69 | } 70 | 71 | /** 72 | * returns the complete field as an array 73 | */ 74 | public T[] GetField() { 75 | return this.field; 76 | } 77 | 78 | /** 79 | * sets all squares in current the field to the specified value 80 | */ 81 | public void SetAll(T val) { 82 | Arrays.fill(field, val); 83 | } 84 | 85 | @Override 86 | public int Xdim() { 87 | return xDim; 88 | } 89 | 90 | @Override 91 | public int Ydim() { 92 | return yDim; 93 | } 94 | 95 | @Override 96 | public int Zdim() { 97 | return zDim; 98 | } 99 | 100 | @Override 101 | public int Length() { 102 | return length; 103 | } 104 | 105 | @Override 106 | public boolean IsWrapX() { 107 | return wrapX; 108 | } 109 | 110 | @Override 111 | public boolean IsWrapY() { 112 | return wrapY; 113 | } 114 | 115 | @Override 116 | public boolean IsWrapZ() { 117 | return wrapZ; 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /HAL/GridsAndAgents/KernelGrid.java: -------------------------------------------------------------------------------- 1 | package HAL.GridsAndAgents; 2 | 3 | import HAL.GridsAndAgents.Grid2Ddouble; 4 | import HAL.Interfaces.Coords2DDouble; 5 | import HAL.Interfaces.DoubleToDouble; 6 | import HAL.Interfaces.Grid2D; 7 | import HAL.Tools.Lenia.FFTGrid; 8 | 9 | public class KernelGrid implements Grid2D { 10 | private final FFTGrid fftKernel; 11 | private final FFTGrid fftField; 12 | public final Grid2Ddouble out; 13 | public final int xDim,yDim,length; 14 | //Kernel must hav the same dimensions as the domain that will be convolved with it! 15 | public KernelGrid(Grid2Ddouble kernel) { 16 | if (kernel.xDim != kernel.yDim || (kernel.xDim & kernel.xDim - 1) != 0) { 17 | throw new IllegalArgumentException("Kernel must have equal xDim and yDim, and xDim, yDim must be powers of 2"); 18 | } 19 | this.fftKernel=new FFTGrid(kernel.xDim,kernel.yDim); 20 | this.fftField=new FFTGrid(kernel.xDim,kernel.yDim); 21 | this.xDim=kernel.xDim; 22 | this.yDim=kernel.yDim; 23 | this.length=kernel.length; 24 | fftKernel.SetGrid(kernel); 25 | fftKernel.fftshift(); 26 | fftKernel.fft2(); 27 | this.out = fftField.REAL; 28 | } 29 | private static Grid2Ddouble GenKernel(DoubleToDouble KernelGen, int sideLen,boolean sumToOne) { 30 | Grid2Ddouble out = new Grid2Ddouble(sideLen, sideLen); 31 | for (int x = 0; x < out.xDim; x++) { 32 | for (int y = 0; y < out.yDim; y++) { 33 | out.Set(x, y, KernelGen.Eval(out.Dist(x, y, out.xDim / 2.0, out.yDim / 2.0))); 34 | } 35 | } 36 | if (sumToOne) { 37 | double sum = 0; 38 | for (int i = 0; i { 39 | Diffusion1(ct, i, this, diffRate, xDim, wrapX, null, mn); 40 | }); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /HAL/GridsAndAgents/PopulationGrid1DLong.java: -------------------------------------------------------------------------------- 1 | package HAL.GridsAndAgents; 2 | 3 | import HAL.Interfaces.Grid1D; 4 | import HAL.Tools.MultinomialCalcLong; 5 | 6 | import static HAL.Tools.Internal.PopulationGridPDEequations.Diffusion1L; 7 | 8 | 9 | public class PopulationGrid1DLong extends PopulationGridLongBase implements Grid1D { 10 | public final int xDim; 11 | public final int length; 12 | public boolean wrapX; 13 | 14 | public PopulationGrid1DLong(int xDim, boolean wrapX) { 15 | super(xDim); 16 | this.xDim=xDim; 17 | this.length=xDim; 18 | this.wrapX=wrapX; 19 | } 20 | public PopulationGrid1DLong(int xDim) { 21 | this(xDim,false); 22 | } 23 | 24 | @Override 25 | public int Xdim() { 26 | return xDim; 27 | } 28 | 29 | @Override 30 | public int Length() { 31 | return length; 32 | } 33 | 34 | @Override 35 | public boolean IsWrapX() { 36 | return wrapX; 37 | } 38 | public void Diffusion(double diffRate, MultinomialCalcLong mn) { 39 | ApplyOccupied((i, ct) -> { 40 | Diffusion1L(ct, i, this, diffRate, xDim, wrapX, null, mn); 41 | }); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /HAL/GridsAndAgents/PopulationGrid2D.java: -------------------------------------------------------------------------------- 1 | package HAL.GridsAndAgents; 2 | 3 | import HAL.Interfaces.Grid2D; 4 | import HAL.Tools.MultinomialCalc; 5 | 6 | import static HAL.Tools.Internal.PopulationGridPDEequations.Diffusion2; 7 | 8 | public class PopulationGrid2D extends PopulationGridBase implements Grid2D{ 9 | public final int xDim; 10 | public final int yDim; 11 | public boolean wrapX; 12 | public boolean wrapY; 13 | 14 | public PopulationGrid2D(int xDim, int yDim, boolean wrapX, boolean wrapY) { 15 | super(xDim*yDim); 16 | this.xDim=xDim; 17 | this.yDim=yDim; 18 | this.wrapX=wrapX; 19 | this.wrapY=wrapY; 20 | } 21 | 22 | public PopulationGrid2D(int xDim, int yDim) { 23 | this(xDim,yDim,false,false); 24 | } 25 | public int Get(int x,int y){ 26 | return Get(I(x,y)); 27 | } 28 | public void Set(int x,int y,int val){ 29 | int i=I(x,y); 30 | Add(i,val-Get(i)); 31 | } 32 | public void Add(int x,int y,int val){ 33 | Add(I(x,y),val); 34 | } 35 | public void Move(int xFrom,int yFrom,int xTo,int yTo,int val){ 36 | Move(I(xFrom,yFrom),I(xTo,yTo),val); 37 | } 38 | public void Move(int xFrom,int yFrom,int xTo,int yTo,T gridTo,int val){ 39 | Move(I(xFrom,yFrom),I(xTo,yTo),gridTo,val); 40 | } 41 | 42 | @Override 43 | public int Xdim() { 44 | return xDim; 45 | } 46 | 47 | @Override 48 | public int Ydim() { 49 | return yDim; 50 | } 51 | 52 | @Override 53 | public int Length() { 54 | return length; 55 | } 56 | 57 | @Override 58 | public boolean IsWrapX() { 59 | return wrapX; 60 | } 61 | 62 | @Override 63 | public boolean IsWrapY() { 64 | return wrapY; 65 | } 66 | public void Diffusion(double diffRate,MultinomialCalc mn) { 67 | ApplyOccupied((i, ct) -> { 68 | Diffusion2(ct, ItoX(i), ItoY(i), i, this, diffRate, xDim, yDim, wrapX, wrapY, null, mn); 69 | }); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /HAL/GridsAndAgents/PopulationGrid2DLong.java: -------------------------------------------------------------------------------- 1 | package HAL.GridsAndAgents; 2 | 3 | import HAL.Interfaces.Grid2D; 4 | import HAL.Tools.MultinomialCalcLong; 5 | 6 | import static HAL.Tools.Internal.PopulationGridPDEequations.Diffusion2L; 7 | 8 | 9 | public class PopulationGrid2DLong extends PopulationGridLongBase implements Grid2D{ 10 | public final int xDim; 11 | public final int yDim; 12 | public boolean wrapX; 13 | public boolean wrapY; 14 | 15 | public PopulationGrid2DLong(int xDim, int yDim, boolean wrapX, boolean wrapY) { 16 | super(xDim*yDim); 17 | this.xDim=xDim; 18 | this.yDim=yDim; 19 | this.wrapX=wrapX; 20 | this.wrapY=wrapY; 21 | } 22 | 23 | public PopulationGrid2DLong(int xDim, int yDim) { 24 | this(xDim,yDim,false,false); 25 | } 26 | public long Get(int x,int y){ 27 | return Get(I(x,y)); 28 | } 29 | public void Set(int x,int y,long val){ 30 | int i=I(x,y); 31 | Add(i,val-Get(i)); 32 | } 33 | public void Add(int x,int y,long val){ 34 | Add(I(x,y),val); 35 | } 36 | public void Move(int xFrom,int yFrom,int xTo,int yTo,long val){ 37 | Move(I(xFrom,yFrom),I(xTo,yTo),val); 38 | } 39 | public void Move(int xFrom,int yFrom,int xTo,int yTo,T gridTo,int val){ 40 | Move(I(xFrom,yFrom),I(xTo,yTo),gridTo,val); 41 | } 42 | 43 | @Override 44 | public int Xdim() { 45 | return xDim; 46 | } 47 | 48 | @Override 49 | public int Ydim() { 50 | return yDim; 51 | } 52 | 53 | @Override 54 | public int Length() { 55 | return length; 56 | } 57 | 58 | @Override 59 | public boolean IsWrapX() { 60 | return wrapX; 61 | } 62 | 63 | @Override 64 | public boolean IsWrapY() { 65 | return wrapY; 66 | } 67 | public void Diffusion(double diffRate, MultinomialCalcLong mn) { 68 | ApplyOccupied((i, ct) -> { 69 | Diffusion2L(ct, ItoX(i), ItoY(i), i, this, diffRate, xDim, yDim, wrapX, wrapY, null, mn); 70 | }); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /HAL/GridsAndAgents/PopulationGrid3D.java: -------------------------------------------------------------------------------- 1 | package HAL.GridsAndAgents; 2 | 3 | import HAL.Interfaces.Grid3D; 4 | import HAL.Tools.MultinomialCalc; 5 | 6 | import static HAL.Tools.Internal.PopulationGridPDEequations.Diffusion3; 7 | 8 | public class PopulationGrid3D extends PopulationGridBase implements Grid3D{ 9 | public final int xDim; 10 | public final int yDim; 11 | public final int zDim; 12 | public boolean wrapX; 13 | public boolean wrapY; 14 | public boolean wrapZ; 15 | 16 | public PopulationGrid3D(int xDim, int yDim, int zDim, boolean wrapX, boolean wrapY, boolean wrapZ) { 17 | super(xDim*yDim*zDim); 18 | this.xDim=xDim; 19 | this.yDim=yDim; 20 | this.zDim=zDim; 21 | this.wrapX=wrapX; 22 | this.wrapY=wrapY; 23 | this.wrapZ=wrapZ; 24 | } 25 | public PopulationGrid3D(int xDim, int yDim, int zDim) { 26 | this(xDim,yDim,zDim,false,false,false); 27 | } 28 | 29 | public int Get(int x,int y,int z){ 30 | return Get(I(x,y,z)); 31 | } 32 | 33 | public void Add(int x,int y,int z,int val){ 34 | Add(I(x,y,z),val); 35 | } 36 | public void Set(int x,int y,int z,int val){ 37 | int i=I(x,y,z); 38 | Add(i,val-Get(i)); 39 | } 40 | public void Move(int xFrom,int yFrom,int zFrom,int xTo,int yTo,int zTo,int val){ 41 | Move(I(xFrom,yFrom,zFrom),I(xTo,yTo,zTo),val); 42 | } 43 | public void Move(int xFrom,int yFrom,int zFrom,int xTo,int yTo,int zTo,T gridTo,int val){ 44 | Move(I(xFrom,yFrom,zFrom),I(xTo,yTo,zTo),gridTo,val); 45 | } 46 | 47 | @Override 48 | public int Xdim() { 49 | return xDim; 50 | } 51 | 52 | @Override 53 | public int Ydim() { 54 | return yDim; 55 | } 56 | 57 | @Override 58 | public int Zdim() { 59 | return zDim; 60 | } 61 | 62 | @Override 63 | public int Length() { 64 | return length; 65 | } 66 | 67 | @Override 68 | public boolean IsWrapX() { 69 | return wrapX; 70 | } 71 | 72 | @Override 73 | public boolean IsWrapY() { 74 | return wrapY; 75 | } 76 | 77 | @Override 78 | public boolean IsWrapZ() { 79 | return wrapZ; 80 | } 81 | 82 | public void Diffusion(double diffRate,MultinomialCalc mn){ 83 | ApplyOccupied((i,ct)->{ 84 | Diffusion3(ct,ItoX(i),ItoY(i),ItoZ(i),i,this,diffRate,xDim,yDim,zDim,wrapX,wrapY,wrapZ,null,mn); 85 | }); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /HAL/GridsAndAgents/PopulationGrid3DLong.java: -------------------------------------------------------------------------------- 1 | package HAL.GridsAndAgents; 2 | 3 | import HAL.Interfaces.Grid3D; 4 | import HAL.Tools.MultinomialCalcLong; 5 | 6 | import static HAL.Tools.Internal.PopulationGridPDEequations.Diffusion3L; 7 | 8 | 9 | public class PopulationGrid3DLong extends PopulationGridLongBase implements Grid3D{ 10 | public final int xDim; 11 | public final int yDim; 12 | public final int zDim; 13 | public boolean wrapX; 14 | public boolean wrapY; 15 | public boolean wrapZ; 16 | 17 | public PopulationGrid3DLong(int xDim, int yDim, int zDim, boolean wrapX, boolean wrapY, boolean wrapZ) { 18 | super(xDim*yDim*zDim); 19 | this.xDim=xDim; 20 | this.yDim=yDim; 21 | this.zDim=zDim; 22 | this.wrapX=wrapX; 23 | this.wrapY=wrapY; 24 | this.wrapZ=wrapZ; 25 | } 26 | public PopulationGrid3DLong(int xDim, int yDim, int zDim) { 27 | this(xDim,yDim,zDim,false,false,false); 28 | } 29 | 30 | public long Get(int x,int y,int z){ 31 | return Get(I(x,y,z)); 32 | } 33 | 34 | public void Add(int x,int y,int z,long val){ 35 | Add(I(x,y,z),val); 36 | } 37 | public void Set(int x,int y,int z,long val){ 38 | int i=I(x,y,z); 39 | Add(i,val-Get(i)); 40 | } 41 | 42 | public void Move(int xFrom,int yFrom,int zFrom,int xTo,int yTo,int zTo,long val){ 43 | Move(I(xFrom,yFrom,zFrom),I(xTo,yTo,zTo),val); 44 | } 45 | public void Move(int xFrom,int yFrom,int zFrom,int xTo,int yTo,int zTo,T gridTo,int val){ 46 | Move(I(xFrom,yFrom,zFrom),I(xTo,yTo,zTo),gridTo,val); 47 | } 48 | 49 | 50 | @Override 51 | public int Xdim() { 52 | return xDim; 53 | } 54 | 55 | @Override 56 | public int Ydim() { 57 | return yDim; 58 | } 59 | 60 | @Override 61 | public int Zdim() { 62 | return zDim; 63 | } 64 | 65 | @Override 66 | public int Length() { 67 | return length; 68 | } 69 | 70 | @Override 71 | public boolean IsWrapX() { 72 | return wrapX; 73 | } 74 | 75 | @Override 76 | public boolean IsWrapY() { 77 | return wrapY; 78 | } 79 | 80 | @Override 81 | public boolean IsWrapZ() { 82 | return wrapZ; 83 | } 84 | 85 | public void Diffusion(double diffRate, MultinomialCalcLong mn){ 86 | ApplyOccupied((i,ct)->{ 87 | Diffusion3L(ct,ItoX(i),ItoY(i),ItoZ(i),i,this,diffRate,xDim,yDim,zDim,wrapX,wrapY,wrapZ,null,mn); 88 | }); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /HAL/Gui/PlotLine.java: -------------------------------------------------------------------------------- 1 | package HAL.Gui; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * this class is used to add segments one at a time to a PlotLine on a UIPlot/PlotWindow 7 | */ 8 | public class PlotLine implements Serializable{ 9 | int color; 10 | final UIPlot myPlot; 11 | PlotPointInternal last; 12 | PlotPointInternal first; 13 | int clearState; 14 | 15 | /** 16 | * establishes the UIPlot that will contain the PlotLine, and the color of the segment lines 17 | */ 18 | public PlotLine(UIPlot plot, int color){ 19 | this.myPlot=plot; 20 | this.color=color; 21 | this.clearState=myPlot.clearState; 22 | } 23 | 24 | /** 25 | * adds a segment to the current line, the color and pointHood are used to draw the point at the end of the segment 26 | */ 27 | public void AddSegment(double x,double y,int color,int[]pointHood){ 28 | if(myPlot.clearState>clearState){ 29 | last=null; 30 | first=null; 31 | clearState=myPlot.clearState; 32 | } 33 | PlotPointInternal pt=myPlot.GenPoint(x,y,color,pointHood); 34 | if(first==null){ 35 | first=pt; 36 | } 37 | if(last!=null) { 38 | pt.linePrev = last; 39 | } 40 | last=pt; 41 | myPlot.SetPoint(pt); 42 | } 43 | 44 | /** 45 | * adds a segment to the current line that will end at the specified coordinates 46 | */ 47 | public void AddSegment(double x,double y,int color){ 48 | AddSegment(x,y,color,null); 49 | } 50 | 51 | /** 52 | * adds a segment to the current line that will end at the specified coordinates 53 | */ 54 | public void AddSegment(double x,double y){ 55 | AddSegment(x,y,color,null); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /HAL/Gui/PlotPointInternal.java: -------------------------------------------------------------------------------- 1 | package HAL.Gui; 2 | 3 | import HAL.Util; 4 | 5 | import java.io.Serializable; 6 | 7 | // not meant to be used directly, created by the UIPlot object 8 | class PlotPointInternal implements Serializable{ 9 | int color; 10 | double x; 11 | double y; 12 | PlotPointInternal next; 13 | PlotPointInternal linePrev; 14 | final UIPlot win; 15 | int[]drawHood; 16 | public PlotPointInternal(double x, double y, int color, UIPlot win, int[]drawHood){ 17 | this.win=win; 18 | Init(x,y,color,drawHood); 19 | } 20 | 21 | public void Init(double x,double y, int color, int[]drawHood){ 22 | this.x=x; 23 | this.y=y; 24 | this.color=color; 25 | this.drawHood=drawHood; 26 | this.linePrev=null; 27 | this.next=null; 28 | 29 | } 30 | 31 | public void Draw(){ 32 | int middleX=(int) ((x - win.plotXstart) * win.plotScaleX); 33 | int middleY=(int) ((y - win.plotYstart) * win.plotScaleY); 34 | if(drawHood==null) { 35 | win.grid.SetPix(middleX,middleY, color); 36 | } 37 | else{ 38 | int nDraws=win.grid.MapHood(drawHood,middleX,middleY); 39 | for (int i = 0; i < nDraws; i++) { 40 | win.grid.SetPix(drawHood[i],color); 41 | } 42 | } 43 | if(linePrev!=null){ 44 | int middleXprev=(int) ((linePrev.x - win.plotXstart) * win.plotScaleX); 45 | int middleYprev=(int) ((linePrev.y - win.plotYstart) * win.plotScaleY); 46 | Util.AlongLineAction(middleX,middleY,middleXprev,middleYprev,(x,y)->{ 47 | win.grid.SetPix(x,y,color); 48 | }); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /HAL/Gui/TickTimer.java: -------------------------------------------------------------------------------- 1 | package HAL.Gui; 2 | 3 | /** 4 | * class used to impose a frame rate on the running of a model 5 | * call TickPause every timestep to impose a framerate 6 | * usually used within a window of some kind, but can also be used by itself 7 | * Created by rafael on 2/16/17. 8 | */ 9 | public class TickTimer { 10 | private long lastSleepTime; 11 | 12 | /** 13 | * pauses execution so that the amount of time between calls to TickPause is equal to millis 14 | * @param millis wait duration 15 | */ 16 | public void TickPause(int millis){ 17 | if (lastSleepTime == 0) { 18 | lastSleepTime = System.currentTimeMillis(); 19 | return; 20 | } 21 | long currTime=System.currentTimeMillis(); 22 | long waitTime=millis-(currTime-lastSleepTime); 23 | if(waitTime>0){ 24 | try { 25 | Thread.sleep(waitTime); 26 | } catch (InterruptedException e) { 27 | e.printStackTrace(); 28 | } 29 | } 30 | lastSleepTime=System.currentTimeMillis(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /HAL/Gui/UIGridView.java: -------------------------------------------------------------------------------- 1 | package HAL.Gui; 2 | 3 | 4 | import HAL.Interfaces.Grid2D; 5 | 6 | public class UIGridView extends UIGrid { 7 | UIGrid parent; 8 | int xStart; 9 | int yStart; 10 | public UIGridView(UIGrid parent, int xDim, int yDim, int xStart, int yStart){ 11 | super(xDim,yDim,1,false); 12 | this.parent=parent; 13 | this.xStart=xStart; 14 | this.yStart=yStart; 15 | } 16 | 17 | public void SetPix(int x,int y,int color) { 18 | if(In(x,y)) { 19 | parent.SetPix(x + xStart,y+yStart,color); 20 | } 21 | else{ 22 | throw new IllegalArgumentException(+x+","+y+" is outside the GridView dimensions: "+xDim+","+yDim ); 23 | } 24 | } 25 | 26 | public void SetPix(int i,int color){ 27 | SetPix(ItoX(i),ItoY(i),color); 28 | } 29 | 30 | // @Override 31 | // public int Xdim() { 32 | // return xDim; 33 | // } 34 | // 35 | // @Override 36 | // public int Ydim() { 37 | // return yDim; 38 | // } 39 | // 40 | // @Override 41 | // public int Length() { 42 | // return length; 43 | // } 44 | // 45 | // @Override 46 | // public boolean IsWrapX() { 47 | // return false; 48 | // } 49 | // 50 | // @Override 51 | // public boolean IsWrapY() { 52 | // return false; 53 | // } 54 | } 55 | -------------------------------------------------------------------------------- /HAL/Interfaces/AgentAction.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | import HAL.GridsAndAgents.AgentBase; 4 | 5 | @FunctionalInterface 6 | public interface AgentAction { 7 | void Action(T agent,int validCount); 8 | } 9 | -------------------------------------------------------------------------------- /HAL/Interfaces/AgentRadDispToAction1D.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | import HAL.GridsAndAgents.AgentBase; 4 | 5 | @FunctionalInterface 6 | public interface AgentRadDispToAction1D { 7 | void Action(T agent, double Xdisp, double distSq); 8 | } 9 | -------------------------------------------------------------------------------- /HAL/Interfaces/AgentRadDispToAction2D.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | import HAL.GridsAndAgents.AgentBase; 4 | 5 | @FunctionalInterface 6 | public interface AgentRadDispToAction2D { 7 | void Action(T agent,double Xdisp,double Ydisp,double distSq); 8 | } 9 | -------------------------------------------------------------------------------- /HAL/Interfaces/AgentRadDispToAction3D.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | import HAL.GridsAndAgents.AgentBase; 4 | 5 | @FunctionalInterface 6 | public interface AgentRadDispToAction3D { 7 | void Action(T agent, double Xdisp, double Ydisp,double Zdisp, double distSq); 8 | } 9 | -------------------------------------------------------------------------------- /HAL/Interfaces/AgentStepFunction.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | /** 4 | * Created by rafael on 8/26/17. 5 | */ 6 | @FunctionalInterface 7 | public interface AgentStepFunction { 8 | void AgentStepFunction(T agent); 9 | } 10 | -------------------------------------------------------------------------------- /HAL/Interfaces/AgentToBool.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | import HAL.GridsAndAgents.AgentBase; 4 | 5 | @FunctionalInterface 6 | public interface AgentToBool { 7 | boolean EvalAgent(T agent); 8 | } 9 | -------------------------------------------------------------------------------- /HAL/Interfaces/AgentToColorInt.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | /** 4 | * Created by bravorr on 7/18/17. 5 | */ 6 | @FunctionalInterface 7 | public interface AgentToColorInt { 8 | public int AgentToColor(T agent); 9 | } 10 | -------------------------------------------------------------------------------- /HAL/Interfaces/AgentToDouble.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | import HAL.GridsAndAgents.AgentBase; 4 | 5 | @FunctionalInterface 6 | public interface AgentToDouble { 7 | double EvalAgent(T agent); 8 | } 9 | -------------------------------------------------------------------------------- /HAL/Interfaces/AgentToInts.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | /** 4 | * Created by rafael on 9/7/17. 5 | */ 6 | @FunctionalInterface 7 | public interface AgentToInts { 8 | int[] AgentToInts(T agent); 9 | } 10 | -------------------------------------------------------------------------------- /HAL/Interfaces/AgentToString.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | import HAL.GridsAndAgents.AgentBase; 3 | 4 | /** 5 | * Created by rafael on 8/19/17. 6 | */ 7 | @FunctionalInterface 8 | public interface AgentToString{ 9 | String AtoS(T agent); 10 | } 11 | -------------------------------------------------------------------------------- /HAL/Interfaces/ButtonAction.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | import java.awt.event.ActionEvent; 4 | 5 | /** 6 | * Created by bravorr on 1/30/17. 7 | */ 8 | @FunctionalInterface 9 | public interface ButtonAction { 10 | void Action(ActionEvent e); 11 | } 12 | -------------------------------------------------------------------------------- /HAL/Interfaces/ColorIntGenerator.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | @FunctionalInterface 4 | public interface ColorIntGenerator { 5 | int GenColorInt(); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Interfaces/Coords1DBool.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | @FunctionalInterface 4 | public interface Coords1DBool { 5 | boolean Eval(int x); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Interfaces/Coords1DDouble.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | @FunctionalInterface 4 | public interface Coords1DDouble { 5 | double GenDouble(int x); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Interfaces/Coords1DInt.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | @FunctionalInterface 4 | public interface Coords1DInt { 5 | int GenInt(int x); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Interfaces/Coords2DAction.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | @FunctionalInterface 4 | public interface Coords2DAction { 5 | void Action(int x,int y); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Interfaces/Coords2DBool.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | @FunctionalInterface 4 | public interface Coords2DBool { 5 | boolean Eval(int x,int y); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Interfaces/Coords2DColor.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | @FunctionalInterface 4 | public interface Coords2DColor { 5 | public int SetPix(int x,int y); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Interfaces/Coords2DDouble.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | @FunctionalInterface 4 | public interface Coords2DDouble { 5 | double GenDouble(int x,int y); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Interfaces/Coords2DInt.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | @FunctionalInterface 4 | public interface Coords2DInt { 5 | int GenInt(int x,int y); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Interfaces/Coords2DSetArray.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | /** 4 | * Created by Rafael on 10/20/2017. 5 | */ 6 | @FunctionalInterface 7 | public interface Coords2DSetArray { 8 | void SetArray(int x, int y, double[] out); 9 | } 10 | -------------------------------------------------------------------------------- /HAL/Interfaces/Coords3DAction.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | @FunctionalInterface 4 | public interface Coords3DAction { 5 | public void Action(int x,int y,int z); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Interfaces/Coords3DBool.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | @FunctionalInterface 4 | public interface Coords3DBool { 5 | public boolean Eval(int x, int y,int z); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Interfaces/Coords3DDouble.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | @FunctionalInterface 4 | public interface Coords3DDouble { 5 | double GenDouble(int x, int y, int z); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Interfaces/Coords3DInt.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | @FunctionalInterface 4 | public interface Coords3DInt { 5 | int GenInt(int x, int y, int z); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Interfaces/Coords3DSetArray.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | /** 4 | * Created by Rafael on 10/20/2017. 5 | */ 6 | @FunctionalInterface 7 | public interface Coords3DSetArray { 8 | void SetArray(int x, int y,int z, double[] out); 9 | } 10 | -------------------------------------------------------------------------------- /HAL/Interfaces/Coords6DDouble.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | public interface Coords6DDouble { 4 | double GenDouble(int x1,int y1,int p1,int x2,int y2,int p2); 5 | } 6 | -------------------------------------------------------------------------------- /HAL/Interfaces/CustomSerialization.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | import HAL.Tools.FileIO; 4 | 5 | public interface CustomSerialization { 6 | public void ToBinary(FileIO out); 7 | public void FromBinary(FileIO in); 8 | } 9 | -------------------------------------------------------------------------------- /HAL/Interfaces/DistToForceMap.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | /** 4 | * Created by bravorr on 5/31/17. 5 | */ 6 | @FunctionalInterface 7 | public interface DistToForceMap{ 8 | double DistToForce(double rad); 9 | } 10 | -------------------------------------------------------------------------------- /HAL/Interfaces/DoubleArrayToDouble.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | @FunctionalInterface 4 | public interface DoubleArrayToDouble { 5 | double Eval(double[] in); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Interfaces/DoubleArrayToVoid.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | @FunctionalInterface 4 | public interface DoubleArrayToVoid { 5 | void Action(double[]in); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Interfaces/DoubleToAction.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | @FunctionalInterface 4 | public interface DoubleToAction { 5 | void Action(double val); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Interfaces/DoubleToColor.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | /** 4 | * Created by Rafael on 10/13/2017. 5 | */ 6 | @FunctionalInterface 7 | public interface DoubleToColor { 8 | int GenColor(double val); 9 | } 10 | -------------------------------------------------------------------------------- /HAL/Interfaces/DoubleToDouble.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | /** 4 | * Created by Rafael on 9/18/2017. 5 | */ 6 | @FunctionalInterface 7 | public interface DoubleToDouble { 8 | public double Eval(double in); 9 | } 10 | -------------------------------------------------------------------------------- /HAL/Interfaces/DoubleToDoubles.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | public interface DoubleToDoubles { 4 | double[]GenDoubles(double val); 5 | } 6 | -------------------------------------------------------------------------------- /HAL/Interfaces/DoubleToInt.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | /** 4 | * Created by Rafael on 7/24/2017. 5 | */ 6 | @FunctionalInterface 7 | public interface DoubleToInt { 8 | public int DoubleToInt(double in); 9 | } 10 | -------------------------------------------------------------------------------- /HAL/Interfaces/Doubles2DDouble.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | public interface Doubles2DDouble { 4 | double GenDouble(double x,double y); 5 | } 6 | -------------------------------------------------------------------------------- /HAL/Interfaces/Doubles3DDouble.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | public interface Doubles3DDouble { 4 | double GenDouble(double x,double y,double z); 5 | } 6 | -------------------------------------------------------------------------------- /HAL/Interfaces/DoublesToColor.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | /** 4 | * Created by Rafael on 10/13/2017. 5 | */ 6 | @FunctionalInterface 7 | public interface DoublesToColor { 8 | int GenColor(double val1,double val2); 9 | } 10 | -------------------------------------------------------------------------------- /HAL/Interfaces/DrawFunction.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | import HAL.Gui.UIGrid; 4 | 5 | public interface DrawFunction { 6 | void Draw(UIGrid drawHere); 7 | } 8 | -------------------------------------------------------------------------------- /HAL/Interfaces/GAMutantToString.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | /** 4 | * Created by rafael on 4/8/17. 5 | */ 6 | @FunctionalInterface 7 | public interface GAMutantToString { 8 | String MutantToString(T mut); 9 | } 10 | -------------------------------------------------------------------------------- /HAL/Interfaces/GAMutationFunction.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | /** 4 | * Created by rafael on 4/8/17. 5 | */ 6 | @FunctionalInterface 7 | public interface GAMutationFunction{ 8 | T[] CreateNextGen(T[] parents,double[] scores,int generation); 9 | } 10 | -------------------------------------------------------------------------------- /HAL/Interfaces/GAScoreFunction.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | /** 4 | * Created by rafael on 4/8/17. 5 | */ 6 | @FunctionalInterface 7 | public interface GAScoreFunction { 8 | double ScoreMutant(T mut); 9 | } 10 | -------------------------------------------------------------------------------- /HAL/Interfaces/GenDouble.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | public interface GenDouble { 4 | double GenDouble(); 5 | } 6 | -------------------------------------------------------------------------------- /HAL/Interfaces/GetGenomeAttrs.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | import HAL.Tools.PhylogenyTracker.Genome; 4 | 5 | @FunctionalInterface 6 | public interface GetGenomeAttrs { 7 | String GetAttrs(T genome); 8 | } 9 | -------------------------------------------------------------------------------- /HAL/Interfaces/GetMutationInfo.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | /** 4 | * Created by Rafael on 8/3/2017. 5 | */ 6 | @FunctionalInterface 7 | public interface GetMutationInfo { 8 | String MutantToString(T mutant); 9 | } 10 | -------------------------------------------------------------------------------- /HAL/Interfaces/GridDiff2MultiThreadFunction.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | /** 4 | * Created by rafael on 8/26/17. 5 | */ 6 | @FunctionalInterface 7 | public interface GridDiff2MultiThreadFunction { 8 | public void GridDiff2MulitThreadFunction(int x, int y, int i); 9 | } 10 | -------------------------------------------------------------------------------- /HAL/Interfaces/GuiCloseAction.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | import java.awt.event.WindowEvent; 4 | 5 | /** 6 | * Created by bravorr on 1/30/17. 7 | */ 8 | @FunctionalInterface 9 | public interface GuiCloseAction { 10 | void Action(WindowEvent e); 11 | } 12 | -------------------------------------------------------------------------------- /HAL/Interfaces/GuiComp.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | import java.awt.*; 4 | import java.util.ArrayList; 5 | 6 | /** 7 | * Created by rafael on 1/29/17. 8 | */ 9 | public interface GuiComp { 10 | int compX(); 11 | int compY(); 12 | boolean IsActive(); 13 | void SetActive(boolean isActive); 14 | void _GetComps(ArrayList putHere, ArrayList coordsHere, ArrayList compSizesHere); 15 | } 16 | -------------------------------------------------------------------------------- /HAL/Interfaces/ICoords2DAction.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | @FunctionalInterface 4 | public interface ICoords2DAction { 5 | void Action(int i,int x, int y); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Interfaces/ICoords3DAction.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | @FunctionalInterface 4 | public interface ICoords3DAction { 5 | void Action(int i,int x, int y, int z); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Interfaces/IndexAction.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | @FunctionalInterface 4 | public interface IndexAction { 5 | void Action(int i); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Interfaces/IndexBool.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | @FunctionalInterface 4 | public interface IndexBool { 5 | boolean Eval(int i); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Interfaces/IndexCoords2DAction.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | @FunctionalInterface 4 | public interface IndexCoords2DAction { 5 | void Action(int i,int x,int y); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Interfaces/IndexCoords2DBool.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | @FunctionalInterface 4 | public interface IndexCoords2DBool { 5 | boolean Eval(int i, int x, int y); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Interfaces/IndexCoords2DDouble.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | @FunctionalInterface 4 | public interface IndexCoords2DDouble { 5 | public double Eval(int i,int x,int y); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Interfaces/IndexCoords3DAction.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | @FunctionalInterface 4 | public interface IndexCoords3DAction { 5 | void Action(int i, int x, int y,int z); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Interfaces/IndexCoords3DBool.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | @FunctionalInterface 4 | public interface IndexCoords3DBool { 5 | boolean Eval(int i, int x, int y, int z); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Interfaces/IndexIntAction.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | @FunctionalInterface 4 | public interface IndexIntAction { 5 | void Action(int i, int val); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Interfaces/IndexIntToAction.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | @FunctionalInterface 4 | public interface IndexIntToAction { 5 | void Action(int index,int val); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Interfaces/IndexLongAction.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | @FunctionalInterface 4 | public interface IndexLongAction { 5 | void Action(int i, long val); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Interfaces/IntDoubleToVoid.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | @FunctionalInterface 4 | public interface IntDoubleToVoid { 5 | public void Eval(int i,double d); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Interfaces/IntToBool.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | @FunctionalInterface 4 | public interface IntToBool { 5 | boolean Eval(int num); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Interfaces/IntToDouble.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | @FunctionalInterface 4 | public interface IntToDouble { 5 | double GenDouble(int val); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Interfaces/IntToInt.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | @FunctionalInterface 4 | public interface IntToInt { 5 | int Eval(int in); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Interfaces/IntToVoid.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | @FunctionalInterface 4 | public interface IntToVoid { 5 | void Eval(int num); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Interfaces/IsEntry1Before2.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | @FunctionalInterface 4 | public interface IsEntry1Before2 { 5 | boolean Compare(int i1,int i2); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Interfaces/KeyResponse.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | @FunctionalInterface 4 | public interface KeyResponse { 5 | public void Response(char Character,int keyCode); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Interfaces/LocalIndexAction.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | @FunctionalInterface 4 | public interface LocalIndexAction { 5 | public void Action(int i); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Interfaces/MenuItem.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | /** 4 | * Created by rafael on 11/25/16. 5 | */ 6 | public interface MenuItem{ 7 | public int TypeID();//bool,int,double,String 8 | public void Set(String val); 9 | public String Get(); 10 | public String GetLabel(); 11 | public int NEntries(); 12 | public T GetEntry(int iEntry); 13 | public String _GetInitValue(); 14 | } 15 | -------------------------------------------------------------------------------- /HAL/Interfaces/ObjectToDouble.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | import HAL.GridsAndAgents.AgentBase; 4 | 5 | @FunctionalInterface 6 | public interface ObjectToDouble { 7 | double GenDouble(T input); 8 | } 9 | -------------------------------------------------------------------------------- /HAL/Interfaces/OdeSolution.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | @FunctionalInterface 4 | public interface OdeSolution { 5 | void Get(double t,double[]out); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Interfaces/OverlapForceResponse2D.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | import HAL.GridsAndAgents.SphericalAgent2D; 4 | 5 | /** 6 | * Created by philipaxelrod on 7/11/17. 7 | */ 8 | @FunctionalInterface 9 | public interface OverlapForceResponse2D{ 10 | double CalcForce(double overlap, T other); 11 | } 12 | -------------------------------------------------------------------------------- /HAL/Interfaces/OverlapForceResponse3D.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | import HAL.GridsAndAgents.SphericalAgent3D; 4 | 5 | /** 6 | * Created by philipaxelrod on 7/11/17. 7 | */ 8 | @FunctionalInterface 9 | public interface OverlapForceResponse3D { 10 | double CalcForce(double overlap, T other); 11 | } 12 | -------------------------------------------------------------------------------- /HAL/Interfaces/ParallelFunction.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | @FunctionalInterface 4 | public interface ParallelFunction { 5 | void Run(int runIndex); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Interfaces/ParamSetChangeAction.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | /** 4 | * Created by Rafael on 10/26/2017. 5 | */ 6 | @FunctionalInterface 7 | public interface ParamSetChangeAction { 8 | void Action(String name,String val,String PrevVal); 9 | } 10 | -------------------------------------------------------------------------------- /HAL/Interfaces/Point1DBool.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | @FunctionalInterface 4 | public interface Point1DBool { 5 | boolean Eval(double x); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Interfaces/Point2DBool.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | @FunctionalInterface 4 | public interface Point2DBool { 5 | boolean Eval(double x,double y); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Interfaces/Point3DBool.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | @FunctionalInterface 4 | public interface Point3DBool { 5 | boolean Eval(double x, double y,double z); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Interfaces/RNG.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | public interface RNG { 4 | public int Int(int bound); 5 | public double Double(double bound); 6 | public double Double(); 7 | public long Long(long bound); 8 | public boolean Bool(); 9 | } 10 | -------------------------------------------------------------------------------- /HAL/Interfaces/SerializableModel.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | import java.io.*; 4 | 5 | @FunctionalInterface 6 | public interface SerializableModel extends Serializable{ 7 | //must setup constructors of all grids that are serialized, used when loading 8 | public void SetupConstructors();//sets up the constructors for all Grid2Ds/Grid3Ds, use the _PassAgentConstructor() function to do this, if no Grid2Ds or Grid3Ds are being used, this function can be left empty 9 | } 10 | -------------------------------------------------------------------------------- /HAL/Interfaces/Sortable.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | /** 4 | * allows for the QuickSort function to be used to sort the object 5 | */ 6 | 7 | public interface Sortable { 8 | /** 9 | * should return a positive number if first > second, negative if second > first, 0 if equal 10 | * @param iFirst the index of the first object to compare 11 | * @param iSecond the index of the second object to compare 12 | */ 13 | double Compare(int iFirst, int iSecond);//pos if iFirst > iSecond 14 | 15 | /** 16 | * should swap the objects at these indices so that they switch places in their data structure 17 | * @param iFirst the index of the first object to compare 18 | * @param iSecond the index of the second object to compare 19 | */ 20 | void Swap(int iFirst, int iSecond); 21 | 22 | /** 23 | * should return the number of objects to sort in the data structure 24 | */ 25 | int Length(); 26 | 27 | /** 28 | * Runs quicksort on an object that implements Sortable 29 | * 30 | * @param greatestToLeast if true, sorting will be form greatest to least, otherwise will be least to greatest 31 | */ 32 | default void QuickSort(boolean greatestToLeast) { 33 | _SortHelper(this, 0, this.Length() - 1, greatestToLeast); 34 | } 35 | 36 | default void _SortHelper(T sortMe, int lo, int hi, boolean greatestToLeast) { 37 | if (lo < hi) { 38 | int p = _Partition(sortMe, lo, hi, greatestToLeast); 39 | _SortHelper(sortMe, lo, p - 1, greatestToLeast); 40 | _SortHelper(sortMe, p + 1, hi, greatestToLeast); 41 | } 42 | } 43 | 44 | default int _Partition(T sortMe, int lo, int hi, boolean greatestToLeast) { 45 | if (greatestToLeast) { 46 | for (int j = lo; j < hi; j++) { 47 | if (sortMe.Compare(hi, j) <= 0) { 48 | sortMe.Swap(lo, j); 49 | lo++; 50 | } 51 | } 52 | sortMe.Swap(lo, hi); 53 | return lo; 54 | } else { 55 | for (int j = lo; j < hi; j++) { 56 | if (sortMe.Compare(hi, j) >= 0) { 57 | sortMe.Swap(lo, j); 58 | lo++; 59 | } 60 | } 61 | sortMe.Swap(lo, hi); 62 | return lo; 63 | } 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /HAL/Interfaces/SwapEntries.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | @FunctionalInterface 4 | public interface SwapEntries { 5 | void Swap(int i1,int i2); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Interfaces/VoidFunction.java: -------------------------------------------------------------------------------- 1 | package HAL.Interfaces; 2 | 3 | @FunctionalInterface 4 | public interface VoidFunction { 5 | public void Execute(); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Tools/BoolSet.java: -------------------------------------------------------------------------------- 1 | package HAL.Tools; 2 | 3 | public class BoolSet { 4 | private final long[] data; 5 | final int LBITS=Long.SIZE; 6 | public final int length; 7 | public BoolSet(int capacity){ 8 | this.length=capacity; 9 | data =new long[capacity/LBITS+1]; 10 | } 11 | public BoolSet(long[]data,int capacity){ 12 | this.data=new long[data.length]; 13 | this.length=capacity; 14 | System.arraycopy(data,0,this.data,0,data.length); 15 | } 16 | public BoolSet Copy(){ 17 | return new BoolSet(data,this.length); 18 | } 19 | public long[] GetData(){ 20 | return data; 21 | } 22 | public void Set(int i,boolean val){ 23 | int block=i/LBITS; 24 | int iblock=i%LBITS; 25 | if(val) { 26 | data[block] = data[block] | (1L << iblock); 27 | }else{ 28 | data[block] = data[block] & ~(1L << iblock); 29 | } 30 | } 31 | public boolean Get(int i){ 32 | int block=i/LBITS; 33 | int iblock=i%LBITS; 34 | return (data[block] & (1L << iblock)) != 0; 35 | } 36 | public void SetSafe(int i,boolean val){ 37 | if(i>=length||i<0){ 38 | throw new IndexOutOfBoundsException("set index "+i+" is out of BoolSet bounds, length "+length); 39 | } 40 | Set(i,val); 41 | } 42 | public boolean GetSafe(int i){ 43 | if(i>=length||i<0){ 44 | throw new IndexOutOfBoundsException("get index "+i+" is out of BoolSet bounds, length "+length); 45 | } 46 | return Get(i); 47 | } 48 | 49 | public static void main(String[] args) { 50 | BoolSet ex=new BoolSet(100); 51 | ex.SetSafe(85,true); 52 | System.out.println(ex.GetSafe(85)); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /HAL/Tools/InteractiveModel/TreatableTumor.java: -------------------------------------------------------------------------------- 1 | package HAL.Tools.InteractiveModel; 2 | 3 | import HAL.Gui.UIGrid; 4 | import HAL.Interfaces.SerializableModel; 5 | 6 | /** 7 | * Created by Rafael on 9/26/2017. 8 | */ 9 | public interface TreatableTumor extends SerializableModel { 10 | void Draw(UIGrid vis, int drawState);//alphaVis draws over vis if alpha values are set to nonzero 11 | void InteractiveStep(double[] treatmentVals, int step);//be sure to use the provided random number generator. 12 | String[] GetTreatmentNames();//returns a list of treatment names 13 | int[] GetTreatmentColors();//returns the color for each treatment 14 | int[] GetNumIntensities();//returns how many intensity options the play has to choose between, must be at least 1 15 | int[] GetPlotColors();//returns the colors of the lines to be plotted 16 | String[] GetPlotLegendNames();//returns the colors of the lines to be plotted 17 | double[] GetPlotVals();//returns the values to be plotted in the timeline 18 | } 19 | 20 | 21 | -------------------------------------------------------------------------------- /HAL/Tools/Internal/Gaussian.java: -------------------------------------------------------------------------------- 1 | package HAL.Tools.Internal; 2 | 3 | import HAL.Rand; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * Created by Rafael on 11/16/2017. 9 | */ 10 | 11 | 12 | public class Gaussian implements Serializable{ 13 | double V1=0,V2=0,S=0,phase=0; 14 | public double Sample(double mean, double stdDev, Rand rn) { 15 | double X; 16 | if (phase == 0) { 17 | do { 18 | double U1 = rn.Double(); 19 | double U2 = rn.Double(); 20 | 21 | V1 = 2 * U1 - 1; 22 | V2 = 2 * U2 - 1; 23 | S = V1 * V1 + V2 * V2; 24 | } while (S >= 1 || S == 0); 25 | 26 | X = V1 * Math.sqrt(-2 * Math.log(S) / S); 27 | } else { 28 | X = V2 * Math.sqrt(-2 * Math.log(S) / S); 29 | } 30 | phase = 1 - phase; 31 | return X * stdDev + mean; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /HAL/Tools/Internal/KeyRecorder.java: -------------------------------------------------------------------------------- 1 | package HAL.Tools.Internal; 2 | 3 | import java.awt.event.KeyEvent; 4 | 5 | public class KeyRecorder { 6 | public final boolean[] keys = new boolean[525]; 7 | 8 | public boolean KeyPress(int keyCode) { 9 | //returns whether key was recorded as already being pressed 10 | if (keyCode < keys.length) { 11 | boolean ret = !keys[keyCode]; 12 | keys[keyCode] = true; 13 | return ret; 14 | } 15 | return false; 16 | } 17 | 18 | public boolean KeyRelease(int keyCode) { 19 | //returns wether key was recorded as already being released 20 | if (keyCode < keys.length) { 21 | boolean ret = keys[keyCode]; 22 | keys[keyCode] = false; 23 | return ret; 24 | } 25 | return false; 26 | } 27 | 28 | public boolean IsPressed(int keyCode) { 29 | //returns whether key is recorded as currently pressed 30 | return keys[keyCode]; 31 | } 32 | public boolean IsPressed(char c) { 33 | int code=KeyEvent.getExtendedKeyCodeForChar(c); 34 | //returns whether key is recorded as currently pressed 35 | return keys[code]; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /HAL/Tools/Internal/SweepRun.java: -------------------------------------------------------------------------------- 1 | package HAL.Tools.Internal; 2 | 3 | import HAL.Interfaces.ParallelFunction; 4 | 5 | /** 6 | * Created by rafael on 4/15/17. 7 | */ 8 | public class SweepRun implements Runnable{ 9 | //Runs parameter sweep, saves results to a file 10 | final int iParamSet; 11 | final ParallelFunction RunFun; 12 | public SweepRun(ParallelFunction RunFun, int iParamSet){ 13 | this.iParamSet=iParamSet; 14 | this.RunFun =RunFun; 15 | } 16 | 17 | @Override 18 | public void run() { 19 | RunFun.Run(iParamSet); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /HAL/Tools/Lenia/Coords1DDoubleArrToDouble.java: -------------------------------------------------------------------------------- 1 | package HAL.Tools.Lenia; 2 | 3 | @FunctionalInterface 4 | public interface Coords1DDoubleArrToDouble { 5 | double Eval(int i,double[] vals); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Tools/Lenia/Coords2DDoubleToDouble.java: -------------------------------------------------------------------------------- 1 | package HAL.Tools.Lenia; 2 | 3 | @FunctionalInterface 4 | public interface Coords2DDoubleToDouble { 5 | double Eval(int i,int j,double v); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Tools/Modularity/ModuleSetManager.java: -------------------------------------------------------------------------------- 1 | package HAL.Tools.Modularity; 2 | 3 | import java.lang.reflect.Method; 4 | import java.util.ArrayList; 5 | import java.util.HashMap; 6 | 7 | import static HAL.Util.IsMethodOverridden; 8 | 9 | /** 10 | * the ModuleSetManager class is used to store and use module objects. the type argument is the baseclass module type that the ModuleSetManager will manage 11 | */ 12 | public class ModuleSetManager{ 13 | public Class baseClass; 14 | public HashMap> moduleLists=new HashMap<>(); 15 | public ArrayListmethodNames; 16 | public ArrayList modules =new ArrayList<>(); 17 | 18 | /** 19 | * the module base class object should define all of the method hooks that modules can use, the behavior of the base class object will be ignored 20 | */ 21 | public ModuleSetManager(Class baseClass){ 22 | this.baseClass=baseClass; 23 | Method[] baseMethods=baseClass.getDeclaredMethods(); 24 | methodNames=new ArrayList<>(); 25 | for (Method method : baseMethods) { 26 | moduleLists.put(method.getName(),new ArrayList<>()); 27 | methodNames.add(method.getName()); 28 | } 29 | } 30 | 31 | /** 32 | * adds a module to the ModuleSetManager. the module should override any functions in the baseClass that the will be used with the model 33 | */ 34 | public void AddModule(baseModule newMod) { 35 | for (String method : methodNames) { 36 | if(IsMethodOverridden(newMod.getClass(),baseClass,method)){ 37 | moduleLists.get(method).add(newMod); 38 | } 39 | } 40 | modules.add(newMod); 41 | } 42 | 43 | /** 44 | * use with foreach loop to iterate over modules that override a given method. used to run the module functions when appropriate 45 | */ 46 | public Iterable Iter(String methodName){ 47 | return moduleLists.get(methodName); 48 | } 49 | 50 | public int CountModsWithMethod(String methodName){ 51 | return moduleLists.get(methodName).size(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /HAL/Tools/Modularity/VarSet.java: -------------------------------------------------------------------------------- 1 | package HAL.Tools.Modularity; 2 | 3 | public interface VarSet { 4 | double[] GetVars(); 5 | void SetVars(double[]newVars); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Tools/Modularity/VarSetManager.java: -------------------------------------------------------------------------------- 1 | package HAL.Tools.Modularity; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * the VarSetManager class maintains a count of parameters that are requested for an agent class that implements the 7 | * VarSet interface. this class is useful along with the ModuleSetManger to add agent variables that are only 8 | * manipulated by one module 9 | */ 10 | public class VarSetManager implements Serializable{ 11 | private boolean setup = false; 12 | int nParams; 13 | 14 | /** 15 | * generates a new variable as part of the var array, returns the index of the variable 16 | */ 17 | public int NewVar() { 18 | if (setup) { 19 | throw new IllegalStateException("can't generate varSets before done adding varManager!"); 20 | } 21 | nParams++; 22 | return nParams - 1; 23 | } 24 | 25 | /** 26 | * adds a new variable set to the given agent. does nothing if the variable set has already been initialized 27 | */ 28 | public void AddVarSet(agentType agent) { 29 | setup = true; 30 | if (agent.GetVars() == null && nParams > 0) { 31 | agent.SetVars(new double[nParams]); 32 | } 33 | } 34 | 35 | public double[] GenVarSet(){ 36 | setup = true; 37 | return new double[nParams]; 38 | } 39 | 40 | public int NumParams(){ 41 | return nParams; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /HAL/Tools/MultiWellExperiment/DrawWell.java: -------------------------------------------------------------------------------- 1 | package HAL.Tools.MultiWellExperiment; 2 | 3 | @FunctionalInterface 4 | public interface DrawWell { 5 | int GetPixColor(T model, int x, int y); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Tools/MultiWellExperiment/StepWell.java: -------------------------------------------------------------------------------- 1 | package HAL.Tools.MultiWellExperiment; 2 | 3 | @FunctionalInterface 4 | public interface StepWell { 5 | void Step(T model,int iWell); 6 | } 7 | -------------------------------------------------------------------------------- /HAL/Tools/MultinomialCalc.java: -------------------------------------------------------------------------------- 1 | package HAL.Tools; 2 | 3 | import HAL.Rand; 4 | import HAL.Util; 5 | 6 | import java.io.Serializable; 7 | 8 | public class MultinomialCalc extends Rand implements Serializable{ 9 | public int popRemaining; 10 | public double probRemaining; 11 | public MultinomialCalc(Rand rng){ 12 | super(rng.rn); 13 | } 14 | public void Setup(int pop){ 15 | this.popRemaining=pop; 16 | this.probRemaining =1; 17 | } 18 | public int Sample(double prob){ 19 | if(popRemaining==0||prob==0){ 20 | return 0; 21 | } 22 | if(probRemaining-prob<=0){ 23 | int ret=popRemaining; 24 | popRemaining=0; 25 | probRemaining-=prob; 26 | return ret; 27 | } 28 | int popSelected=Binomial(popRemaining,prob/ probRemaining); 29 | probRemaining -=prob; 30 | popRemaining-=popSelected; 31 | return popSelected; 32 | } 33 | public int GetPopRemaining(){ 34 | return popRemaining; 35 | } 36 | public double GetProbRemaining(){ 37 | return probRemaining; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /HAL/Tools/MultinomialCalcLong.java: -------------------------------------------------------------------------------- 1 | package HAL.Tools; 2 | 3 | import HAL.Rand; 4 | 5 | import java.io.Serializable; 6 | 7 | public class MultinomialCalcLong extends Rand implements Serializable{ 8 | public long popRemaining; 9 | public double probRemaining; 10 | public MultinomialCalcLong(Rand rng){ 11 | super(rng.rn); 12 | } 13 | public void Setup(long pop){ 14 | this.popRemaining=pop; 15 | this.probRemaining =1; 16 | } 17 | public long Sample(double prob){ 18 | if(popRemaining==0||prob==0){ 19 | return 0; 20 | } 21 | if(probRemaining-prob<=0){ 22 | long ret=popRemaining; 23 | popRemaining=0; 24 | probRemaining-=prob; 25 | return ret; 26 | } 27 | long popSelected=Binomial(popRemaining,prob/ probRemaining); 28 | probRemaining -=prob; 29 | popRemaining-=popSelected; 30 | return popSelected; 31 | } 32 | public long GetPopRemaining(){ 33 | return popRemaining; 34 | } 35 | public double GetProbRemaining(){ 36 | return probRemaining; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /HAL/Tools/ODESolver/Derivative.java: -------------------------------------------------------------------------------- 1 | package HAL.Tools.ODESolver; 2 | 3 | public interface Derivative { 4 | void Set(double t, double[]state, double[]derivativesOut); 5 | } 6 | -------------------------------------------------------------------------------- /HAL/Tools/PY4J/DoublesDataFrame.java: -------------------------------------------------------------------------------- 1 | package HAL.Tools.PY4J; 2 | 3 | import HAL.Tools.FileIO; 4 | import HAL.Util; 5 | 6 | import java.util.ArrayList; 7 | import java.util.HashMap; 8 | 9 | public class DoublesDataFrame { 10 | public HashMap columns=new HashMap<>(); 11 | public ArrayList data; 12 | public String[]headers; 13 | public DoublesDataFrame(String csvPath){ 14 | this(csvPath,","); 15 | } 16 | public DoublesDataFrame(String []headers){ 17 | this.headers=headers; 18 | SetCols(headers); 19 | this.data=new ArrayList<>(); 20 | } 21 | public DoublesDataFrame(String csvPath,String delim){ 22 | FileIO reader=new FileIO(csvPath,"r"); 23 | headers=reader.ReadLineDelimit(delim); 24 | SetCols(headers); 25 | data=reader.ReadDoubles(delim); 26 | } 27 | public void SetCols(String[]headers){ 28 | for (int i = 0; i < headers.length; i++) { 29 | columns.put(headers[i],i); 30 | } 31 | 32 | } 33 | public DoublesDataFrame(String[] headers,double[][]rows){ 34 | this.headers=headers; 35 | SetCols(headers); 36 | this.data=new ArrayList<>(); 37 | for (double[] row : rows) { 38 | data.add(row); 39 | } 40 | } 41 | public DoublesDataFrame(String[]headers,ArrayListrows){ 42 | this.headers=headers; 43 | SetCols(headers); 44 | this.data=rows; 45 | } 46 | 47 | public double Get(int row,String column){ 48 | return data.get(row)[columns.get(column)]; 49 | } 50 | public double Get(int row,int column){ 51 | return data.get(row)[column]; 52 | } 53 | public void Set(int row,String column,double val){ 54 | data.get(row)[columns.get(column)]=val; 55 | } 56 | public void Set(int row,int column,double val){ 57 | data.get(row)[column]=val; 58 | } 59 | public double[]GetRow(int row){ 60 | return data.get(row); 61 | } 62 | public int ICol(String column){ 63 | return columns.get(column); 64 | } 65 | public int Nrows(){ 66 | return data.size(); 67 | } 68 | public int Ncols(){ 69 | return headers.length; 70 | } 71 | public void ToCSV(String path){ 72 | FileIO out=new FileIO(path,"w"); 73 | out.Write(Util.ArrToString(headers,",")+"\n"); 74 | for (double[] row : data) { 75 | out.Write(Util.ArrToString(row,",")+"\n"); 76 | } 77 | out.Close(); 78 | } 79 | } 80 | 81 | -------------------------------------------------------------------------------- /HAL/Tools/PY4J/Py4jModel.java: -------------------------------------------------------------------------------- 1 | package HAL.Tools.PY4J; 2 | 3 | 4 | import java.util.ArrayList; 5 | 6 | public interface Py4jModel { 7 | M GenSeed(); 8 | void Reset(double[]params); 9 | double[] Eval(); 10 | ArrayList GetParamHeaders(); 11 | ArrayList GetResultHeaders(); 12 | } 13 | -------------------------------------------------------------------------------- /HAL/Tools/PY4J/Py4jRunner.java: -------------------------------------------------------------------------------- 1 | package HAL.Tools.PY4J; 2 | 3 | /* 4 | 5 | GOAL: be able to add modules and manage parameters from the python side 6 | Entities: 7 | Seed (can be equipped with modules), implements modular modeling 8 | Model (used to run with double[] param inputs and generates double[] outputs) 9 | */ 10 | 11 | import HAL.Util; 12 | import java.util.ArrayList; 13 | import java.util.Collections; 14 | import java.util.List; 15 | 16 | public class Py4jRunner { 17 | public List modelPool=new ArrayList<>(); 18 | int numPoolModels; 19 | M seed; 20 | public Py4jRunner(M seed){ 21 | this.seed=seed; 22 | } 23 | public void ResetModelPool(){ 24 | this.modelPool= Collections.synchronizedList(new ArrayList<>()); 25 | numPoolModels=0; 26 | } 27 | public double[]RunModel(double[]params,Py4jModel model){ 28 | model.Reset(params); 29 | return model.Eval(); 30 | } 31 | public double[][]EvalGen(double[][]params,int nThreads){ 32 | double[][]ret=new double[params.length][]; 33 | if(nThreads>1){ 34 | Util.MultiThread(params.length,nThreads,(i)->{ 35 | M runMe= GetModelFromPool(); 36 | if(params[i].length!=runMe.GetParamHeaders().size()){ 37 | throw new IllegalStateException("parameter array of incorrect length, check the learning algorithm!"); 38 | } 39 | ret[i]=RunModel(params[i],runMe); 40 | synchronized (modelPool) { 41 | modelPool.add(runMe); 42 | } 43 | }); 44 | } 45 | else{ 46 | M runMe= GetModelFromPool(); 47 | for (int i = 0; i < params.length; i++) { 48 | ret[i]=RunModel(params[i],runMe); 49 | } 50 | synchronized (modelPool) { 51 | modelPool.add(runMe); 52 | } 53 | } 54 | return ret; 55 | } 56 | public ArrayList GetParamHeaders(){ 57 | return modelPool.get(0).GetParamHeaders(); 58 | } 59 | 60 | public M AddPoolModel(){ 61 | M newModel=(M)seed.GenSeed(); 62 | synchronized (modelPool) { 63 | modelPool.add(newModel); 64 | } 65 | numPoolModels++; 66 | return newModel; 67 | } 68 | 69 | public int NumPoolModels(){ 70 | return numPoolModels; 71 | } 72 | 73 | public M GetModelFromPool(){ 74 | synchronized (modelPool) { 75 | if (modelPool.size() > 0) { 76 | return modelPool.remove(modelPool.size() - 1); 77 | } else { 78 | throw new IllegalThreadStateException("model pool too small!"); 79 | } 80 | } 81 | } 82 | public int NumParams(){ 83 | return modelPool.get(0).GetParamHeaders().size(); 84 | } 85 | 86 | public M GenModel(){ 87 | return (M) seed.GenSeed(); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /HAL/Tools/PhylogenyTracker/GenomeFn.java: -------------------------------------------------------------------------------- 1 | package HAL.Tools.PhylogenyTracker; 2 | 3 | @FunctionalInterface 4 | public interface GenomeFn{ 5 | void GenomeFn(T c); 6 | } 7 | 8 | -------------------------------------------------------------------------------- /HAL/Tools/PhylogenyTracker/GenomeLineageFn.java: -------------------------------------------------------------------------------- 1 | package HAL.Tools.PhylogenyTracker; 2 | 3 | import java.util.ArrayList; 4 | 5 | @FunctionalInterface 6 | public interface GenomeLineageFn{ 7 | void GenomeLineageFn(ArrayList lineage); 8 | } 9 | 10 | -------------------------------------------------------------------------------- /HAL/lib/lwjgl-assimp-javadoc.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-assimp-javadoc.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-assimp-natives-linux-arm32.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-assimp-natives-linux-arm32.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-assimp-natives-linux-arm64.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-assimp-natives-linux-arm64.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-assimp-natives-linux.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-assimp-natives-linux.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-assimp-natives-macos-arm64.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-assimp-natives-macos-arm64.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-assimp-natives-macos.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-assimp-natives-macos.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-assimp-natives-windows-arm64.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-assimp-natives-windows-arm64.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-assimp-natives-windows-x86.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-assimp-natives-windows-x86.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-assimp-natives-windows.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-assimp-natives-windows.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-assimp-sources.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-assimp-sources.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-assimp.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-assimp.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-glfw-javadoc.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-glfw-javadoc.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-glfw-natives-linux-arm32.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-glfw-natives-linux-arm32.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-glfw-natives-linux-arm64.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-glfw-natives-linux-arm64.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-glfw-natives-linux.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-glfw-natives-linux.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-glfw-natives-macos-arm64.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-glfw-natives-macos-arm64.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-glfw-natives-macos.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-glfw-natives-macos.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-glfw-natives-windows-arm64.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-glfw-natives-windows-arm64.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-glfw-natives-windows-x86.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-glfw-natives-windows-x86.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-glfw-natives-windows.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-glfw-natives-windows.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-glfw-sources.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-glfw-sources.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-glfw.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-glfw.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-javadoc.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-javadoc.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-natives-linux-arm32.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-natives-linux-arm32.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-natives-linux-arm64.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-natives-linux-arm64.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-natives-linux.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-natives-linux.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-natives-macos-arm64.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-natives-macos-arm64.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-natives-macos.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-natives-macos.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-natives-windows-arm64.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-natives-windows-arm64.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-natives-windows-x86.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-natives-windows-x86.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-natives-windows.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-natives-windows.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-openal-javadoc.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-openal-javadoc.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-openal-natives-linux-arm32.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-openal-natives-linux-arm32.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-openal-natives-linux-arm64.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-openal-natives-linux-arm64.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-openal-natives-linux.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-openal-natives-linux.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-openal-natives-macos-arm64.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-openal-natives-macos-arm64.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-openal-natives-macos.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-openal-natives-macos.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-openal-natives-windows-arm64.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-openal-natives-windows-arm64.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-openal-natives-windows-x86.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-openal-natives-windows-x86.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-openal-natives-windows.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-openal-natives-windows.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-openal-sources.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-openal-sources.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-openal.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-openal.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-opengl-javadoc.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-opengl-javadoc.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-opengl-natives-linux-arm32.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-opengl-natives-linux-arm32.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-opengl-natives-linux-arm64.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-opengl-natives-linux-arm64.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-opengl-natives-linux.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-opengl-natives-linux.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-opengl-natives-macos-arm64.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-opengl-natives-macos-arm64.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-opengl-natives-macos.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-opengl-natives-macos.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-opengl-natives-windows-arm64.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-opengl-natives-windows-arm64.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-opengl-natives-windows-x86.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-opengl-natives-windows-x86.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-opengl-natives-windows.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-opengl-natives-windows.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-opengl-sources.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-opengl-sources.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-opengl.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-opengl.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-sources.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-sources.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-stb-javadoc.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-stb-javadoc.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-stb-natives-linux-arm32.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-stb-natives-linux-arm32.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-stb-natives-linux-arm64.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-stb-natives-linux-arm64.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-stb-natives-linux.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-stb-natives-linux.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-stb-natives-macos-arm64.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-stb-natives-macos-arm64.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-stb-natives-macos.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-stb-natives-macos.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-stb-natives-windows-arm64.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-stb-natives-windows-arm64.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-stb-natives-windows-x86.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-stb-natives-windows-x86.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-stb-natives-windows.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-stb-natives-windows.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-stb-sources.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-stb-sources.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl-stb.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl-stb.jar -------------------------------------------------------------------------------- /HAL/lib/lwjgl.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HAL/lib/lwjgl.jar -------------------------------------------------------------------------------- /HalColorSchemes.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/HalColorSchemes.jar -------------------------------------------------------------------------------- /LEARN_HERE/Agents/BirthDeath.java: -------------------------------------------------------------------------------- 1 | package LEARN_HERE.Agents; 2 | 3 | import HAL.GridsAndAgents.AgentSQ2Dunstackable; 4 | import HAL.Gui.GridWindow; 5 | import HAL.GridsAndAgents.AgentGrid2D; 6 | import HAL.Rand; 7 | import HAL.Util; 8 | 9 | import static HAL.Util.*; 10 | 11 | /** 12 | * Created by Rafael on 9/5/2017. 13 | */ 14 | 15 | class Cell extends AgentSQ2Dunstackable { 16 | int color; 17 | 18 | public void Step() { 19 | if (G.rn.Double() < G.DEATH_PROB) { 20 | Dispose(); 21 | return; 22 | } 23 | if (G.rn.Double() < G.BIRTH_PROB) { 24 | int nOptions = G.MapEmptyHood(G.mooreHood, Xsq(), Ysq()); 25 | if(nOptions>0) { 26 | G.NewAgentSQ(G.mooreHood[G.rn.Int(nOptions)]).color=color; 27 | } 28 | } 29 | } 30 | } 31 | 32 | public class BirthDeath extends AgentGrid2D { 33 | int BLACK=RGB(0,0,0); 34 | double DEATH_PROB=0.01; 35 | double BIRTH_PROB=0.2; 36 | Rand rn=new Rand(); 37 | int[]mooreHood=MooreHood(false); 38 | int color; 39 | public BirthDeath(int x, int y,int color) { 40 | super(x, y, Cell.class); 41 | this.color=color; 42 | } 43 | public void Setup(double rad){ 44 | int[]coords= CircleHood(true,rad); 45 | int nCoords= MapHood(coords,xDim/2,yDim/2); 46 | for (int i = 0; i < nCoords ; i++) { 47 | NewAgentSQ(coords[i]).color=color; 48 | } 49 | } 50 | public void Step() { 51 | for (Cell c : this) { 52 | c.Step(); 53 | } 54 | CleanAgents(); 55 | ShuffleAgents(rn); 56 | } 57 | public void Draw(GridWindow vis){ 58 | for (int i = 0; i < vis.length; i++) { 59 | Cell c = GetAgent(i); 60 | vis.SetPix(i, c == null ? BLACK : c.color); 61 | } 62 | } 63 | 64 | 65 | public static void main(String[] args) { 66 | BirthDeath t=new BirthDeath(100,100, Util.RED); 67 | GridWindow win=new GridWindow(100,100,10); 68 | t.Setup(10); 69 | for (int i = 0; i < 100000; i++) { 70 | win.TickPause(10); 71 | t.Step(); 72 | t.Draw(win); 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /LEARN_HERE/Agents/BirthDeathOffLattice.java: -------------------------------------------------------------------------------- 1 | package LEARN_HERE.Agents; 2 | 3 | import HAL.GridsAndAgents.AgentGrid2D; 4 | import HAL.GridsAndAgents.AgentPT2D; 5 | import HAL.Gui.OpenGL2DWindow; 6 | import HAL.Rand; 7 | import HAL.Util; 8 | 9 | class ExampleCell extends AgentPT2D { 10 | int color; 11 | 12 | public void Init(){ 13 | this.color=Util.RGB(G.rng.Double(), G.rng.Double(), G.rng.Double()); 14 | } 15 | 16 | public void StepCell(double dieProb,double divProb){ 17 | if(G.rng.Double() { 32 | Rand rng = new Rand(); 33 | int[] divHood = Util.VonNeumannHood(false); 34 | double[] moveCoords = new double[2]; 35 | 36 | public BirthDeathOffLattice(int x, int y) { 37 | super(x, y, ExampleCell.class); 38 | } 39 | 40 | public void Step(double dieProb, double divProb) { 41 | for (ExampleCell cell : this) { 42 | cell.StepCell(dieProb, divProb); 43 | } 44 | } 45 | 46 | public void DrawModel(OpenGL2DWindow win) { 47 | if(win.IsClosed()){ 48 | System.exit(0);//Stops the program when the close button is clicked 49 | } 50 | win.Clear(Util.BLACK); 51 | for (ExampleCell cell : this) { 52 | win.Circle(cell.Xpt(), cell.Ypt(), 0.5, cell.color); 53 | } 54 | win.Update(); 55 | } 56 | 57 | public static void main(String[] args) { 58 | OpenGL2DWindow.MakeMacCompatible(args); 59 | int x = 100; 60 | int y = 100; 61 | int timesteps = 1000; 62 | double dieProb = 0.1; 63 | double divProb = 0.2; 64 | OpenGL2DWindow win = new OpenGL2DWindow("2D", 500, 500, x, y); 65 | 66 | BirthDeathOffLattice model = new BirthDeathOffLattice(x, y); 67 | 68 | //initialize model 69 | 70 | for (int i = 0; i < timesteps; i++) { 71 | if (model.Pop() == 0) { 72 | model.NewAgentPT(model.xDim / 2.0, model.yDim / 2.0).Init(); 73 | } 74 | //model step 75 | model.Step(dieProb, divProb); 76 | 77 | model.DrawModel(win); 78 | 79 | //can you use iThread to vary the consumption rate? 80 | } 81 | } 82 | } 83 | 84 | -------------------------------------------------------------------------------- /LEARN_HERE/Agents/Mover3D.java: -------------------------------------------------------------------------------- 1 | package LEARN_HERE.Agents; 2 | 3 | import HAL.GridsAndAgents.AgentGrid3D; 4 | import HAL.GridsAndAgents.AgentSQ3Dunstackable; 5 | import HAL.Gui.GridWindow; 6 | import HAL.Gui.OpenGL3DWindow; 7 | import HAL.Util; 8 | 9 | import java.util.Random; 10 | 11 | /** 12 | * Created by Rafael on 10/29/2017. 13 | */ 14 | class MoveAgent extends AgentSQ3Dunstackable { 15 | 16 | } 17 | 18 | public class Mover3D extends AgentGrid3D { 19 | public Mover3D(int x, int y, int z) { 20 | super(x, y,z, MoveAgent.class,false,false,false);//set to true for wraparound 21 | } 22 | 23 | public static void main(String[] args) { 24 | OpenGL3DWindow.MakeMacCompatible(args); 25 | 26 | Mover3D test=new Mover3D(10,10,10); 27 | OpenGL3DWindow win3D=new OpenGL3DWindow("3D",500,500,test.xDim,test.yDim,test.zDim); 28 | GridWindow win2D=new GridWindow("2D",test.xDim,test.yDim,20); 29 | MoveAgent ourHero=test.NewAgentSQ(5,5,5); 30 | Random rn=new Random(); 31 | 32 | for (int i = 0; i < 10000; i++) { 33 | win2D.TickPause(10); 34 | ourHero.MoveSafeSQ(ourHero.Xsq()+(rn.nextInt(3)-1),ourHero.Ysq()+(rn.nextInt(3)-1),ourHero.Zsq()+(rn.nextInt(3)-1));//random movement 35 | 36 | win2D.Clear(Util.BLACK); 37 | win2D.SetPix(ourHero.Xsq(),ourHero.Ysq(), Util.HeatMapRGB(ourHero.Zsq(),0,test.zDim));//draw 2d 38 | 39 | win3D.ClearBox(Util.MAGENTA,Util.BLACK); 40 | win3D.Circle(ourHero.Xsq(),ourHero.Ysq(),ourHero.Zsq(),0.5,Util.GREEN);//draw 3d 41 | win3D.Update(); 42 | if(win3D.IsClosed()){//quit if close button is clicked 43 | break; 44 | } 45 | } 46 | win3D.Close();//destroy guis 47 | win2D.Close(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /LEARN_HERE/Agents/MultiwellExample.java: -------------------------------------------------------------------------------- 1 | package LEARN_HERE.Agents; 2 | 3 | 4 | import HAL.Tools.MultiWellExperiment.MultiWellExperiment; 5 | 6 | import static HAL.Util.*; 7 | 8 | public class MultiwellExample{ 9 | public static void StepModel(BirthDeath model,int iWell){ 10 | model.Step(); 11 | } 12 | public static int DrawModel(BirthDeath model,int x,int y){ 13 | Cell c = model.GetAgent(x,y); 14 | return c == null ? BLACK : c.color; 15 | } 16 | public static void main(String[] args){ 17 | int x=100,y=100; 18 | BirthDeath[] models=new BirthDeath[]{new BirthDeath(x,y,RED),new BirthDeath(x,y,GREEN),new BirthDeath(x,y,BLUE), 19 | new BirthDeath(x,y,YELLOW),new BirthDeath(x,y,CYAN),new BirthDeath(x,y,MAGENTA)}; 20 | for (BirthDeath model : models) { 21 | model.Setup(2); 22 | } 23 | MultiWellExperiment expt=new MultiWellExperiment(3,2,models,x,y, 5, WHITE, MultiwellExample::StepModel,MultiwellExample::DrawModel); 24 | expt.Run(200,false,100); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /LEARN_HERE/Agents/PopGrid.java: -------------------------------------------------------------------------------- 1 | package LEARN_HERE.Agents; 2 | 3 | import HAL.GridsAndAgents.PopulationGrid2D; 4 | import HAL.Gui.GridWindow; 5 | import HAL.Rand; 6 | import HAL.Tools.MultinomialCalc; 7 | import HAL.Util; 8 | 9 | 10 | public class PopGrid { 11 | public static void main(String[] args) { 12 | 13 | //generate the model objects 14 | PopulationGrid2D cells = new PopulationGrid2D(50, 50); 15 | Rand rng=new Rand(); 16 | MultinomialCalc mn = new MultinomialCalc(rng); 17 | GridWindow win = new GridWindow(cells.xDim, cells.yDim,10); 18 | cells.Set(0, 0, 100000000); 19 | int[] hood = Util.VonNeumannHood(false); 20 | 21 | //main loop 22 | while (true) { 23 | cells.Update(); 24 | 25 | //move cells 26 | for (int i : cells) { 27 | int numMoves = cells.MapHood(hood, i); 28 | mn.Setup(cells.Get(i)); 29 | for (int j = 0; j < numMoves; j++) { 30 | int movepop = mn.Sample(0.1); 31 | cells.Add(i, -movepop); 32 | cells.Add(hood[j], movepop); 33 | } 34 | } 35 | 36 | //draw cells 37 | win.TickPause(0); 38 | for(int i=0;i { 13 | 14 | } 15 | 16 | public class mover3DoffLattice extends AgentGrid3D { 17 | public mover3DoffLattice(int x, int y, int z) { 18 | super(x, y,z, MoveAgentoffLattice.class,false,false,false);//set to true for wraparound 19 | } 20 | 21 | public static void main(String[] args) { 22 | OpenGL3DWindow.MakeMacCompatible(args); 23 | 24 | mover3DoffLattice test=new mover3DoffLattice(10,10,10); 25 | OpenGL3DWindow win3D=new OpenGL3DWindow("3D",500,500,test.xDim,test.yDim,test.zDim); 26 | // GridWindow win2D=new GridWindow("2D",test.xDim,test.yDim,20); 27 | MoveAgentoffLattice ourHero=test.NewAgentSQ(5,5,5); 28 | Rand rn=new Rand(); 29 | double[]moveCoordScratch=new double[3]; 30 | 31 | for (int i = 0; i < 10000; i++) { 32 | win3D.TickPause(10); 33 | rn.RandomPointInSphere(0.4,moveCoordScratch); 34 | ourHero.MoveSafePT(ourHero.Xpt()+moveCoordScratch[0],ourHero.Ypt()+moveCoordScratch[1],ourHero.Zpt()+moveCoordScratch[2]);//random movement 35 | 36 | // win2D.Clear(Util.BLUE); 37 | // win2D.SetPix(ourHero.Xsq(),ourHero.Ysq(), Util.HeatMapRGB(ourHero.Zsq(),0,test.zDim));//draw 2d 38 | 39 | win3D.ClearBox(Util.BLUE,Util.BLACK); 40 | win3D.Circle(ourHero.Xpt(),ourHero.Ypt(),ourHero.Zpt(),0.5,Util.RED);//draw 3d 41 | win3D.Update(); 42 | if(win3D.IsClosed()){//quit if close button is clicked 43 | break; 44 | } 45 | } 46 | win3D.Close();//destroy guis 47 | // win2D.Close(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /LEARN_HERE/Diffusibles/DiffusionAdvection3D.java: -------------------------------------------------------------------------------- 1 | package LEARN_HERE.Diffusibles; 2 | 3 | import HAL.GridsAndAgents.PDEGrid3D; 4 | import HAL.Gui.GridWindow; 5 | import HAL.Util; 6 | 7 | /** 8 | * Created by Rafael on 10/28/2017. 9 | */ 10 | public class DiffusionAdvection3D { 11 | public static void main(String[] args) { 12 | GridWindow win = new GridWindow("advection",20,20,10,true); 13 | PDEGrid3D grid=new PDEGrid3D(20,20,20,true,true,true);//last booleans are for wraparound 14 | grid.Set(grid.xDim/2,grid.yDim/2,grid.zDim/2,1); 15 | while(true){ 16 | win.TickPause(100); 17 | grid.Advection(0.1,0,0.1,0);//advection 18 | grid.Diffusion(0.13);//diffusion 19 | grid.Update(); 20 | win.DrawPDEGridXY(grid, (val)->(Util.HeatMapBGR(val*1000))); 21 | //win.DrawPDEGridXZ(grid, (val)->(Util.HeatMapBGR(val*1000)));//uncomment to view from different angles 22 | //win.DrawPDEGridYZ(grid, (val)->(Util.HeatMapBGR(val*1000))); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /LEARN_HERE/Diffusibles/Gradient2D.java: -------------------------------------------------------------------------------- 1 | package LEARN_HERE.Diffusibles; 2 | 3 | import HAL.GridsAndAgents.PDEGrid2D; 4 | 5 | /** 6 | * Created by Rafael on 10/29/2017. 7 | */ 8 | public class Gradient2D { 9 | public static void main(String[] args) { 10 | int xD=10,yD=10; 11 | PDEGrid2D diff=new PDEGrid2D(xD,yD); 12 | for (int y = 0; y < diff.yDim; y++) { 13 | double setVal=y*1.0/diff.xDim; 14 | for (int x = 0; x < diff.xDim; x++) { 15 | diff.Set(x, y, setVal); 16 | } 17 | } 18 | diff.Update(); 19 | System.out.println("y gradient:"+diff.GradientY(5,5)); 20 | System.out.println("x gradient:"+diff.GradientX(5,5)); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /LEARN_HERE/Diffusibles/Gradient3D.java: -------------------------------------------------------------------------------- 1 | package LEARN_HERE.Diffusibles; 2 | 3 | import HAL.GridsAndAgents.PDEGrid3D; 4 | 5 | /** 6 | * Created by Rafael on 10/29/2017. 7 | */ 8 | public class Gradient3D { 9 | public static void main(String[] args) { 10 | int xD=10,yD=10,zD=10; 11 | PDEGrid3D diff=new PDEGrid3D(xD,yD,zD); 12 | for (int z = 0; z < diff.zDim; z++) { 13 | double setVal=z*1.0/diff.xDim; 14 | for (int y = 0; y < diff.yDim; y++) { 15 | for (int x = 0; x < diff.xDim; x++) { 16 | diff.Set(x, y,z, setVal); 17 | } 18 | } 19 | } 20 | diff.Update(); 21 | System.out.println("x gradient:"+diff.GradientX(5,5,5)); 22 | System.out.println("y gradient:"+diff.GradientY(5,5,5)); 23 | System.out.println("z gradient:"+diff.GradientZ(5,5,5)); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /LEARN_HERE/Diffusibles/ReactionDiffusion2D.java: -------------------------------------------------------------------------------- 1 | package LEARN_HERE.Diffusibles; 2 | 3 | import HAL.GridsAndAgents.PDEGrid2D; 4 | import HAL.Gui.UIGrid; 5 | import HAL.Gui.UILabel; 6 | import HAL.Gui.UIWindow; 7 | import HAL.Gui.TickTimer; 8 | import HAL.Util; 9 | 10 | /** 11 | * Created by rafael on 7/18/17. 12 | */ 13 | public class ReactionDiffusion2D { 14 | static final int x=20; 15 | static final int y=10; 16 | static final int time=10000; 17 | static final int visScale=10; 18 | static final int tickRate=0; 19 | public static void main(String[] args) { 20 | //set up gui 21 | TickTimer trt=new TickTimer(); 22 | UIWindow win=new UIWindow("2D Diffusion VesselOcclusion",true); 23 | UIGrid v1=new UIGrid(x,y,visScale); 24 | UIGrid v2=new UIGrid(x,y,visScale); 25 | win.AddCol(0, new UILabel("advection")); 26 | win.AddCol(0, v1); 27 | win.AddCol(1, new UILabel("diffusion")); 28 | win.AddCol(1, v2); 29 | win.RunGui(); 30 | 31 | //set up grids 32 | PDEGrid2D g1=new PDEGrid2D(x,y); 33 | PDEGrid2D g2=new PDEGrid2D(x,y); 34 | 35 | //run loop 36 | for (int i = 0; i < time; i++) { 37 | win.TickPause(5); 38 | trt.TickPause(tickRate); 39 | //reaction 40 | for (int j = 3; j < y-3; j++) { 41 | g1.Set(10,j,1); 42 | g2.Set(10,j,1); 43 | } 44 | //advection 45 | g1.Advection(0.01,0.01,0); 46 | g1.Update(); 47 | //diffusion 48 | g2.DiffusionADI(0.01); 49 | g2.Update(); 50 | //draw results 51 | v1.DrawPDEGrid(g1, Util::HeatMapRGB); 52 | v2.DrawPDEGrid(g2, Util::HeatMapRGB); 53 | } 54 | win.Close(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /LEARN_HERE/Other/BinomialTest.java: -------------------------------------------------------------------------------- 1 | package LEARN_HERE.Other; 2 | 3 | import HAL.Rand; 4 | 5 | /** 6 | * Created by Rafael on 7/20/2017. 7 | */ 8 | public class BinomialTest { 9 | public static void main(String[] args) { 10 | Rand rn=new Rand(); 11 | System.out.println(rn.Binomial(Long.MAX_VALUE,0.1)*1.0/ Long.MAX_VALUE); 12 | // long[] res=new long[1000000]; 13 | // for (int i = 0; i < 1000000; i++) { 14 | // res[i]=rn.Binomial(Integer.MAX_VALUE,0.001); 15 | // } 16 | // //System.out.println(Util.ArrToString(res,",")); 17 | // System.out.println(Util.SumArray(res)/(Long.MAX_VALUE*((double)res.length))); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /LEARN_HERE/Other/ColorInterpolation.java: -------------------------------------------------------------------------------- 1 | package LEARN_HERE.Other; 2 | 3 | import HAL.Gui.GridWindow; 4 | import HAL.Gui.UIGrid; 5 | 6 | import static HAL.Util.Interpolate2D; 7 | import static HAL.Util.RGB256; 8 | 9 | public class ColorInterpolation { 10 | static double[]c1=new double[]{0,113.9850,188.9550}; 11 | static double[]c2=new double[]{216.75,82.875,24.99}; 12 | static double[]c3=new double[]{236.895,176.97,31.875}; 13 | static double[]c4=new double[]{125.97,46.92,141.78}; 14 | public static double InterpComponent(UIGrid colorMe, int x, int y, int rgbIndex){ 15 | return Interpolate2D(x*1.0/colorMe.xDim, y*1.0/colorMe.yDim, c2[rgbIndex],c4[rgbIndex],c1[rgbIndex],c3[rgbIndex]); 16 | } 17 | public static void ColorPix(UIGrid colorMe, int x, int y){ 18 | colorMe.SetPix(x,y,RGB256((int)InterpComponent(colorMe,x,y,0),(int)InterpComponent(colorMe,x,y,1),(int)InterpComponent(colorMe,x,y,2))); 19 | } 20 | public static void main(String[] args) { 21 | GridWindow colorDisp=new GridWindow(100,100,5); 22 | for (int x = 0; x < colorDisp.xDim; x++) { 23 | for (int y = 0; y < colorDisp.yDim; y++) { 24 | ColorPix(colorDisp,x,y); 25 | } 26 | } 27 | colorDisp.ToPNG("test.png"); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /LEARN_HERE/Other/ColorTest.java: -------------------------------------------------------------------------------- 1 | package LEARN_HERE.Other; 2 | 3 | import static HAL.Util.*; 4 | 5 | /** 6 | * Created by rafael on 7/4/17. 7 | */ 8 | public class ColorTest { 9 | public static void main(String[] args) { 10 | int color=RGB(1,0,0); 11 | System.out.println(ColorString(color)); 12 | color=SetBlue(color,1); 13 | System.out.println(ColorString(color)); 14 | color=SetRed256(color,0); 15 | System.out.println(ColorString(color)); 16 | color=SetGreen256(color,GetBlue256(color)); 17 | System.out.println(ColorString(color)); 18 | color=SetAlpha256(color,0); 19 | System.out.println(ColorString(color)); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /LEARN_HERE/Other/FileIOTest.java: -------------------------------------------------------------------------------- 1 | package LEARN_HERE.Other; 2 | 3 | import HAL.Tools.FileIO; 4 | import HAL.Util; 5 | 6 | /** 7 | * Created by bravorr on 7/5/17. 8 | */ 9 | public class FileIOTest { 10 | public static void main(String[] args) { 11 | FileIO[]outs=new FileIO[1000]; 12 | Util.MakeDirs("fileIOtest"); 13 | for (int i = 0; i < outs.length; i++) { 14 | outs[i]=new FileIO("fileIOtest/test"+i+".csv","w"); 15 | } 16 | for (FileIO o : outs) { 17 | o.Write("test"); 18 | o.Close(); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /LEARN_HERE/Other/GIFtest.java: -------------------------------------------------------------------------------- 1 | package LEARN_HERE.Other; 2 | 3 | import HAL.Gui.GifMaker; 4 | import HAL.Gui.UIGrid; 5 | import HAL.Gui.UIWindow; 6 | import HAL.Util; 7 | 8 | import java.util.Random; 9 | 10 | /** 11 | * Created by bravorr on 6/2/17. 12 | */ 13 | public class GIFtest { 14 | public static void main(String[] args) { 15 | UIWindow testGui=new UIWindow("test",true); 16 | UIGrid ggv=new UIGrid(10,10,100); 17 | Random rn=new Random(); 18 | testGui.AddCol(0, ggv); 19 | ggv.SetPix(4, 4, Util.RGB(rn.nextDouble(),rn.nextDouble(),rn.nextDouble())); 20 | ggv.ToGIF("test.jpg"); 21 | GifMaker gm=new GifMaker("test.gif",100,true); 22 | for (int i = 0; i < 10; i++) { 23 | ggv.SetPix(4, 4, Util.RGB(rn.nextDouble(),rn.nextDouble(),rn.nextDouble())); 24 | gm.AddFrame(ggv); 25 | } 26 | gm.Close(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /LEARN_HERE/Other/GuiExample.java: -------------------------------------------------------------------------------- 1 | package LEARN_HERE.Other; 2 | 3 | import HAL.Gui.*; 4 | 5 | import static HAL.Util.RGB; 6 | 7 | /** 8 | * Created by Rafael on 10/30/2017. 9 | */ 10 | public class GuiExample { 11 | public static void main(String[] args) { 12 | UIWindow win=new UIWindow("exampleMenu",true); 13 | win.AddCol(0,new UIBoolInput("boolean",false)); 14 | win.AddCol(0,new UIDoubleInput("double",0.5,0,2)); 15 | win.AddCol(0,new UIIntInput("int",3,0,5)); 16 | win.AddCol(1,new UIStringInput("string","text")); 17 | win.AddCol(1,new UIComboBoxInput("options",0,new String[]{"option 1","option 2","option 3"})); 18 | win.AddCol(1,new UIFileChooserInput("file chooser","example.txt")); 19 | win.AddCol(0,new UIButton("Print",false,(event)->{ 20 | System.out.println(win.GetBool("boolean")+"\n"+win.GetDouble("double")+"\n"+win.GetInt("int")+"\n"+win.GetString("string")+"\n"+win.GetInt("options")+"\n"+win.GetString("file chooser")); 21 | }).SetColor(RGB(1,0,0),RGB(0,0,1))); 22 | win.RunGui(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /LEARN_HERE/Other/HeatMaps.java: -------------------------------------------------------------------------------- 1 | package LEARN_HERE.Other; 2 | 3 | import HAL.Gui.GridWindow; 4 | 5 | import static HAL.Util.*; 6 | 7 | /** 8 | * Created by Rafael on 10/13/2017. 9 | */ 10 | public class HeatMaps { 11 | public static void main(String[] args) { 12 | GridWindow win=new GridWindow("Colors",100,6,10); 13 | for (int i = 0; i < 6; i++) { 14 | for (int j = 0; j < 100; j++) { 15 | switch (i){ 16 | case 5: 17 | win.SetPix(j,i,HeatMapRGB(j*1.0/100)); 18 | break; 19 | case 4: 20 | win.SetPix(j,i,HeatMapRBG(j*1.0/100)); 21 | break; 22 | case 3: 23 | win.SetPix(j,i,HeatMapGRB(j*1.0/100)); 24 | break; 25 | case 2: 26 | win.SetPix(j,i,HeatMapGBR(j*1.0/100)); 27 | break; 28 | case 1: 29 | win.SetPix(j,i,HeatMapBRG(j*1.0/100)); 30 | break; 31 | case 0: 32 | win.SetPix(j,i,HeatMapBGR(j*1.0/100)); 33 | break; 34 | } 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /LEARN_HERE/Other/LineSegmentTest.java: -------------------------------------------------------------------------------- 1 | package LEARN_HERE.Other; 2 | 3 | import HAL.Gui.OpenGL3DWindow; 4 | 5 | import static HAL.Util.RGB; 6 | 7 | public class LineSegmentTest { 8 | public static void main(String[] args) { 9 | OpenGL3DWindow.MakeMacCompatible(args); 10 | OpenGL3DWindow win=new OpenGL3DWindow("segment",500,500,10,10,10); 11 | while(!win.IsClosed()) { 12 | win.Clear(RGB(0,0,0)); 13 | win.Line(0, 0,0, 10, 10,10, RGB(1, 0, 0)); 14 | //win.LineStrip(new double[]{1,2,3,4},new double[]{4,6,7,4},RGB(0,0,1)); 15 | win.Update(); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /LEARN_HERE/Other/LockExample.java: -------------------------------------------------------------------------------- 1 | package LEARN_HERE.Other; 2 | 3 | import HAL.Tools.FileIO; 4 | import HAL.Util; 5 | 6 | import java.util.concurrent.locks.Lock; 7 | import java.util.concurrent.locks.ReentrantLock; 8 | 9 | public class LockExample { 10 | public static void ConcurrentWrite(FileIO out, Lock lock,boolean isLocking, String text){ 11 | if(isLocking) { 12 | lock.lock(); 13 | } 14 | try{ 15 | out.Write(text); 16 | out.Write(text); 17 | out.Write(text); 18 | }finally { 19 | if(isLocking) { 20 | lock.unlock(); 21 | } 22 | } 23 | 24 | } 25 | public static void main(String[] args) { 26 | FileIO out=new FileIO("LockExample.txt","w"); 27 | Lock lock= new ReentrantLock(); 28 | Util.MultiThread(10,(i)->{ 29 | ConcurrentWrite(out,lock,true,"Thread "+i+" wrote this test bit of text!\n"); 30 | }); 31 | out.Close(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /LEARN_HERE/Other/NonSpatialABM.java: -------------------------------------------------------------------------------- 1 | package LEARN_HERE.Other; 2 | 3 | import HAL.Rand; 4 | import HAL.Util; 5 | 6 | public class NonSpatialABM { 7 | long[]pops; 8 | Rand rng=new Rand(); 9 | long totalPop; 10 | public NonSpatialABM(long[]pops){ 11 | this.pops=pops; 12 | totalPop= Util.ArraySum(pops); 13 | } 14 | 15 | double DivProb(int iPop){return 0.5*Math.pow(0.9,iPop)*(1-totalPop*1.0/10000);} 16 | double DieProb(int iPop){return 0.01;} 17 | double MutProb(int iPop){return 0.1;} 18 | void Step(){ 19 | for (int i = pops.length-1; i >= 0; i--) { 20 | //die 21 | pops[i]-=rng.Binomial(pops[i],DieProb(i)); 22 | //divide 23 | long nDivs=rng.Binomial(pops[i], DivProb(i)); 24 | pops[i]+=nDivs; 25 | //mutate 26 | if(i!=pops.length-1) { 27 | long nMuts = rng.Binomial(nDivs, MutProb(i)); 28 | pops[i]-=nMuts; 29 | pops[i+1]+=nMuts; 30 | } 31 | } 32 | totalPop= Util.ArraySum(pops); 33 | } 34 | 35 | public static void main(String[] args) { 36 | long[]startPops=new long[10]; 37 | startPops[0]=100; 38 | NonSpatialABM model=new NonSpatialABM(startPops); 39 | for (int i = 0; i < 100000; i++) { 40 | model.Step(); 41 | System.out.println(Util.ArrToString(model.pops,",")+","+model.totalPop); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /LEARN_HERE/Other/PNGexample.java: -------------------------------------------------------------------------------- 1 | package LEARN_HERE.Other; 2 | 3 | import HAL.Gui.GridWindow; 4 | import HAL.Util; 5 | 6 | public class PNGexample{ 7 | public static void main(String[] args){ 8 | GridWindow win=new GridWindow(10,10,1); 9 | for(int i=0;igrid.Legend(new String[]{"RED HOT LINE"},new int[]{Util.RED},Util.WHITE,Util.BLACK,grid.xDim/3,grid.yDim-1)); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /LEARN_HERE/Other/vis3Dtest.java: -------------------------------------------------------------------------------- 1 | package LEARN_HERE.Other; 2 | 3 | import HAL.Gui.OpenGL3DWindow; 4 | 5 | import static HAL.Util.GenCirclePoints; 6 | import static HAL.Util.RGB; 7 | 8 | /** 9 | * Created by bravorr on 6/16/17. 10 | */ 11 | class Vis3Dtest { 12 | public static void main(String[] args) { 13 | OpenGL3DWindow.MakeMacCompatible(args); 14 | OpenGL3DWindow v3d=new OpenGL3DWindow("testing", 640,480,20,10,10, true); 15 | float[] circ=GenCirclePoints(0.5f,100); 16 | while(!v3d.IsClosed()) { 17 | v3d.TickPause(0); 18 | v3d.ClearBox(RGB(0.5f, 0.5f, 0.5f),RGB(1,1,1)); 19 | v3d.Circle(20,0,0,1,RGB(1,0,0)); 20 | v3d.Circle(0,30,0,1,RGB(0,1,0)); 21 | v3d.Circle(0,0,10,1,RGB(0,0,1)); 22 | //v3d.CelSphere((double) 5, (double) 5, (double) 10, (double) 1,RGB((double) 1, (double) 0, (double) 0)); 23 | //v3d.CelSphere((double) 0, (double) 0, (double) 10, (double) 1,RGB((double) 0, (double) 1, (double) 0)); 24 | //v3d.CelSphere((double) 10, (double) 10, (double) 0, (double) 1,RGB((double) 0, (double) 0, (double) 1)); 25 | v3d.Update(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /LEARN_HERE/Other/yCbCrTest.java: -------------------------------------------------------------------------------- 1 | package LEARN_HERE.Other; 2 | 3 | import HAL.Gui.GridWindow; 4 | 5 | import static HAL.Util.CbCrPlaneColor; 6 | 7 | /** 8 | * Created by Rafael on 10/12/2017. 9 | */ 10 | public class yCbCrTest { 11 | public static void main(String[] args) { 12 | GridWindow win=new GridWindow("CbCrPlane",100,100,10,true); 13 | for (int x = 0; x < win.xDim; x++) { 14 | for (int y = 0; y < win.yDim; y++) { 15 | win.SetPix(x, y, CbCrPlaneColor(x*1.0/win.xDim,y*1.0/win.yDim)); 16 | } 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Rafael Ramon Bravo 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Testing/ConvergenceTesting/ConvergenceDiffusionAdvection1D.java: -------------------------------------------------------------------------------- 1 | package Testing.ConvergenceTesting; 2 | 3 | 4 | import HAL.GridsAndAgents.PDEGrid1D; 5 | 6 | @FunctionalInterface 7 | public interface ConvergenceDiffusionAdvection1D { 8 | void DiffusionAdvection1D(PDEGrid1D grid,double[]rateConstants); 9 | } 10 | -------------------------------------------------------------------------------- /Testing/ConvergenceTesting/ConvergenceDiffusionAdvection2D.java: -------------------------------------------------------------------------------- 1 | package Testing.ConvergenceTesting; 2 | 3 | 4 | import HAL.GridsAndAgents.PDEGrid2D; 5 | 6 | @FunctionalInterface 7 | public interface ConvergenceDiffusionAdvection2D { 8 | void DiffusionAdvection2D(PDEGrid2D grid,double[]rateConstants); 9 | } 10 | -------------------------------------------------------------------------------- /Testing/ConvergenceTesting/ConvergenceDiffusionAdvection3D.java: -------------------------------------------------------------------------------- 1 | package Testing.ConvergenceTesting; 2 | 3 | 4 | import HAL.GridsAndAgents.PDEGrid3D; 5 | 6 | @FunctionalInterface 7 | public interface ConvergenceDiffusionAdvection3D { 8 | void DiffusionAdvection3D(PDEGrid3D grid, double[]rateConstants); 9 | } 10 | -------------------------------------------------------------------------------- /Testing/ConvergenceTesting/ConvergencePlotAdvectionGaussian.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/Testing/ConvergenceTesting/ConvergencePlotAdvectionGaussian.png -------------------------------------------------------------------------------- /Testing/ConvergenceTesting/ConvergenceReaction1D.java: -------------------------------------------------------------------------------- 1 | package Testing.ConvergenceTesting; 2 | 3 | @FunctionalInterface 4 | public interface ConvergenceReaction1D { 5 | public double React(double x,int t,double value,double spaceStep); 6 | } 7 | -------------------------------------------------------------------------------- /Testing/ConvergenceTesting/ConvergenceReaction2D.java: -------------------------------------------------------------------------------- 1 | package Testing.ConvergenceTesting; 2 | 3 | @FunctionalInterface 4 | public interface ConvergenceReaction2D { 5 | public double React(double x,double y, int t, double value, double spaceStep); 6 | } 7 | -------------------------------------------------------------------------------- /Testing/ConvergenceTesting/ConvergenceReaction3D.java: -------------------------------------------------------------------------------- 1 | package Testing.ConvergenceTesting; 2 | 3 | @FunctionalInterface 4 | public interface ConvergenceReaction3D { 5 | public double React(double x, double y, double z,int t, double value, double spaceStep); 6 | } 7 | -------------------------------------------------------------------------------- /Testing/ConvergenceTesting/Dx.txt: -------------------------------------------------------------------------------- 1 | 1.0,3.0,9.0,27.0 -------------------------------------------------------------------------------- /Testing/ConvergenceTesting/L1.txt: -------------------------------------------------------------------------------- 1 | 0.01818459276284306,0.00219239743806956,2.912337454093649E-4 -------------------------------------------------------------------------------- /Testing/ConvergenceTesting/L2.txt: -------------------------------------------------------------------------------- 1 | 0.002172275659245687,2.662396941026965E-4,3.6354206277229826E-5 -------------------------------------------------------------------------------- /Testing/ConvergenceTesting/Linf.txt: -------------------------------------------------------------------------------- 1 | 7.481439158607273E-4,9.740851490838698E-5,5.542745690867434E-6 -------------------------------------------------------------------------------- /Testing/KernelTest.java: -------------------------------------------------------------------------------- 1 | package Testing; 2 | 3 | import HAL.GridsAndAgents.Grid2Ddouble; 4 | import HAL.Gui.GridWindow; 5 | import HAL.Gui.UIGrid; 6 | import HAL.Util; 7 | import HAL.GridsAndAgents.KernelGrid; 8 | 9 | import static HAL.Util.GaussianPDF; 10 | 11 | public class KernelTest { 12 | 13 | static public void PullKernel(KernelGrid g, UIGrid win){ 14 | for (int x = 0; x < win.xDim; x++) { 15 | for (int y = 0; y < win.yDim; y++) { 16 | win.SetPix((x+win.xDim/2)%win.xDim,(y+win.yDim/2)%win.yDim, Util.GreyScale(g.GetKernel(x,y))); 17 | } 18 | } 19 | } 20 | 21 | public static Grid2Ddouble SquareDomain(){ 22 | Grid2Ddouble domain=new Grid2Ddouble(16,16); 23 | for (int x = 4; x < 13; x++) { 24 | for (int y = 4; y < 13; y++) { 25 | domain.Set(x,y,1.0); 26 | } 27 | } 28 | return domain; 29 | } 30 | 31 | public static Grid2Ddouble LineDomain(){ 32 | Grid2Ddouble domain=new Grid2Ddouble(16,16); 33 | for (int x = 8; x < 9; x++) { 34 | for (int y = 4; y < 13; y++) { 35 | domain.Set(x,y,1.0); 36 | } 37 | } 38 | return domain; 39 | } 40 | 41 | static public void PullOut(Grid2Ddouble grid,UIGrid win){ 42 | for (int i = 0; i < win.length; i++) { 43 | win.SetPix(i,Util.GreyScale(grid.Get(i))); 44 | } 45 | } 46 | 47 | public static void main(String[] args) { 48 | KernelGrid g= new KernelGrid((r)->r<5?GaussianPDF(0,2,r):0,16,true); 49 | GridWindow win =new GridWindow(g.xDim,g.yDim,10); 50 | Grid2Ddouble domain=LineDomain(); 51 | PullKernel(g,win); 52 | g.Convolve(domain); 53 | win.ToPNG("KernelGridExampleKernel.png"); 54 | PullOut(domain,win); 55 | win.ToPNG("KernelGridExampleStart.png"); 56 | PullOut(g.out,win); 57 | win.ToPNG("KernelGridExampleEnd.png"); 58 | win.Close(); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Testing/OldTests/ADITest.java: -------------------------------------------------------------------------------- 1 | package Testing.OldTests; 2 | 3 | import HAL.GridsAndAgents.PDEGrid2D; 4 | import HAL.Gui.GridWindow; 5 | import HAL.Gui.UIGrid; 6 | import HAL.Util; 7 | 8 | public class ADITest { 9 | public static void main(String[] args) { 10 | PDEGrid2D g=new PDEGrid2D(100,100); 11 | GridWindow win=new GridWindow(100,100,10); 12 | while(true){ 13 | g.DiffusionADI(0.1, 1.0); 14 | for (int i = 0; i < g.length; i++) { 15 | g.Scale(i, 0.99); 16 | } 17 | g.Update(); 18 | for (int i = 0; i < win.length; i++) { 19 | win.SetPix(i,Util.HeatMapJet(g.Get(i))); 20 | } 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Testing/OldTests/AdvectionTest1D.java: -------------------------------------------------------------------------------- 1 | package Testing.OldTests; 2 | 3 | import HAL.GridsAndAgents.PDEGrid3D; 4 | import HAL.Gui.GridWindow; 5 | import HAL.Util; 6 | 7 | import static HAL.Util.HeatMapRGB; 8 | 9 | public class AdvectionTest1D { 10 | public static void main(String[] args) { 11 | GridWindow win=new GridWindow(100,10,10); 12 | PDEGrid3D grid=new PDEGrid3D(100,10,10); 13 | while(true){ 14 | win.TickPause(0); 15 | grid.Advection(0.1,0.1,0.1,0); 16 | grid.Set(0,1); 17 | grid.Update(); 18 | win.DrawPDEGridXY(grid, Util::HeatMapRGB); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Testing/OldTests/AgentListTest.java: -------------------------------------------------------------------------------- 1 | package Testing.OldTests; 2 | 3 | import HAL.GridsAndAgents.AgentGrid2D; 4 | import HAL.GridsAndAgents.AgentList; 5 | import HAL.GridsAndAgents.AgentSQ2D; 6 | import HAL.Rand; 7 | 8 | class Cell2 extends AgentSQ2D { 9 | 10 | } 11 | 12 | public class AgentListTest { 13 | public static void main(String[] args) { 14 | Rand rng=new Rand(); 15 | AgentGrid2D cells = new AgentGrid2D(50,50,Cell2.class); 16 | AgentList cellList = new AgentList<>(); 17 | cellList.AddAgent(cells.NewAgentSQ(0)); 18 | cellList.AddAgent(cells.NewAgentSQ(0)); 19 | cellList.AddAgent(cells.NewAgentSQ(0)); 20 | cellList.AddAgent(cells.NewAgentSQ(0)); 21 | cells.RandomAgent(rng).Dispose(); 22 | cellList.RandomAgent(rng); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Testing/OldTests/AgetGrid0DTest.java: -------------------------------------------------------------------------------- 1 | package Testing.OldTests; 2 | 3 | import HAL.GridsAndAgents.Agent0D; 4 | import HAL.GridsAndAgents.AgentGrid0D; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | 10 | class AgentGrid0DAgent extends Agent0D{ 11 | 12 | } 13 | 14 | public class AgetGrid0DTest { 15 | public static void main(String[] args) { 16 | AgentGrid0D g=new AgentGrid0D<>(AgentGrid0DAgent.class); 17 | g.NewAgent(); 18 | List l=g.AllAgents(); 19 | System.out.println(l.get(0)); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Testing/OldTests/BitGenomeTest.java: -------------------------------------------------------------------------------- 1 | package Testing.OldTests; 2 | 3 | import HAL.Rand; 4 | import HAL.Util; 5 | 6 | /** 7 | * Created by rafael on 7/23/17. 8 | */ 9 | public class BitGenomeTest { 10 | public static void main(String[] args) { 11 | int[] geneSizes=new int[]{10000,10000,10000,10000,10000,10000,10000,10000,10000,10000}; 12 | double[] probs=new double[]{0.9,0.01,0.01,0.01,0.01,0.01,0.01,0.01,0.01,0.02}; 13 | int[]geneLocs=new int[geneSizes.length+1]; 14 | int[] geneHits=new int[10]; 15 | int[] baseHits=new int[10]; 16 | Rand rn=new Rand(); 17 | 18 | System.out.println(Util.ArrToString(geneHits,",")); 19 | System.out.println(Util.ArrToString(baseHits,",")); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Testing/OldTests/CircleHoodTest.java: -------------------------------------------------------------------------------- 1 | package Testing.OldTests; 2 | 3 | import HAL.Util; 4 | 5 | public class CircleHoodTest { 6 | public static void main(String[] args) { 7 | System.out.println(Util.CircleHood(true,12).length/3); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Testing/OldTests/ConvectionTest.java: -------------------------------------------------------------------------------- 1 | package Testing.OldTests; 2 | 3 | import HAL.GridsAndAgents.PDEGrid2D; 4 | import HAL.Gui.UIGrid; 5 | import HAL.Gui.UIWindow; 6 | import HAL.Gui.TickTimer; 7 | import HAL.Util; 8 | 9 | /** 10 | * Created by bravorr on 7/21/17. 11 | */ 12 | public class ConvectionTest { 13 | static int x=40; 14 | static int y=40; 15 | static int steps=1000000; 16 | static int time=0; 17 | public static void main(String[] args) { 18 | UIWindow win=new UIWindow("ConvectionTest",true); 19 | UIGrid ggv=new UIGrid(x,y,20); 20 | double[] xVels=new double[x*y]; 21 | double[] yVels=new double[x*y]; 22 | for (int xi = 0; xi < x; xi++) { 23 | for (int yi = 0; yi < y; yi++) { 24 | 25 | // xVels[xi*y+yi]=0.9; 26 | // } 27 | if(Math.abs(yi-y/2)>Math.abs(xi-x/2)){ 28 | //at x disp case 29 | if(yi{ 60 | return Util.HeatMapRBG(Util.ScaleMinToMax(val, (double) 0, (double) 1)); 61 | }); 62 | //g.ConvInhomogeneousSwap(xVels,yVels); 63 | g.Advection(0.001,0.001,0); 64 | } 65 | win.Close(); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /Testing/OldTests/ConvectionTest2.java: -------------------------------------------------------------------------------- 1 | package Testing.OldTests; 2 | 3 | import HAL.GridsAndAgents.PDEGrid2D; 4 | import HAL.Gui.UIGrid; 5 | import HAL.Gui.UILabel; 6 | import HAL.Gui.UIWindow; 7 | import HAL.Gui.TickTimer; 8 | import HAL.Util; 9 | 10 | public class ConvectionTest2 { 11 | static int sideLen=1000; 12 | static int steps=100000; 13 | public static void Setup(PDEGrid2D g, double[]diffRates){ 14 | for (int x = 1; x < 11; x++) { 15 | for (int y = 1; y < 11; y++) { 16 | g.Set(x,y,1); 17 | } 18 | } 19 | for (int i = 0; i < diffRates.length; i++) { 20 | if(g.ItoX(i)>g.xDim/2) { 21 | diffRates[i] = 0.1; 22 | } 23 | else{ 24 | diffRates[i]=0.2; 25 | } 26 | } 27 | } 28 | public static void main(String[] args) { 29 | PDEGrid2D g=new PDEGrid2D(sideLen,sideLen,false,false); 30 | UIWindow win=new UIWindow("Advection1stOrder Example",true); 31 | UIGrid vis=new UIGrid(sideLen,sideLen,1); 32 | UILabel lbl=new UILabel("tick"); 33 | TickTimer trt=new TickTimer(); 34 | double[]diffRates=new double[g.length]; 35 | win.AddCol(0, lbl); 36 | win.AddCol(0, vis); 37 | win.RunGui(); 38 | Setup(g,diffRates); 39 | for (int i = 0; i < steps; i++) { 40 | trt.TickPause(0); 41 | //g.Advection1stOrder(0.01,0); 42 | g.Diffusion(0.1,1); 43 | //g.MultiThread(4,(x,y,j)->{ 44 | // Util.Diffusion2(x,y,g.GetField(),g.GetSwapField(),g.xDim,g.yDim,0.1,true,1,false,false); 45 | //}); 46 | g.Diffusion(0.1,1); 47 | vis.DrawPDEGrid(g,(val)->{ 48 | return Util.HeatMapRBG(Util.ScaleMinToMax(val, (double) 0, (double) 1)); 49 | }); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Testing/OldTests/ConvergenceTestAdvection.java: -------------------------------------------------------------------------------- 1 | package Testing.OldTests; 2 | 3 | import HAL.GridsAndAgents.PDEGrid2D; 4 | import HAL.Gui.GridWindow; 5 | 6 | import static HAL.Util.CircleHood; 7 | import static HAL.Util.HeatMapBRG; 8 | 9 | /** 10 | * Created by Rafael on 10/19/2017. 11 | */ 12 | 13 | //public class AdvectionSolver { 14 | // 15 | //} 16 | 17 | public class ConvergenceTestAdvection { 18 | 19 | 20 | public static void main(String[] args) { 21 | int spaceScale = 2; 22 | int xDim = 50, yDim = 8; 23 | for (int k=0;k<4;k++) { 24 | spaceScale=2*spaceScale; 25 | GridWindow win = new GridWindow("diffusion ex", spaceScale*xDim, spaceScale*yDim, 64/spaceScale); 26 | PDEGrid2D diff = new PDEGrid2D(xDim*spaceScale, yDim*spaceScale, true, true); 27 | 28 | //initial condition here 29 | int[] circleCoords = CircleHood(true, 4 * spaceScale); 30 | int nPositions = diff.MapHood(circleCoords, diff.xDim / 2, diff.yDim / 2); 31 | for (int i = 0; i < nPositions; i++) { 32 | diff.Set(circleCoords[i], 1); 33 | } 34 | double[] xVels = new double[diff.length]; 35 | double[] yVels = new double[diff.length]; 36 | for (int x = 0; x < diff.xDim; x++) { 37 | for (int y = 0; y < diff.yDim; y++) { 38 | //if(x>0.) 39 | //xVels[diff.I(x,y)]=((x+0.1)*0.01)/xDim; 40 | //xVels[diff.I(x,y)]=0.1*(1-Math.cos(Math.PI*(x-diff.xDim/2)/(diff.xDim))/2); 41 | xVels[diff.I(x, y)] = 0.1; 42 | // if (x>3*diff.xDim/4) { 43 | // xVels[diff.I(x, y)] = -0.1; 44 | // } 45 | 46 | //yVels[diff.I(x, y)] = 0; 47 | } 48 | 49 | } 50 | for (int i = 0; i < 500; i++) { 51 | 52 | win.TickPause(10); 53 | //step condition here 54 | for (int j = 0; j < spaceScale; j++) { 55 | diff.Advection(xVels, yVels); 56 | } 57 | System.out.println(diff.GetAvg()); 58 | 59 | //draw 60 | for (int x = 0; x < win.xDim; x++) { 61 | for (int y = 0; y < win.yDim; y++) { 62 | win.SetPix(x, y, HeatMapBRG(diff.Get(x , y ))); 63 | } 64 | } 65 | } 66 | } 67 | 68 | } 69 | } 70 | 71 | -------------------------------------------------------------------------------- /Testing/OldTests/CrankTest.java: -------------------------------------------------------------------------------- 1 | package Testing.OldTests; 2 | 3 | import HAL.GridsAndAgents.PDEGrid3D; 4 | import HAL.Gui.GridWindow; 5 | import HAL.Util; 6 | 7 | public class CrankTest { 8 | public static void main(String[] args) { 9 | GridWindow win=new GridWindow(8,9,50); 10 | PDEGrid3D grid=new PDEGrid3D(8,9,10,false,false,false); 11 | for (int i = 0; i < grid.zDim; i++) { 12 | grid.Set(0,0,i,10); 13 | } 14 | grid.Update(); 15 | for (int i = 0; true; i++) { 16 | for (int x = 0; x < grid.xDim; x++) { 17 | for (int y = 0; y < grid.yDim; y++) { 18 | win.SetPix(x,y,Util.HeatMapRGB(grid.Get(x,y,0))); 19 | } 20 | } 21 | System.out.println(grid.GetAvg()); 22 | grid.DiffusionADI(0.1); 23 | //grid.DiffusionCrank(200,(x)->{ 24 | // if(x==-1){ 25 | // return 1; 26 | // } 27 | // return 0; 28 | //}); 29 | grid.Update(); 30 | win.TickPause(100); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Testing/OldTests/CubeTest.java: -------------------------------------------------------------------------------- 1 | package Testing.OldTests; 2 | 3 | import HAL.Gui.OpenGL3DWindow; 4 | import HAL.Util; 5 | 6 | public class CubeTest { 7 | public static void main(String[] args) { 8 | if(OpenGL3DWindow.MakeMacCompatible(args)){ 9 | return; 10 | } 11 | OpenGL3DWindow win =new OpenGL3DWindow(500,500,10,10,10); 12 | while(!win.IsClosed()){ 13 | win.ClearBox(Util.BLACK,Util.WHITE); 14 | // win.Cube(2,6,2,6,2,6,Util.RED); 15 | win.Voxel(1,1,1,Util.RED); 16 | win.Update(); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Testing/OldTests/DiffAnalyticalTest.java: -------------------------------------------------------------------------------- 1 | package Testing.OldTests; 2 | 3 | /** 4 | * Created by Rafael on 8/7/2017. 5 | */ 6 | public class DiffAnalyticalTest { 7 | } 8 | -------------------------------------------------------------------------------- /Testing/OldTests/DiffTest3D.java: -------------------------------------------------------------------------------- 1 | package Testing.OldTests; 2 | 3 | import HAL.GridsAndAgents.PDEGrid3D; 4 | import HAL.Gui.GridWindow; 5 | import HAL.Util; 6 | 7 | public class DiffTest3D { 8 | public static void main(String[] args) { 9 | PDEGrid3D grid3D=new PDEGrid3D(100,10,100,false,false,false); 10 | GridWindow win =new GridWindow("testing",100,100,5); 11 | while(true){ 12 | //pick a random position to test 13 | //for (int x = 0; x < grid3D.xDim; x++) { 14 | // for (int y = 0; y < grid3D.yDim; y++) { 15 | // grid3D.SetPix(x,y,0,1); 16 | // } 17 | //} 18 | win.TickPause(10); 19 | grid3D.Advection(0.1,0.1,0.1,0); 20 | grid3D.Set(345,1); 21 | grid3D.Update(); 22 | win.DrawPDEGridXZ(grid3D,(val)-> Util.HeatMapRGB(val, (double) 0, (double) 1)); 23 | } 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Testing/OldTests/DiffusionDisc1D.java: -------------------------------------------------------------------------------- 1 | package Testing.OldTests; 2 | 3 | import HAL.GridsAndAgents.PDEGrid1D; 4 | import HAL.Gui.GridWindow; 5 | import HAL.Util; 6 | 7 | public class DiffusionDisc1D { 8 | public static void main(String[] args) { 9 | PDEGrid1D pde=new PDEGrid1D(10); 10 | double[]diffRates=new double[10]; 11 | for (int i = 0; i < diffRates.length; i++) { 12 | diffRates[i]=0.1; 13 | } 14 | GridWindow win=new GridWindow(10,1,100); 15 | diffRates[4]=0.01; 16 | for (int i = 0; i < 100000; i++) { 17 | pde.Diffusion(diffRates,(int x)->{ if(x<0)return 1;else return 0;} ,(int x)->0.1); 18 | pde.Update(); 19 | for (int j = 0; j < win.length; j++) { 20 | win.SetPix(j,Util.HeatMapRGB(pde.Get(j))); 21 | } 22 | win.TickPause(10); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Testing/OldTests/DiffusionExampleSimple.java: -------------------------------------------------------------------------------- 1 | package Testing.OldTests; 2 | 3 | import HAL.GridsAndAgents.Grid2Ddouble; 4 | import HAL.GridsAndAgents.PDEGrid2D; 5 | import HAL.Gui.GridWindow; 6 | 7 | import static HAL.Util.*; 8 | 9 | /** 10 | * Created by Rafael on 10/19/2017. 11 | */ 12 | public class DiffusionExampleSimple { 13 | public static void main(String[] args) { 14 | //int spaceScale = 10; 15 | int xDim = 500, yDim = 500; 16 | GridWindow win = new GridWindow("diffusion ex", xDim, yDim,1); 17 | PDEGrid2D diff = new PDEGrid2D(xDim, yDim, true, true); 18 | Grid2Ddouble xVels= new Grid2Ddouble(diff.xDim,diff.yDim); 19 | Grid2Ddouble yVels= new Grid2Ddouble(diff.xDim,diff.yDim); 20 | for (int x = 0; x < diff.xDim; x++) { 21 | for (int y = 0; y < diff.yDim; y++) { 22 | // if(x>diff.xDim/2){ 23 | // xVels.Set(x,y,-0.5); 24 | // } 25 | // else{ 26 | // xVels.Set(x,y,0.5); 27 | // } 28 | // if(y>diff.yDim/2){ 29 | // yVels.Set(x,y,-0.5); 30 | // } 31 | // else{ 32 | // yVels.Set(x,y,0.5); 33 | // } 34 | if(y>=x&&diff.yDim-y>=x){ 35 | yVels.Set(x,y,0.2); 36 | } 37 | if(x>=y&&diff.yDim-y>=x){ 38 | xVels.Set(x,y,-0.2); 39 | } 40 | if(x>y&&diff.yDim-y { 11 | 12 | } 13 | public class MovementTest extends AgentGrid2D { 14 | public MovementTest(int x, int y) { 15 | super(x, y, Mover2D.class); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Testing/OldTests/MultinomialTest.java: -------------------------------------------------------------------------------- 1 | package Testing.OldTests; 2 | 3 | import HAL.Rand; 4 | import HAL.Tools.MultinomialCalc; 5 | import HAL.Util; 6 | 7 | import java.util.Arrays; 8 | 9 | public class MultinomialTest{ 10 | public static void main(String[] args){ 11 | Rand rng=new Rand(); 12 | // MultinomialCalc mn=new MultinomialCalc(rng); 13 | int[] out=new int[3]; 14 | double[] probs=new double[]{0.12454966713960078,0.10666159287850284,0.7687887399818963}; 15 | for(int i=0;i<10;i++){ 16 | rng.Multinomial(probs,1,out); 17 | // mn.Setup(1); 18 | // for(int j=0;j<3;j++){ 19 | // out[j]=mn.Sample(probs[j]); 20 | // } 21 | System.out.println(Util.ArrToString(out,",")); 22 | Arrays.fill(out,0); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Testing/OldTests/MutlinomialTest.java: -------------------------------------------------------------------------------- 1 | package Testing.OldTests; 2 | 3 | import HAL.Rand; 4 | import HAL.Util; 5 | 6 | public class MutlinomialTest { 7 | public static void main(String[] args) { 8 | Rand rng=new Rand(); 9 | int[]ret=new int[3]; 10 | rng.Multinomial(new double[]{0.0,0.5,0.5},1,ret); 11 | System.out.println( rng.Binomial(1,0.5)); 12 | System.out.println(Util.ArrToString(ret,",")); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Testing/OldTests/ODEtest.java: -------------------------------------------------------------------------------- 1 | package Testing.OldTests; 2 | 3 | import HAL.Gui.PlotLine; 4 | import HAL.Gui.PlotWindow; 5 | import HAL.Tools.ODESolver.ODESolver; 6 | 7 | import java.util.ArrayList; 8 | 9 | import static HAL.Util.RED; 10 | 11 | public class ODEtest { 12 | 13 | public static void Equation(double t, double[] state, double[] out){ 14 | out[0]=Math.sin(t)*t; 15 | //out[0]=state[0]*state[0]+1; 16 | //out[0]=state[0]-t*t+1; 17 | //integral: x^2+1 = x^3/3 + x 18 | } 19 | public static void main(String[] args) { 20 | ODESolver s=new ODESolver(); 21 | ArrayListstates=new ArrayList<>(); 22 | ArrayListts=new ArrayList<>(); 23 | ts.add(0.0); 24 | states.add(new double[]{0.5}); 25 | 26 | //s.Runge45(state,0,1.4,2E-5,0.1); 27 | //s.Runge45(state,0,1.4,2E-5,0.2); 28 | s.Runge45(ODEtest::Equation,states,ts,100,2E-5,0.2,0); 29 | PlotWindow win=new PlotWindow(100,100,5); 30 | PlotLine pl=new PlotLine(win,RED); 31 | for (int i = 0; i < states.size(); i++) { 32 | pl.AddSegment(ts.get(i),states.get(i)[0]); 33 | //win.Point(ts.get(i),states.get(i)[0],RED); 34 | } 35 | } 36 | } 37 | //testing comment -------------------------------------------------------------------------------- /Testing/OldTests/OnVsOffLatticeSpeedTest.java: -------------------------------------------------------------------------------- 1 | package Testing.OldTests; 2 | 3 | import HAL.GridsAndAgents.SphericalAgent2D; 4 | import HAL.GridsAndAgents.AgentGrid2D; 5 | import HAL.GridsAndAgents.AgentSQ2Dunstackable; 6 | import HAL.Rand; 7 | 8 | import java.util.ArrayList; 9 | import java.util.Random; 10 | 11 | import static HAL.Util.*; 12 | 13 | /** 14 | * Created by Rafael on 8/2/2017. 15 | */ 16 | 17 | class OnLatticeGrid extends AgentGrid2D { 18 | Rand rn; 19 | int[] mooreHood=MooreHood(false); 20 | OnLatticeGrid(int x,int y,int pop){ 21 | super(x,y,OnLatticeCell.class); 22 | int[] popIs=new int[length]; 23 | rn=new Rand(); 24 | for (int i = 0; i < length; i++) { 25 | popIs[i]=i; 26 | } 27 | rn.Shuffle(popIs, length, pop); 28 | for (int i = 0; i < pop; i++) { 29 | NewAgentSQ(popIs[i]); 30 | } 31 | } 32 | void Step(){ 33 | for (OnLatticeCell c : this) { 34 | int nLocs=MapHood(mooreHood,c.Isq()); 35 | c.chosenI=mooreHood[rn.Int(nLocs)]; 36 | } 37 | } 38 | } 39 | 40 | class OnLatticeCell extends AgentSQ2Dunstackable { 41 | int chosenI; 42 | } 43 | 44 | class OffLatticeCell extends SphericalAgent2D {} 45 | 46 | class OffLatticeGrid extends AgentGrid2D { 47 | Random rn; 48 | double cellRad=0.3; 49 | ArrayList cellScratch; 50 | double interactionRad=cellRad*2; 51 | double forceExp=2; 52 | double forceMul=1; 53 | double friction=0.1; 54 | OffLatticeGrid(int x,int y,int pop){ 55 | super(x,y,OffLatticeCell.class); 56 | rn=new Random(); 57 | for (int i = 0; i < pop; i++) { 58 | double xChild=rn.nextDouble()*xDim; 59 | double yChild=rn.nextDouble()*yDim; 60 | NewAgentPT(xChild,yChild); 61 | } 62 | } 63 | void Step(){ 64 | for (OffLatticeCell c : this) { 65 | c.SumForces(cellRad*2,(overlap,agent)->Math.abs(Math.pow(overlap/interactionRad,forceExp))*forceMul); 66 | } 67 | for (OffLatticeCell c : this) { 68 | c.ApplyFriction(friction); 69 | c.ForceMove(); 70 | } 71 | } 72 | } 73 | 74 | 75 | public class OnVsOffLatticeSpeedTest {//compares looking around an on-lattice neighborhood vs resolving forces 76 | public static void main(String[] args) { 77 | int[]pops=new int[]{10,100,1000,2000,3000}; 78 | for (int j = 0; j < pops.length; j++) { 79 | System.out.println("testing" + pops[j]); 80 | OnLatticeGrid olg = new OnLatticeGrid(100, 100, pops[j]); 81 | double start = System.currentTimeMillis(); 82 | for (int i = 0; i < 100000; i++) { 83 | olg.Step(); 84 | } 85 | System.out.println(System.currentTimeMillis() - start); 86 | OffLatticeGrid flg = new OffLatticeGrid(100, 100, pops[j]); 87 | start = System.currentTimeMillis(); 88 | for (int i = 0; i < 100000; i++) { 89 | flg.Step(); 90 | } 91 | System.out.println(System.currentTimeMillis() - start); 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /Testing/OldTests/PDEtest2.java: -------------------------------------------------------------------------------- 1 | package Testing.OldTests; 2 | 3 | import HAL.GridsAndAgents.PDEGrid2D; 4 | import HAL.Gui.GridWindow; 5 | import HAL.Util; 6 | 7 | public class PDEtest2 { 8 | public static void main(String[] args) { 9 | PDEGrid2D test1 = new PDEGrid2D(100, 100); 10 | PDEGrid2D test2 = new PDEGrid2D(100, 100); 11 | GridWindow win = new GridWindow(200, 100, 5); 12 | for (int i = 0; i < 1000; i++) { 13 | for (int x = 0; x < 200; x++) { 14 | for (int y = 0; y < 100; y++) { 15 | if(x<100){ 16 | win.SetPix(x,y, Util.HeatMapGBR(test1.Get(x,y))); 17 | } 18 | else{ 19 | win.SetPix(x,y,Util.HeatMapRGB(test1.Get(x-100,y))); 20 | } 21 | } 22 | } 23 | win.TickPause(10); 24 | test1.Diffusion(0.1,1); 25 | test1.Diffusion(0.1,1); 26 | test2.Diffusion(0.2,1); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Testing/OldTests/PMFtests.java: -------------------------------------------------------------------------------- 1 | package Testing.OldTests; 2 | 3 | import HAL.Util; 4 | 5 | public class PMFtests { 6 | static void NormalVsBinomial(int n,double p,int k){ 7 | System.out.println(Util.BinomialDistPDF(n,p,k)+","+Util.GaussianPDF(n*p,Math.sqrt(n*0.5*0.5),k)); 8 | } 9 | public static void main(String[] args) { 10 | 11 | NormalVsBinomial(2,0.5,1); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Testing/OldTests/Painter.java: -------------------------------------------------------------------------------- 1 | package Testing.OldTests; 2 | 3 | import HAL.Gui.GridWindow; 4 | import HAL.Interfaces.KeyResponse; 5 | 6 | import java.awt.event.MouseAdapter; 7 | import java.awt.event.MouseEvent; 8 | 9 | import static HAL.Util.*; 10 | 11 | public class Painter extends GridWindow { 12 | public Painter(String title, int xDim, int yDim, int scaleFactor) { 13 | super(title, xDim, yDim, scaleFactor); 14 | } 15 | short ToShort(){ 16 | short out=0; 17 | for (int i = 0; i < length; i++) { 18 | if(IsSet(i)){ 19 | out+=1<>i&1)==0){ 27 | SetPix(i,cOff); 28 | } 29 | else{ 30 | SetPix(i,cOn); 31 | } 32 | } 33 | } 34 | 35 | public boolean IsSet(int i){ 36 | return GetRed(this.GetPix(i))!=0; 37 | } 38 | public static void main(String[] args) { 39 | Painter win=new Painter("painter",3,5,100); 40 | win.AddMouseListeners(new MouseAdapter() { 41 | @Override 42 | public void mousePressed(MouseEvent e) { 43 | System.out.println(win.ClickXsq(e)+""); 44 | int i=win.I(win.ClickXsq(e),win.ClickYsq(e)); 45 | if(win.IsSet(i)){ 46 | win.SetPix(i,BLACK); 47 | } 48 | else{ 49 | win.SetPix(i,RED); 50 | } 51 | System.out.println(win.ToShort()); 52 | } 53 | }); 54 | win.AddKeyResponses(new KeyResponse() { 55 | @Override 56 | public void Response(char c, int keyCode) { 57 | System.out.println(keyCode); 58 | win.SetChar(c,0,4,GREEN,BLUE); 59 | } 60 | },null); 61 | //public void RunEvent(KeyEvent e) { 62 | // if(e.getID()==KeyEvent.KEY_RELEASED){ 63 | // switch (e.getKeyChar()){ 64 | // case 'c':win.Clear(BLACK);break; 65 | // case 's': System.out.println(win.ToShort());break; 66 | // } 67 | // } 68 | //} 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Testing/OldTests/ParticleExample.java: -------------------------------------------------------------------------------- 1 | package Testing.OldTests; 2 | 3 | import HAL.GridsAndAgents.AgentGrid2D; 4 | import HAL.Gui.GridWindow; 5 | import HAL.GridsAndAgents.SphericalAgent2D; 6 | import HAL.Gui.UIGrid; 7 | import HAL.Util; 8 | 9 | import java.util.Random; 10 | 11 | /** 12 | * Created by Rafael on 9/29/2017. 13 | */ 14 | 15 | class Particle extends SphericalAgent2D{ 16 | void Init(){ 17 | radius=0.3; 18 | } 19 | void Step1(){ 20 | SumForces(radius*2,(double overlap,Particle other)->{ 21 | return overlap; 22 | }); 23 | } 24 | void Step2(){ 25 | ForceMove(); 26 | } 27 | } 28 | 29 | public class ParticleExample extends AgentGrid2D { 30 | Random rn=new Random(); 31 | 32 | public ParticleExample(int x, int y){ 33 | super(x, y, Particle.class); 34 | for (int i = 0; i < 100; i++) { 35 | Particle p=NewAgentPT(rn.nextDouble()*xDim,rn.nextDouble()*yDim); 36 | p.Init(); 37 | } 38 | } 39 | public void Draw(UIGrid vis){ 40 | for (int x = 0; x < xDim; x++) { 41 | for (int y = 0; y < yDim; y++) { 42 | Particle p=GetAgent(x/5,y/5); 43 | if(p!=null){ 44 | vis.SetPix(x, y, Util.RGB((double) 1, (double) 1, (double) 1)); 45 | } 46 | else{ 47 | vis.SetPix(x, y, Util.RGB((double) 0, (double) 0, (double) 0)); 48 | } 49 | } 50 | } 51 | } 52 | public void Step(){ 53 | for (Particle p: this) { 54 | p.Step1(); 55 | } 56 | for (Particle p: this) { 57 | p.Step2(); 58 | } 59 | } 60 | 61 | public static void main(String[] args) { 62 | GridWindow win = new GridWindow("particles",50,50,1); 63 | ParticleExample ex=new ParticleExample(10,10); 64 | for (int i = 0; i < 1000; i++) { 65 | win.TickPause(100); 66 | ex.Step(); 67 | ex.Draw(win); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Testing/OldTests/PlotLineTest.java: -------------------------------------------------------------------------------- 1 | package Testing.OldTests; 2 | 3 | import HAL.Gui.PlotLine; 4 | import HAL.Gui.PlotWindow; 5 | import HAL.Util; 6 | 7 | public class PlotLineTest { 8 | public static void main(String[] args) { 9 | PlotWindow win =new PlotWindow(500,500); 10 | PlotLine testLine=new PlotLine(win, Util.RED); 11 | for (int i = 0; i < 10; i++) { 12 | win.Clear(); 13 | for (int j = 0; j < 100; j++) { 14 | testLine.AddSegment(j,Math.sin((i*5+j)/20.0)); 15 | win.TickPause(10); 16 | } 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Testing/OldTests/PlotTest.java: -------------------------------------------------------------------------------- 1 | package Testing.OldTests; 2 | 3 | import HAL.Gui.PlotWindow; 4 | import HAL.Util; 5 | 6 | public class PlotTest { 7 | public static void main(String[] args) { 8 | PlotWindow win=new PlotWindow(250,250,2); 9 | win.AddPoint(1000,-1000, Util.RGB(1,0,0)); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Testing/OldTests/PopGrid3DTest.java: -------------------------------------------------------------------------------- 1 | package Testing.OldTests; 2 | 3 | import HAL.GridsAndAgents.PopulationGrid3D; 4 | import HAL.Rand; 5 | 6 | public class PopGrid3DTest { 7 | public static void main(String[] args){ 8 | PopulationGrid3D grid=new PopulationGrid3D(10,10,10); 9 | Rand rng=new Rand(); 10 | while(true) { 11 | for (int i = 0; i < 2; i++) { 12 | grid.Add(rng.Int(grid.length), 1); 13 | } 14 | grid.Update(); 15 | for (int i = 0; i < grid.length; i++) { 16 | // if(rng.Int(2)==0) { 17 | grid.Add(i, -grid.Get(i)); 18 | // } 19 | } 20 | grid.Update(); 21 | if(grid.usingSparseIndices){ 22 | grid.usingSparseIndices=false; 23 | }else{ 24 | grid.usingSparseIndices=true; 25 | grid.SetupSparseIndices(); 26 | } 27 | // int ct = 0; 28 | // for (int i : grid) { 29 | // ct++; 30 | // } 31 | System.out.println(grid.OccupiedArea()); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Testing/OldTests/RandTest.java: -------------------------------------------------------------------------------- 1 | package Testing.OldTests; 2 | 3 | import HAL.Rand; 4 | 5 | /** 6 | * Created by Rafael on 11/16/2017. 7 | */ 8 | public class RandTest { 9 | public static void main(String[] args) { 10 | Rand rng=new Rand(0); 11 | System.out.println(rng.Double()); 12 | Rand rng2=new Rand(0); 13 | System.out.println(rng2.Double()); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Testing/OldTests/SerializableModelTest.java: -------------------------------------------------------------------------------- 1 | package Testing.OldTests; 2 | 3 | import HAL.GridsAndAgents.AgentGrid2D; 4 | import HAL.GridsAndAgents.AgentSQ2D; 5 | import HAL.Gui.GridWindow; 6 | import HAL.Interfaces.SerializableModel; 7 | import HAL.Util; 8 | 9 | class Cell extends AgentSQ2D { 10 | } 11 | 12 | public class SerializableModelTest extends AgentGrid2D implements SerializableModel{ 13 | public void Draw(GridWindow win){ 14 | for (int i = 0; i < length; i++) { 15 | Cell c=GetAgent(i); 16 | if(c!=null){ 17 | win.SetPix(i, Util.RGB256(256-c.Age()/10,0,c.Age()/10)); 18 | } 19 | else{ 20 | win.SetPix(i,Util.BLACK); 21 | } 22 | } 23 | } 24 | public SerializableModelTest(int x, int y) { 25 | super(x, y, Cell.class); 26 | } 27 | 28 | public static void main(String[] args) { 29 | GridWindow win=new GridWindow(100,100,5); 30 | SerializableModelTest smt=new SerializableModelTest(100,100); 31 | byte[] out=null; 32 | for (int i = 0; i < 10000; i++) { 33 | if(i==1000){out=Util.SaveState(smt);} 34 | if(i==9000){smt=Util.LoadState(out);} 35 | smt.NewAgentSQ(smt.GetTick()); 36 | win.TickPause(1); 37 | smt.Draw(win); 38 | smt.IncTick(); 39 | } 40 | } 41 | 42 | @Override 43 | public void SetupConstructors() { 44 | this._PassAgentConstructor(Cell.class); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Testing/OldTests/ShellCommandTest.java: -------------------------------------------------------------------------------- 1 | package Testing.OldTests; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | 6 | public class ShellCommandTest { 7 | public static void main(String[] args) { 8 | try { 9 | Process p=Runtime.getRuntime().exec("python ~/Desktop/Pythons/test.py"); 10 | p.waitFor(); 11 | BufferedReader reader=new BufferedReader(new InputStreamReader(p.getInputStream())); 12 | System.out.println(reader.readLine()+"!"); 13 | System.out.println("success"); 14 | 15 | } catch (Exception e) { 16 | System.out.println("failed"); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Testing/OldTests/SigmoidTest.java: -------------------------------------------------------------------------------- 1 | package Testing.OldTests; 2 | 3 | import HAL.Gui.GridWindow; 4 | import HAL.Gui.UIGrid; 5 | import HAL.Util; 6 | 7 | /** 8 | * Created by rafael on 9/7/17. 9 | */ 10 | public class SigmoidTest { 11 | public static void PlotSigmoid(UIGrid vis, double stretch, double inflectionValue, double min, double max, int color){ 12 | for (int i = 0; i < vis.xDim; i++) { 13 | double val=Util.Rescale(i,0,vis.xDim*-8,0,1); 14 | double sigRes=Util.Sigmoid(val,stretch,inflectionValue,min,max); 15 | vis.SetPix(i, (int) (sigRes*(vis.yDim-1)),color); 16 | } 17 | } 18 | public static void PlotSigmoid2(UIGrid vis, double stretch, double inflectionValue, double min, double max, int color){ 19 | for (int i = 0; i < vis.xDim; i++) { 20 | double val=Util.Rescale(i,0,vis.xDim*-8,0,1); 21 | double sigRes=Util.Sigmoid(val,stretch,inflectionValue,min,max); 22 | vis.SetPix(i, (int) (sigRes*(vis.yDim-1)),color); 23 | } 24 | } 25 | public static void ContactSigmoid(UIGrid vis, double bias, double neighborWeight, int nNeighbors, int color){ 26 | bias=bias*2; 27 | neighborWeight=Math.exp(-neighborWeight*4); 28 | for (int i = 0; i < vis.xDim; i++) { 29 | double val = Util.Rescale(i, 0, (int) (vis.xDim), 0, 1); 30 | double sigRes = Util.Sigmoid(-val, neighborWeight, 0, 0, bias); 31 | vis.SetPix(i, (int) (sigRes * (vis.yDim - 1)), color); 32 | } 33 | } 34 | public static void main(String[] args) { 35 | GridWindow win=new GridWindow(1000,1000,1); 36 | win.Clear(Util.BLACK); 37 | // for (int i = 0; i < 20; i++) { 38 | // ContactSigmoid(win,1,i*1.0/19,8,Util.CategorialColor(i)); 39 | // } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Testing/OldTests/StringTest.java: -------------------------------------------------------------------------------- 1 | package Testing.OldTests; 2 | 3 | import HAL.Gui.GridWindow; 4 | 5 | import static HAL.Util.BLACK; 6 | import static HAL.Util.WHITE; 7 | 8 | public class StringTest { 9 | public static void main(String[] args) { 10 | GridWindow testWin=new GridWindow("strings",500,500,2); 11 | testWin.SetString("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",0,499,BLACK,WHITE); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Testing/OldTests/SwapPositionsTest.java: -------------------------------------------------------------------------------- 1 | package Testing.OldTests; 2 | 3 | 4 | import HAL.GridsAndAgents.AgentGrid2D; 5 | import HAL.GridsAndAgents.AgentSQ2Dunstackable; 6 | import HAL.Gui.GridWindow; 7 | 8 | import static HAL.Util.RGB; 9 | 10 | class SwapMe extends AgentSQ2Dunstackable{ 11 | int color; 12 | 13 | } 14 | 15 | public class SwapPositionsTest extends AgentGrid2D{ 16 | public SwapPositionsTest() { 17 | super(2, 1, SwapMe.class); 18 | } 19 | 20 | public static void main(String[] args) { 21 | SwapPositionsTest swap=new SwapPositionsTest(); 22 | swap.NewAgentSQ(0).color=RGB(1,0,0); 23 | swap.NewAgentSQ(1).color=RGB(0,0,1); 24 | GridWindow win=new GridWindow("swapTest",2,1,100,true); 25 | while(true){ 26 | win.DrawAgents(swap,(SwapMe c)->c.color); 27 | swap.GetAgent(0).SwapPosition(swap.GetAgent(1)); 28 | win.TickPause(1000); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Testing/OldTests/TDMAtests.java: -------------------------------------------------------------------------------- 1 | package Testing.OldTests; 2 | 3 | import HAL.GridsAndAgents.PDEGrid1D; 4 | import HAL.Gui.OpenGL2DWindow; 5 | import HAL.Util; 6 | 7 | public class TDMAtests { 8 | public static void main(String[] args) { 9 | OpenGL2DWindow.MakeMacCompatible(args); 10 | OpenGL2DWindow win=new OpenGL2DWindow(500,500,100,1); 11 | PDEGrid1D pde=new PDEGrid1D(10); 12 | pde.Set(pde.xDim/2,1); 13 | pde.Update(); 14 | for (int i = 0; i < 1000; i++) { 15 | pde.Diffusion(0.1); 16 | pde.Set(pde.xDim/2,1); 17 | pde.Update(); 18 | for (int j = 0; j < pde.length; j++) { 19 | win.SetPix(j, Util.HeatMapRGB(pde.Get(j))); 20 | } 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Testing/OldTests/Vis2DCircle.java: -------------------------------------------------------------------------------- 1 | package Testing.OldTests; 2 | 3 | import HAL.Gui.OpenGL2DWindow; 4 | import HAL.Gui.TickTimer; 5 | import HAL.Util; 6 | 7 | import static HAL.Util.RGB; 8 | 9 | /** 10 | * Created by rafael on 5/29/17. 11 | */ 12 | public class Vis2DCircle { 13 | public static void main(String[] args) { 14 | OpenGL2DWindow vis = new OpenGL2DWindow("Test", 1000, 1000,50,50, true); 15 | float[] pts= Util.GenCirclePoints(1.0f,4); 16 | TickTimer trt=new TickTimer(); 17 | float x=0; 18 | while(!vis.IsClosed()){ 19 | vis.Clear(RGB(x, (float) 0, (float) 0)); 20 | vis.FanShape((float) 10, (float) 10, (float) 1, pts,RGB((float) 1, (float) 1, (float) 1)); 21 | vis.Update(); 22 | x+=0.000001; 23 | } 24 | vis.Close(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Testing/OldTests/ZeroDiffusionTest.java: -------------------------------------------------------------------------------- 1 | package Testing.OldTests; 2 | 3 | import HAL.GridsAndAgents.Grid2Ddouble; 4 | import HAL.GridsAndAgents.PDEGrid2D; 5 | import HAL.Gui.GridWindow; 6 | import HAL.Util; 7 | 8 | public class ZeroDiffusionTest { 9 | public static void main(String[] args) { 10 | PDEGrid2D testGrid=new PDEGrid2D(100,100); 11 | GridWindow testWin=new GridWindow(100,100,10); 12 | Grid2Ddouble rates=new Grid2Ddouble(100,100); 13 | rates.SetAll(0.15); 14 | for (int x = 10; x < 90; x++) { 15 | for (int y = 10; y < 90; y++) { 16 | rates.Set(x,y,0); 17 | } 18 | } 19 | for (int i = 0; i < 100000; i++) { 20 | testGrid.Set(50,92,1); 21 | testGrid.Diffusion(rates,rates); 22 | testGrid.Update(); 23 | testWin.TickPause(0); 24 | testWin.DrawPDEGrid(testGrid, Util::HeatMapRGB); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Testing/OldTests/mkdirs.java: -------------------------------------------------------------------------------- 1 | package Testing.OldTests; 2 | 3 | import static HAL.Util.MakeDirs; 4 | 5 | /** 6 | * Created by Rafael on 9/19/2017. 7 | */ 8 | public class mkdirs { 9 | public static void main(String[] args) { 10 | System.out.println(MakeDirs("test/ing")); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Testing/SortTest.java: -------------------------------------------------------------------------------- 1 | package Testing; 2 | 3 | import HAL.Util; 4 | 5 | public class SortTest { 6 | public static void main(String[] args) { 7 | double[]test=new double[]{1,3,6,7,7,7,4,3,2}; 8 | Util.Sort((i1,i2)->test[i1]>test[i2],(i1,i2)->{double temp=test[i1];test[i1]=test[i2];test[i2]=temp;},test.length); 9 | System.out.println(Util.ArrToString(test,",")); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /what_is_hybrid_modeliing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MathOnco/HAL/5a8a2f879585da3eb81860c94a1a70680e357c43/what_is_hybrid_modeliing.png --------------------------------------------------------------------------------