hexhex / core

DLVHEX solver: core system and plugin API
http://www.kr.tuwien.ac.at/research/systems/dlvhex/
GNU Lesser General Public License v2.1
24 stars 8 forks source link

Solver hangs when using Python External Atom Function #16

Open 0xbb opened 9 years ago

0xbb commented 9 years ago

Hello! When I run this hex program (example.hex):

time(0).time(1).time(2).time(3).time(4).

exp(START, END)      :-  time(START), time(END),
                        START <= END,
                        &window[START, END](T, V) , V != 3.

all_three(START,END) :- time(START), time(END),
                        START <= END,
                        not exp(START, END).

Together with this python plugin (example.py):

import dlvhex

def values(tup):
    print "&values:["+",".join(x.value() for x in tup)+"]"

    start = int(tup[0].value())
    end = int(tup[1].value())
    for i in range(start, end+1):
        dlvhex.output((i,i ))

    print "======="

def register():
    dlvhex.addAtom("values", (dlvhex.TUPLE,), 2)

I run the example with dlvhex2 --pythonplugin=example.py example.hex

dlvhex 2.4.0 gives me this output:

DLVHEX  2.4.0 [build Jun 22 2015   gcc 4.8.2]

&values:[0,0]
=======
&values:[0,1]
=======
&values:[1,1]
=======
&values:[0,2]
=======
&values:[1,2]
=======
&values:[2,2]
=======
&values:[0,3]
=======
&values:[1,3]
=======
&values:[2,3]
=======
&values:[3,3]
=======
&values:[0,4]
=======
&values:[1,4]
=======
&values:[2,4]
=======
&values:[3,4]
=======
&values:[4,4]
=======
{time(0),time(1),time(2),time(3),time(4),exp(0,0),exp(0,1),exp(1,1),exp(0,2),exp(1,2),exp(2,2),exp(0,3),exp(1,3),exp(2,3),exp(0,4),exp(1,4),exp(2,4),exp(3,4),exp(4,4),all_three(3,3)}

The current version on GitHub (0ba994396aeff1939e221512eced800649a86242) hangs with this output:

DLVHEX  2.4.0 [build Jun 22 2015   gcc 4.8.2]

&values:[0,0]
=======
&values:[0,1]
=======
&values:[1,1]
=======
&values:[0,2]
=======
&values:[1,2]
=======
&values:[2,2]
=======
&values:[0,3]
=======
&values:[1,3]
=======
&values:[2,3]
=======
&values:[3,3]
=======
&values:[0,4]
=======
&values:[1,4]
=======
&values:[2,4]
=======
&values:[3,4]
=======
&values:[4,4]
=======
&values:[0,0]
=======

Both binaries were compiled with PYTHON_BIN=python2.7 ./configure on a computer running Ubuntu 14.04.2 LTS.

I am not sure if I am using the Python Plugin Framwork right or if there is an issue with dlvhex. Any help would be very appreciated!

Greetings Bruno

credl commented 9 years ago

Dear Bruno!

The program did not really get stuck, it just takes much longer with the new version. This can be confirmed by making the instance smaller.

I did not analyze the reason in detail, but we changed several default settings in the most recent development version. As always, this is good for many instances, but might be counter-productive for others (like yours, obviously). Passing the --nocache option seems to make the evaluation of your program much faster (we did not change this option, but it seems to cancel out the effects of other changes).

Best regards, Christoph

2015-06-22 17:03 GMT+02:00 Bruno Bierbaumer notifications@github.com:

Hello! When I run this hex program (example.hex):

time(0).time(1).time(2).time(3).time(4).

exp(START, END) :- time(START), time(END), START <= END, &window[START, END](T, V) , V != 3.

all_three(START,END) :- time(START), time(END), START <= END, not exp(START, END).

Together with this python plugin (example.py):

import dlvhex def values(tup): print "&values:["+",".join(x.value() for x in tup)+"]"

start = int(tup[0].value())
end = int(tup[1].value())
for i in range(start, end+1):
    dlvhex.output((i,i ))

print "======="

def register(): dlvhex.addAtom("values", (dlvhex.TUPLE,), 2)

I run the example with dlvhex2 --pythonplugin=example.py example.hex

dlvhex 2.4.0 gives me this output:

DLVHEX 2.4.0 [build Jun 22 2015 gcc 4.8.2]

&values:[0,0]

&values:[0,1]

&values:[1,1]

&values:[0,2]

&values:[1,2]

&values:[2,2]

&values:[0,3]

&values:[1,3]

&values:[2,3]

&values:[3,3]

&values:[0,4]

&values:[1,4]

&values:[2,4]

&values:[3,4]

&values:[4,4]

{time(0),time(1),time(2),time(3),time(4),exp(0,0),exp(0,1),exp(1,1),exp(0,2),exp(1,2),exp(2,2),exp(0,3),exp(1,3),exp(2,3),exp(0,4),exp(1,4),exp(2,4),exp(3,4),exp(4,4),all_three(3,3)}

The current version on GitHub (0ba9943 https://github.com/hexhex/core/commit/0ba994396aeff1939e221512eced800649a86242) hangs with this output:

DLVHEX 2.4.0 [build Jun 22 2015 gcc 4.8.2]

&values:[0,0]

&values:[0,1]

&values:[1,1]

&values:[0,2]

&values:[1,2]

&values:[2,2]

&values:[0,3]

&values:[1,3]

&values:[2,3]

&values:[3,3]

&values:[0,4]

&values:[1,4]

&values:[2,4]

&values:[3,4]

&values:[4,4]

&values:[0,0]

Both binaries were compiled with PYTHON_BIN=python2.7 ./configure on a computer running Ubuntu 14.04.2 LTS.

I am not sure if I am using the Python Plugin Framwork right or if there is an issue with dlvhex. Any help would be very appreciated!

Greetings Bruno

— Reply to this email directly or view it on GitHub https://github.com/hexhex/core/issues/16.

0xbb commented 9 years ago

Hi Christoph, thank you for your answer!

I think you are right that the solver just takes a long time to solve this program. For now the workaround with passing --nocache works for me. :thumbsup:

Thanks again, Bruno