public TopFetchingWeightedPathIterator(IEnumerator <Path> paths, CostEvaluator <double> costEvaluator, double epsilon) { this._paths = paths; this._costEvaluator = costEvaluator; this._epsilon = epsilon; this._foundWeight = double.MaxValue; }
/// <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; }
public WeightedPathIterator(ResourceIterator <Path> paths, CostEvaluator <double> costEvaluator, double epsilon, PathInterest interest) { this._paths = paths; this._costEvaluator = costEvaluator; this._epsilon = epsilon; this._interest = interest; }
/// <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; }
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; }
/// <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); }
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; }
/// <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; }
/// <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; }
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; }
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; }
public PathFinder <WeightedPath> dijkstra(PathExpander expander, CostEvaluator costEvaluator) { return(new Dijkstra(expander, InitialBranchState.NO_STATE, costEvaluator)); }
public AStar(CostEvaluator <NODE> g, HeuristicEvaluator <NODE> h) : this(g, h, SIMPLE_A_STAR_TOTAL_COST) { }
/// <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)); }
/// <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; }
public WeightedPathIterator(ResourceIterator <Path> paths, CostEvaluator <double> costEvaluator, double epsilon, bool stopAfterLowestWeight) : this(paths, costEvaluator, epsilon, stopAfterLowestWeight ? PathInterestFactory.AllShortest(epsilon) : PathInterestFactory.All(epsilon)) { }
/// <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) { }
public Dijkstra(PathExpander expander, CostEvaluator <double> costEvaluator, bool stopAfterLowestCost) : this(expander, costEvaluator, NoneStrictMath.EPSILON, stopAfterLowestCost ? PathInterestFactory.allShortest(NoneStrictMath.EPSILON) : PathInterestFactory.all(NoneStrictMath.EPSILON)) { }
/// <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)) { }
public static PathFinder <WeightedPath> Dijkstra(PathExpander expander, InitialBranchState stateFactory, CostEvaluator <double> costEvaluator) { return(new Dijkstra(expander, stateFactory, costEvaluator)); }
/// <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))); }
public WeightedPathIterator(ResourceIterator <Path> paths, CostEvaluator <double> costEvaluator, bool stopAfterLowestWeight) : this(paths, costEvaluator, NoneStrictMath.EPSILON, stopAfterLowestWeight) { }
public PathFinder dijkstra( PathExpander expander, CostEvaluator costEvaluator ) { return new Dijkstra( expander, costEvaluator ); }
/// <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) { }
internal DijkstraEvaluator(MutableDouble shortestSoFar, Node endNode, CostEvaluator <double> costEvaluator) { this.ShortestSoFar = shortestSoFar; this.EndNode = endNode; this.CostEvaluator = costEvaluator; }
public Dijkstra(PathExpander expander, InitialBranchState stateFactory, CostEvaluator <double> costEvaluator) : this(expander, stateFactory, costEvaluator, true) { }
public DijkstraSelectorFactory(PathInterest <double> interest, CostEvaluator <double> evaluator) : base(interest) { this._evaluator = evaluator; }
internal DijkstraBidirectionalEvaluator(CostEvaluator <double> costEvaluator) { this.CostEvaluator = costEvaluator; }