Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/src/runtime/rx_plan_arrange.h # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / src / runtime / rx_plan_arrange.h` 128 lines · 5581 bytes Raw Blame History 1 /* SPDX-License-Identifier: Apache-2.0 2 * Copyright 2026 Drake Stapleton (AIEN / aien-dev) 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 /* 18 * rx_plan_arrange.h -- the arrangement planning domain and AIEN's planner 19 * for it (OMEGA_PLAN_REUSE, spec/plan-reuse.md §6). 20 * 21 * The classic arrangement ("blocks world") benchmark lifted onto World 22 * objects. A unit (PL_OT_UNIT) has field 0 = what it rests on (packed 23 * reference of another unit, 0 = the floor), field 1 = a label, field 2 = 24 * its own packed reference. A unit is clear when no unit rests on it. A move 25 * puts a clear unit on the floor or on another clear unit; it is one 26 * publication of field 0, checked by the engine against a capability the 27 * principal holds for that unit's resource. 28 * 29 * A goal is a World object (PL_OT_GOAL: 0 seq, 1 kind, 2 max steps, 30 * 3 energy budget, 4 packed ref of a facts object). The facts object holds 31 * up to eight packed facts "x rests on t" or "x rests on the floor". 32 * 33 * The planner is A* over the World projection of every live unit, with an 34 * admissible heuristic (goal objects not yet in their final place, plus 35 * outsiders resting on protected units). It is a small explicit search model 36 * over World predicates, not a neural model. It reads the World and writes 37 * nothing; the plan runs as an action graph. 38 */ 39 #ifndef RX_PLAN_ARRANGE_H 40 #define RX_PLAN_ARRANGE_H 41 42 #include "rx_plan.h" 43 44 #define PLA_MAX_UNITS 14u 45 #define PLA_MAX_FACTS 8u 46 #define PLA_MAX_MOVES 24u 47 #define PLA_MOVE_ENERGY 5u 48 49 enum { PLA_GOAL_ARRANGE = 1 }; 50 enum { PLA_F_SUPPORT = 0, PLA_F_LABEL = 1, PLA_F_SELF = 2 }; 51 52 /* Packed fact: x (id 8 bits, generation 24 bits), target likewise, bit 62 = 53 * floor, bit 63 = present. */ 54 uint64_t pla_fact(RxObjRef x, const RxObjRef *target); 55 56 typedef struct { 57 uint64_t seq, kind, max_steps, energy; 58 uint32_t n_facts; 59 RxObjRef x[PLA_MAX_FACTS], t[PLA_MAX_FACTS]; 60 uint8_t floor[PLA_MAX_FACTS]; 61 /* Goal shape: chains of goal objects, bottom to top, sorted by code. */ 62 uint32_t n_obj; 63 RxObjRef obj[2 * PLA_MAX_FACTS]; /* canonical order */ 64 uint32_t n_chains; 65 struct { uint32_t start, len, grounded; } chain[2 * PLA_MAX_FACTS]; 66 uint8_t shape[32]; 67 } PlaGoal; 68 69 /* Read the goal and its facts from the view and derive the goal shape. 70 * Negative when the goal is malformed (cycle, two units on one, unknown). */ 71 int pla_goal_read(const PlView *v, const PlEnv *env, PlaGoal *g, PlCost *cost); 72 73 /* Binding attempt `attempt` (permutations of interchangeable chains). Fills 74 * slots and returns 1; returns 0 when there is no such attempt; -1 when this 75 * attempt leaves an involved slot unbound. */ 76 int pla_bind(const PlanTemplate *t, const PlView *v, const PlaGoal *g, uint32_t attempt, 77 RxObjRef slots[PL_MAX_SLOTS], PlCost *cost); 78 79 typedef struct { 80 uint32_t n; 81 RxObjRef mover[PLA_MAX_MOVES]; 82 RxObjRef dest[PLA_MAX_MOVES]; /* ignored when to_floor */ 83 uint8_t to_floor[PLA_MAX_MOVES]; 84 } PlaPlan; 85 86 /* What the planner must reach: facts, and units no outsider may rest on 87 * (outsider = a unit not in `insiders`). Built from a goal, or from a 88 * template's required state (adaptation). */ 89 typedef struct { 90 uint32_t n_facts; 91 RxObjRef x[PL_MAX_SLOTS * 2], t[PL_MAX_SLOTS * 2]; 92 uint8_t floor[PL_MAX_SLOTS * 2]; 93 uint32_t n_insiders; 94 RxObjRef insider[PL_MAX_SLOTS * 2]; 95 uint32_t n_protect; 96 RxObjRef protect[PL_MAX_SLOTS * 2]; 97 } PlaTarget; 98 99 void pla_target_from_goal(const PlaGoal *g, PlaTarget *tg); 100 /* Required state of t under `slots` as a target. Negative when the required 101 * state has a predicate a search cannot aim at (a slot resting on an 102 * unnamed non-slot). */ 103 int pla_target_from_template(const PlanTemplate *t, const RxObjRef *slots, PlaTarget *tg); 104 105 /* A*. 0 found (optimal length), negative: no plan within max_expand. */ 106 int pla_plan(const PlView *v, const PlaGoal *g, const PlaTarget *tg, uint64_t max_expand, 107 PlaPlan *out, PlCost *cost); 108 109 /* Apply a plan to a view (no World change). Negative on an illegal move. */ 110 int pla_apply(PlView *v, const PlaPlan *p); 111 112 /* Generalise an executed-to-be plan found in view v0 (the World before it 113 * ran) into a template: slots = goal objects plus the closure of units 114 * resting on slots; required state, invariants, success, the action graph. 115 * slots_out receives the binding of this origin. Negative when the plan 116 * does not fit (slots, graph nodes). */ 117 int pla_generalize(const PlView *v0, const PlaGoal *g, const PlaPlan *p, uint32_t origin, 118 const uint8_t *parent, uint64_t cog_gen, PlanTemplate *t, 119 RxObjRef slots_out[PL_MAX_SLOTS]); 120 121 /* The template's moves under a binding, in plan order (read from its graph). */ 122 int pla_template_moves(const PlanTemplate *t, const RxObjRef *slots, PlaPlan *out); 123 124 /* Domain legality: every live unit rests on the floor or on a live unit, no 125 * unit carries two, no cycle, and its self reference is intact. */ 126 int pla_legal(const PlView *v); 127 128 #endif /* RX_PLAN_ARRANGE_H */