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
63
64
65
66
67
68
69
70
71
72
73
74
75
Quintiq file version 2.0
#parent: #root
Method Initialize (
  GraphProgram program
)
{
  Description: 'Creates a graph of the product specific supply chain'
  TextBody:
  [*
    // Create new graph, create needed edge value sets, add artificial root node of graph
    graph := program.NewDirectedGraph( MEIO_Treeify::GetGraphName(this.MEIO_Engine().Product_MP().Name()), this );
    leadtimes := program.NewEdgeValueSet( MEIO_Treeify::GetEdgeValueSetLeadtimes(), 0.0 );
    program.NewEdgeValueSet( MEIO_Treeify::GetEdgeValueSetWeights(), 1.0 );
    program.NewEdgeValueSet( MEIO_Treeify::GetEdgeValueSetUtilized(), 0.0 );
    root := graph.NewNode( MEIO_Treeify::GetArtificialRootName() );
    
    debuginfo( 'INITIALIZING GRAPH',
               'Graph:', MEIO_Treeify::GetGraphName(this.MEIO_Engine().Product_MP().Name()) )
    
    // Period specification duration used to bucketize leadtime
    ps_duration := this.MEIO_Engine().MacroPlan().StartOfPlanningPeriod().DurationInDays();
    
    // Traverse all PISPs 
    leadtimelogicfrommiddle := this.MEIO_Engine().Product_MP().MacroPlan().GlobalParameters_MP().OperationLeadTimeLogic() = Translations::MP_GlobalParameter_LeadTimeLogic_From_Middle_Period(); 
    laneleadtimelogicfrommiddle := this.MEIO_Engine().Product_MP().MacroPlan().GlobalParameters_MP().LaneLeadTimeLogic() = Translations::MP_GlobalParameter_LeadTimeLogic_From_Middle_Period() 
    traverse( this, MEIO_Engine.Product_MP.ProductInStockingPoint_MP, pisp )
    {
      // If PISP has an enabled incoming routing, bucketize the max enabled routing leadtime. 
      // Leadtime is translated depending on which leadtime logic is used
      if( exists( pisp, OperationOutput.Routing, r, r.IsEnabled()) )
      {
        leadtime := 0.0;
        
        maxsummedleadtime := max( pisp, OperationOutput, 
                                        oo, 
                                        sum( oo, Routing.RoutingStep.Operation, 
                                                 o, 
                                                 o.IsEnabled(), 
                                                 o.LeadTime().Days() ) )
                                                 
        unroundedleadtime := maxvalue( 0.0, ( this.GetLeadTimeInDays( leadtimelogicfrommiddle, maxsummedleadtime, ps_duration ) ) / ps_duration ); 
        leadtime := [Real] ifexpr( leadtimelogicfrommiddle, ceil( unroundedleadtime ), floor( unroundedleadtime ) ); 
     
        // Find or create edge from artificial root to PISP node ( since it is supplied from a routing )
        edge := this.GetEdge( graph, root, pisp ); 
        leadtimes.Set( edge, leadtime );
      }
      
      // Continue to add nodes and edges by traversing all enabled lanelegs incoming to the PISP
      traverse( pisp, LaneLegOutput.LaneLeg, ll, ll.IsEnabled() )
      {
        // Bucketize leadtime depending on which leadtime logic is used
        leadtime := 0.0;
        unroundedleadtime := this.GetLeadTimeInDays( leadtimelogicfrommiddle, ll.LeadTime().Days(), ps_duration ) / ps_duration; 
        leadtime := [Real] ifexpr( laneleadtimelogicfrommiddle, ceil( unroundedleadtime ), floor( unroundedleadtime ) ); 
        
        // Go through all upstream PISPs ( parents ), created corresponding nodes and edges between child and parent
        traverse( ll, LaneLegInput.ProductInStockingPoint_MP, parent_pisp, parent_pisp.Product_MP() = pisp.Product_MP() )
        {
          parent := graph.FindNode( parent_pisp.Name(), parent_pisp );
          if( isnull( parent ) )
          {
            parent := graph.NewNode( parent_pisp.Name(), parent_pisp );
          }
          edge := this.GetEdge( graph, parent, pisp ); 
          leadtimes.Set( edge, leadtime );
        }
      }
    }
    
    
    // Set max number of trees allowed to be run for this program
    this.SetMaxNrOfTrees( program );
  *]
}