![]() |
AuD
Lecture 'Algorithmen und Datenstrukturen' (code examples)
|
Undirected graph that is defined implicitly by a regular 2d grid. More...
Classes | |
class | Cell |
Cell in a Grid . More... | |
class | CompareCellDistanceFromIndex |
comparator for {#link aud.PriorityQueue} compares Cell#d | |
class | CompareCellEstimatedDistanceFromIndex |
comparator for {#link aud.PriorityQueue} compares Cell#f | |
Public Member Functions | |
Grid () | |
construct an empty grid, use read_file or setup More... | |
Grid (String filename) | |
construct grid by calling read_file More... | |
void | read_file (String filename) |
read file and treat contents as cells, calls setup More... | |
void | setup (String[] lines) |
setup grid from string: create contents as grid cells More... | |
void | setup (String text) |
setup from multi-line string, e.g., EXAMPLE More... | |
int | num_rows () |
get number of rows More... | |
int | num_columns () |
get number of columns More... | |
int | size () |
get total number of cells More... | |
int | cell_index (int i, int j) |
get cell index from coordinates More... | |
int | get_row (int _index) |
get row from cell index More... | |
int | get_column (int _index) |
get columns from cell index More... | |
Cell | cell (int i, int j) |
get cell (i,j) More... | |
int[] | neighbors (int index) |
get neighbors of cell index (4-neighborhood) More... | |
int | find_first (char value) |
find first cell in grid with value @endiliteral More... | |
void | display () |
display current grid More... | |
void | reset_cells () |
reset all cells to default state but keep their values More... | |
void | dfs_recursive (int s) |
recusive DFS More... | |
void | dfs_iterative (int s0) |
iterative DFS More... | |
void | bfs (int s0) |
BFS. More... | |
void | dijkstra (int s0, int s1) |
Dijkstra. More... | |
void | astar (int s0, int s1) |
A*. More... | |
void | backtrack (int s) |
backtrack and display path to source More... | |
Static Public Member Functions | |
static void | main (String[] args) |
Public Attributes | |
int | delay = 100 |
delay in display in milliseconds More... | |
Static Public Attributes | |
static final String | EXAMPLE |
example grid (argument to setup More... | |
Protected Member Functions | |
int[] | neighbors_from_tunnels (int index) |
get neighbors of index from tunnels More... | |
int[] | create_tunnels_for (Cell cell) |
create tunnels for specified entry at cell More... | |
Static Protected Member Functions | |
static void | usage () |
print help message and exit More... | |
Undirected graph that is defined implicitly by a regular 2d grid.
The graph is defined by 4-neighborhoods (north,east,south,west) on a 2-dimensional grid. You can imagine the grid as a "pixel image" with each pixel represented as a Grid.Cell
.
For this graph, we don't use the aud.graph.AbstractGraph
interface.
We use simple "ASCII images" for input and visualization. Note that the output uses ANSI escape codes for displaying colors. Colors will be displayed correctly only on a "command window" with a terminal emulation. This is typically provided by any Unix terminal. (It will not work with the standard Windows command prompt cmd.exe
! Use the -no-color
option in this case.)
construct an empty grid, use read_file
or setup
Definition at line 115 of file Grid.java.
Referenced by aud.example.grid.Grid.main().
aud.example.grid.Grid.Grid | ( | String | filename | ) |
construct grid by calling read_file
Definition at line 118 of file Grid.java.
References aud.example.grid.Grid.read_file().
void aud.example.grid.Grid.astar | ( | int | s0, |
int | s1 | ||
) |
A*.
Definition at line 507 of file Grid.java.
References aud.PriorityQueue< T >.push(), and aud.example.grid.Grid.size().
Referenced by aud.example.grid.Grid.main().
void aud.example.grid.Grid.backtrack | ( | int | s | ) |
backtrack and display
path to source
void aud.example.grid.Grid.bfs | ( | int | s0 | ) |
BFS.
Definition at line 422 of file Grid.java.
References aud.Queue< T >.enqueue().
Referenced by aud.example.grid.Grid.main().
Cell aud.example.grid.Grid.cell | ( | int | i, |
int | j | ||
) |
get cell (i,j)
Definition at line 188 of file Grid.java.
Referenced by aud.example.grid.Grid.create_tunnels_for(), and aud.example.grid.Grid.neighbors_from_tunnels().
int aud.example.grid.Grid.cell_index | ( | int | i, |
int | j | ||
) |
|
protected |
create tunnels for specified entry at cell
Definition at line 252 of file Grid.java.
References aud.example.grid.Grid.cell(), and aud.example.grid.Grid.Cell.is_tunnel().
void aud.example.grid.Grid.dfs_iterative | ( | int | s0 | ) |
iterative DFS
Definition at line 395 of file Grid.java.
References aud.Stack< T >.push().
Referenced by aud.example.grid.Grid.main().
void aud.example.grid.Grid.dfs_recursive | ( | int | s | ) |
recusive DFS
Definition at line 377 of file Grid.java.
Referenced by aud.example.grid.Grid.main().
void aud.example.grid.Grid.dijkstra | ( | int | s0, |
int | s1 | ||
) |
Dijkstra.
Definition at line 449 of file Grid.java.
References aud.PriorityQueue< T >.push(), and aud.example.grid.Grid.size().
Referenced by aud.example.grid.Grid.main().
void aud.example.grid.Grid.display | ( | ) |
display current grid
Definition at line 317 of file Grid.java.
References aud.util.Terminal.cls(), and aud.util.Terminal.instance.
Referenced by aud.example.grid.Grid.main().
int aud.example.grid.Grid.find_first | ( | char | value | ) |
find first cell in grid with value @endiliteral
Definition at line 303 of file Grid.java.
References aud.example.grid.Grid.size().
Referenced by aud.example.grid.Grid.main().
int aud.example.grid.Grid.get_column | ( | int | _index | ) |
get columns from cell index
Definition at line 184 of file Grid.java.
Referenced by aud.example.grid.Grid.neighbors().
int aud.example.grid.Grid.get_row | ( | int | _index | ) |
get row from cell index
Definition at line 180 of file Grid.java.
Referenced by aud.example.grid.Grid.neighbors().
|
static |
Definition at line 594 of file Grid.java.
References aud.example.grid.Grid.astar(), aud.example.grid.Grid.bfs(), aud.example.grid.Grid.delay, aud.example.grid.Grid.dfs_iterative(), aud.example.grid.Grid.dfs_recursive(), aud.example.grid.Grid.dijkstra(), aud.example.grid.Grid.display(), aud.example.grid.Grid.EXAMPLE, aud.example.grid.Grid.find_first(), aud.example.grid.Grid.Grid(), aud.util.Terminal.instance, aud.example.grid.Grid.read_file(), aud.example.grid.Grid.setup(), aud.example.grid.Grid.size(), and aud.example.grid.Grid.usage().
int[] aud.example.grid.Grid.neighbors | ( | int | index | ) |
get neighbors of cell index
(4-neighborhood)
Definition at line 192 of file Grid.java.
References aud.example.grid.Grid.get_column(), and aud.example.grid.Grid.get_row().
|
protected |
get neighbors of index
from tunnels
Definition at line 233 of file Grid.java.
References aud.example.grid.Grid.cell().
int aud.example.grid.Grid.num_columns | ( | ) |
int aud.example.grid.Grid.num_rows | ( | ) |
void aud.example.grid.Grid.read_file | ( | String | filename | ) |
read file and treat contents as cells, calls setup
Definition at line 123 of file Grid.java.
References aud.example.grid.Grid.setup().
Referenced by aud.example.grid.Grid.Grid(), and aud.example.grid.Grid.main().
void aud.example.grid.Grid.reset_cells | ( | ) |
reset all cells to default state but keep their values
Definition at line 368 of file Grid.java.
References aud.example.grid.Grid.size().
void aud.example.grid.Grid.setup | ( | String | text | ) |
setup from multi-line string, e.g., EXAMPLE
Definition at line 162 of file Grid.java.
References aud.example.grid.Grid.setup().
void aud.example.grid.Grid.setup | ( | String[] | lines | ) |
setup grid from string: create contents as grid cells
Definition at line 142 of file Grid.java.
Referenced by aud.example.grid.Grid.main(), aud.example.grid.Grid.read_file(), and aud.example.grid.Grid.setup().
int aud.example.grid.Grid.size | ( | ) |
get total number of cells
Definition at line 171 of file Grid.java.
Referenced by aud.example.grid.Grid.astar(), aud.example.grid.Grid.dijkstra(), aud.example.grid.Grid.find_first(), aud.example.grid.Grid.main(), and aud.example.grid.Grid.reset_cells().
|
staticprotected |
print help message and exit
Definition at line 577 of file Grid.java.
Referenced by aud.example.grid.Grid.main().
int aud.example.grid.Grid.delay = 100 |
delay in display
in milliseconds
Definition at line 55 of file Grid.java.
Referenced by aud.example.grid.Grid.main().
|
static |
example grid (argument to setup
Definition at line 44 of file Grid.java.
Referenced by aud.example.grid.Grid.main().