A list of puns related to "Lexicographic breadth first search"
So I was asked the following problem :
Let G be the nine-vertex grid graph with vertices a, b, c, d, e, f, g, h, i and edges ab, bc, de, ef, gh, hi, ad, dg, be, eh, cf, and fi. Find a lexicographic breadth first search ordering for G, starting from vertex a.
The issue is that I don't understand how to obtain a lexicographic breadth first ordering.
According to the wiki (http://en.wikipedia.org/wiki/Lexicographic_breadth-first_search) the first steps are to "Initialize a sequence Σ of sets, to contain a single set containing all vertices", but I'm not sure what this means :(
I'd appreciate any help at all. Thanks! :)
I had a problem where I had to search a 2D array and was wondering if BFS and DFS would make sense with that kind of data structure.
I want an AI to be able to move between isolated node graphs, essentially platforms. I already have A* for movement within the platforms, but between them is where I'm stuck. To move between two platforms, the AI would have do specific things corresponding to the environment around the two platforms, not simply physically jump from one to another. I don't want to optimize the distance traveled, just the number of crossings done. The platforms can take on any shape, size, and distance from one another. Not all platforms can go to all others.
So I did some searching and found depth-first searching and breadth-first searching but I just want an opinion on the best way to proceed, which is faster, etc.
Hey guys, how you doing?
Im here to ask for you help. Im writing my bachelor paper as an implementation/review of the TPP algorithms out there. Almost every paper that I read references the Ramesh algorithm, that returns an exact solution for TPP problems, but I just can't find the algorithm, not even a high level description that I could use to implement my own version.
Does someone know how to implement it? I would be grateful with even a high level description.
There's other two approaches out there that I would be grateful to have access: the branch-and-bound algorithm of Singh and Van Oudheusden, and the branch-and-cut algorithm of Laporte. If someone know how to implement or something like that, please share with me.
In these two papers, you can find the actual references:
- https://ir.nctu.edu.tw/bitstream/11536/31784/1/000075284000001.pdf
- https://www.fsa.ulaval.ca/personnel/renaudj/pdf/Recherche/tpp(purchaser)%20COR.pdf
If you don't what's the TPP, please see this link: https://en.wikipedia.org/wiki/Traveling_purchaser_problem before answering
Guys, I know that this is an NP-HARD problem, and that it's always best to use Heuristic Algorithms instead of exact ones for larger instances, but I still want to study the exact ones.
Thanks! Any help is very welcome.
Just to mention, the program runs with the help of the OLCPixelGameEngine library for convenience sake thus I will post the github repository to make it easier for people to test.
Source: https://github.com/xGainzMan555x/Breadth-First-Search-visualizer
All the details are listen in the README file.
In short the error happens when adding an obstacle to a certain part of the grid or when the key for the start of the algorithm is pressed and the start and end nodes are added.
I will also paste the code here if anyone wants to look at it here first.
#define OLC_PGE_APPLICATION
#include "olcPixelGameEngine.h"
#include <iostream>
#include <queue>
class BreadthFirstSearch : public olc::PixelGameEngine
{
struct Node
{
int x;
int y;
};
Node *node = nullptr;
Node* rootNode = nullptr;
Node* endNode = nullptr;
int gap = 30; // gap is gotten by dividing the screen width (or height since both are 600 pixels) by the number of rows or columns (both of which are 20)
public:
BreadthFirstSearch()
{
sAppName = "Breadth-First search visualizer";
}
public:
bool OnUserCreate() override
{
Clear(olc::WHITE);
node = new Node[400]; // This is a 20x20 grid so in total there are 400 members
for (int x = 0; x < 20; x++)
{
for (int y = 0; y < 20; y++)
{
DrawLine(x, y * gap, 600, y * gap, olc::BLACK); // Draw rows
DrawLine(x * gap, y, x * gap, 600, olc::BLACK); // Draw columns
// Saving the coordinates for the nodes
node[y * 20 + x].x = x;
node[y * 20 + x].y = y;
}
}
return true;
}
bool OnUserUpdate(float fElapsedTime) override
{
// Gets the coordinates for the mouse position.
int mouseX = (GetMouseX() / gap) * gap;
int mouseY = (GetMouseY() / gap) * gap;
// Variables for storing the coordinates
int startingRow;
int startingColumn;
int endRow{};
int endColumn{};
// Bool variables for checking the validity of the node
bool reachedEnd = false;
bool obstacle[20][20];
bool visited[20][20];
// This is used when searching for neighbours of a node (top, bottom, right, left)
int directionRow[4] = { +1, -1, 0, 0 };
int directionColumn[4] = { 0, 0, +1 ,-1 };
// Queues f
... keep reading on reddit ➡I'm trying to create an exercise that showcases a societal use of breadth-first search? That is an application of breadth-first search that benefits society: breadth-first search helps people find transplant donors, something like that, for instance. And it can't be too obvious, like finding the optimal route from A to B or something.
I haven't been able to come up with anything satisfactory despite my numerous Google searches. I would really appreciate any suggestions.
I understand DFS, but BFS is just really hard for me to wrap my head around. I know that it kind of moves out across a tree like a ripple effect, but how would that be coded? DFS is just going left till you get to the end then moving right, I think. But how could you move an entire level down at one time?
My professor mentioned how BFS can give you the shortest path from the source vertex to the destination vertex, which makes sense since you traverse the adjacent nodes. However, I do not see how that is guaranteed to happen always. Nowhere in the BFS pseudocode logic do I see to pick the correct adjacent node to guarantee to have the shortest path. BFS could pick any random adjacent node and end up with the longer path from the source vertex to the destination vertex. Then how does BFS give the shortest path from the source vertex to the destination vertex?
For example:
Let's say I ran BFS on the below graph: could it not find the path from S to Y to be to S to W to T to X to U to Y, which would not be the shortest path?
I was doing more leetcode when I realized I was rusty on BFS, so I set out to implement it in Racket. Here is my implementation. It takes an adjacency list (a list where each element is a list of the connected nodes for that node index) and the start/source node as input and returns the predecessor array. The queue is something I implemented based on Okasaki's Purely Functional Data Structures (minus the laziness, I'm still figuring out laziness in Racket by reading through code in the pfds collection).
(define (breadth-first-search g s)
(let* ([n (length g)]
[gvec (list->vector g)]
[color (make-vector n 0)]
[d (make-vector n -1)]
[p (make-vector n -1)]
[q (make-queue)])
(vector-set! color s 1)
(vector-set! d s 0)
(queue-push q s)
(do ([u (queue-head q) (queue-head q)])
((queue-empty? q)
p)
(for-each (lambda (v)
(when (zero? (vector-ref color v))
(vector-set! color v 1)
(vector-set! d v (add1 (vector-ref d u)))
(vector-set! p v u)
(queue-push q v)))
(vector-ref gvec u))
(queue-pop q)
(vector-set! color u 2))))
This code works, but it feels very imperative to me. This is partly because of the vectors that I used since I wanted O(1) access to vector elements. The do
also feels weird, though I have don't know of a better way to iterate when the iteration is not over a sequence. Is there a way to convert something like a queue into a sequence? It feels like that might be connected to laziness. Lastly, I mentioned the pfds collection above, is there something that prevents me from using typed Racket in a normal Racket program, i.e. are types an all-or-none proposition?
I know that DFS is one of the most important topics in silver but what about BFS? Does that show up too often?
Side question: Will I need to know dynamic programming in Silver?
Thank you!
Just to mention, the program runs with the help of the OLCPixelGameEngine library for convenience sake thus I will post the github repository to make it easier for people to test.
Source: https://github.com/xGainzMan555x/Breadth-First-Search-visualizer
All the details are listen in the README file.
The errors happen when 1.) Obstacle nodes are being added and a certain part of the grid is passed 2.) When the start and end nodes are placed (without barriers) and the space button is pressed for the algorithm to begin. I have no clue why this happens since it seems to me that everything is initialized. What is actually supposed to happen is that, when the alogrithm starts, it checks the neighbours of the start node first before checking the neighbour of the neighbour etc. After checking the neighbour if the node is not visited or an obstacle it is colored blue and marked as visited. This, of course, does not work for now but the code for it is added.
I will also paste the code here if anyone wants to look at it here first.
#define OLC_PGE_APPLICATION
#include "olcPixelGameEngine.h"
#include <iostream>
#include <queue>
class BreadthFirstSearch : public olc::PixelGameEngine
{
struct Node
{
int x;
int y;
};
Node *node = nullptr;
Node* rootNode = nullptr;
Node* endNode = nullptr;
int gap = 30; // gap is gotten by dividing the screen width (or height since both are 600 pixels) by the number of rows or columns (both of which are 20)
public:
BreadthFirstSearch()
{
sAppName = "Breadth-First search visualizer";
}
public:
bool OnUserCreate() override
{
Clear(olc::WHITE);
node = new Node[400]; // This is a 20x20 grid so in total there are 400 members
for (int x = 0; x < 20; x++)
{
for (int y = 0; y < 20; y++)
{
DrawLine(x, y * gap, 600, y * gap, olc::BLACK); // Draw rows
DrawLine(x * gap, y, x * gap, 600, olc::BLACK); // Draw columns
// Saving the coordinates for the nodes
node[y * 20 + x].x = x;
node[y * 20 + x].y = y;
}
}
return true;
}
bool OnUserUpdate(float fElapsedTime) override
{
// Gets the coordinates for the mouse position.
int mouseX = (GetMouseX() / gap) * gap;
int mouseY = (GetMouseY() / gap) * gap;
... keep reading on reddit ➡Please note that this site uses cookies to personalise content and adverts, to provide social media features, and to analyse web traffic. Click here for more information.