1 /*******************************************************************************
\r
2 * Copyright (c) 2013 Association for Decentralized Information Management in
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * Semantum Oy - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.sysdyn.adapter.distribution;
\r
14 import java.util.Random;
\r
16 import org.simantics.databoard.Bindings;
\r
17 import org.simantics.db.ReadGraph;
\r
18 import org.simantics.db.Resource;
\r
19 import org.simantics.db.exception.DatabaseException;
\r
20 import org.simantics.layer0.Layer0;
\r
21 import org.simantics.sysdyn.SysdynResource;
\r
23 public class UniformDistribution implements IDistribution {
\r
26 private Random random;
\r
30 private int numberOfValues = 10;
\r
31 private int seed = 123;
\r
32 private int index = 0;
\r
34 public UniformDistribution(ReadGraph graph, Resource distribution) {
\r
37 SysdynResource SR = SysdynResource.getInstance(graph);
\r
39 Double minValue = graph.getPossibleRelatedValue(distribution, SR.UniformDistribution_minValue, Bindings.DOUBLE);
\r
40 if(minValue != null)
\r
41 this.min = minValue;
\r
43 Double maxValue = graph.getPossibleRelatedValue(distribution, SR.UniformDistribution_maxValue, Bindings.DOUBLE);
\r
44 if(maxValue != null)
\r
45 this.max = maxValue;
\r
48 Resource parameter = graph.getPossibleObject(distribution, SR.SensitivityAnalysisExperiment_Parameter_propabilityDistribution_Inverse);
\r
50 Integer numberOfValues = graph.getPossibleRelatedValue(parameter, SR.SensitivityAnalysisExperiment_Parameter_numberOfValues, Bindings.INTEGER);
\r
51 if(numberOfValues != null)
\r
52 this.numberOfValues = numberOfValues;
\r
56 Resource experiment = graph.getPossibleObject(parameter, Layer0.getInstance(graph).PartOf);
\r
58 Integer seed = graph.getPossibleRelatedValue(experiment, SR.SensitivityAnalysisExperiment_randomSeed, Bindings.INTEGER);
\r
62 } catch (DatabaseException e) {
\r
68 public Random getRandom() {
\r
72 public double getMin() {
\r
76 public double getMax() {
\r
80 public int getNumberOfValues() {
\r
81 return numberOfValues;
\r
84 public int getSeed() {
\r
92 public double next() {
\r
94 double d = min + ((double)random.nextInt(101) / 100.0) * (max-min);
\r
100 public void initialize() {
\r
101 random = new Random(this.seed);
\r
106 public boolean hasNext() {
\r
107 return index < numberOfValues;
\r