@stevenvo780/st-lang 4.5.0 → 4.5.2
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 +78 -37
- package/dist/bdd/index.d.ts +4 -0
- package/dist/bdd/index.d.ts.map +1 -0
- package/dist/bdd/index.js +29 -0
- package/dist/bdd/index.js.map +1 -0
- package/dist/bdd/manager.d.ts +122 -0
- package/dist/bdd/manager.d.ts.map +1 -0
- package/dist/bdd/manager.js +524 -0
- package/dist/bdd/manager.js.map +1 -0
- package/dist/bdd/types.d.ts +20 -0
- package/dist/bdd/types.d.ts.map +1 -0
- package/dist/bdd/types.js +28 -0
- package/dist/bdd/types.js.map +1 -0
- package/dist/game-theory/common-games.d.ts +50 -0
- package/dist/game-theory/common-games.d.ts.map +1 -0
- package/dist/game-theory/common-games.js +112 -0
- package/dist/game-theory/common-games.js.map +1 -0
- package/dist/game-theory/dominance.d.ts +26 -0
- package/dist/game-theory/dominance.d.ts.map +1 -0
- package/dist/game-theory/dominance.js +203 -0
- package/dist/game-theory/dominance.js.map +1 -0
- package/dist/game-theory/index.d.ts +8 -0
- package/dist/game-theory/index.d.ts.map +1 -0
- package/dist/game-theory/index.js +47 -0
- package/dist/game-theory/index.js.map +1 -0
- package/dist/game-theory/lemke-howson.d.ts +3 -0
- package/dist/game-theory/lemke-howson.d.ts.map +1 -0
- package/dist/game-theory/lemke-howson.js +269 -0
- package/dist/game-theory/lemke-howson.js.map +1 -0
- package/dist/game-theory/linalg.d.ts +7 -0
- package/dist/game-theory/linalg.d.ts.map +1 -0
- package/dist/game-theory/linalg.js +69 -0
- package/dist/game-theory/linalg.js.map +1 -0
- package/dist/game-theory/pure-nash.d.ts +3 -0
- package/dist/game-theory/pure-nash.d.ts.map +1 -0
- package/dist/game-theory/pure-nash.js +86 -0
- package/dist/game-theory/pure-nash.js.map +1 -0
- package/dist/game-theory/support-enumeration.d.ts +3 -0
- package/dist/game-theory/support-enumeration.d.ts.map +1 -0
- package/dist/game-theory/support-enumeration.js +214 -0
- package/dist/game-theory/support-enumeration.js.map +1 -0
- package/dist/game-theory/types.d.ts +57 -0
- package/dist/game-theory/types.d.ts.map +1 -0
- package/dist/game-theory/types.js +191 -0
- package/dist/game-theory/types.js.map +1 -0
- package/dist/index.d.ts +19 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +75 -1
- package/dist/index.js.map +1 -1
- package/dist/information-theory/index.d.ts +29 -0
- package/dist/information-theory/index.d.ts.map +1 -0
- package/dist/information-theory/index.js +323 -0
- package/dist/information-theory/index.js.map +1 -0
- package/dist/namespaces/logic.d.ts +42 -0
- package/dist/namespaces/logic.d.ts.map +1 -0
- package/dist/namespaces/logic.js +112 -0
- package/dist/namespaces/logic.js.map +1 -0
- package/dist/namespaces/proof-systems.d.ts +18 -0
- package/dist/namespaces/proof-systems.d.ts.map +1 -0
- package/dist/namespaces/proof-systems.js +59 -0
- package/dist/namespaces/proof-systems.js.map +1 -0
- package/dist/namespaces/reasoning.d.ts +26 -0
- package/dist/namespaces/reasoning.d.ts.map +1 -0
- package/dist/namespaces/reasoning.js +72 -0
- package/dist/namespaces/reasoning.js.map +1 -0
- package/dist/namespaces/semantics.d.ts +21 -0
- package/dist/namespaces/semantics.d.ts.map +1 -0
- package/dist/namespaces/semantics.js +64 -0
- package/dist/namespaces/semantics.js.map +1 -0
- package/dist/namespaces/solvers.d.ts +22 -0
- package/dist/namespaces/solvers.d.ts.map +1 -0
- package/dist/namespaces/solvers.js +66 -0
- package/dist/namespaces/solvers.js.map +1 -0
- package/dist/namespaces/type-theory.d.ts +22 -0
- package/dist/namespaces/type-theory.d.ts.map +1 -0
- package/dist/namespaces/type-theory.js +65 -0
- package/dist/namespaces/type-theory.js.map +1 -0
- package/dist/optimization/branch-and-bound.d.ts +11 -0
- package/dist/optimization/branch-and-bound.d.ts.map +1 -0
- package/dist/optimization/branch-and-bound.js +311 -0
- package/dist/optimization/branch-and-bound.js.map +1 -0
- package/dist/optimization/index.d.ts +5 -0
- package/dist/optimization/index.d.ts.map +1 -0
- package/dist/optimization/index.js +20 -0
- package/dist/optimization/index.js.map +1 -0
- package/dist/optimization/simplex.d.ts +8 -0
- package/dist/optimization/simplex.d.ts.map +1 -0
- package/dist/optimization/simplex.js +408 -0
- package/dist/optimization/simplex.js.map +1 -0
- package/dist/optimization/standard-form.d.ts +11 -0
- package/dist/optimization/standard-form.d.ts.map +1 -0
- package/dist/optimization/standard-form.js +112 -0
- package/dist/optimization/standard-form.js.map +1 -0
- package/dist/optimization/types.d.ts +44 -0
- package/dist/optimization/types.d.ts.map +1 -0
- package/dist/optimization/types.js +15 -0
- package/dist/optimization/types.js.map +1 -0
- package/dist/profiles/hol/connectives.d.ts +46 -0
- package/dist/profiles/hol/connectives.d.ts.map +1 -0
- package/dist/profiles/hol/connectives.js +104 -0
- package/dist/profiles/hol/connectives.js.map +1 -0
- package/dist/profiles/hol/index.d.ts +7 -0
- package/dist/profiles/hol/index.d.ts.map +1 -0
- package/dist/profiles/hol/index.js +77 -0
- package/dist/profiles/hol/index.js.map +1 -0
- package/dist/profiles/hol/rules.d.ts +31 -0
- package/dist/profiles/hol/rules.d.ts.map +1 -0
- package/dist/profiles/hol/rules.js +258 -0
- package/dist/profiles/hol/rules.js.map +1 -0
- package/dist/profiles/hol/term.d.ts +52 -0
- package/dist/profiles/hol/term.d.ts.map +1 -0
- package/dist/profiles/hol/term.js +345 -0
- package/dist/profiles/hol/term.js.map +1 -0
- package/dist/profiles/hol/type-system.d.ts +38 -0
- package/dist/profiles/hol/type-system.d.ts.map +1 -0
- package/dist/profiles/hol/type-system.js +133 -0
- package/dist/profiles/hol/type-system.js.map +1 -0
- package/dist/profiles/hol/types.d.ts +59 -0
- package/dist/profiles/hol/types.d.ts.map +1 -0
- package/dist/profiles/hol/types.js +26 -0
- package/dist/profiles/hol/types.js.map +1 -0
- package/dist/smt-lib/ast.d.ts +138 -0
- package/dist/smt-lib/ast.d.ts.map +1 -0
- package/dist/smt-lib/ast.js +73 -0
- package/dist/smt-lib/ast.js.map +1 -0
- package/dist/smt-lib/emitter.d.ts +12 -0
- package/dist/smt-lib/emitter.d.ts.map +1 -0
- package/dist/smt-lib/emitter.js +174 -0
- package/dist/smt-lib/emitter.js.map +1 -0
- package/dist/smt-lib/index.d.ts +6 -0
- package/dist/smt-lib/index.d.ts.map +1 -0
- package/dist/smt-lib/index.js +31 -0
- package/dist/smt-lib/index.js.map +1 -0
- package/dist/smt-lib/parser.d.ts +13 -0
- package/dist/smt-lib/parser.d.ts.map +1 -0
- package/dist/smt-lib/parser.js +614 -0
- package/dist/smt-lib/parser.js.map +1 -0
- package/dist/smt-lib/tokenizer.d.ts +16 -0
- package/dist/smt-lib/tokenizer.d.ts.map +1 -0
- package/dist/smt-lib/tokenizer.js +234 -0
- package/dist/smt-lib/tokenizer.js.map +1 -0
- package/dist/tests/api/namespaces.test.d.ts +9 -0
- package/dist/tests/api/namespaces.test.d.ts.map +1 -0
- package/dist/tests/api/namespaces.test.js +218 -0
- package/dist/tests/api/namespaces.test.js.map +1 -0
- package/dist/tests/bdd/manager.test.d.ts +2 -0
- package/dist/tests/bdd/manager.test.d.ts.map +1 -0
- package/dist/tests/bdd/manager.test.js +472 -0
- package/dist/tests/bdd/manager.test.js.map +1 -0
- package/dist/tests/game-theory/game-theory.test.d.ts +2 -0
- package/dist/tests/game-theory/game-theory.test.d.ts.map +1 -0
- package/dist/tests/game-theory/game-theory.test.js +252 -0
- package/dist/tests/game-theory/game-theory.test.js.map +1 -0
- package/dist/tests/hol/hol.test.d.ts +2 -0
- package/dist/tests/hol/hol.test.d.ts.map +1 -0
- package/dist/tests/hol/hol.test.js +340 -0
- package/dist/tests/hol/hol.test.js.map +1 -0
- package/dist/tests/information-theory/information-theory.test.d.ts +2 -0
- package/dist/tests/information-theory/information-theory.test.d.ts.map +1 -0
- package/dist/tests/information-theory/information-theory.test.js +291 -0
- package/dist/tests/information-theory/information-theory.test.js.map +1 -0
- package/dist/tests/optimization/ilp.test.d.ts +2 -0
- package/dist/tests/optimization/ilp.test.d.ts.map +1 -0
- package/dist/tests/optimization/ilp.test.js +204 -0
- package/dist/tests/optimization/ilp.test.js.map +1 -0
- package/dist/tests/optimization/lp.test.d.ts +2 -0
- package/dist/tests/optimization/lp.test.d.ts.map +1 -0
- package/dist/tests/optimization/lp.test.js +224 -0
- package/dist/tests/optimization/lp.test.js.map +1 -0
- package/dist/tests/properties/agm.property.test.d.ts +2 -0
- package/dist/tests/properties/agm.property.test.d.ts.map +1 -0
- package/dist/tests/properties/agm.property.test.js +75 -0
- package/dist/tests/properties/agm.property.test.js.map +1 -0
- package/dist/tests/properties/anti-unification.property.test.d.ts +2 -0
- package/dist/tests/properties/anti-unification.property.test.d.ts.map +1 -0
- package/dist/tests/properties/anti-unification.property.test.js +43 -0
- package/dist/tests/properties/anti-unification.property.test.js.map +1 -0
- package/dist/tests/properties/argumentation.property.test.d.ts +2 -0
- package/dist/tests/properties/argumentation.property.test.d.ts.map +1 -0
- package/dist/tests/properties/argumentation.property.test.js +51 -0
- package/dist/tests/properties/argumentation.property.test.js.map +1 -0
- package/dist/tests/properties/bayesian.property.test.d.ts +2 -0
- package/dist/tests/properties/bayesian.property.test.d.ts.map +1 -0
- package/dist/tests/properties/bayesian.property.test.js +32 -0
- package/dist/tests/properties/bayesian.property.test.js.map +1 -0
- package/dist/tests/properties/bisimulation.property.test.d.ts +2 -0
- package/dist/tests/properties/bisimulation.property.test.d.ts.map +1 -0
- package/dist/tests/properties/bisimulation.property.test.js +50 -0
- package/dist/tests/properties/bisimulation.property.test.js.map +1 -0
- package/dist/tests/properties/cdcl.property.test.d.ts +2 -0
- package/dist/tests/properties/cdcl.property.test.d.ts.map +1 -0
- package/dist/tests/properties/cdcl.property.test.js +70 -0
- package/dist/tests/properties/cdcl.property.test.js.map +1 -0
- package/dist/tests/properties/coinduction.property.test.d.ts +2 -0
- package/dist/tests/properties/coinduction.property.test.d.ts.map +1 -0
- package/dist/tests/properties/coinduction.property.test.js +34 -0
- package/dist/tests/properties/coinduction.property.test.js.map +1 -0
- package/dist/tests/properties/constructive-reals.property.test.d.ts +2 -0
- package/dist/tests/properties/constructive-reals.property.test.d.ts.map +1 -0
- package/dist/tests/properties/constructive-reals.property.test.js +59 -0
- package/dist/tests/properties/constructive-reals.property.test.js.map +1 -0
- package/dist/tests/properties/csp.property.test.d.ts +2 -0
- package/dist/tests/properties/csp.property.test.d.ts.map +1 -0
- package/dist/tests/properties/csp.property.test.js +58 -0
- package/dist/tests/properties/csp.property.test.js.map +1 -0
- package/dist/tests/properties/generators.d.ts +78 -0
- package/dist/tests/properties/generators.d.ts.map +1 -0
- package/dist/tests/properties/generators.js +348 -0
- package/dist/tests/properties/generators.js.map +1 -0
- package/dist/tests/properties/ho-unify.property.test.d.ts +2 -0
- package/dist/tests/properties/ho-unify.property.test.d.ts.map +1 -0
- package/dist/tests/properties/ho-unify.property.test.js +46 -0
- package/dist/tests/properties/ho-unify.property.test.js.map +1 -0
- package/dist/tests/properties/hyperreal.property.test.d.ts +2 -0
- package/dist/tests/properties/hyperreal.property.test.d.ts.map +1 -0
- package/dist/tests/properties/hyperreal.property.test.js +33 -0
- package/dist/tests/properties/hyperreal.property.test.js.map +1 -0
- package/dist/tests/properties/intuit-nj.property.test.d.ts +2 -0
- package/dist/tests/properties/intuit-nj.property.test.d.ts.map +1 -0
- package/dist/tests/properties/intuit-nj.property.test.js +57 -0
- package/dist/tests/properties/intuit-nj.property.test.js.map +1 -0
- package/dist/tests/properties/lambda-calc.property.test.d.ts +2 -0
- package/dist/tests/properties/lambda-calc.property.test.d.ts.map +1 -0
- package/dist/tests/properties/lambda-calc.property.test.js +35 -0
- package/dist/tests/properties/lambda-calc.property.test.js.map +1 -0
- package/dist/tests/properties/mln.property.test.d.ts +2 -0
- package/dist/tests/properties/mln.property.test.d.ts.map +1 -0
- package/dist/tests/properties/mln.property.test.js +41 -0
- package/dist/tests/properties/mln.property.test.js.map +1 -0
- package/dist/tests/properties/mltt.property.test.d.ts +2 -0
- package/dist/tests/properties/mltt.property.test.d.ts.map +1 -0
- package/dist/tests/properties/mltt.property.test.js +33 -0
- package/dist/tests/properties/mltt.property.test.js.map +1 -0
- package/dist/tests/properties/nbe.property.test.d.ts +2 -0
- package/dist/tests/properties/nbe.property.test.d.ts.map +1 -0
- package/dist/tests/properties/nbe.property.test.js +44 -0
- package/dist/tests/properties/nbe.property.test.js.map +1 -0
- package/dist/tests/properties/planning.property.test.d.ts +2 -0
- package/dist/tests/properties/planning.property.test.d.ts.map +1 -0
- package/dist/tests/properties/planning.property.test.js +51 -0
- package/dist/tests/properties/planning.property.test.js.map +1 -0
- package/dist/tests/properties/profile-bridge.property.test.d.ts +2 -0
- package/dist/tests/properties/profile-bridge.property.test.d.ts.map +1 -0
- package/dist/tests/properties/profile-bridge.property.test.js +71 -0
- package/dist/tests/properties/profile-bridge.property.test.js.map +1 -0
- package/dist/tests/properties/refinement-types.property.test.d.ts +2 -0
- package/dist/tests/properties/refinement-types.property.test.d.ts.map +1 -0
- package/dist/tests/properties/refinement-types.property.test.js +37 -0
- package/dist/tests/properties/refinement-types.property.test.js.map +1 -0
- package/dist/tests/properties/sequent-g3.property.test.d.ts +2 -0
- package/dist/tests/properties/sequent-g3.property.test.d.ts.map +1 -0
- package/dist/tests/properties/sequent-g3.property.test.js +34 -0
- package/dist/tests/properties/sequent-g3.property.test.js.map +1 -0
- package/dist/tests/properties/symbolic-diff.property.test.d.ts +2 -0
- package/dist/tests/properties/symbolic-diff.property.test.d.ts.map +1 -0
- package/dist/tests/properties/symbolic-diff.property.test.js +49 -0
- package/dist/tests/properties/symbolic-diff.property.test.js.map +1 -0
- package/dist/tests/properties/system-f.property.test.d.ts +2 -0
- package/dist/tests/properties/system-f.property.test.d.ts.map +1 -0
- package/dist/tests/properties/system-f.property.test.js +37 -0
- package/dist/tests/properties/system-f.property.test.js.map +1 -0
- package/dist/tests/properties/theorem-cache.property.test.d.ts +2 -0
- package/dist/tests/properties/theorem-cache.property.test.d.ts.map +1 -0
- package/dist/tests/properties/theorem-cache.property.test.js +38 -0
- package/dist/tests/properties/theorem-cache.property.test.js.map +1 -0
- package/dist/tests/properties/trs.property.test.d.ts +2 -0
- package/dist/tests/properties/trs.property.test.d.ts.map +1 -0
- package/dist/tests/properties/trs.property.test.js +34 -0
- package/dist/tests/properties/trs.property.test.js.map +1 -0
- package/dist/tests/properties/unification.property.test.d.ts +2 -0
- package/dist/tests/properties/unification.property.test.d.ts.map +1 -0
- package/dist/tests/properties/unification.property.test.js +42 -0
- package/dist/tests/properties/unification.property.test.js.map +1 -0
- package/dist/tests/smt-lib/emitter.test.d.ts +2 -0
- package/dist/tests/smt-lib/emitter.test.d.ts.map +1 -0
- package/dist/tests/smt-lib/emitter.test.js +155 -0
- package/dist/tests/smt-lib/emitter.test.js.map +1 -0
- package/dist/tests/smt-lib/parser.test.d.ts +2 -0
- package/dist/tests/smt-lib/parser.test.d.ts.map +1 -0
- package/dist/tests/smt-lib/parser.test.js +164 -0
- package/dist/tests/smt-lib/parser.test.js.map +1 -0
- package/dist/tests/smt-lib/tokenizer.test.d.ts +2 -0
- package/dist/tests/smt-lib/tokenizer.test.d.ts.map +1 -0
- package/dist/tests/smt-lib/tokenizer.test.js +59 -0
- package/dist/tests/smt-lib/tokenizer.test.js.map +1 -0
- package/package.json +3 -1
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================
|
|
3
|
+
// Branch-and-bound para Integer Linear Programming.
|
|
4
|
+
// ============================================================
|
|
5
|
+
// Estrategia clásica:
|
|
6
|
+
// 1. Resolver la relajación LP. Si infactible/unbounded, salir.
|
|
7
|
+
// 2. Si la solución LP es entera en `integerVars`, es óptima
|
|
8
|
+
// del ILP y devolvemos.
|
|
9
|
+
// 3. Elegir la variable entera más fraccional (closest-to-0.5).
|
|
10
|
+
// Generar dos subproblemas añadiendo x ≤ ⌊x*⌋ y x ≥ ⌈x*⌉ a
|
|
11
|
+
// las restricciones originales y descender (DFS con pila).
|
|
12
|
+
// 4. Mantener mejor incumbent (mejor entero encontrado). Podar
|
|
13
|
+
// cuando el bound de la relajación es peor que el incumbent
|
|
14
|
+
// (más una tolerancia).
|
|
15
|
+
//
|
|
16
|
+
// Para problemas binarios (variables 0/1) las cotas adicionales
|
|
17
|
+
// son innecesarias porque ya están restringidas por
|
|
18
|
+
// `variableBounds`; aún así, la lógica B&B funciona idéntica.
|
|
19
|
+
//
|
|
20
|
+
// Limitación conocida: no detecta optimalidad por GAP=0 sin
|
|
21
|
+
// explorar toda la rama; el `gap` reportado es relativo al
|
|
22
|
+
// bound del root LP.
|
|
23
|
+
// ============================================================
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.lpRelaxation = lpRelaxation;
|
|
26
|
+
exports.solveILP = solveILP;
|
|
27
|
+
const simplex_1 = require("./simplex");
|
|
28
|
+
const DEFAULT_MAX_NODES = 10000;
|
|
29
|
+
const DEFAULT_TIMEOUT_MS = 30000;
|
|
30
|
+
const INTEGER_TOL = 1e-6;
|
|
31
|
+
/**
|
|
32
|
+
* Genera el LP relajado: descarta integerVars/binaryVars pero
|
|
33
|
+
* mantiene `variableBounds` (los binarios ya tienen [0,1] ahí).
|
|
34
|
+
*/
|
|
35
|
+
function lpRelaxation(ilp) {
|
|
36
|
+
// Si hay binarios sin cotas explícitas, las inyectamos.
|
|
37
|
+
const bounds = ilp.variableBounds
|
|
38
|
+
? ilp.variableBounds.map((b) => ({ ...b }))
|
|
39
|
+
: new Array(ilp.objective.coefficients.length)
|
|
40
|
+
.fill({})
|
|
41
|
+
.map(() => ({}));
|
|
42
|
+
if (ilp.binaryVars) {
|
|
43
|
+
for (const idx of ilp.binaryVars) {
|
|
44
|
+
const existing = bounds[idx] ?? {};
|
|
45
|
+
bounds[idx] = {
|
|
46
|
+
lower: existing.lower ?? 0,
|
|
47
|
+
upper: existing.upper !== undefined ? Math.min(existing.upper, 1) : 1,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
objective: {
|
|
53
|
+
kind: ilp.objective.kind,
|
|
54
|
+
coefficients: ilp.objective.coefficients.slice(),
|
|
55
|
+
},
|
|
56
|
+
constraints: ilp.constraints.map((c) => ({
|
|
57
|
+
coefficients: c.coefficients.slice(),
|
|
58
|
+
operator: c.operator,
|
|
59
|
+
rhs: c.rhs,
|
|
60
|
+
})),
|
|
61
|
+
variableBounds: bounds,
|
|
62
|
+
variableNames: ilp.variableNames ? ilp.variableNames.slice() : undefined,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Comprueba qué variable de `integerVars` es la más fraccional en
|
|
67
|
+
* `x`. Devuelve `-1` si todas son enteras (dentro de la tolerancia).
|
|
68
|
+
*/
|
|
69
|
+
function pickBranchVariable(x, integerVars) {
|
|
70
|
+
let bestIdx = -1;
|
|
71
|
+
let bestFrac = -1;
|
|
72
|
+
for (const i of integerVars) {
|
|
73
|
+
const v = x[i] ?? 0;
|
|
74
|
+
const frac = Math.abs(v - Math.round(v));
|
|
75
|
+
if (frac > INTEGER_TOL && frac > bestFrac) {
|
|
76
|
+
bestFrac = frac;
|
|
77
|
+
bestIdx = i;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return bestIdx;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Construye un nuevo LP con una restricción adicional sobre la
|
|
84
|
+
* variable `idx`: si `direction='floor'`, x_idx ≤ value; si
|
|
85
|
+
* `direction='ceil'`, x_idx ≥ value.
|
|
86
|
+
*/
|
|
87
|
+
function branch(lp, idx, value, direction) {
|
|
88
|
+
const row = new Array(lp.objective.coefficients.length).fill(0);
|
|
89
|
+
row[idx] = 1;
|
|
90
|
+
return {
|
|
91
|
+
objective: {
|
|
92
|
+
kind: lp.objective.kind,
|
|
93
|
+
coefficients: lp.objective.coefficients.slice(),
|
|
94
|
+
},
|
|
95
|
+
constraints: [
|
|
96
|
+
...lp.constraints.map((c) => ({
|
|
97
|
+
coefficients: c.coefficients.slice(),
|
|
98
|
+
operator: c.operator,
|
|
99
|
+
rhs: c.rhs,
|
|
100
|
+
})),
|
|
101
|
+
{
|
|
102
|
+
coefficients: row,
|
|
103
|
+
operator: direction === 'floor' ? '<=' : '>=',
|
|
104
|
+
rhs: value,
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
variableBounds: lp.variableBounds ? lp.variableBounds.map((b) => ({ ...b })) : undefined,
|
|
108
|
+
variableNames: lp.variableNames ? lp.variableNames.slice() : undefined,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* ¿La solución LP es entera (en `integerVars`) y respeta los
|
|
113
|
+
* binarios (en {0,1})?
|
|
114
|
+
*/
|
|
115
|
+
function isIntegerSolution(x, integerVars) {
|
|
116
|
+
for (const i of integerVars) {
|
|
117
|
+
const v = x[i] ?? 0;
|
|
118
|
+
if (Math.abs(v - Math.round(v)) > INTEGER_TOL)
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Redondea las componentes enteras de `x` (ya verificadas como
|
|
125
|
+
* casi-enteras) para limpiar ruido numérico.
|
|
126
|
+
*/
|
|
127
|
+
function roundIntegers(x, integerVars) {
|
|
128
|
+
const out = x.slice();
|
|
129
|
+
for (const i of integerVars) {
|
|
130
|
+
const v = out[i];
|
|
131
|
+
if (v !== undefined)
|
|
132
|
+
out[i] = Math.round(v);
|
|
133
|
+
}
|
|
134
|
+
return out;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* ¿`a` es mejor que `b` según la dirección de optimización?
|
|
138
|
+
* Para 'maximize': a > b. Para 'minimize': a < b.
|
|
139
|
+
*/
|
|
140
|
+
function isBetter(a, b, kind) {
|
|
141
|
+
if (kind === 'maximize')
|
|
142
|
+
return a > b + INTEGER_TOL;
|
|
143
|
+
return a < b - INTEGER_TOL;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* El bound del nodo (valor LP relajado) ¿puede mejorar al
|
|
147
|
+
* incumbent? Si no, podamos.
|
|
148
|
+
*/
|
|
149
|
+
function canImprove(bound, incumbent, kind, hasIncumbent) {
|
|
150
|
+
if (!hasIncumbent)
|
|
151
|
+
return true;
|
|
152
|
+
if (kind === 'maximize')
|
|
153
|
+
return bound > incumbent + INTEGER_TOL;
|
|
154
|
+
return bound < incumbent - INTEGER_TOL;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Solver ILP principal. Estrategia DFS con pila explícita.
|
|
158
|
+
*/
|
|
159
|
+
function solveILP(problem, opts = {}) {
|
|
160
|
+
const maxNodes = opts.maxNodes ?? DEFAULT_MAX_NODES;
|
|
161
|
+
const timeoutMs = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
162
|
+
const lpOpts = opts.lpOptions ?? {};
|
|
163
|
+
const kind = problem.objective.kind;
|
|
164
|
+
const startTime = Date.now();
|
|
165
|
+
// integerVars unificado (incluye binarios)
|
|
166
|
+
const integerVarsSet = new Set(problem.integerVars);
|
|
167
|
+
if (problem.binaryVars) {
|
|
168
|
+
for (const b of problem.binaryVars)
|
|
169
|
+
integerVarsSet.add(b);
|
|
170
|
+
}
|
|
171
|
+
const integerVars = Array.from(integerVarsSet);
|
|
172
|
+
const rootLP = lpRelaxation(problem);
|
|
173
|
+
const rootSol = (0, simplex_1.solveLP)(rootLP, lpOpts);
|
|
174
|
+
if (rootSol.status === 'infeasible' || rootSol.status === 'unbounded') {
|
|
175
|
+
return {
|
|
176
|
+
...rootSol,
|
|
177
|
+
nodesExplored: 1,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
if (rootSol.status === 'iteration_limit') {
|
|
181
|
+
return {
|
|
182
|
+
...rootSol,
|
|
183
|
+
nodesExplored: 1,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
// Si la relajación ya es entera, listo
|
|
187
|
+
if (isIntegerSolution(rootSol.variables, integerVars)) {
|
|
188
|
+
return {
|
|
189
|
+
...rootSol,
|
|
190
|
+
variables: roundIntegers(rootSol.variables, integerVars),
|
|
191
|
+
nodesExplored: 1,
|
|
192
|
+
gap: 0,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
let bestValue = kind === 'maximize' ? -Infinity : Infinity;
|
|
196
|
+
let bestVars = null;
|
|
197
|
+
let nodesExplored = 1;
|
|
198
|
+
const rootBound = rootSol.objectiveValue;
|
|
199
|
+
// Stack para DFS. Cada nodo lleva su LP y el bound padre para
|
|
200
|
+
// pruning agresivo (la LP de los hijos no puede mejorar al padre).
|
|
201
|
+
const stack = [{ lp: rootLP, parentBound: rootBound }];
|
|
202
|
+
while (stack.length > 0) {
|
|
203
|
+
if (Date.now() - startTime > timeoutMs) {
|
|
204
|
+
// Timeout: devolvemos el incumbent (si existe) como mejor esfuerzo
|
|
205
|
+
if (bestVars) {
|
|
206
|
+
return {
|
|
207
|
+
status: 'iteration_limit',
|
|
208
|
+
variables: bestVars,
|
|
209
|
+
objectiveValue: bestValue,
|
|
210
|
+
iterations: 0,
|
|
211
|
+
nodesExplored,
|
|
212
|
+
gap: Math.abs(rootBound - bestValue),
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
return {
|
|
216
|
+
status: 'iteration_limit',
|
|
217
|
+
variables: rootSol.variables,
|
|
218
|
+
objectiveValue: NaN,
|
|
219
|
+
iterations: rootSol.iterations,
|
|
220
|
+
nodesExplored,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
if (nodesExplored >= maxNodes) {
|
|
224
|
+
if (bestVars) {
|
|
225
|
+
return {
|
|
226
|
+
status: 'iteration_limit',
|
|
227
|
+
variables: bestVars,
|
|
228
|
+
objectiveValue: bestValue,
|
|
229
|
+
iterations: 0,
|
|
230
|
+
nodesExplored,
|
|
231
|
+
gap: Math.abs(rootBound - bestValue),
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
return {
|
|
235
|
+
status: 'iteration_limit',
|
|
236
|
+
variables: rootSol.variables,
|
|
237
|
+
objectiveValue: NaN,
|
|
238
|
+
iterations: rootSol.iterations,
|
|
239
|
+
nodesExplored,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
const node = stack.pop();
|
|
243
|
+
if (!node)
|
|
244
|
+
break;
|
|
245
|
+
// Pruning preliminar contra el bound del padre
|
|
246
|
+
if (!canImprove(node.parentBound, bestValue, kind, bestVars !== null)) {
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
const sol = (0, simplex_1.solveLP)(node.lp, lpOpts);
|
|
250
|
+
nodesExplored++;
|
|
251
|
+
if (sol.status === 'infeasible' || sol.status === 'unbounded')
|
|
252
|
+
continue;
|
|
253
|
+
if (sol.status === 'iteration_limit')
|
|
254
|
+
continue;
|
|
255
|
+
// Pruning por bound: si el LP relajado de este nodo no mejora al
|
|
256
|
+
// incumbent, podamos.
|
|
257
|
+
if (!canImprove(sol.objectiveValue, bestValue, kind, bestVars !== null)) {
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
if (isIntegerSolution(sol.variables, integerVars)) {
|
|
261
|
+
// Candidato entero. Actualizar incumbent si mejora.
|
|
262
|
+
if (bestVars === null || isBetter(sol.objectiveValue, bestValue, kind)) {
|
|
263
|
+
bestValue = sol.objectiveValue;
|
|
264
|
+
bestVars = roundIntegers(sol.variables, integerVars);
|
|
265
|
+
}
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
// Branch
|
|
269
|
+
const branchIdx = pickBranchVariable(sol.variables, integerVars);
|
|
270
|
+
if (branchIdx === -1)
|
|
271
|
+
continue; // todas enteras: ya manejado arriba
|
|
272
|
+
const value = sol.variables[branchIdx] ?? 0;
|
|
273
|
+
const floor = Math.floor(value);
|
|
274
|
+
const ceil = Math.ceil(value);
|
|
275
|
+
// DFS: empujamos primero el de menor prioridad. Para max,
|
|
276
|
+
// exploramos primero la rama ceil (suele tener mejor bound).
|
|
277
|
+
if (kind === 'maximize') {
|
|
278
|
+
stack.push({
|
|
279
|
+
lp: branch(node.lp, branchIdx, floor, 'floor'),
|
|
280
|
+
parentBound: sol.objectiveValue,
|
|
281
|
+
});
|
|
282
|
+
stack.push({ lp: branch(node.lp, branchIdx, ceil, 'ceil'), parentBound: sol.objectiveValue });
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
stack.push({ lp: branch(node.lp, branchIdx, ceil, 'ceil'), parentBound: sol.objectiveValue });
|
|
286
|
+
stack.push({
|
|
287
|
+
lp: branch(node.lp, branchIdx, floor, 'floor'),
|
|
288
|
+
parentBound: sol.objectiveValue,
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
if (bestVars === null) {
|
|
293
|
+
// No se encontró ningún entero factible
|
|
294
|
+
return {
|
|
295
|
+
status: 'infeasible',
|
|
296
|
+
variables: new Array(problem.objective.coefficients.length).fill(0),
|
|
297
|
+
objectiveValue: NaN,
|
|
298
|
+
iterations: rootSol.iterations,
|
|
299
|
+
nodesExplored,
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
return {
|
|
303
|
+
status: 'optimal',
|
|
304
|
+
variables: bestVars,
|
|
305
|
+
objectiveValue: bestValue,
|
|
306
|
+
iterations: rootSol.iterations,
|
|
307
|
+
nodesExplored,
|
|
308
|
+
gap: Math.abs(rootBound - bestValue),
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
//# sourceMappingURL=branch-and-bound.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"branch-and-bound.js","sourceRoot":"","sources":["../../src/optimization/branch-and-bound.ts"],"names":[],"mappings":";AAAA,+DAA+D;AAC/D,oDAAoD;AACpD,+DAA+D;AAC/D,sBAAsB;AACtB,kEAAkE;AAClE,+DAA+D;AAC/D,6BAA6B;AAC7B,kEAAkE;AAClE,gEAAgE;AAChE,gEAAgE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IACJ,CAAC;IAED,OAAO;QACL,MAAM,EAAE,SAAS;QACjB,SAAS,EAAE,QAAQ;QACnB,cAAc,EAAE,SAAS;QACzB,UAAU,EAAE,OAAO,CAAC,UAAU;QAC9B,aAAa;QACb,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,SAAS,GAAG,SAAS,CAAC;KACrC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { LPProblem, LPSolution, LPStatus, LPConstraint, LPOptions, ILPProblem, ILPSolution, ILPOptions, ObjectiveKind, ConstraintOperator, } from './types';
|
|
2
|
+
export { solveLP } from './simplex';
|
|
3
|
+
export { solveILP, lpRelaxation } from './branch-and-bound';
|
|
4
|
+
export { standardForm } from './standard-form';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/optimization/index.ts"],"names":[],"mappings":"AAUA,YAAY,EACV,SAAS,EACT,UAAU,EACV,QAAQ,EACR,YAAY,EACZ,SAAS,EACT,UAAU,EACV,WAAW,EACX,UAAU,EACV,aAAa,EACb,kBAAkB,GACnB,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================
|
|
3
|
+
// ST Optimization — barrel público.
|
|
4
|
+
// ============================================================
|
|
5
|
+
// API:
|
|
6
|
+
// solveLP(problem, opts?) → LPSolution simplex de dos fases
|
|
7
|
+
// solveILP(problem, opts?) → ILPSolution branch-and-bound
|
|
8
|
+
// lpRelaxation(ilp) → LPProblem relajación continua
|
|
9
|
+
// standardForm(lp) → LPProblem forma estándar
|
|
10
|
+
// ============================================================
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.standardForm = exports.lpRelaxation = exports.solveILP = exports.solveLP = void 0;
|
|
13
|
+
var simplex_1 = require("./simplex");
|
|
14
|
+
Object.defineProperty(exports, "solveLP", { enumerable: true, get: function () { return simplex_1.solveLP; } });
|
|
15
|
+
var branch_and_bound_1 = require("./branch-and-bound");
|
|
16
|
+
Object.defineProperty(exports, "solveILP", { enumerable: true, get: function () { return branch_and_bound_1.solveILP; } });
|
|
17
|
+
Object.defineProperty(exports, "lpRelaxation", { enumerable: true, get: function () { return branch_and_bound_1.lpRelaxation; } });
|
|
18
|
+
var standard_form_1 = require("./standard-form");
|
|
19
|
+
Object.defineProperty(exports, "standardForm", { enumerable: true, get: function () { return standard_form_1.standardForm; } });
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/optimization/index.ts"],"names":[],"mappings":";AAAA,+DAA+D;AAC/D,oCAAoC;AACpC,+DAA+D;AAC/D,OAAO;AACP,oEAAoE;AACpE,gEAAgE;AAChE,mEAAmE;AACnE,8DAA8D;AAC9D,+DAA+D;;;AAe/D,qCAAoC;AAA3B,kGAAA,OAAO,OAAA;AAChB,uDAA4D;AAAnD,4GAAA,QAAQ,OAAA;AAAE,gHAAA,YAAY,OAAA;AAC/B,iDAA+C;AAAtC,6GAAA,YAAY,OAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { LPOptions, LPProblem, LPSolution } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Solver LP principal. Acepta el problema en cualquier forma
|
|
4
|
+
* (min/max, ≤/≥/=, con o sin cotas), lo lleva a standardForm y
|
|
5
|
+
* ejecuta simplex de dos fases.
|
|
6
|
+
*/
|
|
7
|
+
export declare function solveLP(problem: LPProblem, opts?: LPOptions): LPSolution;
|
|
8
|
+
//# sourceMappingURL=simplex.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"simplex.d.ts","sourceRoot":"","sources":["../../src/optimization/simplex.ts"],"names":[],"mappings":"AA8BA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAyRhE;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,SAAS,EAAE,IAAI,GAAE,SAAc,GAAG,UAAU,CA4G5E"}
|