Remove try and catch from writer close

This commit is contained in:
leandrohw 2018-01-08 12:05:39 -07:00
parent 0d5367e836
commit f2b929909f
7 changed files with 46 additions and 57 deletions

View file

@ -138,6 +138,7 @@ public class DynamicSimulation extends CoreObservable
simulator.setupForNewRun(run + 1);
}
}
System.gc();
//double mem = (runtime.totalMemory() - runtime.freeMemory()) / mb;
///double val2 = System.currentTimeMillis();

View file

@ -30,7 +30,7 @@ public interface ParentSimulator
/**
*
*/
public abstract void simulate();
public abstract void simulate() throws IOException, XMLStreamException;
/**
*
@ -46,12 +46,19 @@ public interface ParentSimulator
*
* @param newRun
*/
public abstract void setupForNewRun(int newRun);
public abstract void setupForNewRun(int newRun) throws IOException;
/**
*
*/
public abstract void printStatisticsTSD();
/**
*
* @param randomSeed
* @param runNumber
* @throws IOException
* @throws XMLStreamException
*/
public abstract void initialize(long randomSeed, int runNumber) throws IOException, XMLStreamException;
}

View file

@ -648,17 +648,11 @@ public abstract class HierarchicalSimulation extends AbstractSimulator
return type;
}
protected void setupForOutput(int currentRun)
protected void setupForOutput(int currentRun) throws IOException
{
setCurrentRun(currentRun);
try
{
writer.init(getOutputDirectory() + File.separator + "run-" + currentRun + ".tsd");
}
catch (IOException e)
{
e.printStackTrace();
}
writer.init(getOutputDirectory() + File.separator + "run-" + currentRun + ".tsd");
}
public double getInitialTime()
@ -705,13 +699,12 @@ public abstract class HierarchicalSimulation extends AbstractSimulator
return Double.NaN;
}
protected void closeWriter()
protected void closeWriter() throws IOException
{
try {
if(writer != null)
{
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
protected void printToFile()
{

View file

@ -75,23 +75,12 @@ public final class HierarchicalMixedSimulator extends HierarchicalSimulation
}
@Override
public void simulate()
public void simulate() throws IOException, XMLStreamException
{
if (!isInitialized)
{
try
{
initialize(0, getCurrentRun());
}
catch (IOException e)
{
e.printStackTrace();
}
catch (XMLStreamException e)
{
e.printStackTrace();
}
}
double nextEndTime = currentTime.getValue(0);
fbaTime = nextEndTime;
@ -133,6 +122,8 @@ public final class HierarchicalMixedSimulator extends HierarchicalSimulation
printToFile();
}
closeWriter();
}
@Override

View file

@ -171,15 +171,9 @@ public final class HierarchicalODERKSimulator extends HierarchicalSimulation {
@Override
public void simulate() {
public void simulate() throws IOException, XMLStreamException {
if (!isInitialized) {
try {
initialize(0, 1);
} catch (IOException e) {
e.printStackTrace();
} catch (XMLStreamException e) {
e.printStackTrace();
}
}
double nextEndTime = 0;
while (currentTime.getValue() < getTimeLimit() && !isCancelFlag()) {
@ -214,10 +208,12 @@ public final class HierarchicalODERKSimulator extends HierarchicalSimulation {
printToFile();
}
}
if (!isSingleStep) {
if (!isSingleStep)
{
printToFile();
closeWriter();
}
}

View file

@ -112,14 +112,14 @@ public class HierarchicalSSADirectSimulator extends HierarchicalSimulation
}
@Override
public void setupForNewRun(int newRun)
public void setupForNewRun(int newRun) throws IOException
{
setCurrentTime(getInitialTime());
setupForOutput(newRun);
}
@Override
public void simulate()
public void simulate() throws IOException, XMLStreamException
{
double r1 = 0, r2 = 0, totalPropensity = 0, delta_t = 0, nextReactionTime = 0, previousTime = 0, nextEventTime = 0, nextMaxTime = 0;
@ -131,18 +131,7 @@ public class HierarchicalSSADirectSimulator extends HierarchicalSimulation
if (!isInitialized)
{
try
{
this.initialize(randomSeed, 1);
}
catch (IOException e)
{
e.printStackTrace();
}
catch (XMLStreamException e)
{
e.printStackTrace();
}
}
printTime.setValue(getOutputStartTime());
previousTime = 0;
@ -210,9 +199,10 @@ public class HierarchicalSSADirectSimulator extends HierarchicalSimulation
{
printToFile();
}
closeWriter();
}
closeWriter();
}
private void update(boolean reaction, boolean rateRule, boolean events, double r2, double previousTime)

View file

@ -15,8 +15,11 @@ package edu.utah.ece.async.ibiosim.learn.parameterestimator.methods.sres;
import static java.lang.Math.abs;
import java.io.IOException;
import java.util.List;
import javax.xml.stream.XMLStreamException;
import edu.utah.ece.async.ibiosim.analysis.simulation.hierarchical.HierarchicalSimulation;
import edu.utah.ece.async.ibiosim.analysis.simulation.hierarchical.methods.HierarchicalODERKSimulator;
import edu.utah.ece.async.ibiosim.learn.genenet.Experiments;
@ -121,13 +124,21 @@ public class ObjectiveSqureError extends Objective
{
odeSim.setTimeLimit(experiment.get(i + 1).get(0));
odeSim.simulate();
for (int j = 1; j < speciesCollection.length; j++)
try
{
double tmp = odeSim.getTopLevelValue(speciesCollection[j]) - experiment.get(i + 1).get(j);
tmp = tmp * tmp;
sum = sum + tmp;
}
odeSim.simulate();
for (int j = 1; j < speciesCollection.length; j++)
{
double tmp = odeSim.getTopLevelValue(speciesCollection[j]) - experiment.get(i + 1).get(j);
tmp = tmp * tmp;
sum = sum + tmp;
}
}
catch (XMLStreamException | IOException e)
{
sum = Double.MAX_VALUE;
}
}