Example #1
0
        CreateTestObjects <TPrimary, TSecondary>(
            IHooksDiscovery <TPrimary> primaryDiscovery          = null,
            IHooksDiscovery <TSecondary> secondaryDiscovery      = null,
            DbContextOptions <AppDbContext> repoDbContextOptions = null
            )
            where TPrimary : class, IIdentifiable <int>
            where TSecondary : class, IIdentifiable <int>
        {
            // creates the resource definition mock and corresponding for a given set of discoverable hooks
            var primaryResource   = CreateResourceDefinition <TPrimary>();
            var secondaryResource = CreateResourceDefinition <TSecondary>();

            // mocking the genericServiceFactory and JsonApiContext and wiring them up.
            var(ufMock, constraintsMock, gpfMock, options) = CreateMocks();

            var dbContext = repoDbContextOptions != null ? new AppDbContext(repoDbContextOptions) : null;

            var resourceGraph = new ResourceGraphBuilder(new JsonApiOptions(), NullLoggerFactory.Instance)
                                .Add <TPrimary>()
                                .Add <TSecondary>()
                                .Build();

            SetupProcessorFactoryForResourceDefinition(gpfMock, primaryResource.Object, primaryDiscovery, dbContext, resourceGraph);
            SetupProcessorFactoryForResourceDefinition(gpfMock, secondaryResource.Object, secondaryDiscovery, dbContext, resourceGraph);

            var execHelper      = new HookExecutorHelper(gpfMock.Object, ResourceGraph, options);
            var traversalHelper = new TraversalHelper(ResourceGraph, ufMock.Object);
            var hookExecutor    = new ResourceHookExecutor(execHelper, traversalHelper, ufMock.Object, constraintsMock.Object, ResourceGraph);

            return(constraintsMock, ufMock, hookExecutor, primaryResource, secondaryResource);
        }
        protected override void InternalCompute()
        {
            if (this.RootVertex == null)
            {
                this.RootVertex = TraversalHelper.GetFirstVertex <TVertex, TEdge>(this.VisitedGraph);
            }

            this.Initialize();
            if (this.RootVertex == null)
            {
                this.RootVertex = TraversalHelper.GetFirstVertex <TVertex, TEdge>(this.VisitedGraph);
                foreach (TVertex v in this.VisitedGraph.Vertices)
                {
                    if (this.VertexColors[v] == GraphColor.White)
                    {
                        this.OnStartVertex(v);
                        this.Visit(v);
                    }
                }
            }
            else
            {
                this.OnStartVertex(this.RootVertex);
                this.Visit(this.RootVertex);
            }
        }
        protected override void InternalCompute()
        {
            if (this.VisitedGraph.VertexCount == 0)
            {
                return;
            }

            TVertex rootVertex;

            if (!this.TryGetRootVertex(out rootVertex))
            {
                rootVertex = TraversalHelper.GetFirstVertex <TVertex, TEdge>(this.VisitedGraph);
            }

            this.currentVertex = rootVertex;
            // start search
            Search(this.currentVertex);
            if (CircuitAugmentation())
            {
                return; // circuit is found
            }
            do
            {
                if (!Visit())
                {
                    break; // visit edges and build path
                }
                if (CircuitAugmentation())
                {
                    break; // circuit is found
                }
            } while (true);
        }
Example #4
0
    public void Run()
    {
        int[]    preOrder  = { 3, 9, 20, 15, 7 };
        int[]    inOrder   = { 9, 3, 15, 20, 7 };
        TreeNode finalData = BuildTree(preOrder, inOrder);

        TraversalHelper.TraverseInOrder(finalData);
    }
Example #5
0
        public void Generate(
            [UsingFactories(typeof(EdgeChainFactory))]
            KeyValuePair <IVertexAndEdgeListGraph <string, Edge <string> >, IEdgeChain <string, Edge <String> > > eg
            )
        {
            RandomWalkAlgorithm <string, Edge <string> > walker =
                new RandomWalkAlgorithm <string, Edge <string> >(eg.Key, eg.Value);

            walker.Generate(TraversalHelper.GetFirstVertex(eg.Key));
        }
        protected override void InternalCompute()
        {
            if (this.VisitedGraph.VertexCount == 0)
            {
                return;
            }
            var     cancelManager = this.Services.CancelManager;
            TVertex rootVertex;

            if (!this.TryGetRootVertex(out rootVertex))
            {
                rootVertex = TraversalHelper.GetFirstVertex <TVertex, TEdge>(this.VisitedGraph);
            }

            this.Initialize();

            try
            {
                this.minimumWeights[rootVertex] = 0;
                this.queue.Update(rootVertex);
                this.OnStartVertex(rootVertex);

                while (queue.Count != 0)
                {
                    if (cancelManager.IsCancelling)
                    {
                        return;
                    }
                    TVertex u = queue.Dequeue();
                    foreach (var edge in this.VisitedGraph.AdjacentEdges(u))
                    {
                        if (cancelManager.IsCancelling)
                        {
                            return;
                        }
                        double edgeWeight = this.EdgeWeights[edge];
                        if (
                            queue.Contains(edge.Target) &&
                            edgeWeight < this.minimumWeights[edge.Target]
                            )
                        {
                            this.minimumWeights[edge.Target] = edgeWeight;
                            this.queue.Update(edge.Target);
                            this.OnTreeEdge(edge);
                        }
                    }
                    this.OnFinishVertex(u);
                }
            }
            finally
            {
                this.CleanUp();
            }
        }
Example #7
0
        protected override void InternalCompute()
        {
            if (this.VisitedGraph.VertexCount == 0)
            {
                return;
            }
            if (this.RootVertex == null)
            {
                this.RootVertex = TraversalHelper.GetFirstVertex <TVertex, TEdge>(this.VisitedGraph);
            }

            this.Initialize();

            try
            {
                this.minimumWeights[this.RootVertex] = 0;
                this.queue.Update(this.RootVertex);
                this.OnStartVertex(this.RootVertex);

                while (queue.Count != 0)
                {
                    if (this.IsAborting)
                    {
                        return;
                    }
                    TVertex u = queue.Pop();
                    foreach (TEdge edge in this.VisitedGraph.AdjacentEdges(u))
                    {
                        if (this.IsAborting)
                        {
                            return;
                        }
                        double edgeWeight = this.EdgeWeights[edge];
                        if (
                            queue.Contains(edge.Target) &&
                            edgeWeight < this.minimumWeights[edge.Target]
                            )
                        {
                            this.minimumWeights[edge.Target] = edgeWeight;
                            this.queue.Update(edge.Target);
                            this.OnTreeEdge(edge);
                        }
                    }
                    this.OnFinishVertex(u);
                }
            }
            finally
            {
                this.CleanUp();
            }
        }
Example #8
0
        public void GenerateWithVisitor(
            [UsingFactories(typeof(EdgeChainFactory))]
            KeyValuePair <IVertexAndEdgeListGraph <string, Edge <string> >, IEdgeChain <string, Edge <String> > > eg
            )
        {
            RandomWalkAlgorithm <string, Edge <string> > walker =
                new RandomWalkAlgorithm <string, Edge <string> >(eg.Key, eg.Value);

            EdgeRecorderObserver <string, Edge <string> > vis = new EdgeRecorderObserver <string, Edge <string> >();

            vis.Attach(walker);
            walker.Generate(TraversalHelper.GetFirstVertex(eg.Key));
            vis.Detach(walker);
        }
Example #9
0
        public void RoundRobinTest(IVertexListGraph <string, Edge <string> > g)
        {
            if (g.VertexCount == 0)
            {
                return;
            }

            RandomWalkAlgorithm <String, Edge <string> > walker =
                new RandomWalkAlgorithm <String, Edge <string> >(g);

            walker.EdgeChain = new NormalizedMarkovEdgeChain <string, Edge <string> >();

            string root = TraversalHelper.GetFirstVertex(g);

            walker.Generate(root);
        }
        protected override void InternalCompute()
        {
            this.componentCount = -1;
            this.components.Clear();

            if (this.VisitedGraph.VertexCount != 0)
            {
                if (this.RootVertex == null)
                {
                    this.RootVertex = TraversalHelper.GetFirstVertex <TVertex, TEdge>(this.VisitedGraph);
                }
                dfs.Compute(this.RootVertex);
            }

            ++this.componentCount;
        }
Example #11
0
        internal (ResourceHookExecutor, Mock <IResourceHookContainer <TPrimary> >) CreateTestObjects <TPrimary>(IHooksDiscovery <TPrimary> primaryDiscovery = null)
            where TPrimary : class, IIdentifiable <int>
        {
            // creates the resource definition mock and corresponding ImplementedHooks discovery instance
            var primaryResource = CreateResourceDefinition <TPrimary>();

            // mocking the genericServiceFactory and JsonApiContext and wiring them up.
            var(ufMock, constraintsMock, gpfMock, options) = CreateMocks();

            SetupProcessorFactoryForResourceDefinition(gpfMock, primaryResource.Object, primaryDiscovery);

            var execHelper      = new HookExecutorHelper(gpfMock.Object, ResourceGraph, options);
            var traversalHelper = new TraversalHelper(ResourceGraph, ufMock.Object);
            var hookExecutor    = new ResourceHookExecutor(execHelper, traversalHelper, ufMock.Object, constraintsMock.Object, ResourceGraph);

            return(hookExecutor, primaryResource);
        }
        public ConduitClosureTerminalType(IRouteNetworkState routeNetworkQueryService, IConduitNetworkQueryService conduitNetworkQueryService, IDataLoaderContextAccessor dataLoader)
        {
            this.routeNetworkQueryService    = routeNetworkQueryService;
            this.conduitNetworkEqueryService = conduitNetworkQueryService;

            var traversal = new TraversalHelper(routeNetworkQueryService);

            Description = "A specific terminal part of a condult closure port. Terminal are like sides and ports numbered clockwise reflecting their position. Only single conduits or cables can be attached to terminals.";

            Field(x => x.Position, type: typeof(IntGraphType)).Description("Terminal position/number.");

            Field(x => x.LineSegment, type: typeof(ConduitSegmentType)).Description("The single conduit or cable attacthed to the terminal.");

            Field(x => x.ConnectionKind, type: typeof(ConduitClosureInternalConnectionKindType)).Description("The type of connection the cable or single conduit segment has (or don't have) to another port terminal in the closure.");

            Field(x => x.ConnectedToSide, type: typeof(ConduitClosureSideEnumType)).Description("The other end side position/number, if the cable/conduit segment is connected to another cable/conduit segment (attached to another port terminal) or passing through to another port terminal.");

            Field(x => x.ConnectedToPort, type: typeof(IntGraphType)).Description("The other end port position/number, if the cable/conduit segment is connected to another cable/conduit segment (attached to another port terminal) or passing through to another port terminal.");

            Field(x => x.ConnectedToTerminal, type: typeof(IntGraphType)).Description("The other end terminal position/number, if the cable/conduit segment is connected to another cable/conduit segment (attached to another port terminal) or passing through to another port terminal.");

            Field <StringGraphType>(
                "DiagramLabel",
                resolve: context =>
            {
                // If conduit segment, show end node name
                if (context.Source.LineSegment != null && context.Source.LineSegment is ConduitSegmentInfo)
                {
                    var conduitSegmentInfo = context.Source.LineSegment as ConduitSegmentInfo;
                    var lineInfo           = traversal.CreateTraversalInfoFromSegment(conduitSegmentInfo);

                    if (context.Source.LineSegmentEndKind == ConduitEndKindEnum.Incomming)
                    {
                        return(lineInfo.StartRouteNode.Name);
                    }
                    else
                    {
                        return(lineInfo.EndRouteNode.Name);
                    }
                }


                return(null);
            });
        }
        public void Compute(IVertexAndEdgeListGraph <string, Edge <string> > g)
        {
            if (g.VertexCount == 0)
            {
                return;
            }

            var rnd       = new Random();
            var distances = new Dictionary <Edge <string>, double>();

            foreach (var edge in g.Edges)
            {
                distances.Add(edge, rnd.Next(100));
            }
            var bfs = new DijkstraShortestPathAlgorithm <string, Edge <string> >(g, distances);

            bfs.Compute(TraversalHelper.GetFirstVertex(g));
        }
Example #14
0
        public void RoundRobinTestWithVisitor(IVertexListGraph <string, Edge <string> > g)
        {
            if (g.VertexCount == 0)
            {
                return;
            }

            RandomWalkAlgorithm <String, Edge <string> > walker =
                new RandomWalkAlgorithm <String, Edge <string> >(g);

            walker.EdgeChain = new NormalizedMarkovEdgeChain <string, Edge <string> >();

            string root = TraversalHelper.GetFirstVertex(g);

            EdgeRecorderObserver <string, Edge <string> > vis = new EdgeRecorderObserver <string, Edge <string> >();

            vis.Attach(walker);
            walker.Generate(root);
            vis.Detach(walker);
        }
        protected override void InternalCompute()
        {
            this.componentCount = -1;
            this.components.Clear();

            UndirectedDepthFirstSearchAlgorithm <TVertex, TEdge> dfs = null;

            try
            {
                dfs = new UndirectedDepthFirstSearchAlgorithm <TVertex, TEdge>(
                    this,
                    this.VisitedGraph,
                    new Dictionary <TVertex, GraphColor>(this.VisitedGraph.VertexCount)
                    );

                dfs.StartVertex    += new VertexEventHandler <TVertex>(this.StartVertex);
                dfs.DiscoverVertex += new VertexEventHandler <TVertex>(this.DiscoverVertex);

                if (this.VisitedGraph.VertexCount != 0)
                {
                    TVertex rootVertex;
                    if (!this.TryGetRootVertex(out rootVertex))
                    {
                        rootVertex = TraversalHelper.GetFirstVertex <TVertex, TEdge>(this.VisitedGraph);
                    }
                    dfs.Compute(rootVertex);
                }

                ++this.componentCount;
            }
            finally
            {
                if (dfs != null)
                {
                    dfs.StartVertex    -= new VertexEventHandler <TVertex>(this.StartVertex);
                    dfs.DiscoverVertex -= new VertexEventHandler <TVertex>(this.DiscoverVertex);
                }
            }
        }
        public ConduitSegmentType(IRouteNetworkState routeNetworkQueryService, IConduitNetworkQueryService conduitNetworkEqueryService, IDataLoaderContextAccessor dataLoader)
        {
            this.routeNetworkQueryService    = routeNetworkQueryService;
            this.conduitNetworkEqueryService = conduitNetworkEqueryService;

            var traversal = new TraversalHelper(routeNetworkQueryService);

            Description = "A conduit segment will initially be the original whole length piece of conduit. When the user starts to cut the conduit at various nodes, more conduit segments will emerge. Graph connectivity is maintained on segment level.";

            Field(x => x.Id, type: typeof(IdGraphType)).Description("Guid property");

            Field(x => x.Conduit, type: typeof(ConduitInfoType)).Description("The original conduit that this segment is part of.");

            Field(x => x.Children, type: typeof(ListGraphType <ConduitSegmentType>)).Description("The children of a multi conduit segment.");
            Field(x => x.Parents, type: typeof(ListGraphType <ConduitSegmentType>)).Description("The parents of an inner conduit segment.");

            Field <ConduitLineType>(
                "Line",
                resolve: context =>
            {
                var traversalInfo = traversal.CreateTraversalInfoFromSegment(context.Source);

                var cLineType               = new ConduitLineInfo();
                cLineType.AllSegments       = traversalInfo.AllSegments.OfType <ConduitSegmentInfo>().ToList();
                cLineType.AllRouteNodes     = traversalInfo.AllRouteNodes.OfType <RouteNodeInfo>().ToList();
                cLineType.AllRouteSegments  = traversalInfo.AllRouteSegments.OfType <RouteSegmentInfo>().ToList();
                cLineType.EndRouteNode      = (RouteNodeInfo)traversalInfo.EndRouteNode;
                cLineType.StartRouteNode    = (RouteNodeInfo)traversalInfo.StartRouteNode;
                cLineType.StartRouteSegment = (RouteSegmentInfo)traversalInfo.StartRouteSegment;
                cLineType.EndRouteSegment   = (RouteSegmentInfo)traversalInfo.EndRouteSegment;

                return(cLineType);
            });

            Field <RouteNodeType>(
                "FromRouteNode",
                resolve: context =>
            {
                return(routeNetworkQueryService.GetRouteNodeInfo(context.Source.FromRouteNodeId));
            });

            Field <RouteNodeType>(
                "ToRouteNode",
                resolve: context =>
            {
                return(routeNetworkQueryService.GetRouteNodeInfo(context.Source.ToRouteNodeId));
            });

            Field <ListGraphType <RouteSegmentType> >(
                "AllRouteSegments",
                resolve: context =>
            {
                List <RouteSegmentInfo> result = new List <RouteSegmentInfo>();

                var woi = routeNetworkQueryService.GetWalkOfInterestInfo(context.Source.Conduit.GetRootConduit().WalkOfInterestId).SubWalk2(context.Source.FromRouteNodeId, context.Source.ToRouteNodeId);

                foreach (var segmentId in woi.AllSegmentIds)
                {
                    result.Add(routeNetworkQueryService.GetRouteSegmentInfo(segmentId));
                }

                return(result);
            });

            Field <ListGraphType <RouteNodeType> >(
                "AllRouteNodes",
                resolve: context =>
            {
                List <RouteNodeInfo> result = new List <RouteNodeInfo>();

                var woi = routeNetworkQueryService.GetWalkOfInterestInfo(context.Source.Conduit.GetRootConduit().WalkOfInterestId).SubWalk2(context.Source.FromRouteNodeId, context.Source.ToRouteNodeId);

                foreach (var nodeId in woi.AllNodeIds)
                {
                    result.Add(routeNetworkQueryService.GetRouteNodeInfo(nodeId));
                }

                return(result);
            });

            Field(x => x.Line.LineKind, type: typeof(LineSegmentKindType)).Description("Type of line segment - i.e. conduit, power cable, signal cable etc.");


            //Interface<LineSegmentInterface>();
        }
Example #17
0
        public ConduitSegment(IRouteNetworkState routeNetworkQueryService, IConduitNetworkQueryService conduitNetworkEqueryService, IDataLoaderContextAccessor dataLoader, IHttpContextAccessor httpContextAccessor)
        {
            this.routeNetworkQueryService    = routeNetworkQueryService;
            this.conduitNetworkEqueryService = conduitNetworkEqueryService;

            var traversal = new TraversalHelper(routeNetworkQueryService);

            Description = "A conduit will initially contain one segment that spans the whole length of conduit that was originally placed in the route network. When the user starts to cut the conduit at various nodes, more conduit segments will emerge. However, the original conduit asset is the same, now just cut in pieces. The segment represent the pieces. The line represent the original asset. Graph connectivity is maintained on segment level. Use line field to access general asset information. Use the conduit field to access conduit specific asset information.";

            // Interface fields

            Interface <SegmentInterface>();

            Field(x => x.Id, type: typeof(IdGraphType)).Description("Guid property");

            Field <LineSegmentRelationTypeEnumType>(
                "RelationType",
                resolve: context =>
            {
                Guid routeNodeId = (Guid)httpContextAccessor.HttpContext.Items["routeNodeId"];
                return(context.Source.RelationType(routeNodeId));
            });

            Field(x => x.Line.LineKind, type: typeof(LineSegmentKindType)).Description("Type of line segment - i.e. multi conduit, single conduit, fiber cable etc.");

            Field(x => x.Line, type: typeof(LineInterface)).Description("Line that this segment belongs to.");

            Field(x => x.Parents, type: typeof(ListGraphType <SegmentInterface>)).Description("The parent segments of this segment, if this segment is contained within another segment network - i.e. a fiber cable segment running within one of more conduit segments.");

            Field(x => x.Children, type: typeof(ListGraphType <SegmentInterface>)).Description("The child segments of this segment. As an example, if this is multi conduit, then child segments might be fiber cable segments or inner conduit segments running inside the multi conduit.");

            Field <RouteNodeType>(
                "FromRouteNode",
                resolve: context =>
            {
                return(routeNetworkQueryService.GetRouteNodeInfo(context.Source.FromRouteNodeId));
            });

            Field <RouteNodeType>(
                "ToRouteNode",
                resolve: context =>
            {
                return(routeNetworkQueryService.GetRouteNodeInfo(context.Source.ToRouteNodeId));
            });

            Field <SegmentTraversalType>(
                "Traversal",
                resolve: context =>
            {
                return(traversal.CreateTraversalInfoFromSegment(context.Source));
            });

            // Additional fields

            Field(x => x.Conduit, type: typeof(ConduitInfoType)).Description("The original conduit that this segment belongs to.");

            Field <SegmentTraversalType>(
                "Connectivity",
                resolve: context =>
            {
                return(traversal.CreateTraversalInfoFromSegment(context.Source));
            });


            Field <ListGraphType <RouteSegmentType> >(
                "AllRouteSegments",
                resolve: context =>
            {
                List <RouteSegmentInfo> result = new List <RouteSegmentInfo>();

                var woi = routeNetworkQueryService.GetWalkOfInterestInfo(context.Source.Conduit.GetRootConduit().WalkOfInterestId).SubWalk2(context.Source.FromRouteNodeId, context.Source.ToRouteNodeId);

                foreach (var segmentId in woi.AllSegmentIds)
                {
                    result.Add(routeNetworkQueryService.GetRouteSegmentInfo(segmentId));
                }

                return(result);
            });

            Field <ListGraphType <RouteNodeType> >(
                "AllRouteNodes",
                resolve: context =>
            {
                List <RouteNodeInfo> result = new List <RouteNodeInfo>();

                var woi = routeNetworkQueryService.GetWalkOfInterestInfo(context.Source.Conduit.GetRootConduit().WalkOfInterestId).SubWalk2(context.Source.FromRouteNodeId, context.Source.ToRouteNodeId);

                foreach (var nodeId in woi.AllNodeIds)
                {
                    result.Add(routeNetworkQueryService.GetRouteNodeInfo(nodeId));
                }

                return(result);
            });
        }
Example #18
0
        //Create a graph
        //      A(0)
        //      |
        //      |
        //      B(1)------H(7)
        //      |         |
        //      |         |
        //      C(2)------E(4)------G(6)
        //      |         |
        //      |         |
        //      D(3)      F(5)
        static void Main(string[] args)
        {
            AdjacencyMatrix aM = new AdjacencyMatrix(8);

            aM.addEdge(0, 1);
            aM.addEdge(1, 2);
            aM.addEdge(1, 7);
            aM.addEdge(2, 4);
            aM.addEdge(7, 4);
            aM.addEdge(4, 6);
            aM.addEdge(2, 3);
            aM.addEdge(4, 5);

            Vertex A = new Vertex('A');
            Vertex B = new Vertex('B');
            Vertex C = new Vertex('C');
            Vertex D = new Vertex('D');
            Vertex E = new Vertex('E');
            Vertex F = new Vertex('F');
            Vertex G = new Vertex('G');
            Vertex H = new Vertex('H');

            Vertex[] vertexList = new Vertex[8] {
                A, B, C, D, E, F, G, H
            };

            //CommonGraph cG = new CommonGraph(aM, vertexList, 8);
            TraversalHelper.AllTraversal(aM, vertexList, 8);

            //    5         4
            //   / \       / \
            //  /   \     /   \
            // v     v   v     v
            //2        0        1
            // \               ^
            //  \             /
            //   \           /
            //     \        /
            //       \     /
            //        v   /
            //          3

            // Create a graph given
            // in the above diagram
            TopologicalSort g = new TopologicalSort(6);

            g.AddEdge(5, 2);
            g.AddEdge(5, 0);
            g.AddEdge(4, 0);
            g.AddEdge(4, 1);
            g.AddEdge(2, 3);
            g.AddEdge(3, 1);

            Console.WriteLine("Following is a Topological "
                              + "sort of the given graph");

            // Function Call
            g.TopologicalSorting();

            Console.ReadLine();
        }
        public Diagram Build(Guid nodeId, IRouteNetworkState routeNetworkQueryService, IConduitNetworkQueryService conduitNetworkEqueryService, IFiberNetworkQueryService fiberNetworkService, IConduitClosureRepository conduitClosureRepository)
        {
            _routeNetworkQueryService   = routeNetworkQueryService;
            _conduitNetworkQueryService = conduitNetworkEqueryService;

            _traversalHelper = new TraversalHelper(_routeNetworkQueryService);

            DiagramBuilder builder = new DiagramBuilder();

            double minWidth = 300;

            double offsetY = 0;

            ConduitClosureInfo conduitClosureInfo = null;

            if (conduitClosureRepository.CheckIfRouteNodeContainsConduitClosure(nodeId))
            {
                conduitClosureInfo = conduitClosureRepository.GetConduitClosureInfoByRouteNodeId(nodeId);
            }


            // Add cables passing through
            var cableSegmentRels = fiberNetworkService.GetLineSegmentsRelatedToPointOfInterest(nodeId);

            offsetY += AddCablePassThroughBlock(builder, cableSegmentRels, offsetY, 300);


            // Add multi conduit passing through
            var conduitSegmentRels = conduitNetworkEqueryService.GetConduitSegmentsRelatedToPointOfInterest(nodeId);

            foreach (var conduitSegmentRel in conduitSegmentRels)
            {
                // pass by multi conduit
                if (conduitSegmentRel.RelationType == SegmentRelationTypeEnum.PassThrough && conduitSegmentRel.Segment.Line.LineKind == LineKindEnum.MultiConduit)
                {
                    // check if outside conduit closure
                    if (conduitClosureInfo != null && conduitClosureInfo.Sides.Exists(s => s.Ports.Exists(p => p.MultiConduitId == conduitSegmentRel.Segment.Line.Id)))
                    {
                    }
                    else
                    {
                        offsetY += AddMultiConduitPassThroughBlock(builder, (ConduitSegmentInfo)conduitSegmentRel.Segment, minWidth, offsetY);
                    }
                }
            }

            // Add conduit closure
            offsetY += 20;

            if (conduitClosureInfo != null)
            {
                offsetY += AddConduitClosureBlock(builder, conduitClosureInfo, minWidth, offsetY);
            }


            Diagram diagram = builder.CreateDiagram();

            return(diagram);


            LineBlock junctionBlock = new LineBlock(30, 0);

            junctionBlock.MinWidth = 300;

            // Add first vest port with 5 terminal
            AddMultiConduitPort(junctionBlock, BlockSideEnum.Vest, 10, "Orange");

            // Add second vest port with 7 terminal
            AddMultiConduitPort(junctionBlock, BlockSideEnum.Vest, 7, "Orange");


            // Add fist east port with 10 terminal
            AddMultiConduitPort(junctionBlock, BlockSideEnum.East, 10, "Orange");

            // Add second east port with 7 terminal
            AddMultiConduitPort(junctionBlock, BlockSideEnum.East, 7, "Orange");


            // Add north big conduit port 1 with 3 terminal
            AddBigConduitPort(junctionBlock, BlockSideEnum.North, 3, "Red");

            // Add north big conduit port 2 with 5 terminal
            AddBigConduitPort(junctionBlock, BlockSideEnum.North, 5, "Red");

            junctionBlock.AddTerminalConnection(BlockSideEnum.Vest, 1, 1, BlockSideEnum.East, 1, 1, null, "InnerConduitBlue", LineShapeTypeEnum.Polygon);

            junctionBlock.AddTerminalConnection(BlockSideEnum.Vest, 1, 2, BlockSideEnum.North, 1, 1, null, "InnerConduitBlue", LineShapeTypeEnum.Polygon);

            /*
             *
             * // Feeder calbe from central office
             * junctionBlock.AddConnection(BlockSideEnum.Vest, 2, 5, BlockSideEnum.North, 1, 1, "192", "CableInsideWell");
             *
             * // Transit feeder cable to other flex points
             * junctionBlock.AddConnection(BlockSideEnum.Vest, 1, 4, BlockSideEnum.North, 1, 2, "96", "CableInsideWell");
             * junctionBlock.AddConnection(BlockSideEnum.East, 1, 10, BlockSideEnum.North, 1, 3, "96", "CableInsideWell");
             *
             * // Sp connections
             * junctionBlock.AddConnection(BlockSideEnum.East, 1, 1, BlockSideEnum.North, 2, 2, "24", "CableInsideWell");
             * junctionBlock.AddConnection(BlockSideEnum.East, 1, 2, BlockSideEnum.North, 2, 3, "48", "CableInsideWell");
             * junctionBlock.AddConnection(BlockSideEnum.East, 1, 3, BlockSideEnum.North, 2, 4, "48", "CableInsideWell");
             * junctionBlock.AddConnection(BlockSideEnum.East, 1, 4, BlockSideEnum.North, 2, 5, "48", "CableInsideWell");
             * junctionBlock.AddConnection(BlockSideEnum.Vest, 2, 2, BlockSideEnum.North, 2, 1, "48", "CableInsideWell");
             *
             */

            builder.ContentObjects.Add(junctionBlock);
            junctionBlock.Measure(new Layout.Size());

            //////////////////////////////////////////////////////////
            /// well north label block

            LineBlock wellNorthLabelBlock = new LineBlock(30, junctionBlock.DesiredSize.Height, LineBlockTypeEnum.Simple);

            wellNorthLabelBlock.MinHeight = 30;

            // Add north port with 3 terminal
            AddBigConduitPort(wellNorthLabelBlock, BlockSideEnum.North, 3);

            // Add north port with 5 terminal
            AddBigConduitPort(wellNorthLabelBlock, BlockSideEnum.North, 5);

            // Add south port with 3 terminal
            AddBigConduitPort(wellNorthLabelBlock, BlockSideEnum.South, 3);

            // Add south port with 5 terminal
            AddBigConduitPort(wellNorthLabelBlock, BlockSideEnum.South, 5);

            wellNorthLabelBlock.AddTerminalConnection(BlockSideEnum.North, 1, 1, BlockSideEnum.South, 1, 1, "GSS 1 (1-16)", "CableOutsideWell");
            wellNorthLabelBlock.AddTerminalConnection(BlockSideEnum.North, 1, 2, BlockSideEnum.South, 1, 2, "GSS 1 (1-8)", "CableOutsideWell");
            wellNorthLabelBlock.AddTerminalConnection(BlockSideEnum.North, 1, 3, BlockSideEnum.South, 1, 3, "GSS 1 (9-16)", "CableOutsideWell");

            wellNorthLabelBlock.AddTerminalConnection(BlockSideEnum.North, 2, 1, BlockSideEnum.South, 2, 1, "GPS 1", "CableOutsideWell");
            wellNorthLabelBlock.AddTerminalConnection(BlockSideEnum.North, 2, 2, BlockSideEnum.South, 2, 2, "GPS 1", "CableOutsideWell");
            wellNorthLabelBlock.AddTerminalConnection(BlockSideEnum.North, 2, 3, BlockSideEnum.South, 2, 3, "GPS 2", "CableOutsideWell");
            wellNorthLabelBlock.AddTerminalConnection(BlockSideEnum.North, 2, 4, BlockSideEnum.South, 2, 4, "GPS 2", "CableOutsideWell");
            wellNorthLabelBlock.AddTerminalConnection(BlockSideEnum.North, 2, 5, BlockSideEnum.South, 2, 5, "GPS 2 & 3", "CableOutsideWell");


            builder.ContentObjects.Add(wellNorthLabelBlock);
            wellNorthLabelBlock.Measure(new Layout.Size());

            //////////////////////////////////////////////////////////
            /// well vest label block

            LineBlock wellVestLabelBlock = new LineBlock(0, 0, LineBlockTypeEnum.Simple);

            wellVestLabelBlock.MinWidth = 30;

            // Add vest port with 5 terminal
            AddBigConduitPort(wellVestLabelBlock, BlockSideEnum.Vest, 5);

            // Add vest port with 7 terminal
            AddBigConduitPort(wellVestLabelBlock, BlockSideEnum.Vest, 7);

            // Add east port with 5 terminal
            AddBigConduitPort(wellVestLabelBlock, BlockSideEnum.East, 5);

            // Add east port with 7 terminal
            AddBigConduitPort(wellVestLabelBlock, BlockSideEnum.East, 7);

            wellVestLabelBlock.AddTerminalConnection(BlockSideEnum.Vest, 1, 4, BlockSideEnum.East, 1, 4, "PF-4200", "CableOutsideWell");
            wellVestLabelBlock.AddTerminalConnection(BlockSideEnum.Vest, 2, 2, BlockSideEnum.East, 2, 2, "SP-5420", "CableOutsideWell");
            wellVestLabelBlock.AddTerminalConnection(BlockSideEnum.Vest, 2, 5, BlockSideEnum.East, 2, 5, "CO-1010", "CableOutsideWell");

            wellVestLabelBlock.Measure(new Layout.Size());
            builder.ContentObjects.Add(wellVestLabelBlock);

            //////////////////////////////////////////////////////////
            /// east label block

            LineBlock wellEastLabelBlock = new LineBlock(junctionBlock.DesiredSize.Width + 30, 0, LineBlockTypeEnum.Simple);

            wellEastLabelBlock.MinWidth  = 30;
            wellEastLabelBlock.MinHeight = junctionBlock.DesiredSize.Height;

            // Add vest port with 10 terminal
            AddBigConduitPort(wellEastLabelBlock, BlockSideEnum.Vest, 10);

            // Add east port with 10 terminal
            AddBigConduitPort(wellEastLabelBlock, BlockSideEnum.East, 10);

            wellEastLabelBlock.AddTerminalConnection(BlockSideEnum.Vest, 1, 1, BlockSideEnum.East, 1, 1, "SP-5010", "CableOutsideWell");
            wellEastLabelBlock.AddTerminalConnection(BlockSideEnum.Vest, 1, 2, BlockSideEnum.East, 1, 2, "SP-5011", "CableOutsideWell");
            wellEastLabelBlock.AddTerminalConnection(BlockSideEnum.Vest, 1, 3, BlockSideEnum.East, 1, 3, "SP-5013", "CableOutsideWell");
            wellEastLabelBlock.AddTerminalConnection(BlockSideEnum.Vest, 1, 4, BlockSideEnum.East, 1, 4, "SP-6002", "CableOutsideWell");
            wellEastLabelBlock.AddTerminalConnection(BlockSideEnum.Vest, 1, 10, BlockSideEnum.East, 1, 10, "FP-4203", "CableOutsideWell");

            wellEastLabelBlock.Measure(new Layout.Size());
            builder.ContentObjects.Add(wellEastLabelBlock);



            //////////////////////////////////////////////////////////
            /// well north corner 1

            LineBlock wellNorthCorner1 = new LineBlock(30, junctionBlock.DesiredSize.Height + wellNorthLabelBlock.DesiredSize.Height, LineBlockTypeEnum.Simple);

            wellNorthCorner1.MinHeight = 20;

            // Add south port with 3 terminal
            AddBigConduitPort(wellNorthCorner1, BlockSideEnum.South, 3);

            // Add east port with 3 terminal
            AddBigConduitPort(wellNorthCorner1, BlockSideEnum.East, 3, null, 1, 1);

            wellNorthCorner1.AddTerminalConnection(BlockSideEnum.South, 1, 1, BlockSideEnum.East, 1, 1, "", "CableOutsideWell");
            wellNorthCorner1.AddTerminalConnection(BlockSideEnum.South, 1, 2, BlockSideEnum.East, 1, 2, "", "CableOutsideWell");
            wellNorthCorner1.AddTerminalConnection(BlockSideEnum.South, 1, 3, BlockSideEnum.East, 1, 3, "", "CableOutsideWell");

            // Set margin on east side to 0
            wellNorthCorner1.SetSideMargin(BlockSideEnum.East, 0);

            //builder.ContentObjects.Add(wellNorthCorner1);

            Diagram sdiagram = builder.CreateDiagram();

            return(diagram);
        }