本文整理汇总了C#中AdjacencyGraph.AddEdgeRange方法的典型用法代码示例。如果您正苦于以下问题:C# AdjacencyGraph.AddEdgeRange方法的具体用法?C# AdjacencyGraph.AddEdgeRange怎么用?C# AdjacencyGraph.AddEdgeRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AdjacencyGraph
的用法示例。
在下文中一共展示了AdjacencyGraph.AddEdgeRange方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateAdjacencyGraph
static AdjacencyGraph<Vertex, Edge<Vertex>> CreateAdjacencyGraph(StateMachineGraph data)
{
var graph = new AdjacencyGraph<Vertex, Edge<Vertex>>();
graph.AddVertexRange(data.Vertices);
graph.AddEdgeRange(data.Edges.Select(x => new Edge<Vertex>(x.From, x.To)));
return graph;
}
示例2: NearestRoute
public IEnumerable<MapSolarSystemEdge> NearestRoute(long fromSolarSystemID, long toSolarSystemID, bool safeOnly = false)
{
eveGraph = new AdjacencyGraph<SolarSystem, Edge<SolarSystem>>(); // Eve universe
getPathCache = new Dictionary<long, TryFunc<SolarSystem, IEnumerable<Edge<SolarSystem>>>>(); // function cache
var dbResult = (from s in context.SolarSystems
from e in s.ToSolarSystems
where s.security >= (safeOnly ? 0.5 : -20)
select new { From = s, To = e }).AsEnumerable();
var edges = dbResult.Select(a => new Edge<SolarSystem>(a.From, a.To)).OrderBy(e => e.Source.solarSystemID).ToList();
var vertices = context.SolarSystems;
eveGraph.AddVertexRange(vertices); // Fill Graph
eveGraph.AddEdgeRange(edges); // Fill Graph
var allPathes = new List<IEnumerable<Edge<SolarSystem>>>();
var result = new List<MapSolarSystemEdge>();
var from = context.SolarSystems.Where(m => m.solarSystemID == fromSolarSystemID).SingleOrDefault();
var linkedSystems = from system in context.SolarSystems
where system.solarSystemID == toSolarSystemID
&& system.security >= (safeOnly ? 0.5 : -20)
select system;
TryFunc<SolarSystem, IEnumerable<Edge<SolarSystem>>> tryGetPath;
if (getPathCache.ContainsKey(from.solarSystemID))
{
tryGetPath = getPathCache[from.solarSystemID];
}
else
{
tryGetPath = eveGraph.ShortestPathsDijkstra(v => 1, from);
getPathCache[from.solarSystemID] = tryGetPath;
}
foreach (var s in linkedSystems)
{
IEnumerable<Edge<SolarSystem>> path;
if (tryGetPath(s, out path))
{
allPathes.Add(path);
}
}
var shortestPath = allPathes.OrderBy(p => p.Count()).FirstOrDefault();
if (shortestPath == null)
return null;
foreach (var item in shortestPath)
{
result.Add(new MapSolarSystemEdge() { From = item.Source.solarSystemID, To = item.Target.solarSystemID });
}
return result;
}
示例3: CreateGraph
public Graph CreateGraph(FeatherVaneGraph data)
{
var graph = new AdjacencyGraph<Vertex, Edge<Vertex>>();
graph.AddVertexRange(data.Vertices);
graph.AddEdgeRange(data.Edges.Select(x => new Edge<Vertex>(x.From, x.To)));
GleeGraphPopulator<Vertex, Edge<Vertex>> glee = graph.CreateGleePopulator();
glee.NodeAdded += NodeStyler;
glee.EdgeAdded += EdgeStyler;
glee.Compute();
Graph gleeGraph = glee.GleeGraph;
return gleeGraph;
}
示例4: ExecuteTasks
public async Task<bool> ExecuteTasks(Resource resource)
{
var tasks = new ResourceTask[]
{
new UpdateStreamListTask(),
new UpdatePackageFileTask(),
new BuildAssemblyTask()
};
var graph = new AdjacencyGraph<string, SEdge<string>>();
// add vertices and edges
foreach (var task in tasks)
{
graph.AddVertex(task.Id);
graph.AddEdgeRange(task.DependsOn.Select(a => new SEdge<string>(task.Id, a)));
}
var runTasks = graph.TopologicalSort().Reverse().Select(a => tasks.First(b => b.Id == a)).Where(a => a.NeedsExecutionFor(resource));
if (runTasks.FirstOrDefault() != null)
{
this.Log().Info("Running tasks on {0}: {1}.", resource.Name, string.Join(", ", runTasks.Select(a => a.Id)));
}
foreach (var task in runTasks)
{
if (!await task.Process(resource))
{
this.Log().Warn("Task {0} failed.", task.Id);
return false;
}
}
return true;
}
示例5: GetAgentRoute
private IEnumerable<WayPoint> GetAgentRoute(AgentsGroup group)
{
if (_routesHash.ContainsKey(group.Id))
return _routesHash[group.Id];
WayPoint source = group.SourcePoint;
WayPoint target = group.TargetPoint;
if (_scenario.TransitionGraph == null || _scenario.TransitionGraph.Nodes.Count() == 0)
return null;
if (_transitionsGraph == null)
{
_transitionsGraph = new AdjacencyGraph<WayPoint, Edge<WayPoint>>();
_transitionsGraph.AddVertexRange(_scenario.TransitionGraph.Nodes);
_transitionsGraph.AddEdgeRange(from edge in _scenario.TransitionGraph.Edges select new Edge<WayPoint>(edge.Start, edge.End));
}
var route = new List<WayPoint>();
route.Add(source);
if (target != null)
{
IEnumerable<Edge<WayPoint>> result;
if (_transitionsGraph.ShortestPathsDijkstra((e) => _scenario.TransitionGraph.GetEdgeData(e.Source, e.Target), source).Invoke(target, out result))
{
route.AddRange(result.Select(e => e.Target));
}
else
{
route = null;
}
_routesHash[group.Id] = route;
return route;
}
//TODO допилить адекватное построение маршрута
var curNode = source;
int tryCount = _scenario.TransitionGraph.Nodes.Count();
while (_scenario.TransitionGraph.HasChildNodes(curNode))
{
double rand_value = rand.NextDouble();
var edges = _scenario.TransitionGraph.GetEdgesFrom(curNode).ToList();
if (route.Count > 1)
{
edges.RemoveAll(e => e.End == route[route.Count - 2] || e.End.LayerId > route.Last().LayerId);
}
foreach (var edge in edges)
{
rand_value -= edge.Data / edges.Sum(e => e.Data);
if (rand_value <= 0)
{
route.Add(edge.End);
if (edge.End.IsOutput)
{
route.Remove(route.First());
return route;
}
curNode = edge.End;
break;
}
}
if (tryCount-- == 0) break;
}
route.Remove(route.First());
return route;
}
示例6: GenerateGraphML
public static void GenerateGraphML(string fileName)
{
var graph = new AdjacencyGraph<XOVertex, XOEdge>();
var relationshipsSubset = _relationships.Values
//.Where(e => e.Source.ModuleId == "57$61" && e.Target.ModuleId == "57$61")
.Where(e => (e.Source.ClassSpec == "Audited" || e.Source.ClassSpec == "Metadata") && (e.Target.ClassSpec == "Audited" || e.Target.ClassSpec == "Metadata"))
.ToArray();
foreach (var r in relationshipsSubset)
{
if (!graph.ContainsVertex(r.Source))
graph.AddVertex(r.Source);
if (!graph.ContainsVertex(r.Target))
graph.AddVertex(r.Target);
}
graph.AddEdgeRange(relationshipsSubset);
int idx = 0;
foreach (var v in graph.Vertices)
{
foreach (var super in v.Superclasses.Select(s => _classes[s]).Where(s => graph.ContainsVertex(s)))
{
string id = string.Concat("inheritance_", idx++);
graph.AddEdge(new XOEdge(id, v, super)
{
Weight = BuildEdgeWeight(v, super),
EdgeType = BuildEdgeInheritanceType(v, super),
Color = BuildEdgeInheritanceColor(v, super)
});
}
}
VertexIdentity<XOVertex> vi = v => v.Id;
EdgeIdentity<XOVertex, XOEdge> ei = e => e.Id;
using (XmlWriter xw = XmlWriter.Create(fileName))
{
graph.SerializeToGraphML<XOVertex, XOEdge, AdjacencyGraph<XOVertex, XOEdge>>(xw, vi, ei);
}
}