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
- Model.minimize for creating minimization objectives.
- Model.maximize for creating maximization objectives.
- IntExpr.minimize for fluent-style minimization.
- IntExpr.maximize for fluent-style maximization.
Extends
Accessors
name
Get Signature
get name():
undefined|string
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
undefined | string
Set Signature
set name(
value:string):void
Parameters
| Parameter | Type |
|---|---|
value | string |
Returns
void
Inherited from
Constructors
new Objective()
new Objective():
Objective
Returns
Inherited from
Properties
| Property | Modifier | Type |
|---|---|---|
__brand | readonly | "Objective" |