私は現在、魅力のためのコードを作成しています。私のコンセプトでは、Population、Green Spaces、Residential Spacesのような因子に細胞を割り当てています。私は人口が緑の空間と緑の空間への居住空間に惹かれているこれらの要因の間に魅力の関係をコード化したい。私はいくつかのC#コンポーネントを持っていますが、これらのいくつかは、このシーケンスが要素エラーを含まないために動作していません。私はコード内でエラーを見つけることができないようだ、誰かがこれを修正する方法を知っていれば感謝します。ご協力ありがとうございました!シーケンスを修正する方法C#に要素エラーがありません?
//======================================================
// ------- compute the attractivity landscape ----------
//======================================================
// -- find the max distance value - usually the diagonal from first to last:
int nrLocations = Distances.BranchCount;
int nrDists = Distances.Branch(0).Count;
double maxDist = Distances.Branch(0)[nrDists - 1];
// -- the list store the attractivity values for population to green spaces and housing to green spaces
List<double> attractPop = new List<double>();
List<double> attractSpaces = new List<double>();
List<double> attractResid = new List<double>();
double maxPop = PopulDistrib.Max();
double maxSpaces = GreenSDistrib.Max();
double maxResid = ResiDistrib.Max();
for(int i = 0; i < nrLocations; i++)
{
// -- reset lists in each loop:
double curPopAttract = 0;
double curSpacesAttract = 0;
double curResidAttract = 0;
for(int k = 0; k < nrDists; k++)
{
double curPop = PopulDistrib[k]/maxPop; // population of all cells
double curSpaces = GreenSDistrib[k]/maxPop; // Green Spaces of all cells
double curResid = ResiDistrib[k]/maxResid; // Residential Spaces of all cells
// -- distances to all cells:
// -- index i = from current cell // index k = to other cells
// -- division by maxDist gives normalized values in the range [0; 1] for the distance
double curDist = Distances.Branch(i)[k]/maxDist;
// ** Remember: the distances are normalized! Therefore:
// ** (1 - distance) :: makes close things more important than distant ones.
// ** (Math.Pow(1-distance, 6); :: decrease the effect of the distance exponentially.
// ** The perception of people concerning things in a certain distance can now be expressed by:
double distPerceptPop = Math.Pow(1 - curDist, 7);
//Print("distPercept: " + distPerceptPop.ToString());
// -- in addition, we just cut the relevance of distant things completely:
if (distPerceptPop < 0.4) distPerceptPop = 0;
// -- corresponding "perception" of Green Spaces concerning things in a distance:
double distPerceptSpaces = Math.Pow(1 - curDist, 2);
// -- corresponding "perception" of Residential Space concerning things in a distance:
double distPerceptResid = Math.Pow(1 - curDist, 4);
// ----------- Attractivity Functions ----------------------
// -- define the functions for the attractivity ------------
// -- here we control, what is prefered by which land use --
// -- linear attractivity function -> can become more complex functions!!!
// -- people like to be close to Green Spaces:
curPopAttract += ((distPerceptPop) * curSpaces);
//double curAttract = ((distPerceptPop) * curPop);
//curPopAttract += curAttract;
//Print("attractivityPop: " + curPopAttract.ToString());
// -- people DON'T like to be close to other people:
//curPopAttract += 1- ((distPerceptPop) * curPop);
// -- people DON'T like to be close to other people, + but to workplaces:
//double weightImportWork = 0.3; // -- weighting factor to express the importancy to be close to workplaces in contrast to be away from other people
//curPopAttract += 1- ((distPerceptPop) * curPop) + weightImportWork * Math.Pow(1 - curDist, 2) * curWork;
// -- Residential Spaces like to be close to Green Spaces
curResidAttract += (distPerceptResid) * curSpaces;
// *** EXPERIMENT WITH THE ATTRACTIVITY FUNCTIONS ABOVE !!! **********************************
// *** You may also add additional relations similar to the other system dynamics examples ***
}
// -- collect the current values in the attractivity values lists:
attractPop.Add(curPopAttract);
attractSpaces.Add(curSpacesAttract);
attractResid.Add(curResidAttract);
}
//=======================================================
// -- normalize the attractivity values for both lists --
double minPopAtt = attractPop.Min();
double maxPopAtt = attractPop.Max();
double minSpacesAtt = attractSpaces.Min();
double maxSpacesAtt = attractSpaces.Max();
double minResidAtt = attractResid.Min();
double maxResidAtt = attractResid.Max();
// -- formula for normalization to the range [0; 1]:
// -- normalized valueOfList = (valueOfList - minValueOfList) * 1/maxValueOfList
for(int i = 0; i < attractPop.Count; i++)
{
attractPop[i] = (attractPop[i] - minPopAtt) * (1/maxPopAtt);
attractSpaces[i] = (attractSpaces[i] - minSpacesAtt) * (1/maxSpacesAtt);
attractResid[i] = (attractResid[i] - minResidAtt) * (1/maxResidAtt);
}
//=======================================================
// -- return the lists:
AttractPop = attractPop;
AttractSpaces = attractSpaces;
AttractResid = attractResid;
お返事ありがとうございました。アルゴリズムを調整して、この種の数式を意味していますか? // - さらに、遠く離れたものの関連性を完全に切り捨てます: if(distPerceptPop <0.4)distPerceptPop = 0; –
私はあなたのアルゴリズムをどうすればいいのかわかりません。空のコレクションの場合にはそれらを実行できるかどうか、もしそうであれば、どのように振る舞うべきか、あるいはどのようなデフォルト値を使うかは、自分で決定する必要があります。あなたが最大値で割っているので、0で割ることはできないので、おそらく中止が最も適しています。 –