public void Stop() { Durations.Add(new Duration { Start = LastStartDate ?? DateTimeOffset.Now, End = DateTimeOffset.Now }); LastStartDate = null; }
public void Update(bool inFlow, IDataPacketJSON packet) { if (inFlow == true) { CarCount += packet.interactions.Count; return; } else { foreach (var interaction in packet.interactions) { CarCount--; double duration = interaction.duration; Sum += duration; if (Durations.Count == MAX_STORE) { double removed = Durations[0]; Durations.RemoveAt(0); Sum -= removed; } Durations.Add(duration); MeanDuration = Sum / Durations.Count; } } IDevice dev = Dictionaries.Devices[packet.deviceID]; int nodeBID = dev.Edge.NodeB.NodeID; Ellipse e = Dictionaries.NodeEllipses[nodeBID]; try { e.Dispatcher.Invoke(() => { if (MeanDuration < ORANGE_THRESHOLD) { e.Fill = new SolidColorBrush(Colors.GreenYellow); } else if (MeanDuration < RED_THRESHOLD) { e.Fill = new SolidColorBrush(Colors.Orange); } else { e.Fill = new SolidColorBrush(Colors.Red); } }); } catch { } Dictionaries.SetColours(); }
public Task Execute(IJobExecutionContext context) { DateTime now = DateTime.UtcNow; log.Info("Fire time: " + now); if (lastFireTime != null) { Durations.Add(now - lastFireTime.Value); } lastFireTime = now; return(Task.CompletedTask); }
private void CalculateTrip() { for (var i = 0; i < Coordinates.Count; i++) { Legs.Add(new List <DirectionSteps>()); Distances.Add(new List <double>()); Durations.Add(new List <double>()); for (var j = 0; j < Coordinates.Count; j++) { Legs[i].Add(new DirectionSteps()); Distances[i].Add(0); Durations[i].Add(0); } } GetDistTable(0, 0); BestPath = new List <int>(); NextSet = new List <int>(); BestTrip = MaxTripSentry; var numActive = Coordinates.Count; var numCombos = 1 << Coordinates.Count; var c = new List <List <double> >(); var parent = new List <List <int> >(); for (var i = 0; i < numCombos; i++) { c.Add(new List <double>()); parent.Add(new List <int>()); for (var j = 0; j < numActive; ++j) { c[i].Add(0.0); parent[i].Add(0); } } int index; for (var k = 1; k < numActive; ++k) { index = 1 + (1 << k); c[index][k] = Durations[0][k]; } for (var s = 3; s <= numActive; ++s) { for (var i = 0; i < numActive; ++i) { NextSet.Add(0); } index = NextSetOf(s); while (index >= 0) { for (var k = 1; k < numActive; ++k) { if (NextSet[k] != 0) { var previousIndex = index - (1 << k); c[index][k] = MaxTripSentry; for (var m = 1; m < numActive; ++m) { if (NextSet[m] != 0 && m != k) { if (c[previousIndex][m] + Durations[m][k] < c[index][k]) { c[index][k] = c[previousIndex][m] + Durations[m][k]; parent[index][k] = m; } } } } } index = NextSetOf(s); } } for (var i = 0; i < numActive; ++i) { BestPath.Add(0); } index = (1 << numActive) - 1; var currentNode = -1; BestPath.Add(0); for (var i = 1; i < numActive; ++i) { if (c[index][i] + Durations[i][0] < BestTrip) { BestTrip = c[index][i] + Durations[i][0]; currentNode = i; } } BestPath[numActive - 1] = currentNode; for (var i = numActive - 1; i > 0; --i) { currentNode = parent[index][currentNode]; index -= 1 << BestPath[i]; BestPath[i - 1] = currentNode; } }
private void CalculateTrip() { for (int i = 0; i < Coordinates.Count; i++) { Legs.Add(new List <DirectionSteps>()); Distances.Add(new List <double>()); Durations.Add(new List <double>()); for (int j = 0; j < Coordinates.Count; j++) { Legs[i].Add(new DirectionSteps()); Distances[i].Add(0); Durations[i].Add(0); } } GetDistTable(0, 0); BestPath = new List <int>(); double minDistance = -1; for (int i = 1; i < Coordinates.Count; i++) { List <int> coordinatesIndex = new List <int>(); for (int j = 1; (j < Coordinates.Count); j++) { if (j == i) { continue; } coordinatesIndex.Add(j); } var coordinatesIndexPermutation = GetPermutations(coordinatesIndex, coordinatesIndex.Count); List <List <int> > listCoordinatesIndexPermutationComplete = new List <List <int> >(); foreach (var coordinateIndexPermutation in coordinatesIndexPermutation) { var coordinateIndexPermutationTemp = new List <int> { 0 }; coordinateIndexPermutationTemp.AddRange(coordinateIndexPermutation); coordinateIndexPermutationTemp.Add(i); listCoordinatesIndexPermutationComplete.Add(coordinateIndexPermutationTemp); } // get min foreach (var coordinatesIndexPermutationComplete in listCoordinatesIndexPermutationComplete) { double pathDistance = 0; for (int j = 0; j < coordinatesIndexPermutationComplete.Count - 1; j++) { pathDistance += Distances[coordinatesIndexPermutationComplete[j]][coordinatesIndexPermutationComplete[j + 1]]; } if (minDistance < 0 || pathDistance < minDistance) { BestPath = coordinatesIndexPermutationComplete; minDistance = pathDistance; } } } // get min of results is best path }