Skip to main content

Class: abstract ModelNode

The base class for all modeling objects.

Example

let model = new CP.Model();
let x = model.intervalVar({ length: 10, name: "x" });
let xStart = model.startOf(x);
let result = await CP.solve(model);

Interval variable x and expression xStart are both instances of ModelNode. There are specialized descendant classes such as IntervalVar and IntExpr.

Any modeling object can be assigned a name, see ModelNode#setName and ModelNode#getName.

Extended by

Methods

getName()

getName(): undefined | string

Returns the name assigned to the node.

Returns

undefined | string


setName()

setName(name: string): this

Assigns a name to the node.

Parameters

ParameterTypeDescription
namestringNamed to be assigned.

Returns

this

The node itself so it can be used in chained expression.

Remarks

Assigning a name is optional. However is useful for debugging because variable names appear in the development traces. It is also useful for exporting the model to a file (see problem2json).

Example

let model = new CP.Model();
let x = model.intervalVar({ length: 10 }).setName("x");
// The line above is equivalent to:
// let x = model.intervalVar({ length: 10, name:"x" });
let endOfX = model.endOf(x).setName("endOfX");
let result = await CP.solve(model);