lazhen
2025-01-07 b3987122cbbc46c5c59d3173f37fca3170b6dc5a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
Quintiq file version 2.0
#parent: #root
Method UpdateStatistics (
  MathematicalProgram program,
  Boolean isautoscalingenabled
)
{
  Description: 'Writes attributes related to numerical statistics. This should be done after optimizer run finished for current level.'
  TextBody:
  [*
    statistics := program.Statistics();
    
    //result side
    this.Kappa( statistics.Kappa() );
    this.Remark( program.Remark() );
    this.PrimalInfeasibility( statistics.MaxPrimalInfeasibility() );
    this.DualInfeasibility( statistics.MaxDualInfeasibility() );
    this.PrimalResidual( statistics.MaxPrimalResidual() );
    this.DualResidual( statistics.MaxDualResidual() );
    
    //definition side
    this.MinCoefficient( statistics.MinimumConstraintNonZero() );
    this.MaxCoefficient( statistics.MaximumConstraintNonZero() );
    this.MinGoalCoefficient( statistics.MinimumObjectiveNonZero() );
    this.MaxGoalCoefficient( statistics.MaximumObjectiveNonZero() );
    this.MinRHS( statistics.MinimumRHSNonZero() );
    this.MaxCoefficientRatio( statistics.MaximumCoefficientRatio() );
    
    if( this.MinRHS().IsInfinite() ) //prevent MaxReal from appearing
    {
      this.MinRHS( 0.0 );
    }
    this.MaxRHS( statistics.MaximumRHSNonZero() );
    
    // To improve the performance, the min/max variable value statistics are only updated in autoscaling runs
    if( isautoscalingenabled )
    {
      sets := selectvalues( program, Variables, var, var.Enabled() and guard( var.OptimalValue() <> 0, false ), abs ( var.OptimalValue() ) ); 
      sets := sets.Sort();
      if(  sets.Size() > 0 )
      {  
        this.MinVariableValue( sets.Element( 0 ) );
        this.MaxVariableValue( sets.Element( sets.Size() - 1 ) );
      }
    }
  *]
}