npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@kinaxis/optimization-model-builder

v1.0.0

Published

A library to help create optimization models in Maestro using Embedded Algorithms

Readme

optimization-model-builder

A helper library for building optimization models for use in Embedded Algorithms.

Table of Contents

Quick Start

  1. Create a new Model
  2. Add variables and constraints using the instance methods
  3. Serialize the model using serializeModelToMPS()

Classes

Model

Represents an optimization model. It can have Variables, Constraints added, and an optional objective function offset value. It can then be serialized.

Constructor

Model(objectiveType[, name])

| Argument | Type | Description | | ------------- | --------------------------------- | -------------------------------------- | | objectiveType | ObjectiveType | How to optimize the objective function | | modelName | string \| undefined | The name of the model (optional) |

Example Usage:

import { Model, ObjectiveType } from "@kinaxis/optimization-model-builder";

const myModel = new Model(ObjectiveType.Maximize, "MyModel");

Instance Properties

The properties are read-only and must be populated using the constructor and instance methods.

| Property | Type | Description | | --------------| ------------------------------------ | ------------------------------------------- | | objectiveType | ObjectiveType | How to optimize the objective function | | modelName | string \| undefined | The name of the model | | variables | Map<string, Variable> | The model's variables keyed by name | | constraints | Constraint[] | The model's constraints |

Instance Methods

Model.addVariable(name, params)

Adds a Variable to the model using the provided name and parameters.

Variable names must be unique strings between 1 and 255 characters with no whitespace. The name "OBJ" is prohibited. Names beginning with an underscore are prohibited.

A variable's objective coefficient and bounds (if specified) must be finite numbers. Bounds for binary variables can only be 0 or 1, and bounds for integer variables must be integers.

| Argument | Type | Description | | -------- | ----------------------------------- | ---------------------------------------- | | name | string | The name of the new variable | | params | VariableParams | Paramaters which define the new variable |

Return Value: The newly created and added Variable.

Example Usage:

import { Model, ObjectiveType, VariableType } from "@kinaxis/optimization-model-builder";

const myModel = new Model(ObjectiveType.Maximize, "MyModel");

myModel.addVariable("Var1", {
   variableType: VariableType.Integer,
   objectiveCoefficient: 6.12,
   upperBound: 95
});

Model.addConstraint(lhs, constraintType, rhs[, rhsVariables])

Adds a Constraint to the model.

Constraints must have at least one variable on the left-hand side with no duplicates. Variable coefficients as well as the right-hand side must be finite numbers.

The addVarCoefficient() function can be used to build the left-hand side more easily.

| Argument | Type | Description | | -------------- | -------------------------------------------------------------| ---------------------------------------------------------------------------------------- | | lhs | VariableCoefficient[] | The variables that make up the left-hand side of the constraint, with their coefficients | | constraintType | ConstraintType | The relationship between the left-hand and right-hand sides | | rhs | number | The right-hand side of the constraint | | rhsVariables | VariableCoefficient[] \| undefined | The variables that make up the right-hand side of the constraint, with their coefficients (optional) |

Return Value: The newly created and added Constraint.

Example Usage:

import { Model, ObjectiveType, VariableType, addVarCoefficient } from "@kinaxis/optimization-model-builder";

const myModel = new Model(ObjectiveType.Maximize, "MyModel");

const var1 = myModel.addVariable("Var1", {
   variableType: VariableType.Integer,
   objectiveCoefficient: 6.12,
   upperBound: 95
});

const var2 = myModel.addVariable("Var2", {
   variableType: VariableType.Integer,
   objectiveCoefficient: 10,
   upperBound: 60
});

myModel.addConstraint([
    addVarCoefficient(5, var1)
], ConstraintType.LessEqual, 31);

myModel.addConstraint([
    addVarCoefficient(3, var1)
], ConstraintType.LessEqual, 31, [
    addVarCoefficient(2, var2)
]);

Model.setObjectiveOffset(offset)

Adds a constant offset to the objective function. Must be a finite number.

| Argument | Type | Description | | -------------- | ----------------------------------------------- | ----------------------------------------------------- | | offset | number | The number to set the objective function's offset to |

Example Usage:

import { Model } from "@kinaxis/optimization-model-builder";

const myModel = new Model(ObjectiveType.Maximize, "MyModel");

myModel.setObjectiveOffset(10);

Model.getObjectiveOffset()

Returns the objective function's offset.

Return Value: If the offset has been set, number, else returns undefined.

Example Usage:

import { Model } from "@kinaxis/optimization-model-builder";

const myModel = new Model(ObjectiveType.Maximize, "MyModel");

myModel.setObjectiveOffset(10);

const offsetValue = myModel.getObjectiveOffset();

Free Functions

addVarCoefficient(coefficient, variable)

Helper function for creating VariableCoefficients to define Constraints.

| Argument | Type | Description | | ----------- | ----------------------- | ---------------------------------------------------------- | | coefficient | number | The coefficient for the variable when used in a constraint | | variable | Variable | The variable |

Return Value: Variable and coefficient as a VariableCoefficient.

Example Usage:

import { Model, ObjectiveType, VariableType, addVarCoefficient } from "@kinaxis/optimization-model-builder";

const myModel = new Model(ObjectiveType.Minimize, "MyModel");

const var1 = myModel.addVariable("Var1", {
   variableType: VariableType.Integer,
   objectiveCoefficient: 4.07,
   lowerBound: 65
});

const var2 = myModel.addVariable("Var2", {
   variableType: VariableType.Binary,
   objectiveCoefficient: 5.15
});

const lhs = [
    addVarCoefficient(6, var1),
    addVarCoefficient(1, var2),
];

myModel.addConstraint(lhs, ConstraintType.LessEqual, 1000);

serializeModelToMPS(model)

Serializes a Model to the MPS format.

| Argument | Type | Description | | -------- | ---------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | | model | Model | The optimization model to serialize | | compress | boolean \| undefined | Whether to compress the model (optional; default true). You should only need to set this to false for troubleshooting/debugging purposes. |

Return Value: A string containing the serialized MPS model.

Example Usage:

import { Model, ObjectiveType, serializeModelToMPS } from "@kinaxis/optimization-model-builder";

const myModel = new Model(ObjectiveType.Minimize, "MyModel");

// Populate model...

const mpsString = serializeModelToMPS(myModel);

Enums

ConstraintType

The relationship between a constraint's left-hand side (lhs) and right-hand side (rhs).

| Value | Description | | ------------ | ---------------------- | | GreaterEqual | Indicates lhs >= rhs | | LessEqual | Indicates lhs <= rhs | | Equal | Indicates lhs == rhs |

ObjectiveType

How a Model's objective function should be optimized.

| Value | Description | | -------- | ----------------------------------- | | Maximize | Indicates to maximize the objective | | Minimize | Indicates to minimize the objective |

VariableType

The type of a Variable's value.

| Value | Description | | ---------- | --------------------------------------------------- | | Integer | Indicates an integer variable value | | Binary | Indicates a binary variable value (0 or 1) | | Continuous | Indicates a continuous variable value (real number) |

Types

Variable

A Model variable.

| Property | Type | Description | | -------------------- | ------------------------------- |---------------------------------------------------------------------------------------------------------------------------- | | name | string | The name of the variable | | variableType | VariableType | The type of the variable's value | | objectiveCoefficient | number | The coefficient for the variable when used in a model's objective function | | lowerBound | number \| undefined | The lower bound on the variable's value (optional). Defaults to 0. | | upperBound | number \| undefined | The upper bound on the variable's value (optional). Defaults to positive infinity for continuous variables and 1 otherwise. |

VariableParams

Parameters used when adding a Variable to a Model. See Model instance methods section.

| Property | Type | Description | | -------------------- | ------------------------------- |---------------------------------------------------------------------------------------------------------------------------- | | variableType | VariableType | The type of the variable's value | | objectiveCoefficient | number | The coefficient for the variable when used in a model's objective function | | lowerBound | number \| undefined | The lower bound on the variable's value (optional). Defaults to 0. | | upperBound | number \| undefined | The upper bound on the variable's value (optional). Defaults to positive infinity for continuous variables and 1 otherwise. |

Constraint

A Model constraint.

For example, with constraintType equal to ConstraintType.LessEqual, the constraint is effectively interpreted as lhs[0] + lhs[1] ... lhs[n] <= rhs.

| Property | Type | Description | | -------------- | ----------------------------------------------- | ------------------------------------------------------------------------------------- | | lhs | VariableCoefficient[] | Each variable making up the left-hand side of the constraint, with their coefficients | | constraintType | ConstraintType | The relationship between the left-hand and right-hand sides | | rhs | number | The right-hand side of the constraint | | rhsVariables | VariableCoefficient[] | Each variable making up the right-hand side of the constraint, with their coefficients|

VariableCoefficient

A Variable and its Constraint coefficient. See Model instance methods section.

| Property | Type | Description | | ------------------- | ----------------------- | ---------------------------------------------------------- | | variable | Variable | The variable | | variableCoefficient | number | The coefficient for the variable when used in a constraint |


Please contact [email protected] if you experience any issues.

Copyright © 2025 Kinaxis. All Rights Reserved.