INonLinearConstraints.Add

Syntax

Add: INonLinearConstraint;

Description

The Add method adds a nonlinear constraint to the collection.

Example

Sub Main;

Var

nlo: ISmNonLinearOptimization;

lb,ub: Array[0..3] Of Double;

init: Array[0..3] Of Double;

LinConCfs: Array[0..3] Of Double;

LinCons: ISlLinearConstraints;

LinCon: ISlLinearConstraint;

NonLinCons: INonLinearConstraints;

NonLinCon: INonLinearConstraint;

i,res: Integer;

OptVal: Double;

Sub Print(Data: Array Of Double);

Var

i: Integer;

CI: ICultureInfo;

Begin

CI := CultureInfo.Current;

Debug.WriteLine("---Begin---");

For i := 0 To Data.Length - 1 Do

If Double.IsNan(Data[i]) Then

Debug.WriteLine("---empty---");

Else

Debug.WriteLine(i.ToString + ", " + CI.FormatDoublePrec(Data[i], 4));

End If;

End For;

Debug.WriteLine("---End---");

End Sub Print;

Begin

nlo := New SmNonLinearOptimization.Create;

For i := 0 To 3 Do

lb[i] := 1;

ub[i] := 5;

LinConCfs[i] := 1;

End For;

nlo.Boundary.BoundaryLower := lb;

nlo.Boundary.BoundaryUpper := ub;

nlo.CoefficientsOrder := "x1;x2;x3;x4";

nlo.FunctionString := "x1*x4*(x1+x2+x3)+x3";

init[0] := 1;

init[1] := 5;

init[2] := 5;

init[3] := 1;

nlo.InitApproximation := init;

LinCons := nlo.LinearConstraints;

LinCon := LinCons.Add;

LinCon.BoundaryLower := -10e20;

LinCon.BoundaryUpper := 20;

LinConCfs[0] := 1;

LinConCfs[1] := 1;

LinConCfs[2] := 1;

LinConCfs[3] := 1;

LinCon.Value := LinConCfs;

nlo.MaxIteration := 75;

NonLinCons := nlo.NonLinearConstraints;

NonLinCon := NonLinCons.Add;

NonLinCon.BoundaryLower := -10e20;

NonLinCon.BoundaryUpper := 40;

NonLinCon.NonLinearFunction := "x1*x1+x2*x2+x3*x3+x4*x4";

NonLinCon := NonLinCons.Add;

NonLinCon.BoundaryLower := 25;

NonLinCon.BoundaryUpper := 10e21;

NonLinCon.NonLinearFunction := "x1*x2*x3*x4";

res := nlo.Execute;

If res<>0 Then

Debug.WriteLine(nlo.Errors);

Else

Debug.WriteLine("== Criterion function value ==");

OptVal := nlo.OptimalFunctionValue;

Debug.WriteLine(OptVal.ToString);

Debug.WriteLine("=== Solution ===");

Print(nlo.Solution);

Debug.WriteLine("=== Criterion function gradient ===");

Print(nlo.FunctionGradient);

End If;

End Sub Main;

Executing this example shows the calculation results in the console window:

Module execution started

== Criterion function value ==

17.014017289134742

=== Solution ===

---Begin---

0, 1.0000

1, 4.7430

2, 3.8211

3, 1.3794

---End---

=== Criterion function gradient ===

---Begin---

0, 14.5723

1, 1.3794

2, 2.3794

3, 9.5641

---End---

Module execution finished

See also:

INonLinearConstraints