public void SolverFactoryTest() { var model = EmodlLoader.LoadEMODLModel(_sirModel); ISolver solver = SolverFactory.CreateSolver("SSA", model, 1, 2.0, 3); Assert.IsTrue(solver is Gillespie); solver = SolverFactory.CreateSolver("FIRST", model, 1, 2.0, 3); Assert.IsTrue(solver is GillespieFirstReaction); solver = SolverFactory.CreateSolver("NEXT", model, 1, 2.0, 3); Assert.IsTrue(solver is GibsonBruck); solver = SolverFactory.CreateSolver("HYBRID", model, 1, 2.0, 3); Assert.IsTrue(solver is HybridSSA); solver = SolverFactory.CreateSolver("TAU", model, 1, 2.0, 3); Assert.IsTrue(solver is TauLeaping); solver = SolverFactory.CreateSolver("MID", model, 1, 2.0, 3); Assert.IsTrue(solver is MidPoint); solver = SolverFactory.CreateSolver("R", model, 1, 2.0, 3); Assert.IsTrue(solver is RLeaping); solver = SolverFactory.CreateSolver("RFAST", model, 1, 2.0, 3); Assert.IsTrue(solver is RLeapingFast); solver = SolverFactory.CreateSolver("BLEAP", model, 1, 2.0, 3); Assert.IsTrue(solver is BLeaping); solver = SolverFactory.CreateSolver("TSSA", model, 1, 2.0, 3); Assert.IsTrue(solver is TransportSSA); solver = SolverFactory.CreateSolver("DFSP", model, 1, 2.0, 3); Assert.IsTrue(solver is DFSP); solver = SolverFactory.CreateSolver("OTSSA", model, 1, 2.0, 3); Assert.IsTrue(solver is OptimalTransportSSA); /* Fractional diffusion solver doesn't handle single node models gracefully. * solver = SolverFactory.CreateSolver("LEVY", model, 1, 2.0, 3); * Assert.IsTrue(solver is FractionalDiffusion); */ /* Exit times solver doesn't handle missing target condition gracefully. * solver = SolverFactory.CreateSolver("EXITTIMES", model, 1, 2.0, 3); * Assert.IsTrue(solver is ExitTimes); */ /* dwSSA solver automatically starts solving * Configuration.CurrentConfiguration = Configuration.ConfigurationFromString("{\"dwSSA\":{\"re_name\":\"I\",\"re_val\":500}}"); * solver = SolverFactory.CreateSolver("DWSSA", model, 1, 2.0, 3); * Assert.IsTrue(solver is dwSSA); */ }
public void MigrationReactions() { const string modelDescription = @" ; migration model (import (rnrs) (emodl cmslib)) (start-model ""migration"") (locale site-a) (set-locale site-a) (species A::S 990) (species A::E) (species A::I 10) (species A::R) ;(observe susceptibleA A::S) ;(observe exposedA A::E) ;(observe infectiousA A::I) ;(observe recoveredA A::R) (observe populationA (sum A::S A::E A::I A::R)) ;(observe prevalenceA (/ A::I (sum A::S A::E A::R))) (param Ki 0.0005) (param Kl 0.2) (param Kr (/ 1 7)) (param Kw (/ 1 135)) (reaction exposureA (A::S) (A::E) (* Ki A::S A::I)) (reaction infectionA (A::E) (A::I) (* Kl A::E)) (reaction recoveryA (A::I) (A::R) (* Kr A::I)) (reaction waningA (A::R) (A::S) (* Kw A::R)) (locale site-b) (set-locale site-b) (species B::S 100) (species B::E) (species B::I) (species B::R) ;(observe susceptibleB B::S) ;(observe exposedB B::E) ;(observe infectiousB B::I) ;(observe recoveredB B::R) (observe populationB (sum B::S B::E B::I B::R)) ;(observe prevalenceB (/ B::I (sum B::S B::E B::R))) (reaction exposureB (B::S) (B::E) (* Ki B::S B::I)) (reaction infectionB (B::E) (B::I) (* Kl B::E)) (reaction recoveryB (B::I) (B::R) (* Kr B::I)) (reaction waningB (B::R) (B::S) (* Kw B::R)) ; migration (param Km 0.01) (reaction SA->SB (A::S) (B::S) (* Km A::S)) (reaction EA->EB (A::E) (B::E) (* Km A::E)) (reaction IA->IB (A::I) (B::I) (* Km A::I)) (reaction RA->RB (A::R) (B::R) (* Km A::R)) (reaction SB->SA (B::S) (A::S) (* Km B::S 10)) (reaction EB->EA (B::E) (A::E) (* Km B::E 10)) (reaction IB->IA (B::I) (A::I) (* Km B::I 10)) (reaction RB->RA (B::R) (A::R) (* Km B::R 10)) (end-model) "; Console.WriteLine("Building model with local and migratory/diffusive reactions..."); ModelInfo modelInfo = EmodlLoader.LoadEMODLModel(modelDescription); var local = from reaction in modelInfo.Reactions where reaction.IsLocal select reaction; var migration = from reaction in modelInfo.Reactions where reaction.IsDiffusion select reaction; Console.WriteLine("Checking model for local reactions..."); Expect(local.Count() == 8); Console.WriteLine("Checking model for migratory/diffusive reactions..."); Expect(migration.Count() == 8); Console.WriteLine(""); }