public virtual void SetGraph(FlowNetwork g) { graph = new FlowNetwork(g); graph.OnEdgeFlowChanged += (sender, edge) => OnEdgeFlowChanged?.Invoke(this, sender, edge); graph.OnEdgeMarked += (sender, edge) => OnEdgeMarked?.Invoke(this, sender, edge); graph.OnEdgeUnmarked += (sender, edge) => OnEdgeUnmarked?.Invoke(this, sender, edge); }
public void AddEdge(int from, int to, double capacity, double f = -1) { if (from == to) { throw new InvalidConfigurationException("'from' cant equals 'to'"); } if (capacity < 0) { throw new InvalidConfigurationException($"Capacity can't be less than 0"); } FlowEdge sameEdge = null; try { sameEdge = Edges.Find((e) => (e.From == from && e.To == to) || (e.From == to && e.To == from)); } catch (Exception e) { } if (sameEdge != null) { throw new InvalidConfigurationException($"Edge between {from} and {to} already exists"); } var edge = f == -1 ? new FlowEdge(from, to, capacity) : new FlowEdge(from, to, capacity, f); edge.OnFlowChanged += (sender) => OnEdgeFlowChanged?.Invoke(this, sender); edge.OnLengthChanged += (sender, length) => OnEdgeLengthChanged?.Invoke(this, sender); edge.OnEdgeMarked += (sender) => OnEdgeMarked?.Invoke(this, sender); edge.OnEdgeUnmarked += (sender) => OnEdgeUnmarked?.Invoke(this, sender); Edges.Add(edge); if (!Nodes.ContainsKey(edge.From)) { Nodes.Add(edge.From, new FlowNode(edge.From)); } if (!Nodes.ContainsKey(edge.To)) { Nodes.Add(edge.To, new FlowNode(edge.To)); } Nodes[edge.From].AddEdge(ref edge); Nodes[edge.To].AddEdge(ref edge); }
public void Unmark() { OnEdgeUnmarked?.Invoke(this); }