1

I'm currently developing an Answer Set Programming problem, consisting in a robot that is needed to cover a room avoiding obstacles and reach a Goal point when all the room is covered. My idea was to transform the room map into asp predicates,in the form of room/3, being the parameters:

  • X:x coord
  • Y:y coord
  • V:Value of the point in the room, being 0(initial point),1(point to cover),2(Obstacle),3(Goal point)

One of the criteria that the program must meet is to cover every point with a value of 1,which can be achieved with a constraint, but I do not know how to model the robot movement. My idea was to use a predicate of the form move/1,with up,down,left or right.

Can anybody help me guiding me in how to model this problem?

    void map_to_asp(std::ofstream& file,std::vector<std::vector<char>>& room)
{
  std::cout << room.size() << "," << room[0].size() << std::endl;
  for(int i = 0; i < room.size(); i++)
  {
    for(int j = 0;j < room[0].size(); j++)
    {
      switch(room[i][j])
      {
        case '@':
        file << "initial(" << i+1 << "," << j+1 << ").\n";
        break;
        case '.':
        file << "toClean(" << i+1 << "," << j+1 << ").\n";
        break;
        case '#':
        file << "obstacle(" << i+1 << "," << j+1 << ").\n";
        break;
        case 'X':
        file << "goal(" << i+1 << "," << j+1 << ").\n";
        break;
      }
    }
  }
}

Thank you in advance.

wizenink
  • 11
  • 2

1 Answers1

0

If your goal is to have a model for each possible path, a simple way to go is to make an iterative progression in the graph.

We need first to define all positions we can move in (we are actually building a graph before solving any problem):

position(X,Y,S):- room(X,Y,S) ; not S=2.

Now we decide where we can go from any position (edges of the graph):

edge((X,Y),(I,J)):- position(X,Y,_) ; position(I,J,_) ; |X-I|=0..1 ; |Y-J|=0..1 ; |X-I|+|Y-J|=1..2 .

Note that we consider that the graph is undirected (not necessarily true, if there is a slide in your room for instance). Let's define some constants:

#const start_pos=(1,1).
#const goal=(5,5).
#const path_maxlen=100.

We obviously start at the starting point:

path(1,start_pos).

And now, we recursively indicate that there is a next way to go, with a limit to avoid too useless solutions.

0{path(N+1,E): path(N,S), edge(S,E), S!=goal}1:- path(N,_) ; N<path_maxlen.

We have to avoid all useless paths.

% a path that do not join the end is illegal.
:- path(N,E) ; not path(N+1,_) ; not E=goal.

% a path must go by all milestone (example of milestone: milestone(2,14)).
:- not path(_,(X,Y)): milestone(X,Y).

We want the shortest path:

last_step(N):- path(N,_) ; not path(N+1,_).
#minimize{N: last_step(N)}.

The full code is available here.


As a side-notes:

  • since we don't use them, you could (should) take rid of all room/3 that describe an obstacle.
  • you could also make you goal point artificial (out of the room, but the real goad is linked to it) in order to allow your path to pass by the real goal, without stopping. Using that, you can achieve support for multiple goal.
aluriak
  • 5,559
  • 2
  • 26
  • 39