yanweiyuan3
2023-08-09 588bc7829387dfc761cc25f06f77d4c81818bd10
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
48
49
50
51
52
53
54
55
56
57
58
59
60
Quintiq file version 2.0
#parent: #root
Method InitConstraintsGoalsForDriverOneTime (
  CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm program,
  const RunContextForCapacityPlanning runcontext,
  const LibOpt_Scope scope
) const
{
  Description: 'Init constraints goals for account depends on one time cost'
  TextBody:
  [*
    // One time cost accounts
    
    
    ptisused_varname := typeof( MPPTIsUsedVariable );
    driveronetime_varname := typeof( MPDriverOneTimeVariable );
    driveronetime_constname := typeof( MPDriverOneTimeConstraint );
    
    scalefactor_driver_dconst := this.ScaleConstraintTerm( driveronetime_varname, driveronetime_constname );
    scalefactor_ptisused_dconst := this.ScaleConstraintTerm( ptisused_varname, driveronetime_constname );
    
    scalefactor_rhs_dconst := this.ScaleConstraintRHS( driveronetime_constname, 1.0 );
    
    driver := select( this, MacroPlan.AccountCostDriver, driver, driver.Name() = Translations::MP_AccountAssignmentCostDriverOneTime() );
    traverse( scope.GetAccountsInOptimizerRunConst(), Elements, account, account.HasOneTimeAssignment() )
    {
      // dcconst constraint UoM: Monetary
      dcconst := program.DriverOneTimeConstraints().New( account, driver );
      dcconst.Sense( '=' );
      dcconst.RHSValue( 0.0 * scalefactor_rhs_dconst );
      // Term UoM: Monetary
      dcconst.NewTerm( 1.0 * scalefactor_driver_dconst, program.DriverOneTimeVariables().Get( account, driver ) );
    
      if ( runcontext.UseOneTimeCost() ) 
      {
        traverse( account, AccountAssignment, aa, aa.AccountCostDriver() = driver and aa.AccountCost( relsize ) > 0  )
        {
          // Operation (only include those that are part of this optimizer run and related to a unit period that is part of this optimizer run)
          traverse( aa, astype( UnitAccount ).UnitAccountInPeriodForOneTimeCost.UnitPeriod, up,
                    scope.Contains(  up.UnitPeriodInOptimizerRun() ) )
          {
            traverse( up, Unit.OperationForOptimizationInScope, operation, operation.HasOneTimeCost() ) 
            {
              cost := operation.GetBaseOneTimeCost( aa, up );
              isusedvar := program.PTIsUsedVariables().Find( operation, up.Period_MP() );
              // If the isused variable does not exist, then this combination of period and operation is not considered by the optimizer
              if( not isnull( isusedvar ) )
              {
                // Term:      -cost      * PTIsUSed variable
                // UoM:  [Monetary/Unit] *    [-]    *    [Unit]
                dcconst.NewTerm( -cost * scalefactor_ptisused_dconst, isusedvar );
              }
            }
          }
        }
      }
    }
  *]
  InterfaceProperties { Accessibility: 'Module' }
}