]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
c7da1528475fcd5e5715e7524e2ea7a4b12500f3
[simantics/sysdyn.git] /
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2012 Association for Decentralized Information Management in\r
3  * Industry THTH ry.\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
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.sysdyn.manager;\r
13 \r
14 import java.util.ArrayList;\r
15 import java.util.Collection;\r
16 import java.util.concurrent.ScheduledExecutorService;\r
17 \r
18 import org.simantics.db.ReadGraph;\r
19 import org.simantics.db.Resource;\r
20 import org.simantics.simulation.experiment.IDynamicExperiment;\r
21 \r
22 /**\r
23  * Sensitivity analysis experiment\r
24  * @author Tuomas Miettinen\r
25  *\r
26  */\r
27 public class SysdynSensitivityAnalysisExperiment extends SysdynExperiment implements IDynamicExperiment {\r
28 \r
29     public enum Distribution {\r
30         UNIFORM,\r
31         NORMAL\r
32     }\r
33     \r
34     private final Distribution propabilityDistribution = DEFAULT_PROPABILITY_DISTRIBUTION;\r
35     \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
40     \r
41     private final Collection<Runnable> timeListeners = new ArrayList<Runnable>();\r
42 \r
43     ScheduledExecutorService playbackExecutionService;\r
44     //SensitivityAnalysisConfiguration playbackConfiguration;\r
45 \r
46     public SysdynSensitivityAnalysisExperiment(Resource experiment, Resource model) {\r
47         super(experiment, model);\r
48     }\r
49 \r
50 \r
51     /**\r
52      * Interrupts a possible ongoing playback\r
53      * \r
54      * @param time\r
55      */\r
56 //    public void setTimeInterrupting(double time) {\r
57 //        stopPlayback();\r
58 //        setTime(time);\r
59 //    }\r
60 //\r
61 //    /**\r
62 //     * Sets a new time and continues playback from that point if \r
63 //     * playback was running  \r
64 //     * @param time\r
65 //     */\r
66 //    public void setTimeAndContinue(double time) {\r
67 //        if(isPlaybackRunning()) {\r
68 //            stopPlayback();\r
69 //            setTime(time);\r
70 //            startPlayback(500);\r
71 //        } else {\r
72 //            setTime(time);\r
73 //        }\r
74 //    }\r
75 /*\r
76   private void setTime(double time) {\r
77         this.time = time;\r
78         resultsChanged(); \r
79     }\r
80 \r
81     public double getTime() {\r
82         return this.time;\r
83     }\r
84 \r
85     public double getStartTime() {\r
86         return this.startTime;\r
87     }\r
88 \r
89     public double getEndTime() {\r
90         return this.endTime;\r
91     }\r
92 \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
97             startPlayback();\r
98         }\r
99     }\r
100 \r
101     public long getPlaybackDuration() {\r
102         return this.playbackDuration;\r
103     }\r
104 \r
105     @Override\r
106     public void init(ReadGraph g) {\r
107         super.init(g);\r
108         this.session = g.getSession();\r
109         session.asyncRequest(new ReadRequest() {\r
110 \r
111             @Override\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
119             }\r
120         });\r
121     }\r
122 \r
123 \r
124 \r
125     private class SensitivityAnalysisConfiguration {\r
126         public double simulationDuration, simulationStepLength, intervals, endTime, startTime;\r
127         public long playbackDuration;\r
128     }\r
129 \r
130     @Override\r
131     protected void localStateChange() {\r
132         super.localStateChange();\r
133     }\r
134 \r
135     // TIME LISTENERS\r
136     public void addTimeListener(Runnable timeListener) {\r
137         if(!this.timeListeners.contains(timeListener))\r
138             this.timeListeners.add(timeListener);\r
139     }\r
140 \r
141     public Collection<Runnable> getTimeListeners() {\r
142         return this.timeListeners;\r
143     }\r
144 \r
145     public void removeTimeListener(Runnable timeListener) {\r
146         this.timeListeners.remove(timeListener);\r
147     }\r
148 \r
149     @Override\r
150     public void resultsChanged() {\r
151         for(Runnable listener : timeListeners) {\r
152             listener.run();\r
153         }\r
154         super.resultsChanged();\r
155 \r
156     }\r
157 */\r
158 }\r