@areb0s/scip.js 1.2.3 → 1.2.5

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/dist/types.d.ts CHANGED
@@ -45,6 +45,12 @@ export interface SolveOptions extends InitOptions {
45
45
  verbose?: boolean;
46
46
  /** Additional SCIP parameters */
47
47
  parameters?: Record<string, string | number | boolean>;
48
+ /**
49
+ * Initial solution hint for warm start
50
+ * Object mapping variable names to values
51
+ * @example { "x$sun#0": 1, "x$moon#5": 1 }
52
+ */
53
+ initialSolution?: Record<string, number> | null;
48
54
  }
49
55
 
50
56
  /**
@@ -166,6 +172,170 @@ export interface SCIPModule {
166
172
  declare const SCIP: SCIPModule;
167
173
  export default SCIP;
168
174
 
175
+ // ============================================
176
+ // Callback API Types
177
+ // ============================================
178
+
179
+ /**
180
+ * Callback API solution status (same values, different export)
181
+ */
182
+ export const ApiStatus: typeof Status;
183
+
184
+ /**
185
+ * Callback API solver options (extends base options with callback features)
186
+ */
187
+ export interface CallbackSolveOptions extends SolveOptions {
188
+ /** Initial solution hint for warm start */
189
+ initialSolution?: Record<string, number>;
190
+ /** Cutoff bound - prune nodes with worse objective */
191
+ cutoff?: number;
192
+ }
193
+
194
+ /**
195
+ * Node callback data
196
+ */
197
+ export interface NodeCallbackData {
198
+ /** Current dual (lower) bound */
199
+ dualBound: number;
200
+ /** Current primal (upper) bound */
201
+ primalBound: number;
202
+ /** Number of nodes processed */
203
+ nodes: number;
204
+ }
205
+
206
+ /**
207
+ * Callback API statistics (extended)
208
+ */
209
+ export interface CallbackStatistics {
210
+ /** Solving time in seconds */
211
+ solvingTime: number;
212
+ /** Number of branch-and-bound nodes */
213
+ nodes: number;
214
+ /** Final optimality gap */
215
+ gap: number;
216
+ /** Final dual bound */
217
+ dualBound: number;
218
+ /** Final primal bound */
219
+ primalBound: number;
220
+ }
221
+
222
+ /**
223
+ * Callback API solution result
224
+ */
225
+ export interface CallbackSolution {
226
+ /** Solution status */
227
+ status: StatusType;
228
+ /** Objective function value */
229
+ objective: number;
230
+ /** Variable values */
231
+ variables: Record<string, number>;
232
+ /** Solver statistics */
233
+ statistics: CallbackStatistics;
234
+ /** Error message (if status is ERROR) */
235
+ error?: string;
236
+ }
237
+
238
+ /**
239
+ * Incumbent callback function type
240
+ * Called when a new best solution is found during solving
241
+ */
242
+ export type IncumbentCallback = (objectiveValue: number) => void;
243
+
244
+ /**
245
+ * Node callback function type
246
+ * Called when a node is selected for processing
247
+ */
248
+ export type NodeCallback = (data: NodeCallbackData) => void;
249
+
250
+ /**
251
+ * SCIP API class with callback support
252
+ *
253
+ * @example
254
+ * ```typescript
255
+ * import { SCIPApi } from 'scip.js';
256
+ *
257
+ * const scip = new SCIPApi();
258
+ * await scip.init();
259
+ *
260
+ * // Set callback for new incumbent solutions
261
+ * scip.onIncumbent((objValue) => {
262
+ * console.log('New solution found:', objValue);
263
+ * // Could update cutoff here for custom pruning
264
+ * });
265
+ *
266
+ * const result = await scip.solve(problemZPL, {
267
+ * format: 'zpl',
268
+ * initialSolution: { x: 1, y: 0 },
269
+ * cutoff: 100
270
+ * });
271
+ *
272
+ * scip.destroy();
273
+ * ```
274
+ */
275
+ export class SCIPApi {
276
+ constructor();
277
+
278
+ /**
279
+ * Initialize SCIP API module
280
+ * @param options - Initialization options
281
+ */
282
+ init(options?: InitOptions): Promise<void>;
283
+
284
+ /**
285
+ * Set callback for new incumbent solutions
286
+ * Called whenever SCIP finds a new best solution
287
+ * @param callback - Function receiving the objective value
288
+ */
289
+ onIncumbent(callback: IncumbentCallback | null): void;
290
+
291
+ /**
292
+ * Set callback for node processing (progress tracking)
293
+ * @param callback - Function receiving dual/primal bounds and node count
294
+ */
295
+ onNode(callback: NodeCallback | null): void;
296
+
297
+ /**
298
+ * Solve an optimization problem
299
+ * @param problem - Problem definition string
300
+ * @param options - Solver options including callbacks
301
+ * @returns Solution with statistics
302
+ */
303
+ solve(problem: string, options?: CallbackSolveOptions): Promise<CallbackSolution>;
304
+
305
+ /**
306
+ * Free SCIP resources
307
+ * Call this when done to release memory
308
+ */
309
+ destroy(): void;
310
+ }
311
+
312
+ /**
313
+ * Convenience function to solve with callbacks
314
+ * Creates SCIPApi, solves, and destroys automatically
315
+ *
316
+ * @example
317
+ * ```typescript
318
+ * const result = await solveWithCallbacks(problem, {
319
+ * format: 'zpl',
320
+ * onIncumbent: (obj) => console.log('New best:', obj),
321
+ * onNode: (data) => console.log('Progress:', data.nodes)
322
+ * });
323
+ * ```
324
+ */
325
+ export function solveWithCallbacks(
326
+ problem: string,
327
+ options?: CallbackSolveOptions & {
328
+ onIncumbent?: IncumbentCallback;
329
+ onNode?: NodeCallback;
330
+ }
331
+ ): Promise<CallbackSolution>;
332
+
333
+ /**
334
+ * Create a callback-enabled solver instance
335
+ * Use when you need incumbent callbacks for custom pruning logic
336
+ */
337
+ export function createCallbackSolver(options?: InitOptions): Promise<SCIPApi>;
338
+
169
339
  // Global declaration for CDN usage
170
340
  declare global {
171
341
  interface Window {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@areb0s/scip.js",
3
- "version": "1.2.3",
3
+ "version": "1.2.5",
4
4
  "description": "SCIP Optimization Solver compiled to WebAssembly - LP, MIP, and MINLP support",
5
5
  "main": "dist/index.mjs",
6
6
  "module": "dist/index.mjs",