2017-12-03 18 views
-1

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

답변

0

당신은 빈 컬렉션 .Max() 또는 .Min()을 요구하고있다.

빈 콜렉션을 확인하십시오. if (!collection.Any()) ...을 사용하고 중단 한 다음 (입력 오류 인 경우) 알고리즘을 조정하여 처리하십시오.

+0

답장을 보내 주셔서 감사합니다. 알고리즘을 조정하여 이러한 종류의 수식을 의미합니까? // - 게다가 우리는 단지 먼 것들의 관련성을 완전히 없앴습니다 : if (distPerceptPop <0.4) distPerceptPop = 0; –

+0

나는 당신의 알고리즘으로 무엇을해야할지 모른다. 나는 당신이 그들이하는 일을 알고 있다고 생각한다. 빈 콜렉션의 경우 전혀 실행할 수없는 경우 스스로 결정해야하며, 그렇다면 어떻게해야하는지 또는 사용하는 기본값을 결정해야합니다. 아마도 최대 값으로 나눠서 0으로 나눌 수 없으므로 중단하는 것이 가장 적합합니다. –

0

피터가 말한 것처럼 빈 컬렉션에 Min()Max()을 호출하고 있습니다.

주변의 작업은 다음과 같습니다

double minPopAtt = attractPop.DefaultIfEmpty(-1).Min(); 

-1 경우 기본 값 컬렉션이 비어있을 것입니다.

+0

답장을 보내 주셔서 감사합니다. 나는 내 코드의이 부분에서 마지막 부분에 대해 말한 것을 시도했다. // ============================== ========================= // 두 목록의 매력도 값을 정규화합니다. double minPopAtt = attractPop.DefaultIfEmpty (-1) .Min(); double maxPopAtt = attractPop.DefaultIfEmpty (-1) .Max(); 하지만 아직도 C 언어로 익숙하지 않아 작동하지 않습니다. –

+0

첫 번째 것 (6 번째 줄)뿐만 아니라 사용하는 모든 Max() 및 Min() 줄을 수정해야합니다. – Haytam