/// <summary> /// Create a new FlightSimulator object /// </summary> /// <param name="aircraft">The aircraft that will be used in the simulation</param> /// <param name="endPoint">The position the aircraft will fly towards</param> /// <param name="numberOfSegments">The number of segments used in the simulation. The simulation starts and ends with a straight segment, so the number of segments should be odd.</param> /// <param name="settings">The control parameters, which are a list of doubles between 0 and 1. The number of controls needed for any number of segments can be calculated by calling TrajectoryChromosome.ChromosomeLength().</param> public FlightSimulator(ISimulatorModel aircraft, Point3D endPoint, int numberOfSegments, List <double> settings, TrajectoryGenerator trajectoryGenerator) { _trajectoryGenerator = trajectoryGenerator; _settings = settings; _vertical_state = VERTICAL_STATE.TAKEOFF; _aircraft = aircraft; _speed = 160; _x = 0; _y = 0; _heading = Math.PI / 2; _endPoint = endPoint; _numberOfSegments = numberOfSegments; _segmentIndex = 1; }
protected void OneTrajectoryINM() { var aircraft = new Aircraft("GP7270", "wing"); var trajectoryGenerator = new TrajectoryGenerator(aircraft, referencePoint); if (_view.TrajectoryFile.Contains(".")) { var reader = new TrajectoryFileReader(CoordinateUnit.metric, trajectoryGenerator); trajectory = reader.CreateTrajectoryFromFile(_view.TrajectoryFile); } trajectory.Aircraft = aircraft; noiseModel = new IntegratedNoiseModel(trajectory, aircraft); bool integrateToCurrentPosition = true; int metric = 0; switch (_view.NoiseMetric) { case 0: metric = 1; integrateToCurrentPosition = false; break; case 1: metric = 1; break; case 2: metric = 0; break; case 3: metric = 2; break; case 4: metric = 3; break; } noiseModel.IntegrateToCurrentPosition = integrateToCurrentPosition; noiseModel.NoiseMetric = metric; noiseModel.StartCalculation(ProgressChanged); temporalGrid = noiseModel.TemporalGrid; _view.Invoke(delegate { _view.NoiseCalculationCompleted(); }); }
private void Test_Load(object sender, EventArgs e) { var aircraft = new Aircraft("GP7270", "wing"); var generator = new TrajectoryGenerator(aircraft, new ReferencePointRD()); var reader = new TrajectoryFileReader(CoordinateUnit.metric, generator); var trajectory = reader.CreateTrajectoryFromFile(Globals.currentDirectory + "track_schiphol.dat"); for (int t = 0; t < trajectory.Duration; t++) { chartGroundPath.Series["Groundpath"].Points.AddXY(trajectory.Longitude(t), trajectory.Latitude(t)); } AutoScaleChart(chartGroundPath); chartGroundPath.ChartAreas[0].AxisY.LabelStyle.Format = "{0.00}"; chartGroundPath.ChartAreas[0].AxisX.LabelStyle.Format = "{0.00}"; chartGroundPath.Series["Groundpath"].ChartType = SeriesChartType.FastLine; for (int t = 0; t < trajectory.Duration; t++) { chartAltitude.Series["Altitude [m]"].Points.AddXY(t, trajectory.Z(t)); } chartAltitude.Series["Altitude [m]"].ChartType = SeriesChartType.FastLine; /* * var reader = new TrajectoryFileReader(CoordinateUnit.metric); * trajectory = reader.createTrajectoryFromFile(Globals.currentDirectory + "track_schiphol.dat"); * * aircraft = new Aircraft("GP7270", "wing"); * noiseModel = new IntegratedNoiseModel(trajectory, aircraft); * noiseModel.StartCalculation(progressChanged); * * var legend = new LegendCreator(); * legend.OutputLegendImage(); * legend.OutputLegendTitle(); * * TemporalGrid temporalGrid = noiseModel.TemporalGrid; * //temporalGrid.LowerLeftCorner = new Point3D(104062, 475470, 0, CoordinateUnit.metric); * //temporalGrid.GridSize = 125; * * var population = new PopulationData(Globals.currentDirectory + "population.dat"); * * var camera = new FollowKMLAnimatorCamera(aircraft, trajectory); * var sections = new List<KMLAnimatorSectionInterface>() { * new LegendKMLAnimator(), * new AircraftKMLAnimator(aircraft, trajectory), * new AirplotKMLAnimator(trajectory), * new GroundplotKMLAnimator(trajectory), * new ContourKMLAnimator(temporalGrid, trajectory, new List<int>() { 65, 70, 75 }), * new AnnoyanceKMLAnimator(temporalGrid, population.getPopulationData()) * }; * var animator = new KMLAnimator(sections, camera); * animator.AnimationToFile(trajectory.Duration, Globals.currentDirectory + "test.kml"); * * GoogleEarthServerForm googleEarthForm = new GoogleEarthServerForm(); * * this.Hide(); * googleEarthForm.Closed += (s, args) => this.Close(); * googleEarthForm.Show(); */ }
public Form1() { InitializeComponent(); //Create a list of waypoints List <Pose2d> waypoints = new List <Pose2d>(3); waypoints.Add(new Pose2d(new Translation2d(0, 0), Rotation2d.fromDegrees(0))); waypoints.Add(new Pose2d(new Translation2d(100, 20), Rotation2d.fromDegrees(0))); waypoints.Add(new Pose2d(new Translation2d(254.8, 50.87), Rotation2d.fromDegrees(45))); // For a reversed trajectory List <Pose2d> waypoints_maybe_flipped = waypoints; Pose2d flip = Pose2d.fromRotation(new Rotation2d(-1, 0, false)); if (false) { waypoints_maybe_flipped = new List <Pose2d>(waypoints.Count); for (int i = 0; i < waypoints.Count; ++i) { waypoints_maybe_flipped.Add(waypoints[i].transformBy(flip)); } } //Create a list of splines between each pair of waypoints List <QuinticSpline> splines = new List <QuinticSpline>(waypoints.Count - 1); for (int i = 1; i < waypoints.Count; ++i) { splines.Add(new QuinticSpline(waypoints[i - 1], waypoints[i])); } //Doesnt do much for simple curves //Optimize spline based on curvature QuinticSpline.optimizeSpline(ref splines); Console.WriteLine("Spline Unsegmented"); foreach (QuinticSpline S in splines) { for (double t = 0; t <= 1; t += 1 / 100.0) { Console.WriteLine(S.getPoint(t).x() + " , " + S.getPoint(t).y() + " , " + S.getHeading(t).getDegrees()); } } Console.WriteLine("Spline Combined and Segmented"); //Create the untimed trajectory (Splines into segment generator) UntimedTrajectory trajectory = new UntimedTrajectory(SegmentedSplineGenerator.parameterizeSplines(splines)); for (int i = 0; i < trajectory.length(); i++) { double x = trajectory.getState(i).getTranslation().x(); double y = trajectory.getState(i).getTranslation().y(); double theta = trajectory.getState(i).getRotation().getDegrees(); double curvature = trajectory.getState(i).getCurvature(); double dCurvatureDs = trajectory.getState(i).getDCurvatureDs(); Console.WriteLine(i + " , " + x + " , " + y + " , " + theta + " , " + curvature + " , " + dCurvatureDs); } //For a reversed trajectory if (false) { List <Pose2dWithCurvature> flipped = new List <Pose2dWithCurvature>(trajectory.length()); for (int i = 0; i < trajectory.length(); ++i) { flipped.Add(new Pose2dWithCurvature(trajectory.getState(i).getPose().transformBy(flip), -trajectory.getState(i).getCurvature(), trajectory.getState(i).getDCurvatureDs())); } trajectory = new UntimedTrajectory(flipped); } Console.WriteLine("Trajectory"); TrajectoryContainer final_trajectory = TrajectoryGenerator.parameterizeTrajectory(false, trajectory, 2.0, 0.0, 0.0, 120.0, 120.0, 24.0, 20); final_trajectory.setDefaultVelocity(72.0 / 150.0); for (int i = 0; i < final_trajectory.length(); i++) { double x = final_trajectory.getState(i).get_state().getTranslation().x(); double y = final_trajectory.getState(i).get_state().getTranslation().y(); double position = Math.Sqrt(x * x + y * y); double theta = final_trajectory.getState(i).get_state().getRotation().getDegrees(); double time = final_trajectory.getState(i).get_t(); double velocity = final_trajectory.getState(i).get_velocity(); double accel = final_trajectory.getState(i).get_acceleration(); Console.WriteLine(time + " , " + position + " , " + velocity + " , " + accel); } }
private void TopView_Load(object sender, EventArgs e) { // Parse the file containing multiple trajectories string rawTrackData = File.ReadAllText(Globals.currentDirectory + "inbound.txt"); var _trackData = rawTrackData .Split('\n') .Select(q => q.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries) .Select(Convert.ToString) .ToArray() ) .ToArray(); // Define variables string flight_id = ""; var trajectories = new List <Trajectory>(); ReferencePoint referencePoint = new ReferencePoint(new GeoPoint3D(4.7066753, 52.3297923)); TrajectoryGenerator trajectoryGenerator = new TrajectoryGenerator(new Aircraft("GP7270", "wing"), referencePoint); // Loop through the positions of all trajectories for (int i = 0; i < _trackData.Length; i++) { // Switch to the next trajectory if (i == _trackData.Length - 1 || (_trackData[i][0] != flight_id && i > 0)) { trajectories.Add(trajectoryGenerator.GenerateTrajectory()); // Prepare next trajectory var aircraft = new Aircraft("GP7270", "wing"); trajectoryGenerator = new TrajectoryGenerator(aircraft, referencePoint); } // Prevent failing on empty lines if (_trackData[i].Count() == 0) { continue; } flight_id = _trackData[i][0]; // Parse the next position of the current trajectory //DateTime t = DateTime.Parse(_trackData[i][14]); double x = 0; double.TryParse(_trackData[i][4], out x); double y = 0; double.TryParse(_trackData[i][5], out y); double z = 0; double.TryParse(_trackData[i][6], out z); z = z * 0.3040 * 100; trajectoryGenerator.AddDatapoint(x, y, z, 200, 200000); } // Calculate the noise for each trajectory TemporalGrid temporalGrid = new TemporalGrid(); int counter = 0; foreach (Trajectory trajectory in trajectories) { counter++; Console.WriteLine(counter); if (counter > 15) { break; } var INM = new IntegratedNoiseModel(trajectory, trajectory.Aircraft); INM.RunINMFullTrajectory(); Grid grid = INM.TemporalGrid.GetGrid(0); Console.WriteLine(grid.LowerLeftCorner.X); Console.WriteLine(grid.LowerLeftCorner.Y); grid.ReferencePoint = referencePoint; temporalGrid.AddGrid(grid); } var camera = new TopViewKMLAnimatorCamera(new GeoPoint3D(4.7066753, 52.3297923, 22000)); var sections = new List <KMLAnimatorSectionInterface>() { new ContourKMLAnimator(temporalGrid), new MultipleGroundplotKMLAnimator(trajectories) }; var animator = new KMLAnimator(sections, camera); animator.Duration = 0; animator.AnimationToFile(temporalGrid.GetNumberOfGrids(), Globals.currentDirectory + "topview_fullpath.kml"); }
public double Evaluate(IChromosome chromosome) { try { var trajectoryChromosome = (TrajectoryChromosome)chromosome; var aircraft = new Boeing747_400(); var settings = new List <double>(); for (int i = 0; i < chromosome.Length; i++) { settings.Add((double)chromosome.GetGene(i).Value); } var startPoint = ReferencePoint.GeoPoint; var start = new GeoCoordinate(startPoint.Latitude, startPoint.Longitude); var endDLong = new GeoCoordinate(startPoint.Latitude, GeoEndPoint.Longitude); double xDistance = start.GetDistanceTo(endDLong); if (start.Longitude > GeoEndPoint.Longitude) { xDistance = -xDistance; } var endDLat = new GeoCoordinate(GeoEndPoint.Latitude, startPoint.Longitude); double yDistance = start.GetDistanceTo(endDLat); if (start.Latitude > GeoEndPoint.Latitude) { yDistance = -yDistance; } var endPoint = new Point3D(xDistance, yDistance); var trajectoryGenerator = new TrajectoryGenerator(new Aircraft("PW4056", "wing"), ReferencePoint); FlightSimulator = new FlightSimulator(aircraft, endPoint, trajectoryChromosome.NumberOfSegments, settings, trajectoryGenerator); FlightSimulator._speed = TakeoffSpeed; FlightSimulator._heading = TakeoffHeading * Math.PI / 180; var time = DateTime.Now; FlightSimulator.Simulate(); /* INTERNAL NOISE */ /* * var grid = FlightSimulator.NoiseMaxGrid; * //Console.WriteLine("calculated:"+grid.Data[159][159]); * double[][] noiseDataGrid = grid.Data; * var color = new Models.ColorMap(); * var cmap = color.Custom(noiseDataGrid); * Bitmap b = new Bitmap(200, 200); * LockBitmap l = new LockBitmap(b); * l.LockBits(); * for (int x = 0; x < noiseDataGrid.Length - 1; x++) * { * for (int y = 0; y < noiseDataGrid[0].Length - 1; y++) * { * l.SetPixel(x, y, Color.FromArgb(Math.Max(0,cmap[x, y, 0]), Math.Max(cmap[x, y, 1],0), Math.Max(cmap[x,y,2], 0))); * } * } * l.UnlockBits(); * b.Save(@"noise.png", ImageFormat.Png); */ /* * TemporalGrid temporalGrid = noiseModel.TemporalGrid; * GridConverter converter = new GridConverter(temporalGrid, GridTransformation.MAX); * Grid last = converter.transform().GetGrid(temporalGrid.GetNumberOfGrids() - 1); */ /* POPULATION */ var trajectory = FlightSimulator.CreateTrajectory(); double boundary = 2000; int width = (int)(trajectory.UpperRightPoint.X - trajectory.LowerLeftPoint.X + boundary + boundary) / 125; int height = (int)(trajectory.UpperRightPoint.Y - trajectory.LowerLeftPoint.Y + boundary + boundary) / 125; Point3D shiftedLeftPoint = new Point3D(trajectory.LowerLeftPoint.X - boundary, trajectory.LowerLeftPoint.Y - boundary); Grid populationGrid = Grid.CreateEmptyGrid(height, width, shiftedLeftPoint, ReferencePoint, 125); PopulationData.FillGrid(populationGrid); var noiseDataGrid = populationGrid.Data; var color = new Models.ColorMap(); var cmap = color.Custom(noiseDataGrid); var b = new Bitmap(noiseDataGrid.Length, noiseDataGrid[0].Length); var l = new LockBitmap(b); l.LockBits(); for (int x = 0; x < noiseDataGrid.Length - 1; x++) { for (int y = 0; y < noiseDataGrid[0].Length - 1; y++) { int y_c = noiseDataGrid[0].Length - y - 1; l.SetPixel(x, y_c, Color.FromArgb(Math.Max(0, cmap[x, y, 0]), Math.Max(cmap[x, y, 1], 0), Math.Max(cmap[x, y, 2], 0))); } } l.UnlockBits(); b.Save("Population.png", ImageFormat.Png); /* INM */ var INMaircraft = new Aircraft("GP7270", "wing"); var noiseModel = new IntegratedNoiseModel(trajectory, INMaircraft); noiseModel.UsePopulationGrid(populationGrid, 100); noiseModel.NoiseMetric = 0; Console.WriteLine("INM started"); noiseModel.RunINMFullTrajectory(); Console.WriteLine("INM completed"); long awoken = 0; List <double[]> PopulatedAreaNoise = noiseModel.PopulatedAreaNoise; foreach (double[] pair in PopulatedAreaNoise) { //Console.WriteLine(pair[0] + " " + pair[1]); if (pair[1] <= 50.5) { continue; } awoken += (int)(pair[0] * 0.01 * (0.0087 * Math.Pow(pair[1] - 50.5, 1.79))); } Console.WriteLine(awoken + " people woke up :("); /* * //Console.WriteLine("INM:" + noiseModel.TemporalGrid.GetGrid(0).Data[160][160]); * noiseDataGrid = noiseModel.TemporalGrid.GetGrid(0).Data; * cmap = color.Custom(noiseDataGrid); * b = new Bitmap(noiseDataGrid.Length, noiseDataGrid[0].Length); * l = new LockBitmap(b); * l.LockBits(); * for (int x = 0; x < noiseDataGrid.Length - 1; x++) * { * for (int y = 0; y < noiseDataGrid[0].Length - 1; y++) * { * int y_c = noiseDataGrid[0].Length - y - 1; * l.SetPixel(x, y_c, Color.FromArgb(Math.Max(0,cmap[x, y, 0]), Math.Max(cmap[x, y, 1],0), Math.Max(cmap[x,y,2], 0))); * } * } * l.UnlockBits(); * b.Save("INM.png", ImageFormat.Png); */ Console.WriteLine(DateTime.Now.Subtract(time).TotalMilliseconds + "msec"); double fitness; if (OptimiseFuel) { fitness = FlightSimulator.fuel; } else { /* * Grid noiseMax = noiseModel.TemporalGrid.GetGrid(0); * double sum = 0; * for (int c = 0; c < noiseMax.Data.Length; c++) * { * for (int r = 0; r < noiseMax.Data[0].Length; r++) * { * sum += noiseMax.Data[c][r]; * } * } * return int.MaxValue - sum; */ fitness = awoken; } trajectory.Fitness = fitness; if (trajectories == null) { trajectories = new List <Trajectory>(); } trajectories.Add(trajectory); Best = (int)Math.Max(Best, fitness); return(int.MaxValue - fitness); } catch (Exception ex) { Console.WriteLine("Evaluation exception"); return(int.MaxValue); } }
/// <summary> /// Generations trajectory station data. /// </summary> /// <param name="numOfStations">The number of stations.</param> /// <param name="startMd">The start md.</param> /// <param name="mdUom">The MD index uom.</param> /// <param name="tvdUom">The Tvd uom.</param> /// <param name="angleUom">The angle uom.</param> /// <param name="inCludeExtra">True if to generate extra information for trajectory station.</param> /// <returns>The trajectoryStation collection.</returns> public List <TrajectoryStation> TrajectoryStations(int numOfStations, double startMd, MeasuredDepthUom mdUom = MdUom, WellVerticalCoordinateUom tvdUom = TvdUom, PlaneAngleUom angleUom = AngleUom, bool inCludeExtra = false) { return(TrajectoryGenerator.GenerationStations(numOfStations, startMd, mdUom, tvdUom, angleUom, inCludeExtra)); }