Ejemplo n.º 1
0
        public void LeftClosureWithRemoval(Arc toBeRemoved)
        {
            Assert(InvertPrecedenceCheck, GraphLayer.ArcExists(toBeRemoved.Tail, toBeRemoved.Head, toBeRemoved.MachineId));
            Assert(BeforeRemovalAcyclic, GraphLayer.IsAcyclic());

            if (!GraphLayer.TimesAreUpToDate())
            {
                throw new Exception();
            }


            Route route     = Solution.GetRoute(toBeRemoved.Head);
            var   criterion = route.Operations
                              .SelectMany(op => GraphLayer.OutgoingArcs(op.Id))
                              .Select(a => a.Head)
                              .Distinct()
                              .Select(v => Solution.GetEntryTime(v))
                              .Max() + TimeSpan.FromTicks(1);

            var arcs = SwapInMate(toBeRemoved);

            var otherCriterion = route.Operations
                                 .SelectMany(op => GraphLayer.OutgoingArcs(op.Id))
                                 .Select(a => a.Head)
                                 .Distinct()
                                 .Select(v => Solution.GetEntryTime(v))
                                 .Max() + TimeSpan.FromTicks(1);

            Assert(InvertPrecedenceCheck, !GraphLayer.ArcExists(toBeRemoved.Tail, toBeRemoved.Head, toBeRemoved.MachineId));

            //var criterion = arcs.Select(a => Solution.GetEntryTime(a.Head) + Solution.GetOperation(a.Head).RunTime + TimeSpan.FromTicks(1)).Max();

            LeftClosure(arcs[1], useTerminationCriterion: true, criterion);

            Assert(InvertPrecedenceCheck, !GraphLayer.ArcExists(toBeRemoved.Tail, toBeRemoved.Head, toBeRemoved.MachineId));

            if (!GraphLayer.IsAcyclic())
            {
                Console.WriteLine($"Cycle detected, visualizing");
                Console.WriteLine($"Termination criterion = {criterion.Show()}");
                GraphLayer.Visualize(GraphVisualization.NeighbourSelector(GraphLayer, route, 2));
            }

            Assert(AfterRemoveAcyclic, GraphLayer.IsAcyclic());
        }
Ejemplo n.º 2
0
        public static string Visualize <T>(this LinkedList <T> linkedList)
            where T : struct
        {
            if (linkedList.Count == 0)
            {
                return("");
            }

            var graphVisualization = new GraphVisualization();

            var current = linkedList.First;
            var nextId  = 0;

            var currentNodeId = nextId++.ToString();

            graphVisualization.Nodes.Add(new NodeData(currentNodeId)
            {
                Label = current?.Value.ToString()
            });

            if (linkedList.Count == 1)
            {
                return(graphVisualization.ToString());
            }

            var next = current?.Next;

            while (next != null)
            {
                var nextNodeId = nextId++.ToString();

                graphVisualization.Nodes.Add(new NodeData(nextNodeId)
                {
                    Label = next.Value.ToString()
                });

                graphVisualization.Edges.Add(new EdgeData(currentNodeId, nextNodeId));

                currentNodeId = nextNodeId;
                next          = next.Next;
            }

            return(graphVisualization.ToString());
        }