haorenhui
2023-10-30 6d6cc10d9e8e242661da7fd655dec155a09d676c
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
63
64
65
66
67
68
69
70
71
72
73
74
75
Quintiq file version 2.0
#parent: #root
Method GetBaseAvailableCapacity (
  const ShiftPattern shiftpattern
) const declarative as Duration
{
  TextBody:
  [*
    value := Duration::Zero();
    
    datetimevector := DateTimeVector::Construct();
    durationvector := RealVector::Construct();
    
    planningup := ifexpr( this.IsPlanning(), 
                            this,                                             // Case 1: planning UnitPeriod: aggregate values from associated period tasks 
                            this.PlanningUP().astype( UnitPeriodTimeBase ) ); // Case 2: base, non planning UnitPeriod: disaggregate value from planning UnitPeriod
                           
    if( not isnull( planningup ) )
    {
      if( not isnull( planningup.Period_MP() ) 
          and not isnull( shiftpattern ) 
          and not planningup.Period_MP().IsInHour() ) //gdn1 HourlyPeriod is not applicable for ShiftPattern
      {
        lastshiftday := planningup.StartDate() - planningup.Period_MP().Start().StartOfWeek().Date() + 1
        
        nrdaysinthisperiod := planningup.Duration().DaysAsReal();
          
        firstday := planningup.Period_MP().Start();
        numberofshiftday := shiftpattern.ShiftDay( relsize );
     
        if( not isnull( planningup.Previous() ) )
        {
          lastshiftday := planningup.Previous().astype( UnitPeriodTimeBase ).PreviousPeriodLastShiftDay() + 1;
        
        }
    
        for( i := 0; i < nrdaysinthisperiod and firstday + Duration::Days( i ) >= planningup.Unit().StartDate().DateTime() ; i++ )
        {
          shiftday := lastshiftday + i;
    
          if( shiftday > numberofshiftday )
          {
            shiftday := shiftday mod numberofshiftday;
    
            if( shiftday = 0 )
            {
              shiftday := numberofshiftday;
            }
          }
    
          shift := select( shiftpattern, ShiftDay, shift, shift.Day() = shiftday, true );
          unavailable := planningup.Unit().UnavailableTime( firstday + Duration::Days( i ), firstday + Duration::Days( i + 1 ) );
    
          if( not isnull( shift ) )
          {
            shiftduration := maxvalue( ( shift.Capacity() - unavailable ), Duration::Zero() );
            //value := value + shiftduration;
            datetimevector.Append( firstday + Duration ::Days( i ) );
            durationvector.Append( shiftduration.HoursAsReal() );
          }
        } // for 
       
        value := this.GetPlanningCapacity( datetimevector, durationvector );
      }// if planning period not in hour
      else if ( planningup.Period_MP().DurationInDays() < 1 )   //gdn1 HourlyPeriod is always same as PeriodDuration 
      {
        value := planningup.Unit().UnitCalendar().AvailableTime( planningup.Start(), planningup.End(), 0.00000001 ); // Check calendar to make hourly period work with the calendar
      }
      
      value := maxvalue( ( value * planningup.Efficiency() * planningup.Allocation()  -  ( planningup.Maintenance() * this.PlanningSystemRatio() ) )* planningup.NrOfOpen(), Duration::Zero() );   
    }
    
    return value;
  *]
}