Complex Constraint Search: AI Boundaries and Engineering Optimization

    This article analyzes a constraint-search failure involving 18 geometric regions and explains why local candidate feasibility does not imply global feasibility. It examines visited-state memory bottlenecks, modeling and pruning priorities, search strategies for different goals, independent verification, graceful resource limits, and the verifiable supporting role AI can play in complex constraint problems.

    In one constraint-solving attempt involving multiple geometric regions, a single region labeled “35” produced 4,553 local candidates. As the search advanced to the region labeled “45,” the set used to store visited states continued to grow, eventually exhausting about 12 GB of memory. The running process was terminated by the operating system twice.

    Here, “35” and “45” are region identifiers from the original records, not counts of regions. The real difficulty came from the need to coordinate joint consistency across 18 regions, while each region could also contain many feasible forms.

    The bottleneck in this kind of problem is not “generating a few plausible-looking shapes.” It is selecting, from multiple local candidate sets, a combination that satisfies all constraints at the same time.

    Local candidates may each be valid on their own but still conflict when combined. Examples include:

    • Two regions occupy the same space that is not allowed to be shared.
    • Adjacent boundaries cannot connect according to the rules.
    • Local shapes meet their requirements, but the overall layout is disconnected.
    • A local statistic is satisfied, but the final global statistic exceeds its limit.

    These are common conflict types in geometric constraint problems; they do not mean the original problem necessarily contained all of these rules. Because the original material did not provide a complete problem statement, engineering analysis must distinguish “known facts” from “general methods for reference” and must not invent problem conditions.

    This failure therefore first shows that, under the modeling approach, search strategy, and resource budget used at the time, the existing process did not complete the solve. It does not directly prove that the problem is unsolvable, nor does it prove that all solving methods are unable to handle it.

    2. Why Local Feasibility Does Not Guarantee Global Feasibility

    Let region i have a candidate set Cᵢ. The task is to choose a candidate xᵢ such that all regions satisfy the joint constraints. The problem can be abstracted as follows:

    For each region, choose xᵢ ∈ Cᵢ, and make all local constraints, inter-region constraints, and global constraints hold simultaneously.

    If constraint pruning is temporarily ignored, the number of complete combinations equals the product of the candidate counts for all regions:

    N = |C₁| × |C₂| × … × |C₁₈|

    The original records provided the candidate scale for only one region, so the actual total number of states cannot be calculated from that alone. However, the multiplicative structure already reveals the key issue: a small increase in candidate sets can cause a large increase in the number of combinations.

    More difficult still, some constraints may become visible only at deeper search levels. A branch may appear conflict-free across the first few regions, and only after later regions are added does it become clear that the remaining space is insufficient or that overall connectivity cannot be completed.

    If conflicts are discovered too late, the search program spends substantial time maintaining branches that are ultimately doomed.

    The optimization goal is therefore not only to reduce the cost of each individual computation. More importantly, impossible states should exit as early as possible. A slightly more expensive check that prunes effectively may be more valuable than a very fast check that barely filters any candidates.

    3. Why Visited States Become a Memory Bottleneck

    Search programs often use a visited-state set to avoid repeated exploration. This approach is effective when the state space is small, but it also converts time cost into storage cost.

    It is important to note that a state having little logical content does not mean its actual memory footprint is small. If a state consists of multiple sets, lists, maps, and nested objects, memory must also hold object headers, index structures, references, capacity slack, and other overhead.

    A rough relationship can illustrate the risk:

    Total memory requirement ≈ number of retained states × average state footprint + search stack and auxiliary index overhead

    The average state footprint here should be estimated through actual measurement, not calculated only by counting “how many numbers a state contains.”

    3.1 Distinguish the Working Set from the History Set

    The working set is the branch currently being explored and the information necessary for it. The history set is past states retained for deduplication. Their growth mechanisms differ and should be monitored separately.

    If the history set only grows and never shrinks, memory may be exhausted even when the current search depth is not large. In that case, merely reducing the recursion stack or cutting logs will not address the root cause.

    3.2 Compress the State Representation

    For finite grids, consider using bitsets to represent occupancy, compact integer sequences to represent region choices, and fixed fields to replace repeated nested objects.

    Compression must preserve the information required for solving. For example, two states may occupy the same cells, but if their region identities, boundary conditions, or remaining constraints differ, they may not be mergeable.

    3.3 Set State Equivalence Carefully

    The core of state deduplication is not whether two states “look the same,” but whether the legal continuations from those two states are equivalent.

    If a state key omits conditions that affect future decisions, valid branches may be incorrectly deleted. Conversely, if the state key stores a large amount of irrelevant history, the deduplication rate will decrease and memory consumption will increase.

    For problems with rotational, mirror, or numbering-permutation symmetries, canonical representations can be studied, but first confirm that these transformations truly preserve the problem rules. Different states must not be treated as the same state without proof merely to save space.

    Faced with combinatorial explosion, adding memory usually only delays failure. A more effective order is: clarify constraints, strengthen propagation, optimize branching, and only then consider parallelism or scaling up.

    4.1 Convert Natural-Language Rules into Executable Checks

    Each rule should correspond to explicit inputs, decision conditions, and failure reasons. It is helpful to divide them into three categories:

    • Local constraints that can be checked during candidate generation;
    • Incremental constraints that can be checked after a new region is added;
    • Global constraints that must be checked across all regions.

    Conditions that can be checked earlier should not be deferred to final validation. Otherwise, the search will accumulate many states that could have been eliminated immediately.

    4.2 Prioritize the Hardest Region to Arrange

    A fixed order is not necessarily reasonable. A common strategy is to prioritize the region with the fewest remaining legal candidates, because it is more likely to expose conflicts quickly.

    The degree of constraint association between a region and other regions can also be considered. A variable with many candidates but little effect on other regions may not deserve to be processed first; a region with fewer candidates and broad associations often has more pruning value.

    This is a search heuristic, not a rule guaranteed to be optimal. Its actual effect should be judged through representative instances and runtime statistics.

    4.3 Propagate Constraints Immediately After Each Choice

    After selecting a candidate, not only should its current legality be checked; the candidate sets of other regions should also be updated. If an unprocessed region already has no legal candidate, backtrack immediately.

    An illustrative flow is:

    1. search(current_state):
    2. if all regions are assigned:
    3. run independent global validation
    4. if valid:
    5. record complete solution
    6. return
    7. select the region with the fewest remaining candidates
    8. for each candidate in that region:
    9. if candidate conflicts with current_state:
    10. continue
    11. apply candidate and propagate constraints
    12. if any unassigned region has an empty candidate set:
    13. undo changes
    14. continue
    15. search(updated_state)
    16. undo changes

    This flow expresses a general backtracking framework. A real implementation must also ensure that undo operations restore the full state, avoiding errors caused by shallow copies, shared objects, or residual incremental caches.

    4.4 Check Necessary Global Conditions Early

    Although some global conditions cannot be fully decided early, their necessary conditions can be checked. For example, the remaining space must be sufficient to accommodate unfinished regions, and isolated spaces must not violate the capacity requirements of later regions.

    Necessary-condition checks can only eliminate branches that cannot succeed; they cannot prove that the current branch will ultimately be feasible. Only by understanding this correctly can “no conflict found yet” be avoided as a substitute for “all rules satisfied.”

    5. Different Search Goals Require Different Strategies

    Not every task requires enumerating all answers. The goal should first be identified as one of the following:

    • Find any complete legal solution;
    • Find an optimal solution satisfying some evaluation metric;
    • Enumerate all solutions;
    • Generate the best possible candidates within a limited time;
    • Prove that the problem is unsolvable.

    These goals have different stopping conditions and verification requirements.

    If only one legal solution is needed, the search can stop after finding and verifying it. If an optimal solution is required, it is also necessary to prove that no better solution exists. If the goal is only to generate candidates within a time limit, greedy filling, local improvement, or a search strategy that retains a small number of promising branches can be used, but it must be acknowledged that they may miss correct solutions.

    The original attempt ultimately performed greedy completion from three local layouts and submitted the one with fewer unresolved regions. This can be regarded as a candidate-generation approach after resource exhaustion, but it cannot be regarded as a complete solve.

    “Fewer unresolved regions” is only a progress indicator, not a correctness proof. Sometimes an almost-full layout is already irreparable; another layout with a lower completion level may retain space that leads to a legal solution.

    Therefore, candidate scoring should be recorded separately from constraint validation. A composite score must not hide hard rule violations.

    6. Build an Independent Verifier to Avoid Plausible-Looking Answers

    The solver is responsible for exploration, and the verifier is responsible for judgment. The two should ideally remain moderately independent in implementation, reducing the risk that the same logic error affects both search and acceptance.

    The verification process should include at least:

    1. Check the result format and value range;
    2. Check the local rules of each region;
    3. Check compatibility conditions between regions;
    4. Check the global rules of the complete layout;
    5. Recalculate the final answer from the complete and legal state.

    If the problem submits a number, do not validate only the number format. The computation process from layout to number must be retained; otherwise, it is impossible to determine whether the error lies in the layout, the rule interpretation, or the aggregation calculation.

    At the same time, the following states should be clearly distinguished:

    • Verified complete solution: all necessary constraints have passed checking;
    • Unverified candidate: a result has been formed but has not completed full verification;
    • Partial solution: some regions remain unprocessed;
    • Resource aborted: ended due to time or memory limits;
    • Proven unsatisfiable: all legal possibilities have been excluded under a correct and complete solving process.

    In particular, a “resource abort” must not be reported as “the problem is unsolvable.”

    7. Stop Search Gracefully Before Resource Exhaustion

    A reliable search system should not wait until the operating system terminates the process to discover a problem. Before running, set a time budget, memory warning line, state-count limit, and checkpoint strategy.

    Metrics worth recording continuously include:

    • Current search depth;
    • Number of expanded states;
    • Pruning counts for each type of constraint;
    • Deduplication hit behavior;
    • Remaining candidate scale for each region;
    • Current and peak memory usage;
    • Effective search progress over the most recent period.

    This information helps distinguish the source of the problem: severe state repetition, weak pruning, overly broad candidate generation, or expensive data representation.

    After reaching a warning line, stop expanding new branches, save the state, search order, and candidate records needed for recovery, and then exit in an orderly manner. Saving the complete history set may not be worthwhile; the specific recovery plan should be designed in conjunction with the search algorithm rather than mechanically copying all memory contents.

    Parallel search also requires caution. If multiple execution units each copy large numbers of candidates and historical states, total memory may be exhausted even faster. Whether parallelization is beneficial depends on task partitioning, duplicate computation, and shared-data costs, not just the number of compute cores.

    8. AI Should Take On Verifiable Supporting Responsibilities

    In complex constraint problems, language models are better suited to helping extract rules, discuss modeling approaches, generate program skeletons, explain logs, and design tests, rather than replacing actual proof with confident wording.

    Continuous reasoning and tool calls can improve the workflow, but they do not automatically give the search completeness, nor do they guarantee that limited resources are sufficient to cover the entire state space.

    When the search is not yet complete, a reasonable output should state which checks have been completed, which regions remain undetermined, what defects the current candidates have, and what bottleneck must be resolved to continue computation. Admitting that a task cannot be completed is more consistent with engineering requirements than providing a definite answer without verification.

    A single successful or failed attempt is also insufficient to form a general ranking of model capabilities. Problem representation, constraint implementation, search budget, and verification quality can all significantly affect results.

    What ultimately needs to be established is not “trust in a particular answer,” but an evidence chain that can be checked: rules are expressed explicitly, candidates have a generation basis, pruning has a correctness rationale, results are independently verified, and failures are clearly classified.

    The boundary of AI is not only about stopping output when capabilities are insufficient. It is also about not packaging guesses as proof. For complex geometric and combinatorial search tasks, truly reliable solutions always depend on rigorous modeling, effective pruning, controlled resources, and reproducible results.