public TopFetchingWeightedPathIterator(IEnumerator <Path> paths, CostEvaluator <double> costEvaluator, double epsilon)
 {
     this._paths         = paths;
     this._costEvaluator = costEvaluator;
     this._epsilon       = epsilon;
     this._foundWeight   = double.MaxValue;
 }
Esempio n. 2
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;
 }
Esempio n. 3
0
 public WeightedPathIterator(ResourceIterator <Path> paths, CostEvaluator <double> costEvaluator, double epsilon, PathInterest interest)
 {
     this._paths         = paths;
     this._costEvaluator = costEvaluator;
     this._epsilon       = epsilon;
     this._interest      = interest;
 }
Esempio n. 4
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;
 }
Esempio n. 5
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;
 }
Esempio n. 6
0
        /// <summary>
        /// Creates a new AStar algorithm instance with the provided start and goal nodes.
        /// </summary>
        /// <param name="g">a function that, given a particular node, computes what is the cost for reaching such node</param>
        /// <param name="h">a function that, given a particular node, computes an estimate for reaching the goal state</param>
        /// <param name="totalCostComputer">A function that, given the output of both "g" and "h", retrieve the total cost of the state</param>
        public AStar(CostEvaluator <NODE> g, HeuristicEvaluator <NODE> h, BiFunction totalCostComputer)
        {
            var duplicateComparer = new DuplicateComparer();

            this.Heuristic         = h;
            this.CostFunction      = g;
            this.TotalCostComputer = totalCostComputer;
            openList   = new SortedList <int, Triple <NODE, int, int> >(duplicateComparer);
            closedList = new SortedList <int, Triple <NODE, int, int> >(duplicateComparer);
        }
Esempio n. 7
0
        public WeightedPathImpl(CostEvaluator <double> costEvaluator, Path path)
        {
            this._path = path;
            double cost = 0;

            foreach (Relationship relationship in path.Relationships())
            {
                cost += costEvaluator.GetCost(relationship, Direction.OUTGOING);
            }
            this._weight = cost;
        }
Esempio n. 8
0
 /// <param name="startCost">
 ///            The cost for just starting (or ending) a path in a node. </param>
 /// <param name="infinitelyBad">
 ///            A cost worse than all others. This is used to initialize the
 ///            distance matrix. </param>
 /// <param name="relationDirection">
 ///            The direction in which the paths should follow the
 ///            relationships. </param>
 /// <param name="costEvaluator"> </param>
 /// <seealso cref= <seealso cref="CostEvaluator"/> </seealso>
 /// <param name="costAccumulator"> </param>
 /// <seealso cref= <seealso cref="CostAccumulator"/> </seealso>
 /// <param name="costComparator"> </param>
 /// <seealso cref= <seealso cref="CostAccumulator"/> or <seealso cref="CostEvaluator"/> </seealso>
 /// <param name="nodeSet">
 ///            The set of nodes the calculation should be run on. </param>
 /// <param name="relationshipSet">
 ///            The set of relationships that should be processed. </param>
 public FloydWarshall(CostType startCost, CostType infinitelyBad, Direction relationDirection, CostEvaluator <CostType> costEvaluator, CostAccumulator <CostType> costAccumulator, IComparer <CostType> costComparator, ISet <Node> nodeSet, ISet <Relationship> relationshipSet) : base()
 {
     this.StartCost         = startCost;
     this.InfinitelyBad     = infinitelyBad;
     this.RelationDirection = relationDirection;
     this.CostEvaluator     = costEvaluator;
     this.CostAccumulator   = costAccumulator;
     this.CostComparator    = costComparator;
     this.NodeSet           = nodeSet;
     this.RelationshipSet   = relationshipSet;
 }
Esempio n. 9
0
 /// <param name="startCost"> Starting cost for both the start node and the end node </param>
 /// <param name="startNode"> the start node </param>
 /// <param name="endNode"> the end node </param>
 /// <param name="costRelationTypes"> the relationship that should be included in the
 ///            path </param>
 /// <param name="relationDirection"> relationship direction to follow </param>
 /// <param name="costEvaluator"> the cost function per relationship </param>
 /// <param name="costAccumulator"> adding up the path cost </param>
 /// <param name="costComparator"> comparing to path costs </param>
 public Dijkstra(CostType startCost, Node startNode, Node endNode, CostEvaluator <CostType> costEvaluator, CostAccumulator <CostType> costAccumulator, IComparer <CostType> costComparator, Direction relationDirection, params RelationshipType[] costRelationTypes) : base()
 {
     this.StartCost         = startCost;
     this.StartNodeConflict = startNode;
     this.EndNodeConflict   = endNode;
     this.CostRelationTypes = costRelationTypes;
     this.RelationDirection = relationDirection;
     this.CostEvaluator     = costEvaluator;
     this.CostAccumulator   = costAccumulator;
     this.CostComparator    = costComparator;
 }
Esempio n. 10
0
            public Disposition(int?RobotAt, int BoxesCount, CostEvaluator FullCost)
            {
                boxAt = new int[BoxesCount];
                for (int i = 0; i < BoxesCount; boxAt[i] = i++)
                {
                    ;
                }

                robotAt = RobotAt;

                fullCost = FullCost;
            }
Esempio n. 11
0
            public Disposition(Disposition disposition)
            {
                boxAt = new int[disposition.boxAt.Length];
                for (int i = 0; i < boxAt.Length; i++)
                {
                    boxAt[i] = disposition.boxAt[i];
                }

                robotAt     = disposition.robotAt;
                fullCost    = disposition.fullCost;
                parent      = disposition;
                currentCost = disposition.currentCost;
            }
Esempio n. 12
0
 public PathFinder <WeightedPath> dijkstra(PathExpander expander, CostEvaluator costEvaluator)
 {
     return(new Dijkstra(expander, InitialBranchState.NO_STATE, costEvaluator));
 }
Esempio n. 13
0
 public AStar(CostEvaluator <NODE> g, HeuristicEvaluator <NODE> h) : this(g, h, SIMPLE_A_STAR_TOTAL_COST)
 {
 }
Esempio n. 14
0
 /// <summary>
 /// Returns an <seealso cref="PathFinder"/> which uses the A* algorithm to find the
 /// cheapest path between two nodes. The definition of "cheap" is the lowest
 /// possible cost to get from the start node to the end node, where the cost
 /// is returned from {@code lengthEvaluator} and {@code estimateEvaluator}.
 /// These returned paths cannot contain loops (i.e. a node cannot occur more
 /// than once in any returned path).
 ///
 /// See http://en.wikipedia.org/wiki/A*_search_algorithm for more
 /// information.
 /// </summary>
 /// <param name="expander"> the <seealso cref="PathExpander"/> to use for expanding
 /// <seealso cref="Relationship"/>s for each <seealso cref="Path"/>. </param>
 /// <param name="lengthEvaluator"> evaluator that can return the cost represented
 /// by each relationship the algorithm traverses. </param>
 /// <param name="estimateEvaluator"> evaluator that returns an (optimistic)
 /// estimation of the cost to get from the current node (in the traversal)
 /// to the end node. </param>
 /// <returns> an algorithm which finds the cheapest path between two nodes
 /// using the A* algorithm. </returns>
 public static PathFinder <WeightedPath> AStar(PathExpander expander, CostEvaluator <double> lengthEvaluator, EstimateEvaluator <double> estimateEvaluator)
 {
     return(new AStar(expander, lengthEvaluator, estimateEvaluator));
 }
Esempio n. 15
0
 /// <summary>
 /// Returns a <seealso cref="PathFinder"/> which uses the Dijkstra algorithm to find
 /// the cheapest path between two nodes. The definition of "cheap" is the
 /// lowest possible cost to get from the start node to the end node, where
 /// the cost is returned from {@code costEvaluator}. These returned paths
 /// cannot contain loops (i.e. a node cannot occur more than once in any
 /// returned path).
 ///
 /// Dijkstra assumes none negative costs on all considered relationships.
 /// If this is not the case behaviour is undefined. Do not use Dijkstra
 /// with negative weights or use a <seealso cref="CostEvaluator"/> that handles
 /// negative weights.
 ///
 /// See http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm for more
 /// information.
 /// </summary>
 /// <param name="expander"> the <seealso cref="PathExpander"/> to use for expanding
 /// <seealso cref="Relationship"/>s for each <seealso cref="Path"/>. </param>
 /// <param name="costEvaluator"> evaluator that can return the cost represented
 /// by each relationship the algorithm traverses. </param>
 /// <returns> an algorithm which finds the cheapest path between two nodes
 /// using the Dijkstra algorithm. </returns>
 public static PathFinder <WeightedPath> Dijkstra(PathExpander expander, CostEvaluator <double> costEvaluator)
 {
     return(new DijkstraBidirectional(expander, costEvaluator));
 }
 public DijkstraBranchCollisionDetector(Evaluator evaluator, CostEvaluator costEvaluator, MutableDouble shortestSoFar, double epsilon, System.Predicate <Path> pathPredicate) : base(evaluator, pathPredicate)
 {
     this._costEvaluator = costEvaluator;
     this._shortestSoFar = shortestSoFar;
     this._epsilon       = epsilon;
 }
Esempio n. 17
0
 public WeightedPathIterator(ResourceIterator <Path> paths, CostEvaluator <double> costEvaluator, double epsilon, bool stopAfterLowestWeight) : this(paths, costEvaluator, epsilon, stopAfterLowestWeight ? PathInterestFactory.AllShortest(epsilon) : PathInterestFactory.All(epsilon))
 {
 }
Esempio n. 18
0
 /// <summary>
 /// See <seealso cref="Dijkstra(PathExpander, CostEvaluator, double, PathInterest)"/>
 /// Use <seealso cref="NoneStrictMath.EPSILON"/> as tolerance.
 /// </summary>
 public Dijkstra(PathExpander expander, CostEvaluator <double> costEvaluator, PathInterest <double> interest) : this(expander, costEvaluator, NoneStrictMath.EPSILON, interest)
 {
 }
Esempio n. 19
0
 public Dijkstra(PathExpander expander, CostEvaluator <double> costEvaluator, bool stopAfterLowestCost) : this(expander, costEvaluator, NoneStrictMath.EPSILON, stopAfterLowestCost ? PathInterestFactory.allShortest(NoneStrictMath.EPSILON) : PathInterestFactory.all(NoneStrictMath.EPSILON))
 {
 }
Esempio n. 20
0
 /// <summary>
 /// See <seealso cref="Dijkstra(PathExpander, CostEvaluator, double, PathInterest)"/>
 /// Use <seealso cref="NoneStrictMath.EPSILON"/> as tolerance.
 /// Use <seealso cref="PathInterestFactory.allShortest(double)"/> as PathInterest.
 /// </summary>
 public Dijkstra(PathExpander expander, CostEvaluator <double> costEvaluator) : this(expander, costEvaluator, PathInterestFactory.allShortest(NoneStrictMath.EPSILON))
 {
 }
Esempio n. 21
0
 public static PathFinder <WeightedPath> Dijkstra(PathExpander expander, InitialBranchState stateFactory, CostEvaluator <double> costEvaluator)
 {
     return(new Dijkstra(expander, stateFactory, costEvaluator));
 }
Esempio n. 22
0
 /// <summary>
 /// See <seealso cref="dijkstra(PathExpander, CostEvaluator)"/> for documentation
 ///
 /// Instead of finding all shortest paths with equal cost, find the top {@code numberOfWantedPaths} paths.
 /// This is usually slower than finding all shortest paths with equal cost.
 /// </summary>
 /// <param name="expander"> the <seealso cref="PathExpander"/> to use for expanding
 /// <seealso cref="Relationship"/>s for each <seealso cref="Path"/>. </param>
 /// <param name="costEvaluator"> evaluator that can return the cost represented
 /// by each relationship the algorithm traverses. </param>
 /// <param name="numberOfWantedPaths"> number of paths to find. </param>
 /// <returns> an algorithm which finds the cheapest path between two nodes
 /// using the Dijkstra algorithm. </returns>
 public static PathFinder <WeightedPath> Dijkstra(PathExpander expander, CostEvaluator <double> costEvaluator, int numberOfWantedPaths)
 {
     return(new Dijkstra(expander, costEvaluator, NoneStrictMath.EPSILON, PathInterestFactory.numberOfShortest(NoneStrictMath.EPSILON, numberOfWantedPaths)));
 }
Esempio n. 23
0
 public WeightedPathIterator(ResourceIterator <Path> paths, CostEvaluator <double> costEvaluator, bool stopAfterLowestWeight) : this(paths, costEvaluator, NoneStrictMath.EPSILON, stopAfterLowestWeight)
 {
 }
Esempio n. 24
0
														public PathFinder dijkstra( PathExpander expander, CostEvaluator costEvaluator )
														{
															 return new Dijkstra( expander, costEvaluator );
														}
Esempio n. 25
0
 /// <summary>
 /// See <seealso cref="DijkstraBidirectional(PathExpander, CostEvaluator, double)"/>
 /// Using <seealso cref="NoneStrictMath.EPSILON"/> as tolerance.
 /// </summary>
 public DijkstraBidirectional(PathExpander expander, CostEvaluator <double> costEvaluator) : this(expander, costEvaluator, NoneStrictMath.EPSILON)
 {
 }
 public TopFetchingWeightedPathIterator(IEnumerator <Path> paths, CostEvaluator <double> costEvaluator) : this(paths, costEvaluator, NoneStrictMath.EPSILON)
 {
 }
Esempio n. 27
0
 internal DijkstraEvaluator(MutableDouble shortestSoFar, Node endNode, CostEvaluator <double> costEvaluator)
 {
     this.ShortestSoFar = shortestSoFar;
     this.EndNode       = endNode;
     this.CostEvaluator = costEvaluator;
 }
Esempio n. 28
0
 public Dijkstra(PathExpander expander, InitialBranchState stateFactory, CostEvaluator <double> costEvaluator) : this(expander, stateFactory, costEvaluator, true)
 {
 }
Esempio n. 29
0
 public DijkstraSelectorFactory(PathInterest <double> interest, CostEvaluator <double> evaluator) : base(interest)
 {
     this._evaluator = evaluator;
 }
Esempio n. 30
0
 internal DijkstraBidirectionalEvaluator(CostEvaluator <double> costEvaluator)
 {
     this.CostEvaluator = costEvaluator;
 }