<commit_before>#include "ModuleManager.h"
#include <random>
#include <time.h>
#include <algorithm>

#include <fstream>
#include <iostream>

#include <boost/filesystem.hpp>

#include "EncodedModuleGroup.h"
#include "codecs/EncodedModuleGroupCodec.h"

namespace noise {

ModuleManager::ModuleManager(const Options & options) :
    mRNG((unsigned int)time(nullptr))
{
    mBottomRightBorder = ModuleGroup::makeConstModuleGroup(0.0);

    boost::filesystem::path p(options.directory);

    p /= options.combinerModuleGroup;
    mCombiner = loadModuleGroup(p.string());
    p.remove_filename();

    for (auto it : options.centralModuleGroups)
    {
        p /= it.filename;
        auto inserted = mCentres.insert({it.terrain, loadModuleGroup(p.string())});
        p.remove_filename();

        if (!inserted.second)
            throw std::runtime_error("Tried to load two central module groups with the same terrain");
    }
    for (auto it : options.leftBorderModuleGroups)
    {
        p /= it.filename;
        auto inserted = mLeftBorders.insert({it.terrains, loadModuleGroup(p.string())});
        p.remove_filename();

        if (!inserted.second)
            throw std::runtime_error("Tried to load two horizontal border module groups with the same terrain pair");
        inserted.first->second->setSeeds(mRNG());
    }
    for (auto it : options.topBorderModuleGroups)
    {
        p /= it.filename;
        auto inserted = mTopBorders.insert({it.terrains, loadModuleGroup(p.string())});
        p.remove_filename();

        if (!inserted.second)
            throw std::runtime_error("Tried to load two vertical border module groups with the same terrain pair");
        inserted.first->second->setSeeds(mRNG());
    }
    if (options.defaultModuleGroup)
    {
        p /= options.defaultModuleGroup.get();
    }
    for (const auto& terrain : options.terrains)
    {
        if (mCentres.find(terrain.first) == mCentres.cend())
        {
            if (options.defaultModuleGroup)
                mCentres.insert({terrain.first, loadModuleGroup(p.string())});
            else
                throw std::runtime_error("Missing central module group, and no default module group");
        }
    }
    for (const auto& clique : options.cliques)
    {
        // At least n*(n-1)/2 duplicates will be checked in each clique.
        for (const auto& t1 : clique)
            for (const auto& t2 : clique)
            {
                TerrainIDPair tp{t1, t2};
                if (mLeftBorders.find(tp) == mLeftBorders.end())
                {
                    if (options.defaultModuleGroup)
                        mLeftBorders.insert({tp, loadModuleGroup(p.string())});
                    else
                        throw std::runtime_error("Missing left border module group, and no default module group");
                }
                if (mTopBorders.find(tp) == mTopBorders.end())
                {
                    if(options.defaultModuleGroup)
                        mTopBorders.insert({tp, loadModuleGroup(p.string())});
                    else
                        throw std::runtime_error("Missing top border module group, and no default module group");
                }
            }
    }
    
}

ModuleGroup& ModuleManager::getTopBorder(TerrainID top, TerrainID bottom)
{
    return *mTopBorders.at({top, bottom});<commit_msg>Set default border module seeds on load<commit_after>#include "ModuleManager.h"
#include <random>
#include <time.h>
#include <algorithm>

#include <fstream>
#include <iostream>

#include <boost/filesystem.hpp>

#include "EncodedModuleGroup.h"
#include "codecs/EncodedModuleGroupCodec.h"

namespace noise {

ModuleManager::ModuleManager(const Options & options) :
    mRNG((unsigned int)time(nullptr))
{
    mBottomRightBorder = ModuleGroup::makeConstModuleGroup(0.0);

    boost::filesystem::path p(options.directory);

    p /= options.combinerModuleGroup;
    mCombiner = loadModuleGroup(p.string());
    p.remove_filename();

    for (auto it : options.centralModuleGroups)
    {
        p /= it.filename;
        auto inserted = mCentres.insert({it.terrain, loadModuleGroup(p.string())});
        p.remove_filename();

        if (!inserted.second)
            throw std::runtime_error("Tried to load two central module groups with the same terrain");
    }
    for (auto it : options.leftBorderModuleGroups)
    {
        p /= it.filename;
        auto inserted = mLeftBorders.insert({it.terrains, loadModuleGroup(p.string())});
        p.remove_filename();

        if (!inserted.second)
            throw std::runtime_error("Tried to load two left border module groups with the same terrain pair");
        inserted.first->second->setSeeds(mRNG());
    }
    for (auto it : options.topBorderModuleGroups)
    {
        p /= it.filename;
        auto inserted = mTopBorders.insert({it.terrains, loadModuleGroup(p.string())});
        p.remove_filename();

        if (!inserted.second)
            throw std::runtime_error("Tried to load two top border module groups with the same terrain pair");
        inserted.first->second->setSeeds(mRNG());
    }
    if (options.defaultModuleGroup)
    {
        p /= options.defaultModuleGroup.get();
    }
    for (const auto& terrain : options.terrains)
    {
        if (mCentres.find(terrain.first) == mCentres.cend())
        {
            if (options.defaultModuleGroup)
                mCentres.insert({terrain.first, loadModuleGroup(p.string())});
            else
                throw std::runtime_error("Missing central module group, and no default module group");
        }
    }
    for (const auto& clique : options.cliques)
    {
        // At least n*(n-1)/2 duplicates will be checked in each clique.
        for (const auto& t1 : clique)
            for (const auto& t2 : clique)
            {
                TerrainIDPair tp{t1, t2};
                if (mLeftBorders.find(tp) == mLeftBorders.end())
                {
                    if (options.defaultModuleGroup)
                    {
                        auto inserted = mLeftBorders.insert({tp, loadModuleGroup(p.string())});
                        inserted.first->second->setSeeds(mRNG());
                    }
                    else
                        throw std::runtime_error("Missing left border module group, and no default module group");
                }
                if (mTopBorders.find(tp) == mTopBorders.end())
                {
                    if (options.defaultModuleGroup)
                    {
                        auto inserted = mTopBorders.insert({tp, loadModuleGroup(p.string())});
                        inserted.first->second->setSeeds(mRNG());
                    }
                    else
                        throw std::runtime_error("Missing top border module group, and no default module group");
                }
            }
    }
    
}

ModuleGroup& ModuleManager::getTopBorder(TerrainID top, TerrainID bottom)
{
    return *mTopBorders.at({top, bottom});
{'fraction_non_alphanumeric': 0.1146278870829769, 'fraction_numerical': 0.0022811519817507843, 'mean_word_length': 2.1799637352674526, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3930910', 'n_tokens_mistral': 1995, 'n_tokens_neox': 1948, 'n_words': 442}