Skip to main content

Class: 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 setName and getName.

Hierarchy

Methods

getName

getName(): undefined | string

Returns the name assigned to the node.

Returns

undefined | string


setName

setName(name): ModelNode

Assigns a name to the node.

Parameters

NameTypeDescription
namestringNamed to be assigned.

Returns

ModelNode

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);