コード例 #1
0
        private static IEnumerator ProcessOptimalLine(string graphName, Conditions conditions, float exitSpeed, float exitAlt, float initialSpeed, float initialAlt, CostIncreaseFunction costIncreaseFunc, Predicate <float> neighborPredicate, float[,] predicateData, CostIncreaseFunction timeDifferenceFunc, CancellationTokenSource cancellationTokenSource, GraphableCollection graphables)
        {
            Task <List <AscentPathPoint> > task = Task.Factory.StartNew <List <AscentPathPoint> >(
                () =>
            {
                return(GetOptimalPath(conditions, exitSpeed, exitAlt, initialSpeed, initialAlt, costIncreaseFunc, neighborPredicate, predicateData, timeDifferenceFunc));
            }, cancellationTokenSource.Token
                );

            while (task.Status < TaskStatus.RanToCompletion)
            {
                //Debug.Log(manager.PercentComplete + "% done calculating...");
                yield return(0);
            }

            if (task.Status > TaskStatus.RanToCompletion)
            {
                if (task.Status == TaskStatus.Faulted)
                {
                    Debug.LogError("Wind tunnel task faulted");
                    Debug.LogException(task.Exception);
                }
                else if (task.Status == TaskStatus.Canceled)
                {
                    Debug.Log("Wind tunnel task was canceled.");
                }
                yield break;
            }

            List <AscentPathPoint> results = task.Result;

            if (timeDifferenceFunc != costIncreaseFunc)
            {
                ((MetaLineGraph)graphables[graphName]).SetValues(results.Select(pt => new Vector2(pt.speed, pt.altitude)).ToArray(), new float[][] { results.Select(pt => pt.climbAngle * Mathf.Rad2Deg).ToArray(), results.Select(pt => pt.climbRate).ToArray(), results.Select(pt => pt.cost).ToArray(), results.Select(pt => pt.time).ToArray() });
            }
            else
            {
                ((MetaLineGraph)graphables[graphName]).SetValues(results.Select(pt => new Vector2(pt.speed, pt.altitude)).ToArray(), new float[][] { results.Select(pt => pt.climbAngle * Mathf.Rad2Deg).ToArray(), results.Select(pt => pt.climbRate).ToArray(), results.Select(pt => pt.cost).ToArray() });
            }
            //this.GetOptimalPath(vessel, conditions, 1410, 17700, 0, 0, fuelToClimb, f => f > 0, excessP).Select(pt => new Vector2(pt.speed, pt.altitude)).ToArray());
            //((LineGraph)graphables["Time-Optimal Path"]).SetValues(
            //this.GetOptimalPath(vessel, conditions, 1410, 17700, 0, 0, timeToClimb, f => f > 0, excessP).Select(pt => new Vector2(pt.speed, pt.altitude)).ToArray());
        }
コード例 #2
0
        public static void CalculateOptimalLines(Conditions conditions, float exitSpeed, float exitAlt, float initialSpeed, float initialAlt, EnvelopePoint[,] dataArray, CancellationTokenSource cancellationTokenSource, GraphableCollection graphables)
        {
            float[,] accel    = dataArray.SelectToArray(pt => pt.Accel_excess * WindTunnelWindow.gAccel);
            float[,] burnRate = dataArray.SelectToArray(pt => pt.fuelBurnRate);
            float timeToClimb(PathSolverCoords current, PathSolverCoords last)
            {
                float dE = Math.Abs(WindTunnelWindow.gAccel * (last.y - current.y) / ((current.x + last.x) / 2) + (last.x - current.x));
                float P  = (accel[current.xi, current.yi] + accel[last.xi, last.yi]) / 2;

                return(dE / P);
            }

            float fuelToClimb(PathSolverCoords current, PathSolverCoords last)
            {
                float dF = (burnRate[current.xi, current.yi] + burnRate[last.xi, last.yi]) / 2;

                return(timeToClimb(current, last) * dF);
            }

            WindTunnelWindow.Instance.StartCoroutine(ProcessOptimalLine("Fuel-Optimal Path", conditions, exitSpeed, exitAlt, initialSpeed, initialAlt, fuelToClimb, f => f > 0, accel, timeToClimb, cancellationTokenSource, graphables));
            WindTunnelWindow.Instance.StartCoroutine(ProcessOptimalLine("Time-Optimal Path", conditions, exitSpeed, exitAlt, initialSpeed, initialAlt, timeToClimb, f => f > 0, accel, timeToClimb, cancellationTokenSource, graphables));
        }