 |
Synthia
Generic and flexible data structure generator
|
Go to the documentation of this file.
19 package ca.uqac.lif.synthia.util;
21 import java.util.ArrayList;
22 import java.util.List;
63 m_choices =
new ArrayList<ProbabilityChoice<T>>();
86 ProbabilityChoice<T> pc =
new ProbabilityChoice<T>(
new Constant<T>(t), p);
98 ProbabilityChoice<T> pc =
new ProbabilityChoice<T>(t, p);
112 for (ProbabilityChoice<?> pc :
m_choices)
130 float[] probs =
new float[
m_choices.size()];
131 float total_prob = 0f;
132 for (
int i = 0; i < probs.length; i++)
134 total_prob +=
m_choices.get(i).getProbability();
135 probs[i] = total_prob;
139 while (index < probs.length)
141 if (f <= probs[index])
166 for (ProbabilityChoice<T> pc :
m_choices)
168 ep.
m_choices.add(pc.duplicate(with_state));
178 public static class ProbabilityChoice<T>
183 protected float m_probability;
195 public ProbabilityChoice(
Picker<T> t, Number p)
199 m_probability = p.floatValue();
214 public float getProbability()
216 return m_probability;
225 return m_object.
pick();
234 public String toString()
236 return m_object.toString() +
" (" + m_probability +
")";
245 public ProbabilityChoice<T>
duplicate(
boolean with_state)
247 return new ProbabilityChoice<T>(m_object, m_probability);
Shrinkable< T > shrink(T o, Picker< Float > decision, float m)
Shrinks a picker.
Interface signaling that a picker can be shrunk.
int getChoiceCount()
Gets the total number of alternatives available in this picker.
T pick()
Picks a random element.
A variant of PickIf that selects an element if it is smaller than a reference object.
static final transient RandomFloat instance
A public static instance of RandomFloat.
Shrinkable< T > shrink(T o)
Shrinks a picker with default parameters.
Pickers that produce pseudo-random objects such as numbers.
Picker that returns the same object every time.
Choice< T > duplicate(boolean with_state)
Creates a copy of the element picker.
Picker< Float > m_floatPicker
A picker used to choose the element.
Choice< T > add(ProbabilityChoice< T > pc)
Adds an object-probability association.
Pickers that produce a value in relation to another value.
List< ProbabilityChoice< T > > m_choices
A list storing each element with its associated probability.
Choice< T > add(T t, Number p)
Adds an object-probability association.
Picks a floating point number uniformly in an interval.
Picks an element from a collection, where the probability of picking each element can be user-defined...
Choice< T > add(Picker< T > t, Number p)
Adds an object-probability association.
Choice(Picker< Float > picker)
Creates a new element picker.
Picker< T > duplicate(boolean with_state)
Creates a copy of the picker.
void reset()
Puts the picker back into its initial state.
void reset()
Puts the element picker back into its initial state.