Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion crates/solverforge-console/src/format_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ fn capture_events(f: impl FnOnce()) -> Vec<String> {
outputs: outputs.clone(),
});

tracing::subscriber::with_default(subscriber, f);
tracing::subscriber::with_default(subscriber, || {
// Callsite interest is cached process-wide; rebuild it once this
// thread's dispatcher is installed so a callsite another test thread
// registered concurrently cannot keep a "never" interest.
tracing::callsite::rebuild_interest_cache();
f();
});
let captured = outputs.lock().unwrap().clone();
captured
}
Expand Down
20 changes: 20 additions & 0 deletions crates/solverforge-core/WIREFRAME.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ src/
├── domain/
│ ├── mod.rs — Module declarations and re-exports for domain types
│ ├── traits.rs — PlanningSolution, PlanningEntity, ProblemFact, PlanningId
│ ├── cascade.rs — CascadePropagation: cascading list shadow propagation across list owners
│ ├── dynamic.rs — DynamicModelBackend, scalar/list access contracts, explicit list access/metadata capabilities
│ ├── dynamic/
│ │ ├── assignment.rs — Dynamic scalar-assignment metadata contract and structural capabilities
Expand Down Expand Up @@ -151,6 +152,14 @@ Additionally, `pub mod constraint`, `pub mod constraint_weights`, `pub mod domai
| `list_shadow_elements` | `fn list_shadow_elements(&self, descriptor_index: usize, entity_index: usize) -> Option<(usize, &[usize])>` | Default: `None`; the elements an owner's shadow update writes, with the change source their stream rows use |
| `clear_list_shadows` | `fn clear_list_shadows(&mut self, element: usize)` | Default: no-op; clears the list shadows of an element no list holds |
| `list_shadow_source` | `fn list_shadow_source(collection: &str) -> Option<usize>` | Default: `None`; change source of a collection whose rows carry list shadows |
| `HAS_CASCADING_SHADOWS` | `const HAS_CASCADING_SHADOWS: bool` | Default: `false`; `true` when the list shadows include a cascading shadow (`#[shadow_variable_updates(cascading_field = ...)]`). A score director compiles cascading propagation into its variable-change path only when it is `true` |
| `cascading_element_count` | `fn cascading_element_count(&self) -> usize` | Default: `0`; elements of the collection carrying the cascading shadow |
| `cascading_assigned` | `fn cascading_assigned(&self, element: usize) -> bool` | Default: `false`; whether a list holds `element` |
| `cascading_next` | `fn cascading_next(&self, element: usize) -> Option<usize>` | Default: `None`; the element after `element` in its list |
| `cascading_dependencies` | `fn cascading_dependencies(&self, element: usize, dependencies: &mut Vec<usize>)` | Default: none; appends the elements `element` waits on besides its previous element. Dependencies are problem facts |
| `cascading_unset` | `fn cascading_unset(&self, element: usize) -> bool` | Default: `true`; whether the cascading value is unset |
| `update_cascading_shadow` | `fn update_cascading_shadow<W: FnOnce(&Self)>(&mut self, element: usize, computable: bool, before_write: W) -> bool` | Default: `false`; recomputes (or, when `computable` is `false`, unsets) the value, calls `before_write` before writing a changed value, returns whether it changed |
| `update_list_structure_shadows` | `fn update_list_structure_shadows(&mut self, descriptor_index: usize, entity_index: usize)` | Default: `update_entity_shadows`; refreshes one owner's inverse, index, previous and next shadows without the cascading shadow |
| `is_initialized` | `fn is_initialized(&self) -> bool` | Default: `true` |

**Associated type:** `type Score: Score`
Expand Down Expand Up @@ -328,6 +337,17 @@ pub struct EntityRef {

Derives: `Debug, Clone`

#### `CascadePropagation`

Reusable propagation state for a solution's cascading list shadow (see
`PlanningSolution::HAS_CASCADING_SHADOWS`): the reverse index of the declared
dependencies plus per-element scratch. `Default`.

- `new<S: PlanningSolution>(&S) -> Self` — state with the dependency index built.
- `rebuild_dependencies<S: PlanningSolution>(&mut self, &S)` — rebuilds the index and resizes scratch; panics on a dependency to a missing element.
- `refresh_all<S: PlanningSolution>(&mut S)` — recomputes every cascading value.
- `propagate<S, I, W>(&mut self, &mut S, changed: I, before_write: W)` with `I: IntoIterator<Item = usize>`, `W: FnMut(&S, usize)` — recomputes the downstream cone of the `changed` elements in dependency order: each element at most once, after its inputs in the cone, and only when it is changed, an input changed value, or it is held by a list but unset; elements on a dependency cycle are unset. `before_write` sees the solution before each write.

#### `EntityCollectionExtractor<S, E>`

```rust
Expand Down
15 changes: 14 additions & 1 deletion crates/solverforge-core/public-api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ struct constraint_weights::ConstraintWeights: pub struct ConstraintWeights { /*
constraint_weights::ConstraintWeights: pub fn len(&self) -> usize
constraint_weights::ConstraintWeights: pub fn iter(&self) -> impl Iterator<Item = (&str, u32)>
constraint_weights::ConstraintWeights: pub fn validate<'a>( &self, known: impl IntoIterator<Item = &'a ConstraintRef>, ) -> Result<(), ConstraintWeightError>
struct domain::CascadePropagation: pub struct CascadePropagation { /* private fields */ }
domain::CascadePropagation: pub fn new<S: PlanningSolution>(solution: &S) -> Self
domain::CascadePropagation: pub fn rebuild_dependencies<S: PlanningSolution>(&mut self, solution: &S)
domain::CascadePropagation: pub fn refresh_all<S: PlanningSolution>(solution: &mut S)
domain::CascadePropagation: pub fn propagate<S, I, W>( &mut self, solution: &mut S, changed: I, before_write: W, ) where S: PlanningSolution, I: IntoIterator<Item = usize>, W: FnMut(&S, usize),
struct domain::DynamicListAccessCapabilities: pub struct DynamicListAccessCapabilities { pub set: bool, pub replace: bool, pub reverse: bool, pub sublist: bool, }
struct domain::DynamicListMetadataCapabilities: pub struct DynamicListMetadataCapabilities { pub element_owner: bool, pub construction_order_key: bool, pub precedence_duration: bool, pub precedence_successors: bool, pub cross_position_distance: bool, pub intra_position_distance: bool, pub route: bool, pub savings: bool, }
struct domain::DynamicListVariableSlot: pub struct DynamicListVariableSlot<S> { pub entity: EntityClassId, pub variable: VariableId, pub entity_type_name: &'static str, pub variable_name: &'static str, /* private fields */ }
Expand Down Expand Up @@ -291,8 +296,9 @@ trait domain::PlanningEntity: pub trait PlanningEntity: Clone + Send + Sync + An
trait domain::PlanningId: pub trait PlanningId { type Id: Eq + Hash + Clone + Send + Sync + 'static; // Required method fn planning_id(&self) -> Self::Id; }
domain::PlanningId: type Id: Eq + Hash + Clone + Send + Sync + 'static
domain::PlanningId: fn planning_id(&self) -> Self::Id
trait domain::PlanningSolution: pub trait PlanningSolution: Clone + Send + Sync + 'static { type Score: Score; const HAS_CONSTRAINT_WEIGHTS: bool = false; // Required methods fn score(&self) -> Option<Self::Score>; fn set_score(&mut self, score: Option<Self::Score>); // Provided methods fn update_entity_shadows( &mut self, _descriptor_index: usize, _entity_index: usize, ) { ... } fn update_all_shadows(&mut self) { ... } fn constraint_weights(&self) -> Option<&ConstraintWeights> { ... } fn list_shadow_elements( &self, _descriptor_index: usize, _entity_index: usize, ) -> Option<(usize, &[usize])> { ... } fn clear_list_shadows(&mut self, _element: usize) { ... } fn list_shadow_source(_collection: &str) -> Option<usize> { ... } fn is_initialized(&self) -> bool { ... } }
trait domain::PlanningSolution: pub trait PlanningSolution: Clone + Send + Sync + 'static { type Score: Score; const HAS_CONSTRAINT_WEIGHTS: bool = false; const HAS_CASCADING_SHADOWS: bool = false; Show 16 methods // Required methods fn score(&self) -> Option<Self::Score>; fn set_score(&mut self, score: Option<Self::Score>); // Provided methods fn update_entity_shadows( &mut self, _descriptor_index: usize, _entity_index: usize, ) { ... } fn update_all_shadows(&mut self) { ... } fn constraint_weights(&self) -> Option<&ConstraintWeights> { ... } fn list_shadow_elements( &self, _descriptor_index: usize, _entity_index: usize, ) -> Option<(usize, &[usize])> { ... } fn clear_list_shadows(&mut self, _element: usize) { ... } fn list_shadow_source(_collection: &str) -> Option<usize> { ... } fn cascading_element_count(&self) -> usize { ... } fn cascading_assigned(&self, _element: usize) -> bool { ... } fn cascading_next(&self, _element: usize) -> Option<usize> { ... } fn cascading_dependencies( &self, _element: usize, _dependencies: &mut Vec<usize>, ) { ... } fn cascading_unset(&self, _element: usize) -> bool { ... } fn update_cascading_shadow<W: FnOnce(&Self)>( &mut self, _element: usize, _computable: bool, _before_write: W, ) -> bool { ... } fn update_list_structure_shadows( &mut self, descriptor_index: usize, entity_index: usize, ) { ... } fn is_initialized(&self) -> bool { ... } }
domain::PlanningSolution: const HAS_CONSTRAINT_WEIGHTS: bool = false
domain::PlanningSolution: const HAS_CASCADING_SHADOWS: bool = false
domain::PlanningSolution: type Score: Score
domain::PlanningSolution: fn score(&self) -> Option<Self::Score>
domain::PlanningSolution: fn set_score(&mut self, score: Option<Self::Score>)
Expand All @@ -302,6 +308,13 @@ trait domain::PlanningSolution: pub trait PlanningSolution: Clone + Send + Sync
domain::PlanningSolution: fn list_shadow_elements( &self, _descriptor_index: usize, _entity_index: usize, ) -> Option<(usize, &[usize])>
domain::PlanningSolution: fn clear_list_shadows(&mut self, _element: usize)
domain::PlanningSolution: fn list_shadow_source(_collection: &str) -> Option<usize>
domain::PlanningSolution: fn cascading_element_count(&self) -> usize
domain::PlanningSolution: fn cascading_assigned(&self, _element: usize) -> bool
domain::PlanningSolution: fn cascading_next(&self, _element: usize) -> Option<usize>
domain::PlanningSolution: fn cascading_dependencies( &self, _element: usize, _dependencies: &mut Vec<usize>, )
domain::PlanningSolution: fn cascading_unset(&self, _element: usize) -> bool
domain::PlanningSolution: fn update_cascading_shadow<W: FnOnce(&Self)>( &mut self, _element: usize, _computable: bool, _before_write: W, ) -> bool
domain::PlanningSolution: fn update_list_structure_shadows( &mut self, descriptor_index: usize, entity_index: usize, )
domain::PlanningSolution: fn is_initialized(&self) -> bool
trait domain::ProblemFact: pub trait ProblemFact: Clone + Send + Sync + Any + 'static { // Required method fn as_any(&self) -> &dyn Any; }
domain::ProblemFact: fn as_any(&self) -> &dyn Any
Expand Down
Loading
Loading