Skip to content

Commit

Permalink
add: new marriage & childbearing
Browse files Browse the repository at this point in the history
  • Loading branch information
AsPJT committed Dec 14, 2024
1 parent 267b776 commit 4333a1e
Show file tree
Hide file tree
Showing 8 changed files with 336 additions and 51 deletions.
102 changes: 102 additions & 0 deletions Data/Simulations/Sample/Childbearing.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
age hunter_gatherer agricultural
0 0 0
1 0 0
2 0 0
3 0 0
4 0 0
5 0 0
6 0 0
7 0 0
8 0 0
9 0 0
10 0 0
11 0 0
12 0 0
13 0 0
14 0.009022766008 0.003007588669
15 0.03746975846 0.01248991949
16 0.06757353696 0.02252451232
17 0.09958830351 0.03319610117
18 0.1337557159 0.04458523864
19 0.1703668704 0.05678895681
20 0.2098868832 0.0699622944
21 0.2526807842 0.08422692807
22 0.2995459554 0.09984865178
23 0.3511586331 0.1170528777
24 0.4089346823 0.1363115608
25 0.4743033249 0.1581011083
26 0.5500259893 0.1833419964
27 0.6405890518 0.2135296839
28 0.7534403528 0.2511467843
29 0.9056625696 0.3018875232
30 1.151236496 0.3837454986
31 1.312976024 0.4376586748
32 1.087701736 0.3625672452
33 0.8668848806 0.2889616269
34 0.7222288212 0.2407429404
35 0.6129487486 0.2043162495
36 0.5239938899 0.17466463
37 0.4484244189 0.1494748063
38 0.3825212912 0.1275070971
39 0.3241175852 0.1080391951
40 0.2715395289 0.09051317629
41 0.2237504232 0.07458347441
42 0.1799112904 0.05997043012
43 0.139559001 0.046519667
44 0.1021741604 0.03405805348
45 0.06747719441 0.02249239814
46 0.03521142259 0.01173714086
47 0.005148315889 0.001716105296
48 0 0
49 0 0
50 0 0
51 0 0
52 0 0
53 0 0
54 0 0
55 0 0
56 0 0
57 0 0
58 0 0
59 0 0
60 0 0
61 0 0
62 0 0
63 0 0
64 0 0
65 0 0
66 0 0
67 0 0
68 0 0
69 0 0
70 0 0
71 0 0
72 0 0
73 0 0
74 0 0
75 0 0
76 0 0
77 0 0
78 0 0
79 0 0
80 0 0
81 0 0
82 0 0
83 0 0
84 0 0
85 0 0
86 0 0
87 0 0
88 0 0
89 0 0
90 0 0
91 0 0
92 0 0
93 0 0
94 0 0
95 0 0
96 0 0
97 0 0
98 0 0
99 0 0
100 0 0
102 changes: 102 additions & 0 deletions Data/Simulations/Sample/Marriage.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
age hunter_gatherer agricultural
0 0 0
1 0 0
2 0 0
3 0 0
4 0 0
5 0 0
6 0 0
7 0 0
8 0 0
9 0 0
10 0 0
11 0 0
12 0 0
13 0 0
14 0.00002406070935 0.00002406070935
15 0.0000999193559 0.0000999193559
16 0.0001801960986 0.0001801960986
17 0.0002655688094 0.0002655688094
18 0.0003566819091 0.0003566819091
19 0.0004543116545 0.0004543116545
20 0.0005596983552 0.0005596983552
21 0.0006738154246 0.0006738154246
22 0.0007987892143 0.0007987892143
23 0.0009364230216 0.0009364230216
24 0.001090492486 0.001090492486
25 0.001264808867 0.001264808867
26 0.001466735971 0.001466735971
27 0.001708237472 0.001708237472
28 0.002009174274 0.002009174274
29 0.002415100186 0.002415100186
30 0.003069963989 0.003069963989
31 0.003501269398 0.003501269398
32 0.002900537962 0.002900537962
33 0.002311693015 0.002311693015
34 0.001925943523 0.001925943523
35 0.001634529996 0.001634529996
36 0.00139731704 0.00139731704
37 0.00119579845 0.00119579845
38 0.001020056776 0.001020056776
39 0.0008643135606 0.0008643135606
40 0.0007241054103 0.0007241054103
41 0.0005966677953 0.0005966677953
42 0.000479763441 0.000479763441
43 0.000372157336 0.000372157336
44 0.0002724644279 0.0002724644279
45 0.0001799391851 0.0001799391851
46 0.0000938971269 0.0000938971269
47 0.00001372884237 0.00001372884237
48 0 0
49 0 0
50 0 0
51 0 0
52 0 0
53 0 0
54 0 0
55 0 0
56 0 0
57 0 0
58 0 0
59 0 0
60 0 0
61 0 0
62 0 0
63 0 0
64 0 0
65 0 0
66 0 0
67 0 0
68 0 0
69 0 0
70 0 0
71 0 0
72 0 0
73 0 0
74 0 0
75 0 0
76 0 0
77 0 0
78 0 0
79 0 0
80 0 0
81 0 0
82 0 0
83 0 0
84 0 0
85 0 0
86 0 0
87 0 0
88 0 0
89 0 0
90 0 0
91 0 0
92 0 0
93 0 0
94 0 0
95 0 0
96 0 0
97 0 0
98 0 0
99 0 0
100 0 0
10 changes: 2 additions & 8 deletions Data/Simulations/Settings.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,23 @@ female_marriageable_age_min 13 女性の最小婚姻可能年齢(歳)
male_marriageable_age_min 17 男性の最小婚姻可能年齢(歳)
female_marriageable_age_max 60 女性の最大婚姻可能年齢(歳)
male_marriageable_age_max 70 男性の最大婚姻可能年齢(歳)
marriageable_age_constant 8.5 婚姻可能年齢定数
marriageable_age_threshold 0.98 婚姻可能年齢閾値
marriageable_age_all_weight 101.8 婚姻可能年齢重み
#Childbirth -------------------- #出産 --------------------------------------------------
birth_interval 10 妊娠から出産までのStep間隔(step)
hunter_gatherer_stillbirth_rate 0 狩猟採集死産率 (no effect)
agricultural_stillbirth_rate 0 水田稲作死産率 (no effect)
child_agriculture_priority 0.5 片親が農耕文化を持ち、もう一方の片親が農耕文化を持たない時の農耕文化継承の優先度
childbearing_age_min 15 出産の最小可能年齢(歳)
childbearing_age_max 50 出産の最大可能年齢(歳)
childbearing_age_constant 8.5 出産可能年齢定数
childbearing_age_threshold 16 出産可能年齢閾値
childbearing_age_all_weight 101.8 出産可能年齢重み
#Movement -------------------- #移動 --------------------------------------------------
max_hunter_gatherer_settlement_population 25 狩猟採集集落の最大人数(人)
max_agricultural_settlement_population 80 水田稲作集落の最大人数(人)
min_move_distance 1 最小移動距離(cell)
max_move_distance 1600 最大移動距離(cell)
move_probability 0.01 移動確率
move_probability 0.0021 移動確率
ocean_cost 1.1 海上の通行コスト
coast_cost 0.7 海岸の通行コスト
land_cost 2.5 傾斜度0度の陸上の通行コスト
move_redo 10 移動再試行回数
move_method astar 移動の手法(astar/random)
move_astar_loop 8 A*を行うルート数
move_astar_distance 64 A*を行うルート間隔
move_astar_distance 128 A*を行うルート間隔
5 changes: 0 additions & 5 deletions Library/PAX_SAPIENTICA/Simulation/JapanProvinces.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ namespace paxs {
life_span_tsv.deleteBOM();
// 1 行目を分割する
std::unordered_map<std::uint_least32_t, std::size_t> menu = life_span_tsv.splitHashMapMurMur3('\t');
std::size_t i = 1;

// 1 行ずつ読み込み(区切りはタブ)
while (life_span_tsv.getLine()) {
Expand All @@ -165,13 +164,11 @@ namespace paxs {
life_span.weight_farming_male.emplace_back(std::stod(sub_menu_v[menu[MurMur3::calcHash("agricultural_male_ndx")]]));
life_span.weight_hunter_gatherer_female.emplace_back(std::stod(sub_menu_v[menu[MurMur3::calcHash("hunter_gatherer_female_ndx")]]));
life_span.weight_hunter_gatherer_male.emplace_back(std::stod(sub_menu_v[menu[MurMur3::calcHash("hunter_gatherer_male_ndx")]]));
;
// 確率分布を生成
life_span.dist_farming_female = std::discrete_distribution<>(life_span.weight_farming_female.begin(), life_span.weight_farming_female.end());
life_span.dist_farming_male = std::discrete_distribution<>(life_span.weight_farming_male.begin(), life_span.weight_farming_male.end());
life_span.dist_hunter_gatherer_female = std::discrete_distribution<>(life_span.weight_hunter_gatherer_female.begin(), life_span.weight_hunter_gatherer_female.end());
life_span.dist_hunter_gatherer_male = std::discrete_distribution<>(life_span.weight_hunter_gatherer_male.begin(), life_span.weight_hunter_gatherer_male.end());
++i;
}
}

Expand Down Expand Up @@ -315,7 +312,6 @@ namespace paxs {
inputMtDNA_Region(japan_provinces_path);
inputDistrict(japan_provinces_path);
inputLifeSpan(japan_provinces_path);

}

/// @brief
Expand Down Expand Up @@ -488,7 +484,6 @@ namespace paxs {
//std::vector<std::uint_least32_t> mtdna_region_hash_list; // mtDNA ハッシュ計算用
std::vector<std::string> mtdna_list; // mtDNA
lifeSpan life_span;

};

}
Expand Down
30 changes: 10 additions & 20 deletions Library/PAX_SAPIENTICA/Simulation/Settlement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ namespace paxs {
// 妊娠していたら婚姻しない(婚姻可能と定義すると再婚者のデータで上書きされ子供への継承が不自然になる)
if (female.getBirthIntervalCount() > 0) continue;
// 婚姻するか乱数で決定
if (!isMarried(female.getAge())) continue;
if (!isMarried(female.getAgeSizeT(), female.cgetFarming() > 0)) continue;

// 集落グリッドを重み付け
if (close_settlements_list_probabilities.size() == 0) {
Expand Down Expand Up @@ -842,7 +842,7 @@ namespace paxs {
}
}
// 出産可能かどうか
else if (agent.isAbleToGiveBirth() && isAbleToGiveBirth(agent.getAge())) {
else if (agent.isAbleToGiveBirth() && isAbleToGiveBirth(agent.getAgeSizeT(), agent.cgetFarming() > 0)) {
agent.setBirthIntervalCount(SimulationConstants::getInstance()->birth_interval);
}

Expand Down Expand Up @@ -895,30 +895,20 @@ namespace paxs {

/// @brief Is the agent married?
/// @brief 確率で結婚するかどうかを返す
bool isMarried(const double age) noexcept {
bool isMarried(const std::size_t age, const bool is_agricultural) noexcept {
// 婚姻可能年齢の上限値以上だったら結婚しない
if (age >= SimulationConstants::getInstance()->female_marriageable_age_max) return false;
auto x = [](double age) { return (age - SimulationConstants::getInstance()->female_marriageable_age_min_f64) / SimulationConstants::getInstance()->marriageable_age_constant; };
auto weight = [=](double age) {
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);
};

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

const double threshold = SimulationConstants::getInstance()->getMarriageProbability(age, is_agricultural);
if (threshold == 0.0) return false;
if (threshold >= 1.0) return true;
return SimulationConstants::getInstance()->random_dist(*gen) < threshold;
}

/// @brief Is able to give birth?
/// @brief 確率で出産するかどうかを返す
bool isAbleToGiveBirth(const double age) noexcept {
//return true;// 毎回出産
auto x = [](double age) { return (age - SimulationConstants::getInstance()->pregnant_age_min_f64) / SimulationConstants::getInstance()->childbearing_age_constant; };
auto weight = [=](double age) {
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);
};

const double threshold = static_cast<double>(weight(age)) * (SimulationConstants::getInstance()->childbearing_age_threshold / SimulationConstants::getInstance()->childbearing_age_all_weight); // (16 / 101.8);

bool isAbleToGiveBirth(const std::size_t age, const bool is_agricultural) noexcept {
const double threshold = SimulationConstants::getInstance()->getChildbearingProbability(age, is_agricultural);
if (threshold == 0.0) return false;
if (threshold >= 1.0) return true;
return SimulationConstants::getInstance()->random_dist(*gen) < threshold;
}
};
Expand Down
1 change: 1 addition & 0 deletions Library/PAX_SAPIENTICA/Simulation/SettlementAgent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ namespace paxs {
/// @brief Get the agent's age.
/// @brief エージェントの年齢を取得する
float getAge() const noexcept { return age / static_cast<float>(SimulationConstants::getInstance()->steps_per_year); }
std::size_t getAgeSizeT() const noexcept { return static_cast<std::size_t>(age) / static_cast<std::size_t>(SimulationConstants::getInstance()->steps_per_year); }

constexpr AgeType getAgeInt() const noexcept { return age; }

Expand Down
Loading

0 comments on commit 4333a1e

Please sign in to comment.