1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2012 Association for Decentralized Information Management in
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.sysdyn.manager;
\r
14 import java.util.ArrayList;
\r
15 import java.util.Collection;
\r
16 import java.util.concurrent.ScheduledExecutorService;
\r
18 import org.simantics.db.ReadGraph;
\r
19 import org.simantics.db.Resource;
\r
20 import org.simantics.simulation.experiment.IDynamicExperiment;
\r
23 * Sensitivity analysis experiment
\r
24 * @author Tuomas Miettinen
\r
27 public class SysdynSensitivityAnalysisExperiment extends SysdynExperiment implements IDynamicExperiment {
\r
29 public enum Distribution {
\r
34 private final Distribution propabilityDistribution = DEFAULT_PROPABILITY_DISTRIBUTION;
\r
36 public static Distribution DEFAULT_PROPABILITY_DISTRIBUTION = Distribution.UNIFORM;
\r
37 public static double DEFAULT_MIN_VALUE = 1.0;
\r
38 public static double DEFAULT_MAX_VALUE = 3.0;
\r
39 public static int DEFAULT_NUM_VALUES = 3;
\r
41 private final Collection<Runnable> timeListeners = new ArrayList<Runnable>();
\r
43 ScheduledExecutorService playbackExecutionService;
\r
44 //SensitivityAnalysisConfiguration playbackConfiguration;
\r
46 public SysdynSensitivityAnalysisExperiment(Resource experiment, Resource model) {
\r
47 super(experiment, model);
\r
52 * Interrupts a possible ongoing playback
\r
56 // public void setTimeInterrupting(double time) {
\r
62 // * Sets a new time and continues playback from that point if
\r
63 // * playback was running
\r
66 // public void setTimeAndContinue(double time) {
\r
67 // if(isPlaybackRunning()) {
\r
70 // startPlayback(500);
\r
76 private void setTime(double time) {
\r
81 public double getTime() {
\r
85 public double getStartTime() {
\r
86 return this.startTime;
\r
89 public double getEndTime() {
\r
90 return this.endTime;
\r
93 public void setPlaybackDuration(long duration) {
\r
94 this.playbackDuration = duration;
\r
95 if(isPlaybackRunning()) {
\r
96 //Restart playback with different time settings
\r
101 public long getPlaybackDuration() {
\r
102 return this.playbackDuration;
\r
106 public void init(ReadGraph g) {
\r
108 this.session = g.getSession();
\r
109 session.asyncRequest(new ReadRequest() {
\r
112 public void run(ReadGraph graph) throws DatabaseException {
\r
113 changeState(ExperimentState.RUNNING);
\r
114 final Resource configuration = graph.getPossibleObject(model, SimulationResource.getInstance(graph).HasConfiguration);
\r
115 sysdynModel = SysdynModelManager.getInstance(session).getModel(graph, configuration);
\r
116 toggleActivation(graph, true);
\r
117 //getPlaybackConfiguration(graph);
\r
118 startSimulationJob();
\r
125 private class SensitivityAnalysisConfiguration {
\r
126 public double simulationDuration, simulationStepLength, intervals, endTime, startTime;
\r
127 public long playbackDuration;
\r
131 protected void localStateChange() {
\r
132 super.localStateChange();
\r
136 public void addTimeListener(Runnable timeListener) {
\r
137 if(!this.timeListeners.contains(timeListener))
\r
138 this.timeListeners.add(timeListener);
\r
141 public Collection<Runnable> getTimeListeners() {
\r
142 return this.timeListeners;
\r
145 public void removeTimeListener(Runnable timeListener) {
\r
146 this.timeListeners.remove(timeListener);
\r
150 public void resultsChanged() {
\r
151 for(Runnable listener : timeListeners) {
\r
154 super.resultsChanged();
\r