package simulation;
import java.io.File;
import java.util.concurrent.Callable;
import miscellaneous.DirectoryManager;
import miscellaneous.LSVList;
import reaction.Reaction;
import recorders.Recorder;
import tables.DimensionMap;
import vsv.DIPModel;
import weka.core.converters.JEXTableWriter;
public class DIPSim implements Callable<Integer> {
public DIPModel model;
public DimensionMap params;
public double duration, dt, dtRecorder;
public File outputFile = null;
// Results Stuff
public Recorder recorder = new Recorder();
public static void main(String[] args)
{
// String outputPath = "/Users/jaywarrick/Desktop/JavaModelOutputs";
// String outputPath = "C:\\Users\\ctimm\\Desktop\\JavaModelOutputs";
String outputPath = "C:\\Users\\akpinar\\Desktop\\JavaOutput_VSV";
Recorder.setHostDirectory(outputPath);
DIPSim sim = new DIPSim();
DIPModel model = new DIPModel();// initializes the model (cell, virus, DIP and reactions)
sim.setParams(model, 6 * 60 * 60, 1.0, 15 * 60); // sets the simulation parameters
sim.call();
}
public DIPSim()
{
this.outputFile = new File(DirectoryManager.getUniqueAbsoluteTempPath(JEXTableWriter.ARFF_FILE));
}
/**
*
* @param model
* @param duration
* total infection time
* @param dt
* time increment
* @param dtRecorder
* recorded time increment
* @param outputPath
*
* @questions What does mature fnc do? Why do you mature everything in the pool? What is madeit? a parameter to indicate where the simulation stopped?
*/
public void setParams(DIPModel model, double duration, double dt, double dtRecorder)
{
this.model = model;
this.duration = duration;
this.dt = dt;
this.dtRecorder = dtRecorder;
// Print the reactions used
LSVList reactions = new LSVList();
reactions.add(" ");
for (Reaction r : model.rxns)
{
reactions.add(r.toString());
}
Recorder.log(reactions.toString(), this);
}
/**
* runs the simulation
*
* @param duration
* @param dt
* @param dtRecorder
*/
@Override
public Integer call()
{
this.recorder.reset();
// Simulation
double t = 0;
while (t < this.duration)
{
// Add matured items to the pool
this.model.cell.mature(t);
double decay = this.model.cellDecay(t);
// decay = 1.0; // use for testing purposes
// records and reports time, cell pool status and decay
this.recorder.record(this.duration, t, this.model.cell, this.dtRecorder, "DIPSim", decay);
if(t % 100 == 0)
{
double madeIt = t;
t = madeIt;
}
// increment time here
// This way, time 0 is recorded initially but time is incremented
// dt for integrating and finding the next solution.
t = t + this.dt;
// calculate rates based on each reaction in the simulation and updates 'rates'
for (Reaction rxn : this.model.rxns)
{
rxn.calculateBaseRate();
rxn.applyStoichAndRate(); // applies changes to the pool of each reactant based on their stochiometric constant and reaction rate
}
this.model.cell.simpleLinearIntegrate(this.dt, t, decay); // calculates the production rates and yields within a time period and at a given time
}
this.recorder.saveData(this.duration, this.dt, this.outputFile);
return 0;
}
}
// ////////////////////////////////////////////////////////////////////////////////////////
// OLD METHODS
// //////////////////////////////////////////////////////////////////////////////////////
// public void recordData(double t, double dtRecorder)
// {
// if(t/dtRecorder >= ticker + 1 || t == 0.0)
// {
// // update the ticker
// ticker = (int) (t/dtRecorder);
//
// // update the available numbers
// SimplePool temp = this.pool.copy();
// this.total.put(t, temp);
//
// // // update the total numbers
// // temp = temp.copy();
// // temp.add(reactantDelayPool.getAll());
// // this.total.put(t, temp);
// }
// }
// private void calculateCumulativeRates()
// {
// this.reactantRates.clear();
// this.productRates.clear();
//
// // get the rate of usage of each reactant for all the reactions in this simulation
// for(Reaction reaction : reactions)
// {
// // Calculate the rates of molecule usage/production for each molecule in the reaction based on available reactants
// reaction.calculateRates(this.pool);
//
// // dA/dt_RXN1 + dA/dt_RXN2 + ... + dA/dt_RXNn for each molecule (reactant or product)
// // Reactants
// this.reactantRates = Reaction.addMaps(this.reactantRates, reaction.reactantRates);
//
// //Products
// this.productRates = Reaction.addMaps(this.productRates, reaction.productRates);
// }
// }
// public String getResults()
// {
// LSVList ret = new LSVList();
// for(SimplePool result : this.total.values())
// {
// CSVList line = new CSVList();
// line.add("time");
// for(String reactant : result.keySet())
// {
// line.add(""+reactant);
// }
// ret.add(line.toString());
// break;
// }
// for(Entry<Double,SimplePool> result : this.total.entrySet())
// {
// CSVList line = new CSVList();
// line.add(result.getKey().toString());
// for(String reactant : result.getValue().keySet())
// {
// line.add(""+result.getValue().get(reactant));
// }
// ret.add(line.toString());
// }
// return ret.toString();
// }