Ejemplo n.º 1
0
 public void AddStructure(MathIdentifier structureId, ConversionRouter router, Type type)
 {
     if (!_table.ContainsId(structureId))
     {
         _table.Add(structureId, new StructureType(structureId, router, type));
     }
 }
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 3
0
 private void Propose(Dictionary <MathIdentifier, ConversionDistance> vec, ConversionRouter proposedBy)
 {
     foreach (KeyValuePair <MathIdentifier, ConversionDistance> distance in vec)
     {
         Propose(distance.Value, proposedBy);
     }
 }
Ejemplo n.º 4
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;
 }
Ejemplo n.º 5
0
 private void AddTargetNeighbor(ConversionRouter routerWeCanConvertTo)
 {
     if (!targetNeighbors.ContainsKey(routerWeCanConvertTo.structureId))
     {
         targetNeighbors.Add(routerWeCanConvertTo.structureId, routerWeCanConvertTo);
         BroadcastDistanceVector(routerWeCanConvertTo);
     }
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 7
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();
     }
 }
Ejemplo n.º 8
0
 public void AddStructure(MathIdentifier structureId, ConversionRouter router, Type type)
 {
     if(!_table.ContainsId(structureId))
         _table.Add(structureId, new StructureType(structureId, router, type));
 }
Ejemplo n.º 9
0
 public StructureType(MathIdentifier id, ConversionRouter router, Type type)
 {
     this.Type = type;
     this.Identifier = id;
     this.Router = router;
 }
Ejemplo n.º 10
0
 public void BroadcastDistanceVector(ConversionRouter target)
 {
     target.Propose(vector, this);
 }
Ejemplo n.º 11
0
 private void Propose(Dictionary<MathIdentifier, ConversionDistance> vec, ConversionRouter proposedBy)
 {
     foreach(KeyValuePair<MathIdentifier, ConversionDistance> distance in vec)
         Propose(distance.Value, proposedBy);
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 13
0
 private void AddTargetNeighbor(ConversionRouter routerWeCanConvertTo)
 {
     if(!targetNeighbors.ContainsKey(routerWeCanConvertTo.structureId))
     {
         targetNeighbors.Add(routerWeCanConvertTo.structureId, routerWeCanConvertTo);
         BroadcastDistanceVector(routerWeCanConvertTo);
     }
 }
Ejemplo n.º 14
0
 public StructureType(MathIdentifier id, ConversionRouter router, Type type)
 {
     this.Type       = type;
     this.Identifier = id;
     this.Router     = router;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 16
0
 public void BroadcastDistanceVector(ConversionRouter target)
 {
     target.Propose(vector, this);
 }