// // On-Demand hypergraph construction. // public Hypergraph.Hypergraph <Region, SimpleRegionEquation> ConstructHypergraph() { Queue <Region> worklist = new Queue <Region>(); List <ShapeRegion> shapeRegions = new List <ShapeRegion>(); // Add all the shapes to the worklist. foreach (Figure fig in figures) { ShapeRegion r = new ShapeRegion(fig); shapeRegions.Add(r); worklist.Enqueue(r); } // // Deconstruct non-atomic regions, construct atomic regions. // while (worklist.Any()) { Region currRegion = worklist.Dequeue(); if (!currRegion.IsAtomic()) { RegionDecomposition(currRegion, shapeRegions, worklist); } if (currRegion.IsAtomic()) { RegionComposition(currRegion, shapeRegions, worklist); } } graph.DebugDumpClauses(); Debug.WriteLine(graph.ToString()); return(graph); }
// // Given a shape that owns the atomic region, recur through the resulting atomic region // // From // public void SolveHelper(Region currOuterRegion, List <TreeNode <Figure> > currHierarchyRoots, ComplexRegionEquation currEquation, double currArea, KnownMeasurementsAggregator known) { IndexList currOuterRegionIndices = IndexList.AcquireAtomicRegionIndices(figureAtoms, currOuterRegion.atoms); // There is no outer region if (currOuterRegionIndices.IsEmpty()) { return; } // // We have reached this point by subtracting shapes, therefore, we have an equation. // SolutionAgg agg = new SolutionAgg(); agg.solEq = new ComplexRegionEquation(currEquation); agg.solEq.SetTarget(currOuterRegion); agg.solType = currArea < 0 ? SolutionAgg.SolutionType.INCOMPUTABLE : SolutionAgg.SolutionType.COMPUTABLE; agg.solArea = currArea; agg.atomIndices = currOuterRegionIndices; // // Add this solution to the database. // solutions.AddSolution(agg); // Was this equation solving for a single atomic region? If so, leave. if (currOuterRegion.IsAtomic()) { return; } // // Recursively explore EACH sub-shape root inside of the outer region. // foreach (TreeNode <Figure> shapeNode in currHierarchyRoots) { // A list omitting this shape List <TreeNode <Figure> > updatedHierarchy = new List <TreeNode <Figure> >(currHierarchyRoots); updatedHierarchy.Remove(shapeNode); // Process this shape ProcessShape(currOuterRegion, shapeNode, updatedHierarchy, currEquation, currArea, known); // Process the children ProcessChildrenShapes(currOuterRegion, shapeNode, updatedHierarchy, currEquation, currArea, known); } }
// // Given a shape that owns the atomic region, recur through the resulting atomic region // // From // public void SolveHelper(Region currOuterRegion, List<TreeNode<Figure>> currHierarchyRoots, ComplexRegionEquation currEquation, double currArea, KnownMeasurementsAggregator known) { IndexList currOuterRegionIndices = IndexList.AcquireAtomicRegionIndices(figureAtoms, currOuterRegion.atoms); // There is no outer region if (currOuterRegionIndices.IsEmpty()) return; // // We have reached this point by subtracting shapes, therefore, we have an equation. // SolutionAgg agg = new SolutionAgg(); agg.solEq = new ComplexRegionEquation(currEquation); agg.solEq.SetTarget(currOuterRegion); agg.solType = currArea < 0 ? SolutionAgg.SolutionType.INCOMPUTABLE : SolutionAgg.SolutionType.COMPUTABLE; agg.solArea = currArea; agg.atomIndices = currOuterRegionIndices; // // Add this solution to the database. // solutions.AddSolution(agg); // Was this equation solving for a single atomic region? If so, leave. if (currOuterRegion.IsAtomic()) return; // // Recursively explore EACH sub-shape root inside of the outer region. // foreach (TreeNode<Figure> shapeNode in currHierarchyRoots) { // A list omitting this shape List<TreeNode<Figure>> updatedHierarchy = new List<TreeNode<Figure>>(currHierarchyRoots); updatedHierarchy.Remove(shapeNode); // Process this shape ProcessShape(currOuterRegion, shapeNode, updatedHierarchy, currEquation, currArea, known); // Process the children ProcessChildrenShapes(currOuterRegion, shapeNode, updatedHierarchy, currEquation, currArea, known); } }