// Start is called before the first frame update
 void Start()
 {
     n          = Model.GetInstance().GetNumCells(0);
     iterations = BacteriaFactory.GetIterations();
     CellDoneHandler.Setup(n);
     StartCoroutine(Load());
     ExportHandler.init();
 }
 public static BacteriaFactory GetInstance()
 {
     if (instance == null)
     {
         instance = new BacteriaFactory();
     }
     return(instance);
 }
    private static String CreateDirPath()
    {
        BacteriaFactory b          = BacteriaFactory.GetInstance();
        Model           m          = Model.GetInstance();
        String          enviroMode = m.environment.IsDynamic() ? "Dynamic": "Static";
        String          death      = b.GetLifeRegulator() is LifeRegulator ? "Death" : "Immortal";

        return(Application.dataPath + "/Exports/" + b.GetRegulatorType().ToString() + "_" + death + "_" + m.GetNumCells(0) + "_" +
               enviroMode + "_" + BacteriaFactory.GetIterations() + "_" + timeStamp + "/");
    }
Beispiel #4
0
    public void OnEndSimClick() //called when the user clicks the end sim button to open the stat page
    {
        endSimButton.gameObject.SetActive(false);
        endSimScreen.gameObject.SetActive(true);
        prevTimeScaleFactor = model.GetTimeScaleFactor();
        model.SetTimeScaleFactor(0);

        //Update the texts for the end screen
        numOfCells.text      = "Number of Bacteria: " + model.GetCells().Count;
        numOfIterations.text = "Number of Iterations: " + BacteriaFactory.GetIterations();
        timeElapsed.text     = "Time elapsed: " + FormatTimeString();
    }
    private Cell parentObject; //TODO replce this with something smarter

    private ForwardInternals(float v, float dT, float angle, ICellRegulation regulation, int iterations) : base(v, dT, angle, regulation)
    {
        initalAngel     = angle;
        this.iterations = iterations;
        deathDate       = iterations + 1;

        lifeRegulator = BacteriaFactory.GetInstance().GetLifeRegulator();

        //crete the arrays
        positions          = new IPointAdapter[iterations + 1];
        states             = new State[iterations + 1];
        cellDeathListeners = new List <ICellDeathListener>();
    }
    //Simulates numCells many cells with iterations many steps each
    public void CreateCells(int numCells)
    {
        cells[0] = new List <Cell>();
        for (int i = 0; i < numCells; i++)
        {
            float x = RandomFloat.Range(-12f, 12f);
            float z = RandomFloat.Range(-12f, 12f);

            Cell cell = BacteriaFactory.CreateNewCell(x, z, RandomFloat.Range(0, 2 * MathFloat.PI), false);
            cells[0].Add(cell);
            allCells.Add(cell);
        }
    }
Beispiel #7
0
    public void HandleDropDownSelection(int index)
    {
        switch (index)
        {
        case 0:
            BacteriaFactory.SetCellRegulatorType(RegulatorType.ODE);
            break;

        case 1:
            BacteriaFactory.SetCellRegulatorType(RegulatorType.Delta);
            break;
        }
    }
 //Sets up the model and factory to simulate numCells many cells with iterations many steps
 public void SetupCells(int numCells, int iterations)
 {
     cells = new List <Cell> [iterations + 1];
     for (int i = 0; i < cells.Length; i++)
     {
         cells[i] = new List <Cell>();
     }
     initalNumOfCells = numCells;
     BacteriaFactory.SetCellIterations(iterations);
     timeScaleFactor    = 1;
     cellBirthListeners = new List <ICellBirthListener>();
     allCells           = new List <Cell>();
     IterationHandler.GetInstance().Reset();
     averageLigandC = null;
 }
    // Start is called before the first frame update
    void Start()
    {
        model = Model.GetInstance();

        if (!BacteriaFactory.IsForwardSimulation() || smart)
        {
            cell         = BacteriaFactory.CreateNewCell(transform.position.x, transform.position.z, transform.rotation.y, smart);
            nextLocation = TranslateToVector3(cell.GetNextLocation()); //calculate the first location
        }

        myAnimator    = GetComponent <Animator>();
        cellRigidBody = GetComponent <Rigidbody>();

        originalScale = transform.localScale;
        run           = false; // set run to false so that it begins by rotating towards the first location
    }
    //Calculates the average ligand consentration for each time step
    private float[] CalculateAverageLigandC()
    {
        if (allCells.Count == 0)
        {
            return(null);
        }

        float[] averageLigandC = new float[BacteriaFactory.GetIterations()];

        for (int i = 0; i < averageLigandC.Length; i++) //for each iteration
        {
            float averageC = 0;
            for (int j = 0; j < cells[i + 1].Count; j++) //for the cells present in that iteration
            {
                averageC += (float)((ForwardInternals)cells[i + 1][j].GetInternals()).GetInternalStates()[i + 1].l;
            }

            averageLigandC[i] = (cells[i + 1].Count != 0 ? averageC / cells[i + 1].Count : 0);
        }

        return(averageLigandC);
    }
    public void Run()
    {
        Model model = Model.GetInstance();

        for (int k = 0; k < runs; k++) //simulates m different runs only showing the last one but exporting the data for the rest
        {
            if (k != 0)
            { //reset data if not the first run (since that is already setup elsewhere in the code)
                model.SetupCells(n, iterations);
                model.CreateCells(n);
            }

            for (simulatedStep = 1; simulatedStep <= iterations; simulatedStep++) //Simulate the cells one timestep at a time
            {
                model.SimulateTimeStep(simulatedStep);
            }


            model.ExportData(n, BacteriaFactory.GetIterations());
        }

        model.GetAverageLigandC();
    }
Beispiel #12
0
    // Dropdown
    private void Start()
    {
        // Create basic listeners for various elements
        simulateButton.onClick.AddListener(StartSimulation);
        i0Slider.onValueChanged.AddListener(delegate { EnvValueChanged(); });
        dSlider.onValueChanged.AddListener(delegate { EnvValueChanged(); });
        sourcesSlider.onValueChanged.AddListener(delegate { EnvValueChanged(); });
        nOfCellsSlider.onValueChanged.AddListener(delegate { CellValueChanged(); });
        nOfIterations.onValueChanged.AddListener(delegate { CellValueChanged(); });
        forwardSim.onValueChanged.AddListener(delegate { CellValueChanged(); });
        quitButton.onClick.AddListener(Quit);

        model = Model.GetInstance();

        BacteriaFactory.SetCellIterations(500);
        BacteriaFactory.SetCellDeathAndDivision(true);
        BacteriaFactory.SetCellRegulatorType(RegulatorType.ODE);

        //added just to make the program a lot less anoying to use

        createBasicEnv(i0, d);
        EnvValueChanged(); // bug fix for first value change
        CellValueChanged();
    }
Beispiel #13
0
 public void SetCellDeathDivision(bool status)
 {
     BacteriaFactory.SetCellDeathAndDivision(status);
 }