From: miettinen Date: Fri, 15 Mar 2013 07:02:42 +0000 (+0000) Subject: Initial version of the user interface for the sensitivity analysis simulation (refs... X-Git-Tag: simantics-1.10.1~4 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=c29b55be4038c38707c030db0862f3fbf7a7ffc1;p=simantics%2Fsysdyn.git Initial version of the user interface for the sensitivity analysis simulation (refs #4171). Currently there is little functionality under the interface. git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@27102 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ontology/graph.tg b/org.simantics.sysdyn.ontology/graph.tg index 138c666d..a7b7d77e 100644 Binary files a/org.simantics.sysdyn.ontology/graph.tg and b/org.simantics.sysdyn.ontology/graph.tg differ diff --git a/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph b/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph index 12ada0e5..30c5641a 100644 --- a/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph +++ b/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph @@ -345,6 +345,14 @@ SYSDYN.SimulateOnChangeExperiment -- SYSDYN.SensitivityAnalysisExperiment.propabilityDistribution --> L0.String -- SYSDYN.SensitivityAnalysisExperiment.variedParameter --> SYSDYN.Auxiliary -- SYSDYN.SensitivityAnalysisExperiment.variedParameter --> L0.String -- SYSDYN.SensitivityAnalysisExperiment.minValue --> L0.Double -- SYSDYN.SensitivityAnalysisExperiment.maxValue --> L0.Double -- SYSDYN.SensitivityAnalysisExperiment.numValues --> L0.Integer + + @@ -459,6 +463,86 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -563,6 +647,23 @@ + + + + + + + + + + + + + + + + + + + + @@ -1627,9 +1755,13 @@ commandId="org.simantics.sysdyn.ui.newPlaybackExperiment"> + + diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/AbstractNodeImager.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/AbstractNodeImager.java index 966a8b47..7b41ca14 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/AbstractNodeImager.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/AbstractNodeImager.java @@ -76,6 +76,8 @@ public class AbstractNodeImager extends ImagerContributor image = "icons/timeline_marker.png"; else if(graph.isInstanceOf(node.data, sr.GameExperiment)) image = "icons/time_go.png"; + else if(graph.isInstanceOf(node.data, sr.SensitivityAnalysisExperiment)) + image = "icons//rainbow.png"; else image = "icons/time.png"; } else if (node instanceof InputNode) diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewGameExperimentNodeHanlder.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewGameExperimentNodeHandler.java similarity index 94% rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewGameExperimentNodeHanlder.java rename to org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewGameExperimentNodeHandler.java index fb83a750..7d759c34 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewGameExperimentNodeHanlder.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewGameExperimentNodeHandler.java @@ -23,7 +23,7 @@ import org.simantics.sysdyn.manager.SysdynGameExperiment; * @author Teemu Lempinen * */ -public class NewGameExperimentNodeHanlder extends NewExperimentNodeHandler { +public class NewGameExperimentNodeHandler extends NewExperimentNodeHandler { protected Resource getExperimentType(ReadGraph g) { return SysdynResource.getInstance(g).GameExperiment; diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewSensitivityAnalysisExperimentNodeHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewSensitivityAnalysisExperimentNodeHandler.java new file mode 100644 index 00000000..26d63daf --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewSensitivityAnalysisExperimentNodeHandler.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers.newComponents; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.manager.SysdynSensitivityAnalysisExperiment; + +/** + * Creates a new sensitivity analysis experiment. + * + * @author Tuomas Miettinen + * + */ +public class NewSensitivityAnalysisExperimentNodeHandler extends NewExperimentNodeHandler { + + @Override + protected void configureExperiment(WriteGraph graph, Resource experiment) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + graph.claimLiteral(experiment, sr.SensitivityAnalysisExperiment_minValue, SysdynSensitivityAnalysisExperiment.DEFAULT_MIN_VALUE); + graph.claimLiteral(experiment, sr.SensitivityAnalysisExperiment_maxValue, SysdynSensitivityAnalysisExperiment.DEFAULT_MAX_VALUE); + graph.claimLiteral(experiment, sr.SensitivityAnalysisExperiment_numValues, SysdynSensitivityAnalysisExperiment.DEFAULT_NUM_VALUES); + graph.claimLiteral(experiment, sr.SensitivityAnalysisExperiment_propabilityDistribution, "uniform"); + } + + @Override + protected Resource getExperimentType(ReadGraph g) { + return SysdynResource.getInstance(g).SensitivityAnalysisExperiment; + } + + @Override + protected String getNameSuggestion() { + return "Sensitivity Experiment"; + } +} \ No newline at end of file diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/sensitivityAnalysis/RunSensitivityAnalysisExperiment.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/sensitivityAnalysis/RunSensitivityAnalysisExperiment.java new file mode 100644 index 00000000..9702a8e2 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/sensitivityAnalysis/RunSensitivityAnalysisExperiment.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers.sensitivityAnalysis; + + +import java.util.Map; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.ui.commands.IElementUpdater; +import org.eclipse.ui.menus.UIElement; +import org.simantics.simulation.experiment.ExperimentState; +import org.simantics.simulation.experiment.IDynamicExperiment; +import org.simantics.simulation.experiment.IExperiment; +import org.simantics.simulation.project.IExperimentManager; +import org.simantics.sysdyn.manager.SysdynExperiment; +import org.simantics.sysdyn.ui.utils.HandlerUtils; +import org.simantics.ui.SimanticsUI; + +/** + * Handler for starting a sensitivity analysis simulation + * @author Tuomas Miettinen + * + */ +public class RunSensitivityAnalysisExperiment extends AbstractHandler implements IElementUpdater { + + public static final String COMMAND = "org.simantics.sysdyn.ui.runSensitivityAnalysis"; + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + // Current functionality is normal run experiment + + HandlerUtils.saveEquation(event); + + IExperimentManager manager = + SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER); + IExperiment experiment = manager.getActiveExperiment(); + if(experiment instanceof IDynamicExperiment) + ((IDynamicExperiment)experiment).simulate(true); + return null; + } + + // What does this method do, is this needed? + @SuppressWarnings("rawtypes") + @Override + public void updateElement(UIElement element, Map parameters) { + IExperimentManager manager = + SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER); + IExperiment experiment = manager.getActiveExperiment(); + if(experiment instanceof SysdynExperiment) { + ExperimentState state = experiment.getState(); + if(state == ExperimentState.RUNNING) { + this.setBaseEnabled(false); + } else { + this.setBaseEnabled(true); + } + } + } +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/sensitivityAnalysis/SaveResultsHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/sensitivityAnalysis/SaveResultsHandler.java new file mode 100644 index 00000000..e0bc013b --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/sensitivityAnalysis/SaveResultsHandler.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers.sensitivityAnalysis; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.simantics.simulation.experiment.IDynamicExperiment; +import org.simantics.simulation.experiment.IExperiment; +import org.simantics.simulation.project.IExperimentManager; +import org.simantics.sysdyn.ui.utils.HandlerUtils; +import org.simantics.ui.SimanticsUI; + +/** + * Save the results of a sensitivity analysis experiment + * @author Tuomas Miettinen + * + */ +public class SaveResultsHandler extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + // Current functionality is normal run experiment + + HandlerUtils.saveEquation(event); + + IExperimentManager manager = + SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER); + IExperiment experiment = manager.getActiveExperiment(); + if(experiment instanceof IDynamicExperiment) { + ((IDynamicExperiment)experiment).saveState(); + } + return null; + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/sensitivityAnalysis/ToggleSimulation.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/sensitivityAnalysis/ToggleSimulation.java new file mode 100644 index 00000000..291f936f --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/sensitivityAnalysis/ToggleSimulation.java @@ -0,0 +1,87 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers.sensitivityAnalysis; + + +import java.util.Map; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.Command; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.State; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.commands.ICommandService; +import org.eclipse.ui.commands.IElementUpdater; +import org.eclipse.ui.menus.UIElement; +import org.simantics.simulation.experiment.IExperiment; +import org.simantics.simulation.project.IExperimentManager; +import org.simantics.sysdyn.manager.SysdynExperiment; +import org.simantics.sysdyn.ui.utils.HandlerUtils; +import org.simantics.ui.SimanticsUI; + +/** + * Handle for the Toggle Simulation button. When the button is down, the + * simulation is run every time the model is changed. + * @author Tuomas Miettinen + * + */ +public class ToggleSimulation extends AbstractHandler implements IElementUpdater { + + public static final String COMMAND = "org.simantics.sysdyn.ui.toggleSensitivityAnalysisSimulation"; + public static final String STATE = "org.simantics.sysdyn.ui.toggleSensitivityAnalysisSimulation.state"; + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + // Current functionality is normal run experiment + + ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class); + Command command = service.getCommand(COMMAND); + State state = command.getState(STATE); + Boolean value = (Boolean) state.getValue(); + value = !value; + state.setValue(value); + service.refreshElements(RunSensitivityAnalysisExperiment.COMMAND, null); + + IExperimentManager manager = + SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER); + IExperiment experiment = manager.getActiveExperiment(); + if(experiment instanceof SysdynExperiment) { + if(getState()) { + ((SysdynExperiment)experiment).toggleSimulation(true); + } else { + ((SysdynExperiment)experiment).toggleSimulation(false); + } + } + + HandlerUtils.saveEquation(event); + + return null; + } + + public static Boolean getState() { + ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class); + Command command = service.getCommand(COMMAND); + State state = command.getState(STATE); + return (Boolean)state.getValue(); + } + + @SuppressWarnings("rawtypes") + @Override + public void updateElement(UIElement element, Map parameters) { + ICommandService commandService = + (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class); + Command command = commandService.getCommand(COMMAND); + boolean checked = (Boolean) command.getState(STATE).getValue(); + element.setChecked(checked); + } +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/listeners/SysdynExperimentManagerListener.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/listeners/SysdynExperimentManagerListener.java index 4201112a..d9c50e81 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/listeners/SysdynExperimentManagerListener.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/listeners/SysdynExperimentManagerListener.java @@ -26,13 +26,15 @@ import org.simantics.simulation.project.IExperimentManagerListener; import org.simantics.sysdyn.manager.SysdynExperiment; import org.simantics.sysdyn.manager.SysdynGameExperiment; import org.simantics.sysdyn.manager.SysdynPlaybackExperiment; +import org.simantics.sysdyn.manager.SysdynSensitivityAnalysisExperiment; public class SysdynExperimentManagerListener implements IExperimentManagerListener{ public static final String BASIC_EXPERIMENT_CONTEXT = "org.simantics.sysdyn.ui.basicExperiment"; public static final String PLAYBACK_EXPERIMENT_CONTEXT = "org.simantics.sysdyn.ui.playbackExperiment"; public static final String GAME_EXPERIMENT_CONTEXT = "org.simantics.sysdyn.ui.gameExperiment"; - + public static final String SENSITIVITY_ANALYSIS_EXPERIMENT_CONTEXT = "org.simantics.sysdyn.ui.sensitivityAnalysisExperiment"; + static Set managers = new HashSet(); @@ -72,8 +74,11 @@ public class SysdynExperimentManagerListener implements IExperimentManagerListen contextActivations.add(contextService.activateContext(PLAYBACK_EXPERIMENT_CONTEXT)); experiment.addListener(new SysdynPlaybackExperimentListener((SysdynPlaybackExperiment)experiment)); } else if(experiment instanceof SysdynGameExperiment) { - contextActivations.add(contextService.activateContext(GAME_EXPERIMENT_CONTEXT)); - // TODO: some listener? + contextActivations.add(contextService.activateContext(GAME_EXPERIMENT_CONTEXT)); + // TODO: some listener? + } else if(experiment instanceof SysdynSensitivityAnalysisExperiment) { + contextActivations.add(contextService.activateContext(SENSITIVITY_ANALYSIS_EXPERIMENT_CONTEXT)); + // TODO: some listener? } else if(experiment instanceof SysdynExperiment) { contextActivations.add(contextService.activateContext(BASIC_EXPERIMENT_CONTEXT)); } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java index ab4c39b5..28e01ecc 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java @@ -295,7 +295,7 @@ public class ResourceSelectionProcessor implements SelectionProcessor { + + final private String propertyURI; + + public IntegerPropertyFactory(String propertyURI) { + this.propertyURI = propertyURI; + } + + @Override + public Object getIdentity(Object inputContents) { + return new Triple((Resource)inputContents, propertyURI, getClass()); + } + + @Override + public String perform(ReadGraph graph, Resource issue) throws DatabaseException { + + Integer value = graph.getPossibleRelatedValue(issue, graph.getResource(propertyURI)); + if (value != null) + return value.toString(); + else + return ""; + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/factories/IntegerPropertyModifier.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/factories/IntegerPropertyModifier.java new file mode 100644 index 00000000..fb612405 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/factories/IntegerPropertyModifier.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.factories; + +import org.simantics.browsing.ui.swt.widgets.impl.TextModifyListenerImpl; +import org.simantics.databoard.Bindings; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.management.ISessionContext; + +public class IntegerPropertyModifier extends TextModifyListenerImpl { + + final private String propertyURI; + + public IntegerPropertyModifier(ISessionContext context, String propertyURI) { + this.propertyURI = propertyURI; + } + + @Override + public void applyText(WriteGraph graph, Resource input, String text) throws DatabaseException { + if (text == null || text.equals("")) { + if(graph.hasStatement(input, graph.getResource(propertyURI))) + graph.deny(input, graph.getResource(propertyURI)); + } else { + graph.claimLiteral(input, graph.getResource(propertyURI), Integer.parseInt(text), Bindings.INTEGER); + } + } + +} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynModel.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynModel.java index b5c5e6e0..bfe35fa1 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynModel.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynModel.java @@ -74,12 +74,12 @@ public class SysdynModel implements IMappingListener, IModel, VariableSubscripti private Configuration configuration; - private Set modules = new HashSet(); + private final Set modules = new HashSet(); private ArrayList displayedResults; - private ArrayList listeningHistories = new ArrayList(); + private final ArrayList listeningHistories = new ArrayList(); - private CopyOnWriteArrayList modificationListeners = + private final CopyOnWriteArrayList modificationListeners = new CopyOnWriteArrayList(); @SuppressWarnings("rawtypes") @@ -88,7 +88,7 @@ public class SysdynModel implements IMappingListener, IModel, VariableSubscripti protected volatile VariableValueSubscription[] variableValueSubscriptionsSnapshot = null; @SuppressWarnings("rawtypes") - private Map services = new HashMap(); + private final Map services = new HashMap(); /** * Recursively read all module configurations that are used in @@ -413,6 +413,8 @@ public class SysdynModel implements IMappingListener, IModel, VariableSubscripti exp = new SysdynPlaybackExperiment(experiment, modelResource); } else if(g.isInstanceOf(experiment, sr.GameExperiment)) { exp = new SysdynGameExperiment(experiment, modelResource); + } else if(g.isInstanceOf(experiment, sr.SensitivityAnalysisExperiment)) { + exp = new SysdynSensitivityAnalysisExperiment(experiment, modelResource); } else if(g.isInstanceOf(experiment, sr.BasicExperiment)) { exp = new SysdynExperiment(experiment, modelResource); } else { diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynSensitivityAnalysisExperiment.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynSensitivityAnalysisExperiment.java new file mode 100644 index 00000000..c7da1528 --- /dev/null +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynSensitivityAnalysisExperiment.java @@ -0,0 +1,158 @@ +/******************************************************************************* + * Copyright (c) 2007, 2012 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.manager; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.concurrent.ScheduledExecutorService; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.simulation.experiment.IDynamicExperiment; + +/** + * Sensitivity analysis experiment + * @author Tuomas Miettinen + * + */ +public class SysdynSensitivityAnalysisExperiment extends SysdynExperiment implements IDynamicExperiment { + + public enum Distribution { + UNIFORM, + NORMAL + } + + private final Distribution propabilityDistribution = DEFAULT_PROPABILITY_DISTRIBUTION; + + public static Distribution DEFAULT_PROPABILITY_DISTRIBUTION = Distribution.UNIFORM; + public static double DEFAULT_MIN_VALUE = 1.0; + public static double DEFAULT_MAX_VALUE = 3.0; + public static int DEFAULT_NUM_VALUES = 3; + + private final Collection timeListeners = new ArrayList(); + + ScheduledExecutorService playbackExecutionService; + //SensitivityAnalysisConfiguration playbackConfiguration; + + public SysdynSensitivityAnalysisExperiment(Resource experiment, Resource model) { + super(experiment, model); + } + + + /** + * Interrupts a possible ongoing playback + * + * @param time + */ +// public void setTimeInterrupting(double time) { +// stopPlayback(); +// setTime(time); +// } +// +// /** +// * Sets a new time and continues playback from that point if +// * playback was running +// * @param time +// */ +// public void setTimeAndContinue(double time) { +// if(isPlaybackRunning()) { +// stopPlayback(); +// setTime(time); +// startPlayback(500); +// } else { +// setTime(time); +// } +// } +/* + private void setTime(double time) { + this.time = time; + resultsChanged(); + } + + public double getTime() { + return this.time; + } + + public double getStartTime() { + return this.startTime; + } + + public double getEndTime() { + return this.endTime; + } + + public void setPlaybackDuration(long duration) { + this.playbackDuration = duration; + if(isPlaybackRunning()) { + //Restart playback with different time settings + startPlayback(); + } + } + + public long getPlaybackDuration() { + return this.playbackDuration; + } + + @Override + public void init(ReadGraph g) { + super.init(g); + this.session = g.getSession(); + session.asyncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + changeState(ExperimentState.RUNNING); + final Resource configuration = graph.getPossibleObject(model, SimulationResource.getInstance(graph).HasConfiguration); + sysdynModel = SysdynModelManager.getInstance(session).getModel(graph, configuration); + toggleActivation(graph, true); + //getPlaybackConfiguration(graph); + startSimulationJob(); + } + }); + } + + + + private class SensitivityAnalysisConfiguration { + public double simulationDuration, simulationStepLength, intervals, endTime, startTime; + public long playbackDuration; + } + + @Override + protected void localStateChange() { + super.localStateChange(); + } + + // TIME LISTENERS + public void addTimeListener(Runnable timeListener) { + if(!this.timeListeners.contains(timeListener)) + this.timeListeners.add(timeListener); + } + + public Collection getTimeListeners() { + return this.timeListeners; + } + + public void removeTimeListener(Runnable timeListener) { + this.timeListeners.remove(timeListener); + } + + @Override + public void resultsChanged() { + for(Runnable listener : timeListeners) { + listener.run(); + } + super.resultsChanged(); + + } +*/ +}