Skip to content

Variable: LP

@kortexya/reasoninglayer


@kortexya/reasoninglayer / LP

Variable: LP

const LP: object

Defined in: src/builders/lp.ts:71

Builder namespace for defining Linear Program optimization problems.

Type Declaration

bounds()

readonly bounds(min?, max?): VariableBounds

Create bounds for a variable.

Parameters

min?

number

Lower bound (omit for unbounded below).

max?

number

Upper bound (omit for unbounded above).

Returns

VariableBounds

Variable bounds specification.

Remarks

Serialization format: SDK-internal (compiled to constraint sorts).

Example

LP.bounds(0, 100)
// { min: 0, max: 100 }

constraint()

readonly constraint(coefficients, op, rhs, label?): LinearConstraint

Create a linear constraint.

Parameters

coefficients

LinearExpression

Map of variable names to their constraint coefficients.

op

ConstraintOperator

Comparison operator: ’<=’, ’>=’, or ’=‘.

rhs

number

Right-hand side constant.

label?

string

Optional human-readable label.

Returns

LinearConstraint

A linear constraint.

Remarks

Serialization format: SDK-internal (compiled to constraint sorts).

Example

LP.constraint({ chairs: 1, tables: 3 }, '<=', 12, 'wood')
// { coefficients: { chairs: 1, tables: 3 }, op: '<=', rhs: 12, label: 'wood' }

maximize()

readonly maximize(coefficients): ObjectiveFunction

Create a maximization objective.

Parameters

coefficients

LinearExpression

Map of variable names to their objective coefficients.

Returns

ObjectiveFunction

An objective function to maximize.

Remarks

Serialization format: SDK-internal (compiled to constraint sorts).

Example

LP.maximize({ chairs: 3, tables: 5 })
// { direction: 'maximize', coefficients: { chairs: 3, tables: 5 } }

minimize()

readonly minimize(coefficients): ObjectiveFunction

Create a minimization objective.

Parameters

coefficients

LinearExpression

Map of variable names to their objective coefficients.

Returns

ObjectiveFunction

An objective function to minimize.

Remarks

Serialization format: SDK-internal (compiled to constraint sorts).

Example

LP.minimize({ cost_a: 2, cost_b: 5 })
// { direction: 'minimize', coefficients: { cost_a: 2, cost_b: 5 } }

nonNegative()

readonly nonNegative(…variables): Record<string, VariableBounds>

Create non-negativity bounds (>= 0) for the given variables.

Parameters

variables

string[]

Variable names to constrain to be non-negative.

Returns

Record<string, VariableBounds>

A bounds map with { min: 0 } for each variable.

Remarks

Serialization format: SDK-internal (compiled to constraint sorts).

Example

LP.nonNegative('chairs', 'tables')
// { chairs: { min: 0 }, tables: { min: 0 } }

Remarks

Provides sugar functions for constructing LinearProgramDefinition objects that can be passed to client.optimize.solve(). All functions return plain objects — the builder is optional convenience, not required.

Serialization format: The LP builder produces types consumed by the SDK’s optimize client, which internally compiles them into untagged TermInputDto structures using CLP(Q) constraint sorts.

Example

import { LP } from '@kortexya/reasoninglayer';
const result = await client.optimize.solve({
objective: LP.maximize({ chairs: 3, tables: 5 }),
constraints: [
LP.constraint({ chairs: 1, tables: 3 }, '<=', 12),
LP.constraint({ chairs: 2, tables: 1 }, '<=', 8),
],
bounds: LP.nonNegative('chairs', 'tables'),
});