Solving a Logic Maze: Shortest Path to the Goal

  • Context: Graduate 
  • Thread starter Thread starter madameChing
  • Start date Start date
  • Tags Tags
    Logic Path
Click For Summary

Discussion Overview

The discussion revolves around solving a logic maze using a "solver" program that requires defining sorts, functions, and clauses to find the shortest path from a starting position to a goal while avoiding obstacles. Participants explore various approaches to represent the problem and suggest methods for the solver to determine valid paths.

Discussion Character

  • Exploratory
  • Technical explanation
  • Mathematical reasoning

Main Points Raised

  • One participant describes the maze setup, including the grid layout and the need for the robot to navigate from square Ad to square Dd while avoiding blocked squares.
  • Participants discuss the definition of sorts, functions, and clauses necessary for the solver to operate effectively, with emphasis on the need for predicates that account for obstacles and valid moves.
  • Another participant proposes a simple algorithm for determining the path, suggesting the use of an array to represent the grid and iterating through cells to assign values based on adjacent cells.
  • There is mention of optimizing the algorithm by reevaluating only adjacent cells that have changed and considering barriers in the grid layout.
  • Concerns are raised about the algorithm potentially finding equivalent paths that may not be represented in the initial solution provided by the original poster.

Areas of Agreement / Disagreement

Participants express varying levels of familiarity with the logic scheme and the proposed algorithm. While some agree on the need for certain conditions to define valid moves, there is no consensus on the best approach to implement the solution or the effectiveness of the proposed methods.

Contextual Notes

Participants highlight the complexity of defining the clauses and the potential for multiple valid paths. The discussion includes assumptions about the grid layout and the behavior of the solver that may not be fully resolved.

madameChing
Messages
2
Reaction score
0
Hi guys,

I'm new to logic and have a logic maze to solve.
basically there is a "solver" program which takes in a set of predicates which must be satisfied to obtain a solution. here's a reproduction of the question below:

The routes to the goal in this case are easy to see. The problem for the solver is to find the shortest route. Of course, you can solve the problem yourself; it is less easy to represent it to the automatic solver.

Here is a simple grid, with some small squares blocked out:
Code:
        a     b     c     d     e     f

     +-----+-----+-----+-----+-----+-----+
     |     |     |     |  o  |     |*****|
  A  |     |     |     | [:] |     |*****|
     |     |     |     | / \ |     |*****|
     +-----+-----+-----+-----+-----+-----+
     |*****|     |*****|     |     |     |
  B  |*****|     |*****|     |     |     |
     |*****|     |*****|     |     |     |
     +-----+-----+-----+-----+-----+-----+
     |     |     |     |*****|     |     |
  C  |     |     |     |*****|     |     |
     |     |     |     |*****|     |     |
     +-----+-----+-----+-----+-----+-----+
     |     |*****|*****|     |*****|     |
  D  |     |*****|*****| [G] |*****|     |
     |     |*****|*****|     |*****|     |
     +-----+-----+-----+-----+-----+-----+
     |     |*****|     |     |*****|     |
  E  |     |*****|     |     |*****|     |
     |     |*****|     |     |*****|     |
     +-----+-----+-----+-----+-----+-----+
     |     |     |     |     |     |     |
  F  |     |     |     |     |     |     |
     |     |     |     |     |     |     |
     +-----+-----+-----+-----+-----+-----+

There is a robot in square Ad, and he needs to find his way to the goal (G) in square Dd. At each step he can move to any adjacent square (North, South, East or West) but must avoid the blocked ones.

Find the shortest path he can follow.

--------
There are 3 types of things to define: sorts, functions and the clauses (predicates that must be satisfied).

I have defined my sorts as such:
#sorts
row enum: A,B,C,D,E,F.

col enum:a,b,c,d,e,f.

dir enum: up,down,left,right.

---
then the functions:

pos: row,col -> int {partial all_different}

obs: row,col -> bool {print: none}

goal: row,col -> bool {print:none}

start: row,col -> bool {print:none}

next: row,col,dir -> bool{partial print:none}

---
note: partial means that the function may be undefined for certain arguments
all_different means no two arguments give the same value.

---
clauses - this is where I am stuck.
I want to tell the solver that there is a next cell if it is not an obstacle, it is not out of range and the goal has not been reached.

The solution should look something like:

Code:
path | a  b  c  d  e  f  
    -----+------------------
       A |          0        
       B |          1  2  3  
       C |                4  
       D |          11    5  
       E |          10    6  
       F |          9  8  7

So far, I have define some clauses :

pos(A,d) = 0 .x=B, y=d -> goal(x,y).

%define obstacles
obs(A,f).
obs(B,a).
obs(B,c).
obs(C,d).
obs(D,b).
obs(D,c).
obs(D,e).
obs(E,b).
obs(E,e).

%there does not exist a pos(x,y) at an obstacle
EST(x), EST(y), EST(pos(x,y)) -> NOT(obs(x,y)).

%this assigns a number to every cell except the obstacles (which is not exactly what i want of course).

---
sorry that it is a long post. any ideas/hints/tips very welcome and appreciated.

thanks!
 
Last edited:
Physics news on Phys.org
Wrap your preformatted text in [ code ] ... [ /code ] tags so it shows up right.
 
Thanks for the tip Hurkyl!
much more comprehensible now. didn't know know to.
 
-I’m unfamiliar with the language or logic scheme you are using, but
-Here is the simplest algorithm for determining the path

Create an array: a grid a-f x A-F
Fill is array with a number > 6*6 = 36 ( assume least optimal )
Place a zero at the robots position.

Look at every cell in this array and…
If that cell has an adjacent cell to it ( which is not blocked or off the edge )
And the number in the adjacent cell is > the number in the current cell +1
Then assign that cell the number in the current cell +1
Repeat this until the goal is reached OR no cells are changed.

(Thinning it out to look like the solution)
Do not display any cell which does not have a higher neighbor OR is >= the number in the ‘goal’ unless it is the goal.

-If you want to tell the “solver” that there is a next cell it is as you stated, the adjacent cell is only a possibility if its not an obstacle, its not out of range, and the goal has not been reached. But there are few things you can do to directly eliminate any other possibilities without trying them.

-Note that the above method finds equivalent paths not shown in your solution, is this still correct?

To improve things quite a bit in terms of speed you can:
Only reevaluate cells adjacent to cells that have changed.
Make a pass though beforehand and add barriers to any cells with three adjacent barriers, repeat.
Simultaneously derive a path from the goal to the robot until it intersects the robot goal path.
Divide the board into quadrants around the goal, sum the barriers in each quadrant and have the search look in quadrants with the fewest barriers first.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 11 ·
Replies
11
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 20 ·
Replies
20
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
Replies
5
Views
3K
  • · Replies 18 ·
Replies
18
Views
3K