- Prototype of ExecutionEngine supporting stochastic events
- Fix ExternalControl accordingly
- Adapt releng to build on JavaSE-17
Change-Id: I481ff1e689a1b6da7aff03892ec329d695306198
diff --git a/externalcontrol/bundles/org.eclipse.papyrus.moka.externalcontrol/META-INF/MANIFEST.MF b/externalcontrol/bundles/org.eclipse.papyrus.moka.externalcontrol/META-INF/MANIFEST.MF
index c0e774b..feaf5c0 100644
--- a/externalcontrol/bundles/org.eclipse.papyrus.moka.externalcontrol/META-INF/MANIFEST.MF
+++ b/externalcontrol/bundles/org.eclipse.papyrus.moka.externalcontrol/META-INF/MANIFEST.MF
@@ -15,12 +15,14 @@
org.eclipse.papyrus.moka.engine.uml.time.scheduling;bundle-version="[4.1.0,5.0.0)",
org.eclipse.papyrus.moka.engine.uml.time;bundle-version="4.1.0",
org.eclipse.papyrus.moka.pscs,
- org.eclipse.papyrus.moka.engine.uml;bundle-version="4.1.0"
+ org.eclipse.papyrus.moka.engine.uml;bundle-version="4.1.0",
+ org.eclipse.papyrus.moka.engine.uml.debug;bundle-version="4.1.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Bundle-Vendor: Eclipse Modeling Project
Export-Package: org.eclipse.papyrus.moka.externalcontrol,
org.eclipse.papyrus.moka.externalcontrol.advice,
+ org.eclipse.papyrus.moka.externalcontrol.control.queue,
org.eclipse.papyrus.moka.externalcontrol.controller,
org.eclipse.papyrus.moka.externalcontrol.engine,
org.eclipse.papyrus.moka.externalcontrol.semantics
diff --git a/externalcontrol/bundles/org.eclipse.papyrus.moka.externalcontrol/src/org/eclipse/papyrus/moka/externalcontrol/controller/AbstractExternallyControlledVisitor.java b/externalcontrol/bundles/org.eclipse.papyrus.moka.externalcontrol/src/org/eclipse/papyrus/moka/externalcontrol/controller/AbstractExternallyControlledVisitor.java
index 8076bf5..a1e2359 100644
--- a/externalcontrol/bundles/org.eclipse.papyrus.moka.externalcontrol/src/org/eclipse/papyrus/moka/externalcontrol/controller/AbstractExternallyControlledVisitor.java
+++ b/externalcontrol/bundles/org.eclipse.papyrus.moka.externalcontrol/src/org/eclipse/papyrus/moka/externalcontrol/controller/AbstractExternallyControlledVisitor.java
@@ -115,7 +115,6 @@
}
}
-
protected Double getDuration() {
Double totalDuration= null;
for (IControllerAdvice advice : advices ){
diff --git a/externalcontrol/bundles/org.eclipse.papyrus.moka.externalcontrol/src/org/eclipse/papyrus/moka/externalcontrol/semantics/ExternalControlExecutionFactory.java b/externalcontrol/bundles/org.eclipse.papyrus.moka.externalcontrol/src/org/eclipse/papyrus/moka/externalcontrol/semantics/ExternalControlExecutionFactory.java
index 822e1c0..f2a9e29 100644
--- a/externalcontrol/bundles/org.eclipse.papyrus.moka.externalcontrol/src/org/eclipse/papyrus/moka/externalcontrol/semantics/ExternalControlExecutionFactory.java
+++ b/externalcontrol/bundles/org.eclipse.papyrus.moka.externalcontrol/src/org/eclipse/papyrus/moka/externalcontrol/semantics/ExternalControlExecutionFactory.java
@@ -28,6 +28,7 @@
import org.eclipse.papyrus.moka.fuml.activities.ActivityExecution;
import org.eclipse.papyrus.moka.fuml.activities.IActivityEdgeInstance;
import org.eclipse.papyrus.moka.fuml.commonbehavior.IExecution;
+import org.eclipse.papyrus.moka.fuml.commonbehavior.IOpaqueBehaviorExecution;
import org.eclipse.papyrus.moka.fuml.loci.ExecutionFactory;
import org.eclipse.papyrus.moka.fuml.loci.IExecutionFactory;
import org.eclipse.papyrus.moka.fuml.loci.ILocus;
@@ -76,6 +77,14 @@
}
}
+
+
+
+ @Override
+ public void addPrimitiveBehaviorPrototype(IOpaqueBehaviorExecution execution) {
+ this.delegatedExecutionFactory.addPrimitiveBehaviorPrototype(execution);
+ }
+
@Override
public ISemanticVisitor instantiateVisitor(Element element) {
diff --git a/externalcontrol/features/org.eclipse.papyrus.moka.externalcontrol.feature/feature.xml b/externalcontrol/features/org.eclipse.papyrus.moka.externalcontrol.feature/feature.xml
index b132f2a..1825643 100644
--- a/externalcontrol/features/org.eclipse.papyrus.moka.externalcontrol.feature/feature.xml
+++ b/externalcontrol/features/org.eclipse.papyrus.moka.externalcontrol.feature/feature.xml
@@ -8,7 +8,7 @@
license-feature-version="2.0.2">
<description url="https://wiki.eclipse.org/Papyrus/UserGuide/ModelExecution">
- %description
+ %description
</description>
<copyright>
@@ -20,7 +20,6 @@
</license>
<requires>
- <import plugin="org.eclipse.core.runtime" version="3.20.0" match="compatible"/>
<import plugin="org.eclipse.debug.core" version="3.17.0" match="compatible"/>
<import plugin="org.eclipse.core.runtime" version="3.20.0" match="compatible"/>
<import plugin="org.aspectj.runtime" version="1.9.0" match="compatible"/>
@@ -37,9 +36,6 @@
<plugin
id="org.eclipse.papyrus.moka.externalcontrol"
- download-size="0"
- install-size="0"
- version="0.0.0"
- unpack="false"/>
+ version="0.0.0"/>
</feature>
diff --git a/externalcontrol/pom.xml b/externalcontrol/pom.xml
index d433f11..c44c81f 100644
--- a/externalcontrol/pom.xml
+++ b/externalcontrol/pom.xml
@@ -11,7 +11,6 @@
<groupId>org.eclipse.papyrus.moka.externalcontrol</groupId>
<artifactId>org.eclipse.papyrus.moka.externalcontrol.root</artifactId>
- <version>0.7.0-SNAPSHOT</version>
<packaging>pom</packaging>
<profiles>
diff --git a/pom.xml b/pom.xml
index f56c946..ce46e7f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -26,14 +26,14 @@
</modules>
<properties>
- <tycho.version>2.1.0</tycho.version>
- <tycho.extras.version>1.7.0</tycho.extras.version>
+ <tycho.version>3.0.4</tycho.version>
+ <tycho.extras.version>3.0.4</tycho.extras.version>
<xtend.version>2.21.0</xtend.version>
<maven.resources.version>3.1.0</maven.resources.version>
<maven.clean.version>3.1.0</maven.clean.version>
<maven.compiler.version>3.8.0</maven.compiler.version>
- <java.source.version>1.8</java.source.version>
- <java.target.version>1.8</java.target.version>
+ <java.source.version>17</java.source.version>
+ <java.target.version>17</java.target.version>
<jboss.version>1.3.0</jboss.version>
</properties>
diff --git a/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/.classpath b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/.classpath
new file mode 100644
index 0000000..db26433
--- /dev/null
+++ b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/.classpath
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
+ <attributes>
+ <attribute name="module" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" output="bin-test" path="src-test">
+ <attributes>
+ <attribute name="test" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/.gitignore b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/.gitignore
new file mode 100644
index 0000000..8fa0bc7
--- /dev/null
+++ b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/.gitignore
@@ -0,0 +1 @@
+/bin-test/
diff --git a/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/.project b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/.project
new file mode 100644
index 0000000..93f7ba2
--- /dev/null
+++ b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.papyrus.moka.engine.uml.stochastic</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/META-INF/MANIFEST.MF b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..2a08298
--- /dev/null
+++ b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/META-INF/MANIFEST.MF
@@ -0,0 +1,17 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: StochasticMokaEngine
+Bundle-SymbolicName: org.eclipse.papyrus.moka.engine.uml.stochastic;singleton:=true
+Bundle-Version: 1.0.0.qualifier
+Bundle-Activator: org.eclipse.papyrus.moka.engine.uml.stochastic.Activator
+Require-Bundle: org.eclipse.papyrus.moka.engine.uml.time.scheduling;bundle-version="[4.0.0,5.0.0)";visibility:=reexport,
+ org.eclipse.papyrus.moka.engine.uml.time.interfaces;bundle-version="[4.0.0,5.0.0)";visibility:=reexport,
+ org.aspectj.runtime;bundle-version="[1.9.6,2.0.0)",
+ org.eclipse.core.runtime;bundle-version="[3.18.0,4.0.0)",
+ org.eclipse.papyrus.moka.engine.uml.debug;bundle-version="[4.0.0,5.0.0)",
+ org.eclipse.papyrus.moka.kernel.animation;bundle-version="[4.0.0,5.0.0)",
+ org.eclipse.papyrus.moka.engine.uml.time;bundle-version="[4.0.0,5.0.0)",
+ org.junit;bundle-version="[4.0.0,5.0.0)"
+Bundle-RequiredExecutionEnvironment: JavaSE-11
+Automatic-Module-Name: org.eclipse.papyrus.moka.engine.uml.stochastic
+Bundle-ActivationPolicy: lazy
diff --git a/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/build.properties b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/build.properties
new file mode 100644
index 0000000..e9863e2
--- /dev/null
+++ b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/build.properties
@@ -0,0 +1,5 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml
diff --git a/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/plugin.xml b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/plugin.xml
new file mode 100644
index 0000000..6968b7f
--- /dev/null
+++ b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/plugin.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ point="org.eclipse.papyrus.moka.kernel.engine">
+ <engine
+ class="org.eclipse.papyrus.moka.engine.uml.stochastic.engine.UMLStochasticExecutionEngine"
+ description="Stochastic Executable UML Execution Engine"
+ id="org.eclipse.papyrus.moka.engine.uml.stochastic">
+ </engine>
+ </extension>
+</plugin>
diff --git a/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src-test/org/eclipse/papyrus/moka/engine/uml/stochastic/DistributionTests.java b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src-test/org/eclipse/papyrus/moka/engine/uml/stochastic/DistributionTests.java
new file mode 100644
index 0000000..5e91278
--- /dev/null
+++ b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src-test/org/eclipse/papyrus/moka/engine/uml/stochastic/DistributionTests.java
@@ -0,0 +1,45 @@
+/*****************************************************************************
+ * Copyright (c) 2023 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * CEA LIST Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.moka.engine.uml.stochastic;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class DistributionTests {
+
+ @Test
+ public void testPseudoRNG() {
+ // Arrange
+ PseudoRandomGenerator generator = new PseudoRandomGenerator();
+
+ // Act
+ generator.updateSeed();
+ long current_seed = generator.getSeed();
+ PseudoRandomGenerator new_generator = new PseudoRandomGenerator(current_seed, generator.getMultiplier(), generator.getAdditive(), generator.getModulus());
+ double u = generator.nextDouble();
+ double v = new_generator.nextDouble();
+ System.out.println(System.currentTimeMillis());
+
+ // Assert
+ Assert.assertEquals(u, v, 0.0);
+ }
+
+ @Test
+ public void testDistribution() {
+
+ }
+
+
+
+}
diff --git a/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/Activator.java b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/Activator.java
new file mode 100644
index 0000000..51582d3
--- /dev/null
+++ b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/Activator.java
@@ -0,0 +1,52 @@
+/*****************************************************************************
+ * Copyright (c) 2023 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * CEA LIST Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.moka.engine.uml.stochastic;
+
+import org.eclipse.core.runtime.ILog;
+import org.eclipse.core.runtime.Platform;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator implements BundleActivator {
+
+ /**
+ * Plugin instance
+ */
+ private static Activator plugin;
+
+ /**
+ * Logger used within that plugin
+ */
+ public ILog logger;
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ plugin = this;
+ logger = Platform.getLog(this.getClass());
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ logger = null;
+ plugin = null;
+ }
+
+ public static Activator getInstance() {
+ return plugin;
+ }
+
+}
diff --git a/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/BernoulliDistribution.java b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/BernoulliDistribution.java
new file mode 100644
index 0000000..29dfe47
--- /dev/null
+++ b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/BernoulliDistribution.java
@@ -0,0 +1,42 @@
+/*****************************************************************************
+ * Copyright (c) 2023 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * CEA LIST Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.moka.engine.uml.stochastic;
+
+public class BernoulliDistribution implements IDrawSample {
+
+ protected double p;
+ private PseudoRandomGenerator generator;
+
+ public BernoulliDistribution(double p) {
+ if (p == Double.NaN) {
+ throw new IllegalArgumentException("Invalid argument: BernouilliDistribution cannot take NaN argument.");
+ }
+ if (0 > p || p < 1) {
+ throw new IllegalArgumentException("Invalid argument: p must belong to [0, 1].");
+ } else {
+ this.p = p;
+ this.generator = new PseudoRandomGenerator();
+ }
+ }
+
+ public Double nextSample() {
+ Double sample;
+ if (this.generator.nextDouble() < p) {
+ sample = 1.0;
+ } else {
+ sample = 0.0;
+ }
+ return sample;
+ }
+}
diff --git a/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/DiscreteUniformDistribution.java b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/DiscreteUniformDistribution.java
new file mode 100644
index 0000000..919a901
--- /dev/null
+++ b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/DiscreteUniformDistribution.java
@@ -0,0 +1,40 @@
+/*****************************************************************************
+ * Copyright (c) 2023 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * CEA LIST Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.moka.engine.uml.stochastic;
+
+public class DiscreteUniformDistribution implements IDrawSample {
+
+ private int a;
+ private int b;
+ private PseudoRandomGenerator generator;
+
+ public DiscreteUniformDistribution(int a, int b) {
+ if (a > b) {
+ throw new IllegalArgumentException("Invalid argument: lower bound cannot be greater than upper bound.");
+ }
+ this.a = a;
+ this.b = b;
+ this.generator = new PseudoRandomGenerator();
+ }
+
+ public Double nextSample() {
+ double sample = Double.valueOf(this.a);
+ if (this.a != this.b) {
+ // A verifier !!
+ double u = this.generator.nextDouble();
+ sample = Math.ceil((this.b - this.a + 1) * u);
+ }
+ return sample;
+ }
+}
diff --git a/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/DistributionsInterpreter.java b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/DistributionsInterpreter.java
new file mode 100644
index 0000000..a223a54
--- /dev/null
+++ b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/DistributionsInterpreter.java
@@ -0,0 +1,198 @@
+/*****************************************************************************
+ * Copyright (c) 2023 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * CEA LIST Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.moka.engine.uml.stochastic;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class DistributionsInterpreter {
+
+ private static final String UNIFORM = "uniform";
+ private static final String EXPONENTIAL = "exponential";
+ private static final String TRUNCATED_EXPONENTIAL = "troncated_exponential";
+ private static final String POISSON = "poisson";
+ private static final String GEOMETRIC = "geomtric";
+ private static final String NORMAL = "normal";
+ private static final String TRUNCATED_NORMAL = "troncated_normal";
+ private static final String CUSTOM = "custom";
+
+ private static final List<String> distribution_names_librairy = Arrays.asList(UNIFORM, EXPONENTIAL,
+ TRUNCATED_EXPONENTIAL, POISSON, GEOMETRIC, NORMAL, TRUNCATED_NORMAL, CUSTOM);
+
+
+ public static double matchDistribution(String expression) {
+
+ String pattern = "(.*)\\((.*)\\)";
+ Pattern r = Pattern.compile(pattern);
+
+ Matcher m = r.matcher(expression);
+
+ if (!m.find()) {
+ throw new IllegalArgumentException(
+ "Invalid argument: expression must be of the form 'distribution_name(parameters)'.");
+ } else {
+ String distribution_name = m.group(1);
+ if (distribution_names_librairy.contains(distribution_name)) {
+ String parameters = m.group(2).replaceAll("\\s", "");
+ String[] params = parameters.split(",");
+ List<Double> parameters_list = new ArrayList<Double>();
+
+ double sample = 0;
+
+ IDrawSample distribution = null;
+
+ switch (distribution_name) {
+ case UNIFORM:
+ if (params.length != 2) {
+ throw new IllegalArgumentException(
+ "Invalid argument: uniform distribution parameters must be two floats.");
+ }
+ for (String param : params) {
+ try {
+ parameters_list.add(Double.valueOf(param));
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException(
+ "Invalid argument: uniform distribution parameters must be two floats.");
+ }
+ }
+ double a = parameters_list.get(0);
+ double b = parameters_list.get(1);
+ distribution = new UniformDistribution(a, b);
+
+ break;
+
+ case EXPONENTIAL:
+ if (params.length != 1) {
+ throw new IllegalArgumentException(
+ "Invalid argument: exponential distribution parameter must be a strictly positive float.");
+ }
+ for (String param : params) {
+ try {
+ parameters_list.add(Double.valueOf(param));
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException(
+ "Invalid argument: exponential distribution parameter must be a strictly positive float.");
+ }
+ }
+ double l = parameters_list.get(0);
+ distribution = new ExponentialDistribution(l);
+
+ break;
+
+ case TRUNCATED_EXPONENTIAL:
+ if (params.length != 2) {
+ throw new IllegalArgumentException(
+ "Invalid argument: truncated exponential distribution parameter must be two strictly positive floats.");
+ }
+ for (String param : params) {
+ try {
+ parameters_list.add(Double.valueOf(param));
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException(
+ "Invalid argument: truncated exponential distribution parameter must be two strictly positive floats.");
+ }
+ }
+ l = parameters_list.get(0);
+ double bound = parameters_list.get(1);
+ distribution = new TruncatedExponentialDistribution(l, bound);
+ break;
+
+ case POISSON:
+ if (params.length != 1) {
+ throw new IllegalArgumentException(
+ "Invalid argument: poisson distribution parameter must be a strictly positive float.");
+ }
+ for (String param : params) {
+ try {
+ parameters_list.add(Double.valueOf(param));
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException(
+ "Invalid argument: exponential distribution parameter must be a strictly positive float.");
+ }
+ }
+ l = parameters_list.get(0);
+ distribution = new PoissonDistribution(l);
+ break;
+
+ case GEOMETRIC:
+ if (params.length != 1) {
+ throw new IllegalArgumentException(
+ "Invalid argument: geometric distribution parameter must be a float.");
+ }
+ for (String param : params) {
+ try {
+ parameters_list.add(Double.valueOf(param));
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException(
+ "Invalid argument: geometric distribution parameter must be a float.");
+ }
+ }
+ double p = parameters_list.get(0);
+ distribution = new GeometricDistribution(p);
+ break;
+
+ case NORMAL:
+ if(params.length != 2) {
+ throw new IllegalArgumentException(
+ "Invalid argument: normal distribution parameters must be two floats.");
+ }
+ for (String param : params) {
+ try {
+ parameters_list.add(Double.valueOf(param));
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException(
+ "Invalid argument: normal distribution parameters must be two floats.");
+ }
+ }
+ double mean = parameters_list.get(0);
+ double sd = parameters_list.get(1);
+ distribution = new NormalDistribution(mean, sd);
+
+ break;
+
+ case TRUNCATED_NORMAL:
+ if(params.length != 2) {
+ throw new IllegalArgumentException(
+ "Invalid argument: truncated normal distribution parameters must be four floats.");
+ }
+ for (String param : params) {
+ try {
+ parameters_list.add(Double.valueOf(param));
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException(
+ "Invalid argument: truncated normal distribution parameters must be four floats.");
+ }
+ }
+ mean = parameters_list.get(0);
+ sd = parameters_list.get(1);
+ double lb = parameters_list.get(2);
+ double ub = parameters_list.get(3);
+ distribution = new TruncatedNormalDistribution(mean, sd, lb, ub);
+ }
+
+
+ sample = distribution.nextSample();
+ return sample;
+
+ } else {
+ throw new IllegalArgumentException(
+ "Invalid argument: name must belong to 'uniform', 'normal', 'poisson', 'custom'}.");
+ }
+ }
+ }
+
+}
diff --git a/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/ExponentialDistribution.java b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/ExponentialDistribution.java
new file mode 100644
index 0000000..81a6521
--- /dev/null
+++ b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/ExponentialDistribution.java
@@ -0,0 +1,38 @@
+/*****************************************************************************
+ * Copyright (c) 2023 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * CEA LIST Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.moka.engine.uml.stochastic;
+
+public class ExponentialDistribution implements IDrawSample {
+
+ protected double l;
+ protected PseudoRandomGenerator generator;
+
+ public ExponentialDistribution(double l) {
+ if (l == Double.NaN) {
+ throw new IllegalArgumentException("Invalid argument: ExponentialDistribution cannot take NaN argument.");
+ }
+ if (l <= 0) {
+ throw new IllegalArgumentException("illegal argument: lambda must belong to (0, inf).");
+ }
+ this.l = l;
+ this.generator = new PseudoRandomGenerator();
+ }
+
+ public Double nextSample() {
+ double u = this.generator.nextDouble();
+ double sample = - Math.log1p(-u) / this.l;
+ return sample;
+ }
+
+}
diff --git a/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/GeometricDistribution.java b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/GeometricDistribution.java
new file mode 100644
index 0000000..9bd7b27
--- /dev/null
+++ b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/GeometricDistribution.java
@@ -0,0 +1,30 @@
+/*****************************************************************************
+ * Copyright (c) 2023 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * CEA LIST Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.moka.engine.uml.stochastic;
+
+public class GeometricDistribution extends BernoulliDistribution implements IDrawSample {
+
+ public GeometricDistribution(double p) {
+ super(p);
+ }
+
+ public Double nextSample() {
+ double sample = 0.0;
+ BernoulliDistribution b = new BernoulliDistribution(this.p);
+ while (b.nextSample() == 0) {
+ sample += 1;
+ }
+ return sample;
+ }
+}
diff --git a/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/IDrawSample.java b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/IDrawSample.java
new file mode 100644
index 0000000..e4ccd80
--- /dev/null
+++ b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/IDrawSample.java
@@ -0,0 +1,20 @@
+/*****************************************************************************
+ * Copyright (c) 2023 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * CEA LIST Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.moka.engine.uml.stochastic;
+
+public interface IDrawSample {
+
+ Double nextSample();
+
+}
diff --git a/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/ListOfChar2String.java b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/ListOfChar2String.java
new file mode 100644
index 0000000..be3bf98
--- /dev/null
+++ b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/ListOfChar2String.java
@@ -0,0 +1,30 @@
+/*****************************************************************************
+ * Copyright (c) 2023 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * CEA LIST Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.moka.engine.uml.stochastic;
+
+import java.util.List;
+
+public class ListOfChar2String {
+
+ public static String ListOfCharToString(List<Character> args) {
+ StringBuilder builder = new StringBuilder();
+
+ for (Character ch : args) {
+ builder.append(ch);
+ }
+
+ String str = builder.toString();
+ return str;
+ }
+}
diff --git a/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/NormalDistribution.java b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/NormalDistribution.java
new file mode 100644
index 0000000..8c7ef67
--- /dev/null
+++ b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/NormalDistribution.java
@@ -0,0 +1,49 @@
+/*****************************************************************************
+ * Copyright (c) 2023 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * CEA LIST Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.moka.engine.uml.stochastic;
+
+import java.util.Random;
+
+public class NormalDistribution implements IDrawSample {
+
+ private double mean;
+ private double sd;
+ private PseudoRandomGenerator generator;
+
+ public NormalDistribution(double mean, double sd) {
+ if (mean == Double.NaN || sd == Double.NaN) {
+ throw new IllegalArgumentException(
+ "Invalid argument: NormalDistribution cannot take NaN argument");
+ }
+ if (sd < 0) {
+ throw new IllegalArgumentException(
+ "Invalid argument: standard deviation must be positive.");
+ }
+ this.mean = mean;
+ this.sd = sd;
+ this.generator = new PseudoRandomGenerator();
+ }
+
+ public Double nextSample() {
+ double sample;
+ if (this.sd == 0) {
+ sample = this.mean;
+ } else {
+ Random random = new Random(this.generator.getSeed());
+ sample = random.nextGaussian();
+ }
+ return sample;
+ }
+
+}
diff --git a/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/PoissonDistribution.java b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/PoissonDistribution.java
new file mode 100644
index 0000000..4a5178c
--- /dev/null
+++ b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/PoissonDistribution.java
@@ -0,0 +1,45 @@
+/*****************************************************************************
+ * Copyright (c) 2023 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * CEA LIST Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.moka.engine.uml.stochastic;
+
+public class PoissonDistribution implements IDrawSample {
+
+ private double l;
+ private PseudoRandomGenerator generator;
+
+ public PoissonDistribution(double l) {
+ if (l == Double.NaN) {
+ throw new IllegalArgumentException("Invalid argument: PoissonDistribution cannot take NaN argument.");
+ }
+ if (l <= 0) {
+ throw new IllegalArgumentException("Invalid argument: lambda must belong to (0, inf).");
+ } else {
+ this.l = l;
+ this.generator = new PseudoRandomGenerator();
+ }
+ }
+
+ public Double nextSample() {
+ double u = this.generator.nextDouble();
+ double sample = 0.0;
+ double y = Math.exp(-this.l);
+ double x = y;
+ while (x < u) {
+ sample += 1;
+ y = y * this.l /sample;
+ x += y;
+ }
+ return sample;
+ }
+}
diff --git a/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/PseudoRandomGenerator.java b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/PseudoRandomGenerator.java
new file mode 100644
index 0000000..d25cccf
--- /dev/null
+++ b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/PseudoRandomGenerator.java
@@ -0,0 +1,97 @@
+/*****************************************************************************
+ * Copyright (c) 2023 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * CEA LIST Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.moka.engine.uml.stochastic;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Random;
+
+public class PseudoRandomGenerator {
+
+ private long seed;
+ private long a;
+ private long b;
+ private long m;
+
+ public PseudoRandomGenerator(long seed, long a, long b, long m) {
+ if (!(m > 0)) {
+ throw new IllegalArgumentException("Invalid argument: modulus must be greater than 0.");
+ } else if (!(0 < a && a < m)) {
+ throw new IllegalArgumentException("Invalid argument: multiplier must belong to (0, m).");
+ } else if (!(0 <= b && b < m)) {
+ throw new IllegalArgumentException("Invalid argument: increment must belong to [0, m).");
+ } else if (!(0 <= seed && seed < m)) {
+ throw new IllegalArgumentException("Invalid argument: initial seed must belong to [0, m).");
+ }
+
+ this.seed = seed;
+ this.a = a;
+ this.b = b;
+ this.m = m;
+ }
+
+ public PseudoRandomGenerator() {
+ /*
+ * Attributes are generated 'randomly' by shuffling the currentTime.
+ */
+ long date = System.currentTimeMillis();
+ String date_str = Long.toString(date);
+ date_str = date_str.replaceAll("0", "1");
+ List<Character> date_integers = new ArrayList<>();
+ for (char ch : date_str.toCharArray()) {
+ date_integers.add(ch);
+ }
+
+ Collections.shuffle(date_integers);
+
+ String seed_str = ListOfChar2String.ListOfCharToString(date_integers.subList(0, 4));
+ String a_str = ListOfChar2String.ListOfCharToString(date_integers.subList(4, 6));
+ String b_str = ListOfChar2String.ListOfCharToString(date_integers.subList(6, 8));
+ String m_str = ListOfChar2String.ListOfCharToString(date_integers.subList(8, 13));
+
+ this.seed = Long.valueOf(seed_str);
+ this.a = Long.valueOf(a_str);
+ this.b = Long.valueOf(b_str);
+ this.m = Long.valueOf(m_str);
+ }
+
+ public void updateSeed() {
+ long new_seed = (a * this.seed + b) % m;
+ this.seed = new_seed;
+ }
+
+ public Double nextDouble() {
+ Random random = new Random(this.seed);
+ updateSeed();
+ return random.nextDouble();
+ }
+
+ public long getSeed() {
+ return this.seed;
+ }
+
+ public long getMultiplier() {
+ return this.a;
+ }
+
+ public long getAdditive() {
+ return this.b;
+ }
+
+ public long getModulus() {
+ return this.m;
+ }
+
+}
diff --git a/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/TriangularDistribution.java b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/TriangularDistribution.java
new file mode 100644
index 0000000..b3a9644
--- /dev/null
+++ b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/TriangularDistribution.java
@@ -0,0 +1,64 @@
+/*****************************************************************************
+ * Copyright (c) 2023 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * CEA LIST Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.moka.engine.uml.stochastic;
+
+public class TriangularDistribution implements IDrawSample {
+
+ private double a;
+ private double b;
+ private double c;
+ private PseudoRandomGenerator generator;
+
+ public TriangularDistribution(double a, double b, double c) {
+ if (a == Double.NaN || b == Double.NaN || c == Double.NaN) {
+ throw new IllegalArgumentException(
+ "Invalid argument: TriangularDistribution cannot accept NaN parameters");
+ }
+ if (!(a <= c && c <= b)) {
+ throw new IllegalArgumentException(
+ "Invalid argument: parameters must be ordered as follows a < c < b.");
+ }
+ this.a = a;
+ this.b = b;
+ this.c = c;
+ this.generator = new PseudoRandomGenerator();
+ }
+
+ public TriangularDistribution(double a, double b) {
+ if (a == Double.NaN || b == Double.NaN) {
+ throw new IllegalArgumentException(
+ "Invalid argument: TriangularDistribution cannot accept NaN parameters");
+ }
+ if (a >= b) {
+ throw new IllegalArgumentException(
+ "Invalid argument: b must be greater than a.");
+ }
+ this.a = a;
+ this.b = b;
+ this.c = (b - a) / 2.0;
+ this.generator = new PseudoRandomGenerator();
+ }
+
+ public Double nextSample() {
+ double u = this.generator.nextDouble();
+ double sample;
+ if (u <= (this.c - this.a) / (this.b - this.a)) {
+ sample = Math.sqrt((this.b - this.a) * (this.c - this.a) * u) + this.a;
+ } else {
+ sample = Math.sqrt((this.b - this.a) * (this.c - this.a) * (1 - u)) + this.b;
+ }
+ return sample;
+ }
+
+}
diff --git a/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/TruncatedExponentialDistribution.java b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/TruncatedExponentialDistribution.java
new file mode 100644
index 0000000..07cf5a6
--- /dev/null
+++ b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/TruncatedExponentialDistribution.java
@@ -0,0 +1,37 @@
+/*****************************************************************************
+ * Copyright (c) 2023 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * CEA LIST Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.moka.engine.uml.stochastic;
+
+public class TruncatedExponentialDistribution extends ExponentialDistribution implements IDrawSample {
+
+ private double bound;
+
+ public TruncatedExponentialDistribution(double l, double bound) {
+ super(l);
+ if (bound == Double.NaN) {
+ throw new IllegalArgumentException("Invalid argument: TruncatedExponentialDistribution cannot take NaN arguments.");
+ }
+ if (bound < 0) {
+ throw new IllegalArgumentException("Invalid argument: the troncated bound must be positive.");
+ }
+ this.bound = bound;
+ }
+
+ public Double nextSample() {
+ double u = this.generator.nextDouble();
+ double sample = - Math.log1p(-u) / this.l + this.bound;
+ return sample;
+ }
+
+}
diff --git a/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/TruncatedNormalDistribution.java b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/TruncatedNormalDistribution.java
new file mode 100644
index 0000000..6525409
--- /dev/null
+++ b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/TruncatedNormalDistribution.java
@@ -0,0 +1,107 @@
+/*****************************************************************************
+ * Copyright (c) 2023 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * CEA LIST Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.moka.engine.uml.stochastic;
+
+public class TruncatedNormalDistribution extends NormalDistribution implements IDrawSample {
+
+ private double mean;
+ private double sd;
+ private double lb;
+ private double ub;
+ private PseudoRandomGenerator generator;
+
+ public TruncatedNormalDistribution(double mean, double sd, double lb, double ub) {
+ super(mean, sd);
+ if (lb == Double.NaN || ub == Double.NaN) {
+ throw new IllegalArgumentException("Invalid argument : TruncatedNormalDistribution cannot take NaN argument.");
+ } else if (ub > ub) {
+ throw new IllegalArgumentException("Invalid argument : lower bound cannot be greater than upper bound.");
+ }
+ this.lb = lb;
+ this.ub = ub;
+ }
+
+ public Double nextSample() {
+
+ double sample = Double.NaN;
+
+ if (this.sd == 0.0) {
+ if (this.lb <= this.mean && this.mean <= this.ub) {
+ sample = this.mean;
+ }
+ } else {
+ double rho = 0.0;
+ double u = this.generator.nextDouble();
+
+ if (this.ub == Double.MAX_VALUE) {
+
+ // Location-scale rescaling of the boundaries to standard normal distribution
+ double standardised_lb = (this.lb - this.mean) / this.sd;
+
+ double alpha = (standardised_lb + Math.sqrt(Math.pow(standardised_lb, 2) + 4.0)) / 2.0;
+ TruncatedExponentialDistribution distribution = new TruncatedExponentialDistribution(alpha,
+ standardised_lb);
+
+ while (u > rho) {
+ double z = distribution.nextSample();
+ rho = Math.exp(-Math.pow((z - alpha), 2) / 2.0);
+ u = this.generator.nextDouble();
+ sample = z;
+ }
+
+ return sample;
+
+ } else if (this.lb == Double.MIN_VALUE) {
+
+ // Location-scale rescaling of the boundaries to standard normal distribution
+ double standardised_ub = (this.ub - this.mean) / this.sd;
+
+ double alpha = (-standardised_ub + Math.sqrt(Math.pow(standardised_ub, 2) + 4.0)) / 2.0;
+ TruncatedExponentialDistribution distribution = new TruncatedExponentialDistribution(alpha,
+ -standardised_ub);
+
+ while (u > rho) {
+ double z = distribution.nextSample();
+ rho = Math.exp(-Math.pow((z - alpha), 2) / 2.0);
+ u = this.generator.nextDouble();
+ sample = z;
+ }
+
+ } else {
+
+ // Location-scale rescaling of the boundaries to standard normal distribution
+ double standardised_lb = (this.lb - this.mean) / this.sd;
+ double standardised_ub = (this.ub - this.mean) / this.sd;
+
+ UniformDistribution distribution = new UniformDistribution(standardised_lb, standardised_ub);
+
+ while (u > rho) {
+ double z = distribution.nextSample();
+ if (standardised_lb <= 0 && 0 <= standardised_ub) {
+ rho = Math.exp(-Math.pow(z, 2) / 2);
+ } else if (standardised_ub < 0) {
+ rho = Math.exp((Math.pow(this.ub, 2) - Math.pow(z, 2)) / 2.0);
+ } else {
+ rho = Math.exp((Math.pow(this.lb, 2) - Math.pow(z, 2)) / 2.0);
+ }
+ u = distribution.nextSample();
+ sample = z;
+ }
+ }
+ // We return the 'unrescaled' sample
+ sample = this.mean + this.sd * sample;
+ }
+ return sample;
+ }
+}
diff --git a/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/UniformDistribution.java b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/UniformDistribution.java
new file mode 100644
index 0000000..93aa1ed
--- /dev/null
+++ b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/UniformDistribution.java
@@ -0,0 +1,41 @@
+/*****************************************************************************
+ * Copyright (c) 2023 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * CEA LIST Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.moka.engine.uml.stochastic;
+
+public class UniformDistribution implements IDrawSample {
+
+ private double lb;
+ private double ub;
+ private PseudoRandomGenerator generator;
+
+
+ public UniformDistribution(final double lb, final double ub) {
+ if (lb == Double.NaN || ub == Double.NaN) {
+ throw new IllegalArgumentException("Invalid argument: UniformDistribution cannot take NaN arguments.");
+ }
+ if (lb >= ub) {
+ throw new IllegalArgumentException("Invalid argument: lower bound greater than upper bound");
+ }
+ this.lb = lb;
+ this.ub = ub;
+ this.generator = new PseudoRandomGenerator();
+ }
+
+ public Double nextSample() {
+
+ double sample = (this.ub - this.lb) * this.generator.nextDouble() + this.lb;
+
+ return sample;
+ }
+}
diff --git a/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/engine/UMLStochasticExecutionEngine.java b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/engine/UMLStochasticExecutionEngine.java
new file mode 100644
index 0000000..422fb95
--- /dev/null
+++ b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/engine/UMLStochasticExecutionEngine.java
@@ -0,0 +1,35 @@
+/*****************************************************************************
+ * Copyright (c) 2023 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * CEA LIST Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.moka.engine.uml.stochastic.engine;
+
+import org.eclipse.papyrus.moka.engine.uml.stochastic.semantics.StochasticExecutionFactory;
+import org.eclipse.papyrus.moka.engine.uml.time.UMLTimedExecutionEngine;
+import org.eclipse.papyrus.moka.engine.uml.time.semantics.Loci.TimedLocus;
+import org.eclipse.papyrus.moka.fuml.loci.ILocus;
+import org.eclipse.papyrus.moka.pscs.loci.CS_Executor;
+
+public class UMLStochasticExecutionEngine extends UMLTimedExecutionEngine {
+
+
+ /**
+ * Create and parameterize the locus
+ */
+ @Override
+ public ILocus createLocus() {
+ ILocus locus = new TimedLocus();
+ locus.setExecutor(new CS_Executor());
+ locus.setFactory(new StochasticExecutionFactory());
+ return locus;
+ }
+}
diff --git a/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/semantics/StochasticAcceptEventActionActivation.java b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/semantics/StochasticAcceptEventActionActivation.java
new file mode 100644
index 0000000..e28d1f3
--- /dev/null
+++ b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/semantics/StochasticAcceptEventActionActivation.java
@@ -0,0 +1,159 @@
+/*****************************************************************************
+ * Copyright (c) 2023 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * CEA LIST Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.moka.engine.uml.stochastic.semantics;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.papyrus.moka.engine.uml.time.scheduling.de.DEScheduler;
+import org.eclipse.papyrus.moka.engine.uml.time.scheduling.de.Event;
+import org.eclipse.papyrus.moka.engine.uml.time.semantics.Actions.CompleteActions.TimedAcceptEventActionActivation;
+import org.eclipse.papyrus.moka.engine.uml.time.semantics.CommonBehaviors.TimedEventOccurrence;
+import org.eclipse.papyrus.moka.fuml.activities.IActivityExecution;
+import org.eclipse.papyrus.moka.fuml.activities.IToken;
+import org.eclipse.papyrus.moka.fuml.commonbehavior.IEventOccurrence;
+import org.eclipse.papyrus.moka.fuml.debug.Debug;
+import org.eclipse.papyrus.moka.fuml.loci.ISemanticVisitor;
+import org.eclipse.papyrus.moka.fuml.simpleclassifiers.IEvaluation;
+import org.eclipse.papyrus.moka.fuml.simpleclassifiers.IRealValue;
+import org.eclipse.papyrus.moka.fuml.simpleclassifiers.IValue;
+import org.eclipse.papyrus.moka.fuml.simpleclassifiers.RealValue;
+import org.eclipse.papyrus.moka.fuml.structuredclassifiers.IObject_;
+import org.eclipse.papyrus.moka.pssm.values.ISM_OpaqueExpressionEvaluation;
+import org.eclipse.uml2.uml.AcceptEventAction;
+import org.eclipse.uml2.uml.TimeEvent;
+import org.eclipse.uml2.uml.Trigger;
+
+public class StochasticAcceptEventActionActivation extends TimedAcceptEventActionActivation {
+
+ private Map<Trigger, RealValue> evaluationValues;
+
+ public StochasticAcceptEventActionActivation() {
+ super();
+ evaluationValues = new HashMap<>();
+ }
+
+ @Override
+ public void fire(List<IToken> incomingTokens) {
+
+ // Register the event accepter for this accept event action activation
+ // with the context object of the enclosing activity execution
+ // and wait for an event to be accepted.
+ Debug.println("[fire] Action " + this.node.getName() + "...");
+ this.getExecutionContext().register(this.eventAccepter);
+ this.waiting = true;
+ this.firing = false;
+ this.suspend();
+
+ pushEvents(((AcceptEventAction) this.getNode()).getTriggers(), this, this.getExecutionContext(),this.getGroup().getActivityExecution());
+ }
+
+ @Override
+ public Boolean match(IEventOccurrence eventOccurrence) {
+ boolean matches = false;
+
+ if (eventOccurrence instanceof TimedEventOccurrence) {
+ TimedEventOccurrence timedEventOccurrence = (TimedEventOccurrence) eventOccurrence;
+
+ AcceptEventAction action = (AcceptEventAction) (this.node);
+
+ for (Trigger trigger : action.getTriggers()) {
+ if (trigger.getEvent() instanceof TimeEvent) {
+ TimeEvent timeEvent = (TimeEvent) trigger.getEvent();
+ if (timeEvent.getWhen() != null && timeEvent.getWhen().getExpr() != null) {
+ IValue evaluatedInstant = getEvaluationValue(trigger);
+
+ if (evaluatedInstant instanceof IRealValue) {
+
+ if (timeEvent.isRelative()) {
+ matches = timedEventOccurrence.getReferenceInstance().getValue() + ((IRealValue) evaluatedInstant)
+ .getValue() == timedEventOccurrence.getOccurrenceInstant().getValue();
+ } else {
+ matches = timedEventOccurrence.getOccurrenceInstant().equals(evaluatedInstant);
+ }
+ }
+ }
+ }
+
+ }
+
+ }
+ return matches;
+
+// return eventOccurrence.matchAny(action.getTriggers());
+
+// evaluationValues.get(even)
+
+ // Return true if the given event occurrence matches a trigger of the
+ // accept event action of this activation.
+// AcceptEventAction action = (AcceptEventAction) (this.node);
+// return eventOccurrence.matchAny(action.getTriggers());
+ }
+
+ private void pushEvents(List<Trigger> triggers, ISemanticVisitor visitor, IObject_ context, IActivityExecution activityExecution) {
+ // Register timers for triggers that may accept a time event in the future.
+ // When the timer will fire the context object will receive a time event
+ // occurrence.
+ for (Trigger trigger : triggers) {
+ pushEvent(trigger, visitor, context,activityExecution);
+ }
+ }
+
+ private void pushEvent(Trigger trigger, ISemanticVisitor visitor, IObject_ context, IActivityExecution activityExecution) {
+ // Register a timer for a trigger associated to a time event. The specification
+ // of the timer consists in an event registered to the DEScheduler. This event
+ // is time
+ // stamped with the instant at which the timer shall fire.
+ if (context != null && trigger != null && trigger.getEvent() instanceof TimeEvent) {
+ TimeEvent timeEvent = (TimeEvent) trigger.getEvent();
+ if (timeEvent.getWhen() != null && timeEvent.getWhen().getExpr() != null) {
+ IEvaluation evaluation = context.getLocus().getFactory()
+ .createEvaluation(timeEvent.getWhen().getExpr());
+ if (evaluation != null) {
+ if (evaluation instanceof ISM_OpaqueExpressionEvaluation) {
+ ((ISM_OpaqueExpressionEvaluation) evaluation).setContext(context);
+ }
+ IValue evaluationValue = evaluation.evaluate();
+
+ if (evaluationValue instanceof RealValue) {
+ RealValue evaluationRealValue = (RealValue) evaluationValue;
+
+ evaluationValues.put(trigger, evaluationRealValue);
+
+ if (getEvaluationValue(trigger) != null && getEvaluationValue(trigger) instanceof IRealValue) {
+ double clockTime = DEScheduler.getInstance().getCurrentTime();
+ Event clockEvent = new Event(((IRealValue) getEvaluationValue(trigger)).getValue(),
+ new StochasticSendTimeEventOccurrence((IRealValue) getEvaluationValue(trigger),
+ clockTime, visitor, context,activityExecution));
+ if (timeEvent.isRelative()) {
+ DEScheduler.getInstance().pushEvent(clockEvent);
+ } else {
+ DEScheduler.getInstance().pushEvent(clockEvent,
+ ((IRealValue) getEvaluationValue(trigger)).getValue());
+ }
+ }
+ }
+
+
+ }
+ }
+ }
+ }
+
+ public IValue getEvaluationValue(Trigger trigger) {
+ return evaluationValues.get(trigger);
+ }
+
+}
diff --git a/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/semantics/StochasticActivityExecution.java b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/semantics/StochasticActivityExecution.java
new file mode 100644
index 0000000..6db48da
--- /dev/null
+++ b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/semantics/StochasticActivityExecution.java
@@ -0,0 +1,41 @@
+package org.eclipse.papyrus.moka.engine.uml.stochastic.semantics;
+
+import java.util.List;
+
+import org.eclipse.papyrus.moka.engine.uml.time.activities.Timed_ActivityExecution;
+import org.eclipse.papyrus.moka.engine.uml.time.scheduling.de.DEScheduler;
+import org.eclipse.papyrus.moka.engine.uml.time.scheduling.de.Event;
+import org.eclipse.papyrus.moka.engine.uml.time.scheduling.de.actions.CallbackAction;
+import org.eclipse.papyrus.moka.fuml.activities.IActivityExecution;
+
+public class StochasticActivityExecution extends Timed_ActivityExecution {
+
+ @Override
+ public void destroy() {
+
+ List<Event> events = DEScheduler.getInstance().getEvents();
+
+ for (Event event : events) {
+ CallbackAction callbackAction = event.getAction();
+ if (callbackAction instanceof StochasticSendTimeEventOccurrence) {
+ IActivityExecution activityExecution = ((StochasticSendTimeEventOccurrence) callbackAction).getActivityExecution();
+
+ if (activityExecution.equals(this)) {
+ return;
+ }
+ }
+ }
+ // Stop the object activation (if any), clear all types and destroy the
+ // object as an extensional value.
+
+ // Issue FUML12-33 Extensional values should have an unique identifier
+
+ if (this.objectActivation != null) {
+ this.objectActivation.stop();
+ this.objectActivation = null;
+ }
+ this.types.clear();
+ super.destroy();
+ }
+
+}
diff --git a/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/semantics/StochasticEventOccurrence.java b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/semantics/StochasticEventOccurrence.java
new file mode 100644
index 0000000..36b3c97
--- /dev/null
+++ b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/semantics/StochasticEventOccurrence.java
@@ -0,0 +1,70 @@
+/*****************************************************************************
+ * Copyright (c) 2023 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * CEA LIST Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.moka.engine.uml.stochastic.semantics;
+
+import org.eclipse.papyrus.moka.engine.uml.time.semantics.CommonBehaviors.TimedEventOccurrence;
+import org.eclipse.papyrus.moka.fuml.simpleclassifiers.IEvaluation;
+import org.eclipse.papyrus.moka.fuml.simpleclassifiers.IRealValue;
+import org.eclipse.papyrus.moka.pssm.values.ISM_OpaqueExpressionEvaluation;
+import org.eclipse.uml2.uml.TimeEvent;
+import org.eclipse.uml2.uml.Trigger;
+
+public class StochasticEventOccurrence extends TimedEventOccurrence {
+ private IRealValue evaluationValue;
+
+ @Override
+ public boolean match(Trigger trigger) {
+ // Define the rule to match this event occurrence against a trigger
+ // This event occurrence matches if the following condition hold:
+ // 1] If the trigger is for a TimeEvent
+ // 2] If the time expression can be evaluated
+ // 3] If the occurrence instant (i.e., the time at which this occurrence
+ // occurred) matches the time at which the model element referencing the
+ // trigger was expected to fire. Note that the triggering time can either
+ // relative or absolute.
+ boolean matches = false;
+ if (trigger.getEvent() instanceof TimeEvent) {
+ TimeEvent timeEvent = (TimeEvent) trigger.getEvent();
+ if (timeEvent.getWhen() != null && timeEvent.getWhen().getExpr() != null) {
+
+ IRealValue evaluatedInstant = evaluationValue;
+
+ if (evaluatedInstant == null) {
+ IEvaluation evaluation = this.target.getReferent().getLocus().getFactory()
+ .createEvaluation(timeEvent.getWhen().getExpr());
+ if (evaluation != null) {
+ if (evaluation instanceof ISM_OpaqueExpressionEvaluation) {
+ ((ISM_OpaqueExpressionEvaluation) evaluation).setContext(this.target.getReferent());
+ }
+ evaluatedInstant = (IRealValue) evaluation.evaluate();
+ }
+ }
+
+ if (evaluatedInstant != null) {
+ if (timeEvent.isRelative()) {
+ matches = this.referenceInstant.getValue()
+ + evaluatedInstant.getValue() == this.occurrenceInstant.getValue();
+ } else {
+ matches = this.occurrenceInstant.equals(evaluatedInstant);
+ }
+ }
+ }
+ }
+ return matches;
+ }
+
+ public void setEvaluationValue(IRealValue evaluationValue) {
+ this.evaluationValue = evaluationValue;
+ }
+}
diff --git a/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/semantics/StochasticExecutionFactory.java b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/semantics/StochasticExecutionFactory.java
new file mode 100644
index 0000000..f9c3d04
--- /dev/null
+++ b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/semantics/StochasticExecutionFactory.java
@@ -0,0 +1,57 @@
+/*****************************************************************************
+ * Copyright (c) 2023 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * CEA LIST Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.moka.engine.uml.stochastic.semantics;
+
+import org.eclipse.papyrus.moka.engine.uml.time.UMLTimedExecutionEngineUtils;
+import org.eclipse.papyrus.moka.engine.uml.time.activities.Timed_ActivityExecution;
+import org.eclipse.papyrus.moka.engine.uml.time.semantics.Loci.TimedExecutionFactory;
+import org.eclipse.papyrus.moka.fuml.loci.ISemanticVisitor;
+import org.eclipse.uml2.uml.AcceptCallAction;
+import org.eclipse.uml2.uml.AcceptEventAction;
+import org.eclipse.uml2.uml.Activity;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.OpaqueExpression;
+
+public class StochasticExecutionFactory extends TimedExecutionFactory {
+
+ private static final String STOCHASTIC = "stochastic";
+
+ @Override
+ public ISemanticVisitor instantiateVisitor(Element element) {
+ // Extends fUML semantics in the sense that newly introduced
+ // semantic visitors are instantiated instead of fUML visitors
+ ISemanticVisitor visitor = null;
+ if (element instanceof OpaqueExpression && isStochasticLanguage((OpaqueExpression) element)) {
+ visitor = new StochasticOpaqueExpressionEvaluation();
+ } else if (element instanceof AcceptEventAction && !(element instanceof AcceptCallAction)
+ && UMLTimedExecutionEngineUtils.isTimeTriggered(((AcceptEventAction) element).getTriggers())) {
+ visitor = new StochasticAcceptEventActionActivation();
+ } else if (element instanceof Activity) {
+ visitor = new StochasticActivityExecution();
+ } else {
+ visitor = super.instantiateVisitor(element);
+ }
+ return visitor;
+ }
+
+ private boolean isStochasticLanguage(OpaqueExpression element) {
+ if (element.getLanguages().size() == 1) {
+ if (element.getLanguages().get(0).equals(STOCHASTIC)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+}
\ No newline at end of file
diff --git a/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/semantics/StochasticOpaqueExpressionEvaluation.java b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/semantics/StochasticOpaqueExpressionEvaluation.java
new file mode 100644
index 0000000..be1a7a0
--- /dev/null
+++ b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/semantics/StochasticOpaqueExpressionEvaluation.java
@@ -0,0 +1,55 @@
+/*****************************************************************************
+ * Copyright (c) 2023 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * CEA LIST Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.moka.engine.uml.stochastic.semantics;
+
+import org.eclipse.papyrus.moka.engine.uml.stochastic.DistributionsInterpreter;
+import org.eclipse.papyrus.moka.fuml.simpleclassifiers.IRealValue;
+import org.eclipse.papyrus.moka.fuml.simpleclassifiers.IValue;
+import org.eclipse.papyrus.moka.fuml.simpleclassifiers.RealValue;
+import org.eclipse.papyrus.moka.pssm.values.SM_OpaqueExpressionEvaluation;
+import org.eclipse.uml2.uml.OpaqueExpression;
+import org.eclipse.uml2.uml.PrimitiveType;
+
+public class StochasticOpaqueExpressionEvaluation extends SM_OpaqueExpressionEvaluation {
+
+ @Override
+ public IValue evaluate() {
+
+ if (specification instanceof OpaqueExpression) {
+ OpaqueExpression opaqueExpression = (OpaqueExpression) specification;
+
+ if (opaqueExpression.getBodies().size() == 1) {
+ String expression = opaqueExpression.getBodies().get(0);
+ double sample = DistributionsInterpreter.matchDistribution(expression);
+ if (sample != Double.NaN) {
+// if(sample < 0) {
+ Math.abs(sample);
+// }
+ IRealValue result = new RealValue();
+ result.setValue(sample);
+ result.setType((PrimitiveType) this.locus.getFactory().getBuiltInType("Real"));
+
+ return result;
+ } else {
+ System.out.println("Pb !!!");
+ }
+
+ }
+
+ }
+
+ return super.evaluate();
+ }
+
+}
\ No newline at end of file
diff --git a/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/semantics/StochasticSendTimeEventOccurrence.java b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/semantics/StochasticSendTimeEventOccurrence.java
new file mode 100644
index 0000000..5be6123
--- /dev/null
+++ b/stochastic/org.eclipse.papyrus.moka.engine.uml.stochastic/src/org/eclipse/papyrus/moka/engine/uml/stochastic/semantics/StochasticSendTimeEventOccurrence.java
@@ -0,0 +1,55 @@
+/*****************************************************************************
+ * Copyright (c) 2023 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * CEA LIST Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.moka.engine.uml.stochastic.semantics;
+
+import org.eclipse.papyrus.moka.engine.uml.time.actions.SendTimeEventOccurrence;
+import org.eclipse.papyrus.moka.engine.uml.time.scheduling.de.DEScheduler;
+import org.eclipse.papyrus.moka.fuml.activities.IActivityExecution;
+import org.eclipse.papyrus.moka.fuml.loci.ISemanticVisitor;
+import org.eclipse.papyrus.moka.fuml.simpleclassifiers.IRealValue;
+import org.eclipse.papyrus.moka.fuml.structuredclassifiers.IObject_;
+import org.eclipse.papyrus.moka.fuml.structuredclassifiers.IReference;
+import org.eclipse.papyrus.moka.fuml.structuredclassifiers.Reference;
+
+public class StochasticSendTimeEventOccurrence extends SendTimeEventOccurrence {
+ private IRealValue evaluationValue;
+ private IActivityExecution activityExecution;
+
+
+ public StochasticSendTimeEventOccurrence(IRealValue evaluationValue, double referenceInstant,
+ ISemanticVisitor visitor, IObject_ target, IActivityExecution activityExecution) {
+ super(referenceInstant, visitor, target);
+ this.evaluationValue = evaluationValue;
+ this.activityExecution = activityExecution;
+ }
+
+ @Override
+ public void execute() {
+ // Register a time event occurrence to the target object. This
+ // enables the target object classifier behavior to react (if possible)
+ // to the fact that clock time has evolved.
+ StochasticEventOccurrence eventOccurrence = new StochasticEventOccurrence();
+ eventOccurrence.setReferenceInstant(this.referenceInstant);
+ eventOccurrence.setOccurrenceInstant(DEScheduler.getInstance().getCurrentTime());
+ IReference targetReference = new Reference();
+ targetReference.setReferent(this.target);
+ eventOccurrence.setTarget(targetReference);
+ eventOccurrence.register();
+ eventOccurrence.setEvaluationValue(evaluationValue);
+ }
+
+ public IActivityExecution getActivityExecution() {
+ return activityExecution;
+ }
+}