저는 현재 매력적인 개념인데, 인구, 녹색 공간 및 주거 공간과 같은 요소에 세포를 할당하고 있습니다. 나는 인구가 녹색 공간과 녹색 공간에 주거 공간으로 끌리는 이러한 요소들 사이에 매력도 관계를 규정하고 싶다. 몇 가지 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으로 나눌 수 없으므로 중단하는 것이 가장 적합합니다. –