本文整理汇总了C#中AdjacencyGraph.AddVerticesAndEdge方法的典型用法代码示例。如果您正苦于以下问题:C# AdjacencyGraph.AddVerticesAndEdge方法的具体用法?C# AdjacencyGraph.AddVerticesAndEdge怎么用?C# AdjacencyGraph.AddVerticesAndEdge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AdjacencyGraph
的用法示例。
在下文中一共展示了AdjacencyGraph.AddVerticesAndEdge方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Sample
public void Sample()
{
var testGraph = new AdjacencyGraph<int, Edge<int>>();
testGraph.AddVerticesAndEdge(new Edge<int>(1, 2));
testGraph.AddVerticesAndEdge(new Edge<int>(1, 3));
testGraph.AddVerticesAndEdge(new Edge<int>(3, 4));
testGraph.AddVerticesAndEdge(new Edge<int>(1, 4));
var testPath = testGraph.ShortestPathsBellmanFord<int, Edge<int>>(e => 1.0, 1);
foreach(var i in testGraph.Vertices)
{
IEnumerable<Edge<int>> es;
if (testPath(i, out es))
Console.WriteLine("{0}: {1}", i, es.Count());
}
}
示例2: Create
public static AdjacencyGraph<int, Edge<int>> Create(
bool allowParralelEdges,
KeyValuePair<int, int>[] edges)
{
PexAssume.IsNotNull(edges);
var adjacencyGraph
= new AdjacencyGraph<int, Edge<int>>(allowParralelEdges);
if(edges != null && edges.Length <= 3)
foreach (var edge in edges)
adjacencyGraph.AddVerticesAndEdge(new Edge<int>(edge.Key, edge.Value));
return adjacencyGraph;
}
示例3: ShortestPath
public void ShortestPath()
{
var cities = new AdjacencyGraph<int, Edge<int>>(); // a graph of cities
cities.AddVerticesAndEdge(new Edge<int>(0, 1));
Func<Edge<int>, double> cityDistances = e => e.Target + e.Source ; // a delegate that gives the distance between cities
int sourceCity = 0; // starting city
int targetCity = 1; // ending city
// vis can create all the shortest path in the graph
// and returns a delegate vertex -> path
var tryGetPath = cities.ShortestPathsDijkstra(cityDistances, sourceCity);
IEnumerable<Edge<int>> path;
if (tryGetPath(targetCity, out path))
foreach (var e in path)
Console.WriteLine(e);
}
示例4: BuildGraph
private static DirectedGraph BuildGraph(Dictionary<string, string> allDbObjTypes, Tuple<string, string, string>[] allDependencies)
{
var graph = new AdjacencyGraph<SqlItem, Edge<SqlItem>>();
foreach (var item in allDependencies)
{
string objType1, objType2;
objType1 = allDbObjTypes.TryGetValue(item.Item1, out objType1) ? objType1 : "Unknown";
objType2 = allDbObjTypes.TryGetValue(item.Item2, out objType2) ? objType2 : "Unknown";
SqlItem sqlItem1 = new SqlItem(item.Item1, objType1);
SqlItem sqlItem2 = new SqlItem(item.Item2, objType2);
Edge<SqlItem> newEdge = new Edge<SqlItem>(sqlItem1, sqlItem2);
graph.AddVerticesAndEdge(newEdge);
}
foreach (string item in allDbObjTypes.Values.Distinct())
{
Console.WriteLine(item);
}
var graphToDirectedGraphML = graph.ToDirectedGraphML(vertex => vertex.Name,
ege => string.Empty,
(sqI, dgn) => { dgn.TypeName = GetShortSqlTypeName(sqI.SqlType); },
(eqi, dgl) => { });
return graphToDirectedGraphML;
}
示例5: GetDependencyGraph
/// <summary>
/// Build the dependency graph from the projects found in the root folder - the exlusion patterns
/// </summary>
/// <param name="coreOptions">
/// The coreOptions used to get the dependency order of the projects
/// </param>
/// <returns>
/// A graph representing the dependencies between the projects in the root folder
/// </returns>
public AdjacencyGraph<VisualStudioProject, Edge<VisualStudioProject>> GetDependencyGraph(IMsBuilderificCoreOptions coreOptions)
{
if (!Directory.Exists(coreOptions.RootFolder))
throw new ArgumentException(string.Format("Le répertoire source est inexistant : {0}", coreOptions.RootFolder), "rootFolder");
var graph = new AdjacencyGraph<VisualStudioProject, Edge<VisualStudioProject>>();
var projects = Directory.GetFiles(coreOptions.RootFolder, "*.*proj", SearchOption.AllDirectories);
if (coreOptions.CSharpSupport && coreOptions.VbNetSupport)
projects = projects.Where(s => s.EndsWith(".vbproj") || s.EndsWith(".csproj")).ToArray();
else if (coreOptions.CSharpSupport)
projects = projects.Where(s => s.EndsWith(".csproj")).ToArray();
else if (coreOptions.VbNetSupport)
projects = projects.Where(s => s.EndsWith(".vbproj")).ToArray();
else
projects = new string[]{};
var projs = projects.Where(f => !_excludedPatterns.Any(f.Contains));
foreach (var projectFile in projs)
{
var currentProjectFile = projectFile;
// Get all instances from supported project parser, and retrieve the only one that can work
var projectInstance = _projectLoader.Select(pl =>
{
VisualStudioProject result;
pl.TryParse(currentProjectFile, out result);
return result;
}).SingleOrDefault(s => s != null);
graph.AddVertex(projectInstance);
}
foreach (var v in graph.Vertices)
{
foreach (var dep in v.Dependencies)
{
var dependence = dep;
var target = graph.Vertices.SingleOrDefault(x => x.AssemblyName == dependence);
if (target != null)
graph.AddVerticesAndEdge(new Edge<VisualStudioProject>(v, target));
}
}
return graph;
}
示例6: AddModuleToContext
public static void AddModuleToContext(Module module, ModulesContext ctx, Context global, AdjacencyGraph<Module, Edge<Module>> dependencyGraph)
{
// add module to index
Module storedModule;
if (ctx.ModuleIndex.ContainsKey(module.ModuleName))
{
storedModule = ctx.ModuleIndex[module.ModuleName];
}
else
{
ctx.ModuleIndex[module.ModuleName] = module;
dependencyGraph.AddVertex(module);
storedModule = module;
}
// fill in module's sections first
module.NodeList.ForEach(o =>
{
Section s = o as Section;
if (s != null)
{
List<Section> secList;
if (storedModule.Sections.ContainsKey(s.SectionName))
{
secList = storedModule.Sections[s.SectionName];
}
else
{
secList = new List<Section>();
storedModule.Sections[s.SectionName] = secList;
}
secList.Add(s);
}
});
// then parse dependencies and upgrade dependency graph
module.NodeList.ForEach(o =>
{
DependsOn d = o as DependsOn;
if (d != null)
{
// add this module to context
Module dependsOn = AddModuleToContextByName(d.ModuleName, ctx, global, dependencyGraph);
// upgrade graph
dependencyGraph.AddVerticesAndEdge(new Edge<Module>(dependsOn, storedModule));
}
});
}
示例7: BuildServicesThree
//TODO <ServiceVertex, CKEdge>
private AdjacencyGraph<IVertex, CKEdge> BuildServicesThree(String ckAssemblieFolder)
{
PluginDiscoverer discoverer = GetFooBarPluginDiscoverer(ckAssemblieFolder);
List<ServiceVertex> serviceVertices = new List<ServiceVertex>();
var serviceThree = new AdjacencyGraph<IVertex, CKEdge>();
ConsoleManager.Toggle();
foreach (IServiceInfo serv in discoverer.AllServices)
{
serviceVertices.Add(new ServiceVertex(serv));
}
foreach (ServiceVertex servVertex in serviceVertices)
{
if (servVertex.Service.Generalization != null)
{
ServiceVertex gen = serviceVertices.Where(
delegate(ServiceVertex item)
{
if ( item.Service == servVertex.Service.Generalization)
{
return true;
}
return false;
}
).First();
serviceThree.AddVerticesAndEdge(
new CKEdge(servVertex, gen)
);
}
else
{
serviceThree.AddVertex(servVertex);
}
}
/* foreach(IServiceInfo serv in discoverer.AllServices)
{
if (serv.Generalization != null)
{
/*serviceThree.AddVerticesAndEdge(
new TaggedEdge<IServiceInfo, string>(serv, serv.Generalization, String.Format("{0} generalisation", serv.ServiceFullName))
);/
serviceThree.AddVerticesAndEdge(
new CKEdge(new ServiceVertex(serv), new ServiceVertex(serv.Generalization))
);
}
else
{
serviceThree.AddVertex(new ServiceVertex(serv));
}
}*/
Console.WriteLine(serviceThree);
ConsoleManager.Toggle();
return serviceThree;
}