private List <IQueryResult> IsPathFree() { string[] line; do { Console.WriteLine("Enter path: <e1> <e2> ..."); line = Console.ReadLine()?.Split(' '); } while (line == null || line.Length == 0 || line.Any(e => !int.TryParse(e, out _))); return(new List <IQueryResult> { EnumerationInference.EnumerationAsk(network, line.Select(int.Parse).Select(graph.Edge).Select(e => new Query(network.BlockageNode(e), false)) .ToList(), evidences) }); }
private List <IQueryResult> BestPath() { string[] line; int id1, id2; do { Console.WriteLine("Select two nodes: <v1> <v2>"); line = Console.ReadLine()?.Split(' '); } while (line == null || line.Length != 2 || !int.TryParse(line[0], out id1) || !int.TryParse(line[1], out id2) || graph.Vertices.All(v => v.Id != id1) || graph.Vertices.All(v => v.Id != id2)); var v1 = graph.Vertex(id1); var v2 = graph.Vertex(id2); var paths = graph.Dfs(v1, v2).Select(path => path.Edges).ToList(); var results = paths.Select(edges => EnumerationInference.EnumerationAsk(network, edges.Select(e => new Query(network.BlockageNode(e), false)).ToList(), evidences)).ToList(); var max = results.Max(r => r.Result); return(results.Where(r => Math.Abs(r.Result - max) < double.Epsilon).ToList()); }
public List <IQueryResult> QueryNodes <T>(List <T> nodes) where T : BayesianNode { return(nodes.Select(node => new Query(node, true)) .Select(query => EnumerationInference.EnumerationAsk(network, query, evidences)) .ToList()); }