| 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 ); | 
|   *] | 
| } |