示例#1
0
 public void AddStructure(MathIdentifier structureId, ConversionRouter router, Type type)
 {
     if (!_table.ContainsId(structureId))
     {
         _table.Add(structureId, new StructureType(structureId, router, type));
     }
 }
示例#2
0
        public void AddSourceNeighbor(ConversionRouter routerWeCanConvertFrom, bool lossless, Converter <ValueStructure, ValueStructure> directConvert)
        {
            MathIdentifier id = routerWeCanConvertFrom.structureId;

            if (Propose(new ConversionDistance(id, 0, lossless, null, directConvert), routerWeCanConvertFrom))
            {
                ConversionRoute route = new ConversionRoute(id, directConvert);
                if (lossless)
                {
                    if (losslessNeighbors.ContainsKey(id))
                    {
                        losslessNeighbors[id] = route;
                    }
                    else
                    {
                        losslessNeighbors.Add(id, route);
                    }
                }
                else
                {
                    if (lossyNeighbors.ContainsKey(id))
                    {
                        lossyNeighbors[id] = route;
                    }
                    else
                    {
                        lossyNeighbors.Add(id, route);
                    }
                }
                routerWeCanConvertFrom.AddTargetNeighbor(this); //receiving all its routes ...
                BroadcastDistanceVector();
            }
        }
示例#3
0
 private void Propose(Dictionary <MathIdentifier, ConversionDistance> vec, ConversionRouter proposedBy)
 {
     foreach (KeyValuePair <MathIdentifier, ConversionDistance> distance in vec)
     {
         Propose(distance.Value, proposedBy);
     }
 }
 public ConversionDistance(MathIdentifier canConvertFrom, int cost, bool lossless, ConversionRouter nextHop, Converter<ValueStructure, ValueStructure> convert)
 {
     this.CanConvertFrom = canConvertFrom;
     this.Cost = cost;
     this.Lossless = lossless;
     this.NextHop = nextHop;
     this.Convert = convert;
 }
示例#5
0
 private void AddTargetNeighbor(ConversionRouter routerWeCanConvertTo)
 {
     if (!targetNeighbors.ContainsKey(routerWeCanConvertTo.structureId))
     {
         targetNeighbors.Add(routerWeCanConvertTo.structureId, routerWeCanConvertTo);
         BroadcastDistanceVector(routerWeCanConvertTo);
     }
 }
示例#6
0
        /// <returns>True if the route was better than existing routes.</returns>
        private bool Propose(ConversionDistance distance, ConversionRouter proposedBy)
        {
            MathIdentifier id = distance.CanConvertFrom;

            if (structureId.Equals(id))
            {
                return(false);
            }
            distance.Lossless = distance.Lossless && losslessNeighbors.ContainsKey(proposedBy.structureId);
            distance.Cost++;
            if (distance.NextHop != null) //not a new neighbour
            {
                Converter <ValueStructure, ValueStructure> distanceC = distance.Convert, localC;
                if (losslessNeighbors.ContainsKey(proposedBy.structureId))
                {
                    localC = losslessNeighbors[proposedBy.structureId].Convert;
                }
                else
                {
                    localC = lossyNeighbors[proposedBy.structureId].Convert;
                }
                distance.Convert = delegate(ValueStructure v) { return(localC(distanceC(v))); };
            }
            distance.NextHop = proposedBy;
            if (vector.ContainsKey(id))
            {
                ConversionDistance cd = vector[id];
                if (distance.Lossless && !cd.Lossless || distance.Cost < cd.Cost && (distance.Lossless || !cd.Lossless))
                {
                    vector[id] = distance;
                    BroadcastDistanceVector();
                    return(true);
                }
                return(false);
            }
            vector.Add(id, distance);
            BroadcastDistanceVector();
            return(true);
        }
 public void AddSourceNeighbor(ConversionRouter routerWeCanConvertFrom, bool lossless, Converter<ValueStructure, ValueStructure> directConvert)
 {
     MathIdentifier id = routerWeCanConvertFrom.structureId;
     if(Propose(new ConversionDistance(id, 0, lossless, null, directConvert), routerWeCanConvertFrom))
     {
         ConversionRoute route = new ConversionRoute(id, directConvert);
         if(lossless)
         {
             if(losslessNeighbors.ContainsKey(id))
                 losslessNeighbors[id] = route;
             else
                 losslessNeighbors.Add(id, route);
         }
         else
         {
             if(lossyNeighbors.ContainsKey(id))
                 lossyNeighbors[id] = route;
             else
                 lossyNeighbors.Add(id, route);
         }
         routerWeCanConvertFrom.AddTargetNeighbor(this); //receiving all its routes ...
         BroadcastDistanceVector();
     }
 }
示例#8
0
 public void AddStructure(MathIdentifier structureId, ConversionRouter router, Type type)
 {
     if(!_table.ContainsId(structureId))
         _table.Add(structureId, new StructureType(structureId, router, type));
 }
示例#9
0
 public StructureType(MathIdentifier id, ConversionRouter router, Type type)
 {
     this.Type = type;
     this.Identifier = id;
     this.Router = router;
 }
示例#10
0
 public void BroadcastDistanceVector(ConversionRouter target)
 {
     target.Propose(vector, this);
 }
示例#11
0
 private void Propose(Dictionary<MathIdentifier, ConversionDistance> vec, ConversionRouter proposedBy)
 {
     foreach(KeyValuePair<MathIdentifier, ConversionDistance> distance in vec)
         Propose(distance.Value, proposedBy);
 }
示例#12
0
 /// <returns>True if the route was better than existing routes.</returns>
 private bool Propose(ConversionDistance distance, ConversionRouter proposedBy)
 {
     MathIdentifier id = distance.CanConvertFrom;
     if(structureId.Equals(id))
         return false;
     distance.Lossless = distance.Lossless && losslessNeighbors.ContainsKey(proposedBy.structureId);
     distance.Cost++;
     if(distance.NextHop != null) //not a new neighbour
     {
         Converter<ValueStructure, ValueStructure> distanceC = distance.Convert, localC;
         if(losslessNeighbors.ContainsKey(proposedBy.structureId))
             localC = losslessNeighbors[proposedBy.structureId].Convert;
         else
             localC = lossyNeighbors[proposedBy.structureId].Convert;
         distance.Convert = delegate(ValueStructure v) { return localC(distanceC(v)); };
     }
     distance.NextHop = proposedBy;
     if(vector.ContainsKey(id))
     {
         ConversionDistance cd = vector[id];
         if(distance.Lossless && !cd.Lossless || distance.Cost < cd.Cost && (distance.Lossless || !cd.Lossless))
         {
             vector[id] = distance;
             BroadcastDistanceVector();
             return true;
         }
         return false;
     }
     vector.Add(id, distance);
     BroadcastDistanceVector();
     return true;
 }
示例#13
0
 private void AddTargetNeighbor(ConversionRouter routerWeCanConvertTo)
 {
     if(!targetNeighbors.ContainsKey(routerWeCanConvertTo.structureId))
     {
         targetNeighbors.Add(routerWeCanConvertTo.structureId, routerWeCanConvertTo);
         BroadcastDistanceVector(routerWeCanConvertTo);
     }
 }
示例#14
0
 public StructureType(MathIdentifier id, ConversionRouter router, Type type)
 {
     this.Type       = type;
     this.Identifier = id;
     this.Router     = router;
 }
示例#15
0
 public ConversionDistance(MathIdentifier canConvertFrom, int cost, bool lossless, ConversionRouter nextHop, Converter <ValueStructure, ValueStructure> convert)
 {
     this.CanConvertFrom = canConvertFrom;
     this.Cost           = cost;
     this.Lossless       = lossless;
     this.NextHop        = nextHop;
     this.Convert        = convert;
 }
示例#16
0
 public void BroadcastDistanceVector(ConversionRouter target)
 {
     target.Propose(vector, this);
 }