StreamComponent

Enum StreamComponent 

Source
pub enum StreamComponent {
Show 23 variants ForEach { class_name: String, }, ForEachIncludingUnassigned { class_name: String, }, ForEachUniquePair { class_name: String, joiners: Vec<Joiner>, }, Filter { predicate: WasmFunction, }, Join { class_name: String, joiners: Vec<Joiner>, }, IfExists { class_name: String, joiners: Vec<Joiner>, }, IfNotExists { class_name: String, joiners: Vec<Joiner>, }, IfExistsOther { class_name: String, joiners: Vec<Joiner>, }, IfNotExistsOther { class_name: String, joiners: Vec<Joiner>, }, IfExistsIncludingUnassigned { class_name: String, joiners: Vec<Joiner>, }, IfNotExistsIncludingUnassigned { class_name: String, joiners: Vec<Joiner>, }, GroupBy { keys: Vec<WasmFunction>, aggregators: Vec<Collector>, }, Map { mappers: Vec<WasmFunction>, }, FlattenLast { map: Option<WasmFunction>, }, Expand { mappers: Vec<WasmFunction>, }, Complement { class_name: String, }, Penalize { weight: String, scale_by: Option<WasmFunction>, }, Reward { weight: String, scale_by: Option<WasmFunction>, }, Concat { other_components: Vec<StreamComponent>, }, Distinct, Impact { weight: String, scale_by: Option<WasmFunction>, }, IndictWith { indicted_object_provider: WasmFunction, }, JustifyWith { justification_supplier: WasmFunction, },
}
Expand description

A component in a constraint stream pipeline.

Constraint streams transform entity streams through filtering, joining, grouping, and finally scoring. Components chain together to form constraints.

§Pipeline Structure

A typical constraint pipeline:

  1. Source: for_each("Lesson") - iterate over entities
  2. Filter: filter(predicate) - exclude non-matching entities
  3. Join: join("Timeslot") - combine with another entity type
  4. Score: penalize("1hard") or reward("1soft") - apply scoring

§Example

use solverforge_core::constraints::StreamComponent;

// Simple penalty: penalize each lesson by 1 hard point
let stream = vec![
    StreamComponent::for_each("Lesson"),
    StreamComponent::penalize("1hard"),
];

// Unique pair constraint: penalize conflicting lessons
let conflict = vec![
    StreamComponent::for_each_unique_pair("Lesson"),
    StreamComponent::penalize("1hard"),
];

§Score Weights

Weights specify the penalty/reward magnitude:

  • "1hard" - 1 hard constraint violation
  • "10soft" - 10 soft constraint points
  • "1hard/5soft" - both hard and soft impact

Variants§

§

ForEach

Fields

§class_name: String
§

ForEachIncludingUnassigned

Fields

§class_name: String
§

ForEachUniquePair

Fields

§class_name: String
§joiners: Vec<Joiner>
§

Filter

Fields

§predicate: WasmFunction
§

Join

Fields

§class_name: String
§joiners: Vec<Joiner>
§

IfExists

Fields

§class_name: String
§joiners: Vec<Joiner>
§

IfNotExists

Fields

§class_name: String
§joiners: Vec<Joiner>
§

IfExistsOther

Fields

§class_name: String
§joiners: Vec<Joiner>
§

IfNotExistsOther

Fields

§class_name: String
§joiners: Vec<Joiner>
§

IfExistsIncludingUnassigned

Fields

§class_name: String
§joiners: Vec<Joiner>
§

IfNotExistsIncludingUnassigned

Fields

§class_name: String
§joiners: Vec<Joiner>
§

GroupBy

Fields

§aggregators: Vec<Collector>
§

Map

Fields

§

FlattenLast

§

Expand

Fields

§

Complement

Fields

§class_name: String
§

Penalize

Fields

§weight: String
§

Reward

Fields

§weight: String
§

Concat

Fields

§other_components: Vec<StreamComponent>
§

Distinct

§

Impact

Fields

§weight: String
§

IndictWith

Fields

§indicted_object_provider: WasmFunction
§

JustifyWith

Fields

§justification_supplier: WasmFunction

Implementations§

Source§

impl StreamComponent

Source

pub fn for_each(class_name: impl Into<String>) -> Self

Iterates over all entities of the given class.

This is the most common way to start a constraint stream. Only considers entities with assigned planning variables.

use solverforge_core::constraints::StreamComponent;

let source = StreamComponent::for_each("Lesson");
Source

pub fn for_each_including_unassigned(class_name: impl Into<String>) -> Self

Source

pub fn for_each_unique_pair(class_name: impl Into<String>) -> Self

Iterates over all unique pairs of entities of the given class.

Use this for constraints that compare two entities of the same type, like detecting room conflicts between lessons.

use solverforge_core::constraints::StreamComponent;

// Pairs: (A,B), (A,C), (B,C) - no duplicates like (B,A)
let pairs = StreamComponent::for_each_unique_pair("Lesson");
Source

pub fn for_each_unique_pair_with_joiners( class_name: impl Into<String>, joiners: Vec<Joiner>, ) -> Self

Source

pub fn filter(predicate: WasmFunction) -> Self

Source

pub fn join(class_name: impl Into<String>) -> Self

Source

pub fn join_with_joiners( class_name: impl Into<String>, joiners: Vec<Joiner>, ) -> Self

Source

pub fn if_exists(class_name: impl Into<String>) -> Self

Source

pub fn if_exists_with_joiners( class_name: impl Into<String>, joiners: Vec<Joiner>, ) -> Self

Source

pub fn if_not_exists(class_name: impl Into<String>) -> Self

Source

pub fn if_not_exists_with_joiners( class_name: impl Into<String>, joiners: Vec<Joiner>, ) -> Self

Source

pub fn if_exists_other(class_name: impl Into<String>) -> Self

Source

pub fn if_exists_other_with_joiners( class_name: impl Into<String>, joiners: Vec<Joiner>, ) -> Self

Source

pub fn if_not_exists_other(class_name: impl Into<String>) -> Self

Source

pub fn if_not_exists_other_with_joiners( class_name: impl Into<String>, joiners: Vec<Joiner>, ) -> Self

Source

pub fn if_exists_including_unassigned(class_name: impl Into<String>) -> Self

Source

pub fn if_exists_including_unassigned_with_joiners( class_name: impl Into<String>, joiners: Vec<Joiner>, ) -> Self

Source

pub fn if_not_exists_including_unassigned(class_name: impl Into<String>) -> Self

Source

pub fn if_not_exists_including_unassigned_with_joiners( class_name: impl Into<String>, joiners: Vec<Joiner>, ) -> Self

Source

pub fn group_by(keys: Vec<WasmFunction>, aggregators: Vec<Collector>) -> Self

Source

pub fn group_by_key(key: WasmFunction) -> Self

Source

pub fn group_by_collector(aggregator: Collector) -> Self

Source

pub fn map(mappers: Vec<WasmFunction>) -> Self

Source

pub fn map_single(mapper: WasmFunction) -> Self

Source

pub fn flatten_last() -> Self

Source

pub fn flatten_last_with_map(map: WasmFunction) -> Self

Source

pub fn expand(mappers: Vec<WasmFunction>) -> Self

Source

pub fn complement(class_name: impl Into<String>) -> Self

Source

pub fn penalize(weight: impl Into<String>) -> Self

Penalizes matching entities by a fixed weight.

The weight reduces the solution score. Higher penalties are worse.

use solverforge_core::constraints::StreamComponent;

// Hard constraint: 1 point per violation
let hard = StreamComponent::penalize("1hard");

// Soft constraint: 100 points per violation
let soft = StreamComponent::penalize("100soft");
Source

pub fn penalize_with_weigher( weight: impl Into<String>, scale_by: WasmFunction, ) -> Self

Source

pub fn reward(weight: impl Into<String>) -> Self

Rewards matching entities by a fixed weight.

The weight increases the solution score. Higher rewards are better.

use solverforge_core::constraints::StreamComponent;

// Reward preferred assignments
let bonus = StreamComponent::reward("10soft");
Source

pub fn reward_with_weigher( weight: impl Into<String>, scale_by: WasmFunction, ) -> Self

Source

pub fn concat(other_components: Vec<StreamComponent>) -> Self

Source

pub fn distinct() -> Self

Source

pub fn impact(weight: impl Into<String>) -> Self

Source

pub fn impact_with_weigher( weight: impl Into<String>, scale_by: WasmFunction, ) -> Self

Source

pub fn indict_with(indicted_object_provider: WasmFunction) -> Self

Source

pub fn indict_with_expr(indicted_object_provider: NamedExpression) -> Self

Source

pub fn justify_with(justification_supplier: WasmFunction) -> Self

Source

pub fn justify_with_expr(justification_supplier: NamedExpression) -> Self

Source

pub fn filter_expr(expr: NamedExpression) -> Self

Creates a filter component from a named expression.

§Example
use solverforge_core::wasm::{Expr, FieldAccessExt};
use solverforge_core::constraints::{StreamComponent, IntoNamedExpression};

let has_room = Expr::is_not_null(Expr::param(0).get("Lesson", "room"))
    .named_as("has_room");
let filter = StreamComponent::filter_expr(has_room);
assert!(matches!(filter, StreamComponent::Filter { .. }));
Source

pub fn map_expr(mappers: Vec<NamedExpression>) -> Self

Creates a map component from named expressions.

Source

pub fn map_single_expr(mapper: NamedExpression) -> Self

Creates a single-mapper map component from a named expression.

Source

pub fn group_by_expr( keys: Vec<NamedExpression>, aggregators: Vec<Collector>, ) -> Self

Creates a groupBy component with expression-based key extractors.

Source

pub fn group_by_key_expr(key: NamedExpression) -> Self

Creates a groupBy component with a single expression-based key.

Source

pub fn penalize_with_expr( weight: impl Into<String>, scale_by: NamedExpression, ) -> Self

Creates a penalize component with an expression-based weigher.

Source

pub fn reward_with_expr( weight: impl Into<String>, scale_by: NamedExpression, ) -> Self

Creates a reward component with an expression-based weigher.

Source

pub fn flatten_last_with_expr(map: NamedExpression) -> Self

Creates a flattenLast component with an expression-based mapper.

Source

pub fn expand_expr(mappers: Vec<NamedExpression>) -> Self

Creates an expand component from named expressions.

Source

pub fn impact_with_expr( weight: impl Into<String>, scale_by: NamedExpression, ) -> Self

Creates an impact component with an expression-based weigher.

Trait Implementations§

Source§

impl Clone for StreamComponent

Source§

fn clone(&self) -> StreamComponent

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for StreamComponent

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for StreamComponent

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for StreamComponent

Source§

fn eq(&self, other: &StreamComponent) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for StreamComponent

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for StreamComponent

Source§

impl StructuralPartialEq for StreamComponent

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,