Пример #1
0
        public NewRoute(
            ServiceIntention currentIntention,
            List <RouteSection> route,
            Dictionary <string, SectionRequirement> requirements,
            Dictionary <string, Resource> resources,
            List <Connection> ontoNeedsBeSet)
        {
            Sections       = route;
            RoutingPenalty = Sections.Select(s => s.penalty ?? 0.0).Sum();

            SectionRequirement GetSectionRequirement(RouteSection section)
            {
                if (section.section_marker != null)
                {
                    foreach (string s in section.section_marker)
                    {
                        if (requirements.TryGetValue(s, out var r))
                        {
                            return(r);
                        }
                    }
                }

                return(null);
            }

            var dummyEndNode = new RouteSection();

            Sections.Add(dummyEndNode);

            SectionRequirement[] sectionRequirements = Sections.Select(GetSectionRequirement).ToArray();

            Sections[0].Setup(currentIntention, null, sectionRequirements[0],
                              resources, ontoNeedsBeSet, false);
            for (int i = 1; i < Sections.Count; i++)
            {
                Sections[i].Setup(currentIntention, sectionRequirements[i - 1], sectionRequirements[i],
                                  resources, ontoNeedsBeSet,
                                  i == Sections.Count - 2 ||
                                  i == Sections.Count - 1);
            }
        }
Пример #2
0
        internal void Setup()
        {
            var RouteDictionary    = routes.ToDictionary(r => r.id);
            var ResourceDictionary = resources.ToDictionary(r => r.id);

            List <Connection> ontoNeedsBeSet = new List <Connection>();

            foreach (var intention in service_intentions)
            {
                intention.Setup(RouteDictionary, ResourceDictionary, ontoNeedsBeSet);
            }


            foreach (Connection connection in ontoNeedsBeSet)
            {
                var id = connection.onto_service_intention;
                connection.Onto = service_intentions.First(i => i.id == id);

                foreach (NewRoute route in connection.Onto.SbbRoutes)
                {
                    RouteSection section = route.Sections
                                           .FirstOrDefault(s => s.section_marker?.Contains(connection.onto_section_marker) ?? false);

                    if (section != null)
                    {
                        section.SbbIncomingConnections.Add(connection);
                    }
                    else
                    {
                        Console.WriteLine($"Warning: connectionId = {connection.id}, routeId = {route.ToString()}, no section with onto marker {connection.onto_section_marker} found.");
                    }
                }
            }

            Jobs = service_intentions;
        }