Table of Contents

Class ModelElement

Namespace
OptalCP
Assembly
OptalCP.dll

The base class for all modeling objects.

public abstract class ModelElement
Inheritance
ModelElement
Derived
Inherited Members

Remarks

The base class for all modeling objects.

Example:

var model = new Model();
var x = model.IntervalVar(length: 10, name: "x");
var start = model.Start(x);
var result = 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.

Properties

Name

The name assigned to this model element.

public string? Name { get; set; }

Property Value

string

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:

var model = new Model();

// Name a variable at creation var task = model.IntervalVar(length: 10, name: "assembly");

// Or set name later var x = model.IntVar(min: 0, max: 100); x.Name = "quantity";

Console.WriteLine(task.Name); // "assembly" Console.WriteLine(x.Name); // "quantity"