Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 196234 Details for
Bug 346732
FiniteDifference splits time steps when values go negative
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Patch for the time step splitting
patch.txt (text/plain), 28.70 KB, created by
Christian Thoens
on 2011-05-20 12:29:39 EDT
(
hide
)
Description:
Patch for the time step splitting
Filename:
MIME Type:
Creator:
Christian Thoens
Created:
2011-05-20 12:29:39 EDT
Size:
28.70 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.stem.core >Index: src/org/eclipse/stem/core/graph/IntegrationLabelValue.java >=================================================================== >--- src/org/eclipse/stem/core/graph/IntegrationLabelValue.java (revision 1861) >+++ src/org/eclipse/stem/core/graph/IntegrationLabelValue.java (working copy) >@@ -76,8 +76,9 @@ > * @param value reference value > * @return boolean True if changed > */ >- public boolean adjustDelta(IntegrationLabelValue value); >+ public boolean avoidNegative(IntegrationLabelValue value); > >+ public double computeDeltaAdjustment(IntegrationLabelValue value); > > /** > * divide. Divide the input with this value >#P org.eclipse.stem.populationmodels >Index: src/org/eclipse/stem/populationmodels/standard/provider/PopulationInitializerItemProvider.java >=================================================================== >--- src/org/eclipse/stem/populationmodels/standard/provider/PopulationInitializerItemProvider.java (revision 1861) >+++ src/org/eclipse/stem/populationmodels/standard/provider/PopulationInitializerItemProvider.java (working copy) >@@ -18,6 +18,7 @@ > import org.eclipse.emf.common.notify.AdapterFactory; > import org.eclipse.emf.common.notify.Notification; > import org.eclipse.emf.common.util.ResourceLocator; >+import org.eclipse.emf.common.util.URI; > import org.eclipse.emf.edit.provider.ComposeableAdapterFactory; > import org.eclipse.emf.edit.provider.IEditingDomainItemProvider; > import org.eclipse.emf.edit.provider.IItemLabelProvider; >Index: src/org/eclipse/stem/populationmodels/standard/impl/StandardPopulationModelLabelValueImpl.java >=================================================================== >--- src/org/eclipse/stem/populationmodels/standard/impl/StandardPopulationModelLabelValueImpl.java (revision 1861) >+++ src/org/eclipse/stem/populationmodels/standard/impl/StandardPopulationModelLabelValueImpl.java (working copy) >@@ -249,43 +249,53 @@ > * <!-- end-user-doc --> > * @generated NOT > */ >- public boolean adjustDelta(IntegrationLabelValue value) { >+ public boolean avoidNegative(IntegrationLabelValue value) { > StandardPopulationModelLabelValue sval = (StandardPopulationModelLabelValue)value; > boolean adjusted = false; > double newCount = this.getCount() + sval.getCount(); > double newBirths = this.getBirths() + sval.getBirths(); > double newDeaths = this.getDeaths() + sval.getDeaths(); > >- double factor = 1.0; >- if(newCount < newBirths && newCount < newDeaths && newCount < 0.0) { >- // Scale using S >- adjusted = true; >- factor = -sval.getCount()/this.getCount(); >- } else if(newBirths < newDeaths && newBirths < 0.0) { >- // Scale using R >- adjusted = true; >- factor = -sval.getBirths()/this.getBirths(); >- } else if (newDeaths < 0) { >- // Scale using R >+ if(newCount<0.0) { > adjusted = true; >- factor = -sval.getDeaths()/this.getDeaths(); >+ this.setCount(-sval.getCount()); > } >- if(adjusted) this.scale(factor); >- // Due to precision limitations it is still possible the number if tiny negative. Adjust if necessary >- newCount = this.getCount() + sval.getCount(); >- newBirths = this.getBirths() + sval.getBirths(); >- newDeaths = this.getDeaths() + sval.getDeaths(); > >- if(newCount<0) >- this.setCount(-sval.getCount()); >- if(newBirths<0) >+ if(newBirths<0.0) { >+ adjusted = true; > this.setBirths(-sval.getBirths()); >- if(newDeaths<0) >+ } >+ >+ if(newDeaths<0.0) { >+ adjusted = true; > this.setDeaths(-sval.getDeaths()); >+ } > > return adjusted; > > } >+ >+ public double computeDeltaAdjustment(IntegrationLabelValue value) { >+ StandardPopulationModelLabelValue sval = (StandardPopulationModelLabelValue)value; >+ double newCount = this.getCount() + sval.getCount(); >+ double newBirths = this.getBirths() + sval.getBirths(); >+ double newDeaths = this.getDeaths() + sval.getDeaths(); >+ double factor = 1.0; >+ >+ if(newCount < 0.0) { >+ factor = Math.min(factor, -sval.getCount()/this.getCount()); >+ } >+ >+ if(newBirths < 0.0) { >+ factor = Math.min(factor, -sval.getBirths()/this.getBirths()); >+ } >+ >+ if (newDeaths < 0.0) { >+ factor = Math.min(factor, -sval.getDeaths()/this.getDeaths()); >+ } >+ >+ return factor; >+ } > > private EList<Exchange>arrivals; > private EList<Exchange>departures; >Index: src/org/eclipse/stem/populationmodels/standard/impl/AgingPopulationModelImpl.java >=================================================================== >--- src/org/eclipse/stem/populationmodels/standard/impl/AgingPopulationModelImpl.java (revision 1861) >+++ src/org/eclipse/stem/populationmodels/standard/impl/AgingPopulationModelImpl.java (working copy) >@@ -28,7 +28,7 @@ > * <em><b>Aging Population Model</b></em>'. <!-- end-user-doc --> > * <p> > * </p> >- * >+ * > * @generated > */ > public class AgingPopulationModelImpl extends DemographicPopulationModelImpl >@@ -44,7 +44,6 @@ > > /** > * <!-- begin-user-doc --> <!-- end-user-doc --> >- * > * @generated > */ > @Override >Index: src/org/eclipse/stem/populationmodels/standard/StandardPopulationModelLabelValue.java >=================================================================== >--- src/org/eclipse/stem/populationmodels/standard/StandardPopulationModelLabelValue.java (revision 1861) >+++ src/org/eclipse/stem/populationmodels/standard/StandardPopulationModelLabelValue.java (working copy) >@@ -139,12 +139,4 @@ > * @generated > */ > void setDensity(double value); >- >- /** >- * <!-- begin-user-doc --> >- * <!-- end-user-doc --> >- * @model valueType="org.eclipse.stem.populationmodels.standard.IntegrationLabelValue" >- * @generated >- */ >- boolean adjustDelta(IntegrationLabelValue value); > } // StandardPopulationModelLabelValue >Index: model/standard.ecore >=================================================================== >--- model/standard.ecore (revision 1861) >+++ model/standard.ecore (working copy) >@@ -37,9 +37,6 @@ > abstract="true" interface="true"/> > <eClassifiers xsi:type="ecore:EClass" name="PopulationModelLabelValue" eSuperTypes="../../org.eclipse.stem.core/model/graph.ecore#//LabelValue"/> > <eClassifiers xsi:type="ecore:EClass" name="StandardPopulationModelLabelValue" eSuperTypes="#//PopulationModelLabelValue #//IntegrationLabelValue"> >- <eOperations name="adjustDelta" eType="ecore:EDataType platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore#//EBoolean"> >- <eParameters name="value" eType="#//IntegrationLabelValue"/> >- </eOperations> > <eStructuralFeatures xsi:type="ecore:EAttribute" name="count" eType="ecore:EDataType platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore#//EDouble"/> > <eStructuralFeatures xsi:type="ecore:EAttribute" name="births" eType="ecore:EDataType platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore#//EDouble"/> > <eStructuralFeatures xsi:type="ecore:EAttribute" name="deaths" eType="ecore:EDataType platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore#//EDouble"/> >Index: src/org/eclipse/stem/populationmodels/standard/impl/StandardPackageImpl.java >=================================================================== >--- src/org/eclipse/stem/populationmodels/standard/impl/StandardPackageImpl.java (revision 1861) >+++ src/org/eclipse/stem/populationmodels/standard/impl/StandardPackageImpl.java (working copy) >@@ -949,9 +949,6 @@ > initEAttribute(getStandardPopulationModelLabelValue_Deaths(), theEcorePackage.getEDouble(), "deaths", null, 0, 1, StandardPopulationModelLabelValue.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); > initEAttribute(getStandardPopulationModelLabelValue_Density(), theEcorePackage.getEDouble(), "density", null, 0, 1, StandardPopulationModelLabelValue.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); > >- EOperation op = addEOperation(standardPopulationModelLabelValueEClass, theEcorePackage.getEBoolean(), "adjustDelta", 0, 1, IS_UNIQUE, IS_ORDERED); >- addEParameter(op, this.getIntegrationLabelValue(), "value", 0, 1, IS_UNIQUE, IS_ORDERED); >- > initEClass(stochasticStandardPopulationModelEClass, StochasticStandardPopulationModel.class, "StochasticStandardPopulationModel", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); > initEAttribute(getStochasticStandardPopulationModel_Gain(), theEcorePackage.getEDouble(), "gain", "0.01", 0, 1, StochasticStandardPopulationModel.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); > >#P org.eclipse.stem.diseasemodels.experimental >Index: src/org/eclipse/stem/diseasemodels/experimental/impl/TBDiseaseModelLabelValueImpl.java >=================================================================== >--- src/org/eclipse/stem/diseasemodels/experimental/impl/TBDiseaseModelLabelValueImpl.java (revision 1861) >+++ src/org/eclipse/stem/diseasemodels/experimental/impl/TBDiseaseModelLabelValueImpl.java (working copy) >@@ -312,9 +312,13 @@ > return result.toString(); > } > >- public boolean adjustDelta(IntegrationLabelValue value) { >+ public boolean avoidNegative(IntegrationLabelValue value) { > // TODO Auto-generated method stub > return false; > } >+ >+ public double computeDeltaAdjustment(IntegrationLabelValue value) { >+ return 1.0; >+ } > > } //TBDiseaseModelLabelValueImpl >#P org.eclipse.stem.definitions >#P org.eclipse.stem.diseasemodels >Index: src/org/eclipse/stem/diseasemodels/standard/impl/SIRLabelValueImpl.java >=================================================================== >--- src/org/eclipse/stem/diseasemodels/standard/impl/SIRLabelValueImpl.java (revision 1861) >+++ src/org/eclipse/stem/diseasemodels/standard/impl/SIRLabelValueImpl.java (working copy) >@@ -279,7 +279,7 @@ > * @return boolean > * @override > */ >- public boolean adjustDelta(IntegrationLabelValue target) { >+ public boolean avoidNegative(IntegrationLabelValue target) { > SIRLabelValue sirValue = (SIRLabelValue)target; > boolean adjusted = false; > double newS = this.getS() + sirValue.getS(); >@@ -287,43 +287,56 @@ > double newR = this.getR() + sirValue.getR(); > double newDD = this.getDiseaseDeaths() + sirValue.getDiseaseDeaths(); > >- double factor = 1.0; >- if(newS < newI && newS < newR && newS < newDD && newS < 0.0) { >- // Scale using S >+ if(newS<0.0) { > adjusted = true; >- factor = -sirValue.getS()/this.getS(); >- } else if(newI < newR && newI < newDD && newI < 0.0) { >- // Scale using I >+ this.setS(-sirValue.getS()); >+ } >+ >+ if(newI<0.0) { > adjusted = true; >- factor = -sirValue.getI()/this.getI(); >- } else if(newR < newDD && newR < 0.0) { >- // Scale using R >+ this.setI(-sirValue.getI()); >+ } >+ >+ if(newR<0.0) { > adjusted = true; >- factor = -sirValue.getR()/this.getR(); >- } else if(newDD < 0.0) { >- // Scale using DD >+ this.setR(-sirValue.getR()); >+ } >+ >+ if(newDD < 0.0) { > adjusted = true; >- factor = -sirValue.getDiseaseDeaths()/this.getDiseaseDeaths(); >+ this.setDiseaseDeaths(-sirValue.getDiseaseDeaths()); > } >- if(adjusted) this.scale(factor); > >+ return adjusted; >+ } >+ >+ public double computeDeltaAdjustment(IntegrationLabelValue value) { >+ SIRLabelValue sirValue = (SIRLabelValue)value; >+ double newS = this.getS() + sirValue.getS(); >+ double newI = this.getI() + sirValue.getI(); >+ double newR = this.getR() + sirValue.getR(); >+ double newDD = this.getDiseaseDeaths() + sirValue.getDiseaseDeaths(); >+ double factor = 1.0; > >- // Due to precision limitations it is still possible the number if tiny negative. Adjust if necessary >- newS = this.getS() + sirValue.getS(); >- newI = this.getI() + sirValue.getI(); >- newR = this.getR() + sirValue.getR(); >- newDD = this.getDiseaseDeaths() + sirValue.getDiseaseDeaths(); >+ if(newS < 0.0) { >+ factor = Math.min(factor, -sirValue.getS()/this.getS()); >+ } >+ >+ if(newI < 0.0) { >+ factor = Math.min(factor, -sirValue.getI()/this.getI()); >+ } > >- if(newS<0) >- this.setS(-sirValue.getS()); >- if(newI<0) >- this.setI(-sirValue.getI()); >- if(newR<0) >- this.setR(-sirValue.getR()); >- if(newDD < 0) >- this.setDiseaseDeaths(-sirValue.getDiseaseDeaths()); >- return adjusted; >+ if(newR < 0.0) { >+ factor = Math.min(factor, -sirValue.getR()/this.getR()); >+ } >+ >+ if(newDD < 0.0) { >+ factor = Math.min(factor, -sirValue.getDiseaseDeaths()/this.getDiseaseDeaths()); >+ } >+ >+ return factor; > } >+ > /** > * @see org.eclipse.stem.core.graph.impl.LabelValueImpl#reset() > */ >Index: src/org/eclipse/stem/diseasemodels/standard/impl/SEIRLabelValueImpl.java >=================================================================== >--- src/org/eclipse/stem/diseasemodels/standard/impl/SEIRLabelValueImpl.java (revision 1861) >+++ src/org/eclipse/stem/diseasemodels/standard/impl/SEIRLabelValueImpl.java (working copy) >@@ -266,9 +266,8 @@ > * @return boolean > * @override > */ >- public boolean adjustDelta(IntegrationLabelValue target) { >- SEIRLabelValue seirValue = (SEIRLabelValue)target; >- >+ public boolean avoidNegative(IntegrationLabelValue target) { >+ SEIRLabelValue seirValue = (SEIRLabelValue)target; > boolean adjusted = false; > double newS = this.getS() + seirValue.getS(); > double newE = this.getE() + seirValue.getE(); >@@ -276,49 +275,65 @@ > double newR = this.getR() + seirValue.getR(); > double newDD = this.getDiseaseDeaths() +seirValue.getDiseaseDeaths(); > >- double factor = 1.0; >- if(newS < newE && newS < newI && newS < newR && newS < newDD && newS < 0.0) { >- // Scale using S >+ if(newS<0.0) { > adjusted = true; >- factor = -seirValue.getS()/this.getS(); >- } else if(newE < newI && newE < newR && newE < newDD && newE < 0.0) { >- // Scale using E >- adjusted = true; >- factor = -seirValue.getE()/this.getE(); >- } else if(newI < newR && newI < newDD && newI < 0.0) { >- // Scale using I >- adjusted = true; >- factor = -seirValue.getI()/this.getI(); >- } else if(newR < newDD && newR < 0.0) { >- // Scale using R >- adjusted = true; >- factor = -seirValue.getR()/this.getR(); >- } else if(newDD < 0) { >- // Scale using R >- adjusted = true; >- factor = -seirValue.getDiseaseDeaths()/this.getDiseaseDeaths(); >+ this.setS(-seirValue.getS()); > } >- if(adjusted) this.scale(factor); > >- // Due to precision limitations it is still possible the number if tiny negative. Adjust if necessary >- newS = this.getS() + seirValue.getS(); >- newE = this.getE() + seirValue.getE(); >- newI = this.getI() + seirValue.getI(); >- newR = this.getR() + seirValue.getR(); >- newDD = this.getDiseaseDeaths() + seirValue.getDiseaseDeaths(); >- if(newS<0) >- this.setS(-seirValue.getS()); >- if(newE<0) >+ if(newE<0.0) { >+ adjusted = true; > this.setE(-seirValue.getE()); >- if(newI<0) >+ } >+ >+ if(newI<0.0) { >+ adjusted = true; > this.setI(-seirValue.getI()); >- if(newR<0) >+ } >+ >+ if(newR<0.0) { >+ adjusted = true; > this.setR(-seirValue.getR()); >- if(newDD < 0) >+ } >+ >+ if(newDD < 0.0) { >+ adjusted = true; > this.setDiseaseDeaths(-seirValue.getDiseaseDeaths()); >+ } >+ > return adjusted; > } > >+ public double computeDeltaAdjustment(IntegrationLabelValue value) { >+ SEIRLabelValue seirValue = (SEIRLabelValue)value; >+ double newS = this.getS() + seirValue.getS(); >+ double newE = this.getE() + seirValue.getE(); >+ double newI = this.getI() + seirValue.getI(); >+ double newR = this.getR() + seirValue.getR(); >+ double newDD = this.getDiseaseDeaths() +seirValue.getDiseaseDeaths(); >+ double factor = 1.0; >+ >+ if(newS < 0.0) { >+ factor = Math.min(factor, -seirValue.getS()/this.getS()); >+ } >+ >+ if(newE < 0.0) { >+ factor = Math.min(factor, -seirValue.getE()/this.getE()); >+ } >+ >+ if(newI < 0.0) { >+ factor = Math.min(factor, -seirValue.getI()/this.getI()); >+ } >+ >+ if(newR < 0.0) { >+ factor = Math.min(factor, -seirValue.getR()/this.getR()); >+ } >+ >+ if(newDD < 0.0) { >+ factor = Math.min(factor, -seirValue.getDiseaseDeaths()/this.getDiseaseDeaths()); >+ } >+ >+ return factor; >+ } > > /** > * @see org.eclipse.stem.diseasemodels.standard.impl.SIRLabelValueImpl#reset() >Index: src/org/eclipse/stem/diseasemodels/standard/impl/SILabelValueImpl.java >=================================================================== >--- src/org/eclipse/stem/diseasemodels/standard/impl/SILabelValueImpl.java (revision 1861) >+++ src/org/eclipse/stem/diseasemodels/standard/impl/SILabelValueImpl.java (working copy) >@@ -406,41 +406,51 @@ > * > * @return boolean > */ >- public boolean adjustDelta(IntegrationLabelValue target) { >+ public boolean avoidNegative(IntegrationLabelValue target) { > SILabelValue siValue = (SILabelValue)target; > boolean adjusted = false; > double newS = this.getS() + siValue.getS(); > double newI = this.getI() + siValue.getI(); > double newDD = this.getDiseaseDeaths() + siValue.getDiseaseDeaths(); > >- double factor = 1.0; >- if(newS < newI && newS < newDD && newS < 0.0) { >- // Scale using S >- adjusted = true; >- factor = -siValue.getS()/this.getS(); >- } else if(newI < newDD && newI < 0.0) { >- // Scale using R >- adjusted = true; >- factor = -siValue.getI()/this.getI(); >- } else if (newDD < 0) { >- // Scale using R >+ if(newS<0.0) { > adjusted = true; >- factor = -siValue.getDiseaseDeaths()/this.getDiseaseDeaths(); >+ this.setS(-siValue.getS()); > } >- if(adjusted) this.scale(factor); >- // Due to precision limitations it is still possible the number if tiny negative. Adjust if necessary >- newS = this.getS() + siValue.getS(); >- newI = this.getI() + siValue.getI(); >- newDD = this.getDiseaseDeaths() + siValue.getDiseaseDeaths(); > >- if(newS<0) >- this.setS(-siValue.getS()); >- if(newI<0) >+ if(newI<0.0) { >+ adjusted = true; > this.setI(-siValue.getI()); >- if(newDD<0) >+ } >+ >+ if(newDD<0.0) { >+ adjusted = true; > this.setDiseaseDeaths(-siValue.getDiseaseDeaths()); >+ } > > return adjusted; > } > >+ public double computeDeltaAdjustment(IntegrationLabelValue value) { >+ SILabelValue siValue = (SILabelValue)value; >+ double newS = this.getS() + siValue.getS(); >+ double newI = this.getI() + siValue.getI(); >+ double newDD = this.getDiseaseDeaths() + siValue.getDiseaseDeaths(); >+ double factor = 1.0; >+ >+ if(newS < 0.0) { >+ factor = Math.min(factor, -siValue.getS()/this.getS()); >+ } >+ >+ if(newI < 0.0) { >+ factor = Math.min(factor, -siValue.getI()/this.getI()); >+ } >+ >+ if (newDD < 0) { >+ factor = Math.min(factor, -siValue.getDiseaseDeaths()/this.getDiseaseDeaths()); >+ } >+ >+ return factor; >+ } >+ > } // SILabelValueImpl >#P org.eclipse.stem.solvers.fd >Index: src/org/eclipse/stem/solvers/fd/impl/FdJob.java >=================================================================== >--- src/org/eclipse/stem/solvers/fd/impl/FdJob.java (revision 1861) >+++ src/org/eclipse/stem/solvers/fd/impl/FdJob.java (working copy) >@@ -13,6 +13,7 @@ > > > >+import org.eclipse.core.internal.runtime.LocalizationUtils; > import org.eclipse.core.runtime.IProgressMonitor; > import org.eclipse.core.runtime.IStatus; > import org.eclipse.core.runtime.Status; >@@ -30,6 +31,9 @@ > this.threadnum = thread; > this.solver = s; > } >+ >+ public static int COMPUTE_DELTAS = 0; >+ public static int APPLY_DELTAS = 1; > > protected double progress; > protected double t; >@@ -39,6 +43,7 @@ > long timeDelta; > int cycle; > short threadnum; >+ int step; > > public double getProgress() { > return this.progress; >@@ -47,8 +52,17 @@ > this.progress = p; > } > protected IStatus run(final IProgressMonitor monitor) { >- solver._step(time,timeDelta,cycle,threadnum); >+ IStatus status = Status.CANCEL_STATUS; > >- return Status.OK_STATUS; >+ if (step == COMPUTE_DELTAS) { >+ double adjustmentFactor = solver.computeDeltasStep(time,timeDelta,cycle,threadnum); >+ >+ status = new Status(IStatus.OK, "unknownId", adjustmentFactor + ""); >+ } else if (step == APPLY_DELTAS) { >+ solver.applyDeltasStep(time, timeDelta, cycle, threadnum); >+ status = new Status(IStatus.OK, "unknownId", ""); >+ } >+ >+ return status; > } > } >Index: src/org/eclipse/stem/solvers/fd/impl/FiniteDifferenceImpl.java >=================================================================== >--- src/org/eclipse/stem/solvers/fd/impl/FiniteDifferenceImpl.java (revision 1861) >+++ src/org/eclipse/stem/solvers/fd/impl/FiniteDifferenceImpl.java (working copy) >@@ -97,7 +97,7 @@ > } else currentStateLabelIter.next(); > } > } >- >+ > if(jobs == null || jobs.length != num_threads) { > // Initialize the jobs if not done yet or of the number of threads changes > jobs = new FdJob[num_threads]; >@@ -107,13 +107,20 @@ > jobs[i] = new FdJob("Finite Difference Worker "+i, threadnum, this); > } // For each job > } // If not initialized >- >+ >+ recursiveStep(time, timeDelta, cycle); >+ >+ return true; >+ } >+ >+ protected void recursiveStep(STEMTime time, long timeDelta, int cycle) { > // Initialize > > for(FdJob j:jobs) { > j.cycle = cycle; > j.time = time; > j.timeDelta = timeDelta; >+ j.step = FdJob.COMPUTE_DELTAS; > } > > // Schedule. Jobs can be rescheduled after finished >@@ -129,30 +136,84 @@ > } > } > >- // Set the common time and step size here and validate everything is right >- //double minStep = Double.MAX_VALUE; >- //double currentT = jobs[0].t; >- //for(SimJob j : jobs) { >- // The jobs have calculated new step sizes after they finished. Pick the >- // smallest one for the next cycle >- // if(j.h < minStep) minStep = j.h; >- // if(j.t != currentT) Activator.logError("Error, one thread was in misstep with other threads, its time was "+j.t+" versus "+currentT, new Exception()); >- //} >+ double factor = 1.0; > >- //this.setCurrentX(currentT); >- //this.setStepSize(minStep); // smallest one from above. >- return true; >+ for (FdJob j : jobs) { >+ factor = Math.min(factor, Double.parseDouble(j.getResult().getMessage())); >+ } >+ >+ if (factor == 1.0) { >+ // Apply deltas >+ >+ for(FdJob j:jobs) >+ j.step = FdJob.APPLY_DELTAS; >+ >+ for(FdJob j:jobs) >+ j.schedule(); >+ >+ for(FdJob j : jobs) { >+ try { >+ j.join(); >+ } catch(InterruptedException ie) { >+ Activator.logError(ie.getMessage(), ie); >+ } >+ } >+ } else { >+ // Compute deltas for smaller time step >+ long newTimeDelta = (long) Math.floor(factor*timeDelta); >+ >+ for(FdJob j:jobs) >+ j.timeDelta = newTimeDelta; >+ >+ for(FdJob j:jobs) >+ j.schedule(); >+ >+ for(FdJob j : jobs) { >+ try { >+ j.join(); >+ } catch(InterruptedException ie) { >+ Activator.logError(ie.getMessage(), ie); >+ } >+ } >+ >+ // Apply deltas >+ >+ for(FdJob j:jobs) >+ j.step = FdJob.APPLY_DELTAS; >+ >+ for(FdJob j:jobs) >+ j.schedule(); >+ >+ for(FdJob j : jobs) { >+ try { >+ j.join(); >+ } catch(InterruptedException ie) { >+ Activator.logError(ie.getMessage(), ie); >+ } >+ } >+ >+ // Call this method again for the rest of the time step >+ >+ for(Decorator decorator:this.getDecorators()) { >+ EList<DynamicLabel>allLabels = decorator.getLabelsToUpdate(); >+ for (final Iterator<DynamicLabel> currentStateLabelIter = allLabels >+ .iterator(); currentStateLabelIter.hasNext();) { >+ if(decorator instanceof IntegrationDecorator) { >+ // It's a standard disease model with a standard disease model label >+ final IntegrationLabel iLabel = (IntegrationLabel) currentStateLabelIter.next(); >+ ((IntegrationLabelValue)iLabel.getProbeValue()).set((IntegrationLabelValue)iLabel.getNextValue()); >+ ((IntegrationLabelValue)iLabel.getTempValue()).set((IntegrationLabelValue)iLabel.getNextValue()); >+ ((IntegrationLabelValue)iLabel.getTempValue()).prepareCycle(); >+ ((IntegrationLabelValue)iLabel.getProbeValue()).prepareCycle(); >+ } else currentStateLabelIter.next(); >+ } >+ } >+ >+ recursiveStep(time, timeDelta - newTimeDelta, cycle); >+ } > } > >- /** >- * _step Do the step for a single thread >- * >- * @param time >- * @param timeDelta >- * @param cycle >- * @param threadnum >- */ >- protected void _step(STEMTime time, long timeDelta, int cycle, short threadnum) { >+ protected double computeDeltasStep(STEMTime time, long timeDelta, int cycle, short threadnum) { > // Now give each decorator a chance to update its dynamic > // labels in the canonical graph, but only if it is enabled. A > // Decorator might not be enabled if it is the action of a Trigger >@@ -170,11 +231,41 @@ > for(IntegrationDecorator imodel:iDecorators) > imodel.applyExternalDeltas(time, timeDelta, partitioner.partitionDecoratorLabels((Decorator)imodel, threadnum)); > >+ double factor = 1.0; >+ > for(IntegrationDecorator imodel:iDecorators) >- updateStandardDiseaseModelLabels((Decorator)imodel, time, timeDelta, cycle, threadnum); >+ factor = Math.min(factor, getDeltaAdjustment((Decorator)imodel, threadnum)); > >+ return factor; >+ } >+ >+ protected void applyDeltasStep(STEMTime time, long timeDelta, int cycle, short threadnum) { >+ EList<IntegrationDecorator> iDecorators = new BasicEList<IntegrationDecorator>(); >+ for (final Iterator<Decorator> decoratorIter = this >+ .getDecorators().iterator(); decoratorIter.hasNext();) { >+ final Decorator decorator = decoratorIter.next(); >+ // Is the decorator enabled? >+ if (decorator.isEnabled() && decorator instanceof IntegrationDecorator) iDecorators.add((IntegrationDecorator)decorator); >+ } >+ >+ for(IntegrationDecorator imodel:iDecorators) >+ updateStandardDiseaseModelLabels((Decorator)imodel, time, timeDelta, cycle, threadnum); > } > >+ protected double getDeltaAdjustment(Decorator model, short threadnum) { >+ EList<DynamicLabel> myLabels = partitioner.partitionDecoratorLabels(model, threadnum); >+ double factor = 1.0; >+ >+ for (final Iterator<DynamicLabel> currentStateLabelIter = myLabels >+ .iterator(); currentStateLabelIter.hasNext();) { >+ final IntegrationLabel label = (IntegrationLabel) currentStateLabelIter.next(); >+ >+ IntegrationLabelValue delta = (IntegrationLabelValue)label.getDeltaValue(); >+ factor = Math.min(factor, delta.computeDeltaAdjustment((IntegrationLabelValue)label.getProbeValue())); >+ } >+ >+ return factor; >+ } > > protected void updateStandardDiseaseModelLabels(Decorator model, STEMTime time, long timeDelta, int cycle, short threadnum) { > >@@ -189,13 +280,13 @@ > // Initialize the next value from the current value and add the delta > for (final Iterator<DynamicLabel> currentStateLabelIter = myLabels > .iterator(); currentStateLabelIter.hasNext();) { >- final DynamicLabel label = (DynamicLabel) currentStateLabelIter.next(); >+ final IntegrationLabel label = (IntegrationLabel) currentStateLabelIter.next(); > LabelValue nextState = label.getNextValue(); > > LabelValue delta = ((IntegrationLabel)label).getDeltaValue(); > // For finite difference, we need to make sure we don't > // move too many people from one state to another >- ((IntegrationLabelValue)delta).adjustDelta((IntegrationLabelValue)label.getCurrentValue()); >+ ((IntegrationLabelValue)delta).avoidNegative((IntegrationLabelValue)label.getProbeValue()); > > nextState.reset(); > // Add delta, this will also add the incidence >#P org.eclipse.stem.tests.populationmodels >Index: src/org/eclipse/stem/populationmodels/standard/tests/StandardPopulationModelLabelValueTest.java >=================================================================== >--- src/org/eclipse/stem/populationmodels/standard/tests/StandardPopulationModelLabelValueTest.java (revision 1861) >+++ src/org/eclipse/stem/populationmodels/standard/tests/StandardPopulationModelLabelValueTest.java (working copy) >@@ -15,12 +15,6 @@ > * <!-- begin-user-doc --> > * A test case for the model object '<em><b>Population Model Label Value</b></em>'. > * <!-- end-user-doc --> >- * <p> >- * The following operations are tested: >- * <ul> >- * <li>{@link org.eclipse.stem.populationmodels.standard.StandardPopulationModelLabelValue#adjustDelta(org.eclipse.stem.core.graph.IntegrationLabelValue) <em>Adjust Delta</em>}</li> >- * </ul> >- * </p> > * @generated > */ > public class StandardPopulationModelLabelValueTest extends PopulationModelLabelValueTest { >@@ -104,10 +98,10 @@ > } > > /** >- * Tests the '{@link org.eclipse.stem.populationmodels.standard.StandardPopulationModelLabelValue#adjustDelta(org.eclipse.stem.core.graph.IntegrationLabelValue) <em>Adjust Delta</em>}' operation. >+ * Tests the '{@link org.eclipse.stem.populationmodels.standard.StandardPopulationModelLabelValue#avoidNegative(org.eclipse.stem.core.graph.IntegrationLabelValue) <em>Adjust Delta</em>}' operation. > * <!-- begin-user-doc --> > * <!-- end-user-doc --> >- * @see org.eclipse.stem.populationmodels.standard.StandardPopulationModelLabelValue#adjustDelta(org.eclipse.stem.core.graph.IntegrationLabelValue) >+ * @see org.eclipse.stem.populationmodels.standard.StandardPopulationModelLabelValue#avoidNegative(org.eclipse.stem.core.graph.IntegrationLabelValue) > * @generated NOT > */ > public void testAdjustDelta__IntegrationLabelValue() {
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
sedlund
:
iplog+
Actions:
View
|
Diff
Attachments on
bug 346732
: 196234 |
196250
|
196256
|
196577