13#if !defined(VITA_SYMBOL_SET_H)
14#define VITA_SYMBOL_SET_H
39 using weight_t = unsigned;
46 template<
class S,
class ...Args>
symbol *
insert(Args &&...);
68 std::vector<std::unique_ptr<symbol>> symbols_;
72 w_symbol(
symbol *s, weight_t w) : sym(s),
weight(w) { Expects(s); }
74 bool operator==(w_symbol rhs)
const
75 {
return sym == rhs.sym &&
weight == rhs.weight; }
84 static constexpr weight_t base_weight = 100;
92 explicit collection(std::string =
"");
99 using sum_container_t = std::vector<w_symbol>;
100 using iterator = sum_container_t::iterator;
101 using const_iterator = sum_container_t::const_iterator;
104 : elems_(), sum_(0), name_(std::move(n))
106 Expects(!name_.empty());
109 void insert(
const w_symbol &);
111 std::size_t size()
const {
return elems_.size(); }
112 const w_symbol &operator[](std::size_t i)
const {
return elems_[i]; }
114 iterator begin() {
return elems_.begin(); }
115 const_iterator begin()
const {
return elems_.begin(); }
116 iterator end() {
return elems_.end(); }
117 const_iterator end()
const {
return elems_.end(); }
119 weight_t sum()
const {
return sum_; }
121 template<
class F>
void scale_weights(
double, F);
127 sum_container_t elems_;
147 std::vector<collection> views_;
169 return insert(std::make_unique<S>(std::forward<Args>(args)...));
A symbol with arity() > 0.
void insert(const w_symbol &)
Inserts a weighted symbol in the container.
const symbol & roulette() const
Extracts a random symbol from the collection.
A container for the symbols used by the GP engine.
symbol * decode(opcode_t) const
symbol_set()
Sets up the object.
void clear()
Clears the current symbol set.
const function & roulette_function(category_t) const
const symbol & roulette(category_t) const
Extracts a random symbol from the symbol set without bias between terminals and functions .
bool enough_terminals() const
We want at least one terminal for every used category.
weight_t weight(const symbol &) const
symbol * insert(std::unique_ptr< symbol >, double=1.0)
Adds a new symbol to the set.
friend std::ostream & operator<<(std::ostream &, const symbol_set &)
Prints the symbol set to an output stream.
const symbol & roulette_free(category_t) const
Extracts a random symbol from the symbol set.
const terminal & roulette_terminal(category_t) const
category_t categories() const
std::size_t terminals(category_t) const
Together functions and terminals are referred to as symbols.
A symbol with zero-arity.
The main namespace for the project.
std::size_t category_t
A category provide operations which supplement or supersede those of the domain but which are restric...
std::ostream & operator<<(std::ostream &o, hash_t h)
Mainly useful for debugging / testing.
unsigned opcode_t
This is the type used as key for symbol identification.