Skip to main content

Abstract Class: ModelElement

The base class for all modeling objects.

Remarks​

The base class for all modeling objects.

Example​

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

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

Any modeling object can be assigned a name using the ModelElement.name property.

Extended by​

Accessors​

name​

Get Signature​

get name(): string | undefined

The name assigned to this model element.

Remarks​

The name is optional and primarily useful for debugging purposes. When set, it helps identify the element in solver logs, error messages, and when inspecting solutions.

Names can be assigned to any model element including variables, expressions, and constraints.

Example​
import * as CP from "optalcp";

const model = new CP.Model();

// Name a variable at creation
const task = model.intervalVar({ length: 10, name: "assembly" });

// Or set name later
const x = model.intVar({ min: 0, max: 100 });
x.name = "quantity";

console.log(task.name); // "assembly"
console.log(x.name); // "quantity"
Returns​

string | undefined

Set Signature​

set name(value: string): void

Parameters​
ParameterType
valuestring
Returns​

void

Constructors​

Constructor​

new ModelElement(): ModelElement

Returns​

ModelElement