本文整理汇总了C#中AdjacencyGraph.AddVertexRange方法的典型用法代码示例。如果您正苦于以下问题:C# AdjacencyGraph.AddVertexRange方法的具体用法?C# AdjacencyGraph.AddVertexRange怎么用?C# AdjacencyGraph.AddVertexRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AdjacencyGraph
的用法示例。
在下文中一共展示了AdjacencyGraph.AddVertexRange方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: YenOneVertexCaseTest
public void YenOneVertexCaseTest()
{
var graph = new AdjacencyGraph<char, TaggedEquatableEdge<char, double>>(true);
graph.AddVertexRange("1");
var yen = new YenShortestPathsAlgorithm<char>(graph, '1', '1', 10);
var exeptionWas = false;
try
{
yen.Execute();
}
catch (Exception e)
{
Assert.AreEqual(true, e is NoPathFoundException);
exeptionWas = true;
}
Assert.AreEqual(exeptionWas, true);
}
示例5: SortByEvaluationOrder
/// <summary>
/// Sorts the collection by evaluation order, using a topological sort.
/// </summary>
/// <param name="calcs">The collection to sort.</param>
/// <returns>The sorted collection.</returns>
public static IEnumerable<CalculationControl> SortByEvaluationOrder(this IEnumerable<CalculationControl> calcs)
{
AdjacencyGraph<CalculationControl, SEdge<CalculationControl>> graph = new AdjacencyGraph<CalculationControl, SEdge<CalculationControl>>();
graph.AddVertexRange(calcs);
foreach (var target in calcs)
{
foreach (var calc in calcs)
{
if (target.CalculationExpression.Contains("{%" + calc.Name + "%}") || Regex.IsMatch(target.CalculationExpression, @"{%[^\.]*." + calc.Name + ".Total%}"))
{
graph.AddEdge(new SEdge<CalculationControl>(calc, target));
}
}
}
return graph.TopologicalSort();
}
示例6: IncrementalConnectedComponent
public void IncrementalConnectedComponent()
{
var g = new AdjacencyGraph<int, SEquatableEdge<int>>();
g.AddVertexRange(new int[] { 0, 1, 2, 3 });
var components = AlgorithmExtensions.IncrementalConnectedComponents(g);
var current = components();
Assert.AreEqual(4, current.Key);
g.AddEdge(new SEquatableEdge<int>(0, 1));
current = components();
Assert.AreEqual(3, current.Key);
g.AddEdge(new SEquatableEdge<int>(2, 3));
current = components();
Assert.AreEqual(2, current.Key);
g.AddEdge(new SEquatableEdge<int>(1, 3));
current = components();
Assert.AreEqual(1, current.Key);
}
示例7: Region
public Region(string id, List<Waypoint> waypointList, List<Tuple<string, string>> connections,
Size size, string miniMap, Point miniMapOffset, string worldMap, Point worldMapOffset, bool chokePoint)
{
ChokePoint = chokePoint;
WorldMapOffset = worldMapOffset;
WorldMap = worldMap;
MiniMapOffset = miniMapOffset;
MiniMap = miniMap;
Size = size;
Id = id;
WaypointList = waypointList;
Connections = connections;
foreach (var wp in WaypointList)
{
wp.Region = this;
}
Waypoints = WaypointList.ToDictionary(x => x.Id.ToLowerInvariant());
RegionGraph = new AdjacencyGraph<Waypoint, Connection>(true);
RegionGraph.AddVertexRange(waypointList);
foreach (var c in Connections)
{
var wp1 = Waypoints[c.Item1];
var wp2 = Waypoints[c.Item2];
var dist = Math.Sqrt(Math.Pow(wp1.Location.X - wp2.Location.X, 2) + Math.Pow(wp1.Location.Y - wp2.Location.Y, 2));
var time = TimeSpan.FromSeconds(dist / BaseSpeed);
RegionGraph.AddEdge(new Connection(wp1, wp2, time));
RegionGraph.AddEdge(new Connection(wp2, wp1, time));
}
}
示例8: Compute
public void Compute()
{
var g = new AdjacencyGraph<char, Edge<char>>();
var distances = new Dictionary<Edge<char>, double>();
g.AddVertexRange("ABCDE");
AddEdge(g, distances, 'A', 'C', 1);
AddEdge(g, distances, 'B', 'B', 2);
AddEdge(g, distances, 'B', 'D', 1);
AddEdge(g, distances, 'B', 'E', 2);
AddEdge(g, distances, 'C', 'B', 7);
AddEdge(g, distances, 'C', 'D', 3);
AddEdge(g, distances, 'D', 'E', 1);
AddEdge(g, distances, 'E', 'A', 1);
AddEdge(g, distances, 'E', 'B', 1);
var dijkstra = new DijkstraShortestPathAlgorithm<char, Edge<char>>(g, distances);
var predecessors = new VertexPredecessorRecorderObserver<char, Edge<char>>();
predecessors.Attach(dijkstra);
dijkstra.Compute('A');
Assert.AreEqual(0, dijkstra.Distances['A']);
Assert.AreEqual(6, dijkstra.Distances['B']);
Assert.AreEqual(1, dijkstra.Distances['C']);
Assert.AreEqual(4, dijkstra.Distances['D']);
Assert.AreEqual(5, dijkstra.Distances['E']);
}
示例9: 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;
}
示例10: GenerateNormalInput
private AdjacencyGraph<char, TaggedEquatableEdge<char, double>> GenerateNormalInput()
{
var graph = new AdjacencyGraph<char, TaggedEquatableEdge<char,double>>(true);
graph.AddVertexRange("123456");
graph.AddEdge(new TaggedEquatableEdge<char, double>('1', '2', 7)); // 0
graph.AddEdge(new TaggedEquatableEdge<char, double>('1', '3', 9)); // 1
graph.AddEdge(new TaggedEquatableEdge<char, double>('1', '6', 14)); // 2
graph.AddEdge(new TaggedEquatableEdge<char, double>('2', '3', 10)); // 3
graph.AddEdge(new TaggedEquatableEdge<char, double>('2', '4', 15)); // 4
graph.AddEdge(new TaggedEquatableEdge<char, double>('3', '4', 11)); // 5
graph.AddEdge(new TaggedEquatableEdge<char, double>('3', '6', 2)); // 6
graph.AddEdge(new TaggedEquatableEdge<char, double>('4', '5', 6)); // 7
graph.AddEdge(new TaggedEquatableEdge<char, double>('5', '6', 9)); // 8
return graph;
}
示例11: BuildGraph
static AdjacencyGraph<AutoMixingBucket, AutoMixEdge> BuildGraph(
IEnumerable<IMixItem> mixableTracks,
IEnumerable<IMixItem> unknownTracks,
AutoMixingContext context, out AutoMixingBucket optionalStartVertex)
{
IList<AutoMixingBucket> buckets = mixableTracks
.GroupBy(g => g.ActualKey)
.Select(g => new AutoMixingBucket(g, g.Key))
.ToList();
Log.DebugFormat("{0} mixable tracks ({1} buckets aka vertices), {2} unmixable tracks (unknown key/BPM).",
mixableTracks.Count(), buckets.Count(), unknownTracks.Count());
var graph = new AdjacencyGraph<AutoMixingBucket, AutoMixEdge>();
graph.AddVertexRange(buckets);
// If we are auto-mixing a subset of tracks within a mix, we must
// keep them harmonically compatible with the tracks immediately
// before and after i.e. (preceeding)(tracks to mix)(following).
//
// To find such a path, we unfortunately can't just look for paths
// where (start = preceeding and end = following) because they
// might be using different keys that are not used by any of the
// tracks in the graph.
//
// To get around this problem, we add empty 'placeholder' buckets
// (vertices) to the graph for the preceeding/following keys, and
// look for paths that use these vertices as start/end points.
// This works because when we unpack the buckets, these vertices
// simply unpack as empty (they don't contain any tracks) so we can
// use them for the final path of mix items without producing any
// messy placeholder/temporary tracks.
optionalStartVertex = AddPlaceholderVertexIfRequired(graph, context.GetOptionalStartKey());
AddPlaceholderVertexIfRequired(graph, context.GetOptionalEndKey());
return graph;
}