tla-ts 0.0.8-dev.d9bffda → 0.0.9-dev.0493be549
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 +30 -0
- package/dist/compile.cjs +23 -0
- package/dist/compile.js +23 -0
- package/dist/deciders.cjs +28 -28
- package/dist/deciders.js +43 -43
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +80 -10
- package/dist/index.d.ts +80 -10
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove-worker.cjs +1 -1
- package/dist/prove-worker.js +1 -1
- package/dist/prove.cjs +116 -36
- package/dist/prove.js +116 -36
- package/dist/run.cjs +143 -31
- package/dist/run.js +143 -31
- package/dist/tlapm.cjs +2 -2
- package/dist/tlapm.js +2 -2
- package/dist/transfer.cjs +128 -103
- package/dist/transfer.js +128 -103
- package/dist/worker.cjs +7 -7
- package/dist/worker.js +7 -7
- package/package.json +3 -1
- package/src/ast.ts +7 -21
- package/src/bags.ts +99 -99
- package/src/builtins.ts +44 -75
- package/src/bundled-modules.ts +1 -8
- package/src/check.ts +605 -311
- package/src/cli/options.ts +12 -6
- package/src/cli/run.ts +2 -2
- package/src/cli/runtime-invariants.ts +135 -0
- package/src/cli/shared.ts +20 -9
- package/src/cli/tlapm.ts +0 -12
- package/src/cli/tlc-arguments.ts +646 -0
- package/src/cli/tlc-usage.ts +362 -0
- package/src/cli/tlc.ts +545 -218
- package/src/cli/typescript.ts +23 -0
- package/src/cli/xml-exporter.ts +4 -16
- package/src/cli.ts +0 -1
- package/src/codegen.ts +191 -64
- package/src/config.ts +140 -109
- package/src/coverage.ts +837 -0
- package/src/dependencies.ts +6 -40
- package/src/dfid.ts +618 -0
- package/src/environment.ts +240 -118
- package/src/errors.ts +70 -55
- package/src/evaluate.ts +632 -298
- package/src/exit-codes.ts +37 -3
- package/src/fingerprints.ts +10 -10
- package/src/index.ts +3 -0
- package/src/instances.ts +79 -11
- package/src/java-overrides.ts +2 -12
- package/src/json-reader.ts +456 -0
- package/src/json.ts +262 -139
- package/src/levels.ts +2 -3
- package/src/lexer.ts +17 -26
- package/src/liveness-checker.ts +10 -18
- package/src/liveness.ts +121 -49
- package/src/obligations/action.ts +4 -28
- package/src/obligations/anonymize.ts +84 -80
- package/src/obligations/equality.ts +1 -1
- package/src/obligations/expression.ts +2 -19
- package/src/obligations/format.ts +1 -9
- package/src/obligations/generate.ts +1 -11
- package/src/obligations/index.ts +0 -11
- package/src/obligations/levels.ts +4 -8
- package/src/obligations/module.ts +1 -15
- package/src/obligations/normalize.ts +5 -24
- package/src/obligations/operators.ts +1 -2
- package/src/obligations/pragma.ts +1 -10
- package/src/obligations/printer.ts +47 -46
- package/src/obligations/proof.ts +1 -5
- package/src/obligations/regroup.ts +1 -4
- package/src/obligations/simplify.ts +3 -14
- package/src/obligations/source.ts +1 -21
- package/src/obligations/subexpression.ts +5 -11
- package/src/obligations/substitution.ts +1 -3
- package/src/obligations/temporal.ts +8 -14
- package/src/obligations/tuples.ts +3 -9
- package/src/parallel-worker.ts +31 -38
- package/src/parallel.ts +41 -17
- package/src/parser.ts +436 -90
- package/src/pcal/ast.ts +7 -28
- package/src/pcal/parse.ts +11 -39
- package/src/pcal/tokenize.ts +4 -20
- package/src/pcal/translate.ts +10 -42
- package/src/pcal/validate.ts +3 -21
- package/src/pretty-print.ts +1 -2
- package/src/prover/decide-pool.ts +5 -10
- package/src/prover/deciders.ts +0 -4
- package/src/prover/first-order.ts +0 -11
- package/src/prover/isabelle/decide.ts +0 -6
- package/src/prover/isabelle/encode.ts +11 -23
- package/src/prover/isabelle/isar/inner-syntax.ts +108 -114
- package/src/prover/isabelle/isar/method.ts +25 -38
- package/src/prover/isabelle/isar/proof.ts +1 -10
- package/src/prover/isabelle/isar/statement.ts +1 -6
- package/src/prover/isabelle/isar/theory.ts +15 -26
- package/src/prover/isabelle/isar/type-check.ts +11 -25
- package/src/prover/isabelle/provers/blast/blast.ts +10 -41
- package/src/prover/isabelle/provers/blast/branch.ts +1 -32
- package/src/prover/isabelle/provers/blast/prove.ts +1 -35
- package/src/prover/isabelle/provers/blast/rules.ts +6 -44
- package/src/prover/isabelle/provers/blast/state.ts +2 -28
- package/src/prover/isabelle/provers/blast/term.ts +9 -36
- package/src/prover/isabelle/provers/clasimp.ts +1 -13
- package/src/prover/isabelle/provers/classical.ts +14 -42
- package/src/prover/isabelle/provers/hypsubst.ts +11 -25
- package/src/prover/isabelle/pure/bicompose.ts +16 -13
- package/src/prover/isabelle/pure/consts.ts +1 -7
- package/src/prover/isabelle/pure/conv.ts +1 -9
- package/src/prover/isabelle/pure/drule.ts +24 -40
- package/src/prover/isabelle/pure/envir.ts +3 -52
- package/src/prover/isabelle/pure/goal.ts +1 -7
- package/src/prover/isabelle/pure/interrupt.ts +0 -5
- package/src/prover/isabelle/pure/list.ts +0 -3
- package/src/prover/isabelle/pure/logic.ts +1 -14
- package/src/prover/isabelle/pure/name.ts +2 -9
- package/src/prover/isabelle/pure/net.ts +3 -59
- package/src/prover/isabelle/pure/object-logic.ts +3 -10
- package/src/prover/isabelle/pure/pattern.ts +2 -19
- package/src/prover/isabelle/pure/raw-simplifier.ts +13 -49
- package/src/prover/isabelle/pure/rewriter.ts +26 -58
- package/src/prover/isabelle/pure/search.ts +3 -10
- package/src/prover/isabelle/pure/seq.ts +1 -10
- package/src/prover/isabelle/pure/simplifier.ts +4 -12
- package/src/prover/isabelle/pure/table.ts +1 -31
- package/src/prover/isabelle/pure/tactic.ts +12 -22
- package/src/prover/isabelle/pure/tactical.ts +6 -12
- package/src/prover/isabelle/pure/term-ord.ts +2 -6
- package/src/prover/isabelle/pure/term.ts +2 -43
- package/src/prover/isabelle/pure/thm.ts +13 -36
- package/src/prover/isabelle/pure/type.ts +2 -15
- package/src/prover/isabelle/pure/unify.ts +20 -30
- package/src/prover/isabelle/pure/variable.ts +3 -7
- package/src/prover/isabelle/tla/classical-setup.ts +9 -19
- package/src/prover/isabelle/tla/context.ts +8 -16
- package/src/prover/isabelle/tla/logic.ts +4 -11
- package/src/prover/isabelle/tla/simpdata.ts +46 -34
- package/src/prover/isabelle/tools/intuitionistic.ts +1 -10
- package/src/prover/ocaml.ts +0 -6
- package/src/prover/prep/action.ts +4 -36
- package/src/prover/prep/enabled-axioms.ts +12 -19
- package/src/prover/prep/fingerprint.ts +0 -16
- package/src/prover/prep/level-comparison.ts +8 -12
- package/src/prover/prep/md5.ts +0 -2
- package/src/prover/prep/methods.ts +9 -36
- package/src/prover/prep/normalize.ts +4 -28
- package/src/prover/prove-worker.ts +0 -2
- package/src/prover/prove.ts +0 -36
- package/src/prover/ptl/decide.ts +7 -12
- package/src/prover/ptl/encode.ts +14 -36
- package/src/prover/ptl/sat.ts +24 -32
- package/src/prover/ptl/tableau.ts +12 -26
- package/src/prover/smt/axioms.ts +0 -7
- package/src/prover/smt/context.ts +19 -26
- package/src/prover/smt/data.ts +51 -54
- package/src/prover/smt/encode.ts +14 -35
- package/src/prover/smt/extensionality.ts +0 -10
- package/src/prover/smt/flatten.ts +3 -22
- package/src/prover/smt/format.ts +5 -10
- package/src/prover/smt/instances.ts +0 -10
- package/src/prover/smt/rewrite.ts +66 -101
- package/src/prover/smt/solver/act-cache.ts +0 -15
- package/src/prover/smt/solver/arith-rewriter.ts +3 -48
- package/src/prover/smt/solver/array.ts +1 -3
- package/src/prover/smt/solver/asserted-formulas.ts +1 -43
- package/src/prover/smt/solver/ast-lt.ts +1 -11
- package/src/prover/smt/solver/ast-util.ts +1 -6
- package/src/prover/smt/solver/ast.ts +1 -143
- package/src/prover/smt/solver/auf-solver.ts +6 -39
- package/src/prover/smt/solver/case-split-queue.ts +1 -9
- package/src/prover/smt/solver/cg-table.ts +1 -18
- package/src/prover/smt/solver/clause.ts +1 -27
- package/src/prover/smt/solver/conflict-resolution.ts +0 -9
- package/src/prover/smt/solver/context.ts +4 -61
- package/src/prover/smt/solver/ctx-simplify.ts +14 -41
- package/src/prover/smt/solver/der.ts +2 -21
- package/src/prover/smt/solver/dyn-ack.ts +1 -11
- package/src/prover/smt/solver/e-matching.ts +3 -34
- package/src/prover/smt/solver/enode.ts +1 -21
- package/src/prover/smt/solver/expr-ref.ts +1 -5
- package/src/prover/smt/solver/expr-safe-replace.ts +0 -5
- package/src/prover/smt/solver/fingerprints.ts +1 -12
- package/src/prover/smt/solver/flat-literals.ts +1 -9
- package/src/prover/smt/solver/goal.ts +2 -14
- package/src/prover/smt/solver/hash.ts +0 -8
- package/src/prover/smt/solver/hashtable.ts +1 -12
- package/src/prover/smt/solver/internalizer.ts +6 -98
- package/src/prover/smt/solver/lbool.ts +1 -2
- package/src/prover/smt/solver/literal.ts +0 -3
- package/src/prover/smt/solver/lp/bound-propagator.ts +8 -26
- package/src/prover/smt/solver/lp/constraints.ts +2 -8
- package/src/prover/smt/solver/lp/containers.ts +12 -30
- package/src/prover/smt/solver/lp/core-solver.ts +10 -31
- package/src/prover/smt/solver/lp/cross-nested.ts +6 -20
- package/src/prover/smt/solver/lp/dep-intervals.ts +7 -22
- package/src/prover/smt/solver/lp/dependency.ts +1 -4
- package/src/prover/smt/solver/lp/dioph-eq.ts +12 -98
- package/src/prover/smt/solver/lp/explanation.ts +1 -6
- package/src/prover/smt/solver/lp/gomory.ts +9 -22
- package/src/prover/smt/solver/lp/hnf-cutter.ts +17 -23
- package/src/prover/smt/solver/lp/hnf.ts +11 -26
- package/src/prover/smt/solver/lp/int-cube.ts +15 -36
- package/src/prover/smt/solver/lp/int-solver.ts +4 -34
- package/src/prover/smt/solver/lp/lar-solver.ts +32 -81
- package/src/prover/smt/solver/lp/lar-term.ts +1 -5
- package/src/prover/smt/solver/lp/lp-settings.ts +1 -14
- package/src/prover/smt/solver/lp/maximize-term.ts +20 -45
- package/src/prover/smt/solver/lp/nex-creator.ts +5 -28
- package/src/prover/smt/solver/lp/nex.ts +1 -6
- package/src/prover/smt/solver/lp/nla-backoff.ts +1 -4
- package/src/prover/smt/solver/lp/nla-basics.ts +5 -30
- package/src/prover/smt/solver/lp/nla-core.ts +35 -130
- package/src/prover/smt/solver/lp/nla-divisions.ts +32 -42
- package/src/prover/smt/solver/lp/nla-emonics.ts +4 -21
- package/src/prover/smt/solver/lp/nla-factorization.ts +1 -4
- package/src/prover/smt/solver/lp/nla-grobner.ts +15 -69
- package/src/prover/smt/solver/lp/nla-horner.ts +3 -11
- package/src/prover/smt/solver/lp/nla-intervals.ts +2 -12
- package/src/prover/smt/solver/lp/nla-monomial-bounds.ts +16 -41
- package/src/prover/smt/solver/lp/nla-monotone.ts +2 -6
- package/src/prover/smt/solver/lp/nla-order.ts +2 -13
- package/src/prover/smt/solver/lp/nla-patcher.ts +4 -7
- package/src/prover/smt/solver/lp/nla-tangents.ts +1 -9
- package/src/prover/smt/solver/lp/nla-throttle.ts +1 -6
- package/src/prover/smt/solver/lp/nla-types.ts +1 -11
- package/src/prover/smt/solver/lp/nla-var-eqs.ts +4 -25
- package/src/prover/smt/solver/lp/nra-solver.ts +5 -52
- package/src/prover/smt/solver/lp/numeric-pair.ts +1 -4
- package/src/prover/smt/solver/lp/pdd-interval.ts +1 -3
- package/src/prover/smt/solver/lp/pdd-simplifier.ts +2 -14
- package/src/prover/smt/solver/lp/pdd-solver.ts +4 -33
- package/src/prover/smt/solver/lp/pdd.ts +7 -70
- package/src/prover/smt/solver/lp/random-updater.ts +1 -8
- package/src/prover/smt/solver/lp/static-matrix.ts +9 -19
- package/src/prover/smt/solver/lp/union-find.ts +1 -6
- package/src/prover/smt/solver/mam-compiler.ts +14 -56
- package/src/prover/smt/solver/mam-interpreter.ts +1 -21
- package/src/prover/smt/solver/maximize-ac-sharing.ts +2 -17
- package/src/prover/smt/solver/model-checker.ts +2 -36
- package/src/prover/smt/solver/model-evaluator.ts +3 -29
- package/src/prover/smt/solver/model-finder.ts +3 -15
- package/src/prover/smt/solver/model-generator.ts +1 -12
- package/src/prover/smt/solver/model-macro-solver.ts +12 -69
- package/src/prover/smt/solver/nlsat/algebraic.ts +55 -151
- package/src/prover/smt/solver/nlsat/atoms.ts +5 -19
- package/src/prover/smt/solver/nlsat/evaluator.ts +17 -22
- package/src/prover/smt/solver/nlsat/explain.ts +3 -47
- package/src/prover/smt/solver/nlsat/interval-set.ts +9 -50
- package/src/prover/smt/solver/nlsat/levelwise.ts +48 -129
- package/src/prover/smt/solver/nlsat/mpbq.ts +3 -14
- package/src/prover/smt/solver/nlsat/polynomial.ts +17 -156
- package/src/prover/smt/solver/nlsat/solver.ts +7 -67
- package/src/prover/smt/solver/nlsat/types.ts +1 -8
- package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +1 -44
- package/src/prover/smt/solver/nlsat/upolynomial.ts +11 -92
- package/src/prover/smt/solver/nnf.ts +3 -38
- package/src/prover/smt/solver/pattern-inference.ts +2 -15
- package/src/prover/smt/solver/poly-rewriter.ts +3 -23
- package/src/prover/smt/solver/propagate-values.ts +1 -10
- package/src/prover/smt/solver/proto-model.ts +3 -48
- package/src/prover/smt/solver/pull-quant.ts +1 -12
- package/src/prover/smt/solver/qe-lite-der.ts +1 -29
- package/src/prover/smt/solver/qe-lite-fm.ts +2 -25
- package/src/prover/smt/solver/qe-lite.ts +3 -33
- package/src/prover/smt/solver/qi-queue.ts +1 -16
- package/src/prover/smt/solver/quant-tactics.ts +5 -22
- package/src/prover/smt/solver/quantifier-analyzer.ts +17 -37
- package/src/prover/smt/solver/quantifier-manager.ts +1 -8
- package/src/prover/smt/solver/random-gen.ts +1 -2
- package/src/prover/smt/solver/rational.ts +1 -8
- package/src/prover/smt/solver/ref-vector.ts +1 -6
- package/src/prover/smt/solver/relevancy.ts +2 -15
- package/src/prover/smt/solver/rewriter-tpl.ts +3 -147
- package/src/prover/smt/solver/rewriter.ts +3 -85
- package/src/prover/smt/solver/rlimit.ts +2 -20
- package/src/prover/smt/solver/smtlib-parser.ts +2 -37
- package/src/prover/smt/solver/solver.ts +23 -34
- package/src/prover/smt/solver/sort.ts +1 -5
- package/src/prover/smt/solver/sticky-generations.ts +0 -5
- package/src/prover/smt/solver/theory-lra-axioms.ts +3 -24
- package/src/prover/smt/solver/theory-lra-bounds.ts +0 -5
- package/src/prover/smt/solver/theory-lra-final-check.ts +4 -22
- package/src/prover/smt/solver/theory-lra-internalize.ts +1 -27
- package/src/prover/smt/solver/theory-lra-model.ts +4 -19
- package/src/prover/smt/solver/theory-lra-propagate.ts +1 -15
- package/src/prover/smt/solver/theory-lra-state.ts +3 -8
- package/src/prover/smt/solver/theory-lra.ts +1 -8
- package/src/prover/smt/solver/var-subst.ts +2 -26
- package/src/prover/smt/table.ts +0 -8
- package/src/prover/tlapm/cache.ts +20 -25
- package/src/prover/tlapm/ocaml-marshal.ts +19 -21
- package/src/prover/tlapm/tlapm.ts +12 -17
- package/src/prover/verdict.ts +0 -2
- package/src/prover/zenon/check/check.ts +0 -9
- package/src/prover/zenon/check/definitions.ts +5 -15
- package/src/prover/zenon/check/equality.ts +0 -8
- package/src/prover/zenon/check/functions.ts +0 -4
- package/src/prover/zenon/check/keys.ts +0 -7
- package/src/prover/zenon/check/propositional.ts +0 -3
- package/src/prover/zenon/check/records.ts +0 -5
- package/src/prover/zenon/check/relations.ts +0 -13
- package/src/prover/zenon/check/rewrites.ts +0 -6
- package/src/prover/zenon/check/sets.ts +0 -3
- package/src/prover/zenon/check/terms.ts +0 -17
- package/src/prover/zenon/check/tla.ts +0 -6
- package/src/prover/zenon/decide.ts +0 -12
- package/src/prover/zenon/encode.ts +1 -8
- package/src/prover/zenon/eqrel.ts +0 -13
- package/src/prover/zenon/equality-rules.ts +0 -4
- package/src/prover/zenon/expr.ts +1 -26
- package/src/prover/zenon/index-table.ts +17 -38
- package/src/prover/zenon/isar-case.ts +9 -19
- package/src/prover/zenon/isar.ts +1 -29
- package/src/prover/zenon/limits.ts +0 -4
- package/src/prover/zenon/llproof.ts +0 -9
- package/src/prover/zenon/mltoll.ts +54 -76
- package/src/prover/zenon/node.ts +1 -11
- package/src/prover/zenon/ocaml.ts +1 -17
- package/src/prover/zenon/parse.ts +2 -7
- package/src/prover/zenon/phrase.ts +1 -11
- package/src/prover/zenon/proof.ts +0 -9
- package/src/prover/zenon/propositional-rules.ts +0 -5
- package/src/prover/zenon/rules.ts +2 -6
- package/src/prover/zenon/search.ts +1 -17
- package/src/prover/zenon/tla/functions.ts +57 -29
- package/src/prover/zenon/tla/llproof.ts +63 -70
- package/src/prover/zenon/tla/records.ts +56 -27
- package/src/prover/zenon/tla/rewrites.ts +12 -19
- package/src/prover/zenon/tla/sets.ts +68 -39
- package/src/prover/zenon/tla/terms.ts +0 -6
- package/src/prover/zenon/tla/tla.ts +59 -58
- package/src/randomization.ts +84 -35
- package/src/resolve.ts +18 -60
- package/src/runtime.ts +11 -4
- package/src/sany/builtins.ts +3 -4
- package/src/sany/generator.ts +128 -176
- package/src/sany/levels.ts +6 -30
- package/src/sany/lexer.ts +7 -23
- package/src/sany/linter.ts +31 -29
- package/src/sany/modules.ts +1 -5
- package/src/sany/nodes.ts +0 -31
- package/src/sany/parse-error.ts +39 -117
- package/src/sany/report.ts +29 -63
- package/src/sany/selectors.ts +15 -39
- package/src/sany/source.ts +1 -17
- package/src/sany/xml.ts +13 -63
- package/src/search.ts +533 -174
- package/src/simulate.ts +694 -0
- package/src/spec-description.ts +166 -48
- package/src/standard-definitions.ts +2 -3
- package/src/standard-modules.ts +264 -68
- package/src/state-graph.ts +51 -18
- package/src/subexpressions.ts +31 -5
- package/src/substitution-levels.ts +2 -3
- package/src/successors.ts +267 -77
- package/src/symmetry.ts +31 -8
- package/src/tableau.ts +27 -24
- package/src/tlc/fingerprint.ts +183 -61
- package/src/tlc/jar-data.ts +113 -6
- package/src/tlc/messages.ts +122 -37
- package/src/tlc/order.ts +33 -38
- package/src/tlc/random.ts +16 -16
- package/src/tlc/replay.ts +563 -211
- package/src/tlc/summary.ts +2 -4
- package/src/tlc/tlc-operators.ts +81 -36
- package/src/tlc/tlcext-operators.ts +138 -117
- package/src/tlc/trace-spec.ts +273 -0
- package/src/tlc/value-stream.ts +143 -0
- package/src/tlc/version.ts +2 -4
- package/src/transfer.ts +22 -25
- package/src/typescript/actions.ts +481 -0
- package/src/typescript/collections.ts +600 -0
- package/src/typescript/compile.ts +65 -0
- package/src/typescript/context.ts +94 -0
- package/src/typescript/emit.ts +121 -0
- package/src/typescript/expressions.ts +496 -0
- package/src/typescript/formula.ts +152 -0
- package/src/typescript/functions.ts +284 -0
- package/src/typescript/model.ts +163 -0
- package/src/typescript/names.ts +114 -0
- package/src/typescript/program.ts +48 -0
- package/src/typescript/properties.ts +139 -0
- package/src/typescript/scope.ts +112 -0
- package/src/typescript/steps.ts +165 -0
- package/src/typescript/types.ts +171 -0
- package/src/values.ts +832 -255
- package/src/worker.ts +7 -8
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
// Ported from Z3 (src/math/lp/lar_solver.h, src/math/lp/lar_solver.cpp, src/math/lp/column.h,
|
|
2
|
-
// src/math/lp/var_register.h), MIT license, see z3-license.txt. Columns for theory variables and
|
|
3
|
-
// for terms, whose rows the tableau keeps, bounds with dependencies on the constraints that set
|
|
4
|
-
// them, and the push and pop of all of it.
|
|
1
|
+
// Ported from Z3 (src/math/lp/lar_solver.h, src/math/lp/lar_solver.cpp, src/math/lp/column.h, src/math/lp/var_register.h), MIT license, see z3-license.txt.
|
|
5
2
|
import { SmtInvariantError } from "../../../../errors";
|
|
6
3
|
import { Rational } from "../rational";
|
|
7
4
|
import { IndexedUintSet, StackedVector } from "./containers";
|
|
@@ -28,7 +25,7 @@ import {
|
|
|
28
25
|
LP_UNKNOWN,
|
|
29
26
|
type ColumnType,
|
|
30
27
|
} from "./core-solver";
|
|
31
|
-
import { Dependency, linearize, mkJoin } from "./dependency";
|
|
28
|
+
import { type Dependency, linearize, mkJoin } from "./dependency";
|
|
32
29
|
import type { Explanation } from "./explanation";
|
|
33
30
|
import { LarTerm } from "./lar-term";
|
|
34
31
|
import { LpSettings } from "./lp-settings";
|
|
@@ -42,7 +39,6 @@ interface AdjustedBound {
|
|
|
42
39
|
bound: Rational;
|
|
43
40
|
}
|
|
44
41
|
|
|
45
|
-
// The column of a term, under its normalized term, with the first coefficient it was divided by.
|
|
46
42
|
interface NormalizedTermColumn {
|
|
47
43
|
coeff: Rational;
|
|
48
44
|
column: number;
|
|
@@ -60,6 +56,23 @@ const getTermKey = (term: LarTerm) =>
|
|
|
60
56
|
.sort()
|
|
61
57
|
.join(",");
|
|
62
58
|
|
|
59
|
+
const updateDelta = (delta: Rational, low: Impq, high: Impq) => {
|
|
60
|
+
if (low.x.compare(high.x) >= 0 || low.y.compare(high.y) <= 0) return delta;
|
|
61
|
+
const candidate = high.x.sub(low.x).div(low.y.sub(high.y));
|
|
62
|
+
return candidate.compare(delta) < 0 ? candidate : delta;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const getBoundsDelta = (core: CoreSolver, columnCount: number) => {
|
|
66
|
+
let delta = Rational.one;
|
|
67
|
+
for (let column = 0; column < columnCount; column++) {
|
|
68
|
+
if (core.hasLowerBound(column))
|
|
69
|
+
delta = updateDelta(delta, core.lowerBounds[column], core.x[column]);
|
|
70
|
+
if (core.hasUpperBound(column))
|
|
71
|
+
delta = updateDelta(delta, core.x[column], core.upperBounds[column]);
|
|
72
|
+
}
|
|
73
|
+
return delta;
|
|
74
|
+
};
|
|
75
|
+
|
|
63
76
|
export class LarSolver {
|
|
64
77
|
readonly settings: LpSettings;
|
|
65
78
|
readonly core: CoreSolver;
|
|
@@ -70,8 +83,8 @@ export class LarSolver {
|
|
|
70
83
|
readonly columnsWithChangedBounds = new IndexedUintSet();
|
|
71
84
|
rowBoundsToReplay: number[] = [];
|
|
72
85
|
status = LP_UNKNOWN;
|
|
73
|
-
crossedBoundsColumn = NULL_LPVAR;
|
|
74
|
-
crossedBoundsDeps: Dependency = null;
|
|
86
|
+
private crossedBoundsColumn = NULL_LPVAR;
|
|
87
|
+
private crossedBoundsDeps: Dependency = null;
|
|
75
88
|
private externalToLocal = new Map<number, number>();
|
|
76
89
|
private localToExternal: number[] = [];
|
|
77
90
|
private localIsInt: boolean[] = [];
|
|
@@ -83,11 +96,8 @@ export class LarSolver {
|
|
|
83
96
|
private fixedBaseVarSet = new IndexedUintSet();
|
|
84
97
|
private normalizedTermsToColumns = new Map<string, NormalizedTermColumn>();
|
|
85
98
|
private isRegisteringTerms = false;
|
|
86
|
-
// m_delta: zero until init_model sets it.
|
|
87
99
|
private delta = Rational.zero;
|
|
88
|
-
// The callback of nla for the columns whose bounds changed.
|
|
89
100
|
onChangedBounds: ((columns: IndexedUintSet) => void) | undefined;
|
|
90
|
-
// m_add_term_callback and m_update_column_bound_callback, which the Diophantine solver sets.
|
|
91
101
|
onAddTerm: ((term: LarTerm) => void) | undefined;
|
|
92
102
|
onColumnBoundUpdate: ((column: number) => void) | undefined;
|
|
93
103
|
|
|
@@ -163,8 +173,6 @@ export class LarSolver {
|
|
|
163
173
|
return column < this.usageInTerms.values.length ? this.usageInTerms.get(column) : 0;
|
|
164
174
|
}
|
|
165
175
|
|
|
166
|
-
// Columns.
|
|
167
|
-
|
|
168
176
|
private registerExternal(external: number, isInt: boolean) {
|
|
169
177
|
const local = this.localToExternal.length;
|
|
170
178
|
this.localToExternal.push(external);
|
|
@@ -174,7 +182,7 @@ export class LarSolver {
|
|
|
174
182
|
|
|
175
183
|
private addNewVarToCoreFields(isBasic: boolean) {
|
|
176
184
|
this.core.addColumn(isBasic);
|
|
177
|
-
if (isBasic) this.
|
|
185
|
+
if (isBasic) this.touchedRows.add(this.getRowCount() - 1);
|
|
178
186
|
}
|
|
179
187
|
|
|
180
188
|
private pushUndoAddColumn() {
|
|
@@ -209,7 +217,6 @@ export class LarSolver {
|
|
|
209
217
|
return true;
|
|
210
218
|
}
|
|
211
219
|
|
|
212
|
-
// subst_known_terms: replaces term columns by their terms, the smallest column first.
|
|
213
220
|
private substKnownTerms(term: LarTerm) {
|
|
214
221
|
const seen = new Set<number>();
|
|
215
222
|
for (const entry of term.coeffs) if (this.hasTerm(entry[0])) seen.add(entry[0]);
|
|
@@ -276,8 +283,6 @@ export class LarSolver {
|
|
|
276
283
|
return this.normalizedTermsToColumns.get(getTermKey(term));
|
|
277
284
|
}
|
|
278
285
|
|
|
279
|
-
// Removing the last column on pop.
|
|
280
|
-
|
|
281
286
|
private removeLastColumnFromTableau() {
|
|
282
287
|
const core = this.core;
|
|
283
288
|
const matrix = core.matrix;
|
|
@@ -306,8 +311,6 @@ export class LarSolver {
|
|
|
306
311
|
core.removeLastColumn(column);
|
|
307
312
|
}
|
|
308
313
|
|
|
309
|
-
// Bounds.
|
|
310
|
-
|
|
311
314
|
private setUpperBoundWitness(column: number, dep: Dependency, bound: Impq) {
|
|
312
315
|
const info = this.columns[column];
|
|
313
316
|
const savedBound = this.core.upperBounds[column];
|
|
@@ -342,7 +345,6 @@ export class LarSolver {
|
|
|
342
345
|
this.crossedBoundsDeps = mkJoin(isLower ? info.lowerWitness : info.upperWitness, dep);
|
|
343
346
|
}
|
|
344
347
|
|
|
345
|
-
// adjust_bound_for_int: a strict or fractional bound on an integer column, rounded.
|
|
346
348
|
private adjustBoundForInt(column: number, kind: ConstraintKind, bound: Rational): AdjustedBound {
|
|
347
349
|
if (!this.isInt(column) || bound.isInt()) return { kind, bound };
|
|
348
350
|
if (kind === KIND_LT || kind === KIND_LE) return { kind: KIND_LE, bound: bound.floor() };
|
|
@@ -355,7 +357,6 @@ export class LarSolver {
|
|
|
355
357
|
return this.constraints.add(column, adjusted.kind, new Impq(adjusted.bound));
|
|
356
358
|
}
|
|
357
359
|
|
|
358
|
-
// constraint_is_redundant: the current bound of the column is at least as strong.
|
|
359
360
|
constraintIsRedundant(index: number) {
|
|
360
361
|
const constraint = this.constraints.constraints[index];
|
|
361
362
|
const column = constraint.column;
|
|
@@ -390,7 +391,6 @@ export class LarSolver {
|
|
|
390
391
|
);
|
|
391
392
|
}
|
|
392
393
|
|
|
393
|
-
// activate_check_on_equal: also the other column fixed to the same value, if there is one.
|
|
394
394
|
activateCheckOnEqual(index: number) {
|
|
395
395
|
this.activate(index);
|
|
396
396
|
const column = this.constraints.constraints[index].column;
|
|
@@ -458,16 +458,6 @@ export class LarSolver {
|
|
|
458
458
|
this.onColumnBoundUpdate?.(column);
|
|
459
459
|
}
|
|
460
460
|
|
|
461
|
-
addTouchedRow(rowIndex: number) {
|
|
462
|
-
this.touchedRows.add(rowIndex);
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
addColumnRowsToTouchedRows(column: number) {
|
|
466
|
-
for (const cell of this.core.matrix.columns[column]) this.addTouchedRow(cell.row);
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
// Solving.
|
|
470
|
-
|
|
471
461
|
private changeBasicColumnsDependingOn(column: number, delta: Impq) {
|
|
472
462
|
const core = this.core;
|
|
473
463
|
for (const cell of core.matrix.columns[column])
|
|
@@ -495,16 +485,12 @@ export class LarSolver {
|
|
|
495
485
|
core.solve();
|
|
496
486
|
this.status = core.status;
|
|
497
487
|
if (this.status === LP_INFEASIBLE || this.status === LP_CANCELLED) return this.status;
|
|
498
|
-
|
|
499
|
-
if (core.isBase(column)) this.addTouchedRow(core.heading[column]);
|
|
500
|
-
else this.addColumnRowsToTouchedRows(column);
|
|
501
|
-
}
|
|
488
|
+
this.collectMoreRowsForLpPropagation();
|
|
502
489
|
this.onChangedBounds?.(this.columnsWithChangedBounds);
|
|
503
490
|
this.columnsWithChangedBounds.clear();
|
|
504
491
|
return this.status;
|
|
505
492
|
}
|
|
506
493
|
|
|
507
|
-
// get_infeasibility_explanation: the crossed bounds, or the bounds of the infeasible row.
|
|
508
494
|
getInfeasibilityExplanation(explanation: Explanation) {
|
|
509
495
|
explanation.clear();
|
|
510
496
|
if (this.crossedBoundsColumn !== NULL_LPVAR) {
|
|
@@ -523,7 +509,6 @@ export class LarSolver {
|
|
|
523
509
|
}
|
|
524
510
|
}
|
|
525
511
|
|
|
526
|
-
// remove_fixed_vars_from_base: pivots fixed basic columns out of the basis.
|
|
527
512
|
removeFixedVarsFromBase() {
|
|
528
513
|
const core = this.core;
|
|
529
514
|
const columnCount = this.getColumnCount();
|
|
@@ -545,8 +530,7 @@ export class LarSolver {
|
|
|
545
530
|
for (const column of toRemove) this.fixedBaseVarSet.delete(column);
|
|
546
531
|
}
|
|
547
532
|
|
|
548
|
-
|
|
549
|
-
removeFromBasis(column: number) {
|
|
533
|
+
private removeFromBasis(column: number) {
|
|
550
534
|
const core = this.core;
|
|
551
535
|
for (const cell of core.matrix.rows[core.heading[column]]) {
|
|
552
536
|
if (cell.column === column || this.isFixed(cell.column)) continue;
|
|
@@ -562,8 +546,6 @@ export class LarSolver {
|
|
|
562
546
|
return !(core.hasLowerBound(column) && value.compare(core.lowerBounds[column]) < 0);
|
|
563
547
|
}
|
|
564
548
|
|
|
565
|
-
// try_to_patch: sets a column to a value unless the column or a basic column it moves is blocked,
|
|
566
|
-
// reporting each changed column.
|
|
567
549
|
tryToPatch(
|
|
568
550
|
column: number,
|
|
569
551
|
value: Rational,
|
|
@@ -591,9 +573,9 @@ export class LarSolver {
|
|
|
591
573
|
}
|
|
592
574
|
|
|
593
575
|
moveNonBasicColumnsToBounds() {
|
|
594
|
-
const core = this.core;
|
|
595
576
|
let isChanged = false;
|
|
596
|
-
for (const column of core.nbasis)
|
|
577
|
+
for (const column of this.core.nbasis)
|
|
578
|
+
if (this.moveNonBasicColumnToBounds(column)) isChanged = true;
|
|
597
579
|
if (isChanged) this.findFeasibleSolution();
|
|
598
580
|
}
|
|
599
581
|
|
|
@@ -629,24 +611,11 @@ export class LarSolver {
|
|
|
629
611
|
return false;
|
|
630
612
|
}
|
|
631
613
|
|
|
632
|
-
// The model.
|
|
633
|
-
|
|
634
|
-
// init_model: a δ that keeps strict bounds strict and distinct values distinct.
|
|
635
614
|
initModel() {
|
|
636
|
-
if (this.
|
|
615
|
+
if (!this.isFeasible()) return false;
|
|
637
616
|
if (this.columnsWithChangedBounds.size > 0) return false;
|
|
638
617
|
const core = this.core;
|
|
639
|
-
let delta =
|
|
640
|
-
const updateDelta = (low: Impq, high: Impq) => {
|
|
641
|
-
if (low.x.compare(high.x) < 0 && low.y.compare(high.y) > 0) {
|
|
642
|
-
const candidate = high.x.sub(low.x).div(low.y.sub(high.y));
|
|
643
|
-
if (candidate.compare(delta) < 0) delta = candidate;
|
|
644
|
-
}
|
|
645
|
-
};
|
|
646
|
-
for (let column = 0; column < this.getColumnCount(); column++) {
|
|
647
|
-
if (core.hasLowerBound(column)) updateDelta(core.lowerBounds[column], core.x[column]);
|
|
648
|
-
if (core.hasUpperBound(column)) updateDelta(core.x[column], core.upperBounds[column]);
|
|
649
|
-
}
|
|
618
|
+
let delta = getBoundsDelta(core, this.getColumnCount());
|
|
650
619
|
const pairs = new Map<string, Impq>();
|
|
651
620
|
for (const value of core.x) pairs.set(value.toString(), value);
|
|
652
621
|
for (;;) {
|
|
@@ -664,7 +633,6 @@ export class LarSolver {
|
|
|
664
633
|
return value.x.add(this.delta.mul(value.y));
|
|
665
634
|
}
|
|
666
635
|
|
|
667
|
-
// has_value: the value of a column, or of the term of a column, when δ does not occur in it.
|
|
668
636
|
getExactValue(column: number) {
|
|
669
637
|
const term = this.columns[column].term;
|
|
670
638
|
if (term === null) {
|
|
@@ -680,7 +648,6 @@ export class LarSolver {
|
|
|
680
648
|
return result;
|
|
681
649
|
}
|
|
682
650
|
|
|
683
|
-
// has_lower_bound and has_upper_bound: the witness, value and strictness of a bound.
|
|
684
651
|
getBound(column: number, isUpper: boolean) {
|
|
685
652
|
if (column >= this.columns.length) return undefined;
|
|
686
653
|
const info = this.columns[column];
|
|
@@ -694,38 +661,25 @@ export class LarSolver {
|
|
|
694
661
|
};
|
|
695
662
|
}
|
|
696
663
|
|
|
697
|
-
// get_rid_of_inf_eps: the values with δ instantiated small enough to keep strict bounds strict.
|
|
698
664
|
getRidOfInfEps() {
|
|
699
665
|
const core = this.core;
|
|
700
666
|
const columnCount = this.getColumnCount();
|
|
701
667
|
if (core.x.slice(0, columnCount).every((value) => value.y.isZero())) return;
|
|
702
|
-
|
|
703
|
-
const updateDelta = (low: Impq, high: Impq) => {
|
|
704
|
-
if (low.x.compare(high.x) < 0 && low.y.compare(high.y) > 0) {
|
|
705
|
-
const candidate = high.x.sub(low.x).div(low.y.sub(high.y));
|
|
706
|
-
if (candidate.compare(delta) < 0) delta = candidate;
|
|
707
|
-
}
|
|
708
|
-
};
|
|
709
|
-
for (let column = 0; column < columnCount; column++) {
|
|
710
|
-
if (core.hasLowerBound(column)) updateDelta(core.lowerBounds[column], core.x[column]);
|
|
711
|
-
if (core.hasUpperBound(column)) updateDelta(core.x[column], core.upperBounds[column]);
|
|
712
|
-
}
|
|
668
|
+
const delta = getBoundsDelta(core, columnCount);
|
|
713
669
|
for (let column = 0; column < columnCount; column++) {
|
|
714
670
|
const value = core.x[column];
|
|
715
671
|
if (!value.y.isZero()) core.x[column] = new Impq(value.x.add(delta.mul(value.y)));
|
|
716
672
|
}
|
|
717
673
|
}
|
|
718
674
|
|
|
719
|
-
// get_bound_constraint_witnesses_for_column: the witnesses of both bounds.
|
|
720
675
|
getBoundWitnesses(column: number) {
|
|
721
676
|
return mkJoin(this.columns[column].lowerWitness, this.columns[column].upperWitness);
|
|
722
677
|
}
|
|
723
678
|
|
|
724
|
-
// collect_more_rows_for_lp_propagation: the rows of the columns whose bounds nla changed.
|
|
725
679
|
collectMoreRowsForLpPropagation() {
|
|
726
680
|
for (const column of this.columnsWithChangedBounds.elems) {
|
|
727
|
-
if (this.core.isBase(column)) this.
|
|
728
|
-
else this.
|
|
681
|
+
if (this.core.isBase(column)) this.touchedRows.add(this.core.heading[column]);
|
|
682
|
+
else for (const cell of this.core.matrix.columns[column]) this.touchedRows.add(cell.row);
|
|
729
683
|
}
|
|
730
684
|
}
|
|
731
685
|
|
|
@@ -737,8 +691,6 @@ export class LarSolver {
|
|
|
737
691
|
return this.columns[column].upperWitness;
|
|
738
692
|
}
|
|
739
693
|
|
|
740
|
-
// Scopes.
|
|
741
|
-
|
|
742
694
|
pushTrail(undo: () => void) {
|
|
743
695
|
this.trail.push(undo);
|
|
744
696
|
}
|
|
@@ -769,7 +721,7 @@ export class LarSolver {
|
|
|
769
721
|
for (const table of [this.fixedVarTableInt, this.fixedVarTableReal])
|
|
770
722
|
for (const entry of table)
|
|
771
723
|
if (entry[1] >= columnCount || !this.isFixed(entry[1])) table.delete(entry[0]);
|
|
772
|
-
for (const rowIndex of this.rowBoundsToReplay) this.
|
|
724
|
+
for (const rowIndex of this.rowBoundsToReplay) this.touchedRows.add(rowIndex);
|
|
773
725
|
this.rowBoundsToReplay = [];
|
|
774
726
|
const rowCount = this.getRowCount();
|
|
775
727
|
for (const rowIndex of this.touchedRows.elems.filter((row) => row >= rowCount))
|
|
@@ -797,7 +749,6 @@ export class LarSolver {
|
|
|
797
749
|
if (core.columnIsFeasible(column)) core.infHeap.erase(column);
|
|
798
750
|
}
|
|
799
751
|
|
|
800
|
-
// add_equality: the term j - k bounded above and below by 0.
|
|
801
752
|
addEquality(first: number, second: number) {
|
|
802
753
|
const column = this.addTerm(
|
|
803
754
|
[
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
// Ported from Z3 (src/math/lp/lar_term.h), MIT license, see z3-license.txt.
|
|
2
|
-
// columns, kept in a u_map so that its iteration order is Z3's.
|
|
1
|
+
// Ported from Z3 (src/math/lp/lar_term.h), MIT license, see z3-license.txt.
|
|
3
2
|
import { getIdentityHash, ObjMap } from "../hashtable";
|
|
4
3
|
import { Rational } from "../rational";
|
|
5
4
|
import { Impq } from "./numeric-pair";
|
|
@@ -32,14 +31,12 @@ export class LarTerm {
|
|
|
32
31
|
else this.coeffs.replace(column, sum);
|
|
33
32
|
}
|
|
34
33
|
|
|
35
|
-
// apply: the value of the term at the column values.
|
|
36
34
|
apply(values: Impq[]) {
|
|
37
35
|
let value = Impq.zero;
|
|
38
36
|
for (const entry of this.coeffs) value = value.add(values[entry[0]].mul(entry[1]));
|
|
39
37
|
return value;
|
|
40
38
|
}
|
|
41
39
|
|
|
42
|
-
// subst_by_term: replaces the term column by its definition.
|
|
43
40
|
substByTerm(term: LarTerm, termColumn: number) {
|
|
44
41
|
const coeff = this.coeffs.get(termColumn);
|
|
45
42
|
if (coeff === undefined) return;
|
|
@@ -47,7 +44,6 @@ export class LarTerm {
|
|
|
47
44
|
for (const entry of term.coeffs) this.addMonomial(coeff.mul(entry[1]), entry[0]);
|
|
48
45
|
}
|
|
49
46
|
|
|
50
|
-
// get_normalized_by_min_var: the term divided by its first coefficient, and that coefficient.
|
|
51
47
|
getNormalized() {
|
|
52
48
|
const entries = [...this.coeffs];
|
|
53
49
|
if (entries.length === 0) return { term: this, coeff: Rational.one };
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
// Ported from Z3 (src/math/lp/lp_settings.h, src/math/lp/lp_settings.cpp), MIT license, see
|
|
2
|
-
// z3-license.txt. The settings that theory_lra's UFNIA configuration gives the lp solver, its
|
|
3
|
-
// random generator and its statistics.
|
|
1
|
+
// Ported from Z3 (src/math/lp/lp_settings.h, src/math/lp/lp_settings.cpp), MIT license, see z3-license.txt.
|
|
4
2
|
import { RandomGen } from "../random-gen";
|
|
5
3
|
|
|
6
4
|
export interface LpStats {
|
|
@@ -23,10 +21,8 @@ export interface LpStats {
|
|
|
23
21
|
lcubeFlipSuccess: number;
|
|
24
22
|
nlaCalls: number;
|
|
25
23
|
nlaAddBounds: number;
|
|
26
|
-
nlaPropagateBounds: number;
|
|
27
24
|
nlaPropagateEq: number;
|
|
28
25
|
nlaLemmas: number;
|
|
29
|
-
nlaBoundsImprovements: number;
|
|
30
26
|
nlaThrottledLemmas: number;
|
|
31
27
|
nraCalls: number;
|
|
32
28
|
}
|
|
@@ -53,37 +49,28 @@ export class LpSettings {
|
|
|
53
49
|
lcubeFlipSuccess: 0,
|
|
54
50
|
nlaCalls: 0,
|
|
55
51
|
nlaAddBounds: 0,
|
|
56
|
-
nlaPropagateBounds: 0,
|
|
57
52
|
nlaPropagateEq: 0,
|
|
58
53
|
nlaLemmas: 0,
|
|
59
|
-
nlaBoundsImprovements: 0,
|
|
60
54
|
nlaThrottledLemmas: 0,
|
|
61
55
|
nraCalls: 0,
|
|
62
56
|
};
|
|
63
57
|
readonly maxRowLengthForBoundPropagation = 300;
|
|
64
|
-
readonly maxIterationsWithNoImprovements = 2000000;
|
|
65
58
|
readonly isPropagatingEqs = true;
|
|
66
59
|
readonly intFindCubePeriod = 4;
|
|
67
|
-
// lp.lcube_flips: the most flips that repair a rounded cube center.
|
|
68
60
|
readonly lcubeFlips = 16;
|
|
69
61
|
readonly hnfCutPeriod = 4;
|
|
70
62
|
readonly limitOnRowsForHnfCutter = 75;
|
|
71
63
|
readonly limitOnColumnsForHnfCutter = 150;
|
|
72
64
|
readonly intGomoryCutPeriod = 4;
|
|
73
|
-
// lp.dio_calls_period, which the Diophantine solver's results move, its decrease, and
|
|
74
|
-
// lp.dio_gomory_enable_period.
|
|
75
65
|
dioCallsPeriod = 1;
|
|
76
66
|
readonly dioCallsPeriodDecrease = 2;
|
|
77
67
|
readonly dioGomoryEnablePeriod = 16;
|
|
78
|
-
// m_run_gomory_with_dio: Gomory cuts run once the Diophantine solver keeps failing.
|
|
79
68
|
isRunningGomoryWithDio = false;
|
|
80
|
-
// lp.dio_ignore_big_nums and lp.dio_undo_max_work.
|
|
81
69
|
readonly isDioIgnoringBigNums = true;
|
|
82
70
|
readonly dioUndoMaxWork = 1000000;
|
|
83
71
|
|
|
84
72
|
constructor(readonly isCanceled: () => boolean) {}
|
|
85
73
|
|
|
86
|
-
// random_next: random_gen's next value, or that value modulo a bound.
|
|
87
74
|
getRandomNext(bound?: number) {
|
|
88
75
|
const value = this.random.next();
|
|
89
76
|
return bound === undefined ? value : value % bound;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
// Ported from Z3 (maximize_term and its helpers in src/math/lp/lar_solver.cpp, and the tableau
|
|
2
|
-
//
|
|
3
|
-
// src/math/lp/lp_primal_core_solver_tableau_def.h), MIT license, see z3-license.txt.
|
|
4
|
-
// simplex with the tableau_costs strategy: from a feasible solution, a non-basic column whose
|
|
5
|
-
// reduced cost improves the objective enters, the ratio test picks the basic column that leaves,
|
|
6
|
-
// and the reduced costs follow every pivot.
|
|
1
|
+
// Ported from Z3 (maximize_term and its helpers in src/math/lp/lar_solver.cpp, and the tableau part
|
|
2
|
+
// of src/math/lp/lp_primal_core_solver.h, src/math/lp/lp_primal_core_solver_def.h,
|
|
3
|
+
// src/math/lp/lp_primal_core_solver_tableau_def.h), MIT license, see z3-license.txt.
|
|
7
4
|
import { Rational } from "../rational";
|
|
8
5
|
import {
|
|
9
6
|
COLUMN_BOXED,
|
|
@@ -22,12 +19,9 @@ import type { LarSolver } from "./lar-solver";
|
|
|
22
19
|
import { LarTerm } from "./lar-term";
|
|
23
20
|
import { Impq } from "./numeric-pair";
|
|
24
21
|
|
|
25
|
-
// m_nbasis_sort_counter: the non-basic columns are sorted again after this many choices.
|
|
26
22
|
const NBASIS_SORT_PERIOD = 20;
|
|
27
|
-
// percent_of_entering_to_check, for more than 300 non-basic columns.
|
|
28
23
|
const PERCENT_OF_ENTERING_TO_CHECK = 5;
|
|
29
24
|
|
|
30
|
-
// The theta of a ratio test, and whether a bound limits it yet.
|
|
31
25
|
interface ThetaLimit {
|
|
32
26
|
theta: Impq;
|
|
33
27
|
isUnlimited: boolean;
|
|
@@ -59,8 +53,6 @@ class CostsSimplex {
|
|
|
59
53
|
private readonly reducedCosts: Rational[],
|
|
60
54
|
) {}
|
|
61
55
|
|
|
62
|
-
// lar_core_solver::solve and lp_primal_core_solver::solve, not only looking for a feasible
|
|
63
|
-
// solution.
|
|
64
56
|
solve() {
|
|
65
57
|
const core = this.core;
|
|
66
58
|
const settings = core.settings;
|
|
@@ -70,7 +62,7 @@ class CostsSimplex {
|
|
|
70
62
|
core.status = LP_CANCELLED;
|
|
71
63
|
return;
|
|
72
64
|
}
|
|
73
|
-
this.
|
|
65
|
+
this.oneIterationTableau();
|
|
74
66
|
if (settings.isCanceled()) {
|
|
75
67
|
core.status = LP_CANCELLED;
|
|
76
68
|
return;
|
|
@@ -82,24 +74,22 @@ class CostsSimplex {
|
|
|
82
74
|
);
|
|
83
75
|
}
|
|
84
76
|
|
|
85
|
-
|
|
86
|
-
private oneIteration() {
|
|
77
|
+
private oneIterationTableau() {
|
|
87
78
|
const core = this.core;
|
|
88
|
-
const entering = this.
|
|
79
|
+
const entering = this.chooseEnteringColumnTableau();
|
|
89
80
|
if (entering === -1) {
|
|
90
81
|
core.status = core.isFeasible() ? LP_OPTIMAL : LP_INFEASIBLE;
|
|
91
82
|
return;
|
|
92
83
|
}
|
|
93
84
|
const limit: ThetaLimit = { theta: Impq.zero, isUnlimited: true };
|
|
94
|
-
const leaving = this.
|
|
85
|
+
const leaving = this.findLeavingAndTTableau(entering, limit);
|
|
95
86
|
if (leaving === -1) {
|
|
96
87
|
core.status = LP_UNBOUNDED;
|
|
97
88
|
return;
|
|
98
89
|
}
|
|
99
|
-
this.
|
|
90
|
+
this.advanceOnEnteringAndLeavingTableau(entering, leaving, limit.theta);
|
|
100
91
|
}
|
|
101
92
|
|
|
102
|
-
// sort_non_basis: the non-basic columns by the size of their columns, the empty ones last.
|
|
103
93
|
private sortNonBasis() {
|
|
104
94
|
const core = this.core;
|
|
105
95
|
const columns = core.matrix.columns;
|
|
@@ -115,23 +105,20 @@ class CostsSimplex {
|
|
|
115
105
|
core.heading[core.nbasis[index]] = -index - 1;
|
|
116
106
|
}
|
|
117
107
|
|
|
118
|
-
|
|
119
|
-
private getNumberToTry() {
|
|
108
|
+
private getNumberOfNonBasicColumnToTryForEnter() {
|
|
120
109
|
const count = this.core.nbasis.length;
|
|
121
110
|
const scaled = count > 300 ? Math.floor((count * PERCENT_OF_ENTERING_TO_CHECK) / 100) : count;
|
|
122
111
|
if (scaled === 0) return 0;
|
|
123
112
|
return Math.max(this.core.settings.getRandomNext() % scaled, 1);
|
|
124
113
|
}
|
|
125
114
|
|
|
126
|
-
|
|
127
|
-
// cells, and a random one among ties. It moves to the end of the list.
|
|
128
|
-
private chooseEntering() {
|
|
115
|
+
private chooseEnteringColumnTableau() {
|
|
129
116
|
const core = this.core;
|
|
130
117
|
if (this.sortCounter === 0) {
|
|
131
118
|
this.sortNonBasis();
|
|
132
119
|
this.sortCounter = NBASIS_SORT_PERIOD;
|
|
133
120
|
} else this.sortCounter--;
|
|
134
|
-
let numToGoOver = this.
|
|
121
|
+
let numToGoOver = this.getNumberOfNonBasicColumnToTryForEnter();
|
|
135
122
|
if (numToGoOver === 0) return -1;
|
|
136
123
|
let minCells = core.matrix.getRowCount() + 1;
|
|
137
124
|
let enteringIndex = -1;
|
|
@@ -139,7 +126,7 @@ class CostsSimplex {
|
|
|
139
126
|
const list = this.nonBasisList;
|
|
140
127
|
for (let index = 0; numToGoOver > 0 && index < list.length; index++) {
|
|
141
128
|
const column = list[index];
|
|
142
|
-
if (!this.
|
|
129
|
+
if (!this.isColumnBeneficialForEnteringBasis(column)) continue;
|
|
143
130
|
const cells = core.matrix.columns[column].length;
|
|
144
131
|
if (cells < minCells) {
|
|
145
132
|
minCells = cells;
|
|
@@ -157,8 +144,7 @@ class CostsSimplex {
|
|
|
157
144
|
return entering;
|
|
158
145
|
}
|
|
159
146
|
|
|
160
|
-
|
|
161
|
-
private isBeneficial(column: number) {
|
|
147
|
+
private isColumnBeneficialForEnteringBasis(column: number) {
|
|
162
148
|
const core = this.core;
|
|
163
149
|
const reducedCost = this.reducedCosts[column];
|
|
164
150
|
if (reducedCost.isZero()) return false;
|
|
@@ -178,10 +164,7 @@ class CostsSimplex {
|
|
|
178
164
|
}
|
|
179
165
|
}
|
|
180
166
|
|
|
181
|
-
|
|
182
|
-
// broken by the shortest row and then at random, or the entering column itself when it reaches
|
|
183
|
-
// its other bound first.
|
|
184
|
-
private findLeaving(entering: number, limit: ThetaLimit) {
|
|
167
|
+
private findLeavingAndTTableau(entering: number, limit: ThetaLimit) {
|
|
185
168
|
const core = this.core;
|
|
186
169
|
const matrix = core.matrix;
|
|
187
170
|
const column = matrix.columns[entering];
|
|
@@ -233,8 +216,6 @@ class CostsSimplex {
|
|
|
233
216
|
return candidates[core.settings.getRandomNext() % candidates.length];
|
|
234
217
|
}
|
|
235
218
|
|
|
236
|
-
// limit_theta_on_basis_column: x[basic] + theta * m stays within the bounds of the column, or
|
|
237
|
-
// moves toward them when it is outside.
|
|
238
219
|
private limitThetaOnBasisColumn(basic: number, m: Rational, limit: ThetaLimit) {
|
|
239
220
|
const core = this.core;
|
|
240
221
|
const x = core.x[basic];
|
|
@@ -280,21 +261,19 @@ class CostsSimplex {
|
|
|
280
261
|
if (!limit.isUnlimited) clampTheta(limit);
|
|
281
262
|
}
|
|
282
263
|
|
|
283
|
-
|
|
284
|
-
private advance(entering: number, leaving: number, theta: Impq) {
|
|
264
|
+
private advanceOnEnteringAndLeavingTableau(entering: number, leaving: number, theta: Impq) {
|
|
285
265
|
const core = this.core;
|
|
286
266
|
const sign = Rational.fromNumber(this.signOfEnteringDelta);
|
|
287
267
|
if (entering === leaving) {
|
|
288
|
-
this.
|
|
268
|
+
this.updateXTableau(entering, theta.mul(sign));
|
|
289
269
|
return;
|
|
290
270
|
}
|
|
291
|
-
if (!theta.isZero()) this.
|
|
271
|
+
if (!theta.isZero()) this.updateXTableau(entering, core.isFeasible() ? theta.mul(sign) : theta);
|
|
292
272
|
core.pivot(entering, leaving);
|
|
293
273
|
this.nonBasisList[this.nonBasisList.length - 1] = leaving;
|
|
294
274
|
}
|
|
295
275
|
|
|
296
|
-
|
|
297
|
-
private updateX(entering: number, delta: Impq) {
|
|
276
|
+
private updateXTableau(entering: number, delta: Impq) {
|
|
298
277
|
const core = this.core;
|
|
299
278
|
core.x[entering] = core.x[entering].add(delta);
|
|
300
279
|
for (const cell of core.matrix.columns[entering])
|
|
@@ -305,9 +284,7 @@ class CostsSimplex {
|
|
|
305
284
|
}
|
|
306
285
|
}
|
|
307
286
|
|
|
308
|
-
|
|
309
|
-
// and the term's value at the optimum, or undefined when it is unbounded or cancelled.
|
|
310
|
-
const maximizeOnFeasibleSolver = (solver: LarSolver, term: LarTerm) => {
|
|
287
|
+
const maximizeTermOnFeasibleRSolver = (solver: LarSolver, term: LarTerm) => {
|
|
311
288
|
const core = solver.core;
|
|
312
289
|
solver.moveNonBasicColumnsToBounds();
|
|
313
290
|
const reducedCosts = core.x.map(() => Rational.zero);
|
|
@@ -330,14 +307,12 @@ const maximizeOnFeasibleSolver = (solver: LarSolver, term: LarTerm) => {
|
|
|
330
307
|
return status === LP_UNBOUNDED || status === LP_CANCELLED ? undefined : term.apply(core.x);
|
|
331
308
|
};
|
|
332
309
|
|
|
333
|
-
// maximize_term without fixing the integer columns: the maximum of the column or of its term, or
|
|
334
|
-
// undefined, with the values restored, when it is unbounded.
|
|
335
310
|
export const maximizeTerm = (solver: LarSolver, column: number) => {
|
|
336
311
|
const term = solver.hasTerm(column)
|
|
337
312
|
? solver.getTerm(column)
|
|
338
313
|
: new LarTerm([[column, Rational.one]]);
|
|
339
314
|
const backup = solver.core.x.slice();
|
|
340
|
-
const maximum =
|
|
315
|
+
const maximum = maximizeTermOnFeasibleRSolver(solver, term);
|
|
341
316
|
if (maximum === undefined) {
|
|
342
317
|
solver.core.x.splice(0, backup.length, ...backup);
|
|
343
318
|
return undefined;
|