LowerConstraintStatus: TargetConstraintStatusType;
LowerConstraintStatus: Prognoz.Platform.Interop.Cp.TargetConstraintStatusType;
The LowerConstraintStatus property returns status of lower constraint limit.
The value is available after criterion function calculation. To get upper constraint limit state, use the IMsTargetConstraintCommon.UpperBoundFixed property.
Executing the example requires that the repository contains a modeling container with the MS identifier containing a configured criterion problem with the TARGETPROBLEM identifier.
Add links to the Cp, Metabase, Ms system assemblies.
Sub UserProc;
Var
mb: IMetabase;
MsObj: IMetabaseObject;
Ms: IMsModelSpace;
Problem: IMsProblem;
TargetProblem: IMsTargetProblem;
i, j: Integer;
CalcSettings: IMsProblemCalculationSettings;
Calc: IMsProblemCalculation;
targetConstraints: IMsTargetConstraints;
targetConstr: IMsTargetConstraint;
targetConstrArray: IMsTargetConstraintInfoArray;
targetConstrInfo: IMsTargetConstraintInfo;
controlVariables: IMsFormulaTermList;
controlTerm: IMsTargetFormulaTerm;
varConstraints: IMsTargetVarConstraints;
varConstr: IMsTargetVarConstraint;
Begin
// Get current repository
mb := MetabaseClass.Active;
// Get modeling container
MsObj := mb.ItemById("MS").Bind;
Ms := MsObj As IMsModelSpace;
// Get criterion problem
Problem := mb.ItemByIdNamespace("TARGETPROBLEM", MsObj.Key).Bind As IMsProblem;
TargetProblem := Problem.AdditionalDetails.Item(0) As IMsTargetProblem;
// Create problem calculation settings
CalcSettings := Problem.CreateCalculationSettings;
// Create a problem calculation object
Calc := Problem.Calculate(CalcSettings);
// Perform calculation
Calc.Run;
// Get calculated problem and display result in the console window
TargetProblem := (Problem.AdditionalDetails.Item(0) As IMsTargetProblem);
// Get criterion function constraints
targetConstraints := targetProblem.Constraints;
// Go through all criterion function constraints
For i := 0 To targetConstraints.Count - 1 Do
targetConstr := targetConstraints.Item(i);
Debug.WriteLine("Criterion function constraint: " + (i + 1).ToString);
// Get criterion function constraint values and display them in the console window
targetConstrArray := targetConstr.ConstraintInfoArray;
Debug.Indent;
Debug.WriteLine("Value corresponding to optimal solution");
Debug.Indent;
For j := 0 To targetConstrArray.Count - 1 Do
targetConstrInfo := targetConstrArray.Item(j);
Debug.WriteLine(targetConstrInfo.OptimalValue);
End For;
Debug.Unindent;
Debug.WriteLine("Lower limit values; State");
Debug.Indent;
For j := 0 To targetConstrArray.Count - 1 Do
targetConstrInfo := targetConstrArray.Item(j);
Debug.Write(targetConstrInfo.LowerBound.ToString + "; " + #9);
Debug.WriteLine(StatusToStr(targetConstrInfo.LowerConstraintStatus));
End For;
Debug.Unindent;
Debug.WriteLine("Lagrange multiplier values for lower limit");
Debug.Indent;
For j := 0 To targetConstrArray.Count - 1 Do
targetConstrInfo := targetConstrArray.Item(j);
Debug.WriteLine(targetConstrInfo.LowerBoundLagrangeMultiplier);
End For;
Debug.Unindent;
Debug.WriteLine("Upper limit values; State");
Debug.Indent;
For j := 0 To targetConstrArray.Count - 1 Do
targetConstrInfo := targetConstrArray.Item(j);
Debug.Write(targetConstrInfo.UpperBound.ToString + "; " + #9);
Debug.WriteLine(StatusToStr(targetConstrInfo.UpperConstraintStatus));
End For;
Debug.Unindent;
Debug.WriteLine("Lagrange multiplier values for upper limit");
Debug.Indent;
For j := 0 To targetConstrArray.Count - 1 Do
targetConstrInfo := targetConstrArray.Item(j);
Debug.WriteLine(targetConstrInfo.UpperBoundLagrangeMultiplier);
End For;
Debug.Unindent;
Debug.Unindent;
End For;
// Get controlling variables
controlVariables := TargetProblem.ControlVariables;
// Go through controlling variables
For i := 0 To controlVariables.Count - 1 Do
controlTerm := controlVariables.Item(i) As IMsTargetFormulaTerm;
Debug.WriteLine("Controlling variable: " + controlTerm.TermToText);
Debug.Indent;
// Get controlling variable constraints and display them in the console window
varConstraints := controlTerm.VarConstraints;
Debug.WriteLine("Lower limit values; State");
Debug.Indent;
For j := 0 To varConstraints.Count - 1 do
varConstr := varConstraints.Item(j);
Debug.Write(varConstr.LowerBound.ToString + "; " + #9);
Debug.WriteLine(StatusToStr(varConstr.LowerConstraintStatus));
End For;
Debug.Unindent;
Debug.WriteLine("Upper limit values; State");
Debug.Indent;
For j := 0 To varConstraints.Count - 1 do
varConstr := varConstraints.Item(j);
Debug.Write(varConstr.UpperBound.ToString + "; " + #9);
Debug.WriteLine(StatusToStr(varConstr.UpperConstraintStatus));
End For;
Debug.Unindent;
Debug.Unindent;
End For;
End Sub UserProc;
// State display function
Function StatusToStr(Status: TargetConstraintStatusType): String;
Var
s: String;
Begin
Select Case Status
Case TargetConstraintStatusType.Disabled: s := "Disabled";
Case TargetConstraintStatusType.NotReached: s := "Not reached";
Case TargetConstraintStatusType.Reached: s := "Reached";
End Select;
Return s;
End Function StatusToStr;
After executing the example the console window displays calculation results for criterion problem constraints.
The requirements and result of the Fore.NET example execution match with those in the Fore example.
Imports Prognoz.Platform.Interop.Cp;
Imports Prognoz.Platform.Interop.Ms;
…
Public Shared Sub Main(Params: StartParams);
Var
mb: IMetabase;
MsObj: IMetabaseObject;
Ms: IMsModelSpace;
Problem: IMsProblem;
TargetProblem: IMsTargetProblem;
i, j: Integer;
CalcSettings: IMsProblemCalculationSettings;
Calc: IMsProblemCalculation;
targetConstraints: IMsTargetConstraints;
targetConstr: IMsTargetConstraint;
targetConstrArray: IMsTargetConstraintInfoArray;
targetConstrInfo: IMsTargetConstraintInfo;
controlVariables: IMsFormulaTermList;
controlTerm: IMsTargetFormulaTerm;
varConstraints: IMsTargetVarConstraints;
varConstr: IMsTargetVarConstraint;
Begin
// Get current repository
mb := Params.Metabase;
// Get modeling container
MsObj := mb.ItemById["MS"].Bind();
Ms := MsObj As IMsModelSpace;
// Get criterion problem
Problem := mb.ItemByIdNamespace["TARGETPROBLEM", MsObj.Key].Bind() As IMsProblem;
TargetProblem := Problem.AdditionalDetails.Item[0] As IMsTargetProblem;
// Create problem calculation settings
CalcSettings := Problem.CreateCalculationSettings();
// Create a problem calculation object
Calc := Problem.Calculate(CalcSettings);
// Perform calculation
Calc.Run();
// Get calculated problem and display result in the console window
TargetProblem := (Problem.AdditionalDetails.Item[0] As IMsTargetProblem);
// Get criterion function constraints
targetConstraints := targetProblem.Constraints;
// Go through all criterion function constraints
For i := 0 To targetConstraints.Count - 1 Do
targetConstr := targetConstraints.Item[i];
System.Diagnostics.Debug.WriteLine("Criterion function constraint: " + (i + 1).ToString());
// Get criterion function constraint values and display them in the console window
targetConstrArray := targetConstr.ConstraintInfoArray;
System.Diagnostics.Debug.Indent();
System.Diagnostics.Debug.WriteLine("Value corresponding to optimal solution");
System.Diagnostics.Debug.Indent();
For j := 0 To targetConstrArray.Count - 1 Do
targetConstrInfo := targetConstrArray.Item[j];
System.Diagnostics.Debug.WriteLine(targetConstrInfo.OptimalValue);
End For;
System.Diagnostics.Debug.Unindent();
System.Diagnostics.Debug.WriteLine("Lower limit values; State");
System.Diagnostics.Debug.Indent();
For j := 0 To targetConstrArray.Count - 1 Do
targetConstrInfo := targetConstrArray.Item[j];
System.Diagnostics.Debug.Write(targetConstrInfo.LowerBound.ToString() + "; " + char.ConvertFromUtf32(9));
System.Diagnostics.Debug.WriteLine(StatusToStr(targetConstrInfo.LowerConstraintStatus));
End For;
System.Diagnostics.Debug.Unindent();
System.Diagnostics.Debug.WriteLine("Lagrange multiplier values for lower limit");
System.Diagnostics.Debug.Indent();
For j := 0 To targetConstrArray.Count - 1 Do
targetConstrInfo := targetConstrArray.Item[j];
System.Diagnostics.Debug.WriteLine(targetConstrInfo.LowerBoundLagrangeMultiplier);
End For;
System.Diagnostics.Debug.Unindent();
System.Diagnostics.Debug.WriteLine("Upper limit values; State");
System.Diagnostics.Debug.Indent();
For j := 0 To targetConstrArray.Count - 1 Do
targetConstrInfo := targetConstrArray.Item[j];
System.Diagnostics.Debug.Write(targetConstrInfo.UpperBound.ToString() + "; " + char.ConvertFromUtf32(9));
System.Diagnostics.Debug.WriteLine(StatusToStr(targetConstrInfo.UpperConstraintStatus));
End For;
System.Diagnostics.Debug.Unindent();
System.Diagnostics.Debug.WriteLine("Lagrange multiplier values for upper limit");
System.Diagnostics.Debug.Indent();
For j := 0 To targetConstrArray.Count - 1 Do
targetConstrInfo := targetConstrArray.Item[j];
System.Diagnostics.Debug.WriteLine(targetConstrInfo.UpperBoundLagrangeMultiplier);
End For;
System.Diagnostics.Debug.Unindent();
System.Diagnostics.Debug.Unindent();
End For;
// Get controlling variables
controlVariables := TargetProblem.ControlVariables;
// Go through controlling variables
For i := 0 To controlVariables.Count - 1 Do
controlTerm := controlVariables.Item[i] As IMsTargetFormulaTerm;
System.Diagnostics.Debug.WriteLine("Controlling variable: " + controlTerm.TermToText());
System.Diagnostics.Debug.Indent();
// Get controlling variable constraints and display them in the console window
varConstraints := controlTerm.VarConstraints;
System.Diagnostics.Debug.WriteLine("Lower limit values; State");
System.Diagnostics.Debug.Indent();
For j := 0 To varConstraints.Count - 1 do
varConstr := varConstraints.Item[j];
System.Diagnostics.Debug.Write(varConstr.LowerBound.ToString() + "; " + char.ConvertFromUtf32(9));
System.Diagnostics.Debug.WriteLine(StatusToStr(varConstr.LowerConstraintStatus));
End For;
System.Diagnostics.Debug.Unindent();
System.Diagnostics.Debug.WriteLine("Upper limit values; State");
System.Diagnostics.Debug.Indent();
For j := 0 To varConstraints.Count - 1 Do
varConstr := varConstraints.Item[j];
System.Diagnostics.Debug.Write(varConstr.UpperBound.ToString() + "; " + char.ConvertFromUtf32(9));
System.Diagnostics.Debug.WriteLine(StatusToStr(varConstr.UpperConstraintStatus));
End For;
System.Diagnostics.Debug.Unindent();
System.Diagnostics.Debug.Unindent();
End For;
End Sub;
// State display function
Public Shared Function StatusToStr(Status: TargetConstraintStatusType): String;
Var
s: String;
Begin
Select Case Status
Case TargetConstraintStatusType.tcstDisabled: s := "Disabled";
Case TargetConstraintStatusType.tcstNotReached: s := "Not reached";
Case TargetConstraintStatusType.tcstReached: s := "Reached";
End Select;
Return s;
End Function StatusToStr;