public override SpecificLayout GetBestLayout(LayoutQuery query) { SpecificLayout best_specificLayout = null; SpecificLayout debugResult = query.ProposedSolution_ForDebugging; if (debugResult != null) { debugResult = debugResult.Clone(); } List <LayoutChoice_Set> good_sourceLayouts = new List <LayoutChoice_Set>(); LayoutQuery originalQuery = query; foreach (LayoutChoice_Set layoutSet in this.layoutOptions) { if (best_specificLayout != null) { // make the query more strict, so we will only ever get dimensions that are at least as good as this // TODO: figure out why it's not better to use OptimizedPastExample query = query.OptimizedUsingExample(best_specificLayout); } SpecificLayout currentLayout; if (query.Debug) { // if the proposed layout is an option, then be sure to consider it if (debugResult != null && debugResult.GetAncestors().Contains(layoutSet)) { query.ProposedSolution_ForDebugging = debugResult; currentLayout = layoutSet.GetBestLayout(query); query.ProposedSolution_ForDebugging = debugResult; return(this.prepareLayoutForQuery(currentLayout, query)); } } currentLayout = layoutSet.GetBestLayout(query); if (currentLayout != null && query.PreferredLayout(currentLayout, best_specificLayout) == currentLayout) { // keep track of this query (which must be the best so far) best_specificLayout = currentLayout; good_sourceLayouts.Add(layoutSet); if (query.Debug && query.ProposedSolution_ForDebugging != null) { if (query.PreferredLayout(query.ProposedSolution_ForDebugging, best_specificLayout) != query.ProposedSolution_ForDebugging) { ErrorReporter.ReportParadox("Error; query " + query + " prefers " + best_specificLayout + " over proposed debug solution " + query.ProposedSolution_ForDebugging); LayoutQuery debugQuery = query.DebugClone(); layoutSet.GetBestLayout(debugQuery); } } } } originalQuery.ProposedSolution_ForDebugging = debugResult; return(this.prepareLayoutForQuery(best_specificLayout, originalQuery)); }