// // Integer-based representation of the main hypergraph // public PebblerHypergraph <T, A> GetPebblerHypergraph() { // // Strictly create the nodes // PebblerHyperNode <T, A>[] pebblerNodes = new PebblerHyperNode <T, A> [vertices.Count]; for (int v = 0; v < vertices.Count; v++) { pebblerNodes[v] = vertices[v].CreatePebblerNode(); } // // Non-redundantly create all hyperedges // for (int v = 0; v < vertices.Count; v++) { foreach (HyperEdge <A> edge in vertices[v].edges) { // Only add once to all nodes when this is the 'minimum' source node if (v == edge.sourceNodes.Min()) { PebblerHyperEdge <A> newEdge = new PebblerHyperEdge <A>(edge.sourceNodes, edge.targetNode, edge.annotation); foreach (int src in edge.sourceNodes) { pebblerNodes[src].AddEdge(newEdge); } } } } return(new PebblerHypergraph <T, A>(pebblerNodes)); }
// // 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); } } } }
public Problem(PebblerHyperEdge <A> edge) { givens = new List <int>(edge.sourceNodes); goal = edge.targetNode; path = new List <int>(); edges = new List <PebblerHyperEdge <A> >(); edges.Add(edge); suppressedGivens = new List <int>(); graph = new DiGraph(); graph.AddHyperEdge(givens, goal); }
private void AddEdge(PebblerHyperEdge <A> edge) { // Add to the graph graph.AddHyperEdge(edge.sourceNodes, edge.targetNode); if (this.edges.Contains(edge)) { return; } // Add in an ordered manner according to the target node. int e = 0; for ( ; e < this.edges.Count; e++) { if (edge.targetNode < this.edges[e].targetNode) { break; } } this.edges.Insert(e, edge); }