public void AddStructure(MathIdentifier structureId, ConversionRouter router, Type type) { if (!_table.ContainsId(structureId)) { _table.Add(structureId, new StructureType(structureId, router, type)); } }
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(); } }
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; }
private void AddTargetNeighbor(ConversionRouter routerWeCanConvertTo) { if (!targetNeighbors.ContainsKey(routerWeCanConvertTo.structureId)) { targetNeighbors.Add(routerWeCanConvertTo.structureId, routerWeCanConvertTo); BroadcastDistanceVector(routerWeCanConvertTo); } }
/// <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(); } }
public void AddStructure(MathIdentifier structureId, ConversionRouter router, Type type) { if(!_table.ContainsId(structureId)) _table.Add(structureId, new StructureType(structureId, router, type)); }
public StructureType(MathIdentifier id, ConversionRouter router, Type type) { this.Type = type; this.Identifier = id; this.Router = router; }
public void BroadcastDistanceVector(ConversionRouter target) { target.Propose(vector, this); }
private void Propose(Dictionary<MathIdentifier, ConversionDistance> vec, ConversionRouter proposedBy) { foreach(KeyValuePair<MathIdentifier, ConversionDistance> distance in vec) Propose(distance.Value, proposedBy); }
/// <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; }
private void AddTargetNeighbor(ConversionRouter routerWeCanConvertTo) { if(!targetNeighbors.ContainsKey(routerWeCanConvertTo.structureId)) { targetNeighbors.Add(routerWeCanConvertTo.structureId, routerWeCanConvertTo); BroadcastDistanceVector(routerWeCanConvertTo); } }
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; }