I have just started to use Anylogic / JAVA and have assembled a process flowchart with agent components. The model includes extracting Histogram Data from a number of locations throughout the flowchart. I'm aiming to get the x%th percentile value of the histogram data such that I get the variable value (in this case queue and delay) that x% of the data is less than.
The help file suggests I can specify a low and high confidence value (i.e the x%th values) I wish to compute. However, during run time, I only see a CDF being shown in the graph and the percentiles are not available. How do I extract the percentile values post-simulation to display as an output? Is there a built-in way within Anylogic to do so?
The closest thing I found was the "getCDF function where I would have to write a custom function to find the closest index that yields the target x%th value. If I have to go the route of a custom function, I started the following code
I was hoping to pass to the function the individual Histogram Data objects as an argument and be able to use the Histogram Data methods within the function body. This does not work since the methods don't get recognized. What did I do wrong? The function is supposed to take in a variable histogram data object and given a specified percentile, calculate the pro-rated index value that yield the target percentile iterating through the getCDF function.
Thank you all for the help in advance!
While I cant confirm if your logic is correct there are a few basic mistakes in your code
HistogramSmartData
not object. That is why "the methods don't get recognized"You can verify the type of object by using code complete - see example below how I verified that a histogram data object that I dragged from the palette is of type HistogramSmartData
. After that you can lookup HistogramSmartData
in the help.
do while
syntax for your while loop - not how it is used in java ;-)It is either
do {
// Do stuff
} while (condition);
or
while (condition) {
// Do stuff
}
The code below works.
PS - screenshots are awesome - but code is better - if it was not for the text recognition on iPhones I used to convert your image to text I would not have answered this question ;-)
int index = 0;
int indexStart = roundToInt(histoName.getXMin());
int indexStop = roundToInt(histoName.getXMax());
double temp1 = 0;
double temp2 = 0;
double size = histoName.getIntervalWidth();
double result;
while (temp2 < percentile) {
index = indexStart;
temp1 = histoName.getCDF(index);
temp2 = histoName.getCDF(index+1);
index++;
}
result = index * (percentile-temp1) /(temp2-temp1)+(index-1)*(temp2-percentile)/(temp2-temp1);
return result;