Skip to content

Commit

Permalink
Merge branch 'master' of github.com:devosoft/Empirical
Browse files Browse the repository at this point in the history
  • Loading branch information
emilydolson committed May 14, 2016
2 parents 7481633 + 6520954 commit bcb6fa9
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 13 deletions.
4 changes: 2 additions & 2 deletions examples/evo/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ CFLAGS_all := -Wall -Wno-unused-variable -Wno-unused-function -Wno-extra-semi -s
CXX_web := emcc
CXX_native := g++

#OFLAGS_native := -g -pedantic
OFLAGS_native := -O3 -DNDEBUG
OFLAGS_native := -g -pedantic
#OFLAGS_native := -O3 -DNDEBUG

OFLAGS_web := -g4 -pedantic -Wno-dollar-in-identifier-extension -s TOTAL_MEMORY=67108864 -s ASSERTIONS=2 -s DEMANGLE_SUPPORT=1 # -s SAFE_HEAP=1
#OFLAGS_web := -Os -DNDEBUG -s TOTAL_MEMORY=67108864
Expand Down
2 changes: 1 addition & 1 deletion examples/evo/NK-Serial.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ int main()
emp::Random random; // Build a random number generator.
emp::evo::NKLandscape<N,K> landscape(random); // Build the landscape...
STWorld world(random); // Build the world...
world.pop.Config(MAX_POP_SIZE,MIN_POP_SIZE); // Setup default population extremes.
world.ConfigPop(MAX_POP_SIZE, MIN_POP_SIZE); // Setup default population extremes.

BitOrg ancestor(random); // Build a random ancestor
world.Insert(ancestor, MIN_POP_SIZE); // Insert several copies of ancestor
Expand Down
9 changes: 6 additions & 3 deletions examples/evo/World.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include "../../evo/World.h"
#include "../../tools/Random.h"

namespace evo = emp::evo;

struct TestOrg1 {
int fitness;

Expand All @@ -22,7 +24,7 @@ struct TestOrg1 {
int main()
{
emp::Random random;
emp::evo::World<int> world(random);
evo::World<int> world(random);

for (int i = 0; i < 100; i++) world.Insert(i+100);

Expand All @@ -49,7 +51,7 @@ int main()



emp::evo::EAWorld<TestOrg1> ea_world(random);
evo::EAWorld<TestOrg1> ea_world(random);
for (int i = 0; i < 100; i++) ea_world.Insert(i+200);

std::cout << "Start Size = " << ea_world.GetSize() << std::endl;
Expand All @@ -71,7 +73,8 @@ int main()


// Test grid Populations
emp::evo::World<int, emp::evo::PopGrid> grid_world(random);
// evo::World<int, evo::PopGrid> grid_world(random);
evo::GridWorld<int> grid_world(random);
for (int i = 0; i < 10; i++) grid_world.Insert(i);
grid_world.Print();

Expand Down
26 changes: 23 additions & 3 deletions examples/tools/reflection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ struct G {
static constexpr int class_id = 7;
};

EMP_CHOOSE_TYPE_WITH_MEMBER(auto_type, use_this, int, C, D, E);
EMP_SETUP_TYPE_SELECTOR(auto_type, use_this);

int TestFun(int x, int y, int z) {
return x+y+z;
}

/*
* template <typename EMP__T, typename... EXTRAS>
Expand All @@ -61,6 +64,11 @@ template <> struct ABC<void> { using type = void; };
using auto_type = typename ABC<int, bool, F, G, D, E, C, D, E, void>::type;
*/

template <typename T> struct has_XY {
EMP_ADD_TYPE_FROM_MEMBER(type_X, T, X, double); // has_XY<A>::type_X = int
EMP_ADD_TYPE_FROM_MEMBER(type_Y, T, Y, double); // has_XY<A>::type_Y = double since A::Y does not exist.
};

int main()
{
// Continuing test of EMP_CHOOSE_MEMBER_TYPE...
Expand All @@ -70,6 +78,18 @@ int main()
std::cout << Wrapper<A>::VALUE/2 << std::endl; // 2.5
std::cout << Wrapper<B>::VALUE/2 << std::endl; // 2

// Continuing test of EMP_CHOOSE_TYPE_WITH_MEMBER...
std::cout << auto_type::class_id << std::endl;
// Continuing test of EMP_SETUP_TYPE_SELECTOR...

std::cout << auto_type<int, C, D, E>::type::class_id << std::endl;

std::cout << TestFun(1,2,3) << std::endl;
std::cout << emp::internal::SubsetCall_impl<int,int,int,int>::Call<>(TestFun, 4,5,6,7.5,8.5) << std::endl;

std::function<int(int,int,int)> tfun(TestFun);
std::cout << emp::SubsetCall(tfun, 4,5,6,7.5,8.5) << std::endl;

has_XY<A>::type_X test_val = (has_XY<A>::type_X) 2.5;
std::cout << "has_XY<A>::type_X = " << test_val << std::endl;
has_XY<A>::type_Y test_val2 = (has_XY<A>::type_Y) 2.5;
std::cout << "has_XY<A>::type_Y = " << test_val2 << std::endl;
}
8 changes: 6 additions & 2 deletions tools/BitSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
//
//
// Class: template <int NUM_BITS> emp::BitSet
//
// Desc: This class handles a fixed-sized (but arbitrarily large) array of bits,
// and optimizes operations on those bits to be as fast as possible.
// Note: 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.
//
// Note: emp::BitSet is based on std::bitset, and can be used as a drop-in replacement.
// 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.
//
//
// Constructors:
Expand Down
2 changes: 1 addition & 1 deletion tools/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace emp {
}

// Toggle an input bool.
inline constexpr bool toggle(bool & in_bool) { return (in_bool = !in_bool); }
inline bool toggle(bool & in_bool) { return (in_bool = !in_bool); }

/// % is actually remainder; this is a proper modulus command that handles negative #'s correctly
inline constexpr int mod(int in_val, int mod_val) {
Expand Down
17 changes: 17 additions & 0 deletions tools/reflection.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,23 @@ template <typename... TYPES> struct NAME {
EMP_IMPL_TYPE_DEFAULT(EMP_DETECT_ ## NEW_TYPE, int, DEFAULT); \
using NEW_TYPE = decltype(EMP_DETECT_ ## NEW_TYPE ## _impl<BASE_TYPE>(true))

#define EMP_ADD_TYPE_FROM_TYPE(NEW_TYPE, BASE_TYPE, TYPE, DEFAULT) \
EMP_IMPL_TYPE_HAS_TYPE(EMP_DETECT_ ## NEW_TYPE, bool, TYPE); \
EMP_IMPL_TYPE_DEFAULT(EMP_DETECT_ ## NEW_TYPE, int, DEFAULT); \
using NEW_TYPE = decltype(EMP_DETECT_ ## NEW_TYPE ## _impl<BASE_TYPE>(true))

#define EMP_ADD_TYPE_FROM_MEMBER_OR_TYPE(NEW_TYPE, BASE_TYPE, MEMBER, TYPE, DEFAULT) \
EMP_IMPL_TYPE_HAS_MEMBER(EMP_DETECT_ ## NEW_TYPE, bool, MEMBER); \
EMP_IMPL_TYPE_HAS_TYPE(EMP_DETECT_ ## NEW_TYPE, int, TYPE); \
EMP_IMPL_TYPE_DEFAULT(EMP_DETECT_ ## NEW_TYPE, ..., DEFAULT); \
using NEW_TYPE = decltype(EMP_DETECT_ ## NEW_TYPE ## _impl<BASE_TYPE>(true))

#define EMP_ADD_TYPE_FROM_TYPE_OR_MEMBER(NEW_TYPE, BASE_TYPE, TYPE, MEMBER, DEFAULT) \
EMP_IMPL_TYPE_HAS_TYPE(EMP_DETECT_ ## NEW_TYPE, bool, TYPE); \
EMP_IMPL_TYPE_HAS_MEMBER(EMP_DETECT_ ## NEW_TYPE, int, MEMBER); \
EMP_IMPL_TYPE_DEFAULT(EMP_DETECT_ ## NEW_TYPE, ..., DEFAULT); \
using NEW_TYPE = decltype(EMP_DETECT_ ## NEW_TYPE ## _impl<BASE_TYPE>(true))

// Call a function with more args than it can take; ignore extras.

namespace emp {
Expand Down
18 changes: 17 additions & 1 deletion tools/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,27 @@ namespace emp {
vector(const std::vector<T> & in) : v(in) { ; } // Emergency fallback conversion.
~vector() = default;

uint32_t size() const { return v.size(); }
size_type size() const noexcept { return v.size(); }
void resize(int new_size) { emp_assert(new_size >= 0, new_size); v.resize(new_size); }
void resize(int new_size, const T & val) {
emp_assert(new_size >= 0, new_size);
v.resize(new_size, val);
}
bool empty() const noexcept { return v.empty(); }
size_type capacity() const noexcept { return v.capacity(); }
size_type max_size() const noexcept { return v.max_size(); }
void reserve(size_type n) { v.reserve(n); }
void shrink_to_fit() { v.shrink_to_fit(); }

emp::vector<T> & operator=(const emp::vector<T> &) = default;
emp::vector<T> & operator=(const std::vector<T> & x) { v = x; return *this; }
emp::vector<T> & operator=(const std::initializer_list<value_type> & il) {
v.operator=(il);
return *this;
}

void swap(emp::vector<T> & x) { v.swap(x.v); }
void swap(std::vector<T> & x) { v.swap(x); }

bool operator==(const emp::vector<T> & in) const { return v == in.v; }
bool operator!=(const emp::vector<T> & in) const { return v != in.v; }
Expand Down Expand Up @@ -88,6 +99,9 @@ namespace emp {
template <typename... T2>
void emplace_back(T2 &&... in) { v.emplace_back(std::forward<T2>(in)...); }

template <typename... T2>
iterator erase(T2 &&... in) { return v.erase(std::forward<T2>(in)...); }

auto begin() -> decltype(v.begin()) { return v.begin(); }
auto end() -> decltype(v.end()) { return v.end(); }
auto begin() const -> const decltype(v.begin()) { return v.begin(); }
Expand All @@ -114,6 +128,8 @@ namespace emp {

T & back() { return v.back(); }
const T & back() const { return v.back(); }
T & front() { return v.front(); }
const T & front() const { return v.front(); }

void pop_back() {
emp_assert(v.size() > 0, v.size());
Expand Down

0 comments on commit bcb6fa9

Please sign in to comment.