-
released this
2026-11-24 07:09:20 +00:00 | 0 commits to main since this releaseThe DOI of this source code: https://doi.org/10.58473/ChengZhuSci0003/04
Introduction: To order to analyze the succession pattern among different plant communities, my previous article has adopt the sampling method specifically aiming to characterize the frequency-size relations between sample plots, which is calculated by Bray-Curtis Dissimilarity index. The underlying theory with regards to the inter-species relationship is discussed correspondingly in detail; my previous article has also tried to improve the traditional knowledge of Hardy Weinberg's Equiliberum Law, by taking the factors of intra-species relationship and geographic separation into consideration. To simulate this process of newly proposed theory, this modeling project designs the model of plant molecular evolution.
Development language: C++;
All Rights Reserved.
Reference: Liu Huan (2024). Original Review of Biodiversity Conservation Progress in China: The Theories and Cases in Practice. Journal of Environment and Health Science (ISSN 2314-1628). 2024(04). https://doi.org/10.58473/JEHS0012
Copyrights Certificate Registered by Brock Chain Technology: Brock Chain ID. (2a6313a6252f4a61ea5865652b9113e8ace73fdfcc9d7fed88904d8de5441b14) ; Register Time: 2025-11-11 09:55.
Source Code:
//@ All rights reserved by Liu Huan. Source from: https://doi.org/10.58473/JEHS0012;
#include <iostream>
#include <vector>
#include <map>
#include <iomanip>
#include <tuple>
using namespace std;
int main() {
int I, J, K, N, S;
const double D=1.00; double E=0.30; double F=0.50;
cout << "=== Ecological Distribution Modeling ===" << endl;
cout << "Input the longitude grid scale (I): ";
cin >> I;
cout << "Input the latitude grid scale (J): ";
cin >> J;
cout << "Input the altitude grid scale (K): ";
cin >> K;
cout << "Input the amount of vegetation species (N): ";
cin >> N;
cout << "Input the sample amount (S-even number): ";
cin >> S;
if (S % 2 != 0) {
cout << "Error: sample amount 'S' must be the even number£¡" << endl;
return 1;
};vector<vector<vector<double>>> a(I, vector<vector<double>>(J, vector<double>(K))); vector<vector<vector<double>>> b(I, vector<vector<double>>(J, vector<double>(K))); vector<vector<vector<double>>> c(I, vector<vector<double>>(J, vector<double>(K))); vector<vector<vector<double>>> d(I, vector<vector<double>>(J, vector<double>(K))); vector<vector<vector<int>>> species(I, vector<vector<int>>(J, vector<int>(K))); vector<vector<vector<int>>> samplePlot(I, vector<vector<int>>(J, vector<int>(K))); cout << "\n=== Input the individual's abundance ===" << endl; for (int i = 0; i < I; i++) { for (int j = 0; j < J; j++) { for (int k = 0; k < K; k++) { cout << "abundance a[" << i << "][" << j << "][" << k << "]: "; cin >> a[i][j][k]; } } } cout << "\n=== Input the individual's frequency ===" << endl; for (int i = 0; i < I; i++) { for (int j = 0; j < J; j++) { for (int k = 0; k < K; k++) { cout << "frequency b[" << i << "][" << j << "][" << k << "]: "; cin >> b[i][j][k]; } } } cout << "\n=== Input the individual's relative size ===" << endl; for (int i = 0; i < I; i++) { for (int j = 0; j < J; j++) { for (int k = 0; k < K; k++) { cout << "Relative size c[" << i << "][" << j << "][" << k << "]: "; cin >> c[i][j][k]; } } } cout << "\n=== Input the species' identifier number for each individual ===" << endl; cout << "Species identifier number: from 0 to " << N - 1 << endl; for (int i = 0; i < I; i++) { for (int j = 0; j < J; j++) { for (int k = 0; k < K; k++) { int n; cout << "Species[" << i << "][" << j << "][" << k << "]: "; cin >> n; if (n < 0 || n >= N) { cout << "Error: Species identifier number must be from 0 to" << N - 1 << endl; return 1; } species[i][j][k] = n; } } } cout << "\n=== Input the sample's identifier number for each individual (0-" << S - 1 << ") ===" << endl; for (int i = 0; i < I; i++) { for (int j = 0; j < J; j++) { for (int k = 0; k < K; k++) { cout << "Individual(" << i << " " << j << " " << k << ")'s sample identifier: "; cin >> samplePlot[i][j][k]; if (samplePlot[i][j][k] < 0 || samplePlot[i][j][k] >= S) { cout << "Error: the sample's identifier number must be from 0 to " << S - 1 << endl; return 1; } } } } // To calculate the relative importance for each individual; for (int i = 0; i < I; i++) { for (int j = 0; j < J; j++) { for (int k = 0; k < K; k++) { d[i][j][k] = (a[i][j][k] + b[i][j][k] + c[i][j][k]) / 3.0; } } } // To calculate the dissimilarity between two samples of each pair; double totalDissimilarity = 0.0; vector<double> PairDissimilarity (S) ; for (int samplePair = 0; samplePair < S; samplePair += 2) { // To calculate the dissimilarity for each species; for (int n = 0; n < N; n++) { double sumSample1 = 0.0, sumSample2 = 0.0; int countSample1 = 0, countSample2 = 0; for (int i = 0; i < I; i++) { for (int j = 0; j < J; j++) { for (int k = 0; k < K; k++) { if (species[i][j][k] == n && samplePlot[i][j][k] == samplePair) { sumSample1 += d[i][j][k]; countSample1++; } if (species[i][j][k] == n && samplePlot[i][j][k] == samplePair + 1) { sumSample2 += d[i][j][k]; countSample2++; } } } } // To calculate the dissimilarity for each pair of samples; if (countSample1 > 0 || countSample2 > 0) { double speciesDissimilarity = abs(sumSample1 - sumSample2) / (sumSample1 + sumSample2); totalDissimilarity += speciesDissimilarity; PairDissimilarity[samplePair] = totalDissimilarity; } } cout << "Sample" <<" "<< samplePair <<" "<< "and Sample" <<" "<< samplePair + 1 << "'s dissimilarity: " << PairDissimilarity[samplePair] << endl; } // To calculate the sum of importance for the individuals in each sample; vector<double> sum_importance(S, 0.0); for (int i = 0; i < I; i++) { for (int j = 0; j < J; j++) { for (int k = 0; k < K; k++) { int currentSample = samplePlot[i][j][k]; sum_importance[currentSample] += d[i][j][k]; } } } // To input the dominant species' correlation between two samples of a pair; vector<double> correlation(S); cout << "\n To input the dominant species' correlation between two samples of a pair:" << endl; for (int samplePair = 0; samplePair < S; samplePair += 2) { int sample1 = samplePair; int sample2 = samplePair + 1; cout << "Sample" <<" "<< sample1 <<" "<< "and Sample" <<" "<< sample2 << "'s correlation: "; cin >> correlation[samplePair]; } vector<double> Genetic_Distance(S); cout << "\n To input the dominant species' genetic distance between two samples of a pair:" << endl; for (int samplePair = 0; samplePair < S; samplePair += 2) { int sample1 = samplePair; int sample2 = samplePair + 1; cout << "Sample" <<" "<< sample1 <<" "<< "and Sample" <<" "<< sample2 << "'s Genetic Distance: "; cin >> Genetic_Distance[samplePair]; } // To output the sum importance for each sample; cout << fixed << setprecision(2); cout << "\n=== Each sample's sum importance ===" << endl; for (int s = 0; s < S; s++) { cout << "Sample " <<" "<< s << " 's sum importance: " << sum_importance[s] << endl; } // To analyze the succession relationship; cout << "\n=== To analyze the succession relationship ===" << endl; for (int samplePair = 0; samplePair < S; samplePair += 2) { int sample1 = samplePair; int sample2 = samplePair + 1; double corr = correlation[samplePair]; double sum1 = sum_importance[sample1]; double sum2 = sum_importance[sample2]; double PairD = PairDissimilarity[samplePair]; if (PairD > D) { if (corr < -E) { if (sum1 > sum2) { cout << "Sample" <<" "<< sample1 <<" "<< "invade Sample" <<" "<< sample2 << endl; } else if (sum2 > sum1) { cout << "Sample" <<" "<< sample2 <<" "<< "invade Sample" <<" "<< sample1 << endl; } else { cout << "Sample" <<" "<< sample1 <<" "<< "and Sample" <<" "<< sample2 << " " <<"Stay in Stable state" << endl; } } else { cout << "Sample" <<" "<< sample1 <<" "<< "and Sample" <<" "<< sample2 << " " <<"Stay in Stable state" << endl; } } else { cout << "Sample" <<" "<< sample1 <<" "<< "and Sample" <<" "<< sample2 << " " <<"Stay in Stable state" << endl; } } // To analyze the evolution of genetic variation: » cout << "\n=== To analyze the evolution of genetic variation ===" << endl; for (int samplePair = 0; samplePair < S; samplePair += 2) { int sample1 = samplePair; int sample2 = samplePair + 1; double Genetics = Genetic_Distance[samplePair]; double sum1 = sum_importance[sample1]; double sum2 = sum_importance[sample2]; if (Genetics > F) { if (sum1 > sum2) { cout << "Sample" <<" "<< sample1 <<" "<< "invade Sample" <<" "<< sample2 << endl; } else if (sum2 > sum1) { cout << "Sample" <<" "<< sample2 <<" "<< "invade Sample" <<" "<< sample1 << endl; } else { cout << "Sample" <<" "<< sample1 <<" "<<"and Sample" <<" "<< sample2 << " " <<"Stay in Stable state" << endl; } } else { cout << "Sample" <<" "<< sample1 <<" "<<"and Sample" <<" "<< sample2 << " " <<"Stay in Stable state" << endl; } } cout << "\n=== To output the sum of relative importance for each species ===" << endl; map<int, vector<tuple<int, int, int, double>>> speciesData; for (int i = 0; i < I; i++) { for (int j = 0; j < J; j++) { for (int k = 0; k < K; k++) { int n = species[i][j][k]; speciesData[n].push_back(make_tuple(i, j, k, d[i][j][k])); } } } cout << fixed << setprecision(4); for (int n = 0; n < N; n++) { if (speciesData.find(n) != speciesData.end()) { cout << "\n Species " << n << " 's relative importance£¨Totally " << speciesData[n].size() << " individuals£©:" << endl; cout << "Individual (i,j,k) -> relative importance" << endl; cout << "--------------------------------" << endl; for (const auto& data : speciesData[n]) { int i = get<0>(data); int j = get<1>(data); int k = get<2>(data); double value = get<3>(data); cout << "(" << setw(2) << i << "," << setw(2) << j << "," << setw(2) << k << ") -> " << setw(10) << value << endl; } } else { cout << "\n Species " << n << " does not occur " << endl; } } cout << "\n=== Species distribution statistics ===" << endl; for (int n = 0; n < N; n++) { if (speciesData.find(n) != speciesData.end()) { int count = speciesData[n].size(); double percentage = (count * 100.0) / (I * J * K); cout << "Species " << n << ": " << count << " 's position (" << percentage << "%)" << endl; } } return 0;}
Downloads