/// <summary> /// /// </summary> /// <param name="first"></param> /// <param name="second"></param> /// <param name="p"></param> /// <param name="seed"></param> public RandomChoiceOfHeuristic(HeuristicCalculator first, HeuristicCalculator second, double p, int seed = 0) { this.first = first; this.second = second; this.p = p; this.rand = new Random(seed); }
/// <summary> /// Default constructor. /// </summary> public ClassicAStar(HeuristicCalculator heuristic = null) { this.closedList = new Dictionary <WorldState, WorldState>(); this.openList = new OpenList(this); this.heuristic = heuristic; this.queryConstraint = new CbsConstraint(); this.queryConstraint.queryInstance = true; }
static void Main(string[] args) { HeuristicCalculator.CellCalculated += new HeuristicCalculator.CellCalculatedEvent(cellCalculated); NonholonomiHeuristicInfo info = HeuristicCalculator.Calculate(150f, 0.75f, 72); Stream stream = File.Open(@"c:\rsheurnorev.dat", FileMode.Create); (new BinaryFormatter()).Serialize(stream, info); stream.Close(); }
public static void Main(string[] args) { string stopJSON; string transportAndScheduleJSON; using (WebClient webClient = new WebClient()) { stopJSON = webClient.DownloadString("https://api.trafi.com/api/stops?userLocationId=kaunas"); transportAndScheduleJSON = webClient.DownloadString("https://api.trafi.com/api/v3/schedules?userLocationId=kaunas"); } ILocationParser locationParser = new TrafiApiLocationParser(stopJSON); var locationsWithIds = ((TrafiApiLocationParser)locationParser).ParseLocationsWithIds(); ITransportParser transportParser = new TrafiApiTransportParser(transportAndScheduleJSON); var transports = transportParser.ParseTransports(locationsWithIds); IGraphFormer <AStarNode> graphFormer = new GraphFormer <AStarNode>(); var stopGraph = graphFormer.FormGraph(locationsWithIds, transports); ITransitAdder pedestrianPathAdder = new PedestrianTransitAdder(); stopGraph = pedestrianPathAdder.AddTransits(stopGraph); IWeightCalculator weightCalculator = new PenalisingWeightCalculator(new WeightCalculator()); IWeightCalculator heuristicCalculator = new HeuristicCalculator(); IPathFinder <AStarNode> pathFinder = new AStarPathFinder(stopGraph, weightCalculator, heuristicCalculator); IInputReader inputReader = new ConsoleInputReader(); IOutputWriter outputWriter = new ConsoleOutputWriter(); var stopWatch = new Stopwatch(); var startingStopID = ((ConsoleInputReader)inputReader).ReadStopID(locationsWithIds); var endingStopID = ((ConsoleInputReader)inputReader).ReadStopID(locationsWithIds); var departureTime = inputReader.ReadTime(); stopWatch.Reset(); stopWatch.Start(); var path = pathFinder.FindBestPath(stopGraph.Nodes[startingStopID], stopGraph.Nodes[endingStopID], departureTime); stopWatch.Stop(); path.Squash(); outputWriter.WriteElapsedTime(stopWatch.Elapsed); outputWriter.WritePath(path); }
public void SetHeuristic(HeuristicCalculator heuristic) { this.heuristic = heuristic; this.solver.SetHeuristic(heuristic); }
public void SetHeuristic(HeuristicCalculator heuristic) { this.heuristic = heuristic; }
public void SetHeuristic(HeuristicCalculator heuristic) { }
public AStarWithPartialExpansion(HeuristicCalculator heuristic = null, bool mstar = false, bool mstarShuffle = false) : base(heuristic, mstar, mstarShuffle) { }
public AStarWithPartialExpansionBasic(HeuristicCalculator heuristic = null) : base(heuristic) { }
public IndependenceDetection(ISolver singleAgentSolver, ISolver groupSolver, HeuristicCalculator heuristic) { this.singleAgentSolver = singleAgentSolver; this.groupSolver = groupSolver; this.heuristic = heuristic; }
public IndependenceDetection(HeuristicCalculator heuristic) : this(new ClassicAStar(heuristic), new AStarWithOD(heuristic), heuristic) { }
public Astar(IWeightedGraph <T> graph, HeuristicCalculator heuristic) { weightedGraph = graph; costHeuristic = heuristic; }
public AStarWithOD(HeuristicCalculator heuristic = null, bool mstar = false, bool mstarShuffle = false) : base(heuristic, mstar, mstarShuffle) { }
public Heuristic(HeuristicCalculator calculator) { _calculator = calculator; }
public AStarWithOD(HeuristicCalculator heuristic = null) : base(heuristic) { }
public void Tick(int ticks) { // Break if we are not working if (State != ExplorerState.Working) { return; } for (int i = 0; i < ticks; i++) { // Completed - if the queue is empty if (_workingQueue.Count == 0) { State = ExplorerState.Completed; return; } // Dequeue var current = _workingQueue.Remove(); // Discard if we already have a better solution var better = HasBetterExistingSolutionOnMap(current.X, current.Y, current.Cost); if (better) { i -= 1; continue; } // Store current solution _solution[current.X, current.Y] = current; // If the heuristic is complete if (HeuristicCalculator.Complete(current.X, current.Y)) { State = ExplorerState.Completed; return; } // Explore Neighbours for (int j = 0; j < _moveVectors.Length; j++) { var moveVector = _moveVectors[j]; // Calculate new coordinates var newX = current.X + moveVector.X; var newY = current.Y + moveVector.Y; // Discard if the cell is not open / available if (!CostCalculator.OpenCheck(current.X, current.Y, newX, newY, moveVector.X, moveVector.Y)) { continue; } // Evaluate Node int cost = current.Cost + CostCalculator.CalculateCost(current.X, current.Y, newX, newY, moveVector.X, moveVector.Y); int heuristic = HeuristicCalculator.Calculate(newX, newY); var value = heuristic + cost; // Discard if we have exceeded our maximum cost if (MaxCost.HasValue && cost > MaxCost.Value) { continue; } // Discard if we already have a better solution on map or in queue better = HasBetterExistingSolutionOnMap(newX, newY, cost); if (better) { continue; } better = HasBetterExistingSolutionInQueue(newX, newY, cost); if (better) { continue; } // Enqueue New Tile var newNode = new PathfinderNode(); newNode.X = newX; newNode.Y = newY; newNode.ParentX = current.X; newNode.ParentY = current.Y; newNode.Cost = cost; newNode.Heuristic = heuristic; newNode.Value = value; newNode.Explored = true; // Store solution in map _workingQueue.Add(newNode); } } }