admin
2025-01-22 7e31442f0e9b07764e9c6a9680d3d4aeba5fe1de
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
61
62
Quintiq file version 2.0
#parent: #root
Method CreatePeriodTaskInCombiElements (
  CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm program,
  CapacityPlanningSuboptimizer suboptimizer
)
{
  TextBody:
  [*
    traverse( this, OptCampaignCombiElement, combielement )
    {
      optelementtype := combielement.OptCampaignElementType();
      
      traverse( optelementtype, OptCampaignOperationInElementType, optoperationinelementtype )
      {
        operation := optoperationinelementtype.Operation();
        combielementoptsubunitperiod := combielement.OptCampaignUnitSubPeriod();
        
        varptqtyinelementtypestart := program.PTQtyInCampaignElementTypeStartVariables().Get( optoperationinelementtype, combielementoptsubunitperiod );
        quantitystart := suboptimizer.GetOptimalValue( varptqtyinelementtypestart );
        
        varptqtyinelementtypemid := program.PTQtyInCampaignElementTypeMidVariables().Get( optoperationinelementtype, combielementoptsubunitperiod );
        quantitymid := suboptimizer.GetOptimalValue( varptqtyinelementtypemid );
        
        varptqtyinelementtypeend := program.PTQtyInCampaignElementTypeEndVariables().Get( optoperationinelementtype, combielementoptsubunitperiod );
        quantityend := suboptimizer.GetOptimalValue( varptqtyinelementtypeend );
        
        finalquantity := 0.0;
        
        if( combielement.IsFirstElementInUnitSubPeriod()
            and combielement.IsLastElementInUnitSubPeriod() )
        {
          // Sum all the quantities in an OptSubUnitPeriod if a element spans the whole OptSubUnitPeriod
          finalquantity := quantitystart + quantityend;
        } 
        else if( combielement.IsFirstElementInUnitSubPeriod() ) // first not last
        {
          // Set the quantity to the value of the variable PTQtyInElementTypeStart if an OptCampaignCombiElement is the first element of an OptSubUnitPeriod
          finalquantity := quantitystart;
        }
        else if( combielement.IsLastElementInUnitSubPeriod() ) // last not first
        {
          // Set the quantity to the value of the variable PTQtyInElementTypeEnd if an OptCampaignCombiElement is the last element of an OptSubUnitPeriod
          finalquantity := quantityend;
        }
        else // middle element 
        {
          // Distribute the quantity evenly
          nrofmidelements := counter( this, OptCampaignCombiElement, ele,
                                      not ele.IsFirstElementInUnitSubPeriod()
                                      and not ele.IsLastElementInUnitSubPeriod()
                                      and ele.OptCampaignUnitSubPeriod() = combielementoptsubunitperiod
                                      and ele.OptCampaignElementType() = optelementtype );      
          finalquantity := quantitymid / nrofmidelements;
        }
        
        optperiodtaskincombielement := OptCampaignPeriodTaskInCombiElement::Create( combielement, operation );
        optperiodtaskincombielement.Quantity( finalquantity );
      }
    }
  *]
}