Other Tools

Alert

namespace emp

If we are in emscripten, make sure to include the header.

This file contains extra analysis tools to use with systematics managers that have non-null DATA_TYPES.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

This file contains functions for adding additional data files to Worlds.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

Functions

void Alert(const std::string &msg)

Send msg to cerr if in C++, or show msg in an alert box if compiled to Javascript Input can be any number of arguments of any types as long as the can be converted to strings with emp::to_string().

template <typename... TYPE_SET>
static void CappedAlert(size_t cap, TYPE_SET... inputs)

A version of Alert that will cap how many times it can go off.

struct AlertObj
#include <alert.h>

An object that will automatically output a message during construction or destruction, usually for use in debugging to disentangle timings.

Public Functions

AlertObj(const std::string &_msg, bool _on_c = true, bool _on_d = false)
~AlertObj()
void Trigger()
void SetMessage(const std::string &_msg)

Public Members

std::string msg

Message for the alert to print.

bool on_construct

Should the message print automatically during construction?

bool on_destruct

Should the message print automatically during destruction?

BitMatrix

A COL x ROW matrix of bits and provides easy indexing and manipulation.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2016-2017
Note
Status: BETA

namespace emp

If we are in emscripten, make sure to include the header.

This file contains extra analysis tools to use with systematics managers that have non-null DATA_TYPES.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

This file contains functions for adding additional data files to Worlds.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

template <size_t COLS, size_t ROWS>
class BitMatrix
#include <BitMatrix.h>

A simple class to manage a COLS x ROWS matrix of bits.

Bits are translated to a bitset with 0 in the upper left and moving through bits from left to right and top to bottom. For example, the indecies in a 3x3 bit matrix would be organized as such:

0 1 2 3 4 5 6 7 8

Public Functions

template <size_t START_POS, size_t STEP_POS, size_t END_POS>
constexpr BitSet<COLS*ROWS> Mask() const
BitMatrix()
BitMatrix(const BitSet<COLS *ROWS> &in_bits)
BitMatrix(const BitMatrix &in_matrix)
~BitMatrix()
constexpr size_t NumRows() const

How many rows are in this matrix?

constexpr size_t NumCols() const

How many columns are in this matrix?

constexpr size_t GetSize() const

How many total cells are in this matrix?

bool Any() const
bool None() const
bool All() const
bool Get(size_t col, size_t row) const
bool Get(size_t id) const
void Set(size_t col, size_t row, bool val = true)
void Set(size_t id)
void Unset(size_t col, size_t row)
void Unset(size_t id)
void Flip(size_t col, size_t row)
void Flip(size_t id)
void SetAll()
void SetCol(size_t col)
void SetRow(size_t row)
void Clear()
void ClearCol(size_t col)
void ClearRow(size_t row)
size_t CountOnes() const
int FindBit() const
BitMatrix LeftShift() const
BitMatrix RightShift() const
BitMatrix UpShift() const
BitMatrix DownShift() const
BitMatrix ULShift() const
BitMatrix DLShift() const
BitMatrix URShift() const
BitMatrix DRShift() const
BitMatrix GetReach() const
BitMatrix GetRegion(size_t start_pos) const
BitMatrix GetRegion(size_t col, size_t row) const
bool IsConnected() const
bool Has2x2() const
void Print(std::ostream &os = std::cout) const
BitMatrix &operator=(const BitMatrix &in)
BitMatrix &operator&=(const BitMatrix &in)
BitMatrix &operator|=(const BitMatrix &in)
BitMatrix &operator^=(const BitMatrix &in)
bool operator==(const BitMatrix &in) const
bool operator!=(const BitMatrix &in) const
BitMatrix operator~() const
BitMatrix operator&(const BitMatrix &in) const
BitMatrix operator|(const BitMatrix &in) const
BitMatrix operator^(const BitMatrix &in) const
const BitSet<COLS*ROWS> &to_bitset()

Public Static Functions

template <size_t COL_ID>
static const BitSet<COLS*ROWS> &MaskCol()

Keep only a single column of values, reducing all others to zeros.

template <size_t ROW_ID>
static const BitSet<COLS*ROWS> &MaskRow()

Keep only a single row of values, reducing all others to zeros.

static size_t ToCol(size_t id)

Identify which column a specific ID is part of.

static size_t ToRow(size_t id)

Identify which row a specific ID is part of.

static size_t ToID(size_t col, size_t row)

Identify the ID associated with a specified row and column.

Private Members

BitSet<COLS*ROWS> bits

Actual bits in matrix.

BitSet

A drop-in replacement for std::bitset, with additional bit magic features.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2016-2018
Note
Status: RELEASE
Note
Like std::bitset, bit zero is on the right side. Unlike std::bitset, emp::BitSet gives access to bit fields for easy access to different sized chucnk of bits and implementation new bit-magic tricks.

Functions

template <size_t NUM_BITS>
std::ostream &operator<<(std::ostream &out, const emp::BitSet<NUM_BITS> &_bit_set)
namespace emp

If we are in emscripten, make sure to include the header.

This file contains extra analysis tools to use with systematics managers that have non-null DATA_TYPES.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

This file contains functions for adding additional data files to Worlds.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

Functions

template <size_t NUM_BITS1, size_t NUM_BITS2>
BitSet<NUM_BITS1+NUM_BITS2> join(const BitSet<NUM_BITS1> &in1, const BitSet<NUM_BITS2> &in2)
template <size_t NUM_BITS>
double SimpleMatchCoeff(const BitSet<NUM_BITS> &in1, const BitSet<NUM_BITS> &in2)

Computes simple matching coefficient (https://en.wikipedia.org/wiki/Simple_matching_coefficient).

template <size_t NUM_BITS>
class BitSet
#include <BitSet.h>

A fixed-sized (but arbitrarily large) array of bits, and optimizes operations on those bits to be as fast as possible.

Public Functions

BitSet()

Constructor: Assume all zeroes in set.

BitSet(const BitSet &in_set)

Copy constructor from another BitSet.

BitSet(Random &random)

Constructor to generate a random BitSet (with equal prob of 0 or 1).

BitSet(Random &random, const double p1)

Constructor to generate a random BitSet with provided prob of 1’s.

~BitSet()

Destructor.

BitSet &operator=(const BitSet<NUM_BITS> &in_set)

Assignment operator.

void Randomize(Random &random)

Set all bits randomly, with a 50% probability of being a 0 or 1.

void Randomize(Random &random, const double p1)

Set all bits randomly, with a given probability of being a 1.

template <size_t NUM_BITS2>
BitSet &Import(const BitSet<NUM_BITS2> &in_set)

Assign from a BitSet of a different size.

template <size_t NUM_BITS2>
BitSet<NUM_BITS2> Export() const

Convert to a Bitset of a different size.

bool operator==(const BitSet &in_set) const

Test if two BitSet objects are identical.

bool operator<(const BitSet &in_set) const

Compare two BitSet objects, based on the associated binary value.

bool operator<=(const BitSet &in_set) const

Compare two BitSet objects, based on the associated binary value.

bool operator!=(const BitSet &in_set) const

Test if two BitSet objects are different.

bool operator>(const BitSet &in_set) const

Compare two BitSet objects, based on the associated binary value.

bool operator>=(const BitSet &in_set) const

Compare two BitSet objects, based on the associated binary value.

bool Get(size_t index) const

Retrieve the bit as a specified index.

void Set(size_t index, bool value)

Set the bit as a specified index.

BitSet &Toggle()

Flip all bits in this BitSet.

BitSet &Toggle(size_t index)

Flip a single bit.

BitSet &Toggle(size_t start, size_t end)

Flips all the bits in a range [start, end)

uint8_t GetByte(size_t index) const

Get the full byte starting from the bit at a specified index.

void SetByte(size_t index, uint8_t value)

Set the full byte starting at the bit at the specified index.

uint32_t GetUInt(size_t index) const

Get the 32-bit unsigned int; index in in 32-bit jumps (i.e., this is a field ID not bit id)

void SetUInt(size_t index, uint32_t value)

Set the 32-bit unsigned int; index in in 32-bit jumps (i.e., this is a field ID not bit id)

uint32_t GetUIntAtBit(size_t index)

Get the full 32-bit unsigned int starting from the bit at a specified index.

template <size_t OUT_BITS>
uint32_t GetValueAtBit(size_t index)

Get OUT_BITS bits starting from the bit at a specified index (max 32)

bool Any() const

Return true if ANY bits in the BitSet are one, else return false.

bool None() const

Return true if NO bits in the BitSet are one, else return false.

bool All() const

Return true if ALL bits in the BitSet are one, else return false.

bool operator[](size_t index) const

Index into a const BitSet (i.e., cannot be set this way.)

BitProxy operator[](size_t index)

Index into a BitSet, returning a proxy that will allow bit assignment to work.

void Clear()

Set all bits to zero.

void SetAll()

Set all bits to one.

void Print(std::ostream &out = std::cout) const

Print all bits to the provided output stream.

void PrintArray(std::ostream &out = std::cout) const

Print all bits from smallest to largest, as if this were an array, not a bit representation.

void PrintOneIDs(std::ostream &out = std::cout, char spacer = ' ') const

Print the locations of all one bits, using the provided spacer (default is a single space)

size_t CountOnes_Sparse() const

Count 1’s by looping through once for each bit equal to 1.

size_t CountOnes_Mixed() const

Count 1’s in semi-parallel; fastest for even 0’s & 1’s.

size_t CountOnes() const

Count the number of ones in the BitSet using bit tricks for a speedup.

int FindBit() const

Return the index of the first one in the sequence; return -1 if no ones are available.

int PopBit()

Return index of first one in sequence (or -1 if no ones); change this position to zero.

int FindBit(const size_t start_pos) const

Return index of first one in sequence AFTER start_pos (or -1 if no ones)

emp::vector<size_t> GetOnes() const

Return a vector indicating the posistions of all ones in the BitSet.

BitSet NOT() const

Perform a Boolean NOT on this BitSet and return the result.

BitSet AND(const BitSet &set2) const

Perform a Boolean AND with a second BitSet and return the result.

BitSet OR(const BitSet &set2) const

Perform a Boolean OR with a second BitSet and return the result.

BitSet NAND(const BitSet &set2) const

Perform a Boolean NAND with a second BitSet and return the result.

BitSet NOR(const BitSet &set2) const

Perform a Boolean NOR with a second BitSet and return the result.

BitSet XOR(const BitSet &set2) const

Perform a Boolean XOR with a second BitSet and return the result.

BitSet EQU(const BitSet &set2) const

Perform a Boolean EQU with a second BitSet and return the result.

BitSet &NOT_SELF()

Perform a Boolean NOT on this BitSet, store result here, and return this object.

BitSet &AND_SELF(const BitSet &set2)

Perform a Boolean AND with a second BitSet, store result here, and return this object.

BitSet &OR_SELF(const BitSet &set2)

Perform a Boolean OR with a second BitSet, store result here, and return this object.

BitSet &NAND_SELF(const BitSet &set2)

Perform a Boolean NAND with a second BitSet, store result here, and return this object.

BitSet &NOR_SELF(const BitSet &set2)

Perform a Boolean NOR with a second BitSet, store result here, and return this object.

BitSet &XOR_SELF(const BitSet &set2)

Perform a Boolean XOR with a second BitSet, store result here, and return this object.

BitSet &EQU_SELF(const BitSet &set2)

Perform a Boolean EQU with a second BitSet, store result here, and return this object.

BitSet SHIFT(const int shift_size) const

Positive shifts go left and negative go right (0 does nothing); return result.

BitSet &SHIFT_SELF(const int shift_size)

Positive shifts go left and negative go right; store result here, and return this object.

BitSet operator~() const

Operator bitwise NOT…

BitSet operator&(const BitSet &ar2) const

Operator bitwise AND…

BitSet operator|(const BitSet &ar2) const

Operator bitwise OR…

BitSet operator^(const BitSet &ar2) const

Operator bitwise XOR…

BitSet operator<<(const size_t shift_size) const

Operator shift left…

BitSet operator>>(const size_t shift_size) const

Operator shift right…

const BitSet &operator&=(const BitSet &ar2)

Compound operator bitwise AND…

const BitSet &operator|=(const BitSet &ar2)

Compound operator bitwise OR…

const BitSet &operator^=(const BitSet &ar2)

Compound operator bitwise XOR…

const BitSet &operator<<=(const size_t shift_size)

Compound operator shift left…

const BitSet &operator>>=(const size_t shift_size)

Compound operator shift right…

bool all() const

Function to allow drop-in replacement with std::bitset.

bool any() const

Function to allow drop-in replacement with std::bitset.

bool none() const

Function to allow drop-in replacement with std::bitset.

size_t count() const

Function to allow drop-in replacement with std::bitset.

BitSet &flip()

Function to allow drop-in replacement with std::bitset.

BitSet &flip(size_t pos)

Function to allow drop-in replacement with std::bitset.

BitSet &flip(size_t start, size_t end)

Function to allow drop-in replacement with std::bitset.

Public Static Functions

static constexpr size_t GetSize()

How many bits are in this BitSet?

static constexpr size_t size()

Function to allow drop-in replacement with std::bitset.

Private Functions

void Copy(const uint32_t in_set[NUM_FIELDS])
void ShiftLeft(const uint32_t shift_size)

Helper: call SHIFT with positive number instead.

void ShiftRight(const uint32_t shift_size)

Helper for calling SHIFT with negative number.

Private Members

template<>
uint32_t bit_set[NUM_FIELDS]

Fields to hold the actual bits for this BitSet.

Private Static Functions

static size_t FieldID(const size_t index)
static size_t FieldPos(const size_t index)
static size_t Byte2Field(const size_t index)
static size_t Byte2FieldPos(const size_t index)

Private Static Attributes

const uint32_t NUM_FIELDS = 1 + ((NUM_BITS - 1) >> 5)

Fields hold bits in groups of 32 (as uint32_t); how many feilds do we need?

const uint32_t LAST_BIT = NUM_BITS & 31

End position of the stored bits in the last field; 0 if perfect fit.

const uint32_t NUM_BYTES = 1 + ((NUM_BITS - 1) >> 3)

How many total bytes are needed to represent these bits? (rounded up to full bytes)

Friends

friend emp::BitProxy
class BitProxy

BitProxy lets us use operator[] on with BitSet as an lvalue.

Public Functions

template<>
BitProxy(BitSet<NUM_BITS> &_set, size_t _idx)
template<>
BitProxy &operator=(bool b)

Set the bit value that this proxy refers to.

template<>
operator bool() const

Convert BitProxy to a regular boolean value.

template<>
BitProxy &Toggle()

Flip this bit.

Private Members

template<>
BitSet<NUM_BITS> &bit_set

BitSet object that this proxy refers to.

template<>
size_t index

Position in BitSet the this proxy refers to.

BitSet Utilities

A set of simple functions to manipulate bitsets.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2016-2017
Note
Status: BETA

namespace emp

If we are in emscripten, make sure to include the header.

This file contains extra analysis tools to use with systematics managers that have non-null DATA_TYPES.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

This file contains functions for adding additional data files to Worlds.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

Functions

template <int NUM_BITS>
constexpr uint32_t UIntMaskFirst()

Create a series of a specified number of ones (at compile time) in a uint.

template <>
template<>
constexpr uint32_t UIntMaskFirst<0>()

Create an empty bit mask (all zeros)

constexpr size_t count_bits(uint64_t val)

Count the number of bits in a 64-bit unsigned integer.

constexpr size_t count_bits(uint32_t val)

Count the number of bits in a 32-bit unsigned integer.

constexpr size_t find_bit(const uint64_t &val)

Return the position of the first one bit (in a 64-bit unsigned int)

constexpr size_t find_bit(const uint32_t &val)

Return the position of the first one bit (in a 32-bit unsigned int)

Variables

constexpr size_t ByteCount[256] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8 }

How many bits are set to one in each possible byte?

BitVector

A drop-in replacement for std::vector<bool>, with additional bitwise logic features.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2016-2017
Note
Status: RELEASE

Note
This class is 15-20% slower than emp::BitSet, but more flexible & run-time configurable.

template <>
template<>
struct hash<emp::BitVector>
#include <BitVector.h>

Hash function to allow BitVector to be used with maps and sets (must be in std).

Public Functions

std::size_t operator()(const emp::BitVector &b) const
namespace emp

If we are in emscripten, make sure to include the header.

This file contains extra analysis tools to use with systematics managers that have non-null DATA_TYPES.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

This file contains functions for adding additional data files to Worlds.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

class BitVector
#include <BitVector.h>

A drop-in replacement for std::vector<bool>, but with extra bitwise logic features.

This class stores an arbirary number of bits in a set of “fields” (either 32-bit or 64-bit, depending on which should be faster.) Individual bits can be extracted, -or- bitwise logic (or bit magic) can be used on the groups of bits,

Public Functions

BitVector(size_t in_num_bits = 0, bool init_val = false)

Build a new BitVector with specified bit count (default 0) and initialization (default 0)

BitVector(const BitVector &in_set)

Copy constructor of existing bit field.

BitVector(BitVector &&in_set)

Move constructor of existing bit field.

~BitVector()

Destructor.

BitVector &operator=(const BitVector &in_set)

Assignment operator.

BitVector &operator=(BitVector &&in_set)

Move operator.

BitVector &Resize(size_t new_bits)

Resize this BitVector to have the specified number of bits.

bool operator==(const BitVector &in_set) const

Test if two bit vectors are identical.

bool operator<(const BitVector &in_set) const

Compare the would-be numerical values of two bit vectors.

bool operator<=(const BitVector &in_set) const

Compare the would-be numerical values of two bit vectors.

bool operator!=(const BitVector &in_set) const

Determine if two bit vectors are different.

bool operator>(const BitVector &in_set) const

Compare the would-be numerical values of two bit vectors.

bool operator>=(const BitVector &in_set) const

Compare the would-be numerical values of two bit vectors.

size_t GetSize() const

How many bits do we currently have?

bool Get(size_t index) const

Retrive the bit value from the specified index.

void Set(size_t index, bool value = true)

Update the bit value at the specified index.

std::size_t Hash() const

A simple hash function for bit vectors.

uint8_t GetByte(size_t index) const

Retrive the byte at the specified byte index.

void SetByte(size_t index, uint8_t value)

Update the byte at the specified byte index.

uint32_t GetUInt(size_t index) const

Retrive the 32-bit uint from the specifeid uint index.

void SetUInt(size_t index, uint32_t value)

Update the 32-bit uint at the specified uint index.

uint32_t GetUIntAtBit(size_t index)

Retrive the 32-bit uint at the specified BIT index.

template <size_t OUT_BITS>
field_t GetValueAtBit(size_t index)

Retrieve the specified number of bits (stored in the field type) at the target bit index.

bool Any() const

Return true if ANY bits are set to 1, otherwise return false.

bool None() const

Return true if NO bits are set to 1, otherwise return false.

bool All() const

Return true if ALL bits are set to 1, otherwise return false.

operator bool() const

Casting a bit array to bool identifies if ANY bits are set to 1.

bool operator[](size_t index) const

Const index operator return the bit at the specified position.

BitProxy operator[](size_t index)

Index operator return a proxy to the bit at the specified position so it can be an lvalue.

void Clear()

Set all bits to 0.

void SetAll()

Set all bits to 1.

void Print(std::ostream &out = std::cout) const

Regular print function (from most significant bit to least)

void PrintFields(std::ostream &out = std::cout, const std::string spacer = " ") const

Print a space between each field (or other provided spacer)

void PrintArray(std::ostream &out = std::cout) const

Print from smallest bit position to largest.

void PrintOneIDs(std::ostream &out = std::cout, std::string spacer = " ") const

Print the positions of all one bits, spaces are the default separator.

size_t CountOnes_Sparse() const

Count 1’s by looping through once for each bit equal to 1.

size_t CountOnes_Mixed() const

Count 1’s in semi-parallel; fastest for even 0’s & 1’s.

size_t CountOnes() const

Count the number of ones in the BitVector.

int FindBit() const

Return the position of the first one; return -1 if no ones in vector.

int PopBit()

Return the position of the first one and change it to a zero. Return -1 if no ones.

int FindBit(const size_t start_pos) const

Return the position of the first one after start_pos; return -1 if no ones in vector. You can loop through all 1-bit positions of a BitVector “bv” with:

for (int pos = bv.FindBit(); pos >= 0; pos = bv.FindBit(pos+1)) { … }

emp::vector<size_t> GetOnes() const

Return positions of all ones.

BitVector NOT() const

Perform a Boolean NOT on this BitVector and return the result.

BitVector AND(const BitVector &set2) const

Perform a Boolean AND on this BitVector and return the result.

BitVector OR(const BitVector &set2) const

Perform a Boolean OR on this BitVector and return the result.

BitVector NAND(const BitVector &set2) const

Perform a Boolean NAND on this BitVector and return the result.

BitVector NOR(const BitVector &set2) const

Perform a Boolean NOR on this BitVector and return the result.

BitVector XOR(const BitVector &set2) const

Perform a Boolean XOR on this BitVector and return the result.

BitVector EQU(const BitVector &set2) const

Perform a Boolean EQU on this BitVector and return the result.

BitVector &NOT_SELF()

Perform a Boolean NOT with this BitVector, store result here, and return this object.

BitVector &AND_SELF(const BitVector &set2)

Perform a Boolean AND with this BitVector, store result here, and return this object.

BitVector &OR_SELF(const BitVector &set2)

Perform a Boolean OR with this BitVector, store result here, and return this object.

BitVector &NAND_SELF(const BitVector &set2)

Perform a Boolean NAND with this BitVector, store result here, and return this object.

BitVector &NOR_SELF(const BitVector &set2)

Perform a Boolean NOR with this BitVector, store result here, and return this object.

BitVector &XOR_SELF(const BitVector &set2)

Perform a Boolean XOR with this BitVector, store result here, and return this object.

BitVector &EQU_SELF(const BitVector &set2)

Perform a Boolean EQU with this BitVector, store result here, and return this object.

BitVector SHIFT(const int shift_size) const

Positive shifts go left and negative go right (0 does nothing); return result.

BitVector &SHIFT_SELF(const int shift_size)

Positive shifts go left and negative go right; store result here, and return this object.

BitVector operator~() const

Operator bitwise NOT…

BitVector operator&(const BitVector &ar2) const

Operator bitwise AND…

BitVector operator|(const BitVector &ar2) const

Operator bitwise OR…

BitVector operator^(const BitVector &ar2) const

Operator bitwise XOR…

BitVector operator<<(const size_t shift_size) const

Operator shift left…

BitVector operator>>(const size_t shift_size) const

Operator shift right…

const BitVector &operator&=(const BitVector &ar2)

Compound operator bitwise AND…

const BitVector &operator|=(const BitVector &ar2)

Compound operator bitwise OR…

const BitVector &operator^=(const BitVector &ar2)

Compound operator bitwise XOR…

const BitVector &operator<<=(const size_t shift_size)

Compound operator for shift left…

const BitVector &operator>>=(const size_t shift_size)

Compound operator for shift right…

size_t size() const

Function to allow drop-in replacement with std::vector<bool>.

void resize(std::size_t new_size)

Function to allow drop-in replacement with std::vector<bool>.

bool all() const

Function to allow drop-in replacement with std::vector<bool>.

bool any() const

Function to allow drop-in replacement with std::vector<bool>.

bool none() const

Function to allow drop-in replacement with std::vector<bool>.

size_t count() const

Function to allow drop-in replacement with std::vector<bool>.

Private Types

using field_t = uint64_t

Field sizes are 64 bits in native.

Private Functions

size_t LastBitID() const

End position of the stored bits in the last field; 0 if perfect fit.

size_t NumFields() const

How many feilds do we need?

size_t NumBytes() const

How many bytes are used in the current vector (round up to whole bytes.)

size_t NumSizeFields() const

How many fields would we need if they had the same number of bits as size_t?

void RawCopy(const Ptr<field_t> in_set)

Assume that the size of the bit_set has already been adjusted to be the size of the one being copied and only the fields need to be copied over.

void ShiftLeft(const size_t shift_size)

Helper: call SHIFT with positive number.

void ShiftRight(const size_t shift_size)

Helper for calling SHIFT with negative number.

Private Members

size_t num_bits

How many total bits are we using?

Ptr<field_t> bit_set

What is the status of each bit?

Private Static Functions

static constexpr size_t FieldID(const size_t index)

Identify the field that a specified bit is in.

static constexpr size_t FieldPos(const size_t index)

Identify the position in a field where a specified bit is.

static constexpr size_t Byte2Field(const size_t index)

Identify which field a specified byte position would be in.

static constexpr size_t Byte2FieldPos(const size_t index)

Convert a byte position in BitVector to a byte position in the target field.

Private Static Attributes

constexpr size_t FIELD_BITS = sizeof(field_t)*8

How many bits are in a field?

struct BitProxy

BitProxy lets us use operator[] on with BitVector as an lvalue.

Public Functions

BitProxy(BitVector &_v, size_t _idx)

Setup a new proxy with the associated vector and index.

BitProxy &operator=(bool b)

Assignment operator to the bit associated with this proxy (as an lvalue).

operator bool() const

Conversion of this proxy to Boolean (as an rvalue)

BitProxy &operator&=(bool b)

Compound assignement operator AND using BitProxy as lvalue.

Note
Implemented in BitProxy since it needs to work, but may not be efficient.

BitProxy &operator|=(bool b)

Compound assignement operator OR using BitProxy as lvalue.

Note
Implemented in BitProxy since it needs to work, but may not be efficient.

BitProxy &operator^=(bool b)

Compound assignement operator XOR using BitProxy as lvalue.

Note
Implemented in BitProxy since it needs to work, but may not be efficient.

BitProxy &operator+=(bool b)

Compound assignement operator PLUS using BitProxy as lvalue.

Note
Implemented in BitProxy since it needs to work, but may not be efficient.

BitProxy &operator-=(bool b)

Compound assignement operator MINUS using BitProxy as lvalue.

Note
Implemented in BitProxy since it needs to work, but may not be efficient.

BitProxy &operator*=(bool b)

Compound assignement operator TIMES using BitProxy as lvalue.

Note
Implemented in BitProxy since it needs to work, but may not be efficient.

BitProxy &operator/=(bool b)

Compound assignement operator DIV using BitProxy as lvalue.

Note
Implemented in BitProxy since it needs to work, but may not be efficient.
Note
Never use this function except for consistency in a template since must divide by 1.

Public Members

BitVector &bit_vector

Which BitVector does this proxy belong to?

size_t index

Which position in the bit vector does this proxy point at?

namespace std

Functions

std::ostream &operator<<(std::ostream &out, const emp::BitVector &bit_v)

operator<< to work with ostream (must be in std to work)

template <>
template<>
struct hash<emp::BitVector>
#include <BitVector.h>

Hash function to allow BitVector to be used with maps and sets (must be in std).

Public Functions

std::size_t operator()(const emp::BitVector &b) const

Cache

similar to an std::unordered_map, but all lookups come with a function to generate the result should the lookup fail.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2016-2018
Note
Status: BETA

namespace emp

If we are in emscripten, make sure to include the header.

This file contains extra analysis tools to use with systematics managers that have non-null DATA_TYPES.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

This file contains functions for adding additional data files to Worlds.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

template <class KEY, class T, class HASH = std::hash<KEY>, class PRED = std::equal_to<KEY>, class ALLOC = std::allocator< std::pair<const KEY,T> >>
class Cache
#include <Cache.h>

Public Types

template<>
using key_type = KEY

Type we are using to look up values.

template<>
using mapped_type = T

Contents of the value we look up.

template<>
using hasher = HASH

Hash method to use.

template<>
using key_equal = PRED

Function to test if two values are identical.

template<>
using allocator_type = ALLOC

Function to allocate new space.

Public Functions

Cache()
Cache(const Cache&)
Cache(Cache&&)
Cache &operator=(const Cache&)
Cache &operator=(Cache&&)
size_t size() const

How many entries are stored in the cache?

bool Has(const KEY &k) const

Determine if a specific key is already in the cache.

void Clear()

Erase contents of cache.

void Erase(const KEY &k)

Erase a specific entry from cache.

T Get(KEY k, const std::function<T(KEY k)> &calc_fun)

Lookup a specific key; provide a function to use if value is not in cahce.

const T &GetRef(const KEY &k, const std::function<T(const KEY &k)> &calc_fun)

A version of Get that allows calls with const references instead of pass-by-value.

Private Members

std::unordered_map<KEY, T, HASH, PRED, ALLOC> cache_map

Combinations

Tools to step through combinations of items.

Step through all combinations of size K from a set of N values. For ComboIDs just return the indecies (the specific of the container don’t matter). Other versions will directly wrapper containers.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2017

namespace emp

If we are in emscripten, make sure to include the header.

This file contains extra analysis tools to use with systematics managers that have non-null DATA_TYPES.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

This file contains functions for adding additional data files to Worlds.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

class ComboIDs
#include <combos.h>

Public Functions

ComboIDs(size_t in_max, size_t combo_size)
~ComboIDs()
const emp::vector<size_t> &GetCombo() const
const emp::vector<size_t> &GetMaxCombo() const
size_t GetComboSize() const
size_t GetNumCombos() const
size_t &operator[](const size_t index)
const size_t &operator[](const size_t index) const
const emp::vector<size_t> &Reset()
bool NextCombo()
void ResizeCombos(size_t new_size)
emp::vector<size_t> GetInverseCombo()
ComboIDs &operator++()
ComboIDs &operator++(int)
size_t size()

Private Members

size_t max_count
emp::vector<size_t> cur_combo
emp::vector<size_t> max_combo
size_t num_combos

Private Static Functions

size_t CountCombos(size_t max_count, size_t combo_size)

Constants

Commonly used constant values.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2015-2017
Note
Status: RELEASE

namespace emp

If we are in emscripten, make sure to include the header.

This file contains extra analysis tools to use with systematics managers that have non-null DATA_TYPES.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

This file contains functions for adding additional data files to Worlds.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

Functions

template <typename T>
constexpr T MaxValue()

Determine the maximum value for any type.

template <typename T>
constexpr double InterpolateTable(T &&table, double pos, double tsize)

The following function takes a table and a position [0.0, 1.0) and intepolates a value.

Variables

constexpr const double E = 2.71828

e

constexpr const double PHI = 1.61803398874

Golden ratio.

constexpr const double PI = 3.14159265358979

pi

constexpr const double SQRT2 = 1.41421356237310

sqrt(2)

constexpr const uint32_t MAX_BYTE = 255

(2^8 - 1)

constexpr const uint32_t MAX_2BYTE = 65535

(2^16 - 1)

constexpr const uint32_t MAX_WORD = 65535

(2^16 - 1)

constexpr const uint32_t MAX_3BYTE = 16777215

(2^24 - 1)

constexpr const uint32_t MAX_UINT = 4294967295

(2^32 - 1)

constexpr const uint32_t MAX_4BYTE = 4294967295

(2^32 - 1)

constexpr const int32_t MIN_INT = -2147483648

(- 2^31)

constexpr const double log2_chart_1_2[]

Large table to log base-2 results.

constexpr const double pow2_chart_bits[] = { 1.4142135623730951, 1.1892071150027210, 1.0905077326652577, 1.0442737824274138, 1.0218971486541166, 1.0108892860517005, 1.0054299011128027, 1.0027112750502025, 1.0013547198921082, 1.0006771306930664, 1.0003385080526823, 1.0001692397053021, 1.0000846162726944, 1.0000423072413958, 1.0000211533969647, 1.0000105766425498, 1.0000052883072919, 1.0000026441501502, 1.0000013220742012, 1.0000006610368821, 1.0000003305183864, 1.0000001652591795, 1.0000000826295863, 1.0000000413147923, 1.0000000206573960, 1.0000000103286979, 1.0000000051643489, 1.0000000025821745, 1.0000000012910872, 1.0000000006455436, 1.0000000003227718, 1.0000000001613858 }

Table to provide results of Pow2 for values of bits (0.1, 0.01, 0.001, etc, in binary)

constexpr const double pow2_chart_0_1[]

Table to provide results of Pow2 from 0 to 1.

Debugging Tools

Basic tools for use in developing high-assurance code.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2015-2017
Note
Status: BETA

Defines

BlockRelease(BLOCK)

BlockRelease() will halt compilation if NDEBUG is on. It is useful to include alongside debug print code that you want to remember to remove when you are done debugging.

namespace emp

If we are in emscripten, make sure to include the header.

This file contains extra analysis tools to use with systematics managers that have non-null DATA_TYPES.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

This file contains functions for adding additional data files to Worlds.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

Functions

static void Depricated(const std::string &name, const std::string &desc = "")

Depricated() prints its contents exactly once to notify a user of a depricated function.

Deterministic Finite Automata

A Deterministic Finite Automata simulator.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2016-2017
Note
Status: BETA

namespace emp

If we are in emscripten, make sure to include the header.

This file contains extra analysis tools to use with systematics managers that have non-null DATA_TYPES.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

This file contains functions for adding additional data files to Worlds.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

Typedefs

using emp::DFA = typedef tDFA<128, uint8_t>

Setup DFA to be a simple tDFA with the basic character set for symbols.

template <int NUM_SYMBOLS = 128, typename STOP_TYPE = uint8_t>
class tDFA
#include <DFA.h>

Public Types

template<>
using stop_t = STOP_TYPE

Public Functions

tDFA(size_t num_states = 0)
tDFA(const tDFA<NUM_SYMBOLS, STOP_TYPE>&)
~tDFA()
tDFA<NUM_SYMBOLS, STOP_TYPE> &operator=(const tDFA<NUM_SYMBOLS, STOP_TYPE>&)
size_t GetSize() const

How many states is this DFA using?

void Resize(size_t new_size)

Add Additional empty states.

const emp::array<int, NUM_SYMBOLS> &GetTransitions(size_t from) const

Return an array of all transitions associated with a specified state.

void SetTransition(size_t from, size_t to, size_t sym)

Add a specific transition associated with an input symbol.

void SetStop(size_t state, stop_t stop_val = 1)

Set the stop value (no matter what it currently is)

void AddStop(size_t state, stop_t stop_val = 1)

Set the stop value only if it’s higher than the current stop value.

stop_t GetStop(int state) const

Get the stop value associated with a state.

bool IsActive(int state) const

Test if a state is still valid.

bool IsStop(int state) const

Test if a state has a stop.

stop_t GetStop(size_t state) const
bool IsActive(size_t state) const
bool IsStop(size_t state) const
int Next(int state, size_t sym) const

Return the new state after a symbol occurs.

int Next(int state, std::string sym_set) const

Return the new state after a series of symbols.

stop_t Test(const std::string &str) const

Determine if an entire series of symbols is valid.

void Print(std::ostream &os = std::cout)

Print details about this DFA.

Private Members

emp::vector<emp::array<int, NUM_SYMBOLS>> transitions
emp::vector<STOP_TYPE> is_stop

Dynamic Strings

A string handler where sections update dynamically based on functions.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2016-2017
Note
Status: BETA

namespace emp

If we are in emscripten, make sure to include the header.

This file contains extra analysis tools to use with systematics managers that have non-null DATA_TYPES.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

This file contains functions for adding additional data files to Worlds.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

class DynamicString
#include <DynamicString.h>

A string handler where some sections can be fixed strings, while others update dynamically based on functions.

Public Types

using value_t = std::function<std::string()>

Public Functions

DynamicString()
DynamicString(const DynamicString&)
size_t GetSize() const

How many string components (funcations or continuous substrings) are in this DynamicString?

std::string operator[](size_t id) const

Index in to a specific component (not a specific character, since size is variable) and return it’s associated string.

const value_t &GetFunction(size_t id) const

Index in to a specific component (not a specific character, since size is variable) and return it’s associated function.

DynamicString &Clear()

Remove all contents on this DynamicString.

std::string str()

Convert to an std::string.

DynamicString &Set(size_t id, const value_t &in_fun)

Set the value of a specified component to the provided function.

DynamicString &Set(size_t id, const std::string &in_text)

Set the value of a specified component to the provided std::string text.

DynamicString &Append(const value_t &in_fun)

Add a new function to the end of the DynamicString.

DynamicString &Append(const std::string &in_text)

Add new std::string text to the end of the DynamicString.

template <typename IN_TYPE>
DynamicString &operator<<(IN_TYPE &&_in)

Allow operator<< to append to the back of a DynamicString.

Private Members

emp::vector<value_t> fun_set
namespace std

Functions

std::ostream &operator<<(std::ostream &os, const emp::DynamicString &strings)

Make sure that DynamicString works with with std::ostream.

Errors

Warning

doxygenfile: Cannot find file “tools/errors.h

In-memory Files

The File object maintains a simple, in-memory file.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018
Note
Status: BETA

namespace emp

If we are in emscripten, make sure to include the header.

This file contains extra analysis tools to use with systematics managers that have non-null DATA_TYPES.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

This file contains functions for adding additional data files to Worlds.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

class File
#include <File.h>

A class to maintin files for loading, writing, storing, and easy access to components.

Public Functions

File()
File(std::istream &input)
File(const std::string &filename)
File(const File&)
File(File&&)
~File()
File &operator=(const File&)
File &operator=(File&&)
auto begin() const

Return const iterator to beginning of file.

auto end() const

Return const iterator to end of file.

auto begin()

Return iterator to beginning of file.

auto end()

Return iterator to end of file.

size_t GetNumLines() const

How many lines are in this file?

size_t size() const

Compatibility with size()

std::string &operator[](size_t pos)

Index into a specific line in this file.

const std::string &operator[](size_t pos) const

Const index into a specific line in this file.

std::string &front()

Return the first line in the file.

const std::string &front() const

Return a const reference to to the first line in the file.

std::string &back()

Return the last line in the file.

const std::string &back() const

Return a const reference to the last line in the file.

File &Append(const std::string &line)

Append a new line to the end of the file.

File &Append(const emp::vector<std::string> &in_lines)

Append a vector of lines to the end of the file.

File &Append(const File &in_file)

Join two files.

template <typename T>
File &operator+=(T &&in)

Append to the end of a file.

template <typename T>
auto operator<<(T &&in)

Insert formatted data into file This is exactly the same as operator+=

auto operator>>(std::string &out)

Extract first line from file.

bool operator==(const File in)

Test if two files are identical.

bool operator!=(const File in)

Test if two files are different.

File &LoadLine(std::istream &input)

Load a line from an input stream into a file.

File &Load(std::istream &input)

Load an entire input stream into a file.

File &Load(const std::string &filename)

Load a file from disk using the provided name. If file does not exist, this is a nop

File &Write(std::ostream &output)

Write this file to a provided output stream.

File &Write(const std::string &filename)

Write this file to a file of the provided name.

std::set<std::string> AsSet() const

Convert this file into an std::set of lines (loses line ordering).

File &Apply(const std::function<void(std::string&)> &fun)

Apply a string manipulation function to all lines in the file.

File &KeepIf(const std::function<bool(const std::string&)> &fun)

Purge functions that don’t meet a certain criterion.

File &RemoveEmpty()

Remove all lines that are empty strings.

File &CompressWhitespace()

Any time multiple whitespaces are next to each other, collapse to a single WS char. Prefer ‘ ‘ if in whitespace collapsed, otherwise use ‘ ‘.

File &RemoveWhitespace(bool keep_newlines = true)

Delete all whitespace; by default keep newlines.

File &RemoveComments(const std::string &marker)

A technique to remove all comments in a file.

template <typename T>
emp::vector<T> Process(const std::function<T(std::string&)> &fun)

Run a function on each line of a file and return the restults as a vector. Note: Function is allowed to modify string.

emp::vector<std::string> ExtractCol(char delim = ',')
template <typename T>
emp::vector<T> ExtractColAs(char delim = ',')

Protected Attributes

emp::vector<std::string> lines

Flex Functions

Based on std::function, but holds default parameter values for calls with fewer args.

A collection of broadly-useful functions (that don’t fit elsewhere)

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2016-2017
Note
Status: ALPHA
Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2016-2018
Note
Status: BETA (though new functions are added frequently)

namespace emp

If we are in emscripten, make sure to include the header.

This file contains extra analysis tools to use with systematics managers that have non-null DATA_TYPES.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

This file contains functions for adding additional data files to Worlds.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

template <class R, class... ARGS>
template<>
class flex_function<R(ARGS...)>
#include <flex_function.h>

A functon class that is almost identical to std::function, but is provided with default values for all parameters so that it can be called with fewer arguments, as needed.

Public Types

template<>
using size_t = std::size_t
template<>
using return_t = R
template<>
using fun_t = std::function<R(ARGS...)>
template<>
using this_t = flex_function<R(ARGS...)>
template<>
using tuple_t = std::tuple<ARGS...>

Public Functions

template <typename T>
flex_function(T &&fun_info)
flex_function(const this_t&)
flex_function(this_t&&)
flex_function()
this_t &operator=(const this_t&)
this_t &operator=(this_t&&)
this_t &operator=(const fun_t &_f)
this_t &operator=(fun_t &&_f)
template <typename T>
this_t &operator=(T &&arg)
template <int ID>
void SetDefault(pack_id<ID, ARGS...> &in_default)

Set the default value for a specific parameter.

void SetDefaults(ARGS... args)

Set the default values for all parameters.

return_t operator()(ARGS... k) const

Allow the function to be called with all args.

template <class... IN_ARGS>
return_t operator()(IN_ARGS&&... k) const

All the function to be called with a subset of arguments (and the rest set to defaults)

operator bool() const

Determine whether this function has been set.

Public Static Attributes

constexpr int num_args = sizeof...(ARGS)

Private Members

fun_t fun

Function to be called.

tuple_t default_args

Arguments to be used if not enough are provided in call.

Functions

namespace emp

If we are in emscripten, make sure to include the header.

This file contains extra analysis tools to use with systematics managers that have non-null DATA_TYPES.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

This file contains functions for adding additional data files to Worlds.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

Functions

static double TimeFun(std::function<void()> test_fun)

A function timer that takes a functor an identifies how long it takes to complete when run.

bool Toggle(bool &in_bool)

Toggle an input bool.

constexpr bool AllTrue()

Combine bools to AND them all together.

template <typename... Ts>
bool AllTrue(bool result, Ts... OTHER)
constexpr bool AnyTrue()

Combine bools to OR them all together.

template <typename... Ts>
bool AnyTrue(bool result, Ts... OTHER)
template <typename T>
static emp::vector<T> BuildRange(T min, T max, T step = 1)

Build a vector with a range of values from min to max at the provided step size.

template <typename T, size_t N>
constexpr size_t GetSize(T (&)[N])

Determine the size of a built-in array.

static size_t UniqueVal()

A function that will always return a unique value (and trip an assert if it can’t…)

static std::string UniqueName(const std::string &prefix = "", const std::string &postfix = "")

A function that will always return a unique stringname (using UniqVal) with provided prefix and postfix.)

Function Sets

Setup a collection of functions, all with the same signature, that can be run as a group.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2016-2017
Note
Status: BETA

namespace emp

If we are in emscripten, make sure to include the header.

This file contains extra analysis tools to use with systematics managers that have non-null DATA_TYPES.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

This file contains functions for adding additional data files to Worlds.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

template <typename RETURN_T, typename... ARGS>
template<>
class FunctionSet<RETURN_T(ARGS...)> : public emp::vector<std::function<RETURN_T(ARGS...)>>
#include <FunctionSet.h>

A vector of functions that can all be triggered at onece; results can either be returned in a vector or post-processed in a function (such as max, min, etc.) Derived from emp::vector, hence with all of the same methods as vector.

Public Types

template<>
using base_t = emp::vector<std::function<RETURN_T(ARGS...)>>
template<>
using value_type = typename base_t::value_type
template<>
using return_t = RETURN_T

Public Functions

FunctionSet()
~FunctionSet()
size_t GetSize() const

How many functions are in this FunctionSet?

void Add(const value_type &in_fun)

Add a new funtion to this FunctionSet.

void Remove(size_t pos)

Remove the function at a specified position.

const emp::vector<RETURN_T> &Run(ARGS... args) const

Run all functions and return a vector of all results.

RETURN_T Run(ARGS... args, std::function<RETURN_T(RETURN_T, RETURN_T)> comp_fun, RETURN_T default_val = 0, ) const

If you want to provide a filter function, you can retrieve a specific return value. The filter should take in two return values and indicate which is “better”.

RETURN_T FindMax(ARGS... args, RETURN_T default_val = 0) const

Run all functions and return the highest value.

RETURN_T FindMin(ARGS... args, RETURN_T default_val = 0) const

Run all functions and return the lowest value.

RETURN_T FindSum(ARGS... args, RETURN_T default_val = 0) const

Run all functions and return the total value.

RETURN_T FindProduct(ARGS... args, RETURN_T default_val = 1) const

Run all functions and return a product of all values.

Protected Attributes

emp::vector<RETURN_T> return_vals
template <typename... ARGS>
template<>
class FunctionSet<void(ARGS...)> : public emp::vector<std::function<void(ARGS...)>>
#include <FunctionSet.h>

A specialized version of FunctionSet for void functions.

Public Types

template<>
using base_t = emp::vector<std::function<void(ARGS...)>>
template<>
using value_type = typename base_t::value_type
template<>
using return_t = void

Public Functions

FunctionSet()
~FunctionSet()
size_t GetSize() const

How many functions are in this FunctionSet?

void Add(const std::function<void(ARGS...)> &in_fun)

Add a new function to this FunctionSet.

void Remove(size_t pos)

Remove the function at the designated position from this FunctionSet.

void Run(ARGS... args) const

Run all functions in the FunctionSet.

Generic Functions

Warning

doxygenfile: Cannot find file “tools/GenericFunctions.h

Graph Utilities

This file provides a number of tools for manipulating graphs.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2017
Note
Status: BETA

namespace emp

If we are in emscripten, make sure to include the header.

This file contains extra analysis tools to use with systematics managers that have non-null DATA_TYPES.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

This file contains functions for adding additional data files to Worlds.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

Functions

Graph shuffle_graph(const Graph &in_graph, Random &random)

Take an existing graph, and build a new one that is isomorphic to it, but with randomized vertex IDs.

Graph build_graph_ring(size_t v_count, Random &random)

Construct a graph where all vertics are degree two and form a single ring.

Graph build_graph_tree(size_t v_count, Random &random)

Construct a random tree graph (new vertices are repeatedly attached to a random position in a treee as it is constructed.)

Graph build_graph_random(size_t v_count, size_t e_count, Random &random, bool connected = true)

Construct a random, graph with the specified number of vertices and edges. If connected is set, start by building a tree. Then connect random (unconnected) pairs of vertices until the proper number of edges are included.

Graph build_graph_grid(size_t width, size_t height, Random &random, double prob_use = 1.0)

Construct a graph with width x height vertices setup into a grid structure.

Graph build_graph_clique_set(size_t clique_size, size_t clique_count, Random &random, double extra_prob = 0.5)

Build a set of cliques (such that one member of each can be part of an independent set) and then links them together

Graph build_graph_dag(size_t v_count, size_t e_count, Random &random, bool connected = true)

Construct a random, graph with the specified number of vertices and edges. If connected is set, start by building a tree. Then connect random (unconnected) pairs of vertices until the proper number of edges are included.

WeightedGraph build_weighted_graph_tree(size_t v_count, size_t min_weight, size_t max_weight, Random &random)

Construct a random WEIGHTED tree graph (new vertices are repeatedly attached to a random position in a treee as it is constructed.)

WeightedGraph build_weighted_graph_random(size_t v_count, size_t e_count, size_t min_weight, size_t max_weight, Random &random, bool connected = true)

Construct a random, WEIGHTED graph with the specified number of vertices, edges, and range of edge weights. If connected is set, start by building a tree. Then connect random (unconnected) pairs of vertices until the proper number of edges are included.

Graph load_graph_sym(std::istream &is, bool sub1 = false)

Helper function for loading symetric graphs from an input stream. sub1 indicates that verticies are numbered 1 to N instead of 0 to N-1.

Graph load_graph_sym(std::string filename, bool sub1 = false)

Load a graph with a specified filename.

Graph load_graph_table(std::istream &is)

Load a graph from a connection matrix. Format: #vertices followed by v^2 0’s or 1’s

Graph load_graph_table(std::string filename)

Load a graph from a connection matrix in a file by the specified name.

Graphs

A simple, fast class for managing verticies (nodes) and edges.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2017
Note
Status: BETA

namespace emp

If we are in emscripten, make sure to include the header.

This file contains extra analysis tools to use with systematics managers that have non-null DATA_TYPES.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

This file contains functions for adding additional data files to Worlds.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

class Graph
#include <Graph.h>

A graph class that maintains a set of vertices (nodes) and edges (connecting pairs of nodes)

Subclassed by emp::WeightedGraph

Public Functions

Graph(size_t num_nodes = 0)

Construct a new graph with the specified number of nodes.

Graph(const Graph&)

Copy constructor.

Graph(Graph&&)

Move constructor.

~Graph()
Graph &operator=(const Graph&)

Copy operator.

Graph &operator=(Graph&&)

Move operator.

size_t GetSize() const

Get number of vertices in this graph.

size_t GetEdgeCount() const

Get the total number of edges in this graph.

void Resize(size_t new_size)

Change the number of vertices in this graph.

const BitVector &GetEdgeSet(size_t id) const

Get the set of nodes that a specified node is connected to.

size_t GetDegree(size_t id) const

Get the degree of a specified node.

size_t GetMaskedDegree(size_t id, const BitVector &mask) const

Get how many of a set of nodes that a specified node is connected to.

bool HasEdge(size_t from, size_t to) const

Determine if a specific edge is included in this graph.

void AddEdge(size_t from, size_t to)

Add a specified edge into this graph.

void RemoveEdge(size_t from, size_t to)

Remove a specified edge from this graph.

void SetEdge(size_t from, size_t to, bool val)

Set the status of a specified edge as to whether or not it should be in the graph.

bool HasEdgePair(size_t from, size_t to) const

Determine if edges exist in both directions between a pair of vertices.

void AddEdgePair(size_t from, size_t to)

Add a pair of edges between two vertieces (in both directions)

void RemoveEdgePair(size_t from, size_t to)

Remove edges in both directions between a pair of vertices.

void SetEdgePairs(size_t from, size_t to, bool val)

Set the status as to whether a pair of edges (in both direction) exist.

void Merge(const Graph &in_graph)

Merge a second graph into this one.

void PrintSym(std::ostream &os = std::cout)

Print a symmetric graph to the provided output stream (defaulting to standard out)

void PrintDirected(std::ostream &os = std::cout)

Print a directed graph to the provided output stream (defaulting to standard out)

Protected Attributes

emp::vector<Node> nodes

Set of vertices in this graph.

class Node
#include <Graph.h>

Information about nodes within a graph.

Public Functions

Node(size_t num_nodes)

What other node IDs is this one connected to?

Node(const Node &in_node)
~Node()
Node &operator=(const Node &in_node)

Set this node to have the same connections as another node.

bool HasEdge(size_t to) const

Is this node connect to a specific other node?

void AddEdge(size_t to)

Add a connection between this node and another.

void AddEdgeSet(BitVector in_set)

Add a full set of connections from this node to others.

void RemoveEdge(size_t to)

Remove the connection (if there is one) between this node and another one.

void SetEdge(size_t to, bool val)

Set whether a connection to another specific node should exist or not.

const BitVector &GetEdgeSet() const

Get a BitVector representing which nodes this one is connected to.

void Resize(size_t new_size)

Change the number of potential node connections that we are tracking.

void Clear()

Remove all edges from this node.

size_t GetDegree() const

Identify how many other nodes this one is connected to.

size_t GetMaskedDegree(const BitVector &mask) const

Identify how many other nodes from a provided set (a BitVector) this one is connected to.

Private Members

BitVector edge_set
class WeightedGraph : public emp::Graph
#include <Graph.h>

Public Functions

WeightedGraph(size_t num_nodes = 0)
WeightedGraph(const WeightedGraph&)

Copy constructor.

WeightedGraph(WeightedGraph&&)

Move constructor.

~WeightedGraph()
WeightedGraph &operator=(const WeightedGraph&)

Copy operator.

WeightedGraph &operator=(WeightedGraph&&)

Move operator.

void Resize(size_t new_size)
double GetWeight(size_t from, size_t to) const

Determine weight of a specific edge in this graph.

void AddEdge(size_t from, size_t to, double weight)

When Adding an edge, must also provide a weight.

void AddEdgePair(size_t from, size_t to, double weight)

When Adding an edge pair, must also provide a weight.

void Merge(const WeightedGraph &in_graph)

Merge two WeightedGraphs into one.

void PrintSym(std::ostream &os = std::cout)

Print a symmetric graph to the provided output stream (defaulting to standard out)

void PrintDirected(std::ostream &os = std::cout)

Print a directed graph to the provided output stream (defaulting to standard out)

size_t GetSize() const

Get number of vertices in this graph.

size_t GetEdgeCount() const

Get the total number of edges in this graph.

const BitVector &GetEdgeSet(size_t id) const

Get the set of nodes that a specified node is connected to.

size_t GetDegree(size_t id) const

Get the degree of a specified node.

size_t GetMaskedDegree(size_t id, const BitVector &mask) const

Get how many of a set of nodes that a specified node is connected to.

bool HasEdge(size_t from, size_t to) const

Determine if a specific edge is included in this graph.

void AddEdge(size_t from, size_t to)

Add a specified edge into this graph.

void RemoveEdge(size_t from, size_t to)

Remove a specified edge from this graph.

void SetEdge(size_t from, size_t to, bool val)

Set the status of a specified edge as to whether or not it should be in the graph.

bool HasEdgePair(size_t from, size_t to) const

Determine if edges exist in both directions between a pair of vertices.

void AddEdgePair(size_t from, size_t to)

Add a pair of edges between two vertieces (in both directions)

void RemoveEdgePair(size_t from, size_t to)

Remove edges in both directions between a pair of vertices.

void SetEdgePairs(size_t from, size_t to, bool val)

Set the status as to whether a pair of edges (in both direction) exist.

void Merge(const Graph &in_graph)

Merge a second graph into this one.

Protected Attributes

emp::vector<emp::vector<double>> weights
emp::vector<Node> nodes

Set of vertices in this graph.

Grids

Warning

doxygenfile: Cannot find file “tools/grid.h

Index Map

A simple class to weight items differently within a container and return the correct index.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2015-2018
Note
Status: BETA

namespace emp

If we are in emscripten, make sure to include the header.

This file contains extra analysis tools to use with systematics managers that have non-null DATA_TYPES.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

This file contains functions for adding additional data files to Worlds.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

class IndexMap
#include <IndexMap.h>

A map of weighted indecies. If a random index is selected, the probability of an index being returned is directly proportional to its weight.

Public Functions

IndexMap(size_t _items = 0)

Construct an IndexMap where num_items is the maximum number of items that can be placed into the data structure. All item weigths default to zero.

IndexMap(size_t _items, double init_weight)
IndexMap(const IndexMap&)
IndexMap(IndexMap&&)
~IndexMap()
IndexMap &operator=(const IndexMap&)
IndexMap &operator=(IndexMap&&)
size_t GetSize() const

How many indices are in this map?

double GetWeight() const

What is the total weight of all indices in this map?

double RawWeight(size_t id) const

What is the current weight of the specified index?

double GetWeight(size_t id) const
double RawProb(size_t id) const

What is the probability of the specified index being selected?

double GetProb(size_t id) const
void Resize(size_t new_size, double def_value = 0.0)

Change the number of indecies in the map.

size_t size() const

Standard library compatibility.

void resize(size_t new_size)

Standard library compatibility.

void Clear()

Reset all item weights to zero.

void ResizeClear(size_t new_size)

Change the size of this map AND change all weights to zero.

void RawAdjust(size_t id, const double new_weight)

Adjust the weight associated with a particular index in the map.

Parameters
  • id: is the identification number of the item whose weight is being adjusted.
  • weight: is the new weight for that entry.

void Adjust(size_t id, const double new_weight)
void Adjust(const emp::vector<double> &new_weights)

Adjust all index weights to the set provided.

void AdjustAll(double new_weight)

Adjust all index weights to the set provided.

size_t Index(double index, size_t cur_id = 0) const

Determine the ID at the specified index position.

Proxy operator[](size_t id)

Index into a specified ID.

double operator[](size_t id) const
IndexMap &operator+=(IndexMap &in_map)

Add the weights in another index map to this one.

IndexMap &operator-=(IndexMap &in_map)

Substract the weigthes from another index map from this one.

void DeferRefresh()

Indicate that we need to adjust weights before relying on them in the future; this will prevent refreshes from occuring immediately and is useful when many updates to weights are likely to be done before any are accessed again.

Private Functions

size_t ParentID(size_t id) const

Which ID is the parent of the ID provided?

size_t LeftID(size_t id) const

Which ID is the left child of the ID provided?

size_t RightID(size_t id) const

Which ID is the right child of the ID provided?

size_t CalcZeroOffset() const

Sift through the nodes to find the where index zero maps to.

size_t ToInternalID(size_t id) const
size_t ToInternalID(size_t id, size_t _items, size_t _offset) const
size_t ToExternalID(size_t id) const
void ResolveRefresh() const

Check if we need to do a refresh, and if so do it!

Private Members

size_t num_items

How many items are being stored in this IndexMap?

size_t zero_offset

Position of id zero.

bool needs_refresh

Are tree weights out of date?

emp::vector<double> weights

The total weights in each sub-tree.

class Proxy

A Proxy class so that an index can be treated as an l-value.

Public Functions

Proxy(IndexMap &_im, size_t _id)
operator double() const
Proxy &operator=(double new_weight)

Private Members

IndexMap &index_map

Which index map is this proxy from?

size_t id

Which id does it represent?

Information Theory Tools

namespace emp

If we are in emscripten, make sure to include the header.

This file contains extra analysis tools to use with systematics managers that have non-null DATA_TYPES.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

This file contains functions for adding additional data files to Worlds.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

Functions

template <typename CONTAINER>
double Entropy(const CONTAINER &weights)

Convert a vector of weights to probabilities and return the entropy of the system.

template <typename CONTAINER, typename WEIGHT_FUN>
double Entropy(const CONTAINER &objs, WEIGHT_FUN fun, double total = 0.0)

Calculate the entropy in a container of arbitrary objects. Args are a container, a function to extract the weight of each member, and an (optional) total weight.

constexpr double Entropy2(const double p)

Calculate the entropy when their are two possibile states based on one state’s probability.

template <typename CONTAINER, typename CAT_FUN_X, typename CAT_FUN_Y, typename WEIGHT_FUN>
double Entropy(const CONTAINER &objs, CAT_FUN_X funX, CAT_FUN_Y funY, WEIGHT_FUN funW)

Conitional Entropy: H(X|Y) Allow for entropy of arbitrary objects with a converter.

Lexer Utilities

A set of utilities to convert between NFAs and DFAs.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2016-2017
Note
Status: BETA

namespace emp

If we are in emscripten, make sure to include the header.

This file contains extra analysis tools to use with systematics managers that have non-null DATA_TYPES.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

This file contains functions for adding additional data files to Worlds.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

Functions

static const DFA &to_DFA(const DFA &dfa)

Converting DFA to DFA no change needed.

static const NFA &to_NFA(const NFA &nfa)

Converting NFA to MFA no change needed.

static DFA to_DFA(const NFA &nfa, int keep_invalid = false)

Systematic conversion of NFA to DFA…

static NFA to_NFA(const DFA &dfa)

Systematic up-conversion of DFA to NFA…

template <typename T1>
static NFA MergeNFA(T1 &&in)

Merge multiple automata into one NFA (base case, single converstion)

template <typename T1, typename T2, typename... Ts>
static NFA MergeNFA(T1 &&in1, T2 &&in2, Ts&&... others)

Merge multiple automata (DFA, NFA, RegEx) into one NFA.

template <typename T1, typename T2, typename... Ts>
static DFA MergeDFA(T1 &&in1, T2 &&in2, Ts&&... others)

Merge multiple automata (DFA, NFA, RegEx) into one DFA.

std::string FindExample(const DFA &dfa, const size_t min_size = 1)

Method to find an example string that satisfies a DFA.

struct DFAStatus
#include <lexer_utils.h>

Structure to track the current status of a DFA.

Public Functions

DFAStatus(size_t _state, const std::string &_seq)

Public Members

size_t state
std::string sequence

Lexer

A general-purpose, fast lexer.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2016-2017
Note
Status: BETA

namespace emp

If we are in emscripten, make sure to include the header.

This file contains extra analysis tools to use with systematics managers that have non-null DATA_TYPES.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

This file contains functions for adding additional data files to Worlds.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

class Lexer
#include <Lexer.h>

A lexer with a set of token types (and associated regular expressions)

Public Functions

Lexer()
~Lexer()
size_t GetNumTokens() const

How many types of tokens can be identified in this Lexer?

size_t AddToken(const std::string &in_name, const std::string &in_regex)

Add a new token, specified by a name and the regex used to identify it.

size_t GetTokenID(const std::string &name) const

Get the ID associated with a token type (you provide the token name)

std::string GetTokenName(size_t id) const

Get the name associated with a token type (you provide the ID)

TokenInfo GetTokenInfo(const std::string &name) const

Get the full information about a token (you provide the name)

void Generate() const

Create the NFA that will identify the current set of tokens in a sequence.

Token Process(std::istream &is)

Get the next token found in an input stream.

Token Process(std::string &in_str)

Shortcut to process a string rather than a stream.

const std::string &GetLexeme()

Get the lexeme associated with the last token identified.

void Print(std::ostream &os = std::cout) const

Print the full information about this lexer (for debugging)

Public Static Functions

static bool TokenOK(size_t id)
static constexpr size_t MaxTokenID()

How many total token types are allowed in this lexer?

Public Static Attributes

const size_t MAX_TOKEN_ID = 256
const size_t ERROR_ID = MAX_TOKEN_ID

Private Members

emp::vector<TokenInfo> token_set

List of all active tokens.

size_t cur_token_id

Which ID should the next new token get?

bool generate_lexer

Do we need to regenerate the lexer?

DFA lexer_dfa

Table driven lexer implementation.

std::string lexeme

Current state of lexeme being generated.

struct Token
#include <Lexer.h>

Information about a token instance from an input stream.

Public Functions

Token(size_t id, const std::string &str = "")
Token(const Token&)
Token &operator=(const Token&)
operator size_t()

Token will automatically convert to its ID if used as an unsigned int.

operator const std::string&()

Token will automatically convert to its matched sequence (lexeme) is used as a string.

Public Members

size_t token_id

Which type of token is this?

std::string lexeme

The specific sequence matched by this token.

struct TokenInfo
#include <Lexer.h>

Information about an individual token type to be processed within a Lexer.

Public Functions

TokenInfo(const std::string &n, const std::string &r, size_t i, bool s = false)
TokenInfo(const TokenInfo&)
TokenInfo &operator=(const TokenInfo&)
void Print(std::ostream &os = std::cout) const

Print out the status of this token (for debugging)

Public Members

std::string name

Name of this token type.

RegEx regex

Pattern to describe token type.

size_t id

Unique id for token.

bool save_lexeme

Should we preserve the lexeme for this token?

Map Utilities

A set of simple functions to manipulate maps.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2016-2017
Note
Status: BETA

namespace emp

If we are in emscripten, make sure to include the header.

This file contains extra analysis tools to use with systematics managers that have non-null DATA_TYPES.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

This file contains functions for adding additional data files to Worlds.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

Functions

template <class MAP_T, class KEY_T>
bool Has(const MAP_T &in_map, const KEY_T &key)

Take any map type, and run find to determine if a key is present.

template <class MAP_T, class KEY_T>
auto Find(const MAP_T &in_map, const KEY_T &key, const typename MAP_T::mapped_type &dval)

Take any map, run find() member function, and return the result found (or default value if no results found).

template <class MAP_T, class KEY_T>
const auto &FindRef(const MAP_T &in_map, const KEY_T &key, const typename MAP_T::mapped_type &dval)

Take any map and element, run find() member function, and return a reference to the result found (or default value if no results found).

template <typename A, typename B>
constexpr std::pair<B, A> flip_pair(const std::pair<A, B> &p)

Take an std::pair<A,B> and return the flipped pair std::pair<B,A>

template <typename A, typename B>
std::multimap<B, A> flip_map(const std::map<A, B> &src)

Take an std::map<A,B> and return the flipped map (now multimap to be safe): std::multimap<B,A>

Math

Useful mathematical functions (that are constexpr when possible.)

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2016-2018
Note
Status: BETA (though new functions are added frequently)

namespace emp

If we are in emscripten, make sure to include the header.

This file contains extra analysis tools to use with systematics managers that have non-null DATA_TYPES.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

This file contains functions for adding additional data files to Worlds.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

Functions

constexpr int Mod(int in_val, int mod_val)

% is actually remainder; Mod is a proper modulus command that handles negative #’s correctly

double Mod(double in_val, double mod_val)

Regular Mod doesn’t work on doubles. Build one that does!

template <typename T>
int Sgn(T val)

Calculate the sign (i.e., +1, -1, or 0) of a value.

template <typename T>
constexpr T Abs(T in)

Find the absolute value for any variable.

int FloorDivide(int dividend, int divisor)

Divide one integer by another, rounding towards minus infinity.

int RoundedDivide(int dividend, int divisor)

Default integer division is truncated, not rounded. Round the division result instead of truncating it. Rounding ties (i.e., result % divisor == 0.5) are rounded up.

size_t RoundedDivide(size_t dividend, size_t divisor)

Default integer division is truncated, not rounded. Round the division result instead of truncating it. Rounding ties (i.e., result % divisor == 0.5) will be rounded up.

int UnbiasedDivide(int dividend, int divisor, emp::Random &r)

Regular integer division is truncated, not rounded. Round the division result instead of truncating it. Rounding ties (i.e., result % divisor == 0.5) are broken by coin toss.

size_t UnbiasedDivide(size_t dividend, size_t divisor, emp::Random &r)

Regular integer division is truncated, not rounded. Round the division result instead of truncating it. Rounding ties (i.e., result % divisor == 0.5) are broken by coin toss.

template <typename TYPE>
constexpr TYPE ToRange(const TYPE &value, const TYPE &in_min, const TYPE &in_max)

Run both min and max on a value to put it into a desired range.

template <typename T>
constexpr T Min(T in1)

Min of only one element is that element itself!

template <typename T, typename... Ts>
constexpr T Min(T in1, T in2, Ts... extras)

Min of multiple elements is solved recursively.

template <typename T>
constexpr T Max(T in1)

Max of only one element is that element itself!

template <typename T, typename... Ts>
constexpr T Max(T in1, T in2, Ts... extras)

Max of multiple elements is solved recursively.

template <typename T>
constexpr const T &MinRef(const T &in1)

MinRef works like Min, but never copies any inputs; always treats as references. MinRef of only one element returns reference to that element itself!

template <typename T, typename... Ts>
constexpr const T &MinRef(const T &in1, const T &in2, const Ts&... extras)

MinRef of multiple elements returns reference to minimum value.

template <typename T>
constexpr const T &MaxRef(const T &in1)

MaxRef works like Max, but never copies any inputs; always treats as references. MaxRef of only one element returns reference to that element itself!

template <typename T, typename... Ts>
constexpr const T &MaxRef(const T &in1, const T &in2, const Ts&... extras)

MaxRef of multiple elements returns reference to maximum value.

static constexpr double Log2(double x)

Compile-time log base 2 calculator.

static constexpr double Log(double x, double base = 10.0)

Compile-time log calculator.

static constexpr double Ln(double x)

Compile-time natural log calculator.

static constexpr double Log10(double x)

Compile-time log base 10 calculator.

template <typename T>
static constexpr T Square(T val)

A simple function to square a value.

template <typename T>
static constexpr type_if<T, std::is_integral> Pow(T base, T p)

A fast (O(log p)) integral-power command.

static constexpr double Pow2(double exp)

A fast 2^x command.

template <typename TYPE>
static constexpr TYPE IntPow(TYPE base, TYPE exp)

A fast method for calculating exponents for int types.

static constexpr double Pow(double base, double exp)

A fast method for calculating exponents on doubles.

static constexpr double Exp(double exp)

A fast method of calculating e^x.

template <typename TYPE>
static constexpr int IntLog2(TYPE x)

A compile-time int-log calculator (aka, significant bits)

template <typename TYPE>
static constexpr int CountOnes(TYPE x)

A compile-time bit counter.

template <typename TYPE>
static constexpr TYPE MaskLow(std::size_t num_bits)

Quick bit-mask generator for low bits.

template <typename TYPE>
static constexpr TYPE MaskHigh(std::size_t num_bits)

Quick bit-mask generator for high bits.

template <typename T>
constexpr const T &Min(const T &in1, const T &in2, const T &in3)

Return the minimum of three values.

template <typename T>
const T &Min(std::initializer_list<const T&> lst)

A version of Min that allows a variable number of inputs to be compared.

template <typename T>
const T &Max(std::initializer_list<const T&> lst)

A version of Max that allows a variable number of inputs to be compared.

namespace internal

Functions

static constexpr double Log2_base(double x)
static constexpr double Log2_frac(double x)
static constexpr double Log2_pos(double x)
static constexpr double Pow2_lt1(double exp, int id = 0)
static constexpr double Pow2_impl(double exp)

Memory Tracking

A set of macros to track how many instances of specific classes are made.

One way of tracking memory leaks is to simply count instances of classes. The macros here simplify this process.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2015-2017
Note
Status: BETA

To setup, every constructor for a class must incude EMP_TRACK_CONSTRUCT(CLASS_NAME), and every destructor must have EMP_TRACK_DESTRUCT(CLASS_NAME). Make sure to avoid implicit constructors/destructors or counts will be off.

To collect information, EMP_TRACK_COUNT(CLASS_NAME) will provide the current count for a specific class, and EMP_TRACK_STATUS will translate into a string providing information about all available classes.

Developer notes:

namespace emp

If we are in emscripten, make sure to include the header.

This file contains extra analysis tools to use with systematics managers that have non-null DATA_TYPES.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

This file contains functions for adding additional data files to Worlds.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

namespace internal

Functions

static std::map<std::string, int> &TrackMem_GetMap()
static std::string TrackMem_Status()
static void TrackMem_Inc(const std::string &class_name)
static void TrackMem_Dec(const std::string &class_name)
static int TrackMem_Count(const std::string &class_name)

Memoized Functions

Warning

doxygenfile: Cannot find file “tools/memo_functions.h

Non-Deterministic Finite Automata

A Non-deterministic Finite Automata simulator.

To build a standard NFA, use emp::NFA. If you want to have more symbols or more stop states, use emp::tNFA<S,T> where S is the number of symbols and T is the type used for stop. (defaults are 128 for ASCII-128 and uint8_t respectively.)

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2016-2017
Note
Status: BETA

The constructor can take as parameters the number of states and the id of the start state (both default to 0)

Note
DFA’s use SetTransition(), but NFA’s use AddTransition. This distinction is intentional since in a DFA a second SetTransition with the same start state and symbol will override first, while in an NFA a second AddTransition will always add a new option.

namespace emp

If we are in emscripten, make sure to include the header.

This file contains extra analysis tools to use with systematics managers that have non-null DATA_TYPES.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

This file contains functions for adding additional data files to Worlds.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

Typedefs

using emp::NFA = typedef tNFA<128, uint8_t>

NFA is the most standard tNFA setup.

using emp::NFA_State = typedef tNFA_State<128, uint8_t>

NFA_State is the most standard tNFA_State setup.

template <size_t S = 128, typename STOP_TYPE = uint8_t>
class tNFA
#include <NFA.h>

A dynamic NFA class, for easily building non-determanistic finite automata.

Public Types

template<>
using opts_t = BitSet<NUM_SYMBOLS>
template<>
using stop_t = STOP_TYPE

Public Functions

tNFA(size_t num_states = 1, size_t start_state = 0)
tNFA(const tNFA<S, STOP_TYPE>&)
~tNFA()
tNFA<S, STOP_TYPE> &operator=(const tNFA<S, STOP_TYPE>&)
size_t GetSize() const

Return the current number of states.

const std::set<size_t> &GetStart() const

Return start state and all others reachable through empty transitions.

std::set<size_t> GetNext(size_t sym, size_t from_id = 0) const

Return the states reachable from the current state given the provided symbol.

std::set<size_t> GetNext(size_t sym, const std::set<size_t> from_set) const

return the states reachable from the current set of states given the provided symbol.

bool HasFreeTransitions(size_t id) const

Does the provided state have free transitions?

bool HasSymTransitions(size_t id) const

Does the provided state have symbol-transitions?

opts_t GetSymbolOptions(const std::set<size_t> &test_set) const

Return an emp::BitSet indicating the symbols available from the provided set of states.

void Resize(size_t new_size)

Change the number of available states.

size_t AddNewState()

Add a new state into the NFA and return its id.

void AddTransition(size_t from, size_t to, size_t sym)

Add a transition between states ‘from’ and ‘to’ that can be taken with the provided symbol.

void AddTransition(size_t from, size_t to, const std::string &sym_set)

Add a transition between states ‘from’ and ‘to’ that can be taken with the provided symbols.

void AddTransition(size_t from, size_t to, const BitSet<NUM_SYMBOLS> &sym_set)

Add a transition between states ‘from’ and ‘to’ that can be taken with the provided symbols.

void AddFreeTransition(size_t from, size_t to)

Create a free transition between ‘from’ and ‘to’.

template <typename T = stop_t>
void SetStop(size_t state, T stop_val = 1)

Set the specified state to be a stop state (with an optional stop value.)

stop_t GetStop(size_t state) const

Get any stop value associated with the provided state.

bool IsStart(size_t state) const

Test if NFA begins at provided state (may have free transitions to other states)

bool IsStop(size_t state) const

Test if this state is a legal endpoint for the NFA.

bool IsEmpty(size_t state) const

Test if this state has only empty transitions from it, and not stop state.

void Merge(const tNFA<NUM_SYMBOLS, STOP_TYPE> &nfa2)

Merge another NFA into this one.

void Print() const

Print information about this NFA (for debugging)

void PrintFreeMoves()

Identify free moves in NFA (for debugging)

Public Static Attributes

constexpr const size_t NUM_SYMBOLS = S

Private Members

emp::vector<State> states

Information about available states.

size_t start

Main start state (others might be reached for free.)

emp::vector<STOP_TYPE> is_stop

0=no 1=yes (char instead of bool for speed)

struct State

Public Functions

template<>
State()

Public Members

template<>
std::map<size_t, Transition> trans

What symbol transitions are available?

template<>
std::set<size_t> free_to

What other states can you move to for free?

template<>
std::set<size_t> free_from

What other states can move here for free?

struct Transition

Public Functions

template<>
Transition()

Public Members

template<>
opts_t symbols
template <size_t NUM_SYMBOLS = 128, typename STOP_TYPE = uint8_t>
class tNFA_State
#include <NFA.h>

Information about the current full state (i.e., set of legal states) of an NFA.

Public Functions

tNFA_State(const tNFA<NUM_SYMBOLS, STOP_TYPE> &_nfa)
~tNFA_State()
const tNFA<NUM_SYMBOLS, STOP_TYPE> &GetNFA() const

Get the NFA associated with this state.

const std::set<size_t> &GetStateSet() const

Get a set of states that are currently active.

bool IsActive() const

Are there currently any legal NFA states?

bool IsStop() const

Can we legally stop in any of the current states?

bool HasState(size_t id)

Is a particular NFA state currently included?

size_t GetSize()

How many states are currently included?

void SetStateSet(const std::set<size_t> &in)

Set the current states.

void Reset()

Change current states to start + free transitions from start.

void Next(size_t sym)

Update states given a new input symbol.

void Next(const std::string &sym_set)

Update states given a new series of input symbols (as a string)

void Print()

Print out current information about this NFA State (for debugging)

Private Members

const tNFA<NUM_SYMBOLS, STOP_TYPE> &nfa

Which NFA is this state set associated with?

std::set<size_t> state_set

Which states are currently legal?

Parser

A general-purpose, fast parser.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2016-2017
Note
Status: DEVELOPMENT

namespace emp

If we are in emscripten, make sure to include the header.

This file contains extra analysis tools to use with systematics managers that have non-null DATA_TYPES.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

This file contains functions for adding additional data files to Worlds.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

class Parser
#include <Parser.h>

Full information about a parser, including a lexer, symbols, and rules.

Public Functions

Parser(Lexer &in_lexer)
~Parser()
Lexer &GetLexer()
size_t GetID(size_t id) const

Trivial conversions of ID to ID…

size_t GetID(const std::string &name)

Converstion of a symbol name to its ID.

std::string GetName(size_t symbol_id) const

Conversion ot a sybol ID to its name.

Parser &operator()(const std::string &name)

Provide a symbol to the compiler and set it as active.

ParseSymbol &GetParseSymbol(const std::string &name)

Get the parser symbol information associated with a provided name.

template <typename... STATES>
Parser &Rule(STATES... states)

Use the currently active symbol and attach a rule to it.

template <typename... STATES>
size_t AddRule(const std::string &name, STATES&&... states)

Specify the name of the symbol and add a rule to it, returning the symbol id.

void Process(std::istream &is, bool test_valid = true)

Convert an input stream into a parse tree (TO FINISH!)

void Print(std::ostream &os = std::cout) const

Print the current status of this parser (for debugging)

Private Functions

void BuildRule(emp::vector<size_t> &new_pattern)
template <typename T, typename... EXTRAS>
void BuildRule(emp::vector<size_t> &new_pattern, T &&arg, EXTRAS&&... extras)
int GetSymbolPos(const std::string &name) const

Return the position in the symbols vector where this name is found; else return -1.

int GetIDPos(size_t id) const

Convert a symbol ID into its position in the symbols[] vector.

size_t AddSymbol(const std::string &name)

Create a new symbol and return its POSITION.

Private Members

Lexer &lexer

Default input lexer.

emp::vector<ParseSymbol> symbols

Set of symbols that make up this grammar.

emp::vector<ParseRule> rules

Set of rules that make up the parser.

size_t cur_symbol_id

Which id should the next new symbol get?

int active_pos

Which symbol pos is active?

struct ParseSymbol
#include <Parser.h>

A single symbol in a grammer including the patterns that generate it.

Public Functions

ParseSymbol()

Public Members

std::string name

Unique name for this parse symbol.

emp::vector<size_t> rule_ids

Which rules apply to this symbol?

size_t id

What is the unique ID of this symbol?

emp::BitVector first

What tokens can begin this symbol?

emp::BitVector follow

What tokens can come after this symbol?

bool nullable

Can this symbol be converted to nothing?

Random-Access Set

This file defines a Random Access Set template.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2017
Note
Status: ALPHA

namespace emp

If we are in emscripten, make sure to include the header.

This file contains extra analysis tools to use with systematics managers that have non-null DATA_TYPES.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

This file contains functions for adding additional data files to Worlds.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

template <typename T>
class ra_set
#include <ra_set.h>

This class uses a combination of a hashtable (std::unordered_map) and emp::vector to lookup insert, lookup, and delete values in constant time, while still being able to step through all values (albeit in an arbitrary order).

Note
The arbitrary order of values may change if any values are deleted.

Public Types

template<>
using value_type = T

Public Functions

ra_set()
ra_set(const ra_set&)
ra_set(ra_set&&)
ra_set<T> &operator=(const ra_set&)
ra_set<T> &operator=(ra_set&&)
bool empty() const

Are there any values in this ra_set?

size_t size() const

How many elements are in this set?

const T &operator[](size_t pos) const

Index into the ra_set, similar to a vector.

void clear()

Remove all values from this container.

void insert(const T &v)

Insert a new value into container.

bool erase(const T &v)

Erase a specific value from the container.

size_t count(const T &v) const

Count the number of times a particular value in in the container (0 or 1).

Private Members

std::map<T, size_t> id_map

A map of where to find values in vector.

emp::vector<T> vals

A vector of all values contained.

Randomness Utilites

Helper functions for emp::Random for common random tasks.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2016-2017
Note
Status: RELEASE

namespace emp

If we are in emscripten, make sure to include the header.

This file contains extra analysis tools to use with systematics managers that have non-null DATA_TYPES.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

This file contains functions for adding additional data files to Worlds.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

Functions

template <typename T>
void Shuffle(Random &random, emp::vector<T> &v, size_t max_count)

Randomly reorder all of the elements in a vector. If max_count is provided, just make sure that the first max_count entries are randomly drawn from entire vector.

template <typename T>
void Shuffle(Random &random, emp::vector<T> &v)
emp::vector<size_t> GetPermutation(Random &random, size_t size)

Return an emp::vector<int> numbered 0 through size-1 in a random order.

void Choose(Random &random, size_t N, size_t K, std::vector<size_t> &choices)

Choose K positions from N possibilities.

std::vector<size_t> Choose(Random &random, size_t N, size_t K)
BitVector RandomBitVector(Random &random, size_t size, double p = 0.5)

Generate a random BitVector of the specified size.

emp::vector<double> RandomDoubleVector(Random &random, size_t size, double min, double max)

Generate a random double vector in the specified range.

emp::vector<size_t> RandomUIntVector(Random &random, size_t size, size_t min, size_t max)

Generate a random size_t vector in the specified range.

template <typename T>
emp::vector<T> RandomVector(Random &random, size_t size, T min, T max)

Generate a random vector in the specified type and range.

void RandomizeBitVector(BitVector &bits, Random &random, double p = 0.5)

Generate a random BitVector of the specified size.

template <typename T>
void RandomizeVector(emp::vector<T> &vals, Random &random, T min, T max)

Generate a random vector in the specified type and range.

Random Number Generator

A versatile and non-patterned pseudo-random-number generator.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2015-2018
Note
Status: RELEASE

namespace emp

If we are in emscripten, make sure to include the header.

This file contains extra analysis tools to use with systematics managers that have non-null DATA_TYPES.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

This file contains functions for adding additional data files to Worlds.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

Range

A simple way to track value ranges.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2016-2018
Note
Status: BETA

namespace emp

If we are in emscripten, make sure to include the header.

This file contains extra analysis tools to use with systematics managers that have non-null DATA_TYPES.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

This file contains functions for adding additional data files to Worlds.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

Functions

template <typename T>
Range<T> MakeRange(T _l, T _u)

Build a new range with auto-detected type.

Range<int> IntRange(int _l, int _u)

Build a new range of type int.

Range<double> DRange(double _l, double _u)

Build a new range of type double.

template <typename T>
class Range
#include <Range.h>

A range of values from a lower limit to and upper limit, of any provided type.

Public Functions

Range()
Range(T _l, T _u)
T GetLower() const
T GetUpper() const
size_t CalcBin(T value, size_t num_bins) const
Range &operator=(const Range&)
bool operator==(const Range &_in) const
bool operator!=(const Range &_in) const
void SetLower(T l)
void SetUpper(T u)
void Set(T _l, T _u)
void SetMaxLower()
void SetMaxUpper()
bool Valid(T value) const

Determine if a provided value is in the range.

T Limit(T _in) const

Force a value into range.

emp::vector<T> Spread(size_t s) const

Produce a vector that spreads values evenly across the range.

Private Members

T lower

Beginning of range, inclusive.

T upper

End of range, inclusive.

Regular Expressions

Basic regular expression handler.

A fully (well, mostly) functional regular expression processor.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2016-2017
Note
Status: BETA

Special chars: ‘|’ - or ‘*’ - zero or more of previous ‘+’ - one or more of previous ‘?’ - previous is optional ‘.’ - Match any character except Pluse the following group contents (and change may translation rules) ‘(‘ and ‘)’ - group contents ‘”’ - Ignore special characters in contents (quotes still need to be escaped) ‘[‘ and ‘]’ - character set choose ONE character ^ as first char negates contents ; - indicates range UNLESS first or last.

Additional overloads for functions in lexer_utils.h:

static NFA to_NFA(const RegEx & regex, int stop_id=1); static DFA to_DFA(const RegEx & regex);

namespace emp

If we are in emscripten, make sure to include the header.

This file contains extra analysis tools to use with systematics managers that have non-null DATA_TYPES.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

This file contains functions for adding additional data files to Worlds.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

Functions

static NFA to_NFA(const RegEx &regex, size_t stop_id = 1)

Simple conversion of RegEx to NFA (mostly implemented in RegEx)

static DFA to_DFA(const RegEx &regex)

Conversion of RegEx to DFA, via NFA intermediate.

class RegEx
#include <RegEx.h>

A basic regular expression handler.

Public Functions

RegEx()
RegEx(const std::string &r)
RegEx(const RegEx &r)
~RegEx()
RegEx &operator=(const RegEx &r)

Set this RegEx equal to another.

std::string AsString() const

Convert the RegEx to an standard string, readable from outsite this class.

void AddToNFA(NFA &nfa, size_t start, size_t stop) const

Add this regex to an NFA being built.

void Generate() const

Assume the RegEx is ready and setup processing for it.

bool Test(const std::string &str) const

Test if a string statisfies this regex.

void PrintInternal()

For debugging: print the internal representation of the regex.

void PrintNotes()

For debugging: print any internal notes generated about this regex.

void PrintDebug()

Print general debuging information about this regex.

Private Types

using opts_t = BitSet<NUM_SYMBOLS>

Private Functions

template <typename... T>
void Error(T&&... args)
bool EnsureNext(char x)

Make sure that there is another element in the RegEx (e.g., after an ‘|’) or else trigger and error to report the problem.

Ptr<re_charset> ConstructSet()

Construct a character range.

Ptr<re_string> ConstructString()

Construct a string, loading everything needed.

Ptr<re_base> ConstructSegment()

Should only be called when we know we have a single unit to produce. Build and return it.

Ptr<re_block> Process(Ptr<re_block> cur_block = nullptr)

Process the input regex into a tree representaion.

Private Members

std::string regex

Original string to define this RegEx.

emp::vector<std::string> notes

Any warnings or errors would be provided here.

bool valid

Set to false if regex cannot be processed.

size_t pos

Position being read in regex.

DFA dfa

DFA that this RegEx translates to.

bool dfa_ready

Is the dfa ready? (or does it need to be generated?)

re_block head

Private Static Attributes

constexpr size_t NUM_SYMBOLS = 128

Maximum number of symbol the RegEx can handle.

struct re_base

Internal base representation of a portion of a regex.

Public Functions

virtual ~re_base()
virtual void Print(std::ostream &os) const
virtual Ptr<re_block> AsBlock()
virtual Ptr<re_charset> AsCharSet()
virtual Ptr<re_parent> AsParent()
virtual Ptr<re_string> AsString()
virtual size_t GetSize() const
virtual bool Simplify()
virtual void AddToNFA(NFA &nfa, size_t start, size_t stop) const
struct re_block : public emp::RegEx::re_parent

Representation of a series of components…

Public Functions

void Print(std::ostream &os) const
Ptr<re_block> AsBlock()
bool Simplify()
virtual void AddToNFA(NFA &nfa, size_t start, size_t stop) const
void Clear()
virtual void push(Ptr<re_base> x)
Ptr<re_base> pop()
size_t GetSize() const
Ptr<re_parent> AsParent()
virtual Ptr<re_charset> AsCharSet()
virtual Ptr<re_string> AsString()

Protected Attributes

emp::vector<Ptr<re_base>> nodes
struct re_charset : public emp::RegEx::re_base

Representation of a character set e.g., [abc].

Public Functions

re_charset()
re_charset(char x, bool neg = false)
re_charset(const std::string &s, bool neg = false)
void Print(std::ostream &os) const
Ptr<re_charset> AsCharSet()
size_t GetSize() const
char First() const
virtual void AddToNFA(NFA &nfa, size_t start, size_t stop) const
virtual Ptr<re_block> AsBlock()
virtual Ptr<re_parent> AsParent()
virtual Ptr<re_string> AsString()
virtual bool Simplify()

Public Members

opts_t char_set
struct re_or : public emp::RegEx::re_parent

Representation of two options in a regex, e.g., a|b.

Public Functions

re_or(Ptr<re_base> l, Ptr<re_base> r)
void Print(std::ostream &os) const
virtual void AddToNFA(NFA &nfa, size_t start, size_t stop) const
void Clear()
virtual void push(Ptr<re_base> x)
Ptr<re_base> pop()
size_t GetSize() const
Ptr<re_parent> AsParent()
bool Simplify()
virtual Ptr<re_block> AsBlock()
virtual Ptr<re_charset> AsCharSet()
virtual Ptr<re_string> AsString()

Protected Attributes

emp::vector<Ptr<re_base>> nodes
struct re_parent : public emp::RegEx::re_base

Intermediate base class for RegEx components that have children (such as “and” and “or”)

Public Functions

re_parent()
~re_parent()
void Clear()
virtual void push(Ptr<re_base> x)
Ptr<re_base> pop()
size_t GetSize() const
Ptr<re_parent> AsParent()
bool Simplify()
virtual void Print(std::ostream &os) const
virtual Ptr<re_block> AsBlock()
virtual Ptr<re_charset> AsCharSet()
virtual Ptr<re_string> AsString()
virtual void AddToNFA(NFA &nfa, size_t start, size_t stop) const

Protected Attributes

emp::vector<Ptr<re_base>> nodes
struct re_plus : public emp::RegEx::re_parent

Representations of one-or-more instances of a component. e.g., a+.

Public Functions

re_plus(Ptr<re_base> c)
void Print(std::ostream &os) const
virtual void AddToNFA(NFA &nfa, size_t start, size_t stop) const
void Clear()
virtual void push(Ptr<re_base> x)
Ptr<re_base> pop()
size_t GetSize() const
Ptr<re_parent> AsParent()
bool Simplify()
virtual Ptr<re_block> AsBlock()
virtual Ptr<re_charset> AsCharSet()
virtual Ptr<re_string> AsString()

Protected Attributes

emp::vector<Ptr<re_base>> nodes
struct re_qm : public emp::RegEx::re_parent

Representations of zero-or-one instances of a component. e.g., a?

Public Functions

re_qm(Ptr<re_base> c)
void Print(std::ostream &os) const
virtual void AddToNFA(NFA &nfa, size_t start, size_t stop) const
void Clear()
virtual void push(Ptr<re_base> x)
Ptr<re_base> pop()
size_t GetSize() const
Ptr<re_parent> AsParent()
bool Simplify()
virtual Ptr<re_block> AsBlock()
virtual Ptr<re_charset> AsCharSet()
virtual Ptr<re_string> AsString()

Protected Attributes

emp::vector<Ptr<re_base>> nodes
struct re_star : public emp::RegEx::re_parent

Representations of zero-or-more instances of a component. e.g., a*.

Public Functions

re_star(Ptr<re_base> c)
void Print(std::ostream &os) const
virtual void AddToNFA(NFA &nfa, size_t start, size_t stop) const
void Clear()
virtual void push(Ptr<re_base> x)
Ptr<re_base> pop()
size_t GetSize() const
Ptr<re_parent> AsParent()
bool Simplify()
virtual Ptr<re_block> AsBlock()
virtual Ptr<re_charset> AsCharSet()
virtual Ptr<re_string> AsString()

Protected Attributes

emp::vector<Ptr<re_base>> nodes
struct re_string : public emp::RegEx::re_base

Representation of strings stored in a RegEx.

Public Functions

re_string()
re_string(char c)
re_string(const std::string &s)
void Print(std::ostream &os) const
Ptr<re_string> AsString()
size_t GetSize() const
virtual void AddToNFA(NFA &nfa, size_t start, size_t stop) const
virtual Ptr<re_block> AsBlock()
virtual Ptr<re_charset> AsCharSet()
virtual Ptr<re_parent> AsParent()
virtual bool Simplify()

Public Members

std::string str

Sequence Utilities

Functions for analyzing with generic sequence types.

A set of functions for analyzing sequences, including distance metrics (Hamming and Edit/Levenschtein) and alignment.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2016-2017
Note
Status: BETA

namespace emp

If we are in emscripten, make sure to include the header.

This file contains extra analysis tools to use with systematics managers that have non-null DATA_TYPES.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

This file contains functions for adding additional data files to Worlds.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

Functions

template <typename TYPE>
size_t calc_hamming_distance(const TYPE &in1, const TYPE &in2, int offset = 0)

Hamming distance is a simple count of substitutions needed to convert one array to another.

Parameters
  • in1: The first sequence to compare.
  • in2: The second sequence to compare.
  • offset: (optional) Position in the first sequence to start the second sequence.

template <typename TYPE>
size_t calc_edit_distance(const TYPE &in1, const TYPE &in2)

Edit distance is the minimum number of insertions, deletions and substitutions to convert one array to another.

template <typename TYPE, typename GAP_TYPE>
size_t align(TYPE &in1, TYPE &in2, GAP_TYPE gap)

Use edit distance to find the minimum number of insertions, deletions and substitutions to convert one array to another, and then insert gaps into the arrays appropriately.

Serialization Macros

Macros for simplifying to serialization of objects.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2015-2017
Note
Status: ALPHA

Serialization Tools

Tools to save and load data from classes.

All of the important information about a class is stored in a DataPod, which can be used to restore the class at a later time.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2015-2017
Note
Status: ALPHA

Why is this better than other serialization techniques?

  1. Only one line of code is added to a custom class to make it serializable.
  2. Serialized objects do not need a default constructor (a DataPod constructor is added)
  3. Serialized objects can be const since they get rebuilt during construction.
  4. Synergistic interactions with other EMP classes, such as config and tuple_struct

In order to setup a target class to be able to be serialized into a pod, you must add a macro to include the needed functionality. For a basic class, use:

EMP_SETUP_DATAPOD(ClassName, var1, var2, …)

Where ClassName is the target class’ name and var1, var2, etc are the names of the member variables that also need to be stored. Note that member variables can either be either built-in types or custom types that have also had DataPods setup in them.

If the target class is a derived class, you must use either:

EMP_SETUP_DATAPOD_D(ClassName, BassClassName, var1, var2, …)

-or-

EMP_SETUP_DATAPOD_D2(ClassName, BassClass1Name, BaseClass2Name, var1, var2, …)

…depending on how many base classes it was derived from (currently max 2).

Note also that this macro must either go in the public section of the target class definition, or the target class must be made a friend to the emp::serialize::DataPod class.

namespace emp

If we are in emscripten, make sure to include the header.

This file contains extra analysis tools to use with systematics managers that have non-null DATA_TYPES.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

This file contains functions for adding additional data files to Worlds.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

namespace serialize

Functions

template <typename T>
auto StoreVar(DataPod &pod, const T &var, bool)

StoreVar() takes a DataPod and a variable and stores that variable to the pod. The third argument (bool vs. int) will receive a bool, and thus bool versions are preferred in the case of a tie. Specialized versions of this function can be included elsewhere, as needed, and should take a bool as the third argument.

template <typename T>
void StoreVar(DataPod &pod, const emp::vector<T> &var, bool)
template <typename T>
void StoreVar(DataPod &pod, const T &var, int)
template <typename T>
auto SetupLoad(DataPod &pod, T *, bool)
template <typename T>
auto SetupLoad(DataPod &pod, const T *, int)
std::string SetupLoad(DataPod &pod, std::string *, bool)
template <typename T>
emp::vector<T> SetupLoad(DataPod &pod, emp::vector<T> *, bool)
template <typename... ARG_TYPES>
void Store(DataPod &pod, ARG_TYPES&... args)
class DataPod
#include <serialize.h>

A DataPod managed information about another class for serialization.

Public Functions

DataPod(std::ostream &_os, std::istream &_is)
DataPod(std::iostream &_ios)
DataPod(DataPod &&rhs)
DataPod &operator=(DataPod &&rhs)
DataPod()
DataPod(const DataPod&)
~DataPod()
std::ostream &OStream()
std::istream &IStream()

Protected Functions

void ClearData()

Protected Attributes

std::ostream *os
std::istream *is
bool own_os
bool own_is
namespace internal
template <typename FIRST_TYPE, typename... OTHER_TYPES>
template<>
struct serial_impl<FIRST_TYPE, OTHER_TYPES...>
#include <serialize.h>

Public Static Functions

static void Store(DataPod &pod, FIRST_TYPE &arg1, OTHER_TYPES&... others)
template <>
template<>
struct serial_impl<>
#include <serialize.h>

Public Static Functions

static void Store(DataPod&)

Set Utilities

Tools to save and load data from classes.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2016-2018
Note
Status: ALPHA

namespace emp

If we are in emscripten, make sure to include the header.

This file contains extra analysis tools to use with systematics managers that have non-null DATA_TYPES.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

This file contains functions for adding additional data files to Worlds.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

Functions

template <typename T>
void insert(std::set<T> &s1, const std::set<T> &s2)

Insert the full contents of s2 into s1.

template <typename T, typename H>
bool Has(const std::set<T, H> &s, const T &val)

Test if an std::set has a particular element without modifying the set in any way.

template <typename T, typename H>
bool Has(const std::multiset<T, H> &s, const T &val)

Test if an std::multiset has a particular element without modifying the set in any way.

template <typename T, typename H>
bool Has(const std::unordered_set<T, H> &s, const T &val)

Test if an std::unordered_set has a particular element without modifying the set in any way.

template <typename T, typename H>
bool Has(const std::unordered_multiset<T, H> &s, const T &val)

Test if an std::unordere_multiset has a particular element without modifying the set in any way.

template <typename T>
std::set<T> difference(std::set<T> &s1, std::set<T> &s2)

Compute the set difference of.

Parameters
  • s1: and
  • s2: (elements that are in S1 but no S2)

template <typename T>
std::set<T> difference(emp::vector<T> s1, emp::vector<T> &s2)

Compute the set difference of.

Parameters
  • s1: and
  • s2: (elements that are in S1 but no S2)

template <typename T>
std::set<T> difference(std::set<T> &s1, emp::vector<T> s2)

Compute the set difference of.

Parameters
  • s1: and
  • s2: (elements that are in S1 but not S2)

template <typename T>
std::set<T> difference(emp::vector<T> s1, std::set<T> &s2)

Compute the set difference of.

Parameters
  • s1: and
  • s2: (elements that are in S1 but no S2)

template <typename T>
std::set<T> intersection(std::set<T> s1, std::set<T> s2)

Compute the set intersection of.

Parameters
  • s1: and
  • s2: (elements that are in both S1 and S2)

template <typename T>
std::set<T> intersection(emp::vector<T> s1, emp::vector<T> s2)

Compute the set intersection of.

Parameters
  • s1: and
  • s2: (elements that are in both S1 and S2)

template <typename T>
std::set<T> intersection(std::set<T> s1, emp::vector<T> s2)

Compute the set intersection of.

Parameters
  • s1: and
  • s2: (elements that are in both S1 and S2)

template <typename T>
std::set<T> intersection(emp::vector<T> s1, std::set<T> s2)

Compute the set intersection of.

Parameters
  • s1: and
  • s2: (elements that are in both S1 and S2)

template <typename T>
std::set<T> set_union(std::set<T> s1, std::set<T> s2)

Compute the set union of.

Parameters
  • s1: and
  • s2: (elements that are in either S1 or S2)

template <typename T>
std::set<T> set_union(emp::vector<T> s1, emp::vector<T> s2)

Compute the set union of.

Parameters
  • s1: and
  • s2: (elements that are in either S1 or S2)

template <typename T>
std::set<T> set_union(std::set<T> s1, emp::vector<T> s2)

Compute the set union of.

Parameters
  • s1: and
  • s2: (elements that are in either S1 or S2)

template <typename T>
std::set<T> set_union(emp::vector<T> s1, std::set<T> s2)

Compute the set union of.

Parameters
  • s1: and
  • s2: (elements that are in either S1 or S2)

template <typename T>
std::set<T> symmetric_difference(std::set<T> s1, std::set<T> s2)

Compute the set symmetric_difference of.

Parameters
  • s1: and
  • s2: (elements that are in either S1 or S2 but not both)

template <typename T>
std::set<T> symmetric_difference(emp::vector<T> s1, emp::vector<T> s2)

Compute the set symmetric_difference of.

Parameters
  • s1: and
  • s2: (elements that are in either S1 or S2 but not both)

template <typename T>
std::set<T> symmetric_difference(std::set<T> s1, emp::vector<T> s2)

Compute the set symmetric_difference of.

Parameters
  • s1: and
  • s2: (elements that are in either S1 or S2 but not both)

template <typename T>
std::set<T> symmetric_difference(emp::vector<T> s1, std::set<T> s2)

Compute the set symmetric_difference of.

Parameters
  • s1: and
  • s2: (elements that are in either S1 or S2 but not both)

Branch and Bound Solution States

Used as part of a branching solver to keep track of the current state.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2016-2017
Note
Status: BETA

namespace emp

If we are in emscripten, make sure to include the header.

This file contains extra analysis tools to use with systematics managers that have non-null DATA_TYPES.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

This file contains functions for adding additional data files to Worlds.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

class SolveState
#include <SolveState.h>

Often in a branch-and-bound algorithm, we need to identify the sub-set of items that maximizes (or minimizes) an optimization metric. SolveState keeps track of the current state for which items have been locked in as “included” in the current branks, which have been “excluded”, and which are still “unknown” (still to be decided upon.) All tracking is performed with BitVectors for high efficiency.

Public Functions

SolveState(size_t state_size = 0)
SolveState(const SolveState &in)
~SolveState()
SolveState &operator=(const SolveState &in)

Set this SolveState to be identical to another.

size_t GetSize() const

How many items are being considered in the current SolveState?

bool IsIn(size_t id) const

Test if a particular item is going to be included for sure in the current solve state. (If it has been excluded -OR- is yet to be decided upon, false will be returned)

bool IsUnk(size_t id) const

Test if a particular item is yet to be decided upon in the current solve state. (If it has been excluded -OR- is included for sure, false will be returned)

bool IsOut(size_t id) const

Test if a particular item is going to be excluded for sure in the current solve state. (If it has been included -OR- is yet to be decided upon, false will be returned)

bool IsFinal() const

Test if all items have been decided upon (none are still in the “unknown” state)

size_t CountIn() const

How many items have been included for sure?

size_t CountUnk() const

How many items have yet to be decided upon (are “unknown”)

size_t CountOut() const

How many items have been excluded for sure.

const BitVector &GetInVector() const

Get the BitVector associated with which items have been included for sure.

const BitVector &GetUnkVector() const

Get the BitVector associated with which items have yet to be decided upon.

BitVector GetOutVector() const

Get the BitVector associated with which iterm have been excluded for sure.

int GetNextUnk(size_t prev_unk) const

Get the ID of the next unknown item.

void Include(size_t id)

Mark a specific item as to be included.

void Exclude(size_t id)

Mark a specific item as to be excluded.

void ForceExclude(size_t id)

Change our mind about a potentially included node (Be careful since many algorithms don’t requite this type of changes to be made.)

void IncludeSet(const BitVector &inc_set)

Include ALL of the items specified in the provided BitVector.

void ExcludeSet(const BitVector &inc_set)

Exclude ALL of the items specified in the provided BitVector.

Private Members

BitVector in_items

Items included for sure.

BitVector unk_items

Items yet to be decided on.

Statistics Tools

Functions for calculating various statistics about an ensemble.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2016-2017
Note
Status: BETA

namespace emp

If we are in emscripten, make sure to include the header.

This file contains extra analysis tools to use with systematics managers that have non-null DATA_TYPES.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

This file contains functions for adding additional data files to Worlds.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

Functions

template <typename C>
std::enable_if<!emp::is_ptr_type<typename C::value_type>::value && std::is_scalar<typename C::value_type>::value, typename C::value_type>::type Sum(C &elements)

Calculate sum of the members of the container passed Only works on containers with a scalar member type

template <typename C>
std::enable_if<emp::is_ptr_type<typename C::value_type>::value && std::is_scalar<typename emp::remove_ptr_type<typename C::value_type>::type >::value, typename emp::remove_ptr_type<typename C::value_type>::type>::type Sum(C &elements)

Calculate sum of the values pointed at by pointers in a container Only works on containers of pointers to a scalar type

template <typename C>
std::enable_if<!emp::is_ptr_type<typename C::value_type>::value, double>::type ShannonEntropy(C &elements)

Calculate Shannon Entropy of the members of the container passed.

template <typename C>
std::enable_if<emp::is_ptr_type<typename C::value_type>::value, double>::type ShannonEntropy(C &elements)

Calculate Shannon Entropy of the members of the container when those members are pointers.

template <typename C>
std::enable_if<!emp::is_ptr_type<typename C::value_type>::value && std::is_scalar<typename C::value_type>::value, double>::type Variance(C &elements)

Calculate variance of the members of the container passed Only works on containers with a scalar member type

template <typename C>
std::enable_if<emp::is_ptr_type<typename C::value_type>::value && std::is_scalar<typename emp::remove_ptr_type<typename C::value_type>::type >::value, double>::type Variance(C &elements)

Calculate variance of the values pointed at by members of the container passed Only works on containers with a scalar member type

template <typename C>
emp::sfinae_decoy<double, typename C::value_type> Mean(C &elements)

Calculate the mean of the values in a container If values are pointers, they will be automatically de-referenced Values must be numeric.

template <typename C>
emp::sfinae_decoy<double, typename C::value_type> StandardDeviation(C &elements)

Calculate the standard deviation of the values in a container If values are pointers, they will be automatically de-referenced Values must be numeric.

template <typename C>
std::enable_if<!emp::is_ptr_type<typename C::value_type>::value, int>::type UniqueCount(C &elements)

Count the number of unique elements in a container.

template <typename C>
std::enable_if<emp::is_ptr_type<typename C::value_type>::value, int>::type UniqueCount(C &elements)

Count the number of unique elements in the container of pointers. (compares objects pointed to; pointers do not have to be identical)

template <typename C, typename RET_TYPE, typename ARG_TYPE>
RET_TYPE MaxResult(std::function<RET_TYPE(ARG_TYPE)> &fun, C &elements, )

Run the provided function on every member of a container and return the MAXIMUM result.

template <typename C, typename RET_TYPE, typename ARG_TYPE>
RET_TYPE MinResult(std::function<RET_TYPE(ARG_TYPE)> &fun, C &elements, )

Run the provided function on every member of a container and return the MINIMUM result.

template <typename C, typename RET_TYPE, typename ARG_TYPE>
std::enable_if<std::is_scalar<RET_TYPE>::value, double>::type MeanResult(std::function<RET_TYPE(ARG_TYPE)> &fun, C &elements, )

Run the provided function on every member of a container and return the AVERAGE result. Function must return a scalar (i.e. numeric) type.

template <typename C, typename RET_TYPE, typename ARG_TYPE>
emp::vector<RET_TYPE> ApplyFunction(std::function<RET_TYPE(ARG_TYPE)> &fun, C &elements, )

Run the provided function on every member of a container and return a vector of ALL results.

String Utilities

Simple functions to manipulate strings.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2016-2018
Note
Status: RELEASE

namespace emp

If we are in emscripten, make sure to include the header.

This file contains extra analysis tools to use with systematics managers that have non-null DATA_TYPES.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

This file contains functions for adding additional data files to Worlds.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

Functions

static const std::string &empty_string()

Return a const reference to an empty string. This function is useful to implement other functions that need to return a const reference for efficiency, but also need a null response.

static std::string to_escaped_string(char value)

Convert a single chararcter to one that uses a proper escape sequence (in a string) if needed.

static std::string to_escaped_string(const std::string &value)

Convert a full string to one that uses proper escape sequences, as needed.

template <typename LIT_TYPE>
std::string to_literal(const LIT_TYPE &value)

Take a value and convert it to a C++-style literal.

static std::string to_literal(char value)

Take a char and convert it to a C++-style literal.

static std::string to_literal(const std::string &value)

Take a string and convert it to a C++-style literal.

static std::string to_upper(std::string value)

Convert a string to all uppercase.

static std::string to_lower(std::string value)

Convert a string to all lowercase.

static std::string to_roman_numeral(int val, const std::string &prefix = "")
bool is_whitespace(char test_char)

Determine if a character is whitespace.

bool is_upper_letter(char test_char)

Determine if a character is an uppercase letter.

bool is_lower_letter(char test_char)

Determine if a character is a lowercase letter.

bool is_letter(char test_char)

Determine if a character is a letter of any kind.

bool is_digit(char test_char)

Determine if a character is a digit.

bool is_alphanumeric(char test_char)

Determine if a character is a letter or digit.

bool is_idchar(char test_char)

Determine if a character is a letter, digit, or underscore.

static bool is_one_of(char test_char, const std::string &char_set)

Determine if a character is in a set of characters (represented as a string)

static bool is_composed_of(const std::string &test_str, const std::string &char_set)

Determine if a string is composed only of a set of characters (represented as a string)

bool has_whitespace(const std::string &test_str)

Determine if there is whitespace anywhere in a string.

bool has_upper_letter(const std::string &test_str)

Determine if there are any uppercase letters in a string.

bool has_lower_letter(const std::string &test_str)

Determine if there are any lowercase letters in a string.

bool has_letter(const std::string &test_str)

Determine if there are any letters in a string.

bool has_digit(const std::string &test_str)

Determine if there are any digits in a string.

bool has_alphanumeric(const std::string &test_str)

Determine if there are any letters or digits anywhere in a string.

bool has_idchar(const std::string &test_str)

Determine if there are any letters, digit, or underscores anywhere in a string.

static bool has_one_of(const std::string &test_str, const std::string &char_set)

Determine if a specified set of characters appears anywhere in a string.

bool is_valid(char test_char)

If no functions are provided to is_valid(), always return false as base case.

template <typename... FUNS>
bool is_valid(char test_char, std::function<bool(char)> fun1, FUNS... funs, )

Determine if a character passes any of the test functions provided.

template <typename... FUNS>
static bool is_valid(const std::string &test_str, FUNS... funs)

For a string to be valid, each character must pass at least one provided function.

static std::string string_pop_fixed(std::string &in_string, std::size_t end_pos, size_t delim_size = 0)

Pop a segment from the beginning of a string as another string, shortening original.

static std::string string_get_range(const std::string &in_string, std::size_t start_pos, std::size_t end_pos)

Get a segment from the beginning of a string as another string, leaving original untouched.

std::string string_pop(std::string &in_string, const char delim = ' ')

Remove a prefix of the input string (up to a specified delimeter) and return it. If the delimeter is not found, return the entire input string and clear it.

std::string string_get(const std::string &in_string, const char delim, size_t start_pos = 0)

Return a prefix of the input string (up to a specified delimeter), but do not modify it. If the delimeter is not found, return the entire input string.

std::string string_pop(std::string &in_string, const std::string &delim_set)

Remove a prefix of the input string (up to any of a specified set of delimeters) and return it. If the delimeter is not found, return the entire input string and clear it.

std::string string_get(const std::string &in_string, const std::string &delim_set, size_t start_pos = 0)

Return a prefix of the input string (up to any of a specified set of delimeters), but do not modify it. If the delimeter is not found, return the entire input string.

std::string string_pop_word(std::string &in_string)

Remove a prefix of a string, up to the first whitespace, and return it.

std::string string_get_word(const std::string &in_string, size_t start_pos = 0)

Return a prefix of a string, up to the first whitespace (do not modify the original string)

std::string string_pop_line(std::string &in_string)

Remove a prefix of a string, up to the first newline, and return it.

std::string string_get_line(const std::string &in_string, size_t start_pos = 0)

Return a prefix of a string, up to the first newline (do not modify the original string)

std::string left_justify(std::string &in_string)

Remove all whitespace at the beginning of a string. Return the whitespace removed.

void right_justify(std::string &in_string)

Remove all whitespace at the end of a string.

static void remove_chars(std::string &in_string, std::string chars)

Remove instances of characters from file.

static void compress_whitespace(std::string &in_string)

Every time one or more whitespace characters appear replace them with a single space.

static void remove_whitespace(std::string &in_string)

Remove all whitespace from anywhere within a string.

static void remove_punctuation(std::string &in_string)

Remove all characters from a string except letters, numbers, and whitespace.

static void slice(const std::string &in_string, emp::vector<std::string> &out_set, char delim = 'n')

Cut up a string based on the provided delimitor; fill them in to the provided vector.

static emp::vector<std::string> slice(const std::string &in_string, char delim = 'n')

Slice a string without passing in result vector (may be less efficient).

template <typename... ALL_TYPES>
std::string to_string(ALL_TYPES&&... all_values)

This function does its very best to convert everything it’s to a string. Takes any number of arguments and returns a single string containing all of them concatenated. Objects can be any normal (POD) data type, container, or anything that can be passed into a stringstream.

template <typename T>
T from_string(const std::string &str)

This function tries to convert a string into any type you’re looking for… You just need to specify the out type as the template argument.

template <typename... Ts>
void from_string(const std::string &str, Ts&... args)

The from_string() function can also take multiple args instead of a return.

template <typename T>
emp::vector<T> from_strings(const emp::vector<std::string> &string_v)

The from_strings() function takes a vector of strings and convets them into a vector of the appropriate type.

namespace internal

Functions

static void _from_string(std::stringstream&)
template <typename T, typename... Ts>
void _from_string(std::stringstream &ss, T &arg1, Ts... extra_args)

Tuple Struct

Tuple Utilities

Functions to simplify the use of std::tuple.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2016-2018
Note
Status: RELEASE

namespace emp

If we are in emscripten, make sure to include the header.

This file contains extra analysis tools to use with systematics managers that have non-null DATA_TYPES.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

This file contains functions for adding additional data files to Worlds.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

Functions

template <typename TUPLE_T>
constexpr int tuple_size()

Quick way to calculate tuple size.

template <typename... Ts, int... Ps>
auto shuffle_tuple(const std::tuple<Ts...> &tup, IntPack<Ps...>)

Reorganize the entries in tuple; the provided int pack must specify the new ordering.

template <typename FUN_T, typename TUPLE_T, int... N>
auto ApplyTuple(const FUN_T &fun, const TUPLE_T &tup, IntPack<N...>)

Apply a tuple as arguments to a function, where all argument positions in function are specified with and IntPack

template <typename FUN_T, typename TUPLE_T>
auto ApplyTuple(const FUN_T &fun, const TUPLE_T &tup)

Apply a tuple as arguments to a function, in order.

template <typename TUPLE_T, typename FUN_T>
void TupleIterate(TUPLE_T &tup, const FUN_T &fun)

Call a provided function on each element of a tuple.

template <typename TUP1_T, typename TUP2_T, typename FUN_T>
void TupleIterate(TUP1_T &tup1, TUP2_T &tup2, const FUN_T &fun)

Call a provided function on each pair of elements in two tuples.

template <typename... TYPES>
struct TupleHash
#include <tuple_utils.h>

Setup tuples to be able to be used in hash tables.

Public Types

template<>
using tuple_t = std::tuple<TYPES...>
template<>
using fun_t = std::function<std::size_t(TYPES...)>

Public Functions

std::size_t operator()(const tuple_t &tup) const
namespace internal
template <typename TUP1_T, typename TUP2_T, typename FUN_T, size_t TOT, size_t POS>
struct TupleIterate2_impl
#include <tuple_utils.h>

Public Static Functions

static void Run(TUP1_T &tup1, TUP2_T &tup2, const FUN_T &fun)
template <typename TUP1_T, typename TUP2_T, typename FUN_T, size_t END_POS>
template<>
struct TupleIterate2_impl<TUP1_T, TUP2_T, FUN_T, END_POS, END_POS>
#include <tuple_utils.h>

Public Static Functions

static void Run(TUP1_T&, TUP2_T&, const FUN_T&)
template <typename TUPLE_T, typename FUN_T, size_t TOT, size_t POS>
struct TupleIterate_impl
#include <tuple_utils.h>

Public Static Functions

static void Run(TUPLE_T &tup, const FUN_T &fun)
template <typename TUPLE_T, typename FUN_T, size_t END_POS>
template<>
struct TupleIterate_impl<TUPLE_T, FUN_T, END_POS, END_POS>
#include <tuple_utils.h>

Public Static Functions

static void Run(TUPLE_T &tup, const FUN_T &fun)

Type Tracker

Track class types abstractly to dynamically call correct function overloads.

TypeTracker is a templated class that must be declared with all of the types that can possibly be tracked. For example:

emp::TypeTracker<int, std::string, double> tt;
Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2016-2018
Note
Status: BETA

…would create a TypeTracker that can manage the three types listed and convert back.

namespace emp

If we are in emscripten, make sure to include the header.

This file contains extra analysis tools to use with systematics managers that have non-null DATA_TYPES.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

This file contains functions for adding additional data files to Worlds.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

struct TrackedInfo_Base
#include <TypeTracker.h>

The proxy base class of any type to be tracked.

Subclassed by emp::TrackedInfo_Value< REAL_T, ID >

Public Functions

virtual size_t GetTypeID() const = 0
virtual ~TrackedInfo_Base()
virtual emp::Ptr<TrackedInfo_Base> Clone() const = 0
template <typename REAL_T, size_t ID>
struct TrackedInfo_Value : public emp::TrackedInfo_Base
#include <TypeTracker.h>

TrackedInfo_Value store both the real type and an ID for it (to be identified from the base class for each conversion back.)

Public Types

template<>
using real_t = REAL_T
template<>
using this_t = TrackedInfo_Value<REAL_T, ID>

Public Functions

TrackedInfo_Value(const REAL_T &in)
TrackedInfo_Value(REAL_T &&in)
TrackedInfo_Value(const TrackedInfo_Value&)
TrackedInfo_Value(TrackedInfo_Value&&)
TrackedInfo_Value &operator=(const TrackedInfo_Value&)
TrackedInfo_Value &operator=(TrackedInfo_Value&&)
size_t GetTypeID() const
emp::Ptr<TrackedInfo_Base> Clone() const

Build a copy of this TrackedInfo_Value; recipient is in charge of deletion.

Public Members

REAL_T value
struct TrackedVar
#include <TypeTracker.h>

The actual TrackedVar object that manages a Ptr to the value.

Public Functions

TrackedVar(emp::Ptr<TrackedInfo_Base> _ptr)
TrackedVar(const TrackedVar &_in)

Copy constructor; use judiciously since it copies the contents!

TrackedVar(TrackedVar &&_in)

Move constructor takes control of the pointer.

~TrackedVar()

Cleanup ptr on destruct.

TrackedVar &operator=(const TrackedVar &_in)

Move assignment hands over control of the pointer.

TrackedVar &operator=(TrackedVar &&_in)

Move assignment hands over control of the pointer.

size_t GetTypeID() const

Public Members

emp::Ptr<TrackedInfo_Base> ptr
template <typename... TYPES>
class TypeTracker
#include <TypeTracker.h>

Dynamic functions that are indexed by parameter types; calls lookup the correct function to forward arguments into.

Public Types

template<>
using this_t = TypeTracker<TYPES...>
template<>
using wrap_t = TrackedInfo_Value<REAL_T, get_type_index<REAL_T, TYPES...>()>
template<>
using var_decoy = TrackedVar

var_decoy converts any variable into a TrackedVar (used to have correct number of vars)

Public Functions

TypeTracker()
TypeTracker(const TypeTracker&)
TypeTracker(TypeTracker&&)
TypeTracker &operator=(const TypeTracker&)
TypeTracker &operator=(TypeTracker&&)
~TypeTracker()
template <typename... Ts>
this_t &AddFunction(std::function<void(Ts...)> fun)

Add a new std::function that this TypeTracker should call if the appropriate types are passed in.

template <typename... Ts>
this_t &AddFunction(void (*fun)(Ts...))

Add a new function pointer that this TypeTracker should call if the appropriate types are passed in.

template <typename LAMBDA_T>
this_t &AddFunction(const LAMBDA_T &fun)

Add a new lambda function that this TypeTracker should call if the appropriate types are passed in.

template <typename... Ts>
void RunFunction(Ts&&... args)

Run the appropriate function based on the argument types received.

template <typename... Ts>
void operator()(Ts&&... args)

Call TypeTracker as a function (refers call to RunFunction)

Public Static Functions

static constexpr size_t GetNumTypes()

How many types are we working with?

static constexpr size_t GetNumCombos(size_t vals = 2)

How many combinations of V types are there?

static constexpr size_t GetCumCombos(size_t vals = 2)

How many combinations are the of the given number of types OR FEWER?

template <typename T>
static constexpr size_t GetID()

Each type should have a unique ID.

template <typename T1, typename T2, typename... Ts>
static constexpr size_t GetID()

Each set of types should have an ID unique within that number of types.

template <typename... Ts>
static constexpr size_t GetComboID()

A ComboID should be unique across all size combinations.

static size_t GetTrackedID(const TrackedVar &tt)

A Tracked ID is simply the unique ID of the type being tracked.

template <typename... Ts>
static size_t GetTrackedID(const TrackedVar &tt1, const TrackedVar &tt2, const Ts&... ARGS)

Or set of types being tracked…

template <typename... Ts>
static constexpr size_t GetTrackedComboID(const Ts&... ARGS)

A tracked COMBO ID, is an ID for this combination of types, unique among all possible type combinations. Consistent with GetComboID with the same underlying types.

template <typename REAL_T>
static TrackedVar Convert(const REAL_T &val)

Convert an input value into a TrackedInfo_Value maintaining the value (universal version)

template <typename TEST_T>
static bool IsType(TrackedVar &tt)

Test if the tracked type is TEST_T.

template <typename REAL_T>
static REAL_T ToType(TrackedVar &tt)

Convert the tracked type back to REAL_T. Assert that this is type safe!

template <typename OUT_T>
static OUT_T Cast(TrackedVar &tt)

Cast the tracked type to OUT_T. Try to do so even if NOT original type!

Protected Attributes

std::unordered_map<size_t, Ptr<emp::GenericFunction>> fun_map

fun_map is a hash table that maps a set of inputs to the appropriate function.

Unit Testing

Warning

doxygenfile: Cannot find file “tools/unit_tests.h

Vector Utilities

A set of simple functions to manipulate emp::vector.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2017-2018
Note
Status: BETA

namespace emp

If we are in emscripten, make sure to include the header.

This file contains extra analysis tools to use with systematics managers that have non-null DATA_TYPES.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

This file contains functions for adding additional data files to Worlds.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2018

Functions

template <typename T>
int FindValue(const emp::vector<T> &v, const T &val, size_t start_pos = 0)

Return the first position of a value in a vector (or -1 if none exists)

template <typename T>
bool RemoveValue(emp::vector<T> &v, const T &val, size_t start_pos = 0)

Remove the first value after start_pos with a given value. Return if removal successful.

template <typename T>
bool Has(const emp::vector<T> &v, const T &val)

Return whether a value exists in a vector.s.

template <typename T>
void Print(const emp::vector<T> &v, std::ostream &os = std::cout, const std::string &spacer = " ")

Print the contects of a vector.

template <typename T>
size_t FindIndex(const T &v, const std::function<bool(typename T::value_type, typename T::value_type)> &fun)

Find the index with the “optimal” value (picks first in cases of a tie).

Parameters
  • v: Any object allowing indexing (e.g. vector, array, etc.)
  • fun: Comparison function; returns true if the first value os more optimal than second.

template <typename T>
size_t FindMinIndex(const T &v)

Find the index with the minimal value (picks first in cases of a tie).

template <typename T>
size_t FindMaxIndex(const T &v)

Find the index with the maximal value (picks first in cases of a tie).

template <typename T>
T Sum(const emp::vector<T> &v)

Sum up the contents of a vector.

template <typename T>
T Product(const emp::vector<T> &v)

Multiply all of the contents of a vector.

template <typename T, typename... Ts>
void Sort(emp::vector<T> &v, Ts... args)

A quick shortcut for sorting a vector.

template <typename T>
emp::vector<T> Slice(emp::vector<T> vec, int start, int stop)

Returns a vector containing a chunk of elements from

Parameters
  • vec: starting at
  • start: and going up to but not including
  • stop.:

constexpr size_t tree_left(size_t id)

Tree manipulation in vectors.

constexpr size_t tree_right(size_t id)
constexpr size_t tree_parent(size_t id)
template <typename T>
bool Heapify(emp::vector<T> &v, size_t id)

Heapify an individual node in a vector.

template <typename T>
void Heapify(emp::vector<T> &v)

Heapify all elements in a vector.

template <typename T>
T HeapExtract(emp::vector<T> &v)

Extraxt maximum element from a heap.

template <typename T>
void HeapInsert(emp::vector<T> &v, T val)

Insert a new element into a heap.