### Question:
TraversalToRelationship extends Algorithm<TraversalToRelationship, Relationships> { @Override public Relationships compute() { RelationshipsBuilder relImporter = new RelationshipsBuilderBuilder() .nodes(((HugeGraph) graphs[0]).idMap()) .orientation(Orientation.NATURAL) .loadRelationshipProperty(false) .aggregation(Aggregation.NONE) .concurrency(config.concurrency()) .executorService(executorService) .tracker(allocationTracker) .build(); var traversalConsumer = config.allowSelfLoops() ? new TraversalConsumer(relImporter, graphs.length) : new NoLoopTraversalConsumer(relImporter, graphs.length); AtomicLong batchOffset = new AtomicLong(0); var tasks = ParallelUtil.tasks(config.concurrency(), () -> () -> { var currentOffset = 0L; long[] startNodes = new long[64]; var localGraphs = new Graph[graphs.length]; for (int i = 0; i < graphs.length; i++) { localGraphs[i] = graphs[i].concurrentCopy(); } while ((currentOffset = batchOffset.getAndAdd(64)) < nodeCount) { if (currentOffset + 64 >= nodeCount) { startNodes = new long[(int) (nodeCount - currentOffset)]; } for (long j = currentOffset; j < Math.min(currentOffset + 64, nodeCount); j++) { startNodes[(int) (j - currentOffset)] = j; } var multiSourceBFS = TraversalToEdgeMSBFSStrategy.initializeMultiSourceBFS( localGraphs, traversalConsumer, config.allowSelfLoops(), allocationTracker, startNodes ); multiSourceBFS.run(); } }); ParallelUtil.runWithConcurrency(config.concurrency(), tasks, Pools.DEFAULT); return relImporter.build(); } TraversalToRelationship(Graph[] graphs, TraversalToRelationshipConfig config, ExecutorService executorService, AllocationTracker allocationTracker); @Override Relationships compute(); @Override TraversalToRelationship me(); @Override void release();  }### Answer:
@Test void testCreatingRelationships() { var tookRel = graphStore.getGraph(RelationshipType.of("TOOK")); var config = ImmutableTraversalToRelationshipConfig .builder() .concurrency(2) .relationshipTypes(List.of("TOOK", "TOOK")) .mutateRelationshipType("SAME_DRUG") .allowSelfLoops(false) .build(); Relationships relationships = new TraversalToRelationship( new Graph[]{tookRel, tookRel}, config, Pools.DEFAULT, AllocationTracker.empty() ).compute(); assertResultGraph(graphStore, relationships, EXPECTED_WITHOUT_LOOPS); }
@Test void testAllowCreatingSelfLoops() { var tookRel = graphStore.getGraph(RelationshipType.of("TOOK")); var config = ImmutableTraversalToRelationshipConfig .builder() .concurrency(2) .relationshipTypes(List.of("TOOK", "TOOK")) .mutateRelationshipType("SAME_DRUG") .allowSelfLoops(true) .build(); Relationships relationships = new TraversalToRelationship( new Graph[]{tookRel, tookRel}, config, Pools.DEFAULT, AllocationTracker.empty() ).compute(); assertResultGraph(graphStore, relationships, EXPECTED_WITH_LOOPS); }
@Test void runWithDifferentRelationshipTypes() { var config = ImmutableTraversalToRelationshipConfig .builder() .concurrency(2) .relationshipTypes(List.of("TOOK", "TAKEN_BY")) .mutateRelationshipType("SAME_DRUG") .allowSelfLoops(false) .build(); Relationships relationships = new TraversalToRelationship( new Graph[]{tookGraph, takenByGraph}, config, Pools.DEFAULT, AllocationTracker.empty() ).compute(); assertResultGraph(tookGraphStore, relationships, EXPECTED_WITHOUT_LOOPS); }