Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solver hangs when using Python External Atom Function #16

Open
0xbb opened this issue Jun 22, 2015 · 2 comments
Open

Solver hangs when using Python External Atom Function #16

0xbb opened this issue Jun 22, 2015 · 2 comments

Comments

@0xbb
Copy link

0xbb commented Jun 22, 2015

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) 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
Copy link
Member

credl commented Jun 22, 2015

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 [email protected]:

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
0ba9943)
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
#16.

@0xbb
Copy link
Author

0xbb commented Jun 23, 2015

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. 👍

Thanks again,
Bruno

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants