public void WriteSlicesUsingTimeFilterShouldBeTheSameAsUsingIndexFilter() { var network = CreateNetwork(); var networkCoverage = new NetworkCoverage("test", true) { Network = network }; var locations = new[] { new NetworkLocation(network.Branches[0], 0.0), new NetworkLocation(network.Branches[0], 100.0), new NetworkLocation(network.Branches[1], 100.0) }; networkCoverage.SetLocations(locations); networkCoverage.Locations.FixedSize = locations.Length; var networkCoverage2 = new NetworkCoverage("test", true) { Network = network }; networkCoverage2.SetLocations(locations); networkCoverage2.Locations.FixedSize = locations.Length; // set 1000 values using time filters in coverage 1 and 2 var startTime = new DateTime(2000, 1, 1); for (int i = 0; i < 1000; i++) { IEnumerable <double> values = new[] { 1.0, 2.0, 3.0 }.Select(d => d * i); DateTime currentTime = startTime.AddMinutes(i); //set values for coverage 1 using value filter networkCoverage.Time.AddValues(new[] { currentTime }); var timeValueFilter = new VariableValueFilter <DateTime>(networkCoverage.Time, currentTime); networkCoverage.SetValues(values, timeValueFilter); //set values for coverage 2 using index filter networkCoverage2.Time.AddValues(new[] { currentTime }); var timeIndexFilter = new VariableIndexRangeFilter(networkCoverage2.Time, i); networkCoverage2.SetValues(values, timeIndexFilter); } Assert.AreEqual(networkCoverage.Components[0].Values, networkCoverage2.Components[0].Values); }
public void WriteSlicesUsingTimeFilterShouldBeTheSameAsUsingIndexFilter() { var network = CreateNetwork(); var networkCoverage = new NetworkCoverage("test", true) { Network = network }; var locations = new[] { new NetworkLocation(network.Branches[0], 0.0), new NetworkLocation(network.Branches[0], 100.0), new NetworkLocation(network.Branches[1], 100.0) }; networkCoverage.SetLocations(locations); networkCoverage.Locations.FixedSize = locations.Length; var networkCoverage2 = new NetworkCoverage("test", true) { Network = network }; networkCoverage2.SetLocations(locations); networkCoverage2.Locations.FixedSize = locations.Length; // set 1000 values using time filters in coverage 1 and 2 var startTime = new DateTime(2000, 1, 1); for (int i = 0; i < 1000;i++ ) { IEnumerable<double> values = new[] { 1.0, 2.0, 3.0 }.Select(d => d * i); DateTime currentTime = startTime.AddMinutes(i); //set values for coverage 1 using value filter networkCoverage.Time.AddValues(new[] { currentTime }); var timeValueFilter = new VariableValueFilter<DateTime>(networkCoverage.Time, currentTime); networkCoverage.SetValues(values,timeValueFilter); //set values for coverage 2 using index filter networkCoverage2.Time.AddValues(new[] { currentTime }); var timeIndexFilter = new VariableIndexRangeFilter(networkCoverage2.Time, i); networkCoverage2.SetValues(values, timeIndexFilter); } Assert.AreEqual(networkCoverage.Components[0].Values,networkCoverage2.Components[0].Values); }
public void AddingTimeSlicesShouldBeFastUsingMemoryStore() { var random = new Random(); //50 branches var network = RouteHelperTest.GetSnakeNetwork(false, 50); //10 offsets var offsets = new[] { 0, 10, 20, 30, 40, 50, 60, 70, 80, 90 }; //500 locations var locations = offsets.SelectMany(o => network.Branches, (o, b) => new NetworkLocation(b, o)).ToList(); var values = (from o in locations select (double)random.Next(100) / 10).ToList(); //setup the coverage with fixed size locations var networkCoverage = new NetworkCoverage() { IsTimeDependent = true, Network = network }; networkCoverage.Locations.FixedSize = 500; networkCoverage.Locations.SetValues(locations.OrderBy(l => l)); var startTime = new DateTime(2000, 1, 1); // add 10000 slices in time.. var times = from i in Enumerable.Range(1, 1000) select startTime.AddDays(i); int outputTimeStepIndex = 0; //write like a flowmodel .. TestHelper.AssertIsFasterThan(2000, () => { foreach (var t in times) { //high performance writing. Using indexes instead of values. var locationsIndexFilter = new VariableIndexRangeFilter(networkCoverage.Locations, 0, networkCoverage.Locations. FixedSize - 1); //current timestep starts at 1 and is increased before outputvalues are set now..hence -2 to get a 0 for the 1st //int timeIndex = currentTimeStep - 1; var timeIndexFilter = new VariableIndexRangeFilter(networkCoverage.Time, outputTimeStepIndex); networkCoverage.Time.AddValues(new[] { t }); networkCoverage.SetValues(values, new[] { locationsIndexFilter, timeIndexFilter }); outputTimeStepIndex++; } }); }