javascript-lp-solver 1.0.0 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -9
- package/dist/index.browser.mjs +515 -774
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.cjs +515 -774
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +38 -33
- package/dist/index.mjs +515 -774
- package/dist/index.mjs.map +1 -1
- package/dist/solver.global.js +515 -774
- package/dist/solver.global.js.map +1 -1
- package/dist/types/main.d.ts +1 -1
- package/dist/types/polyopt.d.ts +1 -1
- package/dist/types/shims/external.d.ts +2 -6
- package/dist/types/tableau/index.d.ts +1 -4
- package/dist/types/tableau/min-heap.d.ts +4 -0
- package/dist/types/tableau/presolve.d.ts +0 -10
- package/dist/types/tableau/simplex.d.ts +16 -0
- package/dist/types/tableau/solution.d.ts +0 -1
- package/dist/types/tableau/tableau.d.ts +6 -0
- package/dist/types/tableau/types.d.ts +4 -21
- package/dist/types/test-utils/problem-generator.d.ts +2 -2
- package/package.json +9 -1
- package/scripts/ts-node-register.js +1 -1
package/dist/types/main.d.ts
CHANGED
|
@@ -51,7 +51,7 @@ declare class Solver {
|
|
|
51
51
|
* @param validate - If true, run model through validation functions
|
|
52
52
|
* @returns Solution object or simplified result with variable values
|
|
53
53
|
*/
|
|
54
|
-
Solve<
|
|
54
|
+
Solve<_TVariable extends string = string>(model: ModelDefinition | Model, precision?: number, full?: boolean, validate?: boolean): SolveResult | unknown;
|
|
55
55
|
/**
|
|
56
56
|
* Delegate solving to an external solver (e.g., lp_solve).
|
|
57
57
|
*/
|
package/dist/types/polyopt.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ interface SolverLike {
|
|
|
16
16
|
}
|
|
17
17
|
type PolyoptSolution = SolveResult & Record<string, number>;
|
|
18
18
|
type Vertex = Record<string, number>;
|
|
19
|
-
|
|
19
|
+
interface PolyoptResult {
|
|
20
20
|
midpoint: PolyoptSolution;
|
|
21
21
|
vertices: Vertex[];
|
|
22
22
|
ranges: Record<string, {
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* In browser environments, external solvers (which require Node.js
|
|
6
|
-
* child_process and fs) are not available. This shim provides an
|
|
7
|
-
* empty export to satisfy imports without runtime errors.
|
|
2
|
+
* Browser shim for external solvers.
|
|
3
|
+
* External solvers require Node.js (child_process) and are unavailable in browsers.
|
|
8
4
|
*/
|
|
9
5
|
import type { ExternalSolvers } from "../external/main";
|
|
10
6
|
declare const External: ExternalSolvers;
|
|
@@ -10,8 +10,5 @@
|
|
|
10
10
|
* - Cutting plane generation
|
|
11
11
|
*/
|
|
12
12
|
import Tableau from "./tableau";
|
|
13
|
-
export {
|
|
14
|
-
export { Solution, MilpSolution } from "./solution";
|
|
15
|
-
export type { BoundType, Branch, BranchCut, OptionalObjective, SavedState, TableauSolution, TableauSolutionSet, VariableValue, } from "./types";
|
|
13
|
+
export type { TableauSolution, TableauSolutionSet } from "./types";
|
|
16
14
|
export default Tableau;
|
|
17
|
-
export { Tableau };
|
|
@@ -14,7 +14,11 @@ export declare class BranchMinHeap {
|
|
|
14
14
|
private heap;
|
|
15
15
|
private size;
|
|
16
16
|
private seqCounter;
|
|
17
|
+
private pool;
|
|
18
|
+
private poolSize;
|
|
17
19
|
constructor(initialCapacity?: number);
|
|
20
|
+
private allocEntry;
|
|
21
|
+
private freeEntry;
|
|
18
22
|
get length(): number;
|
|
19
23
|
isEmpty(): boolean;
|
|
20
24
|
clear(): void;
|
|
@@ -39,13 +39,3 @@ export interface PresolveResult {
|
|
|
39
39
|
* 6. Coefficient tightening
|
|
40
40
|
*/
|
|
41
41
|
export declare function presolve(model: Model): PresolveResult;
|
|
42
|
-
/**
|
|
43
|
-
* Detect problem structure for specialized handling.
|
|
44
|
-
*/
|
|
45
|
-
export interface ProblemStructure {
|
|
46
|
-
type: "general" | "set-covering" | "set-partitioning" | "assignment" | "knapsack";
|
|
47
|
-
hasAllBinaryVars: boolean;
|
|
48
|
-
hasEqualityConstraints: boolean;
|
|
49
|
-
avgConstraintDensity: number;
|
|
50
|
-
}
|
|
51
|
-
export declare function detectProblemStructure(model: Model): ProblemStructure;
|
|
@@ -11,6 +11,22 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import type Tableau from "./tableau";
|
|
13
13
|
export declare function simplex(this: Tableau): Tableau;
|
|
14
|
+
/**
|
|
15
|
+
* Dual simplex algorithm for warm-starting after adding constraints.
|
|
16
|
+
*
|
|
17
|
+
* Use when: The current solution is dual feasible (reduced costs valid) but
|
|
18
|
+
* may be primal infeasible (some RHS values negative). This is common after
|
|
19
|
+
* adding bound constraints in branch-and-cut.
|
|
20
|
+
*
|
|
21
|
+
* Algorithm:
|
|
22
|
+
* 1. Find a basic variable with negative value (leaving variable)
|
|
23
|
+
* 2. Find entering variable using dual ratio test
|
|
24
|
+
* 3. Pivot to restore primal feasibility
|
|
25
|
+
* 4. Repeat until all basic variables are non-negative
|
|
26
|
+
*
|
|
27
|
+
* @returns Number of iterations, or -1 if dual infeasible
|
|
28
|
+
*/
|
|
29
|
+
export declare function dualSimplex(this: Tableau): number;
|
|
14
30
|
export declare function phase1(this: Tableau): number;
|
|
15
31
|
export declare function phase2(this: Tableau): number;
|
|
16
32
|
export declare function pivot(this: Tableau, pivotRowIndex: number, pivotColumnIndex: number): void;
|
|
@@ -39,6 +39,12 @@ export default class Tableau {
|
|
|
39
39
|
simplex(): this;
|
|
40
40
|
phase1(): number;
|
|
41
41
|
phase2(): number;
|
|
42
|
+
/**
|
|
43
|
+
* Dual simplex for warm-starting after adding bound constraints.
|
|
44
|
+
* Use when solution is dual feasible but may be primal infeasible.
|
|
45
|
+
* @returns Number of iterations, or -1 if dual infeasible
|
|
46
|
+
*/
|
|
47
|
+
dualSimplex(): number;
|
|
42
48
|
pivot(pivotRowIndex: number, pivotColumnIndex: number): void;
|
|
43
49
|
checkForCycles(varIndexes: Array<[number, number]>): number[];
|
|
44
50
|
countIntegerValues(): number;
|
|
@@ -5,12 +5,9 @@
|
|
|
5
5
|
* Defines types used within the tableau implementation:
|
|
6
6
|
* - BranchCut: Bound constraint for MIP branching
|
|
7
7
|
* - Branch: Node in the branch-and-bound tree
|
|
8
|
-
* - SavedState: Tableau snapshot for backtracking
|
|
9
8
|
* - OptionalObjective: Secondary objective for hierarchical optimization
|
|
10
9
|
*/
|
|
11
10
|
import type { Solution, MilpSolution } from "./solution";
|
|
12
|
-
import type { Variable } from "../expressions";
|
|
13
|
-
import type Model from "../model";
|
|
14
11
|
export type BoundType = "min" | "max";
|
|
15
12
|
export interface BranchCut {
|
|
16
13
|
type: BoundType;
|
|
@@ -20,6 +17,10 @@ export interface BranchCut {
|
|
|
20
17
|
export interface Branch {
|
|
21
18
|
relaxedEvaluation: number;
|
|
22
19
|
cuts: BranchCut[];
|
|
20
|
+
branchVarIndex?: number;
|
|
21
|
+
branchDirection?: "up" | "down";
|
|
22
|
+
branchFractionality?: number;
|
|
23
|
+
parentEvaluation?: number;
|
|
23
24
|
}
|
|
24
25
|
export interface OptionalObjective {
|
|
25
26
|
priority: number;
|
|
@@ -30,24 +31,6 @@ export interface VariableValue {
|
|
|
30
31
|
index: number | null;
|
|
31
32
|
value: number | null;
|
|
32
33
|
}
|
|
33
|
-
export interface SavedState {
|
|
34
|
-
width: number;
|
|
35
|
-
height: number;
|
|
36
|
-
nVars: number;
|
|
37
|
-
model: Model | null;
|
|
38
|
-
variables: Variable[];
|
|
39
|
-
variablesPerIndex: Array<Variable | undefined>;
|
|
40
|
-
unrestrictedVars: Record<number, boolean>;
|
|
41
|
-
lastElementIndex: number;
|
|
42
|
-
varIndexByRow: number[];
|
|
43
|
-
varIndexByCol: number[];
|
|
44
|
-
rowByVarIndex: number[];
|
|
45
|
-
colByVarIndex: number[];
|
|
46
|
-
availableIndexes: number[];
|
|
47
|
-
optionalObjectives: OptionalObjective[];
|
|
48
|
-
optionalObjectivePerPriority: Record<number, OptionalObjective>;
|
|
49
|
-
matrix: number[][];
|
|
50
|
-
}
|
|
51
34
|
export type TableauSolution = Solution | MilpSolution;
|
|
52
35
|
export interface TableauSolutionSet {
|
|
53
36
|
[variable: string]: number | undefined;
|
|
@@ -34,8 +34,8 @@ export interface GeneratedProblem {
|
|
|
34
34
|
equal?: number;
|
|
35
35
|
}>;
|
|
36
36
|
variables: Record<string, Record<string, number>>;
|
|
37
|
-
ints?: Record<string,
|
|
38
|
-
binaries?: Record<string,
|
|
37
|
+
ints?: Record<string, 1>;
|
|
38
|
+
binaries?: Record<string, 1>;
|
|
39
39
|
}
|
|
40
40
|
/**
|
|
41
41
|
* Generate a random LP problem (continuous variables only)
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "javascript-lp-solver",
|
|
3
3
|
"description": "Easy to use, JSON oriented Linear Programming and Mixed Int. Programming Solver",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.3",
|
|
5
5
|
"private": false,
|
|
6
6
|
"authors": [
|
|
7
7
|
"Justin W. Wolcott <justin.w.wolcott@gmail.com>"
|
|
@@ -42,9 +42,12 @@
|
|
|
42
42
|
"@typescript-eslint/eslint-plugin": "8.2.0",
|
|
43
43
|
"@typescript-eslint/parser": "8.2.0",
|
|
44
44
|
"@vitest/coverage-v8": "^4.0.16",
|
|
45
|
+
"dependency-cruiser": "^17.3.7",
|
|
45
46
|
"eslint": "9.6.0",
|
|
46
47
|
"eslint-config-prettier": "9.1.0",
|
|
47
48
|
"eslint-plugin-unicorn": "55.0.0",
|
|
49
|
+
"knip": "^5.82.1",
|
|
50
|
+
"lefthook": "^2.0.14",
|
|
48
51
|
"mocha": "10.7.3",
|
|
49
52
|
"prettier": "3.4.2",
|
|
50
53
|
"rollup": "4.22.4",
|
|
@@ -55,6 +58,7 @@
|
|
|
55
58
|
"vitest": "^4.0.16"
|
|
56
59
|
},
|
|
57
60
|
"scripts": {
|
|
61
|
+
"prepare": "lefthook install",
|
|
58
62
|
"build": "tsc -p tsconfig.build.json --declaration --emitDeclarationOnly --outDir dist/types && rollup -c",
|
|
59
63
|
"lint": "ESLINT_USE_FLAT_CONFIG=false eslint .",
|
|
60
64
|
"lint:fix": "ESLINT_USE_FLAT_CONFIG=false eslint . --fix",
|
|
@@ -63,6 +67,10 @@
|
|
|
63
67
|
"typecheck": "tsc --noEmit",
|
|
64
68
|
"docs": "typedoc",
|
|
65
69
|
"prepublishOnly": "npm run build",
|
|
70
|
+
"knip": "knip",
|
|
71
|
+
"deps": "depcruise src --config .dependency-cruiser.cjs",
|
|
72
|
+
"deps:graph": "depcruise src --config .dependency-cruiser.cjs --output-type dot | dot -T svg > dependency-graph.svg",
|
|
73
|
+
"quality": "npm run lint && npm run knip && npm run deps && npm run test:coverage",
|
|
66
74
|
"test": "vitest run",
|
|
67
75
|
"test:unit": "vitest run",
|
|
68
76
|
"test:watch": "vitest",
|