Skip to content

Commit bf07d6a

Browse files
authored
Merge pull request #103 from AsPJT/feature-simulation-all-input-data
シミュレーションの全定数の入力データ化
2 parents d2ad4d7 + 430bc53 commit bf07d6a

File tree

7 files changed

+92
-51
lines changed

7 files changed

+92
-51
lines changed

Data/Simulations/Sample/District.tsv

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
2 osumi 大隅 2 4 20 2400 0 0 kyushu_jomon 40600
44
3 hyuga 日向 2 4 20 1820 0 0 kyushu_jomon 30800
55
4 higo 肥後 2 4 20 6426 0 0 kyushu_jomon 108700
6-
5 bungo 豊後 3 4 20 1226 0 0.001 kyushu_jomon 51600
7-
6 chikugo 筑後 3 4 20 1410 0 0.001 kyushu_jomon 59300
8-
7 hizen 肥前 3 4 20 1148 0 0.001 kyushu_jomon 48300
9-
8 chikuzen 筑前 3 4 20 2664 5 0.001 kyushu_jomon 112000
10-
9 buzen 豊前 3 4 20 1122 0 0.001 kyushu_jomon 47200
11-
10 iki 壱岐 3 4 20 288 0 0.001 kyushu_jomon 12100
12-
11 tsushima 対馬 3 4 20 234 0 0.001 kyushu_jomon 9900
6+
5 bungo 豊後 3 4 20 1226 0 0 kyushu_jomon 51600
7+
6 chikugo 筑後 3 4 20 1410 0 0 kyushu_jomon 59300
8+
7 hizen 肥前 3 4 20 1148 0 0 kyushu_jomon 48300
9+
8 chikuzen 筑前 3 4 20 2664 1 0.0003 kyushu_jomon 112000
10+
9 buzen 豊前 3 4 20 1122 0 0 kyushu_jomon 47200
11+
10 iki 壱岐 3 4 20 288 0 0 kyushu_jomon 12100
12+
11 tsushima 対馬 3 4 20 234 0 0 kyushu_jomon 9900
1313
12 nagato 長門 5 4 20 976 0 0 chugoku_jomon 43900
1414
13 suo 周防 5 4 20 1098 0 0 chugoku_jomon 49400
1515
14 aki 安芸 5 4 20 1540 0 0 chugoku_jomon 69200

Data/Simulations/Settings.tsv

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,29 @@ start_julian_day 1319309 シミュレーション開始日(ユリウス日)
44
steps_per_year 12 1年あたりのStepの数(step/年)
55
output_step_frequency 120 何Stepおきに出力するか?(step)
66
immigration_start_steps 2401 渡来開始Step数目(step)
7+
immigration_end_steps 21600 渡来終了Step数目(step)
78
init_lifespan_min 180 初期化時の寿命までの最低Step間隔(step)
89
#Space -------------------- #空間 --------------------------------------------------
910
area honsyu シミュレーションの対象範囲
10-
grid_length 512 集落をグループ分けする際の1グリッド辺の長さ(cell)
11+
grid_length 256 集落をグループ分けする際の1グリッド辺の長さ(cell)
1112
immigration_district_id 73 渡来地区ID
1213
land_key district 陸地データのKey
1314
district_key district 地区データのKey
1415
#Marriage -------------------- #婚姻 --------------------------------------------------
1516
maternal_residence_probability 0.5 母方居住婚の確率
16-
marriage_search_range 320 結婚時に近くの集落からエージェントを探す際の探索距離(cell)
17+
marriage_search_range 200 結婚時に近くの集落からエージェントを探す際の探索距離(cell)
1718
female_marriageable_age_min 13 女性の最小婚姻可能年齢(歳)
1819
male_marriageable_age_min 17 男性の最小婚姻可能年齢(歳)
1920
female_marriageable_age_max 60 女性の最大婚姻可能年齢(歳)
2021
male_marriageable_age_max 70 男性の最大婚姻可能年齢(歳)
2122
birthable_age_min 15 出産の最小可能年齢(歳)
2223
birthable_age_max 50 出産の最大可能年齢(歳)
24+
marriageable_age_constant 8.5 婚姻可能年齢定数
25+
marriageable_age_threshold 0.98 婚姻可能年齢閾値
26+
marriageable_age_all_weight 101.8 婚姻可能年齢重み
27+
birthable_age_constant 8.5 出産可能年齢定数
28+
birthable_age_threshold 16.0 出産可能年齢閾値
29+
birthable_age_all_weight 101.8 出産可能年齢重み
2330
#Childbirth -------------------- #出産 --------------------------------------------------
2431
birth_interval 10 妊娠から出産までのStep間隔(step)
2532
hunter_gatherer_stillbirth_rate 0 狩猟採集死産率
@@ -28,8 +35,6 @@ child_agriculture_priority 0.7 片親が農耕文化を持ち、もう一方の
2835
#Movement -------------------- #移動 --------------------------------------------------
2936
max_hunter_gatherer_settlement_population 25 狩猟採集集落の最大人数(人)
3037
max_farming_settlement_population 80 水田稲作集落の最大人数(人)
31-
min_move_distance 10 最小移動距離
32-
max_move_distance 800 最大移動距離
33-
min_move_probability 1 移動確率下限
34-
max_move_probability 1 移動確率上限
35-
move_probability_normalization_coefficient 1000 移動確率の正規化係数
38+
min_move_distance 50 最小移動距離(cell)
39+
max_move_distance 800 最大移動距離(cell)
40+
move_probability 0.05 移動確率

Library/PAX_MAHOROBA/LocationPoint.hpp

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,8 @@ namespace paxs {
508508
#ifdef PAXS_USING_SIMULATOR
509509
// エージェントの位置を管理
510510
class AgentLocation {
511+
private:
512+
std::size_t select_draw = 1;
511513
public:
512514

513515
/// @brief Get the mercator coordinate from the XYZTile coordinate.
@@ -619,7 +621,15 @@ namespace paxs {
619621
void draw(const double jdn,
620622
std::unordered_map<SettlementGridsType, paxs::SettlementGrid>& agents,
621623
const double map_view_width, const double map_view_height, const double map_view_center_x, const double map_view_center_y
622-
)const {
624+
)/*const Siv3D Key は非 const */ {
625+
626+
#ifdef PAXS_USING_SIV3D
627+
if (s3d::Key1.pressed()) select_draw = 1;
628+
else if (s3d::Key2.pressed()) select_draw = 2;
629+
else if (s3d::Key3.pressed()) select_draw = 3;
630+
else if (s3d::Key4.pressed()) select_draw = 4;
631+
#endif
632+
623633
// 地名を描画
624634
for (const auto& agent : agents) {
625635
for (const auto& settlement : agent.second.cgetSettlements()) {
@@ -661,11 +671,28 @@ namespace paxs {
661671
// エージェント
662672
// if (lli.lpe == MurMur3::calcHash("agent1"))
663673
{
664-
// const std::size_t pop_original = settlement.getFarmingPopulation(); // settlement.getPopulation();
665-
//const float pop_original = settlement.getFarmingPopulation() / float(settlement.getPopulation()) * 75.0f; // settlement.getPopulation();
666-
//const float pop_original = settlement.getMostMtDNA() / 27.0f * 75.0f; // settlement.getPopulation();
667-
const double pop_original = settlement.getSNP() * 75.0; // settlement.getPopulation();
668-
674+
double pop_original = 0.0;
675+
switch (select_draw)
676+
{
677+
case 1:
678+
// const std::size_t
679+
// pop_original = settlement.getFarmingPopulation();
680+
pop_original = static_cast<double>(settlement.getPopulation());
681+
break;
682+
case 2:
683+
//const float
684+
pop_original = settlement.getFarmingPopulation() / float(settlement.getPopulation()) * 75.0;
685+
break;
686+
case 3:
687+
//const float
688+
pop_original = settlement.getMostMtDNA() / 27.0 * 75.0;
689+
break;
690+
case 4:
691+
//const double
692+
pop_original = settlement.getSNP() * 75.0;
693+
break;
694+
}
695+
669696
const std::uint_least8_t pop = (pop_original >= 75) ? 75 : static_cast<std::uint_least8_t>(pop_original);
670697
paxg::Circle(draw_pos,
671698
1.0f + (settlement.getPopulation() / 40.0f)//2.0f

Library/PAX_SAPIENTICA/Simulation/Settlement.hpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -318,13 +318,12 @@ namespace paxs {
318318
/// @brief Move.
319319
/// @brief 移動
320320
/// @return 集落グリッドを移動したかどうか
321-
std::tuple<std::uint_least32_t, Vector2, Vector2> move(std::mt19937& engine, int move_probability) noexcept {
321+
std::tuple<std::uint_least32_t, Vector2, Vector2> move(std::mt19937& engine) noexcept {
322322
Vector2 current_key;
323323
Vector2 target_key;
324324

325325
// 確率で移動
326-
std::uniform_int_distribution<> dist(0, SimulationConstants::getInstance()->move_probability_normalization_coefficient);
327-
if (dist(engine) > move_probability) return { 0, Vector2(), Vector2() };
326+
if (SimulationConstants::getInstance()->random_dist(engine) > SimulationConstants::getInstance()->move_probability) return { 0, Vector2(), Vector2() };
328327

329328
// 座標を移動
330329
// 移動距離0~max_move_distance
@@ -582,25 +581,25 @@ namespace paxs {
582581
bool isMarried(const double age) noexcept {
583582
// 婚姻可能年齢の上限値以上だったら結婚しない
584583
if (age >= SimulationConstants::getInstance()->female_marriageable_age_max) return false;
585-
auto x = [](double age) { return (age - SimulationConstants::getInstance()->female_marriageable_age_min_f64) / 8.5; };
584+
auto x = [](double age) { return (age - SimulationConstants::getInstance()->female_marriageable_age_min_f64) / SimulationConstants::getInstance()->marriageable_age_constant; };
586585
auto weight = [=](double age) {
587586
return std::exp(-std::pow(std::log(x(age)), 2.0) / settlement::sigma_p_2_x_2) / (x(age) * settlement::sigma_x_sqrt_2_x_pi);
588587
};
589588

590-
const double threshold = static_cast<double>(weight(age)) * (0.98 / 101.8);
589+
const double threshold = static_cast<double>(weight(age)) * (SimulationConstants::getInstance()->marriageable_age_threshold / SimulationConstants::getInstance()->marriageable_age_all_weight); // (0.98 / 101.8);
591590

592591
return SimulationConstants::getInstance()->random_dist(*gen) < threshold;
593592
}
594593

595594
/// @brief Is able to give birth?
596595
/// @brief 確率で出産するかどうかを返す
597596
bool isAbleToGiveBirth(const double age) noexcept {
598-
auto x = [](double age) { return (age - 14) / 8.5; };
597+
auto x = [](double age) { return (age - SimulationConstants::getInstance()->pregnant_age_min_f64) / SimulationConstants::getInstance()->birthable_age_constant; };
599598
auto weight = [=](double age) {
600599
return std::exp(-std::pow(std::log(x(age)), 2.0) / settlement::sigma_p_2_x_2) / (x(age) * settlement::sigma_x_sqrt_2_x_pi);
601600
};
602601

603-
const double threshold = static_cast<double>(weight(age)) * (16.0 / 101.8);
602+
const double threshold = static_cast<double>(weight(age)) * (SimulationConstants::getInstance()->birthable_age_threshold / SimulationConstants::getInstance()->birthable_age_all_weight); // (16 / 101.8);
604603

605604
return SimulationConstants::getInstance()->random_dist(*gen) < threshold;
606605
}

Library/PAX_SAPIENTICA/Simulation/SettlementSimulator.hpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ namespace paxs {
4747
environment(std::make_unique<Environment>(map_list_path)), gen(seed) {
4848
japan_provinces = std::make_unique<paxs::JapanProvinces>(japan_provinces_path);
4949
kanakuma_life_span.japan_provinces = japan_provinces.get();
50-
51-
// ランダムに移動確率を設定
52-
std::uniform_int_distribution<> move_probability_dist{ SimulationConstants::getInstance()->min_move_probability, SimulationConstants::getInstance()->max_move_probability };
53-
move_probability = move_probability_dist(gen);
5450
}
5551
/// @brief 環境を設定
5652
void setEnvironment(const std::string& map_list_path, const std::string& japan_provinces_path, /*const int z,*/ const unsigned seed = 0) noexcept {
@@ -62,10 +58,6 @@ namespace paxs {
6258
japan_provinces.reset();
6359
japan_provinces = std::make_unique<paxs::JapanProvinces>(japan_provinces_path);
6460
kanakuma_life_span.japan_provinces = japan_provinces.get();
65-
66-
// ランダムに移動確率を設定
67-
std::uniform_int_distribution<> move_probability_dist{ SimulationConstants::getInstance()->min_move_probability, SimulationConstants::getInstance()->max_move_probability };
68-
move_probability = move_probability_dist(gen);
6961
}
7062

7163
/// @brief
@@ -182,7 +174,7 @@ namespace paxs {
182174
continue;
183175
}
184176

185-
auto [target_id, current_key, target_key] = settlements[i].move(gen, move_probability);
177+
auto [target_id, current_key, target_key] = settlements[i].move(gen);
186178

187179
if (target_id != 0) {
188180
move_list.emplace_back(target_id, current_key, target_key);
@@ -202,7 +194,8 @@ namespace paxs {
202194
}
203195
}
204196
// 前901年から稲作文化開始
205-
if (step_count >= SimulationConstants::getInstance()->immigration_start_steps) {
197+
if (step_count >= SimulationConstants::getInstance()->immigration_start_steps &&
198+
step_count <= SimulationConstants::getInstance()->immigration_end_steps) {
206199
randomizeSettlements(false, 255, 0, 255/*渡来人は SNP:255*/);
207200
}
208201

@@ -283,7 +276,8 @@ namespace paxs {
283276
}
284277

285278
// 前901年から処理開始
286-
if (step_count >= SimulationConstants::getInstance()->immigration_start_steps) {
279+
if (step_count >= SimulationConstants::getInstance()->immigration_start_steps &&
280+
step_count <= SimulationConstants::getInstance()->immigration_end_steps) {
287281
// 渡来数を増やす
288282
japan_provinces->update();
289283
}
@@ -327,7 +321,6 @@ namespace paxs {
327321
std::shared_ptr<Environment> environment;
328322

329323
std::unique_ptr<paxs::JapanProvinces> japan_provinces;
330-
int move_probability = 0; // 移動確率
331324

332325
std::mt19937 gen; // 乱数生成器
333326

0 commit comments

Comments
 (0)