本文整理汇总了C#中IGraph.GetEdges方法的典型用法代码示例。如果您正苦于以下问题:C# IGraph.GetEdges方法的具体用法?C# IGraph.GetEdges怎么用?C# IGraph.GetEdges使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IGraph
的用法示例。
在下文中一共展示了IGraph.GetEdges方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExistsOneHop
/// <summary>
/// Calculates witnesses from one source to multiple targets at once but using only one hop.
/// </summary>
/// <param name="graph"></param>
/// <param name="from"></param>
/// <param name="tos"></param>
/// <param name="tosWeights"></param>
/// <param name="maxSettles"></param>
/// <param name="forwardExists"></param>
/// <param name="backwardExists"></param>
private void ExistsOneHop(IGraph<CHEdgeData> graph, uint from, List<uint> tos, List<float> tosWeights, int maxSettles,
ref bool[] forwardExists, ref bool[] backwardExists)
{
var toSet = new HashSet<uint>();
float maxWeight = 0;
for (int idx = 0; idx < tosWeights.Count; idx++)
{
if (!forwardExists[idx] || !backwardExists[idx])
{
toSet.Add(tos[idx]);
if (maxWeight < tosWeights[idx])
{
maxWeight = tosWeights[idx];
}
}
}
if (toSet.Count > 0)
{
var neighbours = graph.GetEdges(from);
while (neighbours.MoveNext())
{
if (toSet.Contains(neighbours.Neighbour))
{ // ok, this is a to-edge.
int index = tos.IndexOf(neighbours.Neighbour);
toSet.Remove(neighbours.Neighbour);
var edgeData = neighbours.EdgeData;
if (edgeData.CanMoveForward &&
edgeData.Weight < tosWeights[index])
{
forwardExists[index] = true;
}
if (edgeData.CanMoveBackward &&
edgeData.Weight < tosWeights[index])
{
backwardExists[index] = true;
}
if (toSet.Count == 0)
{
break;
}
}
}
}
}
示例2: GraphMerge
public virtual void GraphMerge(IGraph graph)
{
graph.GetVertices().ForEach(v => this.AddVertex(v.Value));
graph.GetEdges().ForEach(e => this.AddEdge(e.Vertices[0].Value, e.Vertices[1].Value));
}
示例3: Exists
//.........这里部分代码省略.........
int index = tos.IndexOf(current.VertexId);
forwardExists[index] = current.Weight <= tosWeights[index];
//if (forwardExists[index])
//{
forwardToSet.Remove(current.VertexId);
//}
}
}
if (current.Backward)
{ // this is a backward settle.
backwardSettled.Add(current.VertexId);
backwardMinWeight.Remove(current.VertexId);
if (backwardToSet.Contains(current.VertexId))
{
int index = tos.IndexOf(current.VertexId);
backwardExists[index] = current.Weight <= tosWeights[index];
//if (backwardExists[index])
//{
backwardToSet.Remove(current.VertexId);
//}
}
}
if (forwardToSet.Count == 0 &&
backwardToSet.Count == 0)
{ // there is nothing left to check.
break;
}
if (forwardSettled.Count >= maxSettles &&
backwardSettled.Count >= maxSettles)
{ // do not continue searching.
break;
}
bool doForward = current.Forward && forwardToSet.Count > 0 && !forwardWasSettled;
bool doBackward = current.Backward && backwardToSet.Count > 0 && !backwardWasSettled;
if (doForward || doBackward)
{ // get the neighbours.
var neighbours = graph.GetEdges(current.VertexId);
while (neighbours.MoveNext())
{ // move next.
var edgeData = neighbours.EdgeData;
var neighbourWeight = current.Weight + edgeData.Weight;
var doNeighbourForward = doForward && edgeData.CanMoveForward && neighbourWeight <= forwardMaxWeight &&
!forwardSettled.Contains(neighbours.Neighbour);
var doNeighbourBackward = doBackward && edgeData.CanMoveBackward && neighbourWeight <= backwardMaxWeight &&
!backwardSettled.Contains(neighbours.Neighbour);
if (doNeighbourBackward || doNeighbourForward)
{
float existingWeight;
if (doNeighbourForward)
{
if (forwardMinWeight.TryGetValue(neighbours.Neighbour, out existingWeight))
{
if(existingWeight <= neighbourWeight)
{
doNeighbourForward = false;
}
else
{
forwardMinWeight[neighbours.Neighbour] = neighbourWeight;
}
}
else
{
forwardMinWeight[neighbours.Neighbour] = neighbourWeight;
}
}
if (doNeighbourBackward)
{
if (backwardMinWeight.TryGetValue(neighbours.Neighbour, out existingWeight))
{
if (existingWeight <= neighbourWeight)
{
doNeighbourBackward = false;
}
else
{
backwardMinWeight[neighbours.Neighbour] = neighbourWeight;
}
}
else
{
backwardMinWeight[neighbours.Neighbour] = neighbourWeight;
}
}
if (doNeighbourBackward || doNeighbourForward)
{
var neighbour = new SettledVertex(neighbours.Neighbour,
neighbourWeight, current.Hops + 1, doNeighbourForward, doNeighbourBackward);
heap.Push(neighbour, neighbour.Weight);
}
}
}
}
}
}
}
示例4: CopyTo
public virtual void CopyTo(IGraph graph)
{
var g = graph as UndirectedGraph;
g.edges = new List<IEdge>();
g.vertices = new List<IVertex>();
this.GetVertices().ForEach(v => g.vertices.Add(v.Clone() as IVertex));
this.GetEdges().ForEach(e => g.edges.Add(e.Clone() as IEdge));
graph.GetVertices().ForEach(v => v.Graph = graph);
graph.GetEdges().ForEach(delegate(IEdge e)
{
e.Vertices[0] = graph[e.Vertices[0].Value];
e.Vertices[1] = graph[e.Vertices[1].Value];
e.Graph = graph;
});
//graph.GraphMerge(this);
}