 |
Synthia
Generic and flexible data structure generator
|
Go to the documentation of this file.
19 package ca.uqac.lif.synthia.sequence;
21 import java.io.PrintStream;
22 import java.util.ArrayList;
23 import java.util.HashMap;
24 import java.util.List;
57 protected Map<Integer,Picker<? extends T>>
m_pickers;
85 m_pickers =
new HashMap<Integer,Picker<? extends T>>();
99 Transition t =
new Transition(destination, probability.floatValue());
103 trans =
new ArrayList<Transition>();
155 throw new PickerException(
"State " + new_state +
" does not have a picker");
177 for (Transition t : transitions)
179 sum_prob += t.getProbability();
180 last_state = t.getDestination();
215 out.println(
"digraph G {");
216 out.println(
" node [style=filled];");
220 out.print(e.getKey());
221 out.print(
" [label=\"");
222 out.print(e.getValue().toString());
225 for (Map.Entry<Integer,List<Transition>> e :
m_transitions.entrySet())
227 for (Transition t : e.getValue())
230 out.print(e.getKey());
232 out.print(t.getDestination());
233 out.print(
" [label=\"");
234 out.print(t.getProbability());
244 public static class Transition
246 protected int m_destination;
248 protected float m_probability;
255 public Transition(
int destination,
float probability)
258 m_destination = destination;
259 m_probability = probability;
262 public int getDestination()
264 return m_destination;
267 public float getProbability()
269 return m_probability;
273 public String toString()
275 return "-> " + m_destination +
" (" + m_probability +
")";
void toDot(PrintStream out)
Produces a rendition of the machine as Graphviz input file.
int m_currentState
The index of the current state of the machine.
MarkovChain< T > add(int state, Picker< T > p)
Associates a picker to a state.
Map< Integer, Picker<? extends T > > m_pickers
The pickers associated to each state.
MarkovChain< T > add(int source, int destination, Number probability)
Adds a new transition to the machine.
void reset()
Puts the picker back into its initial state.
Picker< Float > m_floatSource
A source of numbers between 0 and 1.
Generic runtime exception thrown by the Picker interface.
MarkovChain< T > duplicate(boolean with_state)
Creates a copy of the picker.
MarkovChain(Picker< Float > float_source)
Creates a new empty Markov chain.
Generates a sequence of objects by a random walk in a Markov chain.
Map< Integer, List< Transition > > m_transitions
A map associating state numbers with the list of their outgoing transitions.
int selectTransition(float p)
From the current state, randomly selects a destination state based on the probabilities associated to...
MarkovChain< T > exhaust(boolean b)
Sets whether to exhaust the picker associated to a state before transitioning to another state.
boolean m_exhaust
Whether to exhaust each state before moving to another.
void reset()
Puts the picker back into its initial state.