Skip to main content

Class: Objective

Represents an optimization objective in the model.

Remarks​

An objective specifies what value should be minimized or maximized when solving the model. Objectives are created by calling Model.minimize or Model.maximize, or by using the fluent methods IntExpr.minimize or IntExpr.maximize.

A model can have at most one objective.

import * as CP from "optalcp";

const model = new CP.Model();
const x = model.intervalVar({length: 10, name: "x"});
const y = model.intervalVar({length: 20, name: "y"});

// Create objective using Model.minimize() - automatically registered:
model.minimize(y.end());

// Or using fluent style on expressions - automatically registered:
y.end().minimize();

See​

Extends​

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

Inherited from​

ModelElement.name

Constructors​

Constructor​

new Objective(): Objective

Returns​

Objective

Inherited from​

ModelElement.constructor