10.02.2013 Views

A User's Guide to gringo, clasp, clingo, and iclingo

A User's Guide to gringo, clasp, clingo, and iclingo

A User's Guide to gringo, clasp, clingo, and iclingo

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

2<br />

3<br />

3<br />

1<br />

3<br />

2<br />

6<br />

2<br />

1 2<br />

4<br />

Figure 5: The Graph from Figure 3 along with Edge Costs.<br />

Answer: 1<br />

... color(1,2) color(2,1) color(3,1) \<br />

color(4,3) color(5,2) color(6,3)<br />

Note that we have omitted the six instances of node/1 <strong>and</strong> the 17 instances of edge/2<br />

in order <strong>to</strong> emphasize the actual solution, which is depicted in Figure 4. Such output<br />

projection can also be specified within a logic program file by using the declaratives<br />

#hide <strong>and</strong> #show, described in Section 3.1.12.<br />

4.2 Traveling Salesperson<br />

We now consider the well-known Traveling Salesperson Problem (TSP), where the task<br />

is <strong>to</strong> decide whether there is a round trip that visits each node in a graph exactly once<br />

(viz., a Hamil<strong>to</strong>nian cycle) <strong>and</strong> whose accumulated edge costs must not exceed some<br />

budget B. We tackle a slightly more general variant of the problem by not a priori<br />

fixing B <strong>to</strong> any integer. Rather, we want <strong>to</strong> compute a minimum budget B along with<br />

a round trip of cost B. This problem is FP NP -complete (cf. [44]), that is, it can be<br />

solved with a polynomial number of queries <strong>to</strong> an NP-oracle. As with N-Coloring, we<br />

provide a uniform problem definition by separating the encoding from instances.<br />

4.2.1 Problem Instance<br />

We reuse graph specifications in terms of predicates node/1 <strong>and</strong> edge/2 as in Section<br />

4.1.1. In addition, facts over predicate cost/3 are used <strong>to</strong> define edge costs:<br />

1 % Edge Costs<br />

2 cost(1,2,2). cost(1,3,3). cost(1,4,1).<br />

3 cost(2,4,2). cost(2,5,2). cost(2,6,4).<br />

4 cost(3,1,3). cost(3,4,2). cost(3,5,2).<br />

5 cost(4,1,1). cost(4,2,2).<br />

6 cost(5,3,2). cost(5,4,2). cost(5,6,1).<br />

7 cost(6,2,4). cost(6,3,3). cost(6,5,1).<br />

Figure 5 shows the (directed) graph from Figure 3 along with the associated edge costs.<br />

Symmetric edges have the same costs here, but differing costs would also be possible.<br />

34<br />

1<br />

4<br />

5<br />

2<br />

2<br />

2

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!