Id: String;
The property is read-only.
The Id property returns variable identifier.
Sub Main;
Var
ZCU: LinearOptimization;
Vrbl: ILoVariable; //variable
Constr: ILoConstraint; //constraint
Addend: ILoAddend; //summand
Eq: ILoEquation; //equation
VarS: ILoVariables; //list of variables
ConstrS: ILoConstraints; //list of constraints
AddendS: ILoAddends; //list of summands
EqS: ILoEquations; //list of equations
ObjFun: ILoCriterionFunction; //criterion function
Res: ILoResults;
Retro: Array[1] Of Double;
I, J: Integer;
s: String;
Val: Double;
ci: ICultureInfo;
TimeInterval: Integer;
Begin
ZCU := New LinearOptimization.Create;
// VARIABLES
Retro := New Double[1];
Retro[0] := 1;
Vars := ZCU.Variables;
For I := 1 To 6 Do
s := "x" + i.ToString;
Vrbl := Vars.Add(s);
Vrbl.Retrospective := Retro;
End For;
//Constraints
ConstrS := ZCU.Constraints;
//====x1
For i := 1 To 6 Do
Constr := ConstrS.Add;
Constr.LowerBound := 0;
Constr.UpperBound := 1e20;
AddendS := Constr.Addends;
Addend := AddendS.Add(Vars.FindById("x1"));
Addend.Coeff := 1; //variable held constant
Addend.Lag := i; //
End For;
Constr := ConstrS.Add;
Constr.LowerBound := 2;
Constr.UpperBound := 1e20;
AddendS := Constr.Addends;
Addend := AddendS.Add(Vars.FindById("x1"));
Addend.Coeff := 1; //variable held constant
Addend.Lag := 7; //
//====x2
For i := 1 To 6 Do
Constr := ConstrS.Add;
Constr.LowerBound := 0;
Constr.UpperBound := 1e20;
AddendS := Constr.Addends;
Addend := AddendS.Add(Vars.FindById("x2"));
Addend.Coeff := 1; //variable held constant
Addend.Lag := i; //
End For;
Constr := ConstrS.Add;
Constr.LowerBound := 2;
Constr.UpperBound := 1e20;
AddendS := Constr.Addends;
Addend := AddendS.Add(Vars.FindById("x2"));
Addend.Coeff := 1; //variable held constant
Addend.Lag := 7; //
//====x3
For i := 1 To 6 Do
Constr := ConstrS.Add;
Constr.LowerBound := 0;
Constr.UpperBound := 1e20;
AddendS := Constr.Addends;
Addend := AddendS.Add(Vars.FindById("x3"));
Addend.Coeff := 1; //variable held constant
Addend.Lag := i; //
End For;
Constr := ConstrS.Add;
Constr.LowerBound := 2;
Constr.UpperBound := 1e20;
AddendS := Constr.Addends;
Addend := AddendS.Add(Vars.FindById("x3"));
Addend.Coeff := 1; //variable held constant
Addend.Lag := 7; //
//====x4
For i := 1 To 7 Do
Constr := ConstrS.Add;
Constr.LowerBound := 0;
Constr.UpperBound := 1e20;
AddendS := Constr.Addends;
Addend := AddendS.Add(Vars.FindById("x4"));
Addend.Coeff := 1; //variable held constant
Addend.Lag := i; //
End For;
//====x5
For i := 1 To 7 Do
Constr := ConstrS.Add;
Constr.LowerBound := 0;
Constr.UpperBound := 1e20;
AddendS := Constr.Addends;
Addend := AddendS.Add(Vars.FindById("x5"));
Addend.Coeff := 1; //variable held constant
Addend.Lag := i; //
End For;
//====x6
For i := 1 To 7 Do
Constr := ConstrS.Add;
Constr.LowerBound := 0;
Constr.UpperBound := 1e20;
AddendS := Constr.Addends;
Addend := AddendS.Add(Vars.FindById("x6"));
Addend.Coeff := 1; //variable held constant
Addend.Lag := i; //
End For;
//EQUATIONS
EqS := ZCU.Equations;
// EQUATION #1
Eq := EqS.Add;
AddendS := Eq.Addends;
Addend := Addends.Add(Vars.FindById("x1")); //left part
Addend.Coeff := 1; //variable held constant
Addend.Lag := 0; //lag
Addend := Addends.Add(Vars.FindById("x1")); //1st summand
Addend.Coeff := 0.5; //variable held constant
Addend.Lag := 1; //lag
Addend := Addends.Add(Vars.FindById("x2")); //2nd summand
Addend.Coeff := -0.3; //variable held constant
Addend.Lag := 1; //lag
Addend := Addends.Add(Vars.FindById("x3")); //3rd summand
Addend.Coeff := 0.1; //variable held constant
Addend.Lag := 1; //lag
Addend := Addends.Add(Vars.FindById("x4")); //4th summand
Addend.Coeff := 1; //variable held constant
Addend.Lag := 1; //lag
// EQUATION #2
Eq := EqS.Add;
AddendS := Eq.Addends;
Addend := Addends.Add(Vars.FindById("x2")); //left part
Addend.Coeff := 1; //variable held constant
Addend.Lag := 0; //lag
Addend := Addends.Add(Vars.FindById("x1")); //1st summand
Addend.Coeff := -0.2; //variable held constant
Addend.Lag := 1; //lag
Addend := Addends.Add(Vars.FindById("x2")); //2nd summand
Addend.Coeff := 0.1; //variable held constant
Addend.Lag := 1; //lag
Addend := Addends.Add(Vars.FindById("x5")); //3rd summand
Addend.Coeff := 1; //0.1;//variable held constant
Addend.Lag := 1; //lag
// EQUATION #3
Eq := EqS.Add;
AddendS := Eq.Addends;
Addend := Addends.Add(Vars.FindById("x3")); //left part
Addend.Coeff := 1; //variable held constant
Addend.Lag := 0; //lag
Addend := Addends.Add(Vars.FindById("x3")); //1st summand
Addend.Coeff := 0.1; //variable held constant
Addend.Lag := 1; //lag
Addend := Addends.Add(Vars.FindById("x6")); //2nd summand
Addend.Coeff := 1; //variable held constant
Addend.Lag := 1; //lag
// CRITERION FUNCTION
ObjFun := ZCU.CriterionFunction;
//=== x4
For i := 1 To 7 Do
Addend := ObjFun.Addends.Add(Vars.FindById("x4"));
Addend.Coeff := 1;
Addend.Lag := 7 - i;
End For;
//=== x5
For i := 1 To 7 Do
Addend := ObjFun.Addends.Add(Vars.FindById("x5"));
Addend.Coeff := 1;
Addend.Lag := 7 - i;
End For;
//=== x6
For i := 1 To 7 Do
Addend := ObjFun.Addends.Add(Vars.FindById("x6"));
Addend.Coeff := 1;
Addend.Lag := 7 - i;
End For;
TimeInterval := 7;
ZCU.Extremum := ExtremumType.Minimum;
Res := ZCU.Evaluate(TimeInterval) As ILoResults;
s := "Optimal value: " + Res.OptimalValue.ToString;
Debug.WriteLine(s);
s := Res.ErrorMsg + " (Code: " + Res.Status.ToString + ")";
Debug.WriteLine(s);
s := " ";
For j := 1 To Vars.Count Do
Vrbl := Vars.Item(j - 1);
s := s + Vrbl.Id + ", ";
End For;
Debug.WriteLine(s);
ci := CultureInfo.Current;
For i := 1 To TimeInterval Do
s := "t=" + i.ToString + ", ";
For j := 1 To Vars.Count Do
Vrbl := Vars.Item(j - 1);
Val := Res.VarValues(Vrbl.Id)[i - 1];
s := s + ci.FormatDoublePrec(Val, 6) + ", ";
End For;
Debug.WriteLine(s);
End For;
End Sub Main;
After executing the example the console window displays calculation results.
See also: