// // The combination of new information may lead to other given information being deducible // // // foreach given in the problem // find all edges with target given // foreach edge with target with given // if (all of the source nodes in edge are in the given OR path) then // if this is a minimal edge (fewer sources better) then // save edge // if (found edge) then // AddEdge to problem // move target given to path // private void PerformDeducibilityCheck(HyperEdgeMultiMap <A> edgeDatabase) { // All the givens and path nodes for this problem; this includes the new edgeSources List <int> problemGivensAndPath = new List <int>(this.givens); problemGivensAndPath.AddRange(this.path); // foreach given in the problem List <int> tempGivens = new List <int>(this.givens); // Make a copy because we may be modifying it below foreach (int given in tempGivens) { PebblerHyperEdge <A> savedEdge = null; // find all edges with target given List <PebblerHyperEdge <A> > forwardEdges = edgeDatabase.GetBasedOnGoal(given); if (forwardEdges != null) { // foreach edge with target with given foreach (PebblerHyperEdge <A> edge in forwardEdges) { // if (all of the source nodes in edge are in the given OR path) then if (Utilities.Subset <int>(problemGivensAndPath, edge.sourceNodes)) { // if this is a minimal edge (fewer sources better) then if (savedEdge == null) { savedEdge = edge; } else if (edge.sourceNodes.Count < savedEdge.sourceNodes.Count) { savedEdge = edge; } } } if (savedEdge != null) { // if (Utilities.PROBLEM_GEN_DEBUG) System.Diagnostics.Debug.WriteLine("CTA: Found another edge which can deduce givens." + savedEdge); // Add the found edge to the problem this.AddEdge(savedEdge); // move target given to path: (1) remove from givens; (2) add to path this.givens.Remove(savedEdge.targetNode); Utilities.AddUnique <int>(this.path, savedEdge.targetNode); } } } }
// // Generate ALL maximal problems from the given start node (note, each incoming basic edge results in a maximal problem). // This gives soundness of generating problems from given nodes (current def of interesting problems), but lacks // completeness by not generating all of the subproblems along the way // // // From this node, generate all problems backward. // Do so by generating simple problems first (in a depth-first manner) // private List<Problem<Hypergraph.EdgeAnnotation>> GenerateAllMaximalProblemsFrom(ProblemHashMap<Hypergraph.EdgeAnnotation> memoizedProblems, HyperEdgeMultiMap<Hypergraph.EdgeAnnotation> edgeDatabase, int node) { if (node == 118) { //Debug.WriteLine("NO-OP"); } // If we have already generated problems, no need to regenerate if (memoizedProblems.HasNodeBeenGenerated(node)) return memoizedProblems.Get(node); // For all edges, create base problems and add them all to the database List<PebblerHyperEdge<Hypergraph.EdgeAnnotation>> edges = edgeDatabase.GetBasedOnGoal(node); // If there are no edges, this is a 'root' node (has no predecessors) if (edges == null || !edges.Any()) { // We've successfully generated all the problems for this node: zero problems memoizedProblems.SetGenerated(node); return new List<Problem<Hypergraph.EdgeAnnotation>>(); } // // Create all the base problems consisting of only one edge and add to the database List<Problem<Hypergraph.EdgeAnnotation>> baseProblems = new List<Problem<Hypergraph.EdgeAnnotation>>(); foreach (PebblerHyperEdge<Hypergraph.EdgeAnnotation> edge in edges) { baseProblems.Add(new Problem<Hypergraph.EdgeAnnotation>(edge)); } // memoizedProblems.PutUnchecked(baseProblems); // For all of the base problems, generate backward foreach (Problem<Hypergraph.EdgeAnnotation> baseProblem in baseProblems) { GenerateMaximalProblemFromSingleEdge(memoizedProblems, edgeDatabase, baseProblem); } // We've successfully generated all the problems for this node memoizedProblems.SetGenerated(node); // Return all the generated problems return memoizedProblems.Get(node); }
// // Generate ALL maximal problems from the given start node (note, each incoming basic edge results in a maximal problem). // This gives soundness of generating problems from given nodes (current def of interesting problems), but lacks // completeness by not generating all of the subproblems along the way // // // From this node, generate all problems backward. // Do so by generating simple problems first (in a depth-first manner) // private List <Problem <Hypergraph.EdgeAnnotation> > GenerateAllMaximalProblemsFrom(ProblemHashMap <Hypergraph.EdgeAnnotation> memoizedProblems, HyperEdgeMultiMap <Hypergraph.EdgeAnnotation> edgeDatabase, int node) { // If we have already generated problems, no need to regenerate if (memoizedProblems.HasNodeBeenGenerated(node)) { return(memoizedProblems.Get(node)); } // For all edges, create base problems and add them all to the database List <PebblerHyperEdge <Hypergraph.EdgeAnnotation> > edges = edgeDatabase.GetBasedOnGoal(node); // If there are no edges, this is a 'root' node (has no predecessors) if (edges == null || !edges.Any()) { // We've successfully generated all the problems for this node: zero problems memoizedProblems.SetGenerated(node); return(new List <Problem <Hypergraph.EdgeAnnotation> >()); } // // Create all the base problems consisting of only one edge and add to the database List <Problem <Hypergraph.EdgeAnnotation> > baseProblems = new List <Problem <Hypergraph.EdgeAnnotation> >(); foreach (PebblerHyperEdge <Hypergraph.EdgeAnnotation> edge in edges) { baseProblems.Add(new Problem <Hypergraph.EdgeAnnotation>(edge)); } // memoizedProblems.PutUnchecked(baseProblems); // For all of the base problems, generate backward foreach (Problem <Hypergraph.EdgeAnnotation> baseProblem in baseProblems) { GenerateMaximalProblemFromSingleEdge(memoizedProblems, edgeDatabase, baseProblem); } // We've successfully generated all the problems for this node memoizedProblems.SetGenerated(node); // Return all the generated problems return(memoizedProblems.Get(node)); }