public IFreeGraphAdapter GetAdapter(IObjectWithNameWeightAndType node) { var t = node.GetType(); if (adapters.ContainsKey(t)) { return(adapters[t]); } throw new ArgumentOutOfRangeException("Node type not supported by adapters", nameof(node)); }
/// <summary> /// Gets the identifier - built from prefix (specified by adapter) and object name /// </summary> /// <param name="Node">A node to get identifier for</param> /// <returns></returns> /// <exception cref="ArgumentOutOfRangeException">Node type not supported by adapters - Node</exception> public String GetID(IObjectWithNameWeightAndType Node) { Type t = Node.GetType(); if (!adapters.ContainsKey(t)) { throw new ArgumentOutOfRangeException("Node type not supported by adapters", nameof(Node)); } else { return(adapters[t].GetID(Node)); } }
/// <summary> /// Makes identifier, used as prefix when interfacing the graph /// </summary> /// <param name="item">The item.</param> /// <returns></returns> public String GetID(IObjectWithNameWeightAndType item) { String output = ""; if (item.type > 0 && item.type <= typePrefixes.Count) { output = typePrefixes[item.type]; } else { output = mainPrefix; } return(output + item.name); }
public freeGraphNodeBase Assign(IObjectWithNameWeightAndType NodeA, operation onWeight = operation.assign, operation onType = operation.assign) { String b = GetID(NodeA); var lnk = graph.AddNode(b, NodeA.weight, NodeA.type); if (lnk != null) { lnk.weight = onWeight.compute(lnk.weight, NodeA.weight); lnk.type = onType.compute(lnk.type, NodeA.type); } else { lnk = graph.AddNode(b, NodeA.weight, NodeA.type); } return(lnk); }
//public List<TNodeB> GetLinkedNodesOfType<TNodeB>(TNode item, Boolean includeBtoALinks = false) //{ //} //public List<IObjectWithNameWeightAndType> GetLinkedNodes(TNode item, Boolean includeBtoALinks = false) //{ // String id = GetID(item); // var result = graph.GetLinkedNodes(id, includeBtoALinks); // List<IObjectWithNameWeightAndType> output = new List<IObjectWithNameWeightAndType>(); // IObjectWithNameWeightAndType n = source[t][GetID(item)]; // return GetLinked(item); //} /// <summary> /// Adds new link, or update existing /// </summary> /// <param name="NodeA">The node a.</param> /// <param name="NodeB">The node b.</param> /// <param name="w">The w.</param> /// <param name="type">The type.</param> /// <param name="onWeight">The on weight.</param> /// <param name="onType">Type of the on.</param> /// <returns></returns> public freeGraphLinkBase AddLink(TNode NodeA, IObjectWithNameWeightAndType NodeB, Double w, Int32 type, operation onWeight = operation.assign, operation onType = operation.assign) { String a = GetID(NodeA); String b = GetID(NodeB); var lnk = graph.GetLink(a, b); if (lnk != null) { lnk.weight = onWeight.compute(lnk.weight, w); lnk.type = onWeight.compute(lnk.type, type); } else { lnk = graph.AddLink(a, b, w, type); } return(lnk); }
public List <freeGraphLinkBase> AddLinks(IObjectWithNameWeightAndType NodeA, IEnumerable <IObjectWithNameWeightAndType> NodeBs, double w = 1, int type = 0, operation onWeight = operation.assign, operation onType = operation.assign) { String a = GetID(NodeA); List <freeGraphLinkBase> output = new List <freeGraphLinkBase>(); foreach (var B in NodeBs) { String b = GetID(B); var lnk = graph.GetLink(a, b); if (lnk != null) { lnk.weight = onWeight.compute(lnk.weight, w); lnk.type = onWeight.compute(lnk.type, type); } else { lnk = graph.AddLink(a, b, w, type); } output.Add(lnk); } return(output); }
freeGraphNodeBase IFreeGraphAdapter.Assign(IObjectWithNameWeightAndType NodeA) { return(graph.GetNode(GetID(NodeA))); }
string IFreeGraphAdapter.GetID(IObjectWithNameWeightAndType Node) { throw new NotImplementedException(); }