Beispiel #1
0
 /// <summary>
 /// Creates an instance of <see cref="PipGraphFragmentBuilder"/>.
 /// </summary>
 public PipGraphFragmentBuilderTopSort(
     PipExecutionContext pipExecutionContext,
     IConfiguration configuration,
     PathExpander pathExpander)
     : base(pipExecutionContext, configuration, pathExpander)
 {
 }
Beispiel #2
0
        /// <summary>
        /// Creates an instance of <see cref="PipGraphFragmentBuilder"/>.
        /// </summary>
        public PipGraphFragmentBuilder(
            PipExecutionContext pipExecutionContext,
            IConfiguration configuration,
            PathExpander pathExpander)
        {
            Contract.Requires(pipExecutionContext != null);

            Configuration          = configuration;
            m_pipExecutionContext  = pipExecutionContext;
            m_lazyApiServerMoniker = configuration.Schedule.UseFixedApiServerMoniker
                ? Lazy.Create(() => IpcFactory.GetFixedMoniker())
                : Lazy.Create(() => IpcFactory.GetProvider().CreateNewMoniker());
            SealDirectoryTable = new SealedDirectoryTable(m_pipExecutionContext.PathTable);

            if (configuration.Schedule.ComputePipStaticFingerprints)
            {
                var extraFingerprintSalts = new ExtraFingerprintSalts(
                    configuration,
                    PipFingerprintingVersion.TwoPhaseV2,
                    configuration.Cache.CacheSalt,
                    new DirectoryMembershipFingerprinterRuleSet(configuration, pipExecutionContext.StringTable).ComputeSearchPathToolsHash());

                m_pipStaticFingerprinter = new PipStaticFingerprinter(
                    pipExecutionContext.PathTable,
                    sealDirectoryFingerprintLookup: null,
                    directoryProducerFingerprintLookup: null,
                    extraFingerprintSalts: extraFingerprintSalts,
                    pathExpander: pathExpander)
                {
                    FingerprintTextEnabled = configuration.Schedule.LogPipStaticFingerprintTexts
                };
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void evenDifferentDirectionsKeepsOrder()
        public virtual void EvenDifferentDirectionsKeepsOrder()
        {
            PathExpander       expander = (new OrderedByTypeExpander()).add(_next, INCOMING).add(_firstComment).add(_comment).add(_next, OUTGOING);
            IEnumerator <Node> itr      = GraphDb.traversalDescription().depthFirst().expand(expander).traverse(Node("A2")).nodes().GetEnumerator();

            AssertOrder(itr, "A2", "A1", "C1", "C2", "C3", "C4", "C5", "C6", "A3", "C7", "C8", "C9");
        }
Beispiel #4
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
//ORIGINAL LINE: DijkstraPathExpander(final org.neo4j.graphdb.PathExpander source, org.apache.commons.lang3.mutable.MutableDouble shortestSoFar, double epsilon, boolean stopAfterLowestCost)
            internal DijkstraPathExpander(PathExpander source, MutableDouble shortestSoFar, double epsilon, bool stopAfterLowestCost)
            {
                this.Source              = source;
                this.ShortestSoFar       = shortestSoFar;
                this.Epsilon             = epsilon;
                this.StopAfterLowestCost = stopAfterLowestCost;
            }
Beispiel #5
0
 public TestBestFirstSelectorFactory(PathExpander expander, PathInterest <int> interest, Uniqueness uniqueness, string[] expectedResult)
 {
     this._expander       = expander;
     this._uniqueness     = uniqueness;
     this._expectedResult = expectedResult;
     _factory             = new BestFirstSelectorFactoryAnonymousInnerClass(this, interest);
 }
Beispiel #6
0
 public override TraversalBranch Next(PathExpander expander, TraversalContext context)
 {
     if (_relationships == null)
     {
         ExpandRelationships(expander);
     }
     while (_relationships.MoveNext())
     {
         Relationship relationship = _relationships.Current;
         if (relationship.Equals(_howIGotHere))
         {
             context.UnnecessaryRelationshipTraversed();
             continue;
         }
         _expandedCount++;
         Node node = relationship.GetOtherNode(_source);
         // TODO maybe an unnecessary instantiation. Instead pass in this+node+relationship to uniqueness check
         TraversalBranch next = NewNextBranch(node, relationship);
         if (context.IsUnique(next))
         {
             context.RelationshipTraversed();
             next.Initialize(expander, context);
             return(next);
         }
         else
         {
             context.UnnecessaryRelationshipTraversed();
         }
     }
     ResetRelationships();
     return(null);
 }
Beispiel #7
0
        public FileSystemMonitor(Configuration configuration, PathExpander expander)
        {
            _configuration = configuration;
            _expander      = expander;

            _updates = new Dictionary <string, DateTime>(StringComparer.OrdinalIgnoreCase);

            _timer = new Timer(5000)
            {
                AutoReset = true,
                Enabled   = true
            };

            _timer.Elapsed += (sender, args) =>
            {
                _timer.Enabled = false;
                var updates = new Dictionary <string, DateTime>(StringComparer.OrdinalIgnoreCase);
                var now     = DateTime.Now.Subtract(TimeSpan.FromMilliseconds(_timer.Interval));
                foreach (var key in _updates.Keys)
                {
                    // skip adding keys older than 5 seconds ago
                    if (_updates[key] < now)
                    {
                        continue;
                    }

                    updates.Add(key, _updates[key]);
                }

                _updates       = updates;
                _timer.Enabled = true;
            };

            _timer.Start();
        }
Beispiel #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testExactDepthFinder()
        public virtual void TestExactDepthFinder()
        {
            // Layout (a to k):
            //
            //     (a)--(c)--(g)--(k)
            //    /                /
            //  (b)-----(d)------(j)
            //   |        \      /
            //  (e)--(f)--(h)--(i)
            //
            Graph.makeEdgeChain("a,c,g,k");
            Graph.makeEdgeChain("a,b,d,j,k");
            Graph.makeEdgeChain("b,e,f,h,i,j");
            Graph.makeEdgeChain("d,h");
            PathExpander <object> expander = PathExpanders.forTypeAndDirection(MyRelTypes.R1, Direction.OUTGOING);
            Node a = Graph.getNode("a");
            Node k = Graph.getNode("k");

            AssertPaths(GraphAlgoFactory.pathsWithLength(expander, 3).findAllPaths(a, k), "a,c,g,k");
            AssertPaths(GraphAlgoFactory.pathsWithLength(expander, 4).findAllPaths(a, k), "a,b,d,j,k");
            AssertPaths(GraphAlgoFactory.pathsWithLength(expander, 5).findAllPaths(a, k));
            AssertPaths(GraphAlgoFactory.pathsWithLength(expander, 6).findAllPaths(a, k), "a,b,d,h,i,j,k");
            AssertPaths(GraphAlgoFactory.pathsWithLength(expander, 7).findAllPaths(a, k), "a,b,e,f,h,i,j,k");
            AssertPaths(GraphAlgoFactory.pathsWithLength(expander, 8).findAllPaths(a, k));
        }
Beispiel #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") @Test public void shouldExpandOnFirstAccess()
        public virtual void ShouldExpandOnFirstAccess()
        {
            // GIVEN
            TraversalBranch     parent = mock(typeof(TraversalBranch));
            Node                source = mock(typeof(Node));
            TraversalBranchImpl branch = new TraversalBranchImpl(parent, source);
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("rawtypes") org.neo4j.graphdb.PathExpander expander = mock(org.neo4j.graphdb.PathExpander.class);
            PathExpander expander = mock(typeof(PathExpander));

            when(expander.expand(eq(branch), any(typeof(BranchState)))).thenReturn(Iterables.emptyResourceIterable());
            TraversalContext context = mock(typeof(TraversalContext));

            when(context.Evaluate(eq(branch), Null)).thenReturn(INCLUDE_AND_CONTINUE);

            // WHEN initializing
            branch.Initialize(expander, context);

            // THEN the branch should not be expanded
            verifyZeroInteractions(source);

            // and WHEN actually traversing from it
            branch.Next(expander, context);

            // THEN we should expand it
            verify(expander).expand(any(typeof(Path)), any(typeof(BranchState)));
        }
Beispiel #10
0
 /// <summary>
 /// Construct a new bidirectional dijkstra algorithm. </summary>
 /// <param name="expander">          The <seealso cref="PathExpander"/> to be used to decide which relationships
 ///                          to expand for each node </param>
 /// <param name="costEvaluator">     The <seealso cref="CostEvaluator"/> to be used for calculating cost of a
 ///                          relationship </param>
 /// <param name="epsilon">           The tolerance level to be used when comparing floating point numbers. </param>
 public DijkstraBidirectional(PathExpander expander, CostEvaluator <double> costEvaluator, double epsilon)
 {
     this._expander      = expander;
     this._costEvaluator = costEvaluator;
     this._epsilon       = epsilon;
     this._stateFactory  = InitialBranchState.DOUBLE_ZERO;
 }
Beispiel #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void makeSureAMaxResultCountIsObeyed()
        public virtual void MakeSureAMaxResultCountIsObeyed()
        {
            // Layout:
            //
            //   (a)--(b)--(c)--(d)--(e)
            //    |                 / | \
            //   (f)--(g)---------(h) |  \
            //    |                   |   |
            //   (i)-----------------(j)  |
            //    |                       |
            //   (k)----------------------
            //
            Graph.makeEdgeChain("a,b,c,d,e");
            Graph.makeEdgeChain("a,f,g,h,e");
            Graph.makeEdgeChain("f,i,j,e");
            Graph.makeEdgeChain("i,k,e");
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.graphdb.Node a = graph.getNode("a");
            Node a = Graph.getNode("a");
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.graphdb.Node e = graph.getNode("e");
            Node e = Graph.getNode("e");
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.graphdb.PathExpander expander = org.neo4j.graphdb.PathExpanders.forTypeAndDirection(R1, OUTGOING);
            PathExpander expander = PathExpanders.forTypeAndDirection(R1, OUTGOING);

            TestShortestPathFinder(finder => assertEquals(4, Iterables.count(finder.findAllPaths(a, e))), expander, 10, 10);
            for (int i = 4; i >= 1; i--)
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int count = i;
                int count = i;
                TestShortestPathFinder(finder => assertEquals(count, Iterables.count(finder.findAllPaths(a, e))), expander, 10, count);
            }
        }
Beispiel #12
0
 public ExactDepthPathFinder(PathExpander expander, int onDepth, int startThreshold, bool allowLoops)
 {
     this._expander       = expander;
     this._onDepth        = onDepth;
     this._startThreshold = startThreshold;
     this._uniqueness     = allowLoops ? Uniqueness.RELATIONSHIP_GLOBAL : Uniqueness.NODE_PATH;
 }
Beispiel #13
0
 public FingerprintTextAnalyzer(AnalysisInput input)
     : base(input)
 {
     m_completedPips        = new HashSet <PipId>();
     m_contentFingerprinter = null;
     m_pathExpander         = input.CachedGraph.MountPathExpander;
 }
Beispiel #14
0
 public Dijkstra(PathExpander expander, InitialBranchState stateFactory, CostEvaluator <double> costEvaluator, bool stopAfterLowestCost)
 {
     this._expander      = expander;
     this._costEvaluator = costEvaluator;
     this._stateFactory  = stateFactory;
     _interest           = stopAfterLowestCost ? PathInterestFactory.allShortest(NoneStrictMath.EPSILON) : PathInterestFactory.all(NoneStrictMath.EPSILON);
     _epsilon            = NoneStrictMath.EPSILON;
     this._stateInUse    = true;
 }
Beispiel #15
0
 /// <summary>
 /// Construct new dijkstra algorithm. </summary>
 /// <param name="expander">          <seealso cref="PathExpander"/> to be used to decide which relationships
 ///                          to expand. </param>
 /// <param name="costEvaluator">     <seealso cref="CostEvaluator"/> to be used to calculate cost of relationship </param>
 /// <param name="epsilon">           The tolerance level to be used when comparing floating point numbers. </param>
 /// <param name="interest">          <seealso cref="PathInterest"/> to be used when deciding if a path is interesting.
 ///                          Recommend to use <seealso cref="PathInterestFactory"/> to get reliable behaviour. </param>
 public Dijkstra(PathExpander expander, CostEvaluator <double> costEvaluator, double epsilon, PathInterest <double> interest)
 {
     this._expander      = expander;
     this._costEvaluator = costEvaluator;
     this._epsilon       = epsilon;
     this._interest      = interest;
     this._stateFactory  = InitialBranchState.DOUBLE_ZERO;
     this._stateInUse    = false;
 }
Beispiel #16
0
 internal DijkstraBidirectionalPathExpander(PathExpander source, MutableDouble shortestSoFar, bool stopAfterLowestCost, MutableDouble thisSideShortest, MutableDouble otherSideShortest, double epsilon)
 {
     this.Source              = source;
     this.ShortestSoFar       = shortestSoFar;
     this.StopAfterLowestCost = stopAfterLowestCost;
     this.ThisSideShortest    = thisSideShortest;
     this.OtherSideShortest   = otherSideShortest;
     this.Epsilon             = epsilon;
 }
Beispiel #17
0
 public override TraversalBranch Next(PathExpander expander, TraversalContext metadata)
 {
     if (!HasExpandedRelationships())
     {
         ExpandRelationships(expander);
         return(this);
     }
     return(base.Next(expander, metadata));
 }
Beispiel #18
0
        /// <summary>
        /// Class constructor.
        /// </summary>
        public HashingHelper(PathTable pathTable, bool recordFingerprintString, PathExpander pathExpander = null, HashAlgorithmType hashAlgorithmType = HashAlgorithmType.SHA1Managed)
            : base(recordFingerprintString, hashAlgorithmType)
        {
            Contract.Requires(pathTable != null);

            m_pathTable = pathTable;
            m_recordFingerprintString = recordFingerprintString;
            m_pathExpander            = pathExpander ?? PathExpander.Default;
        }
Beispiel #19
0
 /// <summary>
 /// Computes content hash of this object (by serializing it and hashing the serialized bytes).
 /// </summary>
 public async Task <ContentHash> ToContentHash(PathTable pathTable, PathExpander pathExpander)
 {
     using (var pathSetBuffer = new System.IO.MemoryStream())
         using (var writer = new BuildXLWriter(stream: pathSetBuffer, debug: false, leaveOpen: true, logStats: false))
         {
             Serialize(pathTable, writer, pathExpander);
             return(await ContentHashingUtilities.HashContentStreamAsync(pathSetBuffer));
         }
 }
Beispiel #20
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReturnPathsInIncreasingOrderOfCost()
        public virtual void ShouldReturnPathsInIncreasingOrderOfCost()
        {
            /*
             *
             *      ----- (e) - 1 - (f) ---
             *    /                         \
             *   /    ------- (a) --------   \
             *  1   /            \         \  2
             *  |  2              0         0 |
             *  | /                \         \|
             * (s) - 1 - (c) - 1 - (d) - 1 - (t)
             *   \                 /
             *    -- 1 - (b) - 1 -
             *
             */

            Node s = Graph.makeNode("s");
            Node t = Graph.makeNode("t");

            Graph.makeEdgeChain("s,e,f", "length", 1.0);
            Graph.makeEdge("f", "t", "length", 2);
            Graph.makeEdge("s", "a", "length", 2);
            Graph.makeEdge("a", "t", "length", 0);
            Graph.makeEdge("s", "c", "length", 1);
            Graph.makeEdge("c", "d", "length", 1);
            Graph.makeEdge("s", "b", "length", 1);
            Graph.makeEdge("b", "d", "length", 1);
            Graph.makeEdge("d", "a", "length", 0);
            Graph.makeEdge("d", "t", "length", 1);

            PathExpander expander = PathExpanders.allTypesAndDirections();
            Dijkstra     algo     = new Dijkstra(expander, CommonEvaluators.doubleCostEvaluator("length"), PathInterestFactory.all(NoneStrictMath.EPSILON));

            IEnumerator <WeightedPath> paths = algo.FindAllPaths(s, t).GetEnumerator();

            for (int i = 1; i <= 3; i++)
            {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertTrue("Expected at least " + i + " path(s)", paths.hasNext());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertTrue("Expected 3 paths of cost 2", NoneStrictMath.Equals(paths.next().weight(), 2));
            }
            for (int i = 1; i <= 3; i++)
            {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertTrue("Expected at least " + i + " path(s)", paths.hasNext());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertTrue("Expected 3 paths of cost 3", NoneStrictMath.Equals(paths.next().weight(), 3));
            }
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertTrue("Expected at least 7 paths", paths.hasNext());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertTrue("Expected 1 path of cost 4", NoneStrictMath.Equals(paths.next().weight(), 4));
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertFalse("Expected exactly 7 paths", paths.hasNext());
        }
Beispiel #21
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(timeout = 5000) public void testForLoops()
        public virtual void TestForLoops()
        {
            /*
             *
             *            (b)
             *           /  \         0
             *          0    0       / \            - 0 - (c1) - 0 -
             *           \  /        \/           /                 \
             * (s) - 1 - (a1) - 1 - (a2) - 1 - (a3)                (a4) - 1 - (t)
             *                                    \                 /
             *                                     - 0 - (c2) - 0 -
             *
             */

            using (Transaction tx = GraphDb.beginTx())
            {
                Node s = Graph.makeNode("s");
                Node t = Graph.makeNode("t");

                // Blob loop
                Graph.makeEdge("s", "a1", "length", 1);
                Graph.makeEdge("a1", "b", "length", 0);
                Graph.makeEdge("b", "a1", "length", 0);

                // Self loop
                Graph.makeEdge("a1", "a2", "length", 1);
                Graph.makeEdge("a2", "a2", "length", 0);

                // Diamond loop
                Graph.makeEdge("a2", "a3", "length", 1);
                Graph.makeEdge("a3", "c1", "length", 0);
                Graph.makeEdge("a3", "c2", "length", 0);
                Graph.makeEdge("c1", "a4", "length", 0);
                Graph.makeEdge("c1", "a4", "length", 0);
                Graph.makeEdge("a4", "t", "length", 1);

                PathExpander expander = PathExpanders.allTypesAndDirections();
                Dijkstra     algo     = new Dijkstra(expander, CommonEvaluators.doubleCostEvaluator("length"), PathInterestFactory.all(NoneStrictMath.EPSILON));

                IEnumerator <WeightedPath> paths = algo.FindAllPaths(s, t).GetEnumerator();

//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertTrue("Expected at least one path", paths.hasNext());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertEquals("Expected first path of length 6", 6, paths.next().length());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertTrue("Expected at least two paths", paths.hasNext());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertEquals("Expected second path of length 6", 6, paths.next().length());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertFalse("Expected exactly two paths", paths.hasNext());

                tx.Success();
            }
        }
Beispiel #22
0
 protected internal virtual void ExpandRelationships(PathExpander expander)
 {
     if (Continues())
     {
         _relationships = ExpandRelationshipsWithoutChecks(expander);
     }
     else
     {
         ResetRelationships();
     }
 }
 /// <summary>
 /// Creates an instance of <see cref="PipContentFingerprinter"/>.
 /// </summary>
 /// <remarks>
 /// <see cref="PipContentFingerprinter"/> will look up the content of pip dependencies
 /// (when fingerprinting that pip) via the given callback. The new instance is thread-safe
 /// and so note that the callback may be called concurrently.
 /// </remarks>
 public PipContentFingerprinter(
     PathTable pathTable,
     ContentHashLookup contentHashLookup,
     ExtraFingerprintSalts?extraFingerprintSalts = null,
     PathExpander pathExpander   = null,
     PipDataLookup pipDataLookup = null)
     : base(pathTable, contentHashLookup, extraFingerprintSalts, pathExpander, pipDataLookup)
 {
     Contract.Requires(pathTable != null);
     Contract.Requires(contentHashLookup != null);
 }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void makeSureNodesAreTraversedInCorrectOrder()
        public virtual void MakeSureNodesAreTraversedInCorrectOrder()
        {
            PathExpander       expander = (new OrderedByTypeExpander()).add(_firstComment).add(_comment).add(_next);
            IEnumerator <Node> itr      = GraphDb.traversalDescription().depthFirst().expand(expander).traverse(Node("A1")).nodes().GetEnumerator();

            AssertOrder(itr, "A1", "C1", "C2", "C3", "A2", "C4", "C5", "C6", "A3", "C7", "C8", "C9");

            expander = (new OrderedByTypeExpander()).add(_next).add(_firstComment).add(_comment);
            itr      = GraphDb.traversalDescription().depthFirst().expand(expander).traverse(Node("A1")).nodes().GetEnumerator();
            AssertOrder(itr, "A1", "A2", "A3", "C7", "C8", "C9", "C4", "C5", "C6", "C1", "C2", "C3");
        }
Beispiel #25
0
        public override TraversalBranch Next(PathExpander expander, TraversalContext metadata)
        {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            if (_branches.hasNext())
            {
                _expanded++;
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                return(_branches.next().next(expander, metadata));
            }
            return(null);
        }
Beispiel #26
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testKShortestPaths()
        public virtual void TestKShortestPaths()
        {
            /*
             *      ----- (e) - 3 - (f) ---
             *    /                         \
             *   /    ------- (a) --------   \
             *  3   /            \         \  3
             *  |  2              0         0 |
             *  | /                \         \|
             * (s) - 1 - (c) - 1 - (d) - 1 - (t)
             *   \                 /
             *    -- 1 - (b) - 1 -
             *
             */
            Node s = Graph.makeNode("s");
            Node t = Graph.makeNode("t");

            Graph.makeEdge("s", "a", "length", 2);
            Graph.makeEdge("s", "b", "length", 1);
            Graph.makeEdge("s", "c", "length", 1);
            Graph.makeEdge("s", "e", "length", 3);
            Graph.makeEdge("a", "t", "length", 0);
            Graph.makeEdge("b", "d", "length", 1);
            Graph.makeEdge("c", "d", "length", 1);
            Graph.makeEdge("d", "a", "length", 0);
            Graph.makeEdge("d", "t", "length", 1);
            Graph.makeEdge("e", "f", "length", 3);
            Graph.makeEdge("f", "t", "length", 3);

            PathExpander expander          = PathExpanders.allTypesAndDirections();
            PathFinder <WeightedPath> algo = new Dijkstra(expander, CommonEvaluators.doubleCostEvaluator("length"), PathInterestFactory.numberOfShortest(NoneStrictMath.EPSILON, 6));

            IEnumerator <WeightedPath> paths = algo.FindAllPaths(s, t).GetEnumerator();

            int count = 0;

            while (paths.MoveNext())
            {
                count++;
                WeightedPath path = paths.Current;
                double       expectedWeight;
                if (count <= 3)
                {
                    expectedWeight = 2.0;
                }
                else
                {
                    expectedWeight = 3.0;
                }
                assertTrue("Expected path number " + count + " to have weight of " + expectedWeight, NoneStrictMath.Equals(path.Weight(), expectedWeight));
            }
            assertEquals("Expected exactly 6 returned paths", 6, count);
        }
Beispiel #27
0
        /// <nodoc />
        public PipTwoPhaseCache(LoggingContext loggingContext, EngineCache cache, PipExecutionContext context, PathExpander pathExpander)
        {
            Contract.Requires(loggingContext != null);
            Contract.Requires(cache != null);
            Contract.Requires(context != null);

            LoggingContext           = loggingContext;
            ArtifactContentCache     = cache.ArtifactContentCache;
            TwoPhaseFingerprintStore = cache.TwoPhaseFingerprintStore;
            Context        = context;
            Counters       = new CounterCollection <PipCachingCounter>();
            m_pathExpander = pathExpander;
        }
Beispiel #28
0
            private int?count(Node node, PathExpander expander)
            {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.Iterator<?> expand = expander.expand(singleNodePath(node), BranchState.NO_STATE).iterator();
                IEnumerator <object> expand = expander.expand(singleNodePath(node), BranchState.NO_STATE).GetEnumerator();
                int count = 0;

                while (expand.MoveNext())
                {
                    count++;
                }
                return(count);
            }
Beispiel #29
0
            public BestFirstSelector(BestFirstSelectorFactory <P, D> outerInstance, TraversalBranch source, P startData, PathExpander expander)
            {
                this._outerInstance = outerInstance;

                if (!InstanceFieldsInitialized)
                {
                    InitializeInstanceFields();
                    InstanceFieldsInitialized = true;
                }
                this.Current = source;
                this.CurrentAggregatedValue = startData;
                this.Expander = expander;
            }
Beispiel #30
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public JsonFingerprinter(
            StringBuilder stringBuilder,
            Formatting formatting     = Formatting.None,
            PathTable pathTable       = null,
            PathExpander pathExpander = null)
        {
            Writer            = new JsonTextWriter(new StringWriter(stringBuilder));
            Writer.Formatting = formatting;
            Writer.WriteStartObject();

            PathTable    = pathTable;
            PathExpander = pathExpander ?? PathExpander.Default;

            m_collectionFingerprinter = new JsonCollectionFingerprinter(this);
        }
Beispiel #31
0
        public override int Execute()
        {
            if (!Context.ContainsKey("file"))
            {
                return 0;
            }

            IList<string> files;

            try
            {
                var paths = new PathExpander();
                var recursive = Context.ContainsKey("recursive");
                files = paths.Expand(Environment.CurrentDirectory, Context["file"], recursive);
            }
            catch (InvalidPathException e)
            {
                Context.Error.WriteLine(e.Message);

                return 1;
            }

            if (files.Count > 0)
            {
                Task.BeforeAllExecute();

                foreach (var file in files)
                {
                    if (!ExecuteTask(file))
                    {
                        return 1;
                    }
                }

                Task.AfterAllExecute();
            }

            return 0;
        }
Beispiel #32
0
        public static MutableString/*!*/ ExpandPath(
            RubyContext/*!*/ context, 
            RubyClass/*!*/ self, 
            [DefaultProtocol, NotNull]MutableString/*!*/ path,
            [DefaultProtocol, Optional]MutableString basePath) {

            // We ignore basePath parameter if first string starts with a ~
            if (basePath == null || path.GetFirstChar() == '~') {
                return ExpandPath(context, self, path);
            } 

            string pathStr = RubyUtils.CanonicalizePath(path).ConvertToString();
            string basePathStr = RubyUtils.CanonicalizePath(basePath).ConvertToString();
            char partialDriveLetter;
            string relativePath;

            if (RubyUtils.IsAbsolutePath(pathStr)) {
                // "basePath" can be ignored is "path" is an absolute path
                PathExpander pathExpander = new PathExpander(context, pathStr);
                return pathExpander.GetResult();
            } else if (RubyUtils.HasPartialDriveLetter(pathStr, out partialDriveLetter, out relativePath)) {
                string currentDirectory = partialDriveLetter.ToString() + ":/";
                if (DirectoryExists(context, currentDirectory)) {
                    // File.expand_path("c:foo") returns "c:/current_folder_for_c_drive/foo"
                    currentDirectory = Path.GetFullPath(partialDriveLetter.ToString() + ":");
                }

                return ExpandPath(
                    context, 
                    self, 
                    MutableString.CreateMutable(relativePath), 
                    MutableString.CreateMutable(currentDirectory));
            } else if (RubyUtils.IsAbsolutePath(basePathStr)) {
                PathExpander pathExpander = new PathExpander(context, basePathStr);
                pathExpander.AddRelativePath(pathStr);
                return pathExpander.GetResult();
            } else if (RubyUtils.HasPartialDriveLetter(basePathStr, out partialDriveLetter, out relativePath)) {
                // First expand basePath
                MutableString expandedBasePath = ExpandPath(context, self, basePath);

                return ExpandPath(context, self, path, expandedBasePath);
            } else {
                // First expand basePath
                MutableString expandedBasePath = ExpandPath(context, self, basePath);
                Debug.Assert(RubyUtils.IsAbsolutePath(expandedBasePath.ConvertToString()));

                return ExpandPath(context, self, path, expandedBasePath);
            }
        }