/** * @file src/expressions.ts * @description Core expression classes for building optimization models * * Defines the building blocks for programmatic model construction: * - Variable: Decision variable with cost and bounds * - IntegerVariable: Variable restricted to integer values * - SlackVariable: Internal variable for constraint conversion * - Term: Variable-coefficient pair in a constraint * - Constraint: Linear inequality (<=, >=) with terms * - Equality: Equality constraint (=) represented as two inequalities * * These classes support the fluent API: model.smallerThan(10).addTerm(2, x) */ type Priority = number | "required" | "strong" | "medium" | "weak"; declare class Variable$1 { id: string; cost: number; index: number; value: number; priority: number; isInteger?: true; isSlack?: true; constructor(id: string, cost: number, index: number, priority: number); } declare class IntegerVariable extends Variable$1 { isInteger: true; constructor(id: string, cost: number, index: number, priority: number); } declare class SlackVariable extends Variable$1 { isSlack: true; constructor(id: string, index: number); } declare class Term$1 { variable: Variable$1; coefficient: number; constructor(variable: Variable$1, coefficient: number); } type RelaxationModel = Model & { addVariable(cost: number, id: string, isInteger?: boolean, isUnrestricted?: boolean, priority?: number): Variable$1; }; declare class Constraint$1 { slack: SlackVariable; index: number; model: RelaxationModel; rhs: number; isUpperBound: boolean; terms: Term$1[]; termsByVarIndex: Record; relaxation: Variable$1 | null; constructor(rhs: number, isUpperBound: boolean, index: number, model: RelaxationModel); addTerm(coefficient: number, variable: Variable$1): this; removeTerm(_term: Term$1): this; setRightHandSide(newRhs: number): this; setVariableCoefficient(newCoefficient: number, variable: Variable$1): this | void; relax(weight?: number, priority?: Priority): void; _relax(relaxationVariable: Variable$1 | null): void; } declare class Equality { upperBound: Constraint$1; lowerBound: Constraint$1; model: RelaxationModel; rhs: number; relaxation: Variable$1 | null; isEquality: true; constructor(constraintUpper: Constraint$1, constraintLower: Constraint$1); addTerm(coefficient: number, variable: Variable$1): this; removeTerm(_term: Term$1): this; setRightHandSide(rhs: number): void; relax(weight?: number, priority?: Priority): void; } declare class Numeral$1 { value: number; constructor(value: number); } interface ExternalSolverModule { reformat?: (model: Model$1) => unknown; solve: (model: Model$1) => Promise; } type ExternalSolvers = Record; /** * @file src/types/solver.ts * @description Public API type definitions * * Defines the types exposed to library consumers: * - Model: JSON model definition format * - SolveResult: Solution output format * - SolveOptions: Solver configuration options * - ConstraintBound: Constraint specification * - Variable, Term, Constraint: Expression types */ type ObjectiveDirection = "max" | "min"; type ConstraintRelation = "min" | "max" | "equal"; interface SolveOptions { tolerance?: number; timeout?: number; useMIRCuts?: boolean; exitOnCycles?: boolean; keep_solutions?: boolean; nodeSelection?: "best-first" | "depth-first" | "hybrid"; branching?: "most-fractional" | "pseudocost" | "strong"; presolve?: boolean; useIncremental?: boolean; } interface ConstraintBound { min?: number; max?: number; equal?: number; weight?: number; priority?: number | "required" | "strong" | "medium" | "weak"; } interface VariableCoefficients { [constraintName: string]: number; } interface Model$1 { name?: string; optimize: string | Record; opType?: ObjectiveDirection; constraints: Record; variables: Record; ints?: Record; binaries?: Record; unrestricted?: Record; tolerance?: number; timeout?: number; options?: SolveOptions; external?: { solver: string; [key: string]: unknown; }; } interface Variable { id: string; cost: number; index: number; value: number; priority: number; isInteger?: boolean; isSlack?: boolean; } interface Term { variable: Variable; coefficient: number; } interface Constraint { slack: Variable; index: number; model: unknown; rhs: number; isUpperBound: boolean; terms: Term[]; termsByVarIndex: Record; relaxation: Variable | null; } interface Numeral { value: number; } interface SolveResult { feasible: boolean; result: number; bounded?: boolean; isIntegral?: boolean; [variable: string]: number | boolean | undefined; } type Solution$1 = SolveResult & Record; type SolverAPI = typeof solver; type ModelDefinition = Model$1; /** * @file src/tableau/solution.ts * @description Solution classes for LP and MIP results * * Provides solution containers for optimization results: * - Solution: Base class for continuous LP problems * - MilpSolution: Extended class for mixed-integer problems * * Solutions include feasibility status, objective value, and variable values. */ /** * Represents a solution to a linear programming problem. */ declare class Solution { feasible: boolean; evaluation: number; bounded: boolean; _tableau: Tableau; solutionSet: TableauSolutionSet; constructor(tableau: Tableau, evaluation: number, feasible: boolean, bounded: boolean); /** * Generate the solution set mapping variable IDs to their values. */ generateSolutionSet(): TableauSolutionSet; } /** * Represents a solution to a mixed-integer programming problem. * Extends Solution with branch-and-cut iteration tracking. */ declare class MilpSolution extends Solution { iter: number; constructor(tableau: Tableau, evaluation: number, feasible: boolean, bounded: boolean, branchAndCutIterations: number); } /** * @file src/tableau/types.ts * @description Internal type definitions for the tableau module * * Defines types used within the tableau implementation: * - BranchCut: Bound constraint for MIP branching * - Branch: Node in the branch-and-bound tree * - OptionalObjective: Secondary objective for hierarchical optimization */ type BoundType = "min" | "max"; interface BranchCut { type: BoundType; varIndex: number; value: number; } interface OptionalObjective { priority: number; reducedCosts: number[]; copy(): OptionalObjective; } interface VariableValue { index: number | null; value: number | null; } type TableauSolution = Solution | MilpSolution; interface TableauSolutionSet { [variable: string]: number | undefined; result?: number; } /** * @file src/tableau/presolve.ts * @description Problem preprocessing for LP/MIP * * Applies reductions before solving to simplify the problem: * - Fix variables with equal bounds * - Detect singleton rows (single-variable constraints) * - Tighten variable bounds from constraint coefficients * - Remove redundant constraints * * Based on techniques from COIN-OR CBC, CPLEX, and Gurobi. */ interface PresolveResult { fixedVariables: Map; removedConstraints: Set; tightenedBounds: Map; isInfeasible: boolean; stats: { variablesFixed: number; constraintsRemoved: number; boundsTightened: number; }; } /** * @file src/model.ts * @description Model class for LP/MIP problem representation * * Provides the programmatic API for building optimization problems: * - Add variables with costs and integer constraints * - Define constraints (<=, >=, =) with coefficients * - Load problems from JSON model definitions * - Dynamic model modification after initialization * * The Model converts high-level problem definitions into the internal * Tableau representation used by the simplex algorithm. */ declare class Model { tableau: Tableau; name?: string; variables: Variable$1[]; integerVariables: IntegerVariable[]; unrestrictedVariables: Record; constraints: Constraint$1[]; nConstraints: number; nVariables: number; isMinimization: boolean; tableauInitialized: boolean; relaxationIndex: number; useMIRCuts: boolean; checkForCycles: boolean; messages: unknown[]; tolerance?: number; timeout?: number; keep_solutions?: boolean; solutions?: TableauSolutionSet[]; availableIndexes: number[]; lastElementIndex: number; usePresolve: boolean; presolveResult: PresolveResult | null; constructor(precision?: number, name?: string, branchAndCutService?: BranchAndCutService); minimize(): this; maximize(): this; _getNewElementIndex(): number; _addConstraint(constraint: Constraint$1): void; smallerThan(rhs: number): Constraint$1; greaterThan(rhs: number): Constraint$1; equal(rhs: number): Equality; addVariable(cost?: number | null, id?: string | null, isInteger?: boolean, isUnrestricted?: boolean, priority?: Priority | null): Variable$1; _removeConstraint(constraint: Constraint$1): void; removeConstraint(constraint: Constraint$1 | Equality): this; removeVariable(variable: Variable$1): this | void; updateRightHandSide(constraint: Constraint$1, difference: number): this; updateConstraintCoefficient(constraint: Constraint$1, variable: Variable$1, difference: number): this; setCost(cost: number, variable: Variable$1): this; loadJson(jsonModel: Model$1): this; getNumberOfIntegerVariables(): number; solve(): TableauSolution; /** * Apply presolve reductions to the model. * Sets fixed variable values and removes redundant constraints. */ private applyPresolveReductions; isFeasible(): boolean; save(): void; restore(): void; activateMIRCuts(useMIRCuts: boolean): void; debug(debugCheckForCycles: boolean): void; log(message: unknown): Tableau; } declare class Tableau { model: Model | null; matrix: Float64Array; width: number; height: number; costRowIndex: number; rhsColumn: number; variablesPerIndex: Array; unrestrictedVars: Record; feasible: boolean; evaluation: number; simplexIters: number; varIndexByRow: number[]; varIndexByCol: number[]; rowByVarIndex: number[]; colByVarIndex: number[]; precision: number; optionalObjectives: OptionalObjective[]; objectivesByPriority: Record; optionalObjectivePerPriority: Record; savedState: Tableau | null; availableIndexes: number[]; lastElementIndex: number; variables: Variable$1[]; nVars: number; bounded: boolean; unboundedVarIndex: number | null; branchAndCutIterations: number; bestPossibleEval: number; __isIntegral?: boolean; pricingBatchStart: number; pricingBatchSize: number; readonly branchAndCutService: BranchAndCutService; constructor(precision?: number, branchAndCutService?: BranchAndCutService); simplex(): this; phase1(): number; phase2(): number; /** * Dual simplex for warm-starting after adding bound constraints. * Use when solution is dual feasible but may be primal infeasible. * @returns Number of iterations, or -1 if dual infeasible */ dualSimplex(): number; pivot(pivotRowIndex: number, pivotColumnIndex: number): void; checkForCycles(varIndexes: Array<[number, number]>): number[]; countIntegerValues(): number; isIntegral(): boolean; computeFractionalVolume(ignoreIntegerValues?: boolean): number; addCutConstraints(branchingCuts: BranchCut[]): void; applyMIRCuts(): void; addLowerBoundMIRCut(rowIndex: number): boolean; addUpperBoundMIRCut(rowIndex: number): boolean; getMostFractionalVar(): VariableValue; getFractionalVarWithLowestCost(): VariableValue; putInBase(varIndex: number): number; takeOutOfBase(varIndex: number): number; updateVariableValues(): void; updateRightHandSide(constraint: Constraint$1, difference: number): void; updateConstraintCoefficient(constraint: Constraint$1, variable: Variable$1, difference: number): void; updateCost(variable: Variable$1, difference: number): void; addConstraint(constraint: Constraint$1): void; removeConstraint(constraint: Constraint$1): void; addVariable(variable: Variable$1): void; removeVariable(variable: Variable$1): void; copy(): Tableau; save(): void; restore(): void; log(message: unknown): this; applyCuts(branchingCuts: BranchCut[]): void; branchAndCut(): void; solve(): TableauSolution; getSolution(): TableauSolution; setOptionalObjective(priority: number, column: number, cost: number): void; initialize(width: number, height: number, variables: Variable$1[], unrestrictedVars: Record): void; _resetMatrix(): void; setModel(model: Model): this; getNewElementIndex(): number; density(): number; setEvaluation(): void; } /** * @file src/tableau/branch-and-cut.ts * @description Branch-and-cut algorithm for mixed-integer programming * * Implements the branch-and-bound algorithm with cutting planes to find * integer-optimal solutions. Uses a priority queue (min-heap) to explore * promising branches first based on relaxed objective values. * * Key features: * - Branching on fractional integer variables * - Gomory cuts to tighten LP relaxation * - Best-first node selection * - Early termination via tolerance */ interface BranchAndCutService { applyCuts(tableau: Tableau, branchingCuts: BranchCut[]): void; branchAndCut(tableau: Tableau): void; } /** * Main solver class providing the public API for solving optimization problems. */ declare class Solver { Model: typeof Model; Tableau: typeof Tableau; Constraint: typeof Constraint$1; Variable: typeof Variable$1; Numeral: typeof Numeral$1; Term: typeof Term$1; External: ExternalSolvers; ReformatLP: (model: any) => string | { opType: string; optimize: string; constraints: {}; variables: {}; }; branchAndCutService: BranchAndCutService; branchAndCut: (tableau: Tableau) => void; lastSolvedModel: Model | null; /** * Select the appropriate branch-and-cut service based on model options. * * Enhanced strategies can be enabled via model.options: * - nodeSelection: 'best-first' | 'depth-first' | 'hybrid' * - branching: 'most-fractional' | 'pseudocost' | 'strong' * - useIncremental: true to use incremental state management (experimental) */ private selectBranchAndCutService; /** * Solve a linear or mixed-integer programming problem. * * @param model - Problem definition (JSON format or Model instance) * @param precision - Tolerance for integer constraints (default: 1e-9) * @param full - If true, return full Solution object; otherwise return simplified result * @param validate - If true, run model through validation functions * @returns Solution object or simplified result with variable values */ Solve<_TVariable extends string = string>(model: Model$1 | Model, precision?: number, full?: boolean, validate?: boolean): SolveResult | unknown; /** * Delegate solving to an external solver (e.g., lp_solve). */ private solveWithExternalSolver; /** * Build a simplified result object from a full solution. */ private buildSimplifiedResult; /** * Solve a multi-objective optimization problem. * * Returns a compromise solution using the mid-point formula between * individually optimized objectives. * * @example * const model = { * optimize: { profit: "max", risk: "min" }, * constraints: { budget: { max: 1000 } }, * variables: { ... } * }; * const result = solver.MultiObjective(model); */ MultiObjective(model: Model$1): unknown; } declare const solver: Solver; /** * @file src/solver.ts * @description Main entry point for jsLPSolver library * * Re-exports the solver instance and all public types. This is the primary * import target for library consumers. * * @example * import solver from "javascript-lp-solver"; * const result = solver.Solve(model); */ export { type Constraint, type ConstraintBound, type ConstraintRelation, type ExternalSolverModule, type ExternalSolvers, type Model$1 as Model, type ModelDefinition, type Numeral, type ObjectiveDirection, type Solution$1 as Solution, type SolveOptions, type SolveResult, type SolverAPI, type Term, type Variable, type VariableCoefficients, solver as default };