private double CalculateProb(NodeXY node1, NodeXY node2, out double gradient, double dist) { gradient = node1.Height - node2.Height; double p; double g = (gradient / _initNodeHeight) * 100.0; double pp = Math.Sqrt(Math.Pow(_nodes[Target].Coords.X - node2.Coords.X, 2) + Math.Pow(_nodes[Target].Coords.Y - node2.Coords.Y, 2));; if (gradient > 0) { //p = gradient / (dist + 1); //p = gradient; //p = Math.Pow(pBase, gradient) / (dist + 1) + pSeed; p = Math.Pow(_pBase, g); } else if (gradient == 0) { p = Math.Pow(_pBase, g); //p = rng.NextDouble() / 10; //p = Math.Pow(pBase, gradient) / (dist + 1) + pSeed; //p = delta / Distance(w, currentNode); //p = delta / (dist + 1); //p = _delta; } else { p = Math.Pow(_pBase, g); //p = _omega; //p = omega / (gradient * -1) / (dist + 1); //p = _omega / (gradient * -1); //p = Math.Pow(pBase, gradient) / (dist + 1) + pSeed; } return(p / Math.Pow(5, pp)); }
private double CalculateErosion(NodeXY node1, NodeXY node2) { double gradient = node1.Height - node2.Height; double g = (gradient / _initNodeHeight) * 100.0; double erosion; if (gradient > 0.0) { //erosion = (_paramErosion / ((_nodes.Count - 1) * _populationSize)) * gradient; erosion = Math.Pow(_pEBase, gradient); } else if (gradient == 0.0) { erosion = _eFlat; //erosion = Math.Pow(pEBase_, gradient); } else { erosion = _eUp; //erosion = Math.Pow(pEBase_, gradient); } return(erosion); }
public Drop2() { sediment = 0; path = new List <int>(); pathLength = 0; bestPath = new List <int>(); bestPathLength = 999999; evaporated = false; canClimb = false; currentNode = null; }
private void ErodePath(Drop2 drop) { for (int i = 0; i < drop.path.Count - 1; i++) { NodeXY a = _nodes[drop.path[i]]; NodeXY b = _nodes[drop.path[i + 1]]; double erosion = CalculateErosion(a, b) / drop.pathLength; a.Height -= erosion; _erosionProduced += erosion; } }
private void moveDrop(Drop2 drop, double climbingProbability) { drop.evaporated = false; drop.canClimb = false; drop.path = new List <int>(); drop.pathLength = 0.0; drop.sediment = 0.0; drop.currentNode = _nodes[_source]; drop.path.Add(_source); double rC = _rng.NextDouble(); if (rC <= climbingProbability) { drop.canClimb = true; } while (drop.currentNode.Index != _target && !drop.evaporated) { int nextNodeIdx = PickNextNode(drop.currentNode); NodeXY nextNode = drop.currentNode.Neighbours[nextNodeIdx]; if (drop.path.Count >= _nodes.Count) { drop.evaporated = true; break; } drop.pathLength += drop.currentNode.NeighbourDistance[nextNodeIdx]; drop.currentNode = nextNode; drop.path.Add(nextNode.Index); } if (drop.evaporated) { } else { ErodePath(drop); if (drop.pathLength < drop.bestPathLength) { drop.bestPathLength = drop.pathLength; drop.bestPath = new List <int>(drop.path); } if (drop.pathLength < _bestPathLength) { _bestPathLength = drop.pathLength; _bestPath = new List <int>(drop.path); } } }
private int PickNextNode(NodeXY currentNode) { List <NodeXY> neighbours = currentNode.Neighbours; double[] probs = new double[neighbours.Count]; for (int i = 0; i < neighbours.Count; i++) { if (neighbours[i].Status == 1) { double gradient; probs[i] = CalculateProb(currentNode, neighbours[i], out gradient, currentNode.NeighbourDistance[i]); } } return(_rouletteWheel.ChooseAction(probs)); }