javascript-lp-solver 1.0.1 → 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 +5 -5
- package/dist/index.browser.mjs +255 -694
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.cjs +255 -694
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +32 -33
- package/dist/index.mjs +255 -694
- package/dist/index.mjs.map +1 -1
- package/dist/solver.global.js +255 -694
- 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/mip-utils.d.ts +0 -36
- package/dist/types/tableau/presolve.d.ts +0 -10
- package/dist/types/tableau/solution.d.ts +0 -1
- package/dist/types/tableau/types.d.ts +0 -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 };
|
|
@@ -11,42 +11,6 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import type Tableau from "./tableau";
|
|
13
13
|
import type { VariableValue } from "./types";
|
|
14
|
-
/**
|
|
15
|
-
* Pseudo-cost tracker for intelligent variable selection in branch-and-bound.
|
|
16
|
-
*
|
|
17
|
-
* Tracks the historical change in objective function when branching on each
|
|
18
|
-
* integer variable. Uses this history to predict which variable will have
|
|
19
|
-
* the most impact on the objective, reducing the size of the B&B tree.
|
|
20
|
-
*
|
|
21
|
-
* Based on: "Branching rules revisited" by Achterberg, Koch, Martin (2005)
|
|
22
|
-
*/
|
|
23
|
-
export interface PseudoCosts {
|
|
24
|
-
down: Map<number, {
|
|
25
|
-
sum: number;
|
|
26
|
-
count: number;
|
|
27
|
-
}>;
|
|
28
|
-
up: Map<number, {
|
|
29
|
-
sum: number;
|
|
30
|
-
count: number;
|
|
31
|
-
}>;
|
|
32
|
-
defaultCost: number;
|
|
33
|
-
}
|
|
34
|
-
export declare function createPseudoCosts(): PseudoCosts;
|
|
35
|
-
/**
|
|
36
|
-
* Update pseudo-costs after a branching decision.
|
|
37
|
-
* Call this after solving a child node to record the objective change.
|
|
38
|
-
*/
|
|
39
|
-
export declare function updatePseudoCost(pc: PseudoCosts, varIndex: number, direction: "up" | "down", fractionality: number, objectiveChange: number): void;
|
|
40
|
-
/**
|
|
41
|
-
* Get the pseudo-cost for a variable in a given direction.
|
|
42
|
-
*/
|
|
43
|
-
export declare function getPseudoCost(pc: PseudoCosts, varIndex: number, direction: "up" | "down"): number;
|
|
44
|
-
/**
|
|
45
|
-
* Select branching variable using pseudo-cost branching.
|
|
46
|
-
* Uses the product scoring rule: score = f_down * pc_down * f_up * pc_up
|
|
47
|
-
* This balances the improvement from both branches.
|
|
48
|
-
*/
|
|
49
|
-
export declare function getPseudoCostBranchingVar(tableau: Tableau, pc: PseudoCosts): VariableValue;
|
|
50
14
|
/**
|
|
51
15
|
* Count how many integer variables currently have integral values.
|
|
52
16
|
*/
|
|
@@ -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;
|
|
@@ -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;
|
|
@@ -34,24 +31,6 @@ export interface VariableValue {
|
|
|
34
31
|
index: number | null;
|
|
35
32
|
value: number | null;
|
|
36
33
|
}
|
|
37
|
-
export interface SavedState {
|
|
38
|
-
width: number;
|
|
39
|
-
height: number;
|
|
40
|
-
nVars: number;
|
|
41
|
-
model: Model | null;
|
|
42
|
-
variables: Variable[];
|
|
43
|
-
variablesPerIndex: Array<Variable | undefined>;
|
|
44
|
-
unrestrictedVars: Record<number, boolean>;
|
|
45
|
-
lastElementIndex: number;
|
|
46
|
-
varIndexByRow: number[];
|
|
47
|
-
varIndexByCol: number[];
|
|
48
|
-
rowByVarIndex: number[];
|
|
49
|
-
colByVarIndex: number[];
|
|
50
|
-
availableIndexes: number[];
|
|
51
|
-
optionalObjectives: OptionalObjective[];
|
|
52
|
-
optionalObjectivePerPriority: Record<number, OptionalObjective>;
|
|
53
|
-
matrix: number[][];
|
|
54
|
-
}
|
|
55
34
|
export type TableauSolution = Solution | MilpSolution;
|
|
56
35
|
export interface TableauSolutionSet {
|
|
57
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",
|