/// <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);
 }
Exemple #2
0
        /// <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;
        }
Exemple #3
0
        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();
        }
Exemple #4
0
        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);
        }
Exemple #5
0
 public void SetHeuristic(HeuristicCalculator heuristic)
 {
     this.heuristic = heuristic;
     this.solver.SetHeuristic(heuristic);
 }
Exemple #6
0
 public void SetHeuristic(HeuristicCalculator heuristic)
 {
     this.heuristic = heuristic;
 }
Exemple #7
0
 public void SetHeuristic(HeuristicCalculator heuristic)
 {
 }
 public AStarWithPartialExpansion(HeuristicCalculator heuristic = null, bool mstar = false, bool mstarShuffle = false)
     : base(heuristic, mstar, mstarShuffle)
 {
 }
Exemple #9
0
 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)
 {
 }
Exemple #12
0
 public Astar(IWeightedGraph <T> graph, HeuristicCalculator heuristic)
 {
     weightedGraph = graph;
     costHeuristic = heuristic;
 }
Exemple #13
0
 public AStarWithOD(HeuristicCalculator heuristic = null, bool mstar = false, bool mstarShuffle = false)
     : base(heuristic, mstar, mstarShuffle)
 {
 }
 public Heuristic(HeuristicCalculator calculator)
 {
     _calculator = calculator;
 }
Exemple #15
0
 public AStarWithOD(HeuristicCalculator heuristic = null)
     : base(heuristic)
 {
 }
Exemple #16
0
        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);
                }
            }
        }