ExtraSettings: IQPExtraSettings;
The ExtraSettings property returns additional settings used on calculation by means of Gurobi external solver.
The property is relevant if Gurobi solver is selected in the SolverType property.
Executing an example requires the Gurobi external solver installed on the user computer.
Add a link to the Stat system assembly.
Sub UserProc;
Var
QP: SmQuadraticProgramming;
i, j, Res, N: Integer;
Time: Double;
CF, Lb, Ub, Init, LinC1, H: Array Of Double;
Bound: ISlBoundaryRegion;
LCon1: ISlLinearConstraint;
Begin
QP := New SmQuadraticProgramming.Create;
N := 8;
CF := New Double[N];
Lb := New Double[N];
Ub := New Double[N];
LinC1 := New Double[N];
Init := New Double[N];
// Domain of definition
Lb[0] := -1; Ub[0] := 1;
Lb[1] := -2.1; Ub[1] := 2;
Lb[2] := -3.2; Ub[2] := 3;
Lb[3] := -4.3; Ub[3] := 4;
Lb[4] := -5.4; Ub[4] := 5;
Lb[5] := -6.5; Ub[5] := 6;
Lb[6] := -7.6; Ub[6] := 7;
Lb[7] := -8.7; Ub[7] := 8;
// Initial approximations
Init[0] := -1;
Init[1] := -2;
Init[2] := -3;
Init[3] := -4;
Init[4] := -5;
Init[5] := -6;
Init[6] := -7;
Init[7] := -8;
QP.InitialApproximation.AutoCreate := False;
QP.InitialApproximation.InitValues := Init;
//Criterion function
CF[0] := 7;
CF[1] := 6;
CF[2] := 5;
CF[3] := 4;
CF[4] := 3;
CF[5] := 2;
CF[6] := 1;
CF[7] := 0;
H := New Double[N, N];
H[0, 0] := 1.69; H[0, 1] := 1.00; H[0, 2] := 2.00; H[0, 3] := 3.00; H[0, 4] := 4.00; H[0, 5] := 5.00; H[0, 6] := 6.00; H[0, 7] := 7.00;
H[1, 0] := 1.00; H[1, 1] := 1.69; H[1, 2] := 1.00; H[1, 3] := 2.00; H[1, 4] := 3.00; H[1, 5] := 4.00; H[1, 6] := 5.00; H[1, 7] := 6.00;
H[2, 0] := 2.00; H[2, 1] := 1.00; H[2, 2] := 1.69; H[2, 3] := 1.00; H[2, 4] := 2.00; H[2, 5] := 3.00; H[2, 6] := 4.00; H[2, 7] := 5.00;
H[3, 0] := 3.00; H[3, 1] := 2.00; H[3, 2] := 1.00; H[3, 3] := 1.69; H[3, 4] := 1.00; H[3, 5] := 2.00; H[3, 6] := 3.00; H[3, 7] := 4.00;
H[4, 0] := 4.00; H[4, 1] := 3.00; H[4, 2] := 2.00; H[4, 3] := 1.00; H[4, 4] := 1.69; H[4, 5] := 1.00; H[4, 6] := 2.00; H[4, 7] := 3.00;
H[5, 0] := 5.00; H[5, 1] := 4.00; H[5, 2] := 3.00; H[5, 3] := 2.00; H[5, 4] := 1.00; H[5, 5] := 1.69; H[5, 6] := 1.00; H[5, 7] := 2.00;
H[6, 0] := 6.00; H[6, 1] := 5.00; H[6, 2] := 4.00; H[6, 3] := 3.00; H[6, 4] := 2.00; H[6, 5] := 1.00; H[6, 6] := 1.69; H[6, 7] := 1.00;
H[7, 0] := 7.00; H[7, 1] := 6.00; H[7, 2] := 5.00; H[7, 3] := 4.00; H[7, 4] := 3.00; H[7, 5] := 2.00; H[7, 6] := 1.00; H[7, 7] := 1.69;
For i := 0 To N - 1 Do
For j := 0 To N - 1 Do
If i <> j Then
H[i, j] := 0;
H[j, i] := 0;
End If;
End For;
End For;
//Criterion function
QP.CriterionFunction := CF;
QP.QuadraticForm := H;
Bound := QP.Boundary;
Bound.BoundaryLower := Lb; //Lower area limit
Bound.BoundaryUpper := Ub; //Upper area limit
LCon1 := QP.LinearConstraints.Add;
LinC1[0] := -1; LinC1[1] := 1;
LCon1.Value := LinC1; // Linear constraint coefficient
LCon1.BoundaryLower := -1.00; // Lower linear constraint
LCon1.BoundaryUpper := Double.PositiveInfinity; //Upper linear constraint
LinC1[0] := 0; LinC1[1] := 0;
LCon1 := QP.LinearConstraints.Add;
LinC1[1] := -1; LinC1[2] := 1;
LCon1.Value := LinC1; // Linear constraint coefficient
LCon1.BoundaryLower := -1.05; // Lower linear constraint
LCon1.BoundaryUpper := Double.PositiveInfinity; // Upper linear constraint
LinC1[1] := 0; LinC1[2] := 0;
LCon1 := QP.LinearConstraints.Add;
LinC1[2] := -1; LinC1[3] := 1;
LCon1.Value := LinC1; // Linear constraint coefficient
LCon1.BoundaryLower := -1.10; // Lower linear constraint
LCon1.BoundaryUpper := Double.PositiveInfinity; // Upper linear constraint
LinC1[2] := 0; LinC1[3] := 0;
LCon1 := QP.LinearConstraints.Add;
LinC1[3] := -1; LinC1[4] := 1;
LCon1.Value := LinC1; // Linear constraint coefficient
LCon1.BoundaryLower := -1.15; // Lower linear constraint
LCon1.BoundaryUpper := Double.PositiveInfinity; // Upper linear constraint
LinC1[3] := 0; LinC1[4] := 0;
LCon1 := QP.LinearConstraints.Add;
LinC1[4] := -1; LinC1[5] := 1;
LCon1.Value := LinC1; // Linear constraint coefficient
LCon1.BoundaryLower := -1.2; // Lower linear constraint
LCon1.BoundaryUpper := Double.PositiveInfinity; // Upper linear constraint
LinC1[4] := 0; LinC1[5] := 0;
LCon1 := QP.LinearConstraints.Add;
LinC1[5] := -1; LinC1[6] := 1;
LCon1.Value := LinC1; // Linear constraint coefficient
LCon1.BoundaryLower := -1.25; // Lower linear constraint
LCon1.BoundaryUpper := Double.PositiveInfinity; // Upper linear constraint
LinC1[5] := 0; LinC1[6] := 0;
LCon1 := QP.LinearConstraints.Add;
LinC1[6] := -1; LinC1[7] := 1;
LCon1.Value := LinC1; // Linear constraint coefficient
LCon1.BoundaryLower := -1.<font color="#008000">30</font><font color="#000000">; </font><font color="#008000">// Lower linear constraint<br/> </font><font color="#000000"> LCon1.BoundaryUpper := Double.PositiveInfinity; </font><font color="#008000">// Upper linear constraint<br/> </font><font color="#000000"> LinC1[</font><font color="#008000">6</font><font color="#000000">] := </font><font color="#008000">0</font><font color="#000000">; LinC1[</font><font color="#008000">7</font><font color="#000000">] := </font><font color="#008000">0</font><font color="#000000">;<br/> </font><font color="#008000">// Use Gurobi<br/> </font><font color="#000000"> QP.SolverType := QPSolverType.Grb;<br/> QP.ExtraSettings.DLLPath := </font><font color="#800000">"c:\gurobi752\win64\bin\gurobi75.dll"</font><font color="#000000">;<br/> QP.ExtraSettings.SaveLogToFilePath := </font><font color="#800000">"c:\Files\Gurobi.log"</font><font color="#000000">;<br/> QP.ExtraSettings.SaveModelToFilePath := </font><font color="#800000">"c:\Files\Model.mps"</font><font color="#000000">;<br/> </font><font color="#008000">// Execute calculation<br/> </font><font color="#000000"> Res := QP.Execute;<br/> Time := QP.PerformanceTime / </font><font color="#008000">1000</font><font color="#000000">;<br/> Debug.WriteLine(</font><font color="#800000">"Time[sec] = "</font><font color="#000000"> + time.ToString);<br/> Debug.WriteLine(</font><font color="#800000">"RES = "</font><font color="#000000"> + Res.ToString);<br/> Debug.WriteLine(QP.Errors);<br/> Debug.WriteLine(</font><font color="#800000">"Gurobi error code = "</font><font color="#000000"> + QP.ExtraSettings.nErrorCode.ToString);<br/> Debug.WriteLine(</font><font color="#800000">"Gurobi message = "</font><font color="#000000"> + QP.ExtraSettings.MessageString);<br/> </font><font color="#008080">If</font><font color="#000000"> Res = </font><font color="#008000">0</font><font color="#000000"> </font><font color="#008080">Then</font><font color="#000000"><br/> Debug.WriteLine(</font><font color="#800000">"== Criterion function value =="</font><font color="#000000">);<br/> Debug.WriteLine(QP.OptimalFunctionValue.ToString);<br/> Debug.WriteLine(</font><font color="#800000">"== Solution =="</font><font color="#000000">);<br/> Debug.Indent;<br/> </font><font color="#008080">For</font><font color="#000000"> i := </font><font color="#008000">0</font><font color="#000000"> </font><font color="#008080">To</font><font color="#000000"> QP.Solution.Length - </font><font color="#008000">1</font><font color="#000000"> </font><font color="#008080">Do</font><font color="#000000"><br/> Debug.WriteLine(i.ToString + </font><font color="#800000">": "</font><font color="#000000"> + lb[i].ToString + </font><font color="#800000">" <= "</font><font color="#000000"> + QP.Solution[i].ToString + </font><font color="#800000">" <= "</font><font color="#000000"> + ub[i].ToString);<br/> </font><font color="#008080">End</font><font color="#000000"> </font><font color="#008080">For</font><font color="#000000">;<br/> Debug.Unindent;<br/> Debug.WriteLine(</font><font color="#800000">"== Linear constraints =="</font><font color="#000000">);<br/> Debug.Indent;<br/> </font><font color="#008080">For</font><font color="#000000"> i := </font><font color="#008000">0</font><font color="#000000"> </font><font color="#008080">To</font><font color="#000000"> QP.LinearConstraints.Count - </font><font color="#008000">1</font><font color="#000000"> </font><font color="#008080">Do</font><font color="#000000"><br/> LCon1 := QP.LinearConstraints.Item(i);<br/> Debug.WriteLine(i.ToString + </font><font color="#800000">": "</font><font color="#000000"> + LCon1.BoundaryLower.ToString + </font><font color="#800000">" <= "</font><font color="#000000"> + LCon1.Result.ToString + </font><font color="#800000">" <= "</font><font color="#000000"> + LCon1.BoundaryUpper.ToString);<br/> </font><font color="#008080">End</font><font color="#000000"> </font><font color="#008080">For</font><font color="#000000">;<br/> Debug.Unindent;<br/> </font><font color="#008080">End</font><font color="#000000"> </font><font color="#008080">If</font><font color="#000000">;<br/> </font><font color="#008080">End</font><font color="#000000"> </font><font color="#008080">Sub</font><font color="#000000"> UserProc;</font>
On executing the example, the quadratic programming task will be calculated using the Gurobi external solver. The development environment console displays the following:
Possible error code and message generated by the Gurobi solver.
Criterion function value
Found solutions.
Linear constraints.
Report about calculation and the model are saved to the specified files.
See also: