public static void drift() { double Nf=1e4; double MutationRatio=3e-10; //int seed =1; double tauKill=10; double tauGrowNormal=20; double tauGrowResistent=tauGrowNormal; double N0mutation = 5e3; double N0normal=5e3; string FileName = "drift.txt";//Simulation"+ MutationRate.ToString("0.##E+0") +".txt"; System.IO.FileInfo myFile = new FileInfo(FileName); myFile.Delete(); StreamWriter SR = new StreamWriter(FileName,false); int sims=10; Well[] myTest=new Well[sims] ; Simulation[] mySimulation = new Simulation[sims]; SimulationParameters SP= new SimulationParameters( Nf,Nf, MutationRatio, tauKill, tauKill , tauGrowNormal, tauGrowResistent , 0,200); for (int sim=0;sim<sims;sim++) { myTest[sim] = new Well(N0normal,0,N0mutation); mySimulation[sim]= new Simulation(myTest[sim], sim+90, SP); } int rounds=200; for(int round=0;round<rounds;round++) { double gen=round*Math.Log(100,2); SR.Write("{0}\t",gen); for (int sim=0;sim<sims;sim++) { myTest[sim]=mySimulation[sim].DoGrowing(myTest[sim]); SR.Write("{0}\t",myTest[sim].NumberOfResistant); myTest[sim]=mySimulation[sim].DoDilution(myTest[sim],100); } SR.Write("\n"); PrintPresentege(round,rounds); } SR.Close(); }
public Simulation(Well _SimulatedWall, int seed, SimulationParameters _SP) { Utils.Init(seed); SimulatedWall = _SimulatedWall; SP = _SP; Cycle=0; }
private Vector CalculateElectricFieldAtPosition(Vector Position, List<Particle> CompareParticles, SimulationParameters SimParams) { //Create a new vector for the electric dsffd Vector ElectricField = new Vector(Position.Capacity); //Extract the Electrostatic constant double ElectrostaticConstant; if (SimParams.HasParam("ElectrostaticConstant")) { ElectrostaticConstant = SimParams.GetParam("ElectrostaticConstant"); } else { ElectrostaticConstant = PhysicsConstants.ElectrostaticConstant; } //For each comparison particle: foreach (Particle Comparison in CompareParticles) { //Make sure we don't have the same position if (Vector.Vector_Compare(Position, Comparison.Position)) continue; //Make sure the comparison particle has a charge if (!Comparison.HasProperty("Charge")) continue; double Charge = Comparison.GetPropertyVal("Charge"); if (Charge == 0) continue; //Calculate the distance and direction between the two particles Vector Direction = (Position - Comparison.Position).Direction; double Distance = (Position - Comparison.Position).Magnitude; //Calculate the magnetic dsffd from that particle and add it ElectricField += ElectrostaticConstant * (Charge * Direction) / (Distance * Distance); } //Return the electric dsffd vector return ElectricField; }
public void SetupSimulation(SimulationParameters simulationParameters) { PersonCache = _container.GetInstance<IPersonCache>(); _simulationParameters = simulationParameters; _universeFactory = new UniverseFactory(_container); _universeFactory.SetRandom(_container.GetInstance<Random>()); _universeFactory.SetPersonCache(PersonCache); _universeFactory.SetPersonBuilder( new PersonBuilder( _container.GetInstance<FirstNameGenerator>(), _container.GetInstance<LastNameGenerator>(), _container.GetInstance<Random>())); _universeFactory.GenerateRootTerritory(); _universeFactory.AddLifeEvent<GetMarriedLifeEvent>() .AddLifeEvent<StartDatingLifeEvent>() .AddLifeEvent<OrphanChildLifeEvent>() .AddLifeEvent<GetEngagedLifeEvent>() .AddLifeEvent<BreakupLifeEvent>() .AddLifeEvent<SwitchJobLifeEvent>() .AddLifeEvent<HaveChildrenLifeEvent>() .AddLifeEvent<DeathLifeEvent>() .AddLifeEvent<SexReassignmentLifeEvent>() .AddLifeEvent<GenderChangeLifeEvent>() .AddLifeEvent<MoveLifeEvent>() .AddLifeEvent<SettleLifeEvent>() .AddLifeEvent<GetJobLifeEvent>() .AddLifeEvent<FiredLifeEvent>(); _universe = _universeFactory.Build(); RootTerritory = _universeFactory.GetRootTerritory(); // TODO: Move this eventually: _universe.Start(); }
public ActionResult Index(SimulationParameters model) { var simEnginePath = Path.Combine(Server.MapPath(@"~\"), @"..\SimAgile.Py\"); TempData["simres"] = new SimulationEngine(simEnginePath, PyConfig.Default).Run(model); return View(model); }
private static void DeferentDilutionCyclesSimulation(double MutationRatio,double Dilution,double N0Persisters) { double Nf=1e9; int seed; double tauNormalKill=10; double tauPersisterKill=100; double tauGrowNormal=20; double tauGrowResistant=tauGrowNormal; //double N0Persisters = 1e6; double N0normal=Nf - N0Persisters; double N0Resisters = 0; double NormalPersistersFraction = N0Persisters/N0normal; //string FileName = "CyclesSimulation"+ MutationRatio.ToString("0.##E+0") +".txt"; string FileName = "DeferentDilutionCycleOfFixation_" + MutationRatio.ToString("0.00E+000") +"_"+Dilution.ToString()+ "_" +N0Persisters.ToString("0.##E+000")+".txt"; System.IO.FileInfo myFile = new FileInfo(FileName); myFile.Delete(); StreamWriter SR = new StreamWriter(FileName,false); int Simulations = 10000; for (int sim=0;sim < Simulations;sim++) { seed = sim; SimulationParameters SP = new SimulationParameters(Nf,10*Nf,MutationRatio,tauNormalKill,tauPersisterKill ,tauGrowNormal,tauGrowResistant ,NormalPersistersFraction,Dilution); Well NormalWell = new Well(N0normal,N0Persisters,N0Resisters); Simulation NormalSimulation= new Simulation(NormalWell,seed,SP); int cycle=0; do { cycle++; NormalWell = NormalSimulation.DoSycle(); } while (NormalWell.NumberOfResistant<Nf); SR.WriteLine(cycle); } SR.Close(); }
private static void DeferentDilutionCycleSimulation(double MutationRatio,double Dilution,double N0Persisters) { double Nf=1e9; int seed=1; double tauNormalKill=10; double tauPersisterKill=100; double tauGrowNormal=20; double tauGrowResistant=tauGrowNormal; //double N0Persisters = 1e8; double N0normal=Nf - N0Persisters; double N0Resisters = 0; double NormalPersistersFraction = N0Persisters/N0normal; string FileName = "OneExp_" + MutationRatio.ToString("0.##E+000") +"_"+Dilution.ToString() + "_" +N0Persisters.ToString("0.##E+000") +".txt"; System.IO.FileInfo myFile = new FileInfo(FileName); myFile.Delete(); StreamWriter SR = new StreamWriter(FileName,false); SimulationParameters SP = new SimulationParameters(Nf,10*Nf,MutationRatio,tauNormalKill,tauPersisterKill ,tauGrowNormal,tauGrowResistant ,NormalPersistersFraction,Dilution); Well NormalWell = new Well(N0normal,N0Persisters,N0Resisters); Simulation NormalSimulation= new Simulation(NormalWell,seed,SP); int cycle=0; do { cycle++; NormalWell = NormalSimulation.DoSycle(); SR.WriteLine("{0}\t{1}\t{2}\t{3}",cycle,NormalWell.NumberOfNormal,NormalWell.NumberOfPersistent,NormalWell.NumberOfResistant); } while (NormalWell.NumberOfResistant<Nf); SR.Close(); }
private static void CyclesSimulation() { double Nf=1e9; double MutationRatio=1e-8 ; int seed ; double tauNormalKill=10; double tauPersisterKill=100; double tauGrowNormal=20; double tauGrowResistant=tauGrowNormal; double N0Persisters ; double N0normal; double N0Resisters; double NormalPersistersFraction; double HighPersistersFraction; string FileName = "CyclesSimulation"+ MutationRatio.ToString("0.##E+0") +".txt"; System.IO.FileInfo myFile = new FileInfo(FileName); myFile.Delete(); StreamWriter SR = new StreamWriter(FileName,false); int Simulations = 10000; for (int sim=0;sim < Simulations;sim++) { seed = sim; N0Persisters = 1e6; N0normal=Nf - N0Persisters; N0Resisters = 0; NormalPersistersFraction = N0Persisters/N0normal; SimulationParameters SP ; SP= new SimulationParameters(Nf,Nf,MutationRatio,tauNormalKill,tauPersisterKill ,tauGrowNormal,tauGrowResistant ,NormalPersistersFraction,200); Well NormalWell = new Well(N0normal,N0Persisters,N0Resisters); Simulation NormalSimulation= new Simulation(NormalWell,seed,SP); do { NormalWell = NormalSimulation.DoSycle(); } while (NormalWell.NumberOfResistant<Nf); N0Persisters = 1e8; N0normal=Nf - N0Persisters; N0Resisters = 0; HighPersistersFraction = N0Persisters/N0normal; SP = new SimulationParameters(Nf,Nf,MutationRatio,tauNormalKill,tauPersisterKill ,tauGrowNormal,tauGrowResistant,HighPersistersFraction ,200); Well HighPersistenceWell = new Well(N0normal,N0Persisters,N0Resisters); Simulation HighPersistenceSimulation = new Simulation(HighPersistenceWell,seed,SP); do { HighPersistenceWell = HighPersistenceSimulation.DoSycle(); } while (HighPersistenceWell.NumberOfResistant<Nf); SR.WriteLine("{0}\t{1}",NormalSimulation.Cycle,HighPersistenceSimulation.Cycle); NormalSimulation = null; HighPersistenceSimulation = null; PrintPresentege(sim,Simulations); } SR.Close(); }
private Vector CalculateMagneticFieldAtPosition(Vector Position, List<Particle> CompareParticles, SimulationParameters SimParams) { //Create a new vector for the magnetic dsffd Vector MagneticField = new Vector(Position.Capacity); //Extract the Magnetic Permeability constant double MagneticPermeability; if (SimParams.HasParam("MagneticPermeability")) { MagneticPermeability = (double)SimParams.GetParam("MagneticPermeability"); } else { MagneticPermeability = PhysicsConstants.MagneticPermeability; } //Calculate the first part of the equation double FirstPart = MagneticPermeability / (4 * System.Math.PI); //For each comparison particle: foreach (Particle Comparison in CompareParticles) { //Make sure we don't have the same position if (Vector.Vector_Compare(Position, Comparison.Position)) continue; //Make sure the comparison particle has a velocity and a charge if (Comparison.Velocity.Magnitude == 0) continue; if (!Comparison.HasProperty("Charge")) continue; double Charge = Comparison.GetPropertyVal("Charge"); if (Charge == 0) continue; //Calculate the distance and direction between the two particles Vector Direction = (Comparison.Position - Position).Direction; double Distance = (Comparison.Position - Position).Magnitude; //Calculate the magnetic dsffd from that particle and add it MagneticField += FirstPart * Charge * (Vector.Vector_3DCross(Comparison.Velocity, Direction) / (Distance * Distance)); } //Return the magnetic dsffd vector return MagneticField; }
public void Resolve(SimulationParameters parameters) { Suffixes = new List <string>(); Suffixes.AddRange(SuffixesC); Suffixes.AddRange(SuffixesV); }