SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
Weights.java
1package umontreal.ssj.latnetbuilder.weights;
2
3import java.util.ArrayList;
4import java.util.List;
5
20public abstract class Weights<T> {
25 protected double defaultWeight = 0.0;
26 protected ArrayList<SingletonWeight<T>> weights; // actual weights
27
33 public Weights(List<SingletonWeight<T>> w) {
34 weights = new ArrayList<SingletonWeight<T>>(w);
35 }
36
40 public Weights() {
41 weights = new ArrayList<SingletonWeight<T>>();
42 }
43
49 public ArrayList<SingletonWeight<T>> getWeights() {
50 return weights;
51 }
52
58 public void setDefaultWeight(double dWeight) {
59 defaultWeight = dWeight;
60 }
61
67 public double getDefaultWeight() {
68 return defaultWeight;
69 }
70
77 public void add(SingletonWeight<T> singletonWeight) {
78 boolean added = false;
79 for (SingletonWeight<T> w : weights) {
80 if (w.getIndex() == singletonWeight.getIndex() && (!added)) {
81 weights.set(weights.indexOf(w), singletonWeight);
82 added = true;
83 }
84 }
85 if (!added)
86 weights.add(singletonWeight);
87 }
88
96 public void add(T index, double weight) {
97 add(new SingletonWeight<T>(index, weight));
98 }
99
103 public String toString() {
104 StringBuffer sb = new StringBuffer("");
105 sb.append("Weights [default = " + getDefaultWeight() + "]\n");
106
107 sb.append("[");
108 for (SingletonWeight<T> w : weights)
109 sb.append(w.getWeight() + ",");
110 sb.deleteCharAt(sb.length() - 1);
111 sb.append("]\n");
112 return sb.toString();
113 }
114
115 /*
116 * Methods to be implemented for non-abstract class
117 */
124 public abstract String toLatNetBuilder();
125
126}
Implements a single instance of a weight for search-algorithms for quasi-Monte Carlo point sets as,...
ArrayList< SingletonWeight< T > > getWeights()
Returns the current weights as a list.
Definition Weights.java:49
void add(SingletonWeight< T > singletonWeight)
Adds a new weight.
Definition Weights.java:77
Weights()
Initializes an empty list of weights.
Definition Weights.java:40
double defaultWeight
Weight to be used for indices that were not explicitly set.
Definition Weights.java:25
String toString()
Basic formatted string-output.
Definition Weights.java:103
abstract String toLatNetBuilder()
Provides a String that can be interpreted by the command line interface of LatNetBuilder.
double getDefaultWeight()
Returns the current 'defaultWeight'.
Definition Weights.java:67
Weights(List< SingletonWeight< T > > w)
Constructs weights from a list of SingletonWeights.
Definition Weights.java:33
void setDefaultWeight(double dWeight)
Sets 'dWeight' as the current 'defaultWeight'.
Definition Weights.java:58
void add(T index, double weight)
Adds a new weight with index 'index' and weight 'weight' or overwrites it, if the index already exist...
Definition Weights.java:96