cpsat-js 1.3.1 → 1.4.0
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 +22 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -89,6 +89,8 @@ if (result.status === CpSolverStatus.OPTIMAL) {
|
|
|
89
89
|
- `addBoolOr([...literals])` / `addBoolAnd([...literals])` — boolean logic
|
|
90
90
|
- `addNoOverlap([...intervals])` — scheduling / disjunctive constraints
|
|
91
91
|
- `addCircuit([[tail, head, literal], ...])` — routing / TSP
|
|
92
|
+
- `addMultiplicationEquality`, `addDivisionEquality`, `addModuloEquality` — products, integer division, remainders
|
|
93
|
+
- `addMaxEquality` / `addMinEquality` — maximum / minimum of expressions
|
|
92
94
|
- `minimize(expr)` / `maximize(expr)` — optimization objectives
|
|
93
95
|
- `.onlyEnforceIf(literal)` — conditional enforcement (half-reification)
|
|
94
96
|
|
|
@@ -164,9 +166,29 @@ Builder for constraint programming models.
|
|
|
164
166
|
- `addBoolAnd(literals): Constraint`
|
|
165
167
|
- `addNoOverlap(intervals): Constraint`
|
|
166
168
|
- `addCircuit(arcs): Constraint`
|
|
169
|
+
- `addMultiplicationEquality(target, exprs): Constraint` — `target == exprs[0] * exprs[1] * ...`
|
|
170
|
+
- `addDivisionEquality(target, num, denom): Constraint` — `target == num / denom`, rounded towards zero
|
|
171
|
+
- `addModuloEquality(target, expr, mod): Constraint` — `target == expr % mod`, with `mod > 0`
|
|
172
|
+
- `addMaxEquality(target, exprs): Constraint` / `addMinEquality(target, exprs): Constraint`
|
|
167
173
|
- `minimize(expr)` / `maximize(expr)`
|
|
168
174
|
- `addHint(variable, value)` / `clearHints()` — suggest where the search should start
|
|
169
175
|
|
|
176
|
+
#### Non-linear constraints
|
|
177
|
+
|
|
178
|
+
CP-SAT only accepts multiplication, division and modulo over expressions with at most one variable, such as `x`, `x.times(2)` or `x.minus(3)`. Passing `x.plus(y)` throws when the constraint is built. To use it, introduce an intermediate variable:
|
|
179
|
+
|
|
180
|
+
```ts
|
|
181
|
+
const x = model.newIntVar(0, 10, 'x');
|
|
182
|
+
const y = model.newIntVar(0, 10, 'y');
|
|
183
|
+
const sum = model.newIntVar(0, 20, 'sum');
|
|
184
|
+
const sq = model.newIntVar(0, 400, 'sq');
|
|
185
|
+
|
|
186
|
+
model.add(sum.equals(x.plus(y)));
|
|
187
|
+
model.addMultiplicationEquality(sq, [sum, sum]); // sq == (x + y)^2
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
`addMaxEquality` and `addMinEquality` accept any linear expression.
|
|
191
|
+
|
|
170
192
|
#### Hints
|
|
171
193
|
|
|
172
194
|
A hint is advisory. It constrains nothing, cannot change the optimal value, and a wrong
|