Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit 84350f4b authored by Michael KRISPER's avatar Michael KRISPER
Browse files

performance Optimizations

parent ab7a204d
No related branches found
No related tags found
No related merge requests found
......@@ -279,13 +279,16 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
CycleIntervalIterator.LeftSample.RoadGradient);
}
/// <summary>
/// Progress of the distance in the driving cycle.
/// </summary>
public double Progress
{
get
{
return _data.Entries.Count > 0
? ((CurrentState.Distance - _data.Entries.First().Distance) /
(_data.Entries.Last().Distance - _data.Entries.First().Distance)).Value()
? (CurrentState.Distance.Value() - _data.Entries.First().Distance.Value()) /
(_data.Entries.Last().Distance.Value() - _data.Entries.First().Distance.Value())
: 0;
}
}
......
......@@ -57,7 +57,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
protected IDriverStrategy DriverStrategy;
private Dictionary<string, object> _coastData = new Dictionary<string, object>(20);
private string _currentAction = "";
public string CurrentAction = "";
//public MeterPerSquareSecond LookaheadDeceleration { get; protected set; }
......@@ -155,7 +155,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
IResponse previousResponse = null)
{
IterationStatistics.Increment(this, "Accelerate");
_currentAction = "Accelerate";
CurrentAction = "Accelerate";
Log.Debug("DrivingAction Accelerate");
var operatingPoint = ComputeAcceleration(ds, targetVelocity);
......@@ -235,7 +235,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
public IResponse DrivingActionCoast(Second absTime, Meter ds, MeterPerSecond maxVelocity, Radian gradient)
{
IterationStatistics.Increment(this, "Coast");
_currentAction = "Coast";
CurrentAction = "Coast";
Log.Debug("DrivingAction Coast");
return CoastOrRollAction(absTime, ds, maxVelocity, gradient, false);
......@@ -251,7 +251,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
/// <returns></returns>
public IResponse DrivingActionRoll(Second absTime, Meter ds, MeterPerSecond maxVelocity, Radian gradient)
{
_currentAction = "Roll";
CurrentAction = "Roll";
IterationStatistics.Increment(this, "Roll");
Log.Debug("DrivingAction Roll");
......@@ -357,7 +357,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
IResponse previousResponse = null, Meter targetDistance = null)
{
IterationStatistics.Increment(this, "Brake");
_currentAction = "Brake";
CurrentAction = "Brake";
Log.Debug("DrivingAction Brake");
IResponse retVal = null;
......@@ -765,7 +765,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
/// <returns></returns>
public IResponse DrivingActionHalt(Second absTime, Second dt, MeterPerSecond targetVelocity, Radian gradient)
{
_currentAction = "Halt";
CurrentAction = "Halt";
if (!targetVelocity.IsEqual(0) || !DataBus.VehicleStopped) {
Log.Error("TargetVelocity ({0}) and VehicleVelocity ({1}) must be zero when vehicle is halting!", targetVelocity,
DataBus.VehicleSpeed);
......
......@@ -36,6 +36,7 @@ using System.Drawing;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms.DataVisualization.Charting;
using TUGraz.VectoCommon.Exceptions;
using TUGraz.VectoCommon.Models;
......@@ -100,19 +101,22 @@ namespace TUGraz.VectoCore.Utils
foreach (var point in points) {
// If the vertex lies inside the circumcircle of a triangle, the edges of this triangle are
// added to the edge buffer and the triangle is removed from list.
var point1 = point;
var containerTriangles = triangles.FindAll(t => t.ContainsInCircumcircle(point1));
triangles = triangles.Except(containerTriangles).ToList();
// Remove duplicate edges. This leaves the convex hull of the edges.
// The edges in this convex hull are oriented counterclockwise!
var allEdges = containerTriangles.SelectMany(t => t.GetEdges()).ToList();
var groupedEdges = allEdges.GroupBy(edge => edge).ToList();
var convexHullEdges = groupedEdges.Where(group => group.Count() == 1).Select(group => group.Key).ToList();
var newTriangles = convexHullEdges.Select(edge => new Triangle(edge.P1, edge.P2, point)).ToList();
var newTriangles = triangles.Select((t, i) => Tuple.Create(i, t, t.ContainsInCircumcircle(point)))
.Where(t => t.Item3)
.Reverse()
.SelectMany(t => {
triangles.RemoveAt(t.Item1);
return t.Item2.GetEdges();
})
.GroupBy(edge => edge)
.Where(group => group.Count() == 1)
.Select(group => new Triangle(group.Key.P1, group.Key.P2, point)).ToList();
triangles.AddRange(newTriangles);
//DrawGraph(pointCount, triangles, superTriangle, xmin, xmax, ymin, ymax, point);
pointCount++;
......@@ -148,18 +152,18 @@ namespace TUGraz.VectoCore.Utils
}
}
/// <summary>
/// Draws the delaunay map (except supertriangle).
/// </summary>
[Conditional("TRACE")]
private static void DrawGraph(int i, List<Triangle> triangles, Triangle superTriangle, Point[] points, Point lastPoint = null)
private static void DrawGraph(int i, List<Triangle> triangles, Triangle superTriangle, Point[] points,
Point lastPoint = null)
{
var xmin = points.Min(p => p.X);
var xmax = points.Max(p => p.X);
var ymin = points.Min(p => p.Y);
var ymax = points.Max(p => p.Y);
using (var chart = new Chart { Width = 1000, Height = 1000 }) {
chart.ChartAreas.Add(new ChartArea("main") {
AxisX = new Axis { Minimum = Math.Min(xmin, xmin), Maximum = Math.Max(xmax, xmax) },
......
......@@ -58,6 +58,7 @@ namespace TUGraz.VectoCore.Utils
/// </remarks>
public class VectoCSVFile : LoggingObject
{
private static readonly Regex HeaderFilter = new Regex(@"\[.*?\]|\<|\>", RegexOptions.Compiled);
private const char Delimiter = ',';
private const char Comment = '#';
......@@ -162,9 +163,7 @@ namespace TUGraz.VectoCore.Utils
private static IEnumerable<string> GetColumns(string line, bool fullHeader = false)
{
if (!fullHeader) {
line = Regex.Replace(line, @"\[.*?\]", "");
line = line.Replace("<", "");
line = line.Replace(">", "");
line = HeaderFilter.Replace(line, "");
}
return line.Split(Delimiter).Select(col => col.Trim());
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment