using Unity.Mathematics;
using System.Drawing;
using System.Text;
using BHJD.DEMdll.Public;
using Newtonsoft.Json;
namespace QuYuSaoMiao
{
public class LimitedConcurrencyLevelTaskScheduler : TaskScheduler
{
/// Whether the current thread is processing work items.
[ThreadStatic]
private static bool _currentThreadIsProcessingItems;
/// The list of tasks to be executed.
private readonly LinkedList _tasks = new LinkedList(); // protected by lock(_tasks)
/// The maximum concurrency level allowed by this scheduler.
private readonly int _maxDegreeOfParallelism;
/// Whether the scheduler is currently processing work items.
private int _delegatesQueuedOrRunning = 0; // protected by lock(_tasks)
///
/// Initializes an instance of the LimitedConcurrencyLevelTaskScheduler class with the
/// specified degree of parallelism.
///
/// The maximum degree of parallelism provided by this scheduler.
public LimitedConcurrencyLevelTaskScheduler(int maxDegreeOfParallelism)
{
if (maxDegreeOfParallelism < 1) throw new ArgumentOutOfRangeException("maxDegreeOfParallelism");
_maxDegreeOfParallelism = maxDegreeOfParallelism;
}
///
/// current executing number;
///
public int CurrentCount { get; set; }
/// Queues a task to the scheduler.
/// The task to be queued.
protected sealed override void QueueTask(Task task)
{
// Add the task to the list of tasks to be processed. If there aren't enough
// delegates currently queued or running to process tasks, schedule another.
lock (_tasks)
{
//Console.WriteLine("Task Count : {0} ", _tasks.Count);
_tasks.AddLast(task);
if (_delegatesQueuedOrRunning < _maxDegreeOfParallelism)
{
++_delegatesQueuedOrRunning;
NotifyThreadPoolOfPendingWork();
}
}
}
int executingCount = 0;
private static object executeLock = new object();
///
/// Informs the ThreadPool that there's work to be executed for this scheduler.
///
private void NotifyThreadPoolOfPendingWork()
{
ThreadPool.UnsafeQueueUserWorkItem(_ =>
{
// Note that the current thread is now processing work items.
// This is necessary to enable inlining of tasks into this thread.
_currentThreadIsProcessingItems = true;
try
{
// Process all available items in the queue.
while (true)
{
Task item;
lock (_tasks)
{
// When there are no more items to be processed,
// note that we're done processing, and get out.
if (_tasks.Count == 0)
{
--_delegatesQueuedOrRunning;
break;
}
// Get the next item from the queue
item = _tasks.First.Value;
_tasks.RemoveFirst();
}
// Execute the task we pulled out of the queue
base.TryExecuteTask(item);
}
}
// We're done processing items on the current thread
finally { _currentThreadIsProcessingItems = false; }
}, null);
}
/// Attempts to execute the specified task on the current thread.
/// The task to be executed.
///
/// Whether the task could be executed on the current thread.
protected sealed override bool TryExecuteTaskInline(Task task, bool taskWasPreviouslyQueued)
{
// If this thread isn't already processing a task, we don't support inlining
if (!_currentThreadIsProcessingItems) return false;
// If the task was previously queued, remove it from the queue
if (taskWasPreviouslyQueued) TryDequeue(task);
// Try to run the task.
return base.TryExecuteTask(task);
}
/// Attempts to remove a previously scheduled task from the scheduler.
/// The task to be removed.
/// Whether the task could be found and removed.
protected sealed override bool TryDequeue(Task task)
{
lock (_tasks) return _tasks.Remove(task);
}
/// Gets the maximum concurrency level supported by this scheduler.
public sealed override int MaximumConcurrencyLevel { get { return _maxDegreeOfParallelism; } }
/// Gets an enumerable of the tasks currently scheduled on this scheduler.
/// An enumerable of the tasks currently scheduled.
protected sealed override IEnumerable GetScheduledTasks()
{
bool lockTaken = false;
try
{
Monitor.TryEnter(_tasks, ref lockTaken);
if (lockTaken) return _tasks.ToArray();
else throw new NotSupportedException();
}
finally
{
if (lockTaken) Monitor.Exit(_tasks);
}
}
}
public class Height
{
public string msg { get; set; }
public int code { get; set; }
public double data { get; set; }
}
public class TXResult
{
public double FirstOneReadyTime { get; set; }
public double FirstOneArriveTime { get; set; }
public double FirstOneMaxCover { get; set; }
public int SingleMaxConnect { get; set; }//仅最大一架,单架输出另立列表
public double AverageTotalCover { get; set; }
public double FullCoverTime { get; set; }
public int MaxTotalConnect { get; set; }
public double ConnectTimeRatio { get; set; }
public double UnitFulfilledRatio { get; set; }
public string Stability { get; set; }
public string Robustness { get; set; }
public string Security { get; set; }
}
public class YJTX
{
//public static DemHelper DemHelper()//00
// {
// IDbHelper db = Factory.Load("10.130.100.5", "5432", "postgres", "postgres", "rescue_patrol_platform");
// DemHelper ddemHelper = new DemHelper(db);
// return ddemHelper;
// }
public static double[,] MaxMinPoly(List poly)//01多边形矩形边界
{
List PolyLon = new List();
List PolyLat = new List();
foreach (double[] element in poly)
{
PolyLon.Add(element[0]);
PolyLat.Add(element[1]);
}
double[,] MM1 = new double[2, 2];
MM1[0, 0] = PolyLon.Min();//经度最小(西界)
MM1[0, 1] = PolyLon.Max();//经度最大(东界)
MM1[1, 0] = PolyLat.Min();//纬度最小(南界)
MM1[1, 1] = PolyLat.Max();//纬度最大(北界)
return MM1;
}
public static bool isinpoly(double[] zuobiao, List poly, DemHelper demHelper)//02已经替换成在边界内算法
{
double[,] polyOut = MaxMinPoly(poly);
if (zuobiao[0] <= polyOut[0, 0] || zuobiao[0] >= polyOut[0, 1] || zuobiao[1] <= polyOut[1, 0] || zuobiao[1] >= polyOut[1, 1])
{ return false; }
else
{
string polystring = "MULTIPOLYGON(((";
foreach (double[] element in poly)
{
double e0 = element[0];
double e1 = element[1];
polystring = polystring + element[0] + " " + element[1] + ",";
}
polystring = polystring + poly[0][0] + " " + poly[0][1] + ")))";
string pointstring = "POINT (" + zuobiao[0] + " " + zuobiao[1] + ")";
// Console.WriteLine("isinpoly?");
//Console.WriteLine(pointstring+polystring);
string r1 = demHelper.doDetermine(pointstring, polystring);
// Console.WriteLine(r1);
//double[,] polyOut = MaxMinPoly(poly);
//if (zuobiao[0] <= polyOut[0, 0] || zuobiao[0] >= polyOut[0, 1] || zuobiao[1] <= polyOut[1, 0] || zuobiao[1] >= polyOut[1, 1])
// { return false; }
// else
//{
return (r1 == "True" ? true : false);
// }
}
}
//03格点生成方法[已删除]:输入前四个为经纬度上下限,数组为多边形,后两个是经纬度分辨率。输出0经,1纬,2高,3是否被侦察的【01】变量。
//04格点初始化[已删除]
//05格点显示【已删除】,可以不用
//06两点间距计算,输出米
public static double distance(double[] P1, double[] P2, DemHelper demHelper)
{
//double DL = 6371.004 * Math.Acos(Math.Sin(Math.PI / 180 * P1[1]) * Math.Sin(Math.PI / 180 * P2[1]) + Math.Cos(Math.PI / 180 * P1[1]) * Math.Cos(Math.PI / 180 * P2[1]) * Math.Cos(Math.PI / 180 * (P1[0] - P2[0]))) * 1000;
//double D = Math.Pow(Math.Pow(DL, 2) + Math.Pow(P1[2] - P2[2], 2), 0.5);
//return D;
double3 p1 = new double3();
double3 p2 = new double3();
p1.x = P1[0];
p1.y = P1[1];
p1.z = P1[2];
p2.x = P2[0];
p2.y = P2[1];
p2.z = P2[2];
double D1 = demHelper.getDistance(p1, p2);
//double DD1 = D1;
//Console.WriteLine("距离:" + D1);
return D1;
}
//07两点间距计算,(本地版),输出米
public static double distance1(double[] P1, double[] P2)
{
double DL = 6371.004 * Math.Acos(Math.Sin(Math.PI / 180 * P1[1]) * Math.Sin(Math.PI / 180 * P2[1]) + Math.Cos(Math.PI / 180 * P1[1]) * Math.Cos(Math.PI / 180 * P2[1]) * Math.Cos(Math.PI / 180 * (P1[0] - P2[0]))) * 1000;
double D = Math.Pow(Math.Pow(DL, 2) + Math.Pow(P1[2] - P2[2], 2), 0.5);
return D;
}
//08两点间高度角计算,从P1到P2,角度制
public static double angleH(double[] P1, double[] P2)
{
if (P1[2] == P2[2])
{ return 0; }
else if (P1[0] == P2[0] && P1[1] == P2[1])
{
if (P1[2] < P2[2])
{ return 90; }
else { return -90; }
}
else
{
//if (P1[2] < P2[2])
//{
double angleH = Math.Asin((P2[2] - P1[2]) / distance1(P1, P2)) * (180 / Math.PI);
return angleH;
//}
//else
//{
// double angleH = Math.Asin((P2[2] - P1[2]) / distance(P1, P2)) * (180 / Math.PI);
// return angleH;
//}
}
}
//09MoveTo,输入单位坐标、目标坐标,输出时步结束时的单位坐标【暂不用】
public static double[] MoveTo(double[] aircraft, double[] target, double V, double TimeStep, DemHelper demHelper)
{
double[] direction = { (target[0] - aircraft[0]) / distance(aircraft, target, demHelper), (target[1] - aircraft[1]) / distance(aircraft, target, demHelper), (target[2] - aircraft[2]) / distance(aircraft, target, demHelper) };
double[] delta = { direction[0] * V * TimeStep, direction[1] * V * TimeStep, direction[2] * V * TimeStep };
double[] next = { aircraft[0] + delta[0], aircraft[1] + delta[1], aircraft[2] + delta[2] };
return next;
}
public static bool isBlocked(double[] P1, double[] P2, DemHelper demHelper)//10是否被地形遮挡
{
double3 p1 = new double3();
double3 p2 = new double3();
p1.x = P1[0];
p1.y = P1[1];
p1.z = P1[2];
p2.x = P2[0];
p2.y = P2[1];
p2.z = P2[2];
string r2 = demHelper.doIntervisibility(p1, p2);//这三行代码用于运行判定
// Console.WriteLine("r2="+r2);
return (r2 == "true" ? false : true);
//return false;
}
//11是否符合观察条件【已删除】
//12航线转object【暂不用】
public static List