IMsNonLinearConstraints.Add

Syntax

Add: IMsNonLinearConstraint;

Description

The Add method adds a new constraint.

Example

Executing the example requires that the container includes an optimal control problem.

Sub Main;

Var

MB: IMetabase;

MObj: IMetabaseObject;

Problem: IMsProblem;

ControlProblem: IMsControlProblem;

Transform: IMsFormulaTransform;

Term1: IMsFormulaTerm;

TrVar: IMsFormulaTransformVariable;

Slice: IMsFormulaTransformSlice;

Constrs: IMsNonLinearConstraints;

Constr: IMsNonLinearConstraint;

Begin

MB := MetabaseClass.Active;

MObj := MB.ItemByIdNamespace("New_ControlProblem", MB.ItemById("KONT_MODEL").Key).Edit;

Problem := MObj As IMsProblem;

ControlProblem := Problem.Details As IMsControlProblem;

Transform := ControlProblem.Model.Transform;

Constrs := ControlProblem.Constraints;

Constr := Constrs.Add;

TrVar := Transform.Inputs.Item(0);

Slice := TrVar.Slices.Item(0);

Term1 := Constr.Operands.Add(Slice);

Constr.Expression.AsString := Term1.TermToInnerText;

Constr.LowerBound.AsString := "-150";

Constr.UpperBound.AsString := "150";

MObj.Save;

End Sub Main;

After executing the example a new constraint is added to the problem.

See also:

IMsNonLinearConstraints