-
Notifications
You must be signed in to change notification settings - Fork 1
/
ElevationCostRanges.cs
92 lines (80 loc) · 3.19 KB
/
ElevationCostRanges.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Author: Clément Hardy
using Landis.Library.UniversalCohorts;
using Landis.Core;
using Landis.SpatialModeling;
using System.Collections.Generic;
using System.IO;
using Landis.Library.Metadata;
using System;
using System.Diagnostics;
namespace Landis.Extension.ForestRoadsSimulation
{
/// <summary>
/// A class to contain the parameters relative to the elevation cost ranges
/// </summary>
public class ElevationCostRanges
{
private List<int> listOfLowerThresholds;
private List<int> listOfUpperThresholds;
private List<double> listOfCorrespondingValues;
private int numberOfRanges;
public int NumberOfRanges
{
get { return this.numberOfRanges; }
}
public ElevationCostRanges()
{
this.listOfLowerThresholds = new List<int>();
this.listOfUpperThresholds = new List<int>();
this.listOfCorrespondingValues = new List<double>();
this.numberOfRanges = 0;
}
/// <summary>
/// A function to add a range of elevation cost
/// </summary>
public void AddRange(int LowerThreshold, int UpperThreshold, double MultiplicativeValue)
{
this.listOfLowerThresholds.Add(LowerThreshold);
this.listOfUpperThresholds.Add(UpperThreshold);
this.listOfCorrespondingValues.Add(MultiplicativeValue);
this.numberOfRanges++;
}
/// <summary>
/// A function to verify if the ranges ae complementory, or if they are spaces between them.
/// </summary>
public void VerifyRanges()
{
// First, we check if the lower thresholds are always smaller than the UpperThresholds
for (int i = 0; i < this.numberOfRanges; i++)
{
if (this.listOfUpperThresholds[i] <= this.listOfLowerThresholds[i]) throw new Exception("FOREST ROADS SIMULATION ERROR : one of the upper thresholds for the elevation cost range is lower or equal to its associated lower threshold. This must be fixed." + PlugIn.errorToGithub);
}
// Then, we check if there are holes between the ranges
for (int i = 0; i < this.numberOfRanges - 1; i++)
{
if ((this.listOfUpperThresholds[i] - this.listOfLowerThresholds[i + 1]) != 0) throw new Exception("FOREST ROADS SIMULATION ERROR : There is a hole between the range of elevation " + i + " and " + (i+1) + ". This must be fixed." + PlugIn.errorToGithub);
}
}
/// <summary>
/// A function to get the multiplicative value associated with a certain value of fine elevation.
/// </summary>
public double GetCorrespondingValue(double Elevation)
{
for (int i = 0; i < this.numberOfRanges; i++)
{
if (Elevation < this.listOfUpperThresholds[i] && Elevation >= this.listOfLowerThresholds[i]) return (this.listOfCorrespondingValues[i]);
}
throw new Exception("FOREST ROADS SIMULATION ERROR : Couldn't find the value associated to the elevation value : " + Elevation + ". Please check you parameter file." + PlugIn.errorToGithub);
}
/// <summary>
/// A function for debugging purposes, to display the ranges in a console.
/// </summary>
public void DisplayRangesInConsole(ICore ModelCore)
{
for (int i = 0; i < this.numberOfRanges; i++)
{
ModelCore.UI.WriteLine(" Lower : " + this.listOfLowerThresholds[i] + "; Upper : " + this.listOfUpperThresholds[i] + "; Associated Value : " + this.listOfCorrespondingValues[i]);
}
}
}
}