Skip to content

Commit

Permalink
fix last bugs, hopefully
Browse files Browse the repository at this point in the history
  • Loading branch information
Becheler committed Nov 15, 2021
1 parent e16f886 commit 730c03a
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 5 deletions.
12 changes: 10 additions & 2 deletions include/quetzal/demography/FlowOnDiskImplementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ namespace quetzal

void slide_RAM_window_to(time_type t) const
{
std::cout << t << " " << m_forward_flow.size() << " " << m_backward_flow.size() << std::endl;
// window is well positioned
if(t == m_RAM_window.first || t == m_RAM_window.second )
{
Expand Down Expand Up @@ -264,8 +265,15 @@ namespace quetzal
serialize_layer( m_RAM_window.first );
serialize_layer( m_RAM_window.second );
// slide the windows
m_RAM_window.first = t - 1;
m_RAM_window.second = t;
if(t == 0)
{
m_RAM_window.first = 0;
m_RAM_window.second = 1;
}else{
m_RAM_window.first = t - 1;
m_RAM_window.second = t;
}

// read both layers from disk
deserialize_layer( m_RAM_window.first );
deserialize_layer( m_RAM_window.second );
Expand Down
12 changes: 9 additions & 3 deletions include/quetzal/demography/PopulationSizeOnDiskImplementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "assert.h"
#include <iostream>
#include <fstream>

namespace quetzal
{
namespace demography
Expand Down Expand Up @@ -196,8 +196,14 @@ namespace quetzal
serialize_layer( m_RAM_window.first );
serialize_layer( m_RAM_window.second );
// slide the windows
m_RAM_window.first = t - 1;
m_RAM_window.second = t;
if(t == 0)
{
m_RAM_window.first = 0;
m_RAM_window.second = 1;
}else{
m_RAM_window.first = t - 1;
m_RAM_window.second = t;
}
// read both layers from disk
deserialize_layer( m_RAM_window.first );
deserialize_layer( m_RAM_window.second );
Expand Down
58 changes: 58 additions & 0 deletions test/unit_test/demography_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,64 @@ BOOST_AUTO_TEST_CASE( flow )
}
}

BOOST_AUTO_TEST_CASE( flow_on_disk_implementation )
{
using coord_type = std::string;
using time_type = unsigned int;
using value_type = int;

time_type t = 0;
coord_type i = "A";
coord_type j = "B";

quetzal::demography::FlowOnDiskImplementation<coord_type, time_type, value_type> Phi;

BOOST_TEST( ! Phi.flux_to_is_defined(i, t) );
Phi.set_flux_from_to(i, j, t, 12);
Phi.add_to_flux_from_to(j, j, t, 1);
BOOST_TEST(Phi.flux_to_is_defined(j, t));
BOOST_TEST(Phi.flux_from_to(i,j,t) == 12);
BOOST_TEST(Phi.flux_from_to(j,j,t) == 1);

std::cout << "Flows converging to " << j << " at time t=" << t << ":" <<std::endl;
for(auto const& it : Phi.flux_to(j,t))
{
std::cout << "From "<< it.first << " to " << j << " = " << it.second << std::endl;
}
}

BOOST_AUTO_TEST_CASE( flow_on_disk_implementation_moving_windows )
{
std::cout << "here" <<std::endl;
using coord_type = unsigned int;
using time_type = unsigned int;
using value_type = unsigned int;

quetzal::demography::FlowOnDiskImplementation<coord_type, time_type, value_type> Phi;

for(unsigned int t=0; t <= 5; ++t)
{
for(unsigned int from=0; from <=5; ++from)
{
for(unsigned int to=0; to <= 5; ++to)
{
Phi.set_flux_from_to(from, to, t, from+to+t);
}
}
}

BOOST_TEST(Phi.flux_to_is_defined(5, 5));
BOOST_TEST(Phi.flux_from_to(5,5,5) == 15);
BOOST_TEST(Phi.flux_from_to(2,4,5) == 11);
BOOST_TEST(Phi.flux_from_to(0,0,4) == 4);
BOOST_TEST(Phi.flux_from_to(0,0,3) == 3);
BOOST_TEST(Phi.flux_from_to(0,0,2) == 2);
BOOST_TEST(Phi.flux_from_to(0,0,1) == 1);
BOOST_TEST(Phi.flux_from_to(0,0,0) == 0);
BOOST_TEST(Phi.flux_from_to(1,2,5) == 8);
BOOST_TEST(Phi.flux_from_to(0,0,0) == 0);
}

BOOST_AUTO_TEST_CASE( individual_based_history_default_storage )
{
//! [individual_based_history_default_storage example]
Expand Down

0 comments on commit 730c03a

Please sign in to comment.