Freon793/moonopt/model does not have a README file

    Constraint

    pub struct Constraint {
    name : String
    rel : Rel
    rhs : Double
    terms : Array[(Int, Double)]
    } derive(
    Debug
    )

    One constraint row: terms relation rhs.

    Model

    pub struct Model {
    sense : Sense
    objective_terms : Array[(Int, Double)]
    vars : Array[Var]
    constraints : Array[Constraint]
    } derive(
    Debug
    )

    An optimisation model under construction.

    Model::add_constraint

    fn Model::add_constraint(self : Model, terms : Array[(Int, Double)], rel : Rel, rhs : Double) -> Unit

    Adds an unnamed constraint row.

    Model::add_named_constraint

    fn Model::add_named_constraint(self : Model, terms : Array[(Int, Double)], rel : Rel, rhs : Double, name : String) -> Unit

    Adds a constraint row carrying a human readable name (used by reports and by the MPS writer).

    Model::add_var

    fn Model::add_var(self : Model, name : String, lb? : Double, ub? : Double, is_int? : Bool) -> Int

    Adds a variable and returns its index.

    lb = 0.0 and ub = infinite_bound give the LP default x >= 0. Set is_int = true for integer variables (binary variables are lb = 0, ub = 1, is_int = true).

    Model::clone

    fn Model::clone(self : Model) -> Model

    A copy that can be changed without touching the original.

    Used by the branch and bound, where every node is the parent model with one variable's bound tightened: set_var_bounds replaces the entry it is given, so copying the arrays is enough to keep the parent intact. The terms inside a constraint are shared rather than copied — nothing in this package mutates them, and a tree of nodes that copied every row's coefficients would spend its memory on the part of the model that branching never touches.

    Model::constraint

    fn Model::constraint(self : Model, index : Int) -> Constraint

    Reads back a constraint row.

    Model::get_var

    fn Model::get_var(self : Model, index : Int) -> Var

    Reads back a variable definition. (var is a keyword in MoonBit, hence the name.)

    Model::is_valid

    fn Model::is_valid(self : Model) -> Bool

    Returns true when the model passes validate.

    Model::new

    fn Model::new(sense : Sense) -> Model

    Creates an empty model with the given optimisation direction.

    Model::num_constraints

    fn Model::num_constraints(self : Model) -> Int

    Number of constraint rows.

    Model::num_vars

    fn Model::num_vars(self : Model) -> Int

    Number of variables.

    Model::objective

    fn Model::objective(self : Model) -> Array[(Int, Double)]

    Objective as sorted (variable index, coefficient) pairs.

    Model::sense

    fn Model::sense(self : Model) -> Sense

    Current optimisation direction.

    Model::set_objective

    fn Model::set_objective(self : Model, terms : Array[(Int, Double)]) -> Unit

    Replaces the objective, merging duplicates and dropping zeros.

    Model::set_sense

    fn Model::set_sense(self : Model, sense : Sense) -> Unit

    Changes the optimisation direction after the fact.

    Model::set_var_bounds

    fn Model::set_var_bounds(self : Model, index : Int, lb : Double, ub : Double) -> Unit

    Replaces the bounds of a variable.

    Model file readers need this: a file states bounds in a section that comes after the columns, so the variable exists before its final bounds are known.

    Model::set_var_integer

    fn Model::set_var_integer(self : Model, index : Int) -> Unit

    Marks a variable as integer. Kept separate from set_var_bounds because model files express integrality through markers or sections of their own.

    Model::validate

    fn Model::validate(self : Model) -> Array[String]

    Checks the model for structural problems. An empty result means the model is well formed; a non-empty result lists human readable issues.

    This is deliberately a pure function returning messages instead of raising, so callers (CLI, tests, future LSP tooling) can render them however they want.

    Rel

    pub(all) enum Rel {
    LessEqual
    GreaterEqual
    Equal
    } derive(Eq,
    Debug
    )

    Relation of a constraint row.

    Rel::from_symbol

    fn Rel::from_symbol(symbol : String) -> Rel?

    Parses an MPS row type keyword: L (less-equal), G (greater-equal), E (equal). Returns None for anything else.

    Sense

    pub(all) enum Sense {
    Minimize
    Maximize
    } derive(Eq,
    Debug
    )

    Optimisation direction.

    pub(all) on purpose: other packages (the parsers, the solver, user code) must be able to build and match these values.

    Sense::from_symbol

    fn Sense::from_symbol(symbol : String) -> Sense?

    Parses an objective sense keyword as used by MPS (MAX / MIN, also the long forms). Returns None for anything else so callers can report a precise parse error.

    Var

    pub struct Var {
    name : String
    lb : Double
    ub : Double
    is_int : Bool
    } derive(
    Debug
    )

    One decision variable.

    infinite_bound

    let infinite_bound : Double

    Numeric stand-in for an infinite bound.

    normalize_terms

    fn normalize_terms(terms : Array[(Int, Double)]) -> Array[(Int, Double)]

    Sorts terms by variable index, merges duplicates and drops zeros.