public static double[,] FromTimeSpanMatrix(TimeSpan[,] values) { double[,] result = new double[values.GetLength(0), values.GetLength(1)]; for (int rowindex = 0; rowindex < values.GetLength(0); ++rowindex) { for (int columnindex = 0; columnindex < values.GetLength(1); ++columnindex) { result[rowindex, columnindex] = FromTimeSpanScalar(values[rowindex, columnindex]); } } return(result); }
public static double[,] FromTimeSpan(this TimeSpan[,] timespans) { var nbRow = timespans.GetLength(0); var nbCol = timespans.GetLength(1); var result = new double[nbRow, nbCol]; for (var i = 0; i < nbRow; i++) { for (var j = 0; j < nbCol; j++) { result[i, j] = timespans[i, j].TotalSeconds; } } return(result); }
/// <summary> /// /// </summary> /// <param name="timetable">The timetable</param> /// <param name="station">The station</param> /// <param name="latestTime">The latest time the user can arrive at the station</param> /// <returns></returns> static int GetStationArrivalTimeIndex(TimeSpan[,] timetable, Stations?station, TimeSpan latestTime) { int lastTimeIndex = timetable.GetLength(1) - 1; while (lastTimeIndex > 0 && timetable[(int)station, lastTimeIndex] >= latestTime) { --lastTimeIndex; } return(lastTimeIndex); }
protected virtual TestResult[] PostProcessResults(Delegate[] testCases, TimeSpan[,] results, string[,] ErrTxt) { Int32 numberTestCases = results.GetLength(0); TestResult[] retVal = new TestResult[numberTestCases]; TimeSpan lowestMedian = TimeSpan.MaxValue; for (int i = 0; i < numberTestCases; ++i) { retVal[i] = new TestResult(); retVal[i].TestResults = new TimeSpan[_numberRuns]; retVal[i].ErrorDescription = new string[_numberRuns]; for (int j = 0; j < _numberRuns; ++j) { retVal[i].TestResults[j] = results[i, j]; retVal[i].ErrorDescription[j] = ErrTxt[i, j]; } retVal[i].TestName = testCases[i].Method.Name; TimeSpan min, max; TimeSpan cumTotal = TimeSpan.Zero; double cumTotalSqred = 0.0; min = max = results[i, 0]; for (int j = 0; j < _numberRuns; ++j) { min = min > results[i, j]? results[i, j] : min; max = max < results[i, j]? results[i, j] : max; cumTotal += results[i, j]; cumTotalSqred += (results[i, j].TotalMilliseconds) * (results[i, j].TotalMilliseconds); } retVal[i].Mean = TimeSpan.FromMilliseconds(cumTotal.TotalMilliseconds / _numberRuns); retVal[i].Min = min; retVal[i].Max = max; TimeSpan[] sortedResults = new TimeSpan[_numberRuns]; retVal[i].TestResults.CopyTo(sortedResults, 0); Array.Sort(sortedResults); if (_numberRuns == 1) { retVal[i].Median = sortedResults[0]; } else if (_numberRuns == 2) { retVal[i].Median = TimeSpan.FromMilliseconds(sortedResults[0].TotalMilliseconds / 2 + sortedResults[1].TotalMilliseconds / 2); } else if (_numberRuns % 2 == 0) { retVal[i].Median = TimeSpan.FromMilliseconds(sortedResults[_numberRuns / 2].TotalMilliseconds / 2 + sortedResults[_numberRuns / 2 + 1].TotalMilliseconds / 2); } else { retVal[i].Median = sortedResults[_numberRuns / 2]; } if (lowestMedian > retVal[i].Median) { lowestMedian = retVal[i].Median; } double stddevSqrd = ((_numberRuns * cumTotalSqred - ((cumTotal.TotalMilliseconds) * (cumTotal.TotalMilliseconds))) / (_numberRuns * (_numberRuns - 1))); retVal[i].StdDev = TimeSpan.FromMilliseconds(Math.Sqrt(stddevSqrd)); } for (int i = 0; i < numberTestCases; ++i) { retVal[i].NormalizedTestDuration = (float)(retVal[i].Median.TotalMilliseconds) / (float)(lowestMedian.TotalMilliseconds); } return(retVal); }
public static bool CheckArraySize2(TimeSpan[,] workHours) { return(workHours.GetLength(0) == 6 && workHours.GetLength(1) == 2); }