Ejemplo n.º 1
0
 public int dist(UniverseGraph.SystemId sid1, UniverseGraph.SystemId sid2)
 {
     SystemPair pair = new SystemPair(sid1, sid2);
     if (!distance.ContainsKey(pair))
         return UNREACHABLE;
     else
         return distance[pair];
 }
Ejemplo n.º 2
0
 public void relax(UniverseGraph.SystemId sid1, UniverseGraph.SystemId sid2)
 {
     int distUpperBound = dist(sid1, sid2);
     SystemPair pair = new SystemPair(sid1, sid2);
     foreach (UniverseGraph.SystemId sid in graph.idToInfo.Keys)
     {
         int distCandidate = dist(sid1, sid) + dist(sid, sid2);
         if (distCandidate < distUpperBound)
         {
             distance[pair] = distCandidate;
             distUpperBound = distCandidate;
         }
     }
 }
Ejemplo n.º 3
0
 //todo : add some kind of control to keep cache size in check
 public int getDistance(UniverseGraph.SystemId source, UniverseGraph.SystemId dest)
 {
     SystemPair key = new SystemPair(source.id, dest.id);
     if (distanceCache.ContainsKey(key))
     {
         ++cacheHits;
         return distanceCache[key];
     }
     else
     {
         ++cacheMisses;
         int computedDist = findDist(source, dest);
         distanceCache[key] = computedDist;
         return computedDist;
     }
 }
Ejemplo n.º 4
0
        public void importDistanceCache(string path)
        {
            StreamReader reader = new StreamReader(File.Open(path, FileMode.OpenOrCreate, FileAccess.ReadWrite));

            String line = reader.ReadLine();
            while((line!=null) & (line!=""))
            {
                char[] commas = {','};
                String[] toks = line.Split(commas);
                if (toks.Length == 3)
                {
                    ushort id1 = UInt16.Parse(toks[0]);
                    ushort id2 = UInt16.Parse(toks[1]);
                    int dist = Int32.Parse(toks[2]);
                    SystemPair pair = new SystemPair(id1, id2);
                    distanceCache[pair] = dist;
                }
                line = reader.ReadLine();
                if (line == null)
                    break;
            }

            reader.Close();
        }