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];
 }
 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;
         }
     }
 }
 //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;
     }
 }
        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();
        }