예제 #1
0
파일: Dijkstra.cs 프로젝트: Neo4Net/Neo4Net
//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;
            }
예제 #2
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: private org.neo4j.graphdb.traversal.Traverser traverser(org.neo4j.graphdb.Node start, final org.neo4j.graphdb.Node end, org.neo4j.graphalgo.impl.util.PathInterest interest)
        private Traverser Traverser(Node start, Node end, PathInterest interest)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.apache.commons.lang3.mutable.MutableDouble shortestSoFar = new org.apache.commons.lang3.mutable.MutableDouble(Double.MAX_VALUE);
            MutableDouble shortestSoFar = new MutableDouble(double.MaxValue);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.apache.commons.lang3.mutable.MutableDouble startSideShortest = new org.apache.commons.lang3.mutable.MutableDouble(0);
            MutableDouble startSideShortest = new MutableDouble(0);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.apache.commons.lang3.mutable.MutableDouble endSideShortest = new org.apache.commons.lang3.mutable.MutableDouble(0);
            MutableDouble endSideShortest  = new MutableDouble(0);
            PathExpander  dijkstraExpander = new DijkstraBidirectionalPathExpander(_expander, shortestSoFar, true, startSideShortest, endSideShortest, _epsilon);

            GraphDatabaseService db = start.GraphDatabase;

            TraversalDescription side = Db.traversalDescription().expand(dijkstraExpander, _stateFactory).order(new DijkstraSelectorFactory(interest, _costEvaluator)).evaluator(new DijkstraBidirectionalEvaluator(_costEvaluator)).uniqueness(Uniqueness.NODE_PATH);

            TraversalDescription startSide = side;
            TraversalDescription endSide   = side.Reverse();

            BidirectionalTraversalDescription traversal = Db.bidirectionalTraversalDescription().startSide(startSide).endSide(endSide).collisionEvaluator(Evaluators.all()).collisionPolicy((evaluator, pathPredicate) => new DijkstraBranchCollisionDetector(evaluator, _costEvaluator, shortestSoFar, _epsilon, pathPredicate));

            _lastTraverser = traversal.Traverse(start, end);
            return(_lastTraverser);
        }
예제 #3
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;
 }
예제 #4
0
        /// <summary>
        /// This is used internally to the class for getting back a
        /// MutableDouble in a remove operation.
        /// </summary>
        /// <remarks>
        /// This is used internally to the class for getting back a
        /// MutableDouble in a remove operation.  Not for public use.
        /// </remarks>
        /// <param name="key">The key to remove</param>
        /// <returns>Its value as a MutableDouble</returns>
        private MutableDouble MutableRemove(E key)
        {
            MutableDouble md = Sharpen.Collections.Remove(map, key);

            if (md != null)
            {
                totalCount -= md;
            }
            return(md);
        }
예제 #5
0
        /// <summary>
        /// <inheritDoc/>
        ///
        /// </summary>
        public virtual double Remove(E key)
        {
            MutableDouble d = MutableRemove(key);

            // this also updates totalCount
            if (d != null)
            {
                return(d);
            }
            return(defaultValue);
        }
예제 #6
0
 /* this is (non-tail) recursive right now, haven't figured out a way
  * to speed it up */
 private ICollection <KeyValuePair <object, double> > EntrySet(ICollection <KeyValuePair <object, double> > s, object[] key, bool useLists)
 {
     if (depth == 1)
     {
         //System.out.println("key is long enough to add to set");
         ICollection <K> keys = map.Keys;
         foreach (K finalKey in keys)
         {
             // array doesn't escape
             K[] newKey = ErasureUtils.MkTArray <K>(typeof(object), key.Length + 1);
             if (key.Length > 0)
             {
                 System.Array.Copy(key, 0, newKey, 0, key.Length);
             }
             newKey[key.Length] = finalKey;
             MutableDouble value  = (MutableDouble)map[finalKey];
             double        value1 = value;
             if (useLists)
             {
                 s.Add(new GeneralizedCounter.Entry <object, double>(Arrays.AsList(newKey), value1));
             }
             else
             {
                 s.Add(new GeneralizedCounter.Entry <object, double>(newKey[0], value1));
             }
         }
     }
     else
     {
         ICollection <K> keys = map.Keys;
         //System.out.println("key length " + key.length);
         //System.out.println("keyset level " + depth + " " + keys);
         foreach (K o in keys)
         {
             object[] newKey = new object[key.Length + 1];
             if (key.Length > 0)
             {
                 System.Array.Copy(key, 0, newKey, 0, key.Length);
             }
             newKey[key.Length] = o;
             //System.out.println("level " + key.length + " current key " + Arrays.asList(newKey));
             ConditionalizeHelper(o).EntrySet(s, newKey, true);
         }
     }
     //System.out.println("leaving key length " + key.length);
     return(s);
 }
예제 #7
0
        /// <summary>
        /// <inheritDoc/>
        ///
        /// </summary>
        public virtual double IncrementCount(E key, double count)
        {
            if (tempMDouble == null)
            {
                tempMDouble = new MutableDouble();
            }
            MutableDouble oldMDouble = map[key] = tempMDouble;

            totalCount += count;
            if (oldMDouble != null)
            {
                count += oldMDouble;
            }
            tempMDouble.Set(count);
            tempMDouble = oldMDouble;
            return(count);
        }
예제 #8
0
 /// <summary>
 /// <inheritDoc/>
 ///
 /// </summary>
 public virtual void SetCount(E key, double count)
 {
     if (tempMDouble == null)
     {
         //System.out.println("creating mdouble");
         tempMDouble = new MutableDouble();
     }
     //System.out.println("setting mdouble");
     tempMDouble.Set(count);
     //System.out.println("putting mdouble in map");
     tempMDouble = map[key] = tempMDouble;
     //System.out.println("placed mDouble in map");
     totalCount += count;
     if (tempMDouble != null)
     {
         totalCount -= tempMDouble;
     }
 }
예제 #9
0
        public virtual int getCategoryWithMaxValue(IDictionary <int, MutableDouble> catSimilarities)
        {
            double max = int.MinValue;
            int    catWithMaxSimilarity = -1;

            foreach (int category in catSimilarities.Keys)
            {
                MutableDouble mutableDouble = null;
                catSimilarities.TryGetValue(category, out mutableDouble);
                if (mutableDouble.d > max)
                {
                    max = mutableDouble.d;
                    catWithMaxSimilarity = category;
                }
            }

            return(catWithMaxSimilarity);
        }
예제 #10
0
        // get category similarity (1.0-distance) so we can weight votes. Just add up similarity.
        // I.e., weight votes with similarity 1 (distances of 0) more than votes with lower similarity
        // If we have 2 votes of distance 0.2 and 1 vote of distance 0, it means
        // we have 2 votes of similarity .8 and 1 of similarity of 1, 1.6 vs 6.
        // The votes still outweigh the similarity in this case. For a tie, however,
        // the weights will matter.
        public virtual IDictionary <int, MutableDouble> getCategoryToSimilarityMap(Neighbor[] kNN, int k, IList <int> Y)
        {
            IDictionary <int, MutableDouble> catSimilarities = new Dictionary <int, MutableDouble>();

            for (int i = 0; i < k && i < kNN.Length; i++)
            {
                int           y = Y[kNN[i].corpusVectorIndex];
                MutableDouble d = null;
                catSimilarities.TryGetValue(y, out d);
                if (d == null)
                {
                    d = new MutableDouble(0.0);
                    catSimilarities[y] = d;
                }
                double emphasizedDistance = Math.Pow(kNN[i].distance, 1.0 / 3);                 // cube root
                d.add(1.0 - emphasizedDistance);
            }
            return(catSimilarities);
        }
예제 #11
0
파일: Dijkstra.cs 프로젝트: Neo4Net/Neo4Net
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
//ORIGINAL LINE: private org.neo4j.graphdb.traversal.Traverser traverser(org.neo4j.graphdb.Node start, final org.neo4j.graphdb.Node end, org.neo4j.graphalgo.impl.util.PathInterest<double> interest)
        private Traverser Traverser(Node start, Node end, PathInterest <double> interest)
        {
            PathExpander  dijkstraExpander;
            PathEvaluator dijkstraEvaluator;

            if (_stateInUse)
            {
                dijkstraExpander  = _expander;
                dijkstraEvaluator = Evaluators.includeWhereEndNodeIs(end);
            }
            else
            {
                MutableDouble shortestSoFar = new MutableDouble(double.MaxValue);
                dijkstraExpander  = new DijkstraPathExpander(_expander, shortestSoFar, _epsilon, interest.StopAfterLowestCost());
                dijkstraEvaluator = new DijkstraEvaluator(shortestSoFar, end, _costEvaluator);
            }
            _lastTraverser = (new MonoDirectionalTraversalDescription()).uniqueness(Uniqueness.NODE_PATH).expand(dijkstraExpander, _stateFactory).order(new DijkstraSelectorFactory(interest, _costEvaluator)).evaluator(dijkstraEvaluator).traverse(start);
            return(_lastTraverser);
        }
예제 #12
0
        /// <summary>
        /// Equivalent to <code>
        /// <see cref="GeneralizedCounter{K}.IncrementCount(System.Collections.IList{E})"/>
        /// ({o}, count)</code>;
        /// only works for a depth 1 GeneralizedCounter.
        /// </summary>
        public virtual void IncrementCount1D(K o, double count)
        {
            if (depth > 1)
            {
                WrongDepth();
            }
            AddToTotal(count);
            if (tempMDouble == null)
            {
                tempMDouble = new MutableDouble();
            }
            tempMDouble.Set(count);
            MutableDouble oldMDouble = (MutableDouble)map[o] = tempMDouble;

            if (oldMDouble != null)
            {
                tempMDouble.Set(count + oldMDouble);
            }
            tempMDouble = oldMDouble;
        }
예제 #13
0
        /// <summary>
        /// <inheritDoc/>
        ///
        /// </summary>
        public virtual double LogIncrementCount(E key, double count)
        {
            if (tempMDouble == null)
            {
                tempMDouble = new MutableDouble();
            }
            MutableDouble oldMDouble = map[key] = tempMDouble;

            if (oldMDouble != null)
            {
                count       = SloppyMath.LogAdd(count, oldMDouble);
                totalCount += count - oldMDouble;
            }
            else
            {
                totalCount += count;
            }
            tempMDouble.Set(count);
            tempMDouble = oldMDouble;
            return(count);
        }
예제 #14
0
파일: Dijkstra.cs 프로젝트: Neo4Net/Neo4Net
 internal DijkstraEvaluator(MutableDouble shortestSoFar, Node endNode, CostEvaluator <double> costEvaluator)
 {
     this.ShortestSoFar = shortestSoFar;
     this.EndNode       = endNode;
     this.CostEvaluator = costEvaluator;
 }