Solving a Logic Maze: Shortest Path to the Goal

  • Thread starter madameChing
  • Start date
  • Tags
    Logic Path
In summary: A | | | true |B | | | false |C | | | true |D | | | false |E | | | false |F | | | false
  • #1
madameChing
2
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
  • #2
Wrap your preformatted text in [ code ] ... [ /code ] tags so it shows up right.
 
  • #3
Thanks for the tip Hurkyl!
much more comprehensible now. didn't know know to.
 
  • #4
-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.
 

FAQ: Solving a Logic Maze: Shortest Path to the Goal

How do you define a logic maze?

A logic maze is a type of puzzle or game that requires logical reasoning and problem-solving skills to find the shortest path to a given goal or solution. It typically involves a series of interconnected paths or rooms, with obstacles and clues that must be navigated in a specific way to reach the end goal.

What is the purpose of solving a logic maze?

The main purpose of solving a logic maze is to exercise and improve critical thinking and problem-solving abilities. It can also be a fun and challenging activity that can be enjoyed alone or with others.

How do you approach solving a logic maze?

The first step in solving a logic maze is to carefully analyze the clues and obstacles presented. This may involve making a mental map or drawing out the maze to better understand the layout. Then, using deductive reasoning and trial and error, you can determine the most efficient path to the goal.

What strategies can be used to solve a logic maze?

Some common strategies for solving a logic maze include starting from the end goal and working backwards, keeping track of previous paths taken, and using logic grids or charts to visually organize information. It may also be helpful to break the maze into smaller, more manageable sections.

Are there any tips for solving a logic maze more efficiently?

Here are a few tips for solving a logic maze more efficiently: 1) Look for patterns and connections between clues and obstacles. 2) Don't be afraid to backtrack and try different paths. 3) Take breaks if you get stuck, as fresh eyes may help you see the solution more clearly. 4) Practice regularly to improve your skills and speed.

Similar threads

Back
Top