Пример #1
0
    public static List <GridLocation> run(Bitmap bitmap, GridLocation start, GridLocation goal,
                                          ComputeCost computeCost)
    {
        //Debug.LogWarning("GS: setup dictionaries");
        Dictionary <GridLocation, GridLocation> cameFrom  = new Dictionary <GridLocation, GridLocation>();
        Dictionary <GridLocation, double>       costSoFar = new Dictionary <GridLocation, double>();

        //Debug.LogWarning("GS: setup interval heap");
        var frontier = new C5.IntervalHeap <GridLocation>();

        start.priority = 0;
        frontier.Add(start);
        cameFrom[start]  = null;
        costSoFar[start] = 0;

        //Debug.LogWarning("GS: while loop BEGIN");
        float exitLoopTime = Time.time + 5f;

        while (!frontier.IsEmpty)
        {
            if (Time.time > exitLoopTime)
            {
                Debug.LogWarning("GS: grid search timeout");
                return(null);
            }

            //Debug.LogWarning("GS: while loop entered");
            var current = frontier.DeleteMin();
            if (current.Equals(goal))
            {
                //Debug.LogWarning("GS: current == goal");
                return(RebuildPath(goal, cameFrom));
            }
            foreach (GridLocation next in bitmap.Neighbours(current))
            {
                bool   usingLOS     = false;
                double computedCost = computeCost(current, next, cameFrom, costSoFar, ref usingLOS, bitmap);
                if (!costSoFar.ContainsKey(next) || computedCost < costSoFar[next])
                {
                    if (usingLOS)
                    {
                        cameFrom[next] = cameFrom[current];
                    }
                    else
                    {
                        cameFrom[next] = current;
                    }
                    costSoFar[next] = computedCost;
                    double p = computedCost + next.distanceTo(goal);
                    next.priority = p;
                    frontier.Add(next);
                }
            }
        }

        Debug.LogWarning("GS: returning null");
        return(null);
    }
Пример #2
0
 public override int GetHashCode() {
   int hash = 1;
   if (Name.Length != 0) hash ^= Name.GetHashCode();
   if (Device.Length != 0) hash ^= Device.GetHashCode();
   if (Id != 0) hash ^= Id.GetHashCode();
   hash ^= inputInfo_.GetHashCode();
   hash ^= outputInfo_.GetHashCode();
   if (TemporaryMemorySize != 0L) hash ^= TemporaryMemorySize.GetHashCode();
   if (HostTempMemorySize != 0L) hash ^= HostTempMemorySize.GetHashCode();
   if (DeviceTempMemorySize != 0L) hash ^= DeviceTempMemorySize.GetHashCode();
   if (HostPersistentMemorySize != 0L) hash ^= HostPersistentMemorySize.GetHashCode();
   if (DevicePersistentMemorySize != 0L) hash ^= DevicePersistentMemorySize.GetHashCode();
   if (ComputeCost != 0L) hash ^= ComputeCost.GetHashCode();
   if (ComputeTime != 0L) hash ^= ComputeTime.GetHashCode();
   if (MemoryTime != 0L) hash ^= MemoryTime.GetHashCode();
   if (IsFinal != false) hash ^= IsFinal.GetHashCode();
   hash ^= controlInput_.GetHashCode();
   return hash;
 }